Monday, June 6, 2022

How to calculate total discount for a purchase order through X++ in Dynamics 365 Fin Ops

 

Most of the times consultants get a requirement to calculate the discount for the supply chain documents such as Purchase Orders and Sales Orders.

The key to do this calculation is to use PurchTotals class.

Here is the code mentioned below where we are calculating the discount for a purchase order : - 



class CalculateTotalsOfPurchaseOrder
{
    public static void main(Args _args)
    {
        PurchTotals purchTotals;

        PurchTable  purchTable  = PurchTable::find('PO012345');

        AmountCur   totalAmount;

        purchTotals = PurchTotals::newPurchTable(purchTable);

        purchTotals.calc();

        totalAmount = purchTotals.purchTotalAmount();

        info(strFmt('Purchase order: %1 - Total value: %2', purchTable.PurchId, totalAmount));
    }
}


That's all for now. Please let us know your questions or feedback in comments section !!!!

No comments:

Post a Comment

Demystifying the SysOperation Framework in D365 F&O: Building Scalable and Maintainable Batch Jobs

 If you've been developing in Dynamics 365 Finance and Operations for a while, chances are you've either worked with or heard about ...