Good day
I am making a custom discount calculation on the Payments and Applications screen.
Discount works on the Original Invoice balance (ARInvoice.CuryDocBal)
Multiplied the DiscPecent
Discount = OriginalInvoiceBalance * (CurrentCustomerTerms.DiscPercent.Value / 100);
The main difference being Acumatica uses the Invoice Amount and not the balance.
After working out my discount and payment and trying to release the payment I get the following error:
public void Calculate(PXCache cache, ARAdjust row)
{
try
{
if (row == null)
return;
if (!(row.Released != true && row.Voided != true))
return;
// row.AdjdRefNbr current invoice
ARPayment currentARPayment = this.Base.Document.Current;
if (currentARPayment.DocType != "PMT" || currentARPayment.Status == "C")
return;
if (row.AdjdDocType != "INV")
return;
if (row.Selected != true)
return;
Customer currentCustomer = this.Base.customer.Current;
Terms CurrentCustomerTerms = PXSelect<
Terms,
Where<Terms.termsID, Equal<Required<Customer.termsID>>>>
.Select(Base, currentCustomer.TermsID);
ARInvoice aRInvoicerow = PXSelect<
ARInvoice,
Where<ARInvoice.docType, Equal<Required<ARAdjust.adjdDocType>>,
And<ARInvoice.refNbr, Equal<Required<ARAdjust.adjdRefNbr>>>>>
.Select(Base, row.AdjdDocType, row.AdjdRefNbr);
Termschecks checks = new Termschecks();
// check if current row should get discount according to the date
// bool inTerms = checks.checkIfDiscountshouldBeAplyed(row.AdjdDocDate.Value, CurrentCustomerTerms, currentARPayment.AdjDate.Value);
bool inTerms = true; // hard code true for testing
decimal? Discount = 0;
decimal? DiscountHalfCents = 0;
decimal? OriginalInvoiceBalance = aRInvoicerow.CuryDocBal.Value;
decimal? OriginalInvoiceCuryOrigDiscAmt = aRInvoicerow.CuryOrigDiscAmt.Value;
decimal? DiscountWithOutHalfCents = 0;
decimal? amountToBepaidbeforeround;
//work out the Discount
if (inTerms)
{
if (CurrentCustomerTerms.DiscPercent.Value == 0)
{
Discount = 0;
}
else
{
Discount = OriginalInvoiceBalance * (CurrentCustomerTerms.DiscPercent.Value / 100);
DiscountWithOutHalfCents = Math.Truncate(100 * Discount.Value) / 100;
DiscountHalfCents = Discount - DiscountWithOutHalfCents;
amountToBepaidbeforeround = OriginalInvoiceBalance - Discount;
}
}
decimal? amountToBepaid;
amountToBepaid = OriginalInvoiceBalance - Discount;
if ((amountToBepaid - DiscountHalfCents) > currentARPayment.CuryUnappliedBal)
{
//set discount to 0 because full amount will not be payed
Discount = 0;
// if the total amount that has been payed is greater or equals the amount the client payed no more money is left to pay this invoice
if (currentARPayment.CuryOrigDocAmt.Value <= currentARPayment.CuryUnappliedBal)
{
amountToBepaid = 0;
}
else
{
amountToBepaid = OriginalInvoiceBalance - (OriginalInvoiceBalance - currentARPayment.CuryUnappliedBal.Value);
}
}
decimal? Balance = OriginalInvoiceBalance - amountToBepaid - Discount;
decimal? CashDiscountBal = OriginalInvoiceCuryOrigDiscAmt - Discount;
row.CuryAdjgAmt = amountToBepaid;
row.CuryAdjgPPDAmt = Discount;//Cash Discount Taken
}
catch (System.Exception ex)
{
PXTrace.WriteError(ex);
}
}
question from:
https://stackoverflow.com/questions/66059956/how-to-calculate-custom-discount-on-the-payments-and-applications 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…