Customer Summary aging pr G/L Account - wrong results

dabba23
dabba23 Member Posts: 77
Hi,

I have a report that needs to show Customer summary aging pr G/L Account.

First I start with a dataitem of G/L Account in order to combine my detailed cust. ledg. entries with a g/l account:

G/L Account - OnAfterGetRecord
GLEntry.SETCURRENTKEY("G/L Account No.");
GLEntry.SETRANGE("G/L Account No.","No.");
IF GLEntry.FIND('-') THEN
REPEAT
CustLedgEntry.SETCURRENTKEY("Entry No.");
CustLedgEntry.SETRANGE("Entry No.",GLEntry."Entry No.");
IF CustLedgEntry.FIND('-') THEN
REPEAT
DtldCustLedgEntry.SETCURRENTKEY("Cust. Ledger Entry No.");
DtldCustLedgEntry.SETRANGE("Cust. Ledger Entry No.",CustLedgEntry."Entry No.");
DtldCustLedgEntry.SETRANGE("Customer No.",CustLedgEntry."Customer No.");
IF DtldCustLedgEntry.FIND('-') THEN
REPEAT
TempCustLedgEntry."Entry No." := DtldCustLedgEntry."Entry No.";
TempCustLedgEntry.INSERT;
TempCustLedgEntry."Document No." := GLEntry."G/L Account No.";
TempCustLedgEntry."Posting Date" := DtldCustLedgEntry."Posting Date";
TempCustLedgEntry."Customer No." := DtldCustLedgEntry."Customer No.";
TempCustLedgEntry."Initial Entry Due Date" := DtldCustLedgEntry."Initial Entry Due Date";
TempCustLedgEntry."Amount (LCY)" := DtldCustLedgEntry."Amount (LCY)";
TempCustLedgEntry.MODIFY;
UNTIL DtldCustLedgEntry.NEXT = 0;
UNTIL CustLedgEntry.NEXT = 0;
UNTIL GLEntry.NEXT = 0;

when having filled in my temp record, I then create a new dataitem called Customer.
I want for each G/L account show a summary of aging amount pr cust.:

Customer - OnPreDataItem
CurrReport.CREATETOTALS(CustBalanceDueLCY);

Customer - OnAfterGetRecord

PrintCust := FALSE;
FOR i := 1 TO 5 DO BEGIN
TempCustLedgEntry.SETCURRENTKEY("Customer No.","Initial Entry Due Date","Posting Date","Document No.");
TempCustLedgEntry.SETRANGE("Document No.","G/L Account"."No.");
TempCustLedgEntry.SETRANGE("Customer No.","No.");
TempCustLedgEntry.SETRANGE("Posting Date",0D,StartDate);
TempCustLedgEntry.SETRANGE("Initial Entry Due Date",PeriodStartDate,PeriodStartDate[i + 1] - 1);
TempCustLedgEntry.CALCSUMS("Amount (LCY)");
CustBalanceDueLCY := DtldCustLedgEntry."Amount (LCY)";
IF CustBalanceDueLCY <> 0 THEN
PrintCust := TRUE;
END;
IF NOT PrintCust THEN
CurrReport.SKIP;

Report - OnPreReport

However, I get the result of 1000 for each customer and for each period.
The layout of the report is the same as report 109 however I start with showing G/L Account No. first.

What is wrong with my code, since it is not showing correct data? When debugging through my temp record when wanting to sum the amount, I always only see one customer from the temp record. Why is that?