Solved

how to create a button to pull up an invoice

  • 24 January 2024
  • 5 replies
  • 58 views

I created a button on the customer page called last transaction. it takes you to the customer last trans page and filters for that customers record. the last trans. now, on that last transaction record, there’s a reference number that if you click on it,you are taken to that transactions invoice. I want to make a button on the customer page that goes straight to the customer’s last trans invoice. so far, the invoice button just goes to the invoice page and pulls up a blank invoice. how can i go about this? the invoice button should basically do what pressing on the reference number on the Customer Last Trans page does.

 

icon

Best answer by Vignesh Ponnusamy 24 January 2024, 20:16

View original

5 replies

Badge +11

Is this a “what logic should I use to locate the last Invoice” question or a “what code can I write to pull up an Invoice” question?

what logic can i implement to make it so the button locates and retrieves the invoice of that customers last transaction. and how can i implement it

Badge +11

Try this:

var invoiceGraph = PXGraph.CreateInstance<ARInvoiceEntry>();

// Select Customer's last created invoice
ARInvoice lastInvoice = SelectFrom<ARInvoice>.
Where<ARInvoice.customerID.IsEqual<P.AsInt>>.
OrderBy<ARInvoice.createdDateTime.Desc>.
View.Select(invoiceGraph, Base.BAccount.Current?.BAccountID)?.FirstTableItems?.FirstOrDefault();

// Open invoice in a new window
invoiceGraph.Document.Current = invoiceGraph.Document.Search<ARInvoice.refNbr>(lastInvoice?.RefNbr, lastInvoice?.DocType);
throw new PXRedirectRequiredException(null, invoiceGraph, PXBaseRedirectException.WindowMode.NewWindow, "");

 

Userlevel 7
Badge +4

Just noticed @darylbowman shared a solution. Tried something and sharing my version of it,

	public class CustomerMaint_Extension : PXGraphExtension<PX.Objects.AR.CustomerMaint>
{
#region Event Handlers
public PXAction<Customer> lastTransaction;
[PXUIField(DisplayName = "Last Transaction")]
[PXButton]
protected IEnumerable LastTransaction(PXAdapter adapter)
{
ARInvoice lastInovice = PXSelect<ARInvoice, Where<ARInvoice.customerID, Equal<Required<ARInvoice.customerID>>>,
OrderBy<Desc<ARInvoice.createdDateTime>>>.SelectSingleBound(Base, null, Base.BAccount.Current.BAccountID);
ARInvoiceEntry invoiceEntry = PXGraph.CreateInstance<ARInvoiceEntry>();
invoiceEntry.Document.Current = lastInovice;
throw new PXRedirectRequiredException(invoiceEntry, true, "Last ARInvoice");
return adapter.Get();
}
#endregion
}

Good Luck,

Badge +11

@Vignesh Ponnusamy - I don’t mind being one-upped by you 😁

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved