public virtual void Resequence() { int startSequence = 10; foreach (FSScheduleRoute fsScheduleRouteRow in ServiceContracts.Select()) { fsScheduleRouteRow.GlobalSequence = startSequence.ToString().PadLeft(5, '0'); startSequence = startSequence + 10; } Save.Press(); ServiceContracts.View.RequestRefresh(); }
public RMReportPeriods(PXGraph graph) { _perWildcard = new string(RMReportConstants.DefaultWildcardChar, 6); PXSelectOrderBy <FinPeriod, OrderBy <Asc <FinPeriod.startDate> > > .Select(graph); _finPeriods = new List <FinPeriod>(graph.Caches[typeof(FinPeriod)].Cached.Cast <FinPeriod>()); }
public virtual void InitializeAction() { bool msgExist = MessagesExist(); if (!msgExist || (msgExist && DeleteExistedMessages.AskExt() == WebDialogResult.Yes)) { KCMSMQueueReader price = null; KCMSMQueueReader quantity = null; KCMSMQueueReader vendor = null; try { Initializations.Select().RowCast <KCMSMQInitializationProperty>().ForEach(x => Initializations.Delete(x)); CreatePN(SyncType.InventoryQuantity); CreatePN(SyncType.InventoryPrice); CreatePN(SyncType.VendorQuantity); price = CreateQueue(SyncType.InventoryPrice); quantity = CreateQueue(SyncType.InventoryQuantity); vendor = CreateQueue(SyncType.VendorQuantity); } finally { MSMQServiceStatus(price, quantity, vendor); price?.Dispose(); quantity?.Dispose(); vendor?.Dispose(); } } else { InsertInitializationActivity(KCMSMQConstants.MSMQServiceStatus, KCMSMQConstants.MSMQServiceInterrupted); Persist(); } }
protected virtual void CRSetup_RowInserted(PXCache sender, PXRowInsertedEventArgs e) { CROpportunityProbability p = OpportunityProbabilities.Select(); if (p == null) { p.StageCode = "A"; p.Probability = 60; OpportunityProbabilities.Insert(p); p.StageCode = "L"; p.Probability = 0; OpportunityProbabilities.Insert(p); p.StageCode = "P"; p.Probability = 10; OpportunityProbabilities.Insert(p); p.StageCode = "Q"; p.Probability = 20; OpportunityProbabilities.Insert(p); p.StageCode = "R"; p.Probability = 80; OpportunityProbabilities.Insert(p); p.StageCode = "V"; p.Probability = 40; OpportunityProbabilities.Insert(p); p.StageCode = "W"; p.Probability = 100; OpportunityProbabilities.Insert(p); OpportunityProbabilities.Cache.IsDirty = false; } }
public void Prefetch(PXGraph parameter) { _lookup = PXSelectOrderBy <TCategory, OrderBy <Asc <INCategory.parentID, Asc <INCategory.sortOrder> > > > .Select(parameter) .RowCast <TCategory>() .ToLookup(r => r.ParentID); }
void RenderSiteMap() { DivGraphs.Visible = true; IEnumerable <SiteMap> siteMap = Select <SiteMap>(PXSelectOrderBy <SiteMap, OrderBy <Asc <SiteMap.screenID> > > .Select(new PXGraph())); IList <string> lookup = ToLookup(siteMap); IEnumerable <SiteMap> hidden = GetHiddenScreens(lookup); HtmlTableBuilder b = new HtmlTableBuilder(); b.Table = TableGraphs; foreach (SiteMap rowSiteMap in Concat(siteMap, hidden)) { b.AddRow(); b.AddCellHref(rowSiteMap.ScreenID, rowSiteMap.Url); b.AddCell(rowSiteMap.Graphtype); bool isTypeFound = false; if (!String.IsNullOrEmpty(rowSiteMap.Graphtype)) { Type t = BuildManager.GetType(rowSiteMap.Graphtype, false); if (t != null) { try { string apiGraphName = ServiceManager.GetGraphNameFromType(t); isTypeFound = true; try { //WsdlSchemaBuilder.CreateGraph(t); //Activator.CreateInstance(t); string graphUrl = GetUrl("graph", apiGraphName); b.AddCellHref("Graph" + apiGraphName, graphUrl); } catch { b.AddCell("Graph" + apiGraphName + " - login?"); } } catch (ArgumentException) {} catch (KeyNotFoundException) { } } } if (!isTypeFound) { b.AddCell(null); b.Row.Style.Add("display", "none"); } b.AddCell(rowSiteMap.Title); } }
protected virtual void CROpportunityClass_RowInserted(PXCache sender, PXRowInsertedEventArgs e) { // init default list of opportunity stages CROpportunityProbability s = OpportunityProbabilities.Select(); if (s == null) { InitOpportunityProbabilities(); } // activate all stages for the first class int classesCount = OpportunityClass.Select().Count; if (classesCount == 1) { ActivateAllOpportunityClassProbabilities(); } }
private bool VerifyCAAttributes(int cAAttributeID) { if (CrossReferenceMapping.Select().RowCast <KCCrossReferenceMapping>().Any(item => cAAttributeID == item.CAAttributeID)) { return(true); } else { return(false); } }
public virtual IEnumerable Up(PXAdapter adapter) { FSCustomFieldAppointment fsCustomFieldAppointmentRow = (FSCustomFieldAppointment)CustomFieldAppointmentRecords.Cache.Current; PXResultset <FSCustomFieldAppointment> bqlResultSet = CustomFieldAppointmentRecords.Select(); if (bqlResultSet != null && bqlResultSet.Count > 1) { int currentCustomFieldAppointmentIndex = (int)fsCustomFieldAppointmentRow.Position; if (currentCustomFieldAppointmentIndex > 0) { FSCustomFieldAppointment fsCustomFieldAppointmentRow_Previous = (FSCustomFieldAppointment)bqlResultSet[currentCustomFieldAppointmentIndex - 1]; fsCustomFieldAppointmentRow.Position = fsCustomFieldAppointmentRow_Previous.Position; fsCustomFieldAppointmentRow_Previous.Position = currentCustomFieldAppointmentIndex; CustomFieldAppointmentRecords.Update(fsCustomFieldAppointmentRow); CustomFieldAppointmentRecords.Update(fsCustomFieldAppointmentRow_Previous); } } return(adapter.Get()); }
protected virtual IEnumerable translationHistoryRecords() { PXSelectBase <TranslationHistory> cmd; TranslationEnqFilter filter = Filter.Current as TranslationEnqFilter; this.TranslationHistoryRecords.Cache.AllowInsert = false; this.TranslationHistoryRecords.Cache.AllowDelete = false; this.TranslationHistoryRecords.Cache.AllowUpdate = false; TranslationHistoryRecords.Cache.Clear(); cmd = new PXSelectOrderBy <TranslationHistory, OrderBy <Desc <TranslationHistory.finPeriodID, Desc <TranslationHistory.translDefId, Asc <TranslationHistory.referenceNbr> > > > >(this); if (filter.TranslDefId != null) { cmd.WhereAnd <Where <TranslationHistory.translDefId, Equal <Current <TranslationEnqFilter.translDefId> > > >(); } if (filter.FinPeriodID != null) { cmd.WhereAnd <Where <TranslationHistory.finPeriodID, Equal <Current <TranslationEnqFilter.finPeriodID> > > >(); } if (filter.Released == false) { cmd.WhereAnd <Where <TranslationHistory.status, NotEqual <TranslationReleased> > >(); } if (filter.Unreleased == false) { cmd.WhereAnd <Where <TranslationHistory.status, NotEqual <TranslationUnReleased> > >(); } if (filter.Voided == false) { cmd.WhereAnd <Where <TranslationHistory.status, NotEqual <TranslationVoided> > >(); } foreach (PXResult <TranslationHistory> thist in cmd.Select()) { yield return(thist); } }
protected virtual byte[] CreateExportContents(IEnumerable <DocumentDetails> documents) { bool isRut = documents.First().Rutrot.RUTROTType == RUTROTTypes.RUT; List <RUTROTWorkType> availableWorkTypes = new List <RUTROTWorkType>(); foreach (RUTROTWorkType workType in PXSelectOrderBy <RUTROTWorkType, OrderBy <Asc <RUTROTWorkType.rUTROTType, Asc <RUTROTWorkType.position> > > > .Select(this)) { if (RUTROTHelper.IsUpToDateWorkType(workType, DateTime.Now)) { availableWorkTypes.Add(workType); } } var exporter = isRut ? new RUTExport(availableWorkTypes) : new ROTExport(availableWorkTypes); return(exporter.Export(documents)); }
public virtual void clearLogs() { if (LogMessage.AskExt() == WebDialogResult.Yes) { var logs = Logs.Select(); if (logs != null && logs.Count > 0) { foreach (var log in logs) { Logs.Delete(log); } Actions.PressSave(); } } }
private Dictionary <int, RUTROTWorkType> GetAvailableWorkTypes(PXGraph graph, DateTime?date) { if (date == null) { return(null); } Dictionary <int, RUTROTWorkType> availableWorkTypes = new Dictionary <int, RUTROTWorkType>(); foreach (RUTROTWorkType workType in PXSelectOrderBy <RUTROTWorkType, OrderBy <Asc <RUTROTWorkType.rUTROTType, Asc <RUTROTWorkType.position> > > > .Select(graph)) { if (RUTROTHelper.IsUpToDateWorkType(workType, date.Value)) { availableWorkTypes.Add(workType.WorkTypeID.Value, workType); } } return(availableWorkTypes); }
public virtual IEnumerable Reclassify(PXAdapter adapter) { var tran = TransView.Select().RowCast <GLTran>().LastOrDefault(); if (tran == null) { return(new GLTran[0]); } if (tran.Released == false) { throw new PXException(Messages.TheTransactionCannotBeReclassifiedBecauseItIsNotReleased); } ReclassifyTransactionsProcess.OpenForReclassification(new[] { tran }, PXBaseRedirectException.WindowMode.Same); return(adapter.Get()); }
protected virtual void EPCustomWeek_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { EPCustomWeek row = (EPCustomWeek)e.Row; if (row != null) { EPCustomWeek lastWeek = (EPCustomWeek)PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.weekID> > > .Select(this); if (lastWeek != null) { bool readOnly = lastWeek.WeekID > row.WeekID; PXUIFieldAttribute.SetReadOnly(cache, row, true); PXUIFieldAttribute.SetReadOnly <EPCustomWeek.endDate>(cache, row, readOnly); PXUIFieldAttribute.SetReadOnly <EPCustomWeek.isFullWeek>(cache, row, readOnly); PXUIFieldAttribute.SetReadOnly <EPCustomWeek.startDate>(cache, row, row.Year != null && row.StartDate != null && (row.StartDate.Value.AddDays(-6d).Year <= row.Year.Value && row.Year.Value <= row.StartDate.Value.AddDays(6d).Year)); } } }
protected virtual void EPGenerateWeeksDialog_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { EPGenerateWeeksDialog row = (EPGenerateWeeksDialog)e.Row; if (row == null) { return; } if (row.CutOffDayOne == EPGenerateWeeksDialog.CutOffDayListAttribute.FixedDayOfMonth) { PXUIFieldAttribute.SetEnabled <EPGenerateWeeksDialog.dayOne>(cache, row, true); PXUIFieldAttribute.SetRequired <EPGenerateWeeksDialog.dayOne>(cache, true); PXUIFieldAttribute.SetEnabled <EPGenerateWeeksDialog.cutOffDayTwo>(cache, row, true); PXDefaultAttribute.SetPersistingCheck <EPGenerateWeeksDialog.dayOne>(cache, row, PXPersistingCheck.NullOrBlank); } else { PXUIFieldAttribute.SetEnabled <EPGenerateWeeksDialog.cutOffDayTwo>(cache, row, false); PXUIFieldAttribute.SetEnabled <EPGenerateWeeksDialog.dayOne>(cache, row, false); row.DayOne = null; row.DayTwo = null; row.CutOffDayTwo = EPGenerateWeeksDialog.CutOffDayListAttribute.None; } if (row.CutOffDayTwo == EPGenerateWeeksDialog.CutOffDayListAttribute.FixedDayOfMonth) { PXUIFieldAttribute.SetEnabled <EPGenerateWeeksDialog.dayTwo>(cache, row, true); PXUIFieldAttribute.SetRequired <EPGenerateWeeksDialog.dayTwo>(cache, true); PXDefaultAttribute.SetPersistingCheck <EPGenerateWeeksDialog.dayTwo>(cache, row, PXPersistingCheck.NullOrBlank); } else { PXUIFieldAttribute.SetEnabled <EPGenerateWeeksDialog.dayTwo>(cache, row, false); row.DayTwo = null; } EPCustomWeek lastWeek = (EPCustomWeek)PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.number> > > .Select(this); if (lastWeek != null) { PXUIFieldAttribute.SetEnabled <EPGenerateWeeksDialog.fromDate>(cache, row, false); } }
protected virtual IEnumerable opportunityProbabilities() { List <string> activeProbabilities = new List <string>(); foreach (CROpportunityClassProbability probability in OpportunityClassActiveProbabilities.Select()) { if (probability.ClassID == OpportunityClass.Current.CROpportunityClassID) { activeProbabilities.Add(probability.StageID); } } foreach (CROpportunityProbability probability in PXSelectOrderBy <CROpportunityProbability, OrderBy <Asc <CROpportunityProbability.sortOrder, Asc <CROpportunityProbability.probability, Asc <CROpportunityProbability.stageCode> > > > > . Select(this)) { probability.IsActive = activeProbabilities.Contains(probability.StageCode); yield return(new PXResult <CROpportunityProbability>(probability)); } }
protected virtual void EPCustomWeek_RowDeleting(PXCache cache, PXRowDeletingEventArgs e) { EPCustomWeek row = (EPCustomWeek)e.Row; if (row == null) { return; } if (cache.GetStatus(row) != PXEntryStatus.Inserted && cache.GetStatus(row) != PXEntryStatus.InsertedDeleted) { if ((EPTimeCard)PXSelect <EPTimeCard> .Search <EPTimeCard.weekId>(this, row.WeekID) != null || (PMTimeActivity)PXSelect <PMTimeActivity> .Search <PMTimeActivity.weekID>(this, row.WeekID) != null) { throw new PXException(Messages.WeekInUse); } } EPCustomWeek lastWeek = (EPCustomWeek)PXSelectOrderBy <EPCustomWeek, OrderBy <Desc <EPCustomWeek.weekID> > > .Select(this); if (lastWeek != null && lastWeek.WeekID > row.WeekID) { throw new PXSetPropertyException(Messages.WeekNotLast, PXErrorLevel.RowWarning); } }
public virtual IEnumerable addWorkGroup(PXAdapter adapter) { EPCompanyTreeMaster current = Folders.Current; if (current == null) { current = Folders.Select(); } if (current != null) { int ParentID = (int)current.WorkGroupID; EPCompanyTreeMaster inserted = (EPCompanyTreeMaster)Caches[typeof(EPCompanyTreeMaster)].CreateInstance(); inserted.Description = PX.Objects.CR.Messages.New; inserted.ParentWGID = ParentID; inserted = Caches[typeof(EPCompanyTreeMaster)].Insert(inserted) as EPCompanyTreeMaster; if (inserted != null) { inserted.TempChildID = inserted.WorkGroupID; inserted.TempParentID = ParentID; EPCompanyTreeMaster previous = PXSelect <EPCompanyTreeMaster, Where <EPCompanyTreeMaster.parentWGID, Equal <Required <EPCompanyTreeMaster.parentWGID> > >, OrderBy <Desc <EPCompanyTreeMaster.sortOrder> > > .SelectSingleBound(this, null, ParentID); int sortOrder = (int)previous.SortOrder; sortOrder = sortOrder + 1; inserted.SortOrder = previous != null ? sortOrder : 1; Folders.Cache.ActiveRow = inserted; PXSelect <EPCompanyTreeMaster, Where <EPCompanyTreeMaster.parentWGID, Equal <Required <EPCompanyTreeMaster.parentWGID> > >, OrderBy <Desc <EPCompanyTreeMaster.sortOrder> > > .Clear(this); } } return(adapter.Get()); }
public ARDunningLetterProcess() { DunningLetterList.Cache.AllowDelete = false; DunningLetterList.Cache.AllowInsert = false; DunningLetterList.Cache.AllowUpdate = true; int prevDays = 0; foreach (ARDunningSetup xx in PXSelectOrderBy <ARDunningSetup, OrderBy <Asc <ARDunningSetup.dunningLetterLevel> > > .Select(this)) { this.DunningSetupList.Add(xx); if (xx.DueDays.HasValue) { D_DueDays.Add(xx.DueDays.Value - prevDays); prevDays = xx.DueDays.Value; D_MaxLevel++; } } DunningLetterList.SetProcessDelegate <DunningLetterMassProcess>(DunningLetterProc); PXUIFieldAttribute.SetEnabled(DunningLetterList.Cache, null, false); PXUIFieldAttribute.SetEnabled <ARDunningLetterList.selected>(DunningLetterList.Cache, null, true); DunningLetterList.SetSelected <ARDunningLetterList.selected>(); }
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); }
protected virtual IEnumerable workTypes() { return PXSelectOrderBy<RUTROTWorkType, OrderBy<Asc<RUTROTWorkType.rUTROTType, Asc<RUTROTWorkType.position>>>>.Select(this); }
protected virtual void AccountByYearFilter_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e) { EnqResult.Select(); }
public IEnumerable customFieldAppointmentRecords() { PXSelectOrderBy <FSCustomFieldAppointment, OrderBy <Asc <FSCustomFieldAppointment.position> > > .Clear(this); return(PXSelectOrderBy <FSCustomFieldAppointment, OrderBy <Asc <FSCustomFieldAppointment.position> > > .Select(this)); }
protected virtual void GLHistoryEnqFilter_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e) { EnqResult.Select(); }
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); }