protected void InitializeServices(bool isPaymentByLine) { VendorPreparedBalanceCalculationService = new VendorPreparedBalanceCalculationService(Graph); CashDiscountCalculationService = isPaymentByLine ? new CashDiscountPerLineCalculationService(Graph) : new CashDiscountCalculationService(Graph); }
private void InitializeCalculationServices() { var isPaymentByLines = ApPayBillsExt.CurrentBill.Current?.PaymentsByLinesAllowed == true; jointPayeeAmountsCalculationService = new JointPayeeAmountsCalculationService(ApPayBills); vendorPreparedBalanceCalculationService = new VendorPreparePaymentPreparedBalanceCalculationService(ApPayBills); amountToPayCalculationService = isPaymentByLines ? new AmountToPayPerLineCalculationService(ApPayBills, JointPayeePayments) : new AmountToPayCalculationService(ApPayBills, JointPayeePayments); invoiceBalanceCalculationService = isPaymentByLines ? new InvoiceLineBalanceCalculationService(ApPayBills) : new InvoiceBalanceCalculationService(ApPayBills); }
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); } }