Hi,
I have figure out the solution, below is the code:
PurchAgreementHeader agreementHeader;
AgreementLine agreementLine;
AgreementLineQuantityCommitment qtyCommitment;
PurchQty purchAmt;
PurchQty totalPurchAmt;
PurchQty discountAmt;
PurchQty qtyFromPlannedPO = 50; // Quantity taken from Planned Purchase order
Price retPrice;
if (ReqParameters::find().ReqPOSearchPurchAgreement) // For Purch Agreement
{
select firstonly qtyCommitment
join agreementHeader
where qtyCommitment.Agreement == agreementHeader.RecId &&
qtyCommitment.ItemId == '1000' &&
agreementHeader.VendAccount == '1001';
if (qtyCommitment.PricePerUnit <= qtyFromPlannedPO)
{
if (!qtyCommitment.LineDiscountPercent)
{
purchAmt = (qtyCommitment.PricePerUnit * qtyFromPlannedPO);
}
else if (qtyCommitment.LineDiscountPercent)
{
purchAmt = (qtyCommitment.PricePerUnit * qtyFromPlannedPO);
discountAmt = (purchAmt/ qtyCommitment.LineDiscountPercent) * 100;
retPrice = purchAmt - discountAmt;
}
}
}
else if (!ReqParameters::find().ReqPOSearchPurchAgreement || !qtyCommitment) // For Trade Agreement and Item Unit Price
{
PriceDisc priceDisc;
InventTable inventTable = InventTable::find('1000');
VendTable vendTable = VendTable::find('1001');
//InventDim inventDimItem = inventTable.inventItemInventSetup().inventDim();
InventDim inventDimItem = InventDim::find('000031');
UnitOfMeasureSymbol unitId = inventTable.inventTableModuleInvent().UnitId;
PriceDiscParameters parameters = PriceDiscParameters::construct();
parameters.parmModuleType(ModuleInventPurchSales::Purch);
parameters.parmItemId(inventTable.ItemId);
parameters.parmInventDim(inventDimItem);
parameters.parmUnitID( unitId);
parameters.parmPriceDiscDate(systemDateGet());
parameters.parmQty(qtyFromPlannedPO);
parameters.parmAccountNum(vendTable.AccountNum);
parameters.parmCurrencyCode(vendTable.Currency);
priceDisc = PriceDisc::newFromPriceDiscParameters(parameters);
if (priceDisc.findPrice(vendTable.PriceGroup)) // For TRADE AGREEMENT
{
retPrice = priceDisc.price();
}
else if (priceDisc.findItemPrice()) // For ITEM Price
{
retPrice = priceDisc.price();
}
// return retPrice;
Info(strFmt("Unit price: %1", retPrice));
}