hljs.configure({cssSelector: "code"}); hljs.highlightAll();

Thursday, June 10, 2021

X++ code to get trade agreement price (sales ) based on price group in AX7/D365

     public Real GetPriceRetail(str itemNumber,str size, str color, str style, str channel)

    {

        PriceDisc               priceDisc;

        RetailStoreTable        storeTable;

        CustTable               custtable;

        InventTable             inventTable = InventTable::find(itemNumber);

        UnitOfMeasureSymbol     unitId  = inventTable.inventTableModuleInvent().UnitId;

        Price                   retPrice;

        InventDim               inventDim;

        select firstonly storeTable

            where storeTable.RetailChannelId == channel;

        custtable = CustTable::find(storeTable.DefaultCustAccount);

        InventDim.InventSizeId = size;

        InventDim.InventColorId = color;

        InventDim.InventStyleId = style;

        inventDim = InventDim::findOrCreate(inventDim);

        PriceDiscParameters parameters = PriceDiscParameters::construct();

        parameters.parmModuleType(ModuleInventPurchSales::Sales);

        parameters.parmItemId(itemNumber);

        parameters.parmInventDim(inventDim);

        parameters.parmUnitID(unitId);

        parameters.parmPriceDiscDate(systemDateGet());

        parameters.parmQty(1);

        parameters.parmAccountNum(custtable.AccountNum);

        parameters.parmCurrencyCode(custtable.Currency);

        priceDisc = PriceDisc::newFromPriceDiscParameters(parameters);

        // From Trade agreement

        if (priceDisc.findPrice('Retail')) // clearance ,club price

        {

            retPrice = priceDisc.price();

        }

return retPrice ;

}


  public Price getRRPPrice(salesLine  salesLine)

    {

        PriceDiscTable  priceRetail;

        InventDim     inventDimRetail,inventDim;

        inventDim = InventDim::find(salesLine.InventDimId);

        select firstonly priceRetail

            join inventDimRetail

            where priceRetail.ItemCode == PriceDiscProductCodeType::Table

            && priceRetail.ItemRelation==salesLine.ItemId

            && (priceRetail.FromDate <= DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone()) || priceRetail.FromDate == Global::DateNull())

            && (priceRetail.ToDate >= DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone()) || priceRetail.ToDate == Global::DateNull()) 

            && priceRetail.AccountCode == PriceDiscPartyCodeType::GroupId

            && priceRetail.AccountRelation ==  'Retail'

            && inventDimRetail.InventStyleId == inventDim.InventStyleId

            && inventDimRetail.InventColorId == inventDim.InventColorId

            && inventDimRetail.InventSizeId == inventDim.InventSizeId

            && priceRetail.InventDimId == inventDimRetail.inventDimId;


        return priceRetail.Amount;

    }

No comments:

Post a Comment