Sunday, November 3, 2019
Settle all cutomer transaction open within sum of AmountMST is zero for Microsoft Dynamic AX 2009 SP1 RU8
static void MyCode_Cust_Settlement_Settle_Zero(Args _args)
{
CustTrans _custTransMark;
CustTable _custTable, _custTableMark;
MyCode_CustTransOpenSumZeroView _transOpenZero;
CustTransOpen _custTransOpen;
AmountCur amountCur,netSettledAmt;
AccountNum custNum;
TransDate asOfDate,settleDate;
CustVendTransData custVendTransData;
CustVendOpenTransManager manager;
Boolean goProcess, isInfolog;
int countCust,countTrans;
;
netSettledAmt = 0;
isInfolog = true;
goProcess = false;
asOfDate = str2date('30-09-2019', 123);
settleDate = str2date('01-10-2019', 123);
/** 1. Get list from customer open transaction view (customized), summarized by AccountNum, having sum AmountMST = 0 **/
while select _transOpenZero
join _custTable
where _transOpenZero.MaxOfTransDate <= asOfDate
&& _custTable.AccountNum == _transOpenZero.AccountNum
&& _custTable.CustGroup == 'CORPORATE'
&& _custTable.AccountNum == 'CUST01'
{
//1.a. Reset marked settlement per customer
countCust++;
if(goProcess)
{
_custTableMark = CustTable::find(_transOpenZero.AccountNum);
manager = CustVendOpenTransManager::construct(_custTableMark);
if (manager.getSpecTransCount() > 0)
manager.resetMarkedTrans();
}
/** 2. Get list customer open transaction per customer **/
while select _custTransOpen
where _custTransOpen.AccountNum == _transOpenZero.AccountNum
{
/** 3. Get CustTrans based on CustTransOpen**/
countTrans++;
select firstonly _custTransMark
where _custTransMark.RecId == _custTransOpen.RefRecId;
//netSettledAmt += _custTransMark.remainAmountCur();
if(isInfolog) info(strfmt("CustTrans %1 %2 %3 %4 %5", _custTransMark.AccountNum,_custTransMark.Voucher, _custTransMark.remainAmountCur(), _custTransMark.Txt, _custTransMark.RecId));
if(goProcess) custVendTransData = CustVendTransData::construct(_custTransMark);
if(goProcess) custVendTransData.markForSettlement(_custTableMark);
}
if(goProcess) CustTrans::settleTransact(_custTableMark, null, true,SettleDatePrinc::SelectDate, settleDate);
}
info(strfmt('Settled done! Customers: %1 Transactions: %2', countCust, countTrans ));
info(strfmt('As of date: %1', asOfDate));
}
{
CustTrans _custTransMark;
CustTable _custTable, _custTableMark;
MyCode_CustTransOpenSumZeroView _transOpenZero;
CustTransOpen _custTransOpen;
AmountCur amountCur,netSettledAmt;
AccountNum custNum;
TransDate asOfDate,settleDate;
CustVendTransData custVendTransData;
CustVendOpenTransManager manager;
Boolean goProcess, isInfolog;
int countCust,countTrans;
;
netSettledAmt = 0;
isInfolog = true;
goProcess = false;
asOfDate = str2date('30-09-2019', 123);
settleDate = str2date('01-10-2019', 123);
/** 1. Get list from customer open transaction view (customized), summarized by AccountNum, having sum AmountMST = 0 **/
while select _transOpenZero
join _custTable
where _transOpenZero.MaxOfTransDate <= asOfDate
&& _custTable.AccountNum == _transOpenZero.AccountNum
&& _custTable.CustGroup == 'CORPORATE'
&& _custTable.AccountNum == 'CUST01'
{
//1.a. Reset marked settlement per customer
countCust++;
if(goProcess)
{
_custTableMark = CustTable::find(_transOpenZero.AccountNum);
manager = CustVendOpenTransManager::construct(_custTableMark);
if (manager.getSpecTransCount() > 0)
manager.resetMarkedTrans();
}
/** 2. Get list customer open transaction per customer **/
while select _custTransOpen
where _custTransOpen.AccountNum == _transOpenZero.AccountNum
{
/** 3. Get CustTrans based on CustTransOpen**/
countTrans++;
select firstonly _custTransMark
where _custTransMark.RecId == _custTransOpen.RefRecId;
//netSettledAmt += _custTransMark.remainAmountCur();
if(isInfolog) info(strfmt("CustTrans %1 %2 %3 %4 %5", _custTransMark.AccountNum,_custTransMark.Voucher, _custTransMark.remainAmountCur(), _custTransMark.Txt, _custTransMark.RecId));
if(goProcess) custVendTransData = CustVendTransData::construct(_custTransMark);
if(goProcess) custVendTransData.markForSettlement(_custTableMark);
}
if(goProcess) CustTrans::settleTransact(_custTableMark, null, true,SettleDatePrinc::SelectDate, settleDate);
}
info(strfmt('Settled done! Customers: %1 Transactions: %2', countCust, countTrans ));
info(strfmt('As of date: %1', asOfDate));
}
List all tables, include Table group description and company status for Microsoft Dynamics AX 2012 R3
static void Z_ListTable(Args _args)
{
TextIo file;
FileName filename = @"F:\TableList.txt";
container con;
FileIoPermission permission;
#File
TableId tableId;
SysDictTable sysDictTable;
TableGroup tableGroupx;
NoYes isPerComp;
String255 tableName;
int tablecounter;
Dictionary dict = new Dictionary();
EnumId Id = enumNum(TableGroup);
DictEnum dictEnum = new DictEnum(Id);
int EnumValue;
;
try
{
permission = new FileIoPermission(filename, #io_write);
permission.assert();
file = new TextIo(filename, #io_write);
if (!file)
throw Exception::Error;
file.outRecordDelimiter(#delimiterCRLF);
file.outFieldDelimiter(";");
for (tablecounter=1; tablecounter<=dict.tableCnt(); tablecounter++)
{
tableId = dict.tableCnt2Id(tablecounter);
sysDictTable = new SysDictTable(tableId);
if (sysDictTable && !sysDictTable.isTmp() && !sysDictTable.isMap())
{
tableGroupx = sysDictTable.tableGroup();
EnumValue = enum2Int(tableGroupx);
isPerComp = sysDictTable.dataPrCompany();
tableName = sysDictTable.name();
con = connull();
con = conins(con, 1, tableName);
con = conins(con, 2, tableGroupx);
con = conins(con, 3, dictEnum.index2Symbol(EnumValue));
con = conins(con, 4, isPerComp);
file.writeExp(con);
}
}
}
catch(Exception::Error)
{
error("You do not have access to write the file to the selected folder");
}
CodeAccessPermission::revertAssert();
info('File Created!');
}
{
TextIo file;
FileName filename = @"F:\TableList.txt";
container con;
FileIoPermission permission;
#File
TableId tableId;
SysDictTable sysDictTable;
TableGroup tableGroupx;
NoYes isPerComp;
String255 tableName;
int tablecounter;
Dictionary dict = new Dictionary();
EnumId Id = enumNum(TableGroup);
DictEnum dictEnum = new DictEnum(Id);
int EnumValue;
;
try
{
permission = new FileIoPermission(filename, #io_write);
permission.assert();
file = new TextIo(filename, #io_write);
if (!file)
throw Exception::Error;
file.outRecordDelimiter(#delimiterCRLF);
file.outFieldDelimiter(";");
for (tablecounter=1; tablecounter<=dict.tableCnt(); tablecounter++)
{
tableId = dict.tableCnt2Id(tablecounter);
sysDictTable = new SysDictTable(tableId);
if (sysDictTable && !sysDictTable.isTmp() && !sysDictTable.isMap())
{
tableGroupx = sysDictTable.tableGroup();
EnumValue = enum2Int(tableGroupx);
isPerComp = sysDictTable.dataPrCompany();
tableName = sysDictTable.name();
con = connull();
con = conins(con, 1, tableName);
con = conins(con, 2, tableGroupx);
con = conins(con, 3, dictEnum.index2Symbol(EnumValue));
con = conins(con, 4, isPerComp);
file.writeExp(con);
}
}
}
catch(Exception::Error)
{
error("You do not have access to write the file to the selected folder");
}
CodeAccessPermission::revertAssert();
info('File Created!');
}
Subscribe to:
Posts (Atom)