AX – D365FO – X++ Code to Unsettle Payment and Invoice

This is small utility code if we need to unsettle payments and invoice

Reference article :

select firstonly * from findCustTrans  
 where findCustTrans.Voucher == voucher;  
 if (findCustTrans.RecId) {  
     balanceAmount = findCustTrans.remainAmountCur();  
     if (balanceAmount == 0) {  
         custTable = custTable::find(findCustTrans.AccountNum);  
         select firstonly custSettlement  
         where custSettlement.TransCompany == findCustTrans.dataAreaId && custSettlement.TransRecId == findCustTrans.RecId && custSettlement.AccountNum == findCustTrans.AccountNum;  
         specTransManager = SpecTransManager::newRefTableId(custTable, tablenum(custSettlement), true);  
         specTransManager.insert(custSettlement.DataAreaId, custSettlement.TableId, custSettlement.RecId, custSettlement.SettleAmountCur, findCustTrans.CurrencyCode);  
         custSettlement.CustVendSettlement::markOffsets(specTransManager, findCustTrans.CurrencyCode, true);  
         if (CustTrans::reverseTransact(custTable, null, settleDatePrinc::DateOfPayment, custSettlement.TransDate)) {  

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s