Ejemplo n.º 1
0
 protected virtual int CalcOccurrences(DateTime startDate, DateTime endDate, int?organizationID)
 {
     return(_finPeriodRepository
            .PeriodsBetweenInclusive(startDate, endDate, organizationID)
            .Where((_, periodIndex) => periodIndex % _code.Frequency == 0)
            .Count());
 }
Ejemplo n.º 2
0
        /// <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(
            DateTime currentDate,
            DateTime dateToAge,
            IFinPeriodRepository finPeriodRepository,
            AgingDirection agingDirection,
            int numberOfBuckets,
            int organizationID)
        {
            if (finPeriodRepository == null)
            {
                throw new ArgumentNullException(nameof(finPeriodRepository));
            }
            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 = finPeriodRepository
                               .PeriodsBetweenInclusive(dateToAge, currentDate, organizationID)
                               .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);
        }