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.K3DiscountDate) ? salesTable.K3DiscountDate : 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());

Search

About

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

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags