protected virtual void INTran_ToLocationID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { /// Needed for the posting of Transfer Orders via /// <see cref="SO.SOShipmentEntry.PostShipment(INIssueEntry, PXResult{SO.SOOrderShipment, SO.SOOrder}, DocumentList{INRegister}, AR.ARInvoice)"/> INTran row = (INTran)e.Row; if (row == null || row.DocType != INDocType.Transfer) { return; } INItemSite itemSite = PXSelect <INItemSite, Where <INItemSite.siteID, Equal <Required <INItemSite.siteID> >, And <INItemSite.inventoryID, Equal <Required <INItemSite.inventoryID> > > > > .SelectWindowed(this, 0, 1, row.ToSiteID, row.InventoryID); if (itemSite != null) { e.NewValue = row.SiteID == row.ToSiteID ? itemSite.DfltShipLocationID : itemSite.DfltReceiptLocationID; e.Cancel = true; } else { INSite site = (INSite)PXSelectorAttribute.Select <INTran.toSiteID>(sender, row); if (site != null) { e.NewValue = row.SiteID == row.ToSiteID ? site.ShipLocationID : site.ReceiptLocationID; e.Cancel = true; } } }
protected virtual void INTran_LocationID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { INTran row = (INTran)e.Row; if (row == null) { return; } INItemSite itemSite = itemsite.SelectWindowed(0, 1, row.SiteID, row.InventoryID); if (itemSite != null) { e.NewValue = itemSite.DfltReceiptLocationID; e.Cancel = true; } else { INSite site = (INSite)PXSelectorAttribute.Select <INTran.siteID>(sender, row); if (site != null) { e.NewValue = site.ReceiptLocationID; e.Cancel = true; } } }
protected void UpateSiteLocation <Field, FieldResult>(PXCache cache, PXRowUpdatingEventArgs e) where Field : IBqlField where FieldResult : IBqlField { int?newValue = (int?)cache.GetValue <Field>(e.NewRow); int?value = (int?)cache.GetValue <Field>(e.Row); if (value != newValue && e.ExternalCall == true) { INItemSite itemsite = PXSelect <INItemSite, Where <INItemSite.siteID, Equal <Required <INItemSite.siteID> > > > .SelectWindowed(this, 0, 1, cache.GetValue <INSite.siteID>(e.Row)); if (itemsite != null && site.Ask(Messages.Warning, Messages.SiteLocationOverride, MessageButtons.YesNo) == WebDialogResult.Yes) { cache.SetValue <FieldResult>(e.NewRow, true); } else { cache.SetValue <FieldResult>(e.NewRow, false); } } }
protected virtual void INLocation_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { INLocation row = e.Row as INLocation; if (row == null) { return; } if ((e.Operation & PXDBOperation.Command) != PXDBOperation.Delete && row.ProjectID != null && row.TaskID == null && row.Active == true) { INLocation anotherWildcardLocation = PXSelect <INLocation, Where <INLocation.locationID, NotEqual <Required <INLocation.locationID> >, And <INLocation.projectID, Equal <Required <INLocation.projectID> >, And <INLocation.taskID, IsNull, And <INLocation.active, Equal <True> > > > > > .Select(this, row.LocationID, row.ProjectID); if (anotherWildcardLocation != null) { PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, row.ProjectID); INSite warehouse = PXSelect <INSite, Where <INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(this, anotherWildcardLocation.SiteID); if (sender.RaiseExceptionHandling <INLocation.projectID>(e.Row, project.ContractCD, new PXSetPropertyException(Messages.ProjectWildcardLocationIsUsedIn, PXErrorLevel.Error, warehouse.SiteCD, anotherWildcardLocation.LocationCD))) { throw new PXRowPersistingException(PXDataUtils.FieldName <INLocation.projectID>(), row.ProjectID, Messages.ProjectWildcardLocationIsUsedIn, warehouse.SiteCD, anotherWildcardLocation.LocationCD); } } } if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Delete) { INItemSite itemSite = PXSelect <INItemSite, Where <INItemSite.siteID, Equal <Current <INSite.siteID> >, And <Where <INItemSite.dfltReceiptLocationID, Equal <Required <INItemSite.dfltReceiptLocationID> >, Or <INItemSite.dfltShipLocationID, Equal <Required <INItemSite.dfltShipLocationID> > > > > > > .Select(this, row.LocationID, row.LocationID); if (itemSite != null) { InventoryItem initem = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, itemSite.InventoryID) ?? new InventoryItem(); if (sender.RaiseExceptionHandling <INLocation.locationID>(e.Row, row.LocationCD, new PXSetPropertyException(Messages.LocationInUseInItemWarehouseDetails, PXErrorLevel.Error, row.LocationCD.TrimEnd(), initem.InventoryCD.TrimEnd()))) { throw new PXRowPersistingException(PXDataUtils.FieldName <INLocation.locationID>(), row.LocationID, Messages.LocationInUseInItemWarehouseDetails, row.LocationCD.TrimEnd(), initem.InventoryCD.TrimEnd()); } } INPIClassLocation piLocation = PXSelectJoin <INPIClassLocation, InnerJoin <INPIClass, On <INPIClass.pIClassID, Equal <INPIClassLocation.pIClassID> > >, Where <INPIClass.siteID, Equal <Current <INSite.siteID> >, And <INPIClassLocation.locationID, Equal <Required <INPIClassLocation.locationID> > > > > .Select(this, row.LocationID); if (piLocation != null) { if (sender.RaiseExceptionHandling <INLocation.locationID>(e.Row, row.LocationCD, new PXSetPropertyException(Messages.LocationInUseInPIType, PXErrorLevel.Error, row.LocationCD.TrimEnd(), piLocation.PIClassID.TrimEnd()))) { throw new PXRowPersistingException(PXDataUtils.FieldName <INLocation.locationID>(), row.LocationID, Messages.LocationInUseInPIType, row.LocationCD.TrimEnd(), piLocation.PIClassID.TrimEnd()); } } } }
private List <UpdateMCAssignmentResult> CalcMCAssignments(bool updateDB) { UpdateMCAssignmentSettings us = UpdateSettings.Current; List <UpdateMCAssignmentResult> list = new List <UpdateMCAssignmentResult>(); if (us == null) { return(list); } //empty if ((us.SiteID == null) || (us.StartFinPeriodID == null) || (us.EndFinPeriodID == null)) { return(list); } //empty if (updateDB) { itemsite.Cache.Clear(); } PXSelectBase <INItemSite> cmd = new PXSelectJoin <INItemSite, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <INItemSite.inventoryID>, And <InventoryItem.stkItem, Equal <boolTrue> > > >, Where <INItemSite.siteID, Equal <Current <UpdateMCAssignmentSettings.siteID> > > >(this); foreach (PXResult <INItemSite, InventoryItem> resultset in cmd.Select()) { INItemSite currentItemSite = (INItemSite)resultset; InventoryItem inventoryItem = (InventoryItem)resultset; UpdateMCAssignmentResult updateMC = new UpdateMCAssignmentResult(); updateMC.MCFixed = currentItemSite.MovementClassIsFixed; updateMC.Descr = inventoryItem.Descr; updateMC.InventoryID = currentItemSite.InventoryID; updateMC.OldMC = currentItemSite.MovementClassID; if (updateMC.MCFixed == true) { updateMC.NewMC = currentItemSite.MovementClassID; } else { PXSelectBase <FinPeriod> cmd1 = new PXSelectJoinGroupBy <FinPeriod, InnerJoin <INItemCostHist, On <INItemCostHist.finPeriodID, LessEqual <FinPeriod.finPeriodID> >, InnerJoin <INLocation, On < Where2 < Where < INLocation.isCosted, Equal <boolFalse>, And <INItemCostHist.costSiteID, Equal <INLocation.siteID> > >, Or < Where < INLocation.isCosted, NotEqual <boolFalse>, And <INItemCostHist.costSiteID, Equal <INLocation.locationID> > > > > > > >, Where <INLocation.siteID, Equal <Current <UpdateMCAssignmentSettings.siteID> >, And <INItemCostHist.inventoryID, Equal <Required <INItemCostHist.inventoryID> >, And <FinPeriod.finPeriodID, GreaterEqual <Current <UpdateMCAssignmentSettings.startFinPeriodID> >, And <FinPeriod.finPeriodID, LessEqual <Current <UpdateMCAssignmentSettings.endFinPeriodID> > > > > >, Aggregate < Avg <INItemCostHist.finYtdCost, Avg <INItemCostHist.tranYtdCost, Avg <INItemCostHist.finBegQty, Avg <INItemCostHist.tranBegQty, Avg <INItemCostHist.finYtdQty, Avg <INItemCostHist.tranYtdQty> > > > > > > >(this); INItemCostHist itemHistTranYtdQty = null; decimal tranYtdQty = 0m; foreach (PXResult <FinPeriod, INItemCostHist> ih in cmd1.Select(currentItemSite.InventoryID)) { itemHistTranYtdQty = (INItemCostHist)ih; tranYtdQty += itemHistTranYtdQty.TranYtdQty ?? 0m; } PXSelectBase <INItemCostHist> cmd2 = new PXSelectJoinGroupBy <INItemCostHist, LeftJoin <INLocation, On < Where2 < Where < INLocation.isCosted, Equal <boolFalse>, And <INItemCostHist.costSiteID, Equal <INLocation.siteID> > >, Or < Where < INLocation.isCosted, NotEqual <boolFalse>, And <INItemCostHist.costSiteID, Equal <INLocation.siteID> > > > > > >, Where <INLocation.siteID, Equal <Current <UpdateMCAssignmentSettings.siteID> >, And <INItemCostHist.inventoryID, Equal <Required <INItemCostHist.inventoryID> >, And <INItemCostHist.finPeriodID, GreaterEqual <Current <UpdateMCAssignmentSettings.startFinPeriodID> >, And <INItemCostHist.finPeriodID, LessEqual <Current <UpdateMCAssignmentSettings.endFinPeriodID> > > > > >, Aggregate <Sum <INItemCostHist.tranPtdQtyReceived, Sum <INItemCostHist.tranPtdQtyIssued, Sum <INItemCostHist.tranPtdQtySales, Sum <INItemCostHist.tranPtdQtyCreditMemos, Sum <INItemCostHist.tranPtdQtyDropShipSales, Sum <INItemCostHist.tranPtdQtyTransferIn, Sum <INItemCostHist.tranPtdQtyTransferOut, Sum <INItemCostHist.tranPtdQtyAdjusted, Sum <INItemCostHist.finPtdQtyReceived, Sum <INItemCostHist.finPtdQtyIssued, Sum <INItemCostHist.finPtdQtySales, Sum <INItemCostHist.finPtdQtyCreditMemos, Sum <INItemCostHist.finPtdQtyDropShipSales, Sum <INItemCostHist.finPtdQtyTransferIn, Sum <INItemCostHist.finPtdQtyTransferOut, Sum <INItemCostHist.finPtdQtyAdjusted, Avg <INItemCostHist.tranYtdQty> > > > > > > > > > > > > > > > > > >(this); INItemCostHist itemHistTranPtdQtySales = null; decimal tranPtdQtySales = 0m; foreach (PXResult <INItemCostHist> ih in cmd2.Select(currentItemSite.InventoryID)) { itemHistTranPtdQtySales = (INItemCostHist)ih; tranPtdQtySales += (itemHistTranPtdQtySales.TranPtdQtySales ?? 0m); } if (tranYtdQty != 0m || tranPtdQtySales != 0m) { decimal radio = MovementToStockRatio(tranYtdQty, tranPtdQtySales); PXSelectBase <INMovementClass> cmd3 = new PXSelect <INMovementClass, Where <INMovementClass.maxTurnoverPct, GreaterEqual <Required <INMovementClass.maxTurnoverPct> > >, OrderBy <Asc <INMovementClass.maxTurnoverPct> > >(this); INMovementClass movementClass = (INMovementClass)cmd3.Select(radio); if (movementClass != null) { updateMC.NewMC = movementClass.MovementClassID; } else { updateMC.NewMC = null; } } } updateMC.OldMC = currentItemSite.MovementClassID; list.Add(updateMC); if (updateDB && (currentItemSite.MovementClassID != updateMC.NewMC)) { currentItemSite.MovementClassID = updateMC.NewMC; itemsite.Update(currentItemSite); } } if (updateDB) { this.Actions.PressSave(); } return(list); }
private List <UpdateABCAssignmentResult> CalcABCAssignments(bool updateDB) { UpdateABCAssignmentSettings us = UpdateSettings.Current; List <UpdateABCAssignmentResult> result_list = new List <UpdateABCAssignmentResult>(); if (us == null) { return(result_list); } //empty if ((us.SiteID == null) || (us.FinPeriodID == null)) { return(result_list); } //empty if (updateDB) { itemsite.Cache.Clear(); } CostHistoryBySiteByPeriod costHistory = CreateCostHistory(us.SiteID.Value, us.FinPeriodID); PXSelectBase <INItemSite> cmd = new PXSelectJoin <INItemSite, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <INItemSite.inventoryID>, And <InventoryItem.stkItem, NotEqual <boolFalse>, And <Match <InventoryItem, Current <AccessInfo.userName> > > > > >, Where <INItemSite.siteID, Equal <Current <UpdateABCAssignmentSettings.siteID> > > >(this); PXResultset <INItemSite> intermediateResult = (PXResultset <INItemSite>)cmd.Select(); // 1. set next non-fixed item position to [0] // 2. for each ABC code X starting from 'A' to 'Z' // { // 2.1 move items having X code to the result list, counting their cost until cumulative cost not greater than cumulative ABC cost // (fixed-ABC-code items do not change their code) // } // 0.1 PXResultset <INABCCode> abc_codes = PXSelectOrderBy <INABCCode, OrderBy <Asc <INABCCode.aBCCodeID> > > .Select(this); //0.2 decimal total_cost_on_site = costHistory.GetTotalCostOnSite(); // 0.3 if ((abc_codes.Count == 0) || (total_cost_on_site == 0)) { // nothing to change : foreach (PXResult <INItemSite, InventoryItem> it in intermediateResult) { INItemSite is_rec = (INItemSite)it; InventoryItem ii_rec = (InventoryItem)it; UpdateABCAssignmentResult r_rec = new UpdateABCAssignmentResult(); r_rec.ABCCodeFixed = is_rec.ABCCodeIsFixed; r_rec.Descr = ii_rec.Descr; r_rec.InventoryID = is_rec.InventoryID; r_rec.OldABCCode = is_rec.ABCCodeID; r_rec.NewABCCode = is_rec.ABCCodeID; // null ? result_list.Add(r_rec); } return(result_list); } intermediateResult.Sort((x, y) => { INItemSite a = y; INItemSite b = x; decimal tranYtdCost_X = costHistory.GetTranYTDCost(a.InventoryID.Value); decimal tranYtdCost_Y = costHistory.GetTranYTDCost(b.InventoryID.Value); return(tranYtdCost_X.CompareTo(tranYtdCost_Y)); }); // 1. set next item position to [0] int next_item_to_process = 0; decimal cumulative_cost = 0m; decimal cumulative_abc_pct = 0m; // 2. for each ABC code X starting from 'A' to 'Z' foreach (PXResult <INABCCode> abc_it in abc_codes) { INABCCode abc_rec = (INABCCode)abc_it; cumulative_abc_pct += (abc_rec.ABCPct ?? 0m); // 2.1 move items having X code to the result list, counting their cost until cumulative cost not greater than cumulative ABC cost // (fixed-ABC-code items do not change their code) while (next_item_to_process < intermediateResult.Count) { PXResult <INItemSite, InventoryItem> it = (PXResult <INItemSite, InventoryItem>)intermediateResult[next_item_to_process]; INItemSite is_rec = (INItemSite)it; InventoryItem ii_rec = (InventoryItem)it; decimal tranYtdCost = costHistory.GetTranYTDCost(ii_rec.InventoryID.Value); if (((cumulative_cost + tranYtdCost) / total_cost_on_site) <= (cumulative_abc_pct / 100m)) { cumulative_cost += tranYtdCost; UpdateABCAssignmentResult r_rec = new UpdateABCAssignmentResult(); r_rec.ABCCodeFixed = is_rec.ABCCodeIsFixed; r_rec.Descr = ii_rec.Descr; r_rec.InventoryID = is_rec.InventoryID; if (is_rec.ABCCodeIsFixed ?? false) { r_rec.NewABCCode = is_rec.ABCCodeID; } else { r_rec.NewABCCode = abc_rec.ABCCodeID; } r_rec.OldABCCode = is_rec.ABCCodeID; r_rec.YtdCost = tranYtdCost; r_rec.Ratio = r_rec.YtdCost / total_cost_on_site * 100; r_rec.CumulativeRatio = cumulative_cost / total_cost_on_site * 100; result_list.Add(r_rec); if (updateDB && (is_rec.ABCCodeID != r_rec.NewABCCode)) { is_rec.ABCCodeID = r_rec.NewABCCode; itemsite.Update(is_rec); } next_item_to_process++; } else { break; } } } if (updateDB) { this.Actions.PressSave(); } return(result_list); }
private List <UpdateABCAssignmentResult> CalcABCAssignments(bool updateDB) { UpdateABCAssignmentSettings us = UpdateSettings.Current; List <UpdateABCAssignmentResult> result_list = new List <UpdateABCAssignmentResult>(); if (us == null) { return(result_list); } //empty if ((us.SiteID == null) || (us.FinPeriodID == null)) { return(result_list); } //empty if (updateDB) { itemsite.Cache.Clear(); } PXSelectBase <INItemSite> cmd = new PXSelectJoin <INItemSite, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <INItemSite.inventoryID>, And <InventoryItem.stkItem, NotEqual <boolFalse>, And <Match <InventoryItem, Current <AccessInfo.userName> > > > >, LeftJoin <ItemCostHistByPeriodByItemSite, On <ItemCostHistByPeriodByItemSite.inventoryID, Equal <INItemSite.inventoryID>, And <ItemCostHistByPeriodByItemSite.siteID, Equal <INItemSite.siteID>, And <ItemCostHistByPeriodByItemSite.finPeriodID, Equal <Current <UpdateABCAssignmentSettings.finPeriodID> > > > > > >, Where <INItemSite.siteID, Equal <Current <UpdateABCAssignmentSettings.siteID> > >, OrderBy <Desc <ItemCostHistByPeriodByItemSite.tranYtdCost, Asc <INItemSite.inventoryID> > > >(this); // if 'By Fin. Period' option will be added - we'll need change OrderBy here PXResultset <INItemSite> intermediateResult = (PXResultset <INItemSite>)cmd.Select(); // 1. set next non-fixed item position to [0] // 2. for each ABC code X starting from 'A' to 'Z' // { // 2.1 move items having X code to the result list, counting their cost until cumulative cost not greater than cumulative ABC cost // (fixed-ABC-code items do not change their code) // } // 0.1 PXResultset <INABCCode> abc_codes = PXSelectOrderBy <INABCCode, //Where<INABCCode.aBCPct, NotEqual<decimal0>>, OrderBy <Asc <INABCCode.aBCCodeID> > > .Select(this); //0.2 decimal total_cost_on_site = 0m; foreach (PXResult <INItemSite, InventoryItem, ItemCostHistByPeriodByItemSite> it in intermediateResult) { total_cost_on_site += (((ItemCostHistByPeriodByItemSite)it).TranYtdCost ?? 0m); } // 0.3 if ((abc_codes.Count == 0) || (total_cost_on_site == 0)) { // nothing to change : foreach (PXResult <INItemSite, InventoryItem, ItemCostHistByPeriodByItemSite> it in intermediateResult) { INItemSite is_rec = (INItemSite)it; InventoryItem ii_rec = (InventoryItem)it; ItemCostHistByPeriodByItemSite ich_rec = (ItemCostHistByPeriodByItemSite)it; UpdateABCAssignmentResult r_rec = new UpdateABCAssignmentResult(); r_rec.ABCCodeFixed = is_rec.ABCCodeIsFixed; r_rec.Descr = ii_rec.Descr; r_rec.InventoryID = is_rec.InventoryID; r_rec.OldABCCode = is_rec.ABCCodeID; r_rec.NewABCCode = is_rec.ABCCodeID; // null ? result_list.Add(r_rec); } return(result_list); } // 1. set next item position to [0] int next_item_to_process = 0; decimal cumulative_cost = 0m; decimal cumulative_abc_pct = 0m; // 2. for each ABC code X starting from 'A' to 'Z' foreach (PXResult <INABCCode> abc_it in abc_codes) { INABCCode abc_rec = (INABCCode)abc_it; cumulative_abc_pct += (abc_rec.ABCPct ?? 0m); // 2.1 move items having X code to the result list, counting their cost until cumulative cost not greater than cumulative ABC cost // (fixed-ABC-code items do not change their code) while (next_item_to_process < intermediateResult.Count) { PXResult <INItemSite, InventoryItem, ItemCostHistByPeriodByItemSite> it = (PXResult <INItemSite, InventoryItem, ItemCostHistByPeriodByItemSite>)intermediateResult[next_item_to_process]; INItemSite is_rec = (INItemSite)it; InventoryItem ii_rec = (InventoryItem)it; ItemCostHistByPeriodByItemSite ich_rec = (ItemCostHistByPeriodByItemSite)it; if (((cumulative_cost + (ich_rec.TranYtdCost ?? 0m)) / total_cost_on_site) <= (cumulative_abc_pct / 100m)) { cumulative_cost += (ich_rec.TranYtdCost ?? 0m); UpdateABCAssignmentResult r_rec = new UpdateABCAssignmentResult(); r_rec.ABCCodeFixed = is_rec.ABCCodeIsFixed; r_rec.Descr = ii_rec.Descr; r_rec.InventoryID = is_rec.InventoryID; if (is_rec.ABCCodeIsFixed ?? false) { r_rec.NewABCCode = is_rec.ABCCodeID; } else { r_rec.NewABCCode = abc_rec.ABCCodeID; } r_rec.OldABCCode = is_rec.ABCCodeID; r_rec.YtdCost = (ich_rec.TranYtdCost ?? 0m); r_rec.Ratio = r_rec.YtdCost / total_cost_on_site * 100; r_rec.CumulativeRatio = cumulative_cost / total_cost_on_site * 100; result_list.Add(r_rec); if (updateDB && (is_rec.ABCCodeID != r_rec.NewABCCode)) { is_rec.ABCCodeID = r_rec.NewABCCode; itemsite.Update(is_rec); } next_item_to_process++; } else { break; } } } if (updateDB) { this.Actions.PressSave(); } return(result_list); }
protected void ItemWarehouse_SetProductManagerFields(PXGraph graph, EntityImpl entity, EntityImpl targetEntity) { var productManagerValueField = (EntityValueField)targetEntity.Fields.SingleOrDefault(f => f.Name.OrdinalEquals("ProductManager")); var productWorkgroupValueField = (EntityValueField)targetEntity.Fields.SingleOrDefault(f => f.Name.OrdinalEquals("ProductWorkgroup")); if (productManagerValueField == null && productWorkgroupValueField == null) { return; } var maint = (INItemSiteMaint)graph; var inventoryCD = entity.InternalKeys[nameof(maint.itemsiterecord)][nameof(INItemSite.InventoryID)]; InventoryItem inventory = null; if (maint.Caches <InventoryItem>().Locate(new Dictionary <string, object> { { nameof(InventoryItem.InventoryCD), inventoryCD } }) > 0) { inventory = maint.Caches <InventoryItem>().Current as InventoryItem; } var siteCD = entity.InternalKeys[nameof(maint.itemsiterecord)][nameof(INItemSite.SiteID)]; var site = (INSite) new PXSelectReadonly <INSite, Where <INSite.siteCD, Equal <Required <INSite.siteCD> > > >(graph).Select(siteCD); INItemSite row = maint.itemsitesettings.Select(inventory.InventoryID, site.SiteID); if (row == null) { var cache = maint.itemsiterecord.Cache; row = cache.CreateInstance() as INItemSite; row.InventoryID = inventory.InventoryID; row.SiteID = site.SiteID; row = maint.itemsiterecord.Insert(row); } bool productManagerValueExists = row.ProductManagerID != null; if (productManagerValueField != null) { productManagerValueExists = !string.IsNullOrEmpty(productManagerValueField.Value); } bool productWorkgroupValueExists = row.ProductWorkgroupID != null; if (productWorkgroupValueField != null) { productWorkgroupValueExists = !string.IsNullOrEmpty(productWorkgroupValueField.Value); } bool productManagerOverride = productManagerValueExists || productWorkgroupValueExists; maint.itemsitesettings.Cache.SetValueExt <INItemSite.productManagerOverride>(row, productManagerOverride); if (productManagerValueField != null) { maint.itemsitesettings.Cache.SetValueExt <INItemSite.productManagerID>(row, productManagerValueField.Value); } if (productWorkgroupValueField != null) { maint.itemsitesettings.Cache.SetValueExt <INItemSite.productWorkgroupID>(row, productWorkgroupValueField.Value); } maint.itemsitesettings.Update(row); }
private List <UpdateMCAssignmentResult> CalcMCAssignments(bool updateDB) { UpdateMCAssignmentSettings us = UpdateSettings.Current; List <UpdateMCAssignmentResult> list = new List <UpdateMCAssignmentResult>(); if (us == null) { return(list); } //empty if ((us.SiteID == null) || (us.StartFinPeriodID == null) || (us.EndFinPeriodID == null)) { return(list); } //empty if (updateDB) { itemsite.Cache.Clear(); } PXSelectBase <INItemSite> cmd = new PXSelectJoin <INItemSite, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <INItemSite.inventoryID>, And <InventoryItem.stkItem, Equal <boolTrue> > > >, Where <INItemSite.siteID, Equal <Current <UpdateMCAssignmentSettings.siteID> > > >(this); foreach (PXResult <INItemSite, InventoryItem> resultset in cmd.Select()) { INItemSite currentItemSite = (INItemSite)resultset; InventoryItem inventoryItem = (InventoryItem)resultset; UpdateMCAssignmentResult updateMC = new UpdateMCAssignmentResult(); updateMC.MCFixed = currentItemSite.MovementClassIsFixed; updateMC.Descr = inventoryItem.Descr; updateMC.InventoryID = currentItemSite.InventoryID; updateMC.OldMC = currentItemSite.MovementClassID; if (updateMC.MCFixed == true) { updateMC.NewMC = currentItemSite.MovementClassID; } else { PXSelectBase <INItemSiteHistDay> cmd1 = new PXSelectJoinGroupBy <INItemSiteHistDay, InnerJoin <INItemSiteHistByLastDayInPeriod, On <INItemSiteHistDay.inventoryID, Equal <INItemSiteHistByLastDayInPeriod.inventoryID>, And <INItemSiteHistDay.siteID, Equal <INItemSiteHistByLastDayInPeriod.siteID>, And <INItemSiteHistDay.subItemID, Equal <INItemSiteHistByLastDayInPeriod.subItemID>, And <INItemSiteHistDay.locationID, Equal <INItemSiteHistByLastDayInPeriod.locationID>, And <INItemSiteHistDay.sDate, Equal <INItemSiteHistByLastDayInPeriod.lastActivityDate> > > > > > >, Where <INItemSiteHistDay.siteID, Equal <Current <UpdateMCAssignmentSettings.siteID> >, And <INItemSiteHistDay.inventoryID, Equal <Required <INItemSiteHistDay.inventoryID> >, And <INItemSiteHistDay.sDate, Greater <Current <UpdateMCAssignmentSettings.startDateForAvailableQuantity> >, And <INItemSiteHistByLastDayInPeriod.finPeriodID, LessEqual <Current <UpdateMCAssignmentSettings.endFinPeriodID> > > > > >, Aggregate < Sum <INItemSiteHistDay.endQty, Count <INItemSiteHistByLastDayInPeriod.finPeriodID> > > >(this); decimal tranYtdQty = 0m; PXResult <INItemSiteHistDay> ihYtdQty = cmd1.Select(currentItemSite.InventoryID); var itemHistTranYtdQty = (INItemSiteHistDay)ihYtdQty; if (ihYtdQty.RowCount != 0) { tranYtdQty += (itemHistTranYtdQty.EndQty ?? 0m) / ihYtdQty.RowCount.Value; } PXSelectBase <INItemSiteHistDay> cmd2 = new PXSelectJoinGroupBy <INItemSiteHistDay, InnerJoin <MasterFinPeriod, On <MasterFinPeriod.startDate, LessEqual <INItemSiteHistDay.sDate>, And <INItemSiteHistDay.sDate, Less <MasterFinPeriod.endDate> > > >, Where <INItemSiteHistDay.siteID, Equal <Current <UpdateMCAssignmentSettings.siteID> >, And <INItemSiteHistDay.inventoryID, Equal <Required <INItemCostHist.inventoryID> >, And <MasterFinPeriod.finPeriodID, GreaterEqual <Current <UpdateMCAssignmentSettings.startFinPeriodID> >, And <MasterFinPeriod.finPeriodID, LessEqual <Current <UpdateMCAssignmentSettings.endFinPeriodID> > > > > >, Aggregate < Sum <INItemSiteHistDay.qtySales, Count <MasterFinPeriod.finPeriodID> > > >(this); decimal tranPtdQtySales = 0m; PXResult <INItemSiteHistDay> ihPtdQtySales = cmd2.Select(currentItemSite.InventoryID); INItemSiteHistDay itemHistTranPtdQtySales = (INItemSiteHistDay)ihPtdQtySales; if (ihPtdQtySales.RowCount != 0) { tranPtdQtySales += (itemHistTranPtdQtySales.QtySales ?? 0m) / ihPtdQtySales.RowCount.Value; } if (tranYtdQty != 0m || tranPtdQtySales != 0m) { decimal radio = MovementToStockRatio(tranYtdQty, tranPtdQtySales); PXSelectBase <INMovementClass> cmd3 = new PXSelectReadonly <INMovementClass, Where <INMovementClass.maxTurnoverPct, GreaterEqual <Required <INMovementClass.maxTurnoverPct> > >, OrderBy <Asc <INMovementClass.maxTurnoverPct> > >(this); INMovementClass movementClass = (INMovementClass)cmd3.Select(radio); if (movementClass != null) { updateMC.NewMC = movementClass.MovementClassID; } else { updateMC.NewMC = null; } } } updateMC.OldMC = currentItemSite.MovementClassID; list.Add(updateMC); if (updateDB && (currentItemSite.MovementClassID != updateMC.NewMC)) { currentItemSite.MovementClassID = updateMC.NewMC; itemsite.Update(currentItemSite); } } if (updateDB) { this.Actions.PressSave(); } return(list); }
public static void X_InventoryID_FieldUpdated <DAC, SubItemID, SiteID, SiteLocationID, UOM, EstimatedDuration, EstimatedQty, BillingRule, ActualDuration, ActualQty>( PXCache cache, PXFieldUpdatedEventArgs e, int?branchLocationID, Customer billCustomerRow, bool useActualFields) where DAC : class, IBqlTable, IFSSODetBase, new() where SubItemID : class, IBqlField where SiteID : class, IBqlField where SiteLocationID : class, IBqlField where UOM : class, IBqlField where EstimatedDuration : class, IBqlField where EstimatedQty : class, IBqlField where BillingRule : class, IBqlField where ActualDuration : class, IBqlField where ActualQty : class, IBqlField { if (e.Row == null) { return; } var row = (DAC)e.Row; // This is required in Inventory FieldUpdated events if (e.ExternalCall) { row.CuryUnitPrice = 0m; } if (IsInventoryLine(row.LineType) == false || (row.InventoryID == null && row.LineType != ID.LineType_All.PICKUP_DELIVERY)) { // Clear fields for non-inventory lines row.IsBillable = false; row.ManualPrice = false; row.TranDesc = null; row.SubItemID = null; row.SiteID = null; row.SiteLocationID = null; cache.SetDefaultExt <FSSODet.uOM>(e.Row); cache.RaiseExceptionHandling <UOM>(e.Row, null, null); row.SetDuration(FieldType.EstimatedField, 0, cache, false); row.SetQty(FieldType.EstimatedField, 0, cache, false); if (useActualFields == true) { row.SetDuration(FieldType.ActualField, 0, cache, false); row.SetQty(FieldType.ActualField, 0, cache, false); } row.BillingRule = ID.BillingRule.NONE; return; } InventoryItem inventoryItemRow = SharedFunctions.GetInventoryItemRow(cache.Graph, row.InventoryID); row.TranDesc = null; if (inventoryItemRow != null) { row.TranDesc = PXDBLocalizableStringAttribute.GetTranslation(cache.Graph.Caches[typeof(InventoryItem)], inventoryItemRow, "Descr", billCustomerRow?.LocaleName); } // UOM is assigned to null here to avoid price calculation while duration and qty fields are defaulted. row.UOM = null; cache.RaiseExceptionHandling <UOM>(e.Row, null, null); cache.SetDefaultExt <SubItemID>(e.Row); cache.SetDefaultExt <SiteID>(e.Row); if (inventoryItemRow != null) { if (row.SiteID == null) { row.SiteID = inventoryItemRow.DfltSiteID; } if (row.SiteID == null) { //TODO: this query may return multiple records INItemSite inItemSiteRow = PXSelect <INItemSite, Where < INItemSite.inventoryID, Equal <Required <INItemSite.inventoryID> > > > .Select(cache.Graph, inventoryItemRow.InventoryID); if (inItemSiteRow != null) { row.SiteID = inItemSiteRow.SiteID; } } } cache.SetDefaultExt <SiteLocationID>(e.Row); if (inventoryItemRow != null) { if (row.SiteLocationID == null && row.LineType == ID.LineType_All.INVENTORY_ITEM) { row.SiteLocationID = inventoryItemRow.DfltShipLocationID; } } int? defaultSubItemID = row.SubItemID; object newValue = null; cache.RaiseFieldDefaulting <UOM>(e.Row, out newValue); string defaultUOM = (string)newValue; int? defaultSiteID = row.SiteID; CompleteItemInfoUsingBranchLocation( cache.Graph, branchLocationID, inventoryItemRow != null ? inventoryItemRow.DefaultSubItemOnEntry : false, ref defaultSubItemID, ref defaultUOM, ref defaultSiteID); row.SubItemID = defaultSubItemID; if (defaultSiteID != null) { cache.SetValueExt <SiteID>(e.Row, defaultSiteID); } cache.SetValueExt <UOM>(e.Row, defaultUOM); row.SetDuration(FieldType.EstimatedField, 0, cache, false); // EstimatedQty MUST be assigned after BillingRule BUT before EstimatedDuration. if (row.LineType == ID.LineType_All.SERVICE && inventoryItemRow != null) { FSxService fsxServiceRow = PXCache <InventoryItem> .GetExtension <FSxService>(inventoryItemRow); cache.SetValueExt <BillingRule>(e.Row, fsxServiceRow.BillingRule); cache.SetDefaultExt <EstimatedQty>(e.Row); cache.SetValueExt <EstimatedDuration>(e.Row, fsxServiceRow.EstimatedDuration ?? 0); } else { cache.SetValueExt <BillingRule>(e.Row, ID.BillingRule.FLAT_RATE); cache.SetDefaultExt <EstimatedQty>(e.Row); } if (useActualFields == true) { cache.SetDefaultExt <ActualQty>(e.Row); cache.SetDefaultExt <ActualDuration>(e.Row); } }