示例#1
0
        private void AdjustPeriodsForUnderPayment(int variationPointerIndex,
                                                  decimal latestPeriodAmount,
                                                  IExistingProfilePeriod[] orderedExistingProfilePeriods,
                                                  IProfilePeriod[] orderRefreshProfilePeriods)
        {
            decimal amountAlreadyPaid            = orderedExistingProfilePeriods.Take(variationPointerIndex).Sum(_ => _.GetProfileValue());
            decimal amountThatShouldHaveBeenPaid = latestPeriodAmount * variationPointerIndex;

            decimal amountUnderPaid = Math.Abs(amountAlreadyPaid - amountThatShouldHaveBeenPaid);

            IProfilePeriod periodToAdjust = orderRefreshProfilePeriods[variationPointerIndex];

            periodToAdjust.SetProfiledValue(periodToAdjust.GetProfileValue() + amountUnderPaid);
        }
示例#2
0
        private bool AdjustingPeriodsForOverPaymentLeavesRemainder(int variationPointerIndex,
                                                                   decimal latestPeriodAmount,
                                                                   IExistingProfilePeriod[] orderedSnapShotProfilePeriods,
                                                                   IProfilePeriod[] orderRefreshProfilePeriods,
                                                                   out decimal remainingOverPayment)
        {
            decimal amountAlreadyPaid            = orderedSnapShotProfilePeriods.Take(variationPointerIndex).Sum(_ => _.GetProfileValue());
            decimal amountThatShouldHaveBeenPaid = latestPeriodAmount * (variationPointerIndex);

            remainingOverPayment = amountAlreadyPaid - amountThatShouldHaveBeenPaid;

            for (int profilePeriod = variationPointerIndex; profilePeriod < orderRefreshProfilePeriods.Length; profilePeriod++)
            {
                if (remainingOverPayment <= 0)
                {
                    break;
                }

                IProfilePeriod periodToAdjust = orderRefreshProfilePeriods[profilePeriod];

                decimal adjustedProfileValue = periodToAdjust.GetProfileValue() - remainingOverPayment;

                if (adjustedProfileValue < 0)
                {
                    remainingOverPayment = Math.Abs(adjustedProfileValue);
                    adjustedProfileValue = 0;
                }
                else
                {
                    remainingOverPayment = 0;
                }

                periodToAdjust.SetProfiledValue(adjustedProfileValue);
            }

            return(remainingOverPayment != 0);
        }