Hi,
Fetch Price from Trade Agreements in AX D365
1. Fetch Price Directly from PriceDiscTable - firstonly is mandatory
PriceDiscTable priceDiscTable;
InventTable inventTable=InventTable::find("554264");// Itemid
InventDim InventDim;
DlvModeId dlvModeId = custTable.DlvMode;
FromDate localFromDate = FromEffectiveDate ;// Provide effective date of trade Agreements
ToDate localToDate =ToEffectiveDate ; // Provide closing date of trade Agreements
select firstonly priceDiscTable
where priceDiscTable.Relation == PriceType::PriceSales
&& priceDiscTable.ItemCode ==PriceDiscProductCodeType::Table
&& priceDiscTable.ItemRelation == inventTable.ItemId
&& priceDiscTable.AccountCode ==PriceDiscPartyCodeType::GroupId
&& priceDiscTable.AccountRelation == custTable.PriceGroup
&& priceDiscTable.UnitId == inventTable.salesUnitId()
// && priceDiscTable.InventDimId == inventDim.inventDimId
&& (priceDiscTable.S_DlvMode == dlvModeId || !dlvModeId ) //sales price by delivery mode
&& priceDiscTable.Currency == custTable.Currency
&& ((priceDiscTable.FromDate >= localFromDate || ! localFromDate)
&& (priceDiscTable.ToDate <= localToDate || ! localToDate));
2. Purchase Price
public static Price findPurchPrice(ItemId _itemId, VendAccount _vendAccount, InventDimId _inventDimId, Qty _qty)
{
PriceDisc priceDisc;
InventTable inventTable = InventTable::find(_itemId);
VendTable vendTable = VendTable::find(_vendAccount);
//InventDim inventDimItem = inventTable.inventItemInventSetup().inventDim();
InventDim inventDimItem = InventDim::find(_inventDimId);
UnitOfMeasureSymbol unitId = inventTable.inventTableModuleInvent().UnitId;
Price retPrice;
priceDisc = new PriceDisc(ModuleInventPurchSales::Purch, _itemId, inventDimItem, unitId, systemDateGet(), _qty , _vendAccount);
if (priceDisc.findPrice(_vendTable.PriceGroup))
retPrice = priceDisc.price();
else if (priceDisc.findItemPrice())
retPrice = priceDisc.price();
return retPrice;
}
3. Find Sales Price
public static Price S_findSalesPrice(InventTable _inventTable, CustAccount _custAccount, InventDimId _inventDimId ,TransDate EffectiveDate)
{
PriceDisc priceDisc;
InventTable inventTable = InventTable::find(_inventTable.itemId);
CustTable custTable = CustTable::find(_custAccount);
// InventDimId inventDimItem = inventTable.inventItemInventSetup().inventDim();
InventDim inventDimItem = InventDim::find(_inventDimId);
UnitOfMeasureSymbol unitId = _inventTable.salesUnitId();
Price retPrice;
priceDisc = new PriceDisc( ModuleInventPurchSales::Sales,
_inventTable.ItemId,
inventDimItem,
_inventTable.salesUnitId(),
EffectiveDate,
0,
custTable.AccountNum);
if (priceDisc.findPrice(custTable.PriceGroup))
retPrice = priceDisc.price();
else if (priceDisc.findItemPrice())
retPrice = priceDisc.price();
return retPrice;
}
Reference
Reference
Reference
Reference
Fetch Price from Trade Agreements in AX D365
1. Fetch Price Directly from PriceDiscTable - firstonly is mandatory
PriceDiscTable priceDiscTable;
InventTable inventTable=InventTable::find("554264");// Itemid
InventDim InventDim;
CustTable custTable=CustTable::find("Cust001");
DlvModeId dlvModeId = custTable.DlvMode;
FromDate localFromDate = FromEffectiveDate ;// Provide effective date of trade Agreements
ToDate localToDate =ToEffectiveDate ; // Provide closing date of trade Agreements
select firstonly priceDiscTable
where priceDiscTable.Relation == PriceType::PriceSales
&& priceDiscTable.ItemCode ==PriceDiscProductCodeType::Table
&& priceDiscTable.ItemRelation == inventTable.ItemId
&& priceDiscTable.AccountCode ==PriceDiscPartyCodeType::GroupId
&& priceDiscTable.AccountRelation == custTable.PriceGroup
&& priceDiscTable.UnitId == inventTable.salesUnitId()
// && priceDiscTable.InventDimId == inventDim.inventDimId
&& (priceDiscTable.S_DlvMode == dlvModeId || !dlvModeId ) //sales price by delivery mode
&& priceDiscTable.Currency == custTable.Currency
&& ((priceDiscTable.FromDate >= localFromDate || ! localFromDate)
&& (priceDiscTable.ToDate <= localToDate || ! localToDate));
2. Purchase Price
public static Price findPurchPrice(ItemId _itemId, VendAccount _vendAccount, InventDimId _inventDimId, Qty _qty)
{
PriceDisc priceDisc;
InventTable inventTable = InventTable::find(_itemId);
VendTable vendTable = VendTable::find(_vendAccount);
//InventDim inventDimItem = inventTable.inventItemInventSetup().inventDim();
InventDim inventDimItem = InventDim::find(_inventDimId);
UnitOfMeasureSymbol unitId = inventTable.inventTableModuleInvent().UnitId;
Price retPrice;
priceDisc = new PriceDisc(ModuleInventPurchSales::Purch, _itemId, inventDimItem, unitId, systemDateGet(), _qty , _vendAccount);
if (priceDisc.findPrice(_vendTable.PriceGroup))
retPrice = priceDisc.price();
else if (priceDisc.findItemPrice())
retPrice = priceDisc.price();
return retPrice;
}
3. Find Sales Price
public static Price S_findSalesPrice(InventTable _inventTable, CustAccount _custAccount, InventDimId _inventDimId ,TransDate EffectiveDate)
{
PriceDisc priceDisc;
InventTable inventTable = InventTable::find(_inventTable.itemId);
CustTable custTable = CustTable::find(_custAccount);
// InventDimId inventDimItem = inventTable.inventItemInventSetup().inventDim();
InventDim inventDimItem = InventDim::find(_inventDimId);
UnitOfMeasureSymbol unitId = _inventTable.salesUnitId();
Price retPrice;
priceDisc = new PriceDisc( ModuleInventPurchSales::Sales,
_inventTable.ItemId,
inventDimItem,
_inventTable.salesUnitId(),
EffectiveDate,
0,
custTable.AccountNum);
if (priceDisc.findPrice(custTable.PriceGroup))
retPrice = priceDisc.price();
else if (priceDisc.findItemPrice())
retPrice = priceDisc.price();
return retPrice;
}
In Version 10 Codes
My Scenario code in latest version
ModuleInventPurchSales inventModule = this.parmModuleType();
PriceDisc priceDiscFetch;
PriceDiscParameters parameters = PriceDiscParameters::construct();
parameters.parmModuleType(this.parmModuleType());
parameters.parmItemId(this.parmItemId());
parameters.parmInventDim(this.parmInventDim());
parameters.parmUnitID(this.parmUnitID());
parameters.parmPriceDiscDate(this.parmPriceDate());
parameters.parmQty(this.parmQty());
parameters.parmAccountNum(this.parmAccountNum());
parameters.parmCurrencyCode(this.parmCurrencyCode());
priceDiscFetch = PriceDisc::newFromPriceDiscParameters(parameters);
if(inventModule==1) // Fetch Purchase Price
{
priceDiscFetch.findPrice('');
}
else if(inventModule==2) //Fetch Sales Price
{
CustTable custTable = CustTable::find(this.parmAccountNum());
priceDiscFetch.findPrice(custTable.PriceGroup,false);
}
price = priceDiscFetch.price();
Reference
Reference
Reference
Reference
Comments
Post a Comment