This is related to a question I asked previously:
How to get customer aging fields from a Netsuite restlet
The technique described in the answer to that question works great, but it doesn't handle credit memos. I'm having problems figuring out how to take credit memos into account.
For example, I have a customer record that displays the following values:
BALANCE
1950.00
OVERDUE BALANCE
2000.00
CURRENT 1-30 DAYS 31-60 DAYS 61-90 DAYS OVER 90 DAYS
0.00 -50.00 2,000.00 0.00 0.00
I can pull the 2000 out just fine, but I can't seem to get the -50 from the credit memo.
I tried adjusting the invoice query to do this:
new nlobjSearchFilter('amountremaining', null, 'notequalto', 0),
I also tried doing a separate query for credit memos:
var agingcmemo = nlapiSearchRecord(
'creditmemo',
null,
[
new nlobjSearchFilter('daysoverdue', null, 'greaterthan', 0),
new nlobjSearchFilter('mainline', null, 'is', 'T'),
new nlobjSearchFilter('amountremaining', null, 'notequalto', 0),
new nlobjSearchFilter('entity', null, 'is', result[0].id)
],
[
new nlobjSearchColumn('entity', null, 'group'),
new nlobjSearchColumn('formulanumeric', null, 'sum').setFormula('case when {daysoverdue} < 31 then {amountremaining} else 0 end'),
new nlobjSearchColumn('formulanumeric', null, 'sum').setFormula('case when {daysoverdue} between 31 and 60 then {amountremaining} else 0 end'),
new nlobjSearchColumn('formulanumeric', null, 'sum').setFormula('case when {daysoverdue} between 61 and 90 then {amountremaining} else 0 end'),
new nlobjSearchColumn('formulanumeric', null, 'sum').setFormula('case when {daysoverdue} > 90 then {amountremaining} else 0 end')
]
);
That query returns no rows. If I remove all conditions except for the entity it returns two rows, neither of which is the actual credit memo.
Anyone have any ideas on how to get those right numbers including the credit memos?