Update purchasePrice on Purchase Line from Trade Agreement
Update purchasePrice on Purchase Line from Trade Agreement
I have to update purchase orders that were created in past. Requirement is to update the purchase price by applying new trade agreements that were created later in the system after the purchase order creation. I have written a piece of code but the combinations in trade agreement are endless.
Is there any faster way to get the price that is active for the combinations?
Thank you
public static PriceDiscTable checkPriceDiscTable(PriceDiscAccountRelation _accountRelation,
PriceDiscItemRelation _itemRelation,
InventLocationId _inventLocationId)
{
RecId priceDiscTableRec;
PriceDiscTable priceDiscTable;
TableGroupAll accountCode, ItemCode;
PriceDiscAccountRelation accountRelation;
PriceDiscItemRelation itemRelation;
int totalcases = 3;
int prioritycase = 0;
while(prioritycase < totalcases)
{
switch (priorityCase)
{
case 0:
accountCode = TableGroupAll::Table;
accountRelation = _accountRelation;
itemCode = TableGroupAll::Table;
itemRelation = _itemRelation;
priceDiscTableRec = DAL_PriceFromAgrement::findPriceDiscTable(accountCode, accountRelation,
itemCode, itemRelation, _inventLocationId);
priceDiscTable = PriceDiscTable::findRecId(priceDiscTableRec);
if(priceDiscTable.recId)
{
return priceDiscTable;
}
break;
case 1:
accountCode = TableGroupAll::GroupId;
accountRelation = _accountRelation;
itemCode = TableGroupAll::Table;
itemRelation = _itemRelation;
priceDiscTableRec = DAL_PriceFromAgrement::findPriceDiscTable(accountCode, accountRelation,
itemCode, itemRelation, _inventLocationId);
if(priceDiscTable.recId)
{
return priceDiscTable;
}
break;
case 2:
accountCode = TableGroupAll::All;
accountRelation = "";
itemCode = TableGroupAll::Table;
itemRelation = _itemRelation;
priceDiscTableRec = DAL_PriceFromAgrement::findPriceDiscTable(accountCode, accountRelation,
itemCode, itemRelation, _inventLocationId);
if(priceDiscTable.recId)
{
return priceDiscTable;
}
break;
}
prioritycase++;
}
return priceDiscTable;
}
1 Answer
1
The helper class is already there to do this for you.
The class name is PriceDisc
.
PriceDisc
Take a look at the method purchPriceAgreement
on InventTable
.
purchPriceAgreement
InventTable
...
vendTable= VendTable::find(_accountNum);
priceDisc = new PriceDisc(ModuleInventPurchSales::Purch,
this.ItemId,
_inventDim,
inventTableModule.UnitId,
_priceDate,
_qty,
vendTable.AccountNum,
_currencyCode);
if (!priceDisc.findPrice(vendTable.PriceGroup, false))
...
price = priceDisc.price();
priceMarkup = priceDisc.markup();
priceUnit = priceDisc.priceUnit();
...
etc
@Axer it also does a lot more. You specifically asked for trade agreement price and i gave you the code.
– AnthonyBlake
Oct 28 '16 at 8:58
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thank you, but I used the method in PurchLine, setPriceDisc which does all the calculations
– Axer
Oct 27 '16 at 8:22