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

How to reverse Free Text Invoice Voucher entries without Dialog

 Hey Folks ,  This blog post is in continuation of the previous post for Reversing Free Text Invoice Voucher entries with Dialog. Only diffe...