Monday, June 25, 2018

Code to create a trade agreement in D365

 PriceDiscTable              priceDiscTable;
 PriceDiscAdmTrans           priceDiscAdmTrans;
 RecordInsertList            priceDiscAdmTransInsertList         = new   RecordInsertList(tableNum(PriceDiscAdmTrans), true);
 PriceDiscAdmTable           priceDiscAdmTable;
 PriceDiscAdmCheckPost       priceDiscAdmCheckPost = new priceDiscAdmCheckPost();     PriceDiscAdmName            PriceDiscAdmName;     

 select PriceDiscAdmName where PriceDiscAdmName.JournalName == "DISC";
 priceDiscAdmTable.clear();
 priceDiscAdmTable.JournalName     = PriceDiscAdmName.JournalName;                 priceDiscAdmTable.Name            = PriceDiscAdmName.Name;                 priceDiscAdmTable.DefaultRelation = PriceDiscAdmName.DefaultRelation;                 priceDiscAdmTable.insert();

priceDiscAdmTrans.clear();
priceDiscAdmTrans.JournalNum    = _priceDiscAdmTable.JournalNum;        priceDiscAdmTrans.ItemCode      = PriceDiscProductCodeType::Table;
priceDiscAdmTrans.ItemRelation  = _inventTable.ItemId;
currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
amountMST = currencyExchangeHelper.calculateCurrencyToCurrency(_currencyCode,Ledger::accountingCurrency(CompanyInfo::current()),_purchasePrice ,true);
priceDiscAdmTrans.Amount        = amountMST;
priceDiscAdmTrans.FromDate      = today();
priceDiscAdmTrans.AccountCode   = PriceDiscPartyCodeType::GroupId;
priceDiscAdmTrans.relation      = PriceType::PricePurch;
priceDiscAdmTrans.AccountRelation   = "ItemGroupId";
priceDiscAdmTrans.Currency      = _currencyCode;
priceDiscAdmTrans.UnitId        = InventTablemodule::find(_inventTable.ItemId,ModuleInventPurchSales::Purch).UnitId;
priceDiscAdmTrans.PriceUnit     = 1;
priceDiscAdmTrans.InventDimId   = _inventTable.defaultInventDim(inventitemordersetuptype::Purch).inventDimId; priceDiscAdmTrans.doInsert();

No comments:

Post a Comment