Settle Invoice through X++ in AX:

Hi,
SETTLING INVOICE THROUGH X++:

static void settlePayment(Args _args)
{
CustTable custTable;
CustTrans invCustTrans, payCustTrans;
SpecTransManager manager;
CustVendTransData custVendTransData;
;
custTable = CustTable::find(“3001”);
// Find the oldest invoice that has not been settled yet
// for this customer you can customize the query find the invoice that you
want
//to settle
select firstonly invCustTrans
order by TransDate asc
where invCustTrans.AccountNum == custTable.AccountNum &&
invCustTrans.TransType == LedgerTransType::Sales &&
!invCustTrans.LastSettleDate;
// Find the oldest payment that has not been settled yet
// for this customer
select firstonly payCustTrans
order by TransDate asc
where payCustTrans.AccountNum == custTable.AccountNum &&
payCustTrans.TransType == LedgerTransType::Payment &&
!payCustTrans.LastSettleDate;
ttsbegin;
// Create an object of the CustVendTransData class
// with the invoice transaction as parameter and mark
// it for settlement
custVendTransData = CustVendTransData::construct(invCustTrans);
custVendTransData.markForSettlement(CustTable);
// Create an object of the CustVendTransData class
// with the payment transaction as parameter and mark
// it for settlement
custVendTransData = CustVendTransData::construct(payCustTrans);
custVendTransData.markForSettlement(CustTable);
ttscommit;
// Settle all transactions marked for settlement for this
// customer
if(CustTrans::settleTransact(custTable, null, true,
SettleDatePrinc::DaysDate, systemdateget()))
info(“Transactions settled”);
}

Advertisements

2 thoughts on “Settle Invoice through X++ in AX:

  1. this code is not working properly when i checked output from Customer Details form and checked transaction its not showing settlement transaction??/

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s