/// <summary> /// Returns the financial period for a given date. /// </summary> /// <exception cref="NullReferenceException"> /// Thrown if the provided date object is <c>null</c>. /// </exception> public static string GetPeriod(this IFinancialPeriodProvider financialPeriodProvider, DateTime?dateTime) { if (!dateTime.HasValue) { throw new NullReferenceException(nameof(dateTime)); } return(financialPeriodProvider.GetPeriod(dateTime.Value)); }
public static IEnumerable<string> GetPeriodAgingBucketDescriptions( IFinancialPeriodProvider financialPeriodProvider, DateTime currentDate, AgingDirection agingDirection, int numberOfBuckets) { if (financialPeriodProvider == null) throw new ArgumentNullException(nameof(financialPeriodProvider)); if (numberOfBuckets <= 0) throw new ArgumentOutOfRangeException(nameof(numberOfBuckets)); short periodStep = (short)(agingDirection == AgingDirection.Backwards ? -1 : 1); // Must not re-use any existing graphs due to possible query // caching of financial periods, which can impact localization // of their descriptions, see AC-84505. // - PXGraph graph = new PXGraph(); FinPeriod currentPeriod = financialPeriodProvider.GetFinPeriodByID( graph, financialPeriodProvider.GetPeriodFromDate(graph, currentDate)); yield return currentPeriod.Descr; --numberOfBuckets; while (numberOfBuckets > 1) { currentPeriod = financialPeriodProvider.GetFinPeriodByID( graph, financialPeriodProvider.PeriodPlusPeriod(graph, currentPeriod.FinPeriodID, periodStep)); yield return currentPeriod.Descr; --numberOfBuckets; } if (numberOfBuckets > 0) { yield return PXMessages.LocalizeFormatNoPrefix( agingDirection == AgingDirection.Backwards ? Messages.BeforeMonth : Messages.AfterMonth, currentPeriod.Descr); } }
/// <summary> /// Given the current date and the number of period-based aging buckets, /// returns the zero-based number of bucket that the specified test date /// falls into. /// </summary> /// <param name="numberOfBuckets"> /// The total number of period-based buckets, including the "Current" /// and "Over" bucket. For backwards aging, the "Current" bucket encompasses /// dates in the same (or later) financial period as the current date, and /// the "Over" bucket corresponds to dates that are at least (numberOfBuckets - 1) /// periods back in time from the current date. /// </param> public static int AgeByPeriods( PXGraph graph, DateTime currentDate, DateTime dateToAge, IFinancialPeriodProvider financialPeriodProvider, AgingDirection agingDirection, int numberOfBuckets) { if (graph == null) throw new ArgumentNullException(nameof(graph)); if (financialPeriodProvider == null) throw new ArgumentNullException(nameof(financialPeriodProvider)); if (numberOfBuckets <= 0) throw new ArgumentOutOfRangeException(nameof(numberOfBuckets)); if (agingDirection == AgingDirection.Forward) { agingDirection = AgingDirection.Backwards; Utilities.Swap(ref currentDate, ref dateToAge); } if (dateToAge > currentDate) return 0; int bucketNumber = financialPeriodProvider .PeriodsBetweenInclusive(graph, dateToAge, currentDate) .Count(); --bucketNumber; if (bucketNumber < 0) { // No financial periods found between the dates, // cannot proceed with aging. // - throw new PXException(GL.Messages.NoPeriodsDefined); } if (bucketNumber > numberOfBuckets - 1) { // Force into the last ("over") aging bucket. // - bucketNumber = numberOfBuckets - 1; } return bucketNumber; }
/// <param name="roundingFunction"> /// An optional parameter specifying a function that would be used to round /// the calculated transaction amounts. If <c>null</c>, the generator will use /// <see cref="PXDBCurrencyAttribute.BaseRound(PXGraph, decimal)"/> by default. /// </param> /// <param name="financialPeriodProvider"> /// An optional parameter specifying an object that would be used to manipulate /// financial periods, e.g. extract a start date or an end date for a given period ID. /// If <c>null</c>, the generator will use <see cref="FinancialPeriodProvider.Default"/>. /// </param> public TransactionsGenerator( PXGraph graph, DRDeferredCode code, IFinancialPeriodProvider financialPeriodProvider = null, Func <decimal, decimal> roundingFunction = null) { if (graph == null) { throw new ArgumentNullException(nameof(graph)); } if (code == null) { throw new ArgumentNullException(nameof(code)); } _graph = graph; _code = code; _roundingFunction = roundingFunction ?? (rawAmount => PXDBCurrencyAttribute.BaseRound(_graph, rawAmount)); _financialPeriodProvider = financialPeriodProvider ?? FinancialPeriodProvider.Default; }
public string GetBucketDescriptionForAgedReport( DateTime?reportDate, int?dayBucketBoundary0, int?dayBucketBoundary1, int?dayBucketBoundary2, int?dayBucketBoundary3, bool?isByFinancialPeriod, bool?isForwardAging, int?bucketIndex) { if (reportDate == null || dayBucketBoundary0 == null || dayBucketBoundary1 == null || dayBucketBoundary2 == null || dayBucketBoundary3 == null || bucketIndex == null) { return(null); } AgingDirection agingDirection = isForwardAging == true ? AgingDirection.Forward : AgingDirection.Backwards; if (isByFinancialPeriod == true) { try { IFinancialPeriodProvider periodProvider = FinancialPeriodProvider.Default; IEnumerable <string> bucketDescriptions = AgingEngine.GetPeriodAgingBucketDescriptions( FinancialPeriodProvider.Default, reportDate.Value, agingDirection, NUMBER_OF_AGING_BUCKETS); return(bucketDescriptions.ElementAtOrDefault(bucketIndex.Value)); } catch (PXFinPeriodException) { throw new PXFinPeriodException( isForwardAging == true ? AR.Messages.UnableToCalculateBucketNamesPeriodsAfterwardsNotDefined : AR.Messages.UnableToCalculateBucketNamesPeriodsPrecedingNotDefined); } } else { IEnumerable <string> bucketDescriptions = AgingEngine.GetDayAgingBucketDescriptions( agingDirection, new int[] { dayBucketBoundary0 ?? 0, dayBucketBoundary1 ?? 0, dayBucketBoundary2 ?? 0, dayBucketBoundary3 ?? 0 }, true); return(bucketDescriptions.ElementAtOrDefault(bucketIndex.Value)); } }
public Scheduler(PXGraph graph, IFinancialPeriodProvider financialPeriodProvider = null) { _graph = graph; _financialPeriodProvider = financialPeriodProvider ?? FinancialPeriodProvider.Default; }