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

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

Reference article : https://community.dynamics.com/ax/b/amirsaxspace/posts/x-code-to-unsettle-payment-and-invoice

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)) {  
             specTransManager.deleteAll();  
         }  
     }  
 }  

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s