How to calculate sales retail price of item from code

    priceAgr = PriceDisc::findItemPriceAgreement(
                ModuleInventPurchSales::Sales, 
                retailInformationSubcodeTable.triggerCode,
                InventDim::find(InventDim::inventDimIdBlank()),
                inventTableModule.UnitId,
                SystemDateGet(),
                1,
                salesTable.CustAccount,
                salesTable.CurrencyCode,
                CustTable::find(salesTable.CustAccount).PriceGroup // salesTable.PriceGroupId
    );
    price = conPeek(priceAgr, 1);
    /*
    Price group can be 
    1. salesTable.PriceGroupId
    2. CustTable.PriceGroup
    3. from PriceDiscGroup table:
        salesTableExtended = salesTable.krfSalesTableExtended();
        if (salesTableExtended.RetailChannelTable)
        {
            while select RecId from retailChannelPriceGroup
                where retailChannelPriceGroup.RetailChannel == salesTableExtended.RetailChannelTable
                join GroupId from priceDiscGroup
                    where priceDiscGroup.RecId == retailChannelPriceGroup.PriceGroup
            {
                priceGroup += priceDiscGroup.GroupId;
            }
        }
    */
    
    // Retail price
    retailSalesTable    = salesTable.retailSalesTable();
    retailStoreId       = retailSalesTable.RetailStoreId;
    if (!retailStoreId)
    {
        select firstOnly StoreNumber from retailStoreTable
            where retailStoreTable.inventLocation   == salesTable.InventLocationId
                &&retailStoreTable.ChannelType      == RetailChannelType::RetailStore;
        retailStoreId = retailStoreTable.StoreNumber;
    }
    if (retailStoreId)
    {
        price = RetailPricingEngine::getRetailPriceByItem(retailStoreId, retailInformationSubcodeTable.triggerCode, inventTableModule.UnitId, InventDim::inventDimIdBlank(), DateTimeUtil::newDateTime(((salesTable.VKDiscountDate) ? salesTable.VKDiscountDate : SystemDateGet()), timeNow()), '');
    }

    // Simple varian, it requires SalesTable context. Does not create SalesLine but just using it to get all price related information
    salesLine.clear();
    salesLine.SalesId   = salesTable.SalesId;
    salesLine.ItemId    = 'ItemId';
    salesLine.SalesQty  = 1;
    salesLine.initFromInventTable(salesLine.inventTable());


Support The Author

 If you found value in what I share, I've set up a Buy Me a Coffee page as a way to show your support.

Buy Me a Coffee

Post a Comment


All Comments


No comments. Be the first one to comment on this post.

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics 365 FO.

Authors are allowed to set their own "buy me a coffee" link.
Join us.

Blog Tags