static void demo_CRT_GetSalesPrice(Args _args)
{
Microsoft.Dynamics.Commerce.Runtime.Data.IPricingDataManagerV2 pricingManager;
Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.DiscountParameters priceParameters;
Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesLine crtSalesLine;
Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesTransaction crtSalesTransaction;
System.Object roundingRule, currencyConverter;
CLRObject clrSalesLines, enumeratorSalesLine;
CLRObject clrObjectSalesLines;
System.DateTimeOffset activeDateTimeOffset;
System.String lineIdString;
System.String customerPriceGroup = "";
Price price;
Qty qty;
InventDim inventdim;
RetailStoreTable storeTable = RetailStoreTable::find("HOUSTON");
RetailChannelRecId channelId = storeTable.RecId;
CurrencyCode currencyCode = storeTable.Currency;
appl.setDefaultCompany(storeTable.company(), false);
lineIdString = System.Guid::NewGuid().toString();
InventDim.InventLocationId = storeTable.inventLocation;
InventDim.InventSiteId = InventLocation::find(storeTable.inventLocation).InventSiteId;
InventDim = InventDim::findOrCreate(InventDim);
pricingManager = Microsoft.Dynamics.Commerce.Headquarters.RetailProxy.AxPricingDataManager::BuildDataManager(channelId);
priceParameters = Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.DiscountParameters::CreateAndInitialize(pricingManager);
roundingRule = Microsoft.Dynamics.Commerce.Headquarters.RetailProxy.ServiceHelpers::GetRoundingMethod(currencyCode);
currencyConverter = Microsoft.Dynamics.Commerce.Headquarters.RetailProxy.ServiceHelpers::GetCurrencyConverter(currencyCode);
activeDateTimeOffset = RetailPricingEngineHelper::getSessionDateTimeInChannelTimeZone(channelId);
crtSalesLine = new Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesLine();
crtSalesLine.set_ItemId("0001");
crtSalesLine.set_InventoryDimensionId(InventDim.inventDimId);
crtSalesLine.set_Quantity(10);
crtSalesLine.set_LineId(lineIdString);
crtSalesLine.set_UnitOfMeasureSymbol("ea");
crtSalesTransaction = new Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesTransaction();
clrObjectSalesLines = crtSalesTransaction.get_SalesLines();
clrObjectSalesLines.Add(crtSalesLine);
Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.PricingEngine::CalculatePricesForTransaction(
crtSalesTransaction,
pricingManager,
roundingRule,
currencyConverter,
customerPriceGroup,
currencyCode,
false,
activeDateTimeOffset);
Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.PricingEngine::CalculateDiscountsForLines(
pricingManager,
crtSalesTransaction,
roundingRule,
currencyConverter,
currencyCode,
'',
'',
'',
true,
Microsoft.Dynamics.Commerce.Runtime.DataModel.DiscountCalculationMode::CalculateAll,
activeDateTimeOffset);
qty = crtSalesLine.get_Quantity();
Price = crtSalesLine.get_Price();
info(strFmt("Normal sales price is %1 when buying %2", price, qty ));
Price = crtSalesLine.get_DiscountAmount();
info(strFmt("Discount amount pr unit is %1, when buying %2", price/qty, qty ));
Price = crtSalesLine.get_NetAmountPerUnit();
info(strFmt("Net amount pr unit is %1, when buying %2", price, qty ));
Price = crtSalesLine.get_TotalAmount();
info(strFmt("Total amount is %1 when buying %2", price, qty ));
}
Reference :- Thanks Mr. Kurt Hatlevik for sharing knowledge
https://kurthatlevik.com/2015/05/21/dax2012-r3-playing-with-retail-crt/