protected void InitializeServices(bool isPaymentByLine) { VendorPreparedBalanceCalculationService = new VendorPreparedBalanceCalculationService(Graph); CashDiscountCalculationService = isPaymentByLine ? new CashDiscountPerLineCalculationService(Graph) : new CashDiscountCalculationService(Graph); }
public void Validate() { foreach (var adjustment in ActualAdjustments) { InitializeServices(adjustment.AdjdLineNbr != 0); var allowableCashDiscount = CashDiscountCalculationService.GetAllowableCashDiscount(adjustment); if (adjustment.CuryAdjgPPDAmt > allowableCashDiscount) { ShowErrorMessage <APAdjust.curyAdjgPPDAmt>(adjustment, JointCheckMessages.AmountPaidWithCashDiscountTakenExceedsVendorBalance, allowableCashDiscount); ShowErrorOnPersistIfRequired(Graph.Adjustments.Cache, true); } } }
private void ValidateAmountPaidExceedsVendorBalanceWithCashDiscountTaken(APAdjust adjustment, decimal?amountPaid, bool doNeedShowErrorOnPersist) { var vendorPreparedBalance = VendorPreparedBalanceCalculationService.GetVendorPreparedBalance(adjustment); var totalJointAmountToPay = jointAmountToPayCalculationService.GetTotalJointAmountToPay(adjustment); var cashDiscountTakenFromOtherNonReleasedChecks = CashDiscountCalculationService.GetNonReleasedCashDiscountTakenExceptCurrentAdjustment(adjustment); if (amountPaid > vendorPreparedBalance - cashDiscountTakenFromOtherNonReleasedChecks - adjustment.CuryAdjgPPDAmt + totalJointAmountToPay) { var amountPaidLimit = vendorPreparedBalance - cashDiscountTakenFromOtherNonReleasedChecks + totalJointAmountToPay; ShowErrorMessage <APAdjust.curyAdjgAmt>(adjustment, amountPaid, JointCheckMessages.AmountPaidWithCashDiscountTakenExceedsVendorBalance, amountPaidLimit); ShowErrorOnPersistIfRequired(Graph.Adjustments.Cache, doNeedShowErrorOnPersist); } }
public void ValidateVendorPaymentAmount(APAdjust adjustment, string errorMessage) { InitializeServices(adjustment.AdjdLineNbr != 0); var totalJointAmountToPay = jointAmountToPayCalculationService.GetTotalJointAmountToPay(adjustment); var vendorPaymentAmount = adjustment.CuryAdjgAmt - totalJointAmountToPay; var vendorPreparedBalance = VendorPreparedBalanceCalculationService.GetVendorPreparedBalance(adjustment); if (vendorPaymentAmount > vendorPreparedBalance) { var totalNonReleasedCashDiscountTaken = CashDiscountCalculationService.GetNonReleasedCashDiscountTakenExceptCurrentAdjustment(adjustment) + adjustment.CuryAdjgPPDAmt; var allowableAmountPaid = vendorPreparedBalance + totalJointAmountToPay - totalNonReleasedCashDiscountTaken; allowableAmountPaid = Math.Max(allowableAmountPaid.GetValueOrDefault(), 0); ShowErrorMessage <APAdjust.curyAdjgAmt>(adjustment, errorMessage, allowableAmountPaid); ShowErrorOnPersistIfRequired(Graph.Adjustments.Cache, true); } }