protected virtual void _(Events.FieldUpdated <FeaturesSet, FeaturesSet.centralizedPeriodsManagement> e) { if (e.Row == null) { return; } if ((bool?)e.OldValue != true && e.Row.CentralizedPeriodsManagement == true && EtalonOrganization != null) { foreach (PXResult <MasterFinPeriod, OrganizationFinPeriod> res in MasterFinPeriods.Select(EtalonOrganization.OrganizationID)) { MasterFinPeriod masterFinPeriod = res; OrganizationFinPeriod organizationFinPeriod = res; masterFinPeriod.DateLocked = organizationFinPeriod.DateLocked; masterFinPeriod.Status = organizationFinPeriod.Status; masterFinPeriod.APClosed = organizationFinPeriod.APClosed; masterFinPeriod.ARClosed = organizationFinPeriod.ARClosed; masterFinPeriod.INClosed = organizationFinPeriod.INClosed; masterFinPeriod.CAClosed = organizationFinPeriod.CAClosed; masterFinPeriod.FAClosed = organizationFinPeriod.FAClosed; MasterFinPeriods.Cache.Update(masterFinPeriod); } } }
protected virtual IEnumerable AccountByPeriod(PXAdapter adapter) { if (this.EnqResult.Current != null) { AccountHistoryByYearEnq graph = PXGraph.CreateInstance <AccountHistoryByYearEnq>(); AccountByYearFilter filter = PXCache <AccountByYearFilter> .CreateCopy(graph.Filter.Current); filter.OrgBAccountID = Filter.Current.OrgBAccountID; filter.OrganizationID = Filter.Current.OrganizationID; filter.BranchID = EnqResult.Current.BranchID; filter.LedgerID = Filter.Current.LedgerID; filter.AccountID = EnqResult.Current.AccountID; filter.SubCD = Filter.Current.SubCD; filter.FinPeriodID = EnqResult.Current.LastActivityPeriod; OrganizationFinPeriod fp = PXSelect < OrganizationFinPeriod, Where <OrganizationFinPeriod.finPeriodID, Equal <Required <OrganizationFinPeriod.finPeriodID> >, And <OrganizationFinPeriod.organizationID, Equal <Required <OrganizationFinPeriod.organizationID> > > > > .Select(this, filter.FinPeriodID, PXAccess.GetParentOrganizationID(filter.BranchID)); if (fp != null) { filter.FinYear = fp.FinYear; } filter.ShowCuryDetail = this.Filter.Current.ShowCuryDetail; graph.Filter.Update(filter); throw new PXRedirectRequiredException(graph, "Account By Period"); } return(adapter.Get()); }
protected virtual OrganizationFinYear GenerateNextOrganizationFinYear(OrganizationFinYear year) { string generatedYearNumber = $"{int.Parse(year.Year) + 1:0000}"; MasterFinYear masterFinYear; while ((masterFinYear = FinPeriodRepository.FindMasterFinYearByID(generatedYearNumber, clearQueryCache: true)) == null) { MasterCalendarGraph.Clear(); MasterCalendarGraph.GenerateCalendar( FinPeriod.organizationID.MasterValue, int.Parse(FinPeriodRepository.FindLastYear(FinPeriod.organizationID.MasterValue, clearQueryCache: true).Year), int.Parse(generatedYearNumber)); } short generatedFinPeriodsCount = (short)masterFinYear.FinPeriods; if (YearSetup.Current.HasAdjustmentPeriod == true) { generatedFinPeriodsCount--; } OrganizationFinPeriod lastNonAdjustmentOrgFinPeriod = this.FinPeriodRepository.FindLastNonAdjustmentOrganizationFinPeriodOfYear(year.OrganizationID, year.Year, clearQueryCache: true); int generatedMasterYearNumber = int.Parse(lastNonAdjustmentOrgFinPeriod.FinYear); List <MasterFinPeriod> masterFinPeriods; PXSelectBase <MasterFinPeriod> select = new PXSelectReadonly < MasterFinPeriod, Where <MasterFinPeriod.finPeriodID, Greater <Required <MasterFinPeriod.finPeriodID> >, And <MasterFinPeriod.startDate, NotEqual <MasterFinPeriod.endDate> > >, OrderBy < Asc <MasterFinPeriod.finPeriodID> > >(this); select.View.Clear(); while ((masterFinPeriods = select .SelectWindowed(0, generatedFinPeriodsCount, lastNonAdjustmentOrgFinPeriod.MasterFinPeriodID) .RowCast <MasterFinPeriod>() .ToList()).Count < generatedFinPeriodsCount) { generatedMasterYearNumber++; MasterCalendarGraph.Clear(); MasterCalendarGraph.GenerateCalendar( FinPeriod.organizationID.MasterValue, int.Parse(FinPeriodRepository.FindLastYear(FinPeriod.organizationID.MasterValue, clearQueryCache: true).Year), generatedMasterYearNumber); select.View.Clear(); } MasterFinPeriod startMasterFinPeriod = masterFinPeriods.First(); return(GenerateSingleOrganizationFinYear((int)year.OrganizationID, masterFinYear, startMasterFinPeriod)); }
private string GetProblemFields(Organization organization, OrganizationFinPeriod problemPeriod) { OrganizationFinPeriod currentFinPeriod = PXSelect < OrganizationFinPeriod, Where <OrganizationFinPeriod.organizationID, Equal <Required <OrganizationFinPeriod.organizationID> >, And <OrganizationFinPeriod.finPeriodID, Equal <Required <OrganizationFinPeriod.finPeriodID> > > > > .Select(this, organization.OrganizationID, problemPeriod.FinPeriodID); List <string> fieldList = new List <string>(); if (problemPeriod.DateLocked != currentFinPeriod.DateLocked) { fieldList.Add(nameof(problemPeriod.DateLocked)); } if (problemPeriod.Status != currentFinPeriod.Status) { fieldList.Add(nameof(problemPeriod.Status)); } if (problemPeriod.APClosed != currentFinPeriod.APClosed) { fieldList.Add(nameof(problemPeriod.APClosed)); } if (problemPeriod.ARClosed != currentFinPeriod.ARClosed) { fieldList.Add(nameof(problemPeriod.ARClosed)); } if (problemPeriod.INClosed != currentFinPeriod.INClosed) { fieldList.Add(nameof(problemPeriod.INClosed)); } if (problemPeriod.CAClosed != currentFinPeriod.CAClosed) { fieldList.Add(nameof(problemPeriod.CAClosed)); } if (problemPeriod.FAClosed != currentFinPeriod.FAClosed) { fieldList.Add(nameof(problemPeriod.FAClosed)); } return(String.Join(", ", fieldList.ToArray())); }
public virtual OrganizationFinPeriod GetNearestOpenOrganizationMappedFABookPeriodInSubledger <TClosedInSubledgerField>(int?bookID, int?sourceBranchID, string sourcefinPeriodID, int?targetBranchID) where TClosedInSubledgerField : IBqlField { if (!FABookPeriodRepositoryHelper.IsPostingFABook(bookID)) { return(null); } IFinPeriodUtils finPeriodUtils = Graph.GetService <IFinPeriodUtils>(); IFinPeriodRepository finPeriodRepository = Graph.GetService <IFinPeriodRepository>(); IFABookPeriodRepository faBookPeriodRepository = Graph.GetService <IFABookPeriodRepository>(); int?sourceOrganizationID = PXAccess.GetParentOrganizationID(sourceBranchID); int?targetOrganizationID = PXAccess.GetParentOrganizationID(targetBranchID); // Mapped book period - first way: // FABookPeriod of sourceBranchID -> master book Period -> FABookPeriod of targetBranchID // ProcessingResult <FABookPeriod> targetFABookPeriod = faBookPeriodRepository.FindMappedFABookPeriod( bookID, sourceOrganizationID, sourcefinPeriodID, targetOrganizationID); // Mapped book period - second way: // finPeriodID of sourceBranchID -> masterFinPeriod -> FinPeriodID of targetBranchID -> FABookPeriod of targetBranchID // if (targetFABookPeriod.Result == null) { ProcessingResult <FABookPeriod> targetFABookPeriodSecondWay = faBookPeriodRepository.FindMappedFABookPeriodUsingFinPeriod( bookID, sourceOrganizationID, sourcefinPeriodID, targetOrganizationID); targetFABookPeriodSecondWay.RaiseIfHasError(); targetFABookPeriod = targetFABookPeriodSecondWay; } OrganizationFinPeriod period = finPeriodUtils.GetNearestOpenOrganizationFinPeriodInSubledger <TClosedInSubledgerField>(targetFABookPeriod.ThisOrRaiseIfHasError().Result); return(period); }
protected virtual OrganizationFinPeriod GenerateAdjustmentOrganizationFinPeriod(int organizationID, OrganizationFinPeriod prevFinPeriod) { (string masterYearNumber, string masterPeriodNumber) = FinPeriodUtils.ParseFinPeriodID(prevFinPeriod.FinPeriodID); MasterFinYear masterFinYear = FinPeriodRepository.FindMasterFinYearByID(masterYearNumber, clearQueryCache: true); string adjustmentMasterFinPeriodID = $"{masterYearNumber:0000}{masterFinYear.FinPeriods:00}"; (string yearNumber, string periodNumber) = FinPeriodUtils.ParseFinPeriodID(prevFinPeriod.FinPeriodID); periodNumber = $"{int.Parse(periodNumber) + 1:00}"; OrganizationFinPeriod orgFinPeriod = new OrganizationFinPeriod { OrganizationID = organizationID, FinPeriodID = FinPeriodUtils.ComposeFinPeriodID(yearNumber, periodNumber), MasterFinPeriodID = adjustmentMasterFinPeriodID, FinYear = yearNumber, PeriodNbr = periodNumber, Custom = prevFinPeriod.Custom, DateLocked = prevFinPeriod.DateLocked, StartDate = prevFinPeriod.EndDate, EndDate = prevFinPeriod.EndDate, Status = prevFinPeriod.Status, ARClosed = prevFinPeriod.ARClosed, APClosed = prevFinPeriod.APClosed, FAClosed = prevFinPeriod.FAClosed, CAClosed = prevFinPeriod.CAClosed, INClosed = prevFinPeriod.INClosed, Descr = Messages.AdjustmentPeriod, }; MasterFinPeriod masterFinPeriod = FinPeriodRepository.FindMasterFinPeriodByID(adjustmentMasterFinPeriodID); PXDBLocalizableStringAttribute.CopyTranslations <MasterFinPeriod.descr, OrganizationFinPeriod.descr>(this, masterFinPeriod, orgFinPeriod); return(orgFinPeriod); }
/// <summary> /// TODO: Share function in <see cref="OrganizationMaint.CreateOrganizationCalendar"/> function /// </summary> /// <param name="organizationID"></param> /// <param name="masterFinPeriod"></param> /// <returns></returns> protected virtual OrganizationFinPeriod CopyOrganizationFinPeriodFromMaster( int organizationID, MasterFinPeriod masterFinPeriod, FinPeriod orgFinPeriodStatusSource, string yearNumber = null, string periodNumber = null) { bool isCentralizedManagement = PXAccess.FeatureInstalled <FeaturesSet.centralizedPeriodsManagement>(); string organizationFinPeriodID = FinPeriodUtils.ComposeFinPeriodID(yearNumber, periodNumber) ?? masterFinPeriod.FinPeriodID; OrganizationFinPeriod orgFinPeriod = new OrganizationFinPeriod { OrganizationID = organizationID, FinPeriodID = organizationFinPeriodID, MasterFinPeriodID = masterFinPeriod.FinPeriodID, FinYear = yearNumber ?? masterFinPeriod.FinYear, PeriodNbr = periodNumber ?? masterFinPeriod.PeriodNbr, Custom = masterFinPeriod.Custom, DateLocked = masterFinPeriod.DateLocked, StartDate = masterFinPeriod.StartDate, EndDate = masterFinPeriod.EndDate, Status = isCentralizedManagement ? masterFinPeriod.Status : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.Status : FinPeriod.status.Inactive, ARClosed = isCentralizedManagement ? masterFinPeriod.ARClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.ARClosed : false, APClosed = isCentralizedManagement ? masterFinPeriod.APClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.APClosed : false, FAClosed = isCentralizedManagement ? masterFinPeriod.FAClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.FAClosed : false, CAClosed = isCentralizedManagement ? masterFinPeriod.CAClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.CAClosed : false, INClosed = isCentralizedManagement ? masterFinPeriod.INClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.INClosed : false, Descr = masterFinPeriod.Descr, }; PXDBLocalizableStringAttribute.CopyTranslations <MasterFinPeriod.descr, OrganizationFinPeriod.descr>(this, masterFinPeriod, orgFinPeriod); return(orgFinPeriod); }
protected virtual IEnumerable internalResultRecords() { InventoryTranHistEnqFilter filter = Filter.Current; bool summaryByDay = filter.SummaryByDay ?? false; bool includeUnreleased = filter.IncludeUnreleased ?? false; var resultList = new List <PXResult <InventoryTranHistEnqResult, INTran, INTranSplit> >(); if (filter.InventoryID == null) { PXDelegateResult emptyResult = new PXDelegateResult(); emptyResult.IsResultFiltered = true; emptyResult.IsResultSorted = true; emptyResult.IsResultTruncated = true; return(emptyResult); //empty } PXSelectBase <INTranSplit> cmd = new PXSelectReadonly2 <INTranSplit, InnerJoin <INTran, On <INTranSplit.FK.Tran>, InnerJoin <INSubItem, On <INTranSplit.FK.SubItem>, InnerJoin <INSite, On <INTran.FK.Site> > > >, Where <INTranSplit.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >, And <Match <INSite, Current <AccessInfo.userName> > > >, OrderBy <Asc <INTranSplit.docType, Asc <INTranSplit.refNbr, Asc <INTranSplit.lineNbr, Asc <INTranSplit.splitLineNbr> > > > > >(this); PXSelectBase <INItemSiteHistByDay> cmdBegBalanceNew = new PXSelectReadonly2 <INItemSiteHistByDay, InnerJoin <INItemSiteHistDay, On <INItemSiteHistDay.inventoryID, Equal <INItemSiteHistByDay.inventoryID>, And <INItemSiteHistDay.siteID, Equal <INItemSiteHistByDay.siteID>, And <INItemSiteHistDay.subItemID, Equal <INItemSiteHistByDay.subItemID>, And <INItemSiteHistDay.locationID, Equal <INItemSiteHistByDay.locationID>, And <INItemSiteHistDay.sDate, Equal <INItemSiteHistByDay.lastActivityDate> > > > > >, InnerJoin <INSubItem, On <INSubItem.subItemID, Equal <INItemSiteHistByDay.subItemID> >, InnerJoin <INSite, On <INSite.siteID, Equal <INItemSiteHistByDay.siteID> > > > >, Where <INItemSiteHistByDay.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >, And <INItemSiteHistByDay.date, Equal <Required <INItemSiteHistByDay.date> >, And <Match <INSite, Current <AccessInfo.userName> > > > > >(this); if (!SubCDUtils.IsSubCDEmpty(filter.SubItemCD) && PXAccess.FeatureInstalled <FeaturesSet.subItem>()) { cmd.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >(); cmdBegBalanceNew.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >(); } if (filter.SiteID != null && PXAccess.FeatureInstalled <FeaturesSet.warehouse>()) { cmd.WhereAnd <Where <INTranSplit.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >(); cmdBegBalanceNew.WhereAnd <Where <INItemSiteHistByDay.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >(); } if ((filter.LocationID ?? -1) != -1 && PXAccess.FeatureInstalled <FeaturesSet.warehouseLocation>()) // there are cases when filter.LocationID = -1 { cmd.WhereAnd <Where <INTranSplit.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >(); cmdBegBalanceNew.WhereAnd <Where <INItemSiteHistByDay.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >(); } if ((filter.LotSerialNbr ?? "") != "" && PXAccess.FeatureInstalled <FeaturesSet.lotSerialTracking>()) { cmd.WhereAnd <Where <INTranSplit.lotSerialNbr, Like <Current <InventoryTranHistEnqFilter.lotSerialNbrWildcard> > > >(); } if (!includeUnreleased) { cmd.WhereAnd <Where <INTranSplit.released, Equal <True> > >(); } decimal cumulativeQty = 0m; if (filter.StartDate != null) { foreach (PXResult <INItemSiteHistByDay, INItemSiteHistDay> res in cmdBegBalanceNew.Select(filter.StartDate)) { INItemSiteHistByDay byday = res; INItemSiteHistDay hist = res; cumulativeQty += ((byday.LastActivityDate != null && byday.Date != null && byday.Date.Value.Date == byday.LastActivityDate.Value.Date) ? hist.BegQty : hist.EndQty) ?? 0m; } if (includeUnreleased) { INSite site = INSite.PK.Find(this, filter.SiteID); int calendarOrganizationID = PXAccess.GetParentOrganizationID(site?.BranchID) ?? FinPeriod.organizationID.MasterValue; string TranPeriodID; DateTime?PeriodStartDate; try { TranPeriodID = FinPeriodRepository.GetPeriodIDFromDate(filter.StartDate, calendarOrganizationID); PeriodStartDate = FinPeriodRepository.PeriodStartDate(TranPeriodID, calendarOrganizationID); } catch (PXFinPeriodException) { TranPeriodID = null; PeriodStartDate = filter.StartDate; } PXSelectBase <OrganizationFinPeriod> periodCmd = new PXSelectGroupBy <OrganizationFinPeriod, Where <OrganizationFinPeriod.finPeriodID, LessEqual <Required <OrganizationFinPeriod.finPeriodID> >, And <OrganizationFinPeriod.iNClosed, Equal <False>, Or <OrganizationFinPeriod.finPeriodID, Equal <Required <OrganizationFinPeriod.finPeriodID> > > > >, Aggregate <GroupBy <OrganizationFinPeriod.finPeriodID> >, OrderBy <Asc <OrganizationFinPeriod.finPeriodID> > >(this); List <object> periodCmdParams = new List <object>() { TranPeriodID, TranPeriodID }; if (calendarOrganizationID != FinPeriod.organizationID.MasterValue) { periodCmd.WhereAnd <Where <OrganizationFinPeriod.organizationID, Equal <Required <OrganizationFinPeriod.organizationID> > > >(); periodCmdParams.Add(calendarOrganizationID); } OrganizationFinPeriod firstOpenOrCurrentClosedPeriod = periodCmd.SelectWindowed(0, 1, periodCmdParams.ToArray()); if (firstOpenOrCurrentClosedPeriod != null) { TranPeriodID = firstOpenOrCurrentClosedPeriod.FinPeriodID; PeriodStartDate = FinPeriodRepository.PeriodStartDate(firstOpenOrCurrentClosedPeriod.FinPeriodID, calendarOrganizationID); PXView v2 = new PXView(this, true, cmd.View.BqlSelect .WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Required <INTranSplit.tranDate> > > >() .WhereAnd <Where <INTranSplit.tranDate, Less <Required <INTranSplit.tranDate> > > >() .WhereAnd <Where <INTranSplit.released, Equal <False> > >() .AggregateNew <Aggregate < GroupBy <INTranSplit.inventoryID, GroupBy <INTranSplit.invtMult, Sum <INTranSplit.baseQty> > > > >()); int splitStartRow = 0; int splitTotalRows = 0; foreach (PXResult <INTranSplit> res in v2.Select(new object[0], new object[] { PeriodStartDate, filter.StartDate.Value }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref splitStartRow, 0, ref splitTotalRows)) { INTranSplit tsRec = res; cumulativeQty += (tsRec.InvtMult * tsRec.BaseQty) ?? 0m; } } } } if (filter.StartDate != null) { cmd.WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Current <InventoryTranHistEnqFilter.startDate> > > >(); } if (filter.EndDate != null) { cmd.WhereAnd <Where <INTranSplit.tranDate, LessEqual <Current <InventoryTranHistEnqFilter.endDate> > > >(); } AlterSortsAndFilters(out string[] newSortColumns, out bool[] newDescendings, out bool sortsChanged, out PXFilterRow[] newFilters, out bool filtersChanged); //if user clicks last, sorts will be inverted //as it is not possible to calculate beginning balance from the end //we will select without top from the start and then apply reverse order and select top n records //for next page we will ommit startrow to set beginning balance correctly //top (n, m) will be set in the outer search results since we do not reset PXView.StartRow to 0 //Also, user can set a filter or sort by a column from result DAC (sortsChanged = true, filtersChanged = true) and need to get full result set. int startRow = 0; bool allowSelectWithTop = !sortsChanged && !filtersChanged && !PXView.ReverseOrder; int maximumRows = allowSelectWithTop ? PXView.StartRow + PXView.MaximumRows : 0; int totalRows = 0; PXView selectView = !summaryByDay ? cmd.View : new PXView(this, true, cmd.View.BqlSelect .AggregateNew <Aggregate <GroupBy <INTranSplit.tranDate, Sum <INTranSplit.qtyIn, Sum <INTranSplit.qtyOut> > > > >()); List <object> intermediateResult = selectView.Select(PXView.Currents, new object[] { filter.StartDate }, new string[newSortColumns.Length], newSortColumns, newDescendings, newFilters, ref startRow, maximumRows, ref totalRows); int gridLineNbr = 0; foreach (PXResult <INTranSplit, INTran, INSubItem> it in intermediateResult) { INTranSplit ts_rec = (INTranSplit)it; INTran t_rec = (INTran)it; if (summaryByDay) { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; item.QtyIn = ts_rec.QtyIn; item.QtyOut = ts_rec.QtyOut; item.EndQty = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut; item.GridLineNbr = ++gridLineNbr; resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran, INTranSplit>(item, null, null)); cumulativeQty += (ts_rec.QtyIn - ts_rec.QtyOut) ?? 0m; } else { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; item.QtyIn = ts_rec.QtyIn; item.QtyOut = ts_rec.QtyOut; item.EndQty = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut; item.DocType = ts_rec.DocType; item.RefNbr = ts_rec.RefNbr; item.LineNbr = ts_rec.LineNbr; item.SplitLineNbr = ts_rec.SplitLineNbr; item.GridLineNbr = ++gridLineNbr; decimal?unitcost; if (filter.ShowAdjUnitCost ?? false) { unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? (ts_rec.TotalCost + ts_rec.AdditionalCost) / ts_rec.TotalQty : 0m; } else { unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? ts_rec.TotalCost / ts_rec.TotalQty : 0m; } item.UnitCost = unitcost; resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran, INTranSplit>(item, t_rec, ts_rec)); cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } PXDelegateResult delegateResult = new PXDelegateResult(); delegateResult.IsResultFiltered = !filtersChanged; delegateResult.IsResultSorted = !sortsChanged; delegateResult.IsResultTruncated = totalRows > resultList.Count; if (!PXView.ReverseOrder) { delegateResult.AddRange(resultList); } else { var sortedList = PXView.Sort(resultList); delegateResult.AddRange(sortedList.Cast <PXResult <InventoryTranHistEnqResult, INTran, INTranSplit> >()); delegateResult.IsResultSorted = true; } return(delegateResult); }
protected virtual IEnumerable internalResultRecords() { InventoryTranHistEnqFilter filter = Filter.Current; bool summaryByDay = filter.SummaryByDay ?? false; bool includeUnreleased = filter.IncludeUnreleased ?? false; PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.inventoryID>(ResultRecords.Cache, null, false); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.finPerNbr>(ResultRecords.Cache, null, false); //??? PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.tranPerNbr>(ResultRecords.Cache, null, false); //??? PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.tranType>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.docRefNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.subItemID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.siteID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.locationID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranHistEnqResult.lotSerialNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible(Tran.Cache, null, !summaryByDay); var resultList = new List <PXResult <InventoryTranHistEnqResult, INTran> >(); if (filter.InventoryID == null) { return(resultList); //empty } PXSelectBase <INTranSplit> cmd = new PXSelectReadonly2 <INTranSplit, InnerJoin <INTran, On <INTran.docType, Equal <INTranSplit.docType>, And <INTran.refNbr, Equal <INTranSplit.refNbr>, And <INTran.lineNbr, Equal <INTranSplit.lineNbr> > > >, InnerJoin <INSubItem, On <INSubItem.subItemID, Equal <INTranSplit.subItemID> >, InnerJoin <INSite, On <INSite.siteID, Equal <INTran.siteID> > > > >, Where <INTranSplit.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >, And <Match <INSite, Current <AccessInfo.userName> > > >, OrderBy <Asc <INTranSplit.docType, Asc <INTranSplit.refNbr, Asc <INTranSplit.lineNbr, Asc <INTranSplit.splitLineNbr> > > > > >(this); PXSelectBase <INItemSiteHistByPeriod> cmdBegBalance = new PXSelectReadonly2 <INItemSiteHistByPeriod, InnerJoin <INItemSiteHist, On <INItemSiteHist.inventoryID, Equal <INItemSiteHistByPeriod.inventoryID>, And <INItemSiteHist.siteID, Equal <INItemSiteHistByPeriod.siteID>, And <INItemSiteHist.subItemID, Equal <INItemSiteHistByPeriod.subItemID>, And <INItemSiteHist.locationID, Equal <INItemSiteHistByPeriod.locationID>, And <INItemSiteHist.finPeriodID, Equal <INItemSiteHistByPeriod.lastActivityPeriod> > > > > >, InnerJoin <INSubItem, On <INSubItem.subItemID, Equal <INItemSiteHistByPeriod.subItemID> >, InnerJoin <INSite, On <INSite.siteID, Equal <INItemSiteHistByPeriod.siteID> > > > >, Where <INItemSiteHistByPeriod.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >, And <INItemSiteHistByPeriod.finPeriodID, Equal <Required <INItemSiteHistByPeriod.finPeriodID> >, And <Match <INSite, Current <AccessInfo.userName> > > > > >(this); if (!SubCDUtils.IsSubCDEmpty(filter.SubItemCD) && PXAccess.FeatureInstalled <FeaturesSet.subItem>()) { cmdBegBalance.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >(); cmd.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >(); } if (filter.SiteID != null && PXAccess.FeatureInstalled <FeaturesSet.warehouse>()) { cmdBegBalance.WhereAnd <Where <INItemSiteHistByPeriod.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >(); cmd.WhereAnd <Where <INTranSplit.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >(); } if ((filter.LocationID ?? -1) != -1 && PXAccess.FeatureInstalled <FeaturesSet.warehouseLocation>()) // there are cases when filter.LocationID = -1 { cmdBegBalance.WhereAnd <Where <INItemSiteHistByPeriod.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >(); cmd.WhereAnd <Where <INTranSplit.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >(); } if ((filter.LotSerialNbr ?? "") != "" && PXAccess.FeatureInstalled <FeaturesSet.lotSerialTracking>()) { cmd.WhereAnd <Where <INTranSplit.lotSerialNbr, Like <Current <InventoryTranHistEnqFilter.lotSerialNbrWildcard> > > >(); } if (!includeUnreleased) { cmd.WhereAnd <Where <INTranSplit.released, Equal <True> > >(); } decimal cumulativeQty = 0m; string TranPeriodID; DateTime?PeriodStartDate; bool AnyPeriod = false; INSite site = PXSelect <INSite, Where <INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(this, filter.SiteID); int calendarOrganizationID = PXAccess.GetParentOrganizationID(site?.BranchID) ?? FinPeriod.organizationID.MasterValue; try { TranPeriodID = FinPeriodRepository.GetPeriodIDFromDate(filter.StartDate, calendarOrganizationID); PeriodStartDate = FinPeriodRepository.PeriodStartDate(TranPeriodID, calendarOrganizationID); } catch (PXFinPeriodException) { TranPeriodID = null; PeriodStartDate = filter.StartDate; } int startRow = 0; int totalRows = 0; int maximumRows = 0; if (includeUnreleased) { PXSelectBase <OrganizationFinPeriod> periodCmd = new PXSelectGroupBy <OrganizationFinPeriod, Where <OrganizationFinPeriod.finPeriodID, LessEqual <Required <OrganizationFinPeriod.finPeriodID> >, And <OrganizationFinPeriod.iNClosed, Equal <False>, Or <OrganizationFinPeriod.finPeriodID, Equal <Required <OrganizationFinPeriod.finPeriodID> > > > >, Aggregate <GroupBy <OrganizationFinPeriod.finPeriodID> >, OrderBy <Asc <OrganizationFinPeriod.finPeriodID> > >(this); List <object> periodCmdParams = new List <object>() { TranPeriodID, TranPeriodID }; if (calendarOrganizationID != FinPeriod.organizationID.MasterValue) { periodCmd.WhereAnd <Where <OrganizationFinPeriod.organizationID, Equal <Required <OrganizationFinPeriod.organizationID> > > >(); periodCmdParams.Add(calendarOrganizationID); } OrganizationFinPeriod firstOpenOrCurrentClosedPeriod = periodCmd.SelectWindowed(0, 1, periodCmdParams.ToArray()); if (firstOpenOrCurrentClosedPeriod != null) { TranPeriodID = firstOpenOrCurrentClosedPeriod.FinPeriodID; PeriodStartDate = FinPeriodRepository.PeriodStartDate(firstOpenOrCurrentClosedPeriod.FinPeriodID, calendarOrganizationID); } foreach (PXResult <INItemSiteHistByPeriod, INItemSiteHist> res in cmdBegBalance.Select(TranPeriodID)) { INItemSiteHistByPeriod byperiod = res; INItemSiteHist hist = res; cumulativeQty += string.Equals(byperiod.FinPeriodID, byperiod.LastActivityPeriod) ? (decimal)hist.TranBegQty : (decimal)hist.TranYtdQty; AnyPeriod = true; } if (AnyPeriod) { //if StartDate is not on the Period border, make additional select with grouping if (PeriodStartDate != filter.StartDate) { PXView v2 = new PXView(this, true, cmd.View.BqlSelect .WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Required <INTranSplit.tranDate> > > >() .WhereAnd <Where <INTranSplit.tranDate, Less <Required <INTranSplit.tranDate> > > >() .AggregateNew <Aggregate <GroupBy <INTranSplit.inventoryID, GroupBy <INTranSplit.invtMult, Sum <INTranSplit.baseQty> > > > >()); foreach (PXResult <INTranSplit> res in v2.Select(new object[0], new object[] { PeriodStartDate, filter.StartDate }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref startRow, 0, ref totalRows)) { INTranSplit ts_rec = res; cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } else { PXView v2 = new PXView(this, true, cmd.View.BqlSelect .WhereAnd <Where <INTranSplit.tranDate, Less <Required <INTranSplit.tranDate> > > >() .AggregateNew <Aggregate <GroupBy <INTranSplit.inventoryID, GroupBy <INTranSplit.invtMult, Sum <INTranSplit.baseQty> > > > >()); foreach (PXResult <INTranSplit> res in v2.Select(new object[0], new object[] { filter.StartDate }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref startRow, 0, ref totalRows)) { INTranSplit ts_rec = res; cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } else { foreach (PXResult <INItemSiteHistByPeriod, INItemSiteHist> res in cmdBegBalance.Select(TranPeriodID)) { INItemSiteHistByPeriod byperiod = res; INItemSiteHist hist = res; cumulativeQty += string.Equals(byperiod.FinPeriodID, byperiod.LastActivityPeriod) ? (decimal)hist.TranBegQty : (decimal)hist.TranYtdQty; AnyPeriod = true; } if (AnyPeriod) { //if StartDate is not on the Period border, make additional select with grouping if (PeriodStartDate != filter.StartDate) { PXView v2 = new PXView(this, true, cmd.View.BqlSelect .WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Required <INTranSplit.tranDate> > > >() .WhereAnd <Where <INTranSplit.tranDate, Less <Required <INTranSplit.tranDate> > > >() .AggregateNew <Aggregate <GroupBy <INTranSplit.inventoryID, GroupBy <INTranSplit.invtMult, Sum <INTranSplit.baseQty> > > > >()); foreach (PXResult <INTranSplit> res in v2.Select(new object[0], new object[] { PeriodStartDate, filter.StartDate }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref startRow, 0, ref totalRows)) { INTranSplit ts_rec = res; cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } } if (filter.StartDate != null) { cmd.WhereAnd <Where <INTranSplit.tranDate, GreaterEqual <Current <InventoryTranHistEnqFilter.startDate> > > >(); } if (filter.EndDate != null) { cmd.WhereAnd <Where <INTranSplit.tranDate, LessEqual <Current <InventoryTranHistEnqFilter.endDate> > > >(); } string[] newSortColumns; bool[] newDescendings; AlterSorts(out newSortColumns, out newDescendings); PXFilterRow[] newFilters = AlterFilters(); //if user clicks last, sorts will be inverted //as it is not possible to calculate beginning balance from the end //we will select without top from the start and then apply reverse order and select top n records //for next page we will ommit startrow to set beginning balance correctly //top (n, m) will be set in the outer search results since we do not reset PXView.StartRow to 0 startRow = 0; maximumRows = !PXView.ReverseOrder ? PXView.StartRow + PXView.MaximumRows : 0; totalRows = 0; PXView selectView = !summaryByDay ? cmd.View : new PXView(this, true, cmd.View.BqlSelect.AggregateNew <Aggregate <GroupBy <INTranSplit.tranDate, Sum <INTranSplit.qtyIn, Sum <INTranSplit.qtyOut> > > > >()); List <object> intermediateResult = selectView.Select(PXView.Currents, new object[] { filter.StartDate }, new string[newSortColumns.Length], newSortColumns, PXView.Descendings, newFilters, ref startRow, maximumRows, ref totalRows); int gridLineNbr = 0; foreach (PXResult <INTranSplit, INTran, INSubItem> it in intermediateResult) { INTranSplit ts_rec = (INTranSplit)it; INTran t_rec = (INTran)it; if (ts_rec.TranDate < filter.StartDate) { cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } else { if (summaryByDay) { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; item.QtyIn = ts_rec.QtyIn; item.QtyOut = ts_rec.QtyOut; item.EndQty = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut; item.GridLineNbr = ++gridLineNbr; resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran>(item, null)); cumulativeQty += (ts_rec.QtyIn - ts_rec.QtyOut) ?? 0m; } else { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; item.QtyIn = ts_rec.QtyIn; item.QtyOut = ts_rec.QtyOut; item.EndQty = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut; item.InventoryID = ts_rec.InventoryID; item.TranType = ts_rec.TranType; item.DocType = ts_rec.DocType; item.DocRefNbr = ts_rec.RefNbr; item.SubItemID = ts_rec.SubItemID; item.SiteID = ts_rec.SiteID; item.LocationID = ts_rec.LocationID; item.LotSerialNbr = ts_rec.LotSerialNbr; item.FinPerNbr = t_rec.FinPeriodID; item.TranPerNbr = t_rec.TranPeriodID; item.Released = t_rec.Released; item.GridLineNbr = ++gridLineNbr; decimal?unitcost; if (filter.ShowAdjUnitCost ?? false) { unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? (ts_rec.TotalCost + ts_rec.AdditionalCost) / ts_rec.TotalQty : 0m; } else { unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? ts_rec.TotalCost / ts_rec.TotalQty : 0m; } item.UnitCost = unitcost; resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran>(item, t_rec)); cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } if (!PXView.ReverseOrder) { return(resultList); } return(PXView.Sort(resultList)); }
protected virtual void _(Events.FieldUpdating <FeaturesSet.centralizedPeriodsManagement> e) { e.NewValue = PXBoolAttribute.ConvertValue(e.NewValue); FeaturesSet row = (FeaturesSet)e.Row; if (row == null) { return; } int messageCount = 0; bool isError = false; if (row.CentralizedPeriodsManagement != null && row.CentralizedPeriodsManagement != (bool)e.NewValue && (bool)e.NewValue == true) { foreach (Organization organization in PXSelect <Organization> .Select(this)) { foreach (MasterFinPeriod problemPeriod in PXSelectJoin < MasterFinPeriod, LeftJoin <OrganizationFinPeriod, On <MasterFinPeriod.finPeriodID, Equal <OrganizationFinPeriod.masterFinPeriodID>, And <OrganizationFinPeriod.organizationID, Equal <Required <OrganizationFinPeriod.organizationID> > > > >, Where <OrganizationFinPeriod.finPeriodID, IsNull> > .Select(this, organization.OrganizationID)) { isError = true; if (messageCount <= MAX_FINPERIOD_DISCREPANCY_MESSAGE_COUNT) { PXTrace.WriteError(GL.Messages.DiscrepancyPeriod, organization.OrganizationCD, problemPeriod.FinPeriodID); messageCount++; } else { break; } } } if (isError) { e.Cancel = true; throw new PXSetPropertyException(GL.Messages.DiscrepancyPeriodError); } Organization etalonOrganization = PXSelect <Organization> .Select(this).First(); if (etalonOrganization != null) { foreach (Organization organization in PXSelect <Organization> .Select(this)) { if (organization.OrganizationID == etalonOrganization.OrganizationID) { continue; } foreach (OrganizationFinPeriod problemPeriod in PXSelectJoin < OrganizationFinPeriod, LeftJoin <OrganizationFinPeriodStatus, On <OrganizationFinPeriodStatus.organizationID, Equal <Required <OrganizationFinPeriodStatus.organizationID> >, And <OrganizationFinPeriod.finPeriodID, Equal <OrganizationFinPeriodStatus.finPeriodID>, And <OrganizationFinPeriod.dateLocked, Equal <OrganizationFinPeriodStatus.dateLocked>, And <OrganizationFinPeriod.status, Equal <OrganizationFinPeriodStatus.status>, And <OrganizationFinPeriod.aPClosed, Equal <OrganizationFinPeriodStatus.aPClosed>, And <OrganizationFinPeriod.aRClosed, Equal <OrganizationFinPeriodStatus.aRClosed>, And <OrganizationFinPeriod.iNClosed, Equal <OrganizationFinPeriodStatus.iNClosed>, And <OrganizationFinPeriod.cAClosed, Equal <OrganizationFinPeriodStatus.cAClosed>, And <OrganizationFinPeriod.fAClosed, Equal <OrganizationFinPeriodStatus.fAClosed> > > > > > > > > > >, Where <OrganizationFinPeriodStatus.finPeriodID, IsNull, And <OrganizationFinPeriod.organizationID, Equal <Required <OrganizationFinPeriod.organizationID> > > > > .Select(this, organization.OrganizationID, etalonOrganization.OrganizationID)) { isError = true; if (messageCount <= MAX_FINPERIOD_DISCREPANCY_MESSAGE_COUNT) { string problemFields = GetProblemFields(organization, problemPeriod); PXTrace.WriteError(GL.Messages.DiscrepancyField, etalonOrganization.OrganizationCD, organization.OrganizationCD, problemFields, problemPeriod.FinPeriodID); messageCount++; } else { break; } } } if (isError) { e.Cancel = true; throw new PXSetPropertyException(GL.Messages.DiscrepancyFieldError); } } foreach (PXResult <MasterFinPeriod, OrganizationFinPeriod> res in MasterFinPeriods.Select(etalonOrganization.OrganizationID)) { MasterFinPeriod masterFinPeriod = res; OrganizationFinPeriod organizationFinPeriod = res; masterFinPeriod.DateLocked = organizationFinPeriod.DateLocked; masterFinPeriod.Status = organizationFinPeriod.Status; masterFinPeriod.APClosed = organizationFinPeriod.APClosed; masterFinPeriod.ARClosed = organizationFinPeriod.ARClosed; masterFinPeriod.INClosed = organizationFinPeriod.INClosed; masterFinPeriod.CAClosed = organizationFinPeriod.CAClosed; masterFinPeriod.FAClosed = organizationFinPeriod.FAClosed; this.MasterFinPeriods.Cache.Update(masterFinPeriod); } } }
protected virtual OrganizationFinYear GenerateSingleOrganizationFinYear(int organizationID, MasterFinYear startMasterYear, MasterFinPeriod startMasterFinPeriod) { if (startMasterYear == null) { throw new ArgumentNullException(nameof(startMasterYear)); } if (startMasterFinPeriod == null) { throw new ArgumentNullException(nameof(startMasterFinPeriod)); } OrganizationFinYear newOrganizationFinYear = (OrganizationFinYear)this.Caches <OrganizationFinYear>().Insert( new OrganizationFinYear { OrganizationID = organizationID, Year = startMasterYear.Year, FinPeriods = startMasterYear.FinPeriods, StartMasterFinPeriodID = startMasterFinPeriod.FinPeriodID, StartDate = startMasterFinPeriod.StartDate, }); short periodNumber = 1; MasterFinPeriod sourceMasterFinPeriod = startMasterFinPeriod; int periodsCountForCopy = (int)newOrganizationFinYear.FinPeriods; if (YearSetup.Current.HasAdjustmentPeriod == true) { periodsCountForCopy--; } OrganizationFinPeriod newOrganizationFinPeriod = null; FinPeriod firstOrgFinPeriod = FinPeriodRepository.FindFirstPeriod(organizationID, clearQueryCache: true); while (periodNumber <= periodsCountForCopy) { newOrganizationFinPeriod = (OrganizationFinPeriod)this.Caches <OrganizationFinPeriod>().Insert( CopyOrganizationFinPeriodFromMaster( organizationID, sourceMasterFinPeriod, firstOrgFinPeriod != null && Convert.ToInt32(firstOrgFinPeriod.FinYear) > Convert.ToInt32(newOrganizationFinYear.Year) ? firstOrgFinPeriod : null, newOrganizationFinYear.Year, $"{periodNumber:00}")); if (periodNumber < periodsCountForCopy) // no need to search for the next master period if last organization period is generated { string sourceMasterFinPeriodID = sourceMasterFinPeriod.FinPeriodID; while ((sourceMasterFinPeriod = FinPeriodRepository.FindNextNonAdjustmentMasterFinPeriod(sourceMasterFinPeriodID, clearQueryCache: true)) == null) { MasterCalendarGraph.Clear(); MasterCalendarGraph.GenerateNextMasterFinYear(); } } periodNumber++; } newOrganizationFinYear.EndDate = newOrganizationFinPeriod.EndDate; if (YearSetup.Current.HasAdjustmentPeriod == true) { this.Caches <OrganizationFinPeriod>().Insert(GenerateAdjustmentOrganizationFinPeriod(organizationID, newOrganizationFinPeriod)); } return(newOrganizationFinYear); }