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)); } }
/// <summary> /// Attempts to extract integer values of the financial year and the number of the financial period inside the year /// from a Financial Period ID (<see cref="FinPeriod.FinPeriodID"/>). /// </summary> /// <param name="fiscalPeriodID">The ID of the period to extract parts from</param> /// <param name="year">Output: the financial year, to which the period belongs</param> /// <param name="periodNbr">Output: the number of the period in its financial year</param> /// <returns><c>true</c> upon success or <c>false</c> if failed to parse due to incorrect format of the input period ID</returns> public static bool TryParse(string fiscalPeriodID, out int year, out int periodNbr) { try { year = int.Parse(FinPeriodUtils.FiscalYear(fiscalPeriodID)); periodNbr = int.Parse(FinPeriodUtils.PeriodInYear(fiscalPeriodID)); } catch (FormatException) { year = -1; periodNbr = -1; return(false); } return(true); }