Procurement and sourcing > Prices and
discounts > Trade agreement journals -> Create new PurchPrice trade
agreement journal and go to lines.
1. Add the New field -> PriceDiscAdmTrans.Extension (Table)
2. Create a SysOperatoin - Contract class:
[DataContractAttribute]
class PurchPriceDataContract
{
TransDate transDate;
str packedQuery;
[DataMemberAttribute ,SysOperationLabelAttribute(literalStr("@ABC:PurchTradeAgreementLabel"))]
public TransDate parmTransDate(TransDate _transDate = transDate)
{
transDate = _transDate;
return transDate;
}
[DataMemberAttribute, AifQueryTypeAttribute('_packedQuery', querystr(ItemPurchPrice))]
public str parmQuery(str _packedQuery = packedQuery)
{
packedQuery = _packedQuery;
return packedQuery;
}
public Query getQuery()
{
return new Query(SysOperationHelper::base64Decode(packedQuery));
}
public void setQuery(Query _query)
{
packedQuery = SysOperationHelper::base64Encode(_query.pack());
}
}
3. Created a Service class -
class PurchPriceDataService
{
QueryRun queryRun;
InventTable inventTable;
InventTableModule inventTableModule;
PriceConvertFactory priceConvertFactory;
PriceConvert priceConvert;
TransDate transDate;
PriceDiscAdmTrans priceDiscAdmTrans;
PriceDiscAdmTable priceDiscAdmTable;
PriceCur price;
PriceUnit priceUnit;
//
#ISOCountryRegionCodes
boolean countryRegion_RU;
//
[SysEntryPointAttribute]
public void updateItemPurchPrice(PurchPriceDataContract _purchPriceDataContract)
{
// Query objects
Query query;
QueryRun queryRunpriceDiscAdmTrans;
QueryBuildDataSource qbdspriceDiscAdmTrans;
QueryBuildDataSource qbdspriceDiscAdmTable;
QueryBuildRange qbrpriceDiscAdmTrans;
QueryBuildRange qbrpriceDiscAdmTable;
// create a new queryrun object
queryRun = new queryRun(ItemPurchPriceDataContract.getQuery());
// loop all results from the query
while(queryRun.next())
{
inventTable = queryRun.get(tableNum(InventTable));
transDate = _purchPriceDataContract.parmTransDate();
if(inventTable.PrimaryVendorId)
{
query = new query();
qbdspriceDiscAdmTable = query.addDataSource(tablenum(PriceDiscAdmTable));
qbrpriceDiscAdmTable = qbdspriceDiscAdmTable.addRange(fieldNum(PriceDiscAdmTable,DefaultRelation));
qbrpriceDiscAdmTable.value(enum2Str(PriceType::PricePurch));
qbrpriceDiscAdmTable = qbdspriceDiscAdmTable.addRange(fieldNum(PriceDiscAdmTable,Posted));
qbrpriceDiscAdmTable.value(enum2Str(NoYes::Yes));
qbdspriceDiscAdmTrans = qbdspriceDiscAdmTable.addDataSource(tablenum(PriceDiscAdmTrans));
qbdspriceDiscAdmTrans.addLink(fieldNum(PriceDiscAdmTable, JournalNum), fieldNum(PriceDiscAdmTrans, JournalNum));
qbrpriceDiscAdmTrans = qbdspriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, Relation));
qbrpriceDiscAdmTrans.value(enum2Str(PriceType::PricePurch));
qbrpriceDiscAdmTrans = qbdspriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, ItemRelation));
qbrpriceDiscAdmTrans.value(inventTable.itemId);
qbrpriceDiscAdmTrans = qbdspriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, FromDate));
qbrpriceDiscAdmTrans.value(SysQuery::range(transDate, dateNull()));
qbrpriceDiscAdmTrans = qbdspriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, ToDate));
qbrpriceDiscAdmTrans.value(SysQuery::range(dateNull(), transDate));
// Results sorting
qbdspriceDiscAdmTrans.addSortField(fieldNum(PriceDiscAdmTrans, StandardPurchPrice), SortOrder::Descending);
qbdspriceDiscAdmTrans.addSortField(fieldNum(PriceDiscAdmTrans, Amount), SortOrder::Descending);
qbdspriceDiscAdmTrans.firstOnly(true);
queryRunpriceDiscAdmTrans = new QueryRun(query);
if(queryRunpriceDiscAdmTrans.next())
{
priceDiscAdmTrans = queryRunpriceDiscAdmTrans.get(tableNum(PriceDiscAdmTrans));
inventTableModule = InventTableModule::find(inventTable.ItemId,ModuleInventPurchSales::Purch);
priceConvertFactory = PriceConvertFactory::newItemPrice(priceDiscAdmTrans.ItemRelation,
inventTableModule.UnitId,
priceDiscAdmTrans.Amount,//inventTableModule.price(),
inventTableModule.priceUnit(),
inventTableModule.markup(),
inventTableModule.priceQty(),
'',
countryRegion_RU ? inventTableModule.priceSecCur_RU() : 0,
countryRegion_RU ? inventTableModule.markupSecCur_RU() : 0);
priceConvertFactory.parmNewCurrencyCode(priceDiscAdmTrans.Currency);
priceConvertFactory.parmTransDate(transDate);
priceConvertFactory.parmNewUnitId(priceDiscAdmTrans.UnitId);
priceConvert = priceConvertFactory.priceConvert();
price = priceConvert.parmPrice();
ttsbegin;
inventTableModule.selectForUpdate(true);
inventTableModule.price = price;
inventTableModule.update();
ttscommit;
}
}
}
}
}
4. Create a AOT query for the contract class.
finally, update the price on the item purchase price where primary vendor is mentioned.
The above code will fetch the record from the trade agreements base on the dialog box itemID and date selection (which is a AOT Query) and then convert using the standard logic currency conversion, in case the company currency and trade agreements currency are different and then update the item purchase price.
No comments:
Post a Comment