March 27, 2015

Auto Settlement of Sales Invoice in AX

In an organization where thousands (or more) of sales transaction happening every day, and here is this auto settlement requirement comes in picture. Auto settlement process save a ton of time to manually settlement of each and every customer or record. There are three different ways to perform a auto settlement of the sales invoices.

1. By Sales parameter select auto settlement.
2. By select open transaction at the time of invoice posting
3. Through X++ code

1. By Sales parameter select auto settlement: Go to AR/Setup/Parameter under settlement tab you will found a check box for automatic settlement. Select this check box. And your system will auto settle your sales invoice.
clip_image002

This will settle a transaction whenever you post a payment journal.

2. By select open transaction at the time of invoice posting: You can also choose the open transaction at the time of invoice journal creation. At the time of invoicing click on “open transaction settle” button, this will open a new form to select records to be settle from open transaction of that customer.


clip_image004

clip_image006

3. Finally we have code as well (I love this part ;)): So here we are to do some tricky things. Yes, we can do the settlement by X++ code as well. Below code is an example in Job. You can use the same logic for any trigger point in AX.

static void theAxapta_AutosettlePayment(Args _args)
{
CustTable custTable;
CustTrans invCustTrans, payCustTrans;
SpecTransManager manager;
CustVendTransData custVendTransData;
;
custTable = CustTable::find("504411");
// Find the oldest unsettled invoice
select firstonly invCustTrans
order by TransDate asc
where invCustTrans.AccountNum == custTable.AccountNum &&
invCustTrans.TransType == LedgerTransType::Sales &&
!invCustTrans.closed;
// Find the oldest unsettled payment
select firstonly payCustTrans
order by TransDate asc
where payCustTrans.AccountNum == custTable.AccountNum &&
payCustTrans.TransType == LedgerTransType::Payment &&
!payCustTrans.closed;
ttsbegin;
// Create an object of the CustVendTransData class with the invoice transaction as parameter
custVendTransData = CustVendTransData::construct(invCustTrans);
// Mark it for settlement
custVendTransData.markForSettlement(CustTable);
// Create an object of the CustVendTransData class with the payment transaction as parameter
custVendTransData = CustVendTransData::construct(payCustTrans);
//mark it for settlement
custVendTransData.markForSettlement(CustTable);
ttscommit;
// Settle all marked transactions
if(CustTrans::settleTransact(custTable, null, true,
SettleDatePrinc::DaysDate, systemdateget()))
info("Transactions settled");
}

Enjoy…..

- Harry

1 comment:

  1. Thanks for the post its useful for one customer and if possible to extend this to all customers.

    ReplyDelete

Thanks

Note: Only a member of this blog may post a comment.