web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Calculate the amount while firming the Planned purchase orders

(0) ShareShare
ReportReport
Posted on by 145

Hi Everyone,

I need to know how to calculate the amount when we do the firming of the planned purchase orders which creates the Purchase orders.

My requirement is, I need to add a new field "Total Amount"in the Fact box of the Planned Purchase order similar to the Purchase orders, so need to know how Ax calculates the amount when we do the firming of the Planned PO to PO.

Best Regards 

Pranav

*This post is locked for comments

  • Verified answer
    Pranav Gupta Profile Picture
    145 on at

    Hi,

    I have figure out the solution, below is the code:

    PurchAgreementHeader                agreementHeader;

           AgreementLine                       agreementLine;

           AgreementLineQuantityCommitment     qtyCommitment;

           PurchQty                            purchAmt;

           PurchQty                            totalPurchAmt;

           PurchQty                            discountAmt;

           PurchQty                            qtyFromPlannedPO = 50;  // Quantity taken from Planned Purchase order 

           Price                               retPrice;

           if (ReqParameters::find().ReqPOSearchPurchAgreement) // For Purch Agreement

           {

               select firstonly qtyCommitment

                   join agreementHeader

                       where qtyCommitment.Agreement       == agreementHeader.RecId    &&

                             qtyCommitment.ItemId          == '1000'                   &&

                             agreementHeader.VendAccount   == '1001';

               if (qtyCommitment.PricePerUnit <= qtyFromPlannedPO)

               {

                   if (!qtyCommitment.LineDiscountPercent)

                   {

                       purchAmt = (qtyCommitment.PricePerUnit * qtyFromPlannedPO);

                   }

                   else if (qtyCommitment.LineDiscountPercent)

                   {

                       purchAmt        = (qtyCommitment.PricePerUnit * qtyFromPlannedPO);

                       discountAmt     = (purchAmt/ qtyCommitment.LineDiscountPercent) * 100;

                       retPrice        = purchAmt - discountAmt;

                   }

               }

           }

           else if (!ReqParameters::find().ReqPOSearchPurchAgreement || !qtyCommitment) // For Trade Agreement and Item Unit Price

           {

               PriceDisc               priceDisc;

               InventTable inventTable = InventTable::find('1000');

               VendTable vendTable = VendTable::find('1001');

               //InventDim               inventDimItem       = inventTable.inventItemInventSetup().inventDim();

               InventDim inventDimItem = InventDim::find('000031');

               UnitOfMeasureSymbol     unitId              = inventTable.inventTableModuleInvent().UnitId;

               PriceDiscParameters parameters = PriceDiscParameters::construct();

               parameters.parmModuleType(ModuleInventPurchSales::Purch);

               parameters.parmItemId(inventTable.ItemId);

               parameters.parmInventDim(inventDimItem);

               parameters.parmUnitID( unitId);

               parameters.parmPriceDiscDate(systemDateGet());

               parameters.parmQty(qtyFromPlannedPO);

               parameters.parmAccountNum(vendTable.AccountNum);

               parameters.parmCurrencyCode(vendTable.Currency);

               priceDisc = PriceDisc::newFromPriceDiscParameters(parameters);

               if (priceDisc.findPrice(vendTable.PriceGroup)) // For TRADE AGREEMENT

               {

                   retPrice = priceDisc.price();

               }

               else if (priceDisc.findItemPrice()) // For ITEM Price

               {

                   retPrice = priceDisc.price();

               }

               // return retPrice;

               Info(strFmt("Unit price: %1", retPrice));

           }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans