AX2009 Settle Customer Open Transcation
TL;DR: AX2009 Settle Customer Open Transcation with X++
Description
We have sometimes the problem in AX2009 that a voucher was posted the settle an open transaction of a customer but only a partial amount has been settled. So the job search all open transaction that should have been closed and settles them.
AX2009 Job
static void down1_SettleCustOpenTransactions(Args _args)
{
SpecTransManager lclsSpecTransManager;
CustTrans ltabCustTrans, ltabCustTransSelect;
CustTrans ltabCustTransSecond;
CustTransOpen ltabCustTransOpen, ltabCustTransOpenSelect;
CustSettlement ltabCustSettlement;
CustTable ltabCustTable;
boolean lbolSettle;
Set lsetRecIds = new Set(Types::Int64);
int i;
;
while select ltabCustTable
exists join ltabCustTransSelect
where ltabCustTransSelect.AccountNum == ltabCustTable.AccountNum
exists join ltabCustTransOpenSelect
where ltabCustTransOpenSelect.AccountNum == ltabCustTable.AccountNum
&& ltabCustTransSelect.RecId == ltabCustTransOpenSelect.RefRecId
&& ltabCustTransSelect.AmountCur != ltabCustTransOpenSelect.AmountCur
{
i++; print i;
lbolSettle = false;
while select ltabCustTrans
where ltabCustTrans.Invoice
&& ltabCustTrans.AccountNum == ltabCustTable.AccountNum
&& ltabCustTrans.AmountCur > 0
join firstOnly ltabCustTransOpen
where ltabCustTransOpen.RefRecId == ltabCustTrans.RecId
join firstOnly ltabCustSettlement
where ltabCustSettlement.TransRecId == ltabCustTrans.RecId
join firstOnly ltabCustTransSecond
where ltabCustTransSecond.AccountNum == ltabCustTrans.AccountNum
&& ltabCustTransSecond.Voucher == ltabCustSettlement.OffsetTransVoucher
{
if (lsetRecIds.in(ltabCustTrans.RecId))
continue;
if (ltabCustTransOpen && abs(ltabCustTrans.remainAmountCur()) && abs(ltabCustTrans.remainAmountCur()) == abs(ltabCustTransSecond.remainAmountCur()))
{
lclsSpecTransManager = SpecTransManager::construct(ltabCustTable);
lclsSpecTransManager.insert(curExt(), tableNum(CustTransOpen), ltabCustTransSecond.transOpen().RecId, ltabCustTransSecond.remainAmountCur(), ltabCustTransSecond.CurrencyCode);
lclsSpecTransManager.insert(curExt(), tableNum(CustTransOpen), ltabCustTrans.transOpen().RecId, ltabCustTrans.remainAmountCur(), ltabCustTransSecond.CurrencyCode);
lbolSettle = true;
}
lsetRecIds.add(ltabCustTrans.RecId);
}
if (lbolSettle)
{
info(ltabCustTable.AccountNum);
CustTrans::settleTransact(ltabCustTable, null, true, SettleDatePrinc::SelectDate, systemDateGet());
}
}
}
If you enjoyed this post, you might also enjoy:
- AX2009 Recalculate Vendor Cash Disc
- D365 F&O Replenishment Template Lines - set product queries by code
- AX2009 Cancel SalesOrder with empty SalesLine
- AX2009 Restore deleted sales table without restoring sales line
- AX2009 Create picking list
- D365 F&O IOrganizationService for Dataverse
- D365 F&O Custom Work Types
MS Dynamics AX / D365 FO developer with experience in administration, developing new and adjusting the existing solutions in the Dynamics AX 2009, AX 2012, D365 FO. Ability to support all phases of implementation of project, starting with design, development, final deployment and administration. Responsible team member always looking for new challenges with experience from international projects in Austria, Germany and Switzerland. Experience in implementation of external service to MS Dynamcis AX / D365, like cash registers and warehouse automations. More about the author →