public static string PeriodPlusPeriod(PXGraph graph, string FiscalPeriodID, int counter, int?BookID) { FABook book = PXSelect <FABook, Where <FABook.bookID, Equal <Required <FABook.bookID> > > > .Select(graph, BookID); IYearSetup setup; if (book.UpdateGL == true) { setup = (FinYearSetup)PXSelect <FinYearSetup> .Select(graph); } else { setup = (FABookYearSetup)PXSelect <FABookYearSetup, Where <FABookYearSetup.bookID, Equal <Required <FABookYearSetup.bookID> > > > .Select(graph, BookID); } IPeriodSetup periodsInYear; if (book.UpdateGL == true) { periodsInYear = (FinPeriodSetup)PXSelectGroupBy <FinPeriodSetup, Where <FinPeriodSetup.endDate, Greater <FinPeriodSetup.startDate> >, Aggregate <Max <FinPeriodSetup.periodNbr> > > .Select(graph); } else { periodsInYear = (FABookPeriodSetup)PXSelectGroupBy <FABookPeriodSetup, Where <FABookPeriodSetup.endDate, Greater <FABookPeriodSetup.startDate>, And <FABookPeriodSetup.bookID, Equal <Required <FABookPeriodSetup.bookID> > > >, Aggregate <Max <FABookPeriodSetup.periodNbr> > > .Select(graph, BookID); } if (setup != null && FiscalPeriodSetupCreator.IsFixedLengthPeriod(setup.FPType) && periodsInYear != null && periodsInYear.PeriodNbr != null) { return(OffsetPeriod(graph, FiscalPeriodID, counter, Convert.ToInt32(periodsInYear.PeriodNbr))); } else if (counter > 0) { PXResultset <FABookPeriod> res = PXSelect <FABookPeriod, Where <FABookPeriod.finPeriodID, Greater <Required <FABookPeriod.finPeriodID> >, And <FABookPeriod.startDate, NotEqual <FABookPeriod.endDate>, And <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> > > > >, OrderBy <Asc <FABookPeriod.finPeriodID> > > .SelectWindowed(graph, 0, counter, FiscalPeriodID, BookID); if (res.Count < counter) { throw new PXFABookPeriodException(); } return(((FABookPeriod)res[res.Count - 1]).FinPeriodID); } else if (counter < 0) { PXResultset <FABookPeriod> res = PXSelect <FABookPeriod, Where <FABookPeriod.finPeriodID, Less <Required <FABookPeriod.finPeriodID> >, And <FABookPeriod.startDate, NotEqual <FABookPeriod.endDate>, And <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> > > > >, OrderBy <Desc <FABookPeriod.finPeriodID> > > .SelectWindowed(graph, 0, -counter, FiscalPeriodID, BookID); if (res.Count < -counter) { throw new PXFABookPeriodException(); } return(((FABookPeriod)res[res.Count - 1]).FinPeriodID); } else { return(FiscalPeriodID); } }
public string PeriodPlusPeriodsCount(string finPeriodID, int counter, int?bookID, int?assetID) { FABookPeriodRepository.CheckNotNullOrEmptyStringContract(finPeriodID, nameof(finPeriodID)); FABookPeriodRepository.CheckNotNullIDContract(bookID, nameof(bookID)); FABookPeriodRepository.CheckNotNullIDContract(assetID, nameof(assetID)); IYearSetup setup = FABookPeriodRepositoryHelper.FindFABookYearSetup(bookID); IPeriodSetup periodsInYear = FABookPeriodRepositoryHelper.FindFABookPeriodSetup(bookID).LastOrDefault(); int organizationID = FABookPeriodRepositoryHelper.GetFABookPeriodOrganizationID(bookID, assetID); if (setup != null && FiscalPeriodSetupCreator.IsFixedLengthPeriod(setup.FPType) && periodsInYear != null && periodsInYear.PeriodNbr != null) { return(FinPeriodUtils.OffsetPeriod(finPeriodID, counter, Convert.ToInt32(periodsInYear.PeriodNbr))); } else if (counter > 0) { PXResultset <FABookPeriod> res = PXSelect < FABookPeriod, Where <FABookPeriod.finPeriodID, Greater <Required <FABookPeriod.finPeriodID> >, And <FABookPeriod.startDate, NotEqual <FABookPeriod.endDate>, And <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >, And <FABookPeriod.organizationID, Equal <Required <FABookPeriod.organizationID> > > > > >, OrderBy < Asc <FABookPeriod.finPeriodID> > > .SelectWindowed(Graph, 0, counter, finPeriodID, bookID, organizationID); if (res.Count < counter) { throw new PXFABookPeriodException(); } return(((FABookPeriod)res[res.Count - 1]).FinPeriodID); } else if (counter < 0) { PXResultset <FABookPeriod> res = PXSelect < FABookPeriod, Where <FABookPeriod.finPeriodID, Less <Required <FABookPeriod.finPeriodID> >, And <FABookPeriod.startDate, NotEqual <FABookPeriod.endDate>, And <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >, And <FABookPeriod.organizationID, Equal <Required <FABookPeriod.organizationID> > > > > >, OrderBy < Desc <FABookPeriod.finPeriodID> > > .SelectWindowed(Graph, 0, -counter, finPeriodID, bookID, organizationID); if (res.Count < -counter) { throw new PXFABookPeriodException(); } return(((FABookPeriod)res[res.Count - 1]).FinPeriodID); } else { return(finPeriodID); } }
public FinPeriod FindOffsetPeriod(string finPeriodID, int offset, int?organizationID) { FinYearSetup setup = PXSelect <FinYearSetup> .Select(Graph); //TODO: Need to refactor, duplicates the part of function FABookPeriodIDAttribute.GetBookPeriodsInYear FinPeriodSetup periodsInYear = PXSelectGroupBy <FinPeriodSetup, Where <FinPeriodSetup.endDate, Greater <FinPeriodSetup.startDate> >, Aggregate <Max <FinPeriodSetup.periodNbr> > > .Select(Graph); if (setup != null && FiscalPeriodSetupCreator.IsFixedLengthPeriod(setup.FPType) && periodsInYear != null && periodsInYear.PeriodNbr != null) { string offsetFinPeriodID = FinPeriodUtils.OffsetPeriod(finPeriodID, offset, Convert.ToInt32(periodsInYear.PeriodNbr)); return(FindByID(organizationID, offsetFinPeriodID)); } else if (offset > 0) { PXResultset <FinPeriod> res = PXSelect < FinPeriod, Where < FinPeriod.finPeriodID, Greater <Required <FinPeriod.finPeriodID> >, And <FinPeriod.startDate, NotEqual <FinPeriod.endDate>, And <FinPeriod.organizationID, Equal <Required <FinPeriod.organizationID> > > > >, OrderBy < Asc <FinPeriod.finPeriodID> > > .SelectWindowed(Graph, 0, offset, finPeriodID, organizationID); if (res.Count < offset) { return(null); } return((FinPeriod)res[res.Count - 1]); } else if (offset < 0) { PXResultset <FinPeriod> res = PXSelect < FinPeriod, Where < FinPeriod.finPeriodID, Less <Required <FinPeriod.finPeriodID> >, And <FinPeriod.startDate, NotEqual <FinPeriod.endDate>, And <FinPeriod.organizationID, Equal <Required <FinPeriod.organizationID> > > > >, OrderBy < Desc <FinPeriod.finPeriodID> > > .SelectWindowed(Graph, 0, -offset, finPeriodID, organizationID); if (res.Count < -offset) { return(null); } return((FinPeriod)res[res.Count - 1]); } else { return(FindByID(organizationID, finPeriodID)); } }