Hi Team,
I have created AP Bill using AP Bills and Adjustment screen and on a custom button action I have created a Debit Adjustment out of it. Now, I wanted to apply the newly created debit adjustment against that bill. However, I am getting an issue of “Document out of Balance” error while saving the same.
Below is the code I have written which seems to be failing on (paymentGraph.Actions.PressSave()).
APPaymentEntry paymentGraph = PXGraph.CreateInstance<APPaymentEntry>();
APInvoice fetchedDebitAdj = PXSelect<APInvoice,
Where<APInvoice.docType, Equal<Required<APInvoice.docType>>,
And<APInvoice.refNbr, Equal<Required<APInvoice.refNbr>>>>>
.Select(Base, APDocType.DebitAdj, debitAdj.RefNbr);
APPayment newPayment = paymentGraph.Document.Insert(new APPayment
{
VendorID = apinvoice.VendorID,
DocType = APDocType.DebitAdj,
CuryOrigDocAmt = fetchedDebitAdj.CuryOrigDocAmt,
Hold = false // Set hold status
});
// Link the Debit Adjustment reference number
newPayment.RefNbr = fetchedDebitAdj.RefNbr;
paymentGraph.Document.Update(newPayment);
// Insert APAdjust for applying the Debit Adjustment to the invoice
APAdjust adjustment = paymentGraph.Adjustments.Insert(new APAdjust
{
AdjgDocType = newPayment.DocType,
AdjgRefNbr = newPayment.RefNbr,
AdjdDocType = fetchedDebitAdj.DocType,
AdjdRefNbr = fetchedDebitAdj.RefNbr,
CuryAdjgAmt = fetchedDebitAdj.CuryOrigDocAmt.Value,
CuryAdjdAmt = fetchedDebitAdj.CuryOrigDocAmt.Value,
AdjAmt = fetchedDebitAdj.OrigDocAmt.Value
});
newPayment.CuryUnappliedBal = 0;
newPayment.UnappliedBal = 0;
paymentGraph.Document.Update(newPayment);
paymentGraph.Actions.PressSave();
paymentGraph.releaseFromHold.Press();
PXLongOperation.WaitCompletion(paymentGraph.UID);
Thank you for any help in advance.
Regards,
Sagar