# Auto settlement sample code

**URL:** https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502
**Category:** Developer Forum
**Created:** [March 13, 2013, 2:28am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502 "2013-03-13T02:28:37Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![eity\_182](https://avatars.discourse-cdn.com/v4/letter/e/50afbb/32.png) [@eity\_182](https://www.dynamicsuser.net/u/eity_182)
#### Post date: [March 13, 2013, 2:28am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/1 "2013-03-13T02:28:37Z")

</div>

Hi all,

Anybody have done for auto settlement?may i know how the code design, because my current code its still not function…  
i need to know by refer the sample…  
somebody can share? ☹

---

<div class="post-metadata">

### Author: ![aedula](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@aedula](https://www.dynamicsuser.net/u/aedula)
#### Post date: [March 13, 2013, 6:29am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/2 "2013-03-13T06:29:28Z")

</div>

Hi,

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”);  
}

---

<div class="post-metadata">

### Author: ![eity\_182](https://avatars.discourse-cdn.com/v4/letter/e/50afbb/32.png) [@eity\_182](https://www.dynamicsuser.net/u/eity_182)
#### Post date: [March 14, 2013, 2:28am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/3 "2013-03-14T02:28:00Z")

</div>

hi chatiya,

Thanks for ur reply…

i have using the same code. but after i running, its still appear the balance (-200).  
is it use the different table or use the custTable as well?

---

<div class="post-metadata">

### Author: ![Sikander](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sikander](https://www.dynamicsuser.net/u/Sikander)
#### Post date: [January 27, 2016, 8:49am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/4 "2016-01-27T08:49:05Z")

</div>

Dear ,

This Code is not Working.

---

<div class="post-metadata">

### Author: ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)
#### Post date: [January 27, 2016, 10:24am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/5 "2016-01-27T10:24:26Z")

</div>

You can use, \Classes\CustVendOpenTransManager

---

<div class="post-metadata">

### Author: ![Sikander](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sikander](https://www.dynamicsuser.net/u/Sikander)
#### Post date: [January 27, 2016, 10:40am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/6 "2016-01-27T10:40:29Z")

</div>

Hi kran…

I did’nt get your point please explain

---

<div class="post-metadata">

### Author: ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)
#### Post date: [January 27, 2016, 10:45am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/7 "2016-01-27T10:45:55Z")

</div>

You can use that class to settle the open transactions.

---

<div class="post-metadata">

### Author: ![Sikander](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sikander](https://www.dynamicsuser.net/u/Sikander)
#### Post date: [January 27, 2016, 10:54am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/8 "2016-01-27T10:54:40Z")

</div>

Dear Kran sorry tom ask u again how to change & where to change these codes given above.

☹

---

<div class="post-metadata">

### Author: ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)
#### Post date: [January 27, 2016, 11:02am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/9 "2016-01-27T11:02:56Z")

</div>

Can you please create a separate post and explain your problem/requirement?

---

<div class="post-metadata">

### Author: ![Sikander](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sikander](https://www.dynamicsuser.net/u/Sikander)
#### Post date: [January 27, 2016, 11:18am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/10 "2016-01-27T11:18:32Z")

</div>

I want o settle customer invoices & payments automatically with X++ codes ,I applies below codes but it does not work.Any modification required?

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”);  
}

---

<div class="post-metadata">

### Author: ![Sikander](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sikander](https://www.dynamicsuser.net/u/Sikander)
#### Post date: [January 27, 2016, 11:21am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/11 "2016-01-27T11:21:33Z")

</div>

I want to settle customer payments & invoices but it is not working, does any modification required.

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”);  
}

---

<div class="post-metadata">

### Author: ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)
#### Post date: [January 28, 2016, 6:48am UTC](https://www.dynamicsuser.net/t/auto-settlement-sample-code/44502/12 "2016-01-28T06:48:04Z")

</div>

My suggestion is to use the class i mentioned (to know how to use that class, see the cross references).
