- create a payment journal
- mark journal with invoice
static void settledPaymentwithinoice(Args _args)
{
CustVendOpenTransManager manager;
LedgerJournalTrans journaltrans;
VendTransOpen vendtransopen;
//the payment journal
select firstOnly journaltrans where journaltrans.RecId == 5637195041;
manager = CustVendOpenTransManager::construct(journaltrans);
//select a vendor invoice that open
select firstOnly VendTransOpen;
//manager.resetMarkedTrans();
manager.updateTransMarked(VendTransOpen, true);
// manager.updateAmounts(vendTransOpen, amountToSettle, amountToSettle, 0, false);
info('Done');
}
- update the payment journal “ settle voucher” filed type
- when post. this payment will be settled with that vendor invoice you select.
Also there is a reference link. which mention the SpecTrans. this is a table that record the ready to mark invoice. once it is post , the data will be delete .
http://axhelper.blogspot.hk/2018/03/update-vendor-open-trans-to-mark-and.html
-
after post , check it in vendtrans table
There is also tips for unsettled payment and invocie
https://community.dynamics.com/ax/b/amirsaxspace/archive/2018/03/16/x-code-to-unsettle-payment-and-invoice
static void unSettlement(Args _args)
{
VendTrans vendtrans;
VendTable vendtable;
VendSettlement vendSettlement;
Amount remianingAmt;
SpecTransManager specTransManager;
//select the trans that you want to unsettlement
select firstOnly vendtrans where vendtrans.Voucher == 'APD-18040001';
remianingAmt = vendtrans.remainAmountCur();
if(remianingAmt == 0)
{
vendtable = VendTable::find(vendtrans.AccountNum);
select firstOnly vendSettlement
where vendSettlement.TransCompany == vendtrans.dataAreaId
&& vendSettlement.TransRecId == vendtrans.RecId
&& vendSettlement.AccountNum == vendtrans.AccountNum;
specTransManager = SpecTransManager::newRefTableId(VendTable, tablenum(vendSettlement), true);
specTransManager.insert(vendSettlement.DataAreaId,
vendSettlement.TableId, vendSettlement.RecId,
vendSettlement.SettleAmountCur, vendtrans.CurrencyCode);
vendSettlement.CustVendSettlement::markOffsets(specTransManager, vendtrans.CurrencyCode, true);
if (vendtrans::reverseTransact(vendTable, null, settleDatePrinc::DateOfPayment,
vendSettlement.TransDate))
{
specTransManager.deleteAll();
}
}
info("done");
}
- after unsettlement ,check it again in vends table