Skip to main content
Solved

how to create a button to pull up an invoice


Forum|alt.badge.img

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.

 

Best answer by Vignesh Ponnusamy

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,

View original
Did this topic help you find an answer to your question?

5 replies

darylbowman
Captain II
Forum|alt.badge.img+13

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?


Forum|alt.badge.img

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


darylbowman
Captain II
Forum|alt.badge.img+13

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, "");

 


Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

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,


darylbowman
Captain II
Forum|alt.badge.img+13

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings