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);
            }
        }