I was recently asked to add an Account Summary to the footer of a report in AX 2012, to look something like this:
In my research, I came across a helpful class that allowed me to meet this requirement of calculating customer aging balances in X++ with a minimum of coding effort; the CustVendAgingStatistics class. The calcStatistic method queries StatRepInterval and StatRepIntvervalLine to get the buckets and settings for the calculation, then it writes out the values to tmpAccountSum, which is an InMemory temporary table. Depending on what aging buckets you need, you can use a debugger to figure out which tmpAccountSum records you will want.
For my purpose, I created a new method to calculate the customer’s aging balances using a 30D format (#agingFormat macro). I needed open balances (Balance03) and I opted to store both balance and description in a Map. The integer key was helpful so that I could retrieve the values later and add them to the SalesInvoiceHeaderFooterTmp record in SalesInvoiceDP.insertSalesInvoiceHeaderFooterTmp method. You could easily use a container here, depending on how you are using the aging information.
private void SSI_calcAging(CustInvoiceAccount _invoiceAccount)
custVendTable = CustTable::find(_invoiceAccount);
custVendAgingStats = CustVendAgingStatistics::construct(custVendTable,#agingFormat,
i = 0;
cachedaccountSummary = new Map(Types::Integer,Types::Real);
cachedaccountSummaryTxt = new Map(Types::Integer,Types::String);
while select tmpAccountSumLocal
Obviously, this could be used for Vendor Aging as well. I verified that the values match exactly with the Customer Aging report when it is run with the same parameters.