What is a Purchase Order?
A Purchase Order is a document that represents a request to a vendor to supply goods or services at a specific price and delivery date. The purchase order includes details such as the quantity, unit price, and delivery date of the items or services requested, as well as the vendor's information and the buyer's information.
A purchase order is typically created in the procurement and sourcing module in Dynamics 365 Finance and Operations, and it can be generated automatically from a requisition or manually entered by a user. Once the purchase order is approved and sent to the vendor, it serves as a legally binding agreement between the buyer and the seller.
The purchase order also serves as a basis for tracking the status of the order and receiving the items or services in the receiving and warehousing module. It can also be used for invoice matching and for tracking vendor performance metrics.
Why this article?
It is often difficult to calculate the totals of PO using X++ in D365FO. The form of totals in the Purchase order shows different totals of PO, but it is difficult for developers to get them using X++ code. For this purpose, I am writing this article to give you the code to calculate the totals of PO using X++.
What is Purchase Order Total?
In Dynamics 365 Finance and Operations, the Purchase Order Total refers to the total cost of the items or services requested in a purchase order. This includes the price of the items or services, any applicable taxes or fees, and any additional charges such as shipping or handling fees.
The Purchase Order Total is calculated automatically in Dynamics 365 Finance and Operations based on the details entered in the purchase order. It can be viewed on the purchase order form and can also be used in various financial and accounting processes, such as budgeting, cost accounting, and financial reporting.
Having an accurate Purchase Order Total is important for effective budget management and financial control, as it enables buyers to track and manage their purchasing activities more effectively and provides greater transparency into the costs associated with their procurement processes.
In Dynamics 365 FO, you can review the totals of PO using the following steps:
1. Under Module > Click on Procurement and Sourcing Module.   2. Under purchase orders > Click on All purchase order menu.
3. You can see all the purchase orders created previously, select one purchase order.
You can see the Total under the Purchase Order tab on the action bar.
4. Click the menu Total, and a dialog box shows totals for the whole order.
Calculate the purchase order total value using X++
For this,
1. Create a runnable class (job) named as CalculatePurchaseOrderTotals.
2. Copy the below code and paste it into the newly created class.
internal final class CalculatePurchaseOrderTotals { public static void main(Args _args) { //Calculate totals per Purchase order PurchTotals purchTotals; PurchTable purchTable = PurchTable::find('00000041'); //Change the Purchase Order Id as per your system's data AmountCur totalAmount; purchTotals = PurchTotals::newPurchTable(purchTable); purchTotals.calc(); totalAmount = purchTotals.purchTotalAmount(); info(strFmt("Purchase order: %1 - Total value: %2", purchTable.PurchId, totalAmount)); } }
3. Change the Purchase order id according to your system’s purchase order data. Here we selected 00000041 as the purchase order id.
4. Successfully build and run the job.
5. You can see the purchase order total value in the info log as shown below,
If this article is useful to you, please try to share it with your friends, if you have any doubts about this article please comment in the comment box.