Hi Community,
I’m working on the Customer Details Inquiry screen in Acumatica, specifically on the Pay/Apply Document action. I’ve overridden this action to handle multiple document selection so I can apply payments to multiple invoices at once. Here’s the code I’m using:
public delegate IEnumerable PayDocumentDelegate(PXAdapter adapter);
[PXOverride]
public virtual IEnumerable PayDocument(PXAdapter adapter, PayDocumentDelegate baseMethod)
{
List<ARDocumentEnq.ARDocumentResult> selectedDocuments = Base.Documents.Cache.Updated
.RowCast<ARDocumentEnq.ARDocumentResult>()
.Where(shipment => PXCache<ARDocumentEnq.ARDocumentResult>
.GetExtension<ARDocumentResultExt>(shipment)?.UsrSelect == true)
.ToList();
if (!selectedDocuments.Any())
{
// Fall back to base behavior if no rows are selected
return baseMethod(adapter);
}
// Iterate through each selected document
foreach (var doc in selectedDocuments)
{
if (ARDocType.Payable(doc.DocType) == true)
{
// Create an instance of ARInvoiceEntry for each document
ARInvoiceEntry invoiceGraph = PXGraph.CreateInstance<ARInvoiceEntry>();
// Retrieve the ARInvoice for the selected document
ARInvoice invoice = PXSelect<ARInvoice,
Where<ARInvoice.docType, Equal<Required<ARInvoice.docType>>,
And<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>>
.Select(Base, doc.DocType, doc.RefNbr)
.FirstOrDefault();
if (invoice != null)
{
// Assign the retrieved invoice to the graph
invoiceGraph.Document.Current = invoice;
// Process payment
invoiceGraph.PayInvoice(adapter);
}
}
}
// Return default filter view
return Base.Filter.Select();
}
The issue I’m facing is that it’s not working as expected — the payment is still only applied to a single document, not multiple. I’d really appreciate any guidance on how I can properly apply payments to multiple invoices from the Customer Details Inquiry screen to the Payments and Applications screen.
I have added custom checkbox field UsrSelect to select multiple documents.
Thanks in advance for your help!