Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Aged Account Receivable

(0) ShareShare
ReportReport
Posted on by 190

Hello Experts,

how can we add 2 more slots to the Aged account Receivable report (120), Means, 0-90, 91-180, 180-270,271-360 and 361 and above.

report 120 "Aged Accounts Receivable"
{
    DefaultLayout = RDLC;
    RDLCLayout = './AgedAccountsReceivable.rdlc';
    ApplicationArea = Basic, Suite;
    Caption = 'Aged Accounts Receivable';
    PreviewMode = PrintLayout;
    UsageCategory = ReportsAndAnalysis;
    DataAccessIntent = ReadOnly;

    dataset
    {
        dataitem(Header; "Integer")
        {
            DataItemTableView = SORTING(Number) WHERE(Number = CONST(1));
            column(CompanyName; CompanyDisplayName)
            {
            }
            column(FormatEndingDate; StrSubstNo(Text006, Format(EndingDate, 0, 4)))
            {
            }
            column(PostingDate; StrSubstNo(Text007, SelectStr(AgingBy   1, Text009)))
            {
            }
            column(PrintAmountInLCY; PrintAmountInLCY)
            {
            }
            column(TableCaptnCustFilter; Customer.TableCaption   ': '   CustFilter)
            {
            }
            column(CustFilter; CustFilter)
            {
            }
            column(AgingByDueDate; AgingBy = AgingBy::"Due Date")
            {
            }
            column(AgedbyDocumnetDate; StrSubstNo(Text004, SelectStr(AgingBy   1, Text009)))
            {
            }
            column(HeaderText5; HeaderText[5])
            {
            }
            column(HeaderText4; HeaderText[4])
            {
            }
            column(HeaderText3; HeaderText[3])
            {
            }
            column(HeaderText2; HeaderText[2])
            {
            }
            column(HeaderText1; HeaderText[1])
            {
            }
            column(PrintDetails; PrintDetails)
            {
            }
            column(AgedAccReceivableCptn; AgedAccReceivableCptnLbl)
            {
            }
            column(CurrReportPageNoCptn; CurrReportPageNoCptnLbl)
            {
            }
            column(AllAmtinLCYCptn; AllAmtinLCYCptnLbl)
            {
            }
            column(AgedOverdueAmtCptn; AgedOverdueAmtCptnLbl)
            {
            }
            column(CLEEndDateAmtLCYCptn; CLEEndDateAmtLCYCptnLbl)
            {
            }
            column(CLEEndDateDueDateCptn; CLEEndDateDueDateCptnLbl)
            {
            }
            column(CLEEndDateDocNoCptn; CLEEndDateDocNoCptnLbl)
            {
            }
            column(CLEEndDatePstngDateCptn; CLEEndDatePstngDateCptnLbl)
            {
            }
            column(CLEEndDateDocTypeCptn; CLEEndDateDocTypeCptnLbl)
            {
            }
            column(OriginalAmtCptn; OriginalAmtCptnLbl)
            {
            }
            column(TotalLCYCptn; TotalLCYCptnLbl)
            {
            }
            column(NewPagePercustomer; NewPagePercustomer)
            {
            }
            column(GrandTotalCLE5RemAmt; GrandTotalCustLedgEntry[5]."Remaining Amt. (LCY)")
            {
                AutoFormatType = 1;
            }
            column(GrandTotalCLE4RemAmt; GrandTotalCustLedgEntry[4]."Remaining Amt. (LCY)")
            {
                AutoFormatType = 1;
            }
            column(GrandTotalCLE3RemAmt; GrandTotalCustLedgEntry[3]."Remaining Amt. (LCY)")
            {
                AutoFormatType = 1;
            }
            column(GrandTotalCLE2RemAmt; GrandTotalCustLedgEntry[2]."Remaining Amt. (LCY)")
            {
                AutoFormatType = 1;
            }
            column(GrandTotalCLE1RemAmt; GrandTotalCustLedgEntry[1]."Remaining Amt. (LCY)")
            {
                AutoFormatType = 1;
            }
            column(GrandTotalCLEAmtLCY; GrandTotalCustLedgEntry[1]."Amount (LCY)")
            {
                AutoFormatType = 1;
            }
            column(GrandTotalCLE1CustRemAmtLCY; Pct(GrandTotalCustLedgEntry[1]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
            {
            }
            column(GrandTotalCLE2CustRemAmtLCY; Pct(GrandTotalCustLedgEntry[2]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
            {
            }
            column(GrandTotalCLE3CustRemAmtLCY; Pct(GrandTotalCustLedgEntry[3]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
            {
            }
            column(GrandTotalCLE4CustRemAmtLCY; Pct(GrandTotalCustLedgEntry[4]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
            {
            }
            column(GrandTotalCLE5CustRemAmtLCY; Pct(GrandTotalCustLedgEntry[5]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
            {
            }
            column(GrandTotalCLE1AmtLCY; GrandTotalCustLedgEntry[1]."Amount (LCY)")
            {
                AutoFormatType = 1;
            }
            column(GrandTotalCLE5PctRemAmtLCY; Pct(GrandTotalCustLedgEntry[5]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
            {
            }
            column(GrandTotalCLE3PctRemAmtLCY; Pct(GrandTotalCustLedgEntry[3]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
            {
            }
            column(GrandTotalCLE2PctRemAmtLCY; Pct(GrandTotalCustLedgEntry[2]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
            {
            }
            column(GrandTotalCLE1PctRemAmtLCY; Pct(GrandTotalCustLedgEntry[1]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
            {
            }
            column(GrandTotalCLE5RemAmtLCY; GrandTotalCustLedgEntry[5]."Remaining Amt. (LCY)")
            {
                AutoFormatType = 1;
            }
            column(GrandTotalCLE4RemAmtLCY; GrandTotalCustLedgEntry[4]."Remaining Amt. (LCY)")
            {
                AutoFormatType = 1;
            }
            column(GrandTotalCLE3RemAmtLCY; GrandTotalCustLedgEntry[3]."Remaining Amt. (LCY)")
            {
                AutoFormatType = 1;
            }
            column(GrandTotalCLE2RemAmtLCY; GrandTotalCustLedgEntry[2]."Remaining Amt. (LCY)")
            {
                AutoFormatType = 1;
            }
            column(GrandTotalCLE1RemAmtLCY; GrandTotalCustLedgEntry[1]."Remaining Amt. (LCY)")
            {
                AutoFormatType = 1;
            }
            dataitem(Customer; Customer)
            {
                RequestFilterFields = "No.";
                column(PageGroupNo; PageGroupNo)
                {
                }
                column(CustomerPhoneNoCaption; FieldCaption("Phone No."))
                {
                }
                column(CustomerContactCaption; FieldCaption(Contact))
                {
                }
                dataitem("Cust. Ledger Entry"; "Cust. Ledger Entry")
                {
                    DataItemLink = "Customer No." = FIELD("No.");
                    DataItemTableView = SORTING("Customer No.", "Posting Date", "Currency Code");

                    trigger OnAfterGetRecord()
                    var
                        CustLedgEntry: Record "Cust. Ledger Entry";
                    begin
                        CustLedgEntry.SetCurrentKey("Closed by Entry No.");
                        if "Closed by Entry No." <> 0 then
                            CustLedgEntry.SetFilter("Closed by Entry No.", '%1|%2', "Entry No.", "Closed by Entry No.")
                        else
                            CustLedgEntry.SetRange("Closed by Entry No.", "Entry No.");
                        CustLedgEntry.SetRange("Posting Date", 0D, EndingDate);
                        CopyDimFiltersFromCustomer(CustLedgEntry);
                        if CustLedgEntry.FindSet(false, false) then
                            repeat
                                InsertTemp(CustLedgEntry);
                            until CustLedgEntry.Next() = 0;

                        CustLedgEntry.Reset();
                        CustLedgEntry.SetRange("Entry No.", "Closed by Entry No.");
                        CustLedgEntry.SetRange("Posting Date", 0D, EndingDate);
                        CopyDimFiltersFromCustomer(CustLedgEntry);
                        if CustLedgEntry.FindSet(false, false) then
                            repeat
                                InsertTemp(CustLedgEntry);
                            until CustLedgEntry.Next() = 0;
                        CurrReport.Skip();
                    end;

                    trigger OnPreDataItem()
                    begin
                        SetRange("Posting Date", EndingDate   1, DMY2Date(31, 12, 9999));
                        CopyDimFiltersFromCustomer("Cust. Ledger Entry");
                        Customer.CopyFilter("Currency Filter", "Currency Code");
                    end;
                }
                dataitem(OpenCustLedgEntry; "Cust. Ledger Entry")
                {
                    DataItemLink = "Customer No." = FIELD("No.");
                    DataItemTableView = SORTING("Customer No.", Open, Positive, "Due Date", "Currency Code");

                    trigger OnAfterGetRecord()
                    begin
                        InsertTemp(OpenCustLedgEntry);
                        CurrReport.Skip();
                    end;

                    trigger OnPreDataItem()
                    begin
                        if AgingBy = AgingBy::"Posting Date" then begin
                            SetRange("Posting Date", 0D, EndingDate);
                            SetRange("Date Filter", 0D, EndingDate);
                            SetAutoCalcFields("Remaining Amt. (LCY)");
                            SetFilter("Remaining Amt. (LCY)", '<>0');
                        end;
                        CopyDimFiltersFromCustomer(OpenCustLedgEntry);
                        Customer.CopyFilter("Currency Filter", "Currency Code");
                    end;
                }
                dataitem(CurrencyLoop; "Integer")
                {
                    DataItemTableView = SORTING(Number) WHERE(Number = FILTER(1 ..));
                    PrintOnlyIfDetail = true;
                    dataitem(TempCustLedgEntryLoop; "Integer")
                    {
                        DataItemTableView = SORTING(Number) WHERE(Number = FILTER(1 ..));
                        column(Name1_Cust; Customer.Name)
                        {
                            IncludeCaption = true;
                        }
                        column(No_Cust; Customer."No.")
                        {
                            IncludeCaption = true;
                        }
                        column(CustomerPhoneNo; Customer."Phone No.")
                        {
                        }
                        column(CustomerContactName; Customer.Contact)
                        {
                        }
                        column(CLEEndDateRemAmtLCY; CustLedgEntryEndingDate."Remaining Amt. (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(AgedCLE1RemAmtLCY; AgedCustLedgEntry[1]."Remaining Amt. (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(AgedCLE2RemAmtLCY; AgedCustLedgEntry[2]."Remaining Amt. (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(AgedCLE3RemAmtLCY; AgedCustLedgEntry[3]."Remaining Amt. (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(AgedCLE4RemAmtLCY; AgedCustLedgEntry[4]."Remaining Amt. (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(AgedCLE5RemAmtLCY; AgedCustLedgEntry[5]."Remaining Amt. (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(CLEEndDateAmtLCY; CustLedgEntryEndingDate."Amount (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(CLEEndDueDate; Format(CustLedgEntryEndingDate."Due Date"))
                        {
                        }
                        column(CLEEndDateDocNo; CustLedgEntryEndingDate."Document No.")
                        {
                        }
                        column(CLEDocType; Format(CustLedgEntryEndingDate."Document Type"))
                        {
                        }
                        column(CLEPostingDate; Format(CustLedgEntryEndingDate."Posting Date"))
                        {
                        }
                        column(AgedCLE5TempRemAmt; AgedCustLedgEntry[5]."Remaining Amount")
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(AgedCLE4TempRemAmt; AgedCustLedgEntry[4]."Remaining Amount")
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(AgedCLE3TempRemAmt; AgedCustLedgEntry[3]."Remaining Amount")
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(AgedCLE2TempRemAmt; AgedCustLedgEntry[2]."Remaining Amount")
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(AgedCLE1TempRemAmt; AgedCustLedgEntry[1]."Remaining Amount")
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(RemAmt_CLEEndDate; CustLedgEntryEndingDate."Remaining Amount")
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(CLEEndDate_ExtDocNo; CustLedgEntryEndingDate."External Document No.")
                        {

                        }
                        column(CLEEndDate; CustLedgEntryEndingDate.Amount)
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(Name_Cust; StrSubstNo(Text005, Customer.Name))
                        {
                        }
                        column(TotalCLE1AmtLCY; TotalCustLedgEntry[1]."Amount (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(TotalCLE1RemAmtLCY; TotalCustLedgEntry[1]."Remaining Amt. (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(TotalCLE2RemAmtLCY; TotalCustLedgEntry[2]."Remaining Amt. (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(TotalCLE3RemAmtLCY; TotalCustLedgEntry[3]."Remaining Amt. (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(TotalCLE4RemAmtLCY; TotalCustLedgEntry[4]."Remaining Amt. (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(TotalCLE5RemAmtLCY; TotalCustLedgEntry[5]."Remaining Amt. (LCY)")
                        {
                            AutoFormatType = 1;
                        }
                        column(CurrrencyCode; CurrencyCode)
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(TotalCLE5RemAmt; TotalCustLedgEntry[5]."Remaining Amount")
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(TotalCLE4RemAmt; TotalCustLedgEntry[4]."Remaining Amount")
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(TotalCLE3RemAmt; TotalCustLedgEntry[3]."Remaining Amount")
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(TotalCLE2RemAmt; TotalCustLedgEntry[2]."Remaining Amount")
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(TotalCLE1RemAmt; TotalCustLedgEntry[1]."Remaining Amount")
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(TotalCLE1Amt; TotalCustLedgEntry[1].Amount)
                        {
                            AutoFormatExpression = CurrencyCode;
                            AutoFormatType = 1;
                        }
                        column(TotalCheck; CustFilterCheck)
                        {
                        }

                        trigger OnAfterGetRecord()
                        var
                            PeriodIndex: Integer;
                        begin
                            if Number = 1 then begin
                                if not TempCustLedgEntry.FindSet(false, false) then
                                    CurrReport.Break();
                            end else
                                if TempCustLedgEntry.Next() = 0 then
                                    CurrReport.Break();

                            CustLedgEntryEndingDate := TempCustLedgEntry;
                            DetailedCustomerLedgerEntry.SetRange("Cust. Ledger Entry No.", CustLedgEntryEndingDate."Entry No.");
                            OnTempCustLedgEntryGetRecordOnAfterSetDetailedEntryFilters(DetailedCustomerLedgerEntry);
                            if DetailedCustomerLedgerEntry.FindSet(false, false) then
                                repeat
                                    if (DetailedCustomerLedgerEntry."Entry Type" =
                                        DetailedCustomerLedgerEntry."Entry Type"::"Initial Entry") and
                                       (CustLedgEntryEndingDate."Posting Date" > EndingDate) and
                                       (AgingBy <> AgingBy::"Posting Date")
                                    then begin
                                        if CustLedgEntryEndingDate."Document Date" <= EndingDate then
                                            DetailedCustomerLedgerEntry."Posting Date" :=
                                              CustLedgEntryEndingDate."Document Date"
                                        else
                                            if (CustLedgEntryEndingDate."Due Date" <= EndingDate) and
                                               (AgingBy = AgingBy::"Due Date")
                                            then
                                                DetailedCustomerLedgerEntry."Posting Date" :=
                                                  CustLedgEntryEndingDate."Due Date"
                                    end;

                                    if (DetailedCustomerLedgerEntry."Posting Date" <= EndingDate) or
                                       (TempCustLedgEntry.Open and
                                        (AgingBy = AgingBy::"Due Date") and
                                        (CustLedgEntryEndingDate."Due Date" > EndingDate) and
                                        (CustLedgEntryEndingDate."Posting Date" <= EndingDate))
                                    then begin
                                        if DetailedCustomerLedgerEntry."Entry Type" in
                                           [DetailedCustomerLedgerEntry."Entry Type"::"Initial Entry",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Unrealized Loss",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Unrealized Gain",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Realized Loss",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Realized Gain",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount (VAT Excl.)",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount (VAT Adjustment)",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Payment Tolerance",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount Tolerance",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Payment Tolerance (VAT Excl.)",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Payment Tolerance (VAT Adjustment)",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount Tolerance (VAT Excl.)",
                                            DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount Tolerance (VAT Adjustment)"]
                                        then begin
                                            CustLedgEntryEndingDate.Amount := CustLedgEntryEndingDate.Amount   DetailedCustomerLedgerEntry.Amount;
                                            CustLedgEntryEndingDate."Amount (LCY)" :=
                                              CustLedgEntryEndingDate."Amount (LCY)"   DetailedCustomerLedgerEntry."Amount (LCY)";
                                        end;
                                        if DetailedCustomerLedgerEntry."Posting Date" <= EndingDate then begin
                                            CustLedgEntryEndingDate."Remaining Amount" :=
                                              CustLedgEntryEndingDate."Remaining Amount"   DetailedCustomerLedgerEntry.Amount;
                                            CustLedgEntryEndingDate."Remaining Amt. (LCY)" :=
                                              CustLedgEntryEndingDate."Remaining Amt. (LCY)"   DetailedCustomerLedgerEntry."Amount (LCY)";
                                        end;
                                    end;
                                until DetailedCustomerLedgerEntry.Next() = 0;

                            if CustLedgEntryEndingDate."Remaining Amount" = 0 then
                                CurrReport.Skip();

                            case AgingBy of
                                AgingBy::"Due Date":
                                    PeriodIndex := GetPeriodIndex(CustLedgEntryEndingDate."Due Date");
                                AgingBy::"Posting Date":
                                    PeriodIndex := GetPeriodIndex(CustLedgEntryEndingDate."Posting Date");
                                AgingBy::"Document Date":
                                    begin
                                        if CustLedgEntryEndingDate."Document Date" > EndingDate then begin
                                            CustLedgEntryEndingDate."Remaining Amount" := 0;
                                            CustLedgEntryEndingDate."Remaining Amt. (LCY)" := 0;
                                            CustLedgEntryEndingDate."Document Date" := CustLedgEntryEndingDate."Posting Date";
                                        end;
                                        PeriodIndex := GetPeriodIndex(CustLedgEntryEndingDate."Document Date");
                                    end;
                            end;
                            Clear(AgedCustLedgEntry);
                            AgedCustLedgEntry[PeriodIndex]."Remaining Amount" := CustLedgEntryEndingDate."Remaining Amount";
                            AgedCustLedgEntry[PeriodIndex]."Remaining Amt. (LCY)" := CustLedgEntryEndingDate."Remaining Amt. (LCY)";
                            TotalCustLedgEntry[PeriodIndex]."Remaining Amount"  = CustLedgEntryEndingDate."Remaining Amount";
                            TotalCustLedgEntry[PeriodIndex]."Remaining Amt. (LCY)"  = CustLedgEntryEndingDate."Remaining Amt. (LCY)";
                            GrandTotalCustLedgEntry[PeriodIndex]."Remaining Amt. (LCY)"  = CustLedgEntryEndingDate."Remaining Amt. (LCY)";
                            TotalCustLedgEntry[1].Amount  = CustLedgEntryEndingDate."Remaining Amount";
                            TotalCustLedgEntry[1]."Amount (LCY)"  = CustLedgEntryEndingDate."Remaining Amt. (LCY)";
                            GrandTotalCustLedgEntry[1]."Amount (LCY)"  = CustLedgEntryEndingDate."Remaining Amt. (LCY)";
                            NumberOfLines  = 1;
                        end;

                        trigger OnPostDataItem()
                        begin
                            if not PrintAmountInLCY then
                                UpdateCurrencyTotals;
                        end;

                        trigger OnPreDataItem()
                        begin
                            if not PrintAmountInLCY then begin
                                if (TempCurrency.Code = '') or (TempCurrency.Code = GLSetup."LCY Code") then
                                    TempCustLedgEntry.SetFilter("Currency Code", '%1|%2', GLSetup."LCY Code", '')
                                else
                                    TempCustLedgEntry.SetRange("Currency Code", TempCurrency.Code);
                            end;

                            PageGroupNo := NextPageGroupNo;
                            if NewPagePercustomer and (NumberOfCurrencies > 0) then
                                NextPageGroupNo := PageGroupNo   1;
                        end;
                    }

                    trigger OnAfterGetRecord()
                    begin
                        Clear(TotalCustLedgEntry);

                        if Number = 1 then begin
                            if not TempCurrency.FindSet(false, false) then begin
                                CurrReport.Break();
                                NumberOfLines -= 1;
                            end;
                        end else
                            if TempCurrency.Next() = 0 then begin
                                CurrReport.Break();
                                NumberOfLines -= 1;
                            end;

                        if TempCurrency.Code <> '' then
                            CurrencyCode := TempCurrency.Code
                        else
                            CurrencyCode := GLSetup."LCY Code";

                        NumberOfCurrencies := NumberOfCurrencies   1;
                    end;

                    trigger OnPreDataItem()
                    begin
                        NumberOfCurrencies := 0;
                    end;
                }

                trigger OnAfterGetRecord()
                begin
                    if NewPagePercustomer then
                        PageGroupNo  = 1;
                    TempCurrency.Reset();
                    TempCurrency.DeleteAll();
                    TempCustLedgEntry.Reset();
                    TempCustLedgEntry.DeleteAll();
                    NumberOfLines  = 1;
                end;
            }
            dataitem(CurrencyTotals; "Integer")
            {
                DataItemTableView = SORTING(Number) WHERE(Number = FILTER(1 ..));
                column(CurrNo; Number = 1)
                {
                }
                column(TempCurrCode; TempCurrency2.Code)
                {
                    AutoFormatExpression = CurrencyCode;
                    AutoFormatType = 1;
                }
                column(AgedCLE6RemAmt; AgedCustLedgEntry[6]."Remaining Amount")
                {
                    AutoFormatExpression = CurrencyCode;
                    AutoFormatType = 1;
                }
                column(AgedCLE1RemAmt; AgedCustLedgEntry[1]."Remaining Amount")
                {
                    AutoFormatExpression = CurrencyCode;
                    AutoFormatType = 1;
                }
                column(AgedCLE2RemAmt; AgedCustLedgEntry[2]."Remaining Amount")
                {
                    AutoFormatExpression = CurrencyCode;
                    AutoFormatType = 1;
                }
                column(AgedCLE3RemAmt; AgedCustLedgEntry[3]."Remaining Amount")
                {
                    AutoFormatExpression = CurrencyCode;
                    AutoFormatType = 1;
                }
                column(AgedCLE4RemAmt; AgedCustLedgEntry[4]."Remaining Amount")
                {
                    AutoFormatExpression = CurrencyCode;
                    AutoFormatType = 1;
                }
                column(AgedCLE5RemAmt; AgedCustLedgEntry[5]."Remaining Amount")
                {
                    AutoFormatExpression = CurrencyCode;
                    AutoFormatType = 1;
                }
                column(CurrSpecificationCptn; CurrSpecificationCptnLbl)
                {
                }

                trigger OnAfterGetRecord()
                begin
                    if Number = 1 then begin
                        if not TempCurrency2.FindSet(false, false) then
                            CurrReport.Break();
                    end else
                        if TempCurrency2.Next() = 0 then
                            CurrReport.Break();

                    Clear(AgedCustLedgEntry);
                    TempCurrencyAmount.SetRange("Currency Code", TempCurrency2.Code);
                    if TempCurrencyAmount.FindSet(false, false) then
                        repeat
                            if TempCurrencyAmount.Date <> DMY2Date(31, 12, 9999) then
                                AgedCustLedgEntry[GetPeriodIndex(TempCurrencyAmount.Date)]."Remaining Amount" :=
                                  TempCurrencyAmount.Amount
                            else
                                AgedCustLedgEntry[6]."Remaining Amount" := TempCurrencyAmount.Amount;
                        until TempCurrencyAmount.Next() = 0;
                end;
            }
        }
    }

    requestpage
    {
        SaveValues = true;

        layout
        {
            area(content)
            {
                group(Options)
                {
                    Caption = 'Options';
                    field(AgedAsOf; EndingDate)
                    {
                        ApplicationArea = Basic, Suite;
                        Caption = 'Aged As Of';
                        ToolTip = 'Specifies the date that you want the aging calculated for.';
                    }
                    field(Agingby; AgingBy)
                    {
                        ApplicationArea = Basic, Suite;
                        Caption = 'Aging by';
                        OptionCaption = 'Due Date,Posting Date,Document Date';
                        ToolTip = 'Specifies if the aging will be calculated from the due date, the posting date, or the document date.';
                    }
                    field(PeriodLength; PeriodLength)
                    {
                        ApplicationArea = Basic, Suite;
                        Caption = 'Period Length';
                        ToolTip = 'Specifies the period for which data is shown in the report. For example, enter "1M" for one month, "30D" for thirty days, "3Q" for three quarters, or "5Y" for five years.';
                    }
                    field(AmountsinLCY; PrintAmountInLCY)
                    {
                        ApplicationArea = Basic, Suite;
                        Caption = 'Print Amounts in LCY';
                        ToolTip = 'Specifies if you want the report to specify the aging per customer ledger entry.';
                    }
                    field(PrintDetails; PrintDetails)
                    {
                        ApplicationArea = Basic, Suite;
                        Caption = 'Print Details';
                        ToolTip = 'Specifies if you want the report to show the detailed entries that add up the total balance for each customer.';
                    }
                    field(HeadingType; HeadingType)
                    {
                        ApplicationArea = Basic, Suite;
                        Caption = 'Heading Type';
                        OptionCaption = 'Date Interval,Number of Days';
                        ToolTip = 'Specifies if the column heading for the three periods will indicate a date interval or the number of days overdue.';
                    }
                    field(perCustomer; NewPagePercustomer)
                    {
                        ApplicationArea = Basic, Suite;
                        Caption = 'New Page per Customer';
                        ToolTip = 'Specifies if each customer''s information is printed on a new page if you have chosen two or more customers to be included in the report.';
                    }
                }
            }
        }

        actions
        {
        }

        trigger OnOpenPage()
        begin
            if EndingDate = 0D then
                EndingDate := WorkDate;
            if Format(PeriodLength) = '' then
                Evaluate(PeriodLength, '');
        end;
    }

    labels
    {
        BalanceCaption = 'Balance';
    }

    trigger OnPreReport()
    var
        FormatDocument: Codeunit "Format Document";
    begin
        StartDateTime := CurrentDateTime();
        CustFilter := FormatDocument.GetRecordFiltersWithCaptions(Customer);

        GLSetup.Get();

        CalcDates;
        CreateHeadings;

        PageGroupNo := 1;
        NextPageGroupNo := 1;
        CustFilterCheck := (CustFilter <> 'No.');

        CompanyDisplayName := COMPANYPROPERTY.DisplayName;
    end;

    trigger OnPostReport()
    begin
        FinishDateTime := CurrentDateTime();
        LogReportTelemetry(StartDateTime, FinishDateTime, NumberOfLines);
    end;

    var
        GLSetup: Record "General Ledger Setup";
        CustLedgEntryEndingDate: Record "Cust. Ledger Entry";
        TotalCustLedgEntry: array[5] of Record "Cust. Ledger Entry";
        GrandTotalCustLedgEntry: array[5] of Record "Cust. Ledger Entry";
        AgedCustLedgEntry: array[6] of Record "Cust. Ledger Entry";
        TempCurrency: Record Currency temporary;
        TempCurrency2: Record Currency temporary;
        TempCurrencyAmount: Record "Currency Amount" temporary;
        DetailedCustomerLedgerEntry: Record "Detailed Cust. Ledg. Entry";
        CustFilter: Text;
        PrintAmountInLCY: Boolean;
        EndingDate: Date;
        AgingBy: Option "Due Date","Posting Date","Document Date";
        PeriodLength: DateFormula;
        PrintDetails: Boolean;
        HeadingType: Option "Date Interval","Number of Days";
        NewPagePercustomer: Boolean;
        PeriodStartDate: array[5] of Date;
        PeriodEndDate: array[5] of Date;
        HeaderText: array[5] of Text[30];
        Text000: Label 'Not Due';
        BeforeTok: Label 'Before';
        CurrencyCode: Code[10];
        Text002: Label 'days';
        Text004: Label 'Aged by %1';
        Text005: Label 'Total for %1';
        Text006: Label 'Aged as of %1';
        Text007: Label 'Aged by %1';
        NumberOfCurrencies: Integer;
        Text009: Label 'Due Date,Posting Date,Document Date';
        Text010: Label 'The Date Formula %1 cannot be used. Try to restate it. E.g. 1M CM instead of CM 1M.';
        PageGroupNo: Integer;
        NextPageGroupNo: Integer;
        CustFilterCheck: Boolean;
        Text032Txt: Label '-%1', Comment = 'Negating the period length: %1 is the period length';
        AgedAccReceivableCptnLbl: Label 'Aged Accounts Receivable';
        CurrReportPageNoCptnLbl: Label 'Page';
        AllAmtinLCYCptnLbl: Label 'All Amounts in LCY';
        AgedOverdueAmtCptnLbl: Label 'Aged Overdue Amounts';
        CLEEndDateAmtLCYCptnLbl: Label 'Original Amount ';
        CLEEndDateDueDateCptnLbl: Label 'Due Date';
        CLEEndDateDocNoCptnLbl: Label 'Document No.';
        CLEEndDatePstngDateCptnLbl: Label 'Posting Date';
        CLEEndDateDocTypeCptnLbl: Label 'Document Type';
        OriginalAmtCptnLbl: Label 'Currency Code';
        TotalLCYCptnLbl: Label 'Total (LCY)';
        CurrSpecificationCptnLbl: Label 'Currency Specification';
        EnterDateFormulaErr: Label 'Enter a date formula in the Period Length field.';
        CompanyDisplayName: Text;
        TelemetryCategoryTxt: Label 'Report', Locked = true;
        AgedARReportGeneratedTxt: Label 'Aged AR Report generated.', Locked = true;

    protected var
        TempCustLedgEntry: Record "Cust. Ledger Entry" temporary;
        NumberOfLines: Integer;
        StartDateTime: DateTime;
        FinishDateTime: DateTime;

    local procedure CalcDates()
    var
        i: Integer;
        PeriodLength2: DateFormula;
    begin
        if not Evaluate(PeriodLength2, StrSubstNo(Text032Txt, PeriodLength)) then
            Error(EnterDateFormulaErr);
        if AgingBy = AgingBy::"Due Date" then begin
            PeriodEndDate[1] := DMY2Date(31, 12, 9999);
            PeriodStartDate[1] := EndingDate   1;
        end else begin
            PeriodEndDate[1] := EndingDate;
            PeriodStartDate[1] := CalcDate(PeriodLength2, EndingDate   1);
        end;
        for i := 2 to ArrayLen(PeriodEndDate) do begin
            PeriodEndDate[i] := PeriodStartDate[i - 1] - 1;
            PeriodStartDate[i] := CalcDate(PeriodLength2, PeriodEndDate[i]   1);
        end;
        PeriodStartDate[i] := 0D;

        for i := 1 to ArrayLen(PeriodEndDate) do
            if PeriodEndDate[i] < PeriodStartDate[i] then
                Error(Text010, PeriodLength);
    end;

    local procedure CreateHeadings()
    var
        i: Integer;
    begin
        if AgingBy = AgingBy::"Due Date" then begin
            HeaderText[1] := Text000;
            i := 2;
        end else
            i := 1;
        while i < ArrayLen(PeriodEndDate) do begin
            if HeadingType = HeadingType::"Date Interval" then
                HeaderText[i] := StrSubstNo('%1\..%2', PeriodStartDate[i], PeriodEndDate[i])
            else
                HeaderText[i] :=
                  StrSubstNo('%1 - %2 %3', EndingDate - PeriodEndDate[i]   1, EndingDate - PeriodStartDate[i]   1, Text002);
            i := i   1;
        end;
        if HeadingType = HeadingType::"Date Interval" then
            HeaderText[i] := StrSubstNo('%1 %2', BeforeTok, PeriodStartDate[i - 1])
        else
            HeaderText[i] := StrSubstNo('%1 %2 %3', BeforeTok, EndingDate - PeriodStartDate[i - 1]   1, Text002);
    end;

    local procedure InsertTemp(var CustLedgEntry: Record "Cust. Ledger Entry")
    var
        Currency: Record Currency;
    begin
        with TempCustLedgEntry do begin
            if Get(CustLedgEntry."Entry No.") then
                exit;
            TempCustLedgEntry := CustLedgEntry;
            Insert;
            if PrintAmountInLCY then begin
                Clear(TempCurrency);
                TempCurrency."Amount Rounding Precision" := GLSetup."Amount Rounding Precision";
                if TempCurrency.Insert() then;
                exit;
            end;
            if TempCurrency.Get("Currency Code") then
                exit;
            if TempCurrency.Get('') and ("Currency Code" = GLSetup."LCY Code") then
                exit;
            if TempCurrency.Get(GLSetup."LCY Code") and ("Currency Code" = '') then
                exit;
            if "Currency Code" <> '' then
                Currency.Get("Currency Code")
            else begin
                Clear(Currency);
                Currency."Amount Rounding Precision" := GLSetup."Amount Rounding Precision";
            end;
            TempCurrency := Currency;
            TempCurrency.Insert();
        end;
    end;

    local procedure GetPeriodIndex(Date: Date): Integer
    var
        i: Integer;
    begin
        for i := 1 to ArrayLen(PeriodEndDate) do
            if Date in [PeriodStartDate[i] .. PeriodEndDate[i]] then
                exit(i);
    end;

    local procedure Pct(a: Decimal; b: Decimal): Text[30]
    begin
        if b <> 0 then
            exit(Format(Round(100 * a / b, 0.1), 0, '')   '%');
    end;

    local procedure UpdateCurrencyTotals()
    var
        i: Integer;
    begin
        TempCurrency2.Code := CurrencyCode;
        if TempCurrency2.Insert() then;
        with TempCurrencyAmount do begin
            for i := 1 to ArrayLen(TotalCustLedgEntry) do begin
                "Currency Code" := CurrencyCode;
                Date := PeriodStartDate[i];
                if Find then begin
                    Amount := Amount   TotalCustLedgEntry[i]."Remaining Amount";
                    Modify;
                end else begin
                    "Currency Code" := CurrencyCode;
                    Date := PeriodStartDate[i];
                    Amount := TotalCustLedgEntry[i]."Remaining Amount";
                    Insert;
                end;
            end;
            "Currency Code" := CurrencyCode;
            Date := DMY2Date(31, 12, 9999);
            if Find then begin
                Amount := Amount   TotalCustLedgEntry[1].Amount;
                Modify;
            end else begin
                "Currency Code" := CurrencyCode;
                Date := DMY2Date(31, 12, 9999);
                Amount := TotalCustLedgEntry[1].Amount;
                Insert;
            end;
        end;
    end;

    procedure InitializeRequest(NewEndingDate: Date; NewAgingBy: Option; NewPeriodLength: DateFormula; NewPrintAmountInLCY: Boolean; NewPrintDetails: Boolean; NewHeadingType: Option; NewPagePercust: Boolean)
    begin
        EndingDate := NewEndingDate;
        AgingBy := NewAgingBy;
        PeriodLength := NewPeriodLength;
        PrintAmountInLCY := NewPrintAmountInLCY;
        PrintDetails := NewPrintDetails;
        HeadingType := NewHeadingType;
        NewPagePercustomer := NewPagePercust;
    end;

    local procedure CopyDimFiltersFromCustomer(var CustLedgerEntry: Record "Cust. Ledger Entry")
    begin
        if Customer.GetFilter("Global Dimension 1 Filter") <> '' then
            CustLedgerEntry.SetFilter("Global Dimension 1 Code", Customer.GetFilter("Global Dimension 1 Filter"));
        if Customer.GetFilter("Global Dimension 2 Filter") <> '' then
            CustLedgerEntry.SetFilter("Global Dimension 2 Code", Customer.GetFilter("Global Dimension 2 Filter"));
    end;

    local procedure LogReportTelemetry(StartDateTime: DateTime; FinishDateTime: DateTime; NumberOfLines: Integer)
    var
        Dimensions: Dictionary of [Text, Text];
        ReportDuration: BigInteger;
    begin
        ReportDuration := FinishDateTime - StartDateTime;
        Dimensions.Add('Category', TelemetryCategoryTxt);
        Dimensions.Add('ReportStartTime', Format(StartDateTime, 0, 9));
        Dimensions.Add('ReportFinishTime', Format(FinishDateTime, 0, 9));
        Dimensions.Add('ReportDuration', Format(ReportDuration));
        Dimensions.Add('NumberOfLines', Format(NumberOfLines));
        Session.LogMessage('0000FJM', AgedARReportGeneratedTxt, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, Dimensions);
    end;

    [IntegrationEvent(false, false)]
    local procedure OnTempCustLedgEntryGetRecordOnAfterSetDetailedEntryFilters(var DetailedCustLedgEntry: Record "Detailed Cust. Ledg. Entry")
    begin
    end;
}

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: Aged Account Receivable

    If you are new to AL development you would probably need to find a more easy task to start with. The aging report is one of the most complex reports in the whole systems. Mentoring you through the changes you need in that report through this forum is not a good option. Reach out to a developer at your partner or someone near you that can assist you in this case.

    But please continue to learn more about AL programming. Just don't start with that specific report.

  • Suggested answer
    Amit Baru Profile Picture
    3,029 on at
    RE: Aged Account Receivable

    Hi,

    Please contact with Technical consultant for doing the above task. My suggestion is to develop new report as per your company requirement.

    Regards

    Amit Sharma

    www.erpconsultors.com

    linkedin.com/in/amit-sharma-94542440/

    Please press Yes button for verification.

  • LearnBC Profile Picture
    190 on at
    RE: Aged Account Receivable

    the report i have been modified but there is erros while compilation  but the report is coming as blank but while running rows are fetching

    report 60028 " Aged Accounts Receivable"
    {
        DefaultLayout = RDLC;
        RDLCLayout = './AgedAccountsReceivable.rdlc';
        ApplicationArea = Basic, Suite;
        Caption = 'EPM Aged Accounts Receivable';
        PreviewMode = PrintLayout;
        UsageCategory = ReportsAndAnalysis;
        DataAccessIntent = ReadOnly;
    
        dataset
        {
            dataitem(Header; "Integer")
            {
                DataItemTableView = SORTING(Number) WHERE(Number = CONST(1));
                column(CompanyName; CompanyDisplayName)
                {
                }
                column(FormatEndingDate; StrSubstNo(Text006, Format(EndingDate, 0, 4)))
                {
                }
                column(PostingDate; StrSubstNo(Text007, SelectStr(AgingBy   1, Text009)))
                {
                }
                column(PrintAmountInLCY; PrintAmountInLCY)
                {
                }
                column(TableCaptnCustFilter; Customer.TableCaption   ': '   CustFilter)
                {
                }
                column(CustFilter; CustFilter)
                {
                }
                column(AgingByDueDate; AgingBy = AgingBy::"Due Date")
                {
                }
                column(AgedbyDocumnetDate; StrSubstNo(Text004, SelectStr(AgingBy   1, Text009)))
                {
                }
                column(HeaderText5; HeaderText[5])
                {
                }
                column(HeaderText4; HeaderText[4])
                {
                }
                column(HeaderText3; HeaderText[3])
                {
                }
                column(HeaderText2; HeaderText[2])
                {
                }
                column(HeaderText1; HeaderText[1])
                {
                }
                column(PrintDetails; PrintDetails)
                {
                }
                column(AgedAccReceivableCptn; AgedAccReceivableCptnLbl)
                {
                }
                column(CurrReportPageNoCptn; CurrReportPageNoCptnLbl)
                {
                }
                column(AllAmtinLCYCptn; AllAmtinLCYCptnLbl)
                {
                }
                column(AgedOverdueAmtCptn; AgedOverdueAmtCptnLbl)
                {
                }
                column(CLEEndDateAmtLCYCptn; CLEEndDateAmtLCYCptnLbl)
                {
                }
                column(CLEEndDateDueDateCptn; CLEEndDateDueDateCptnLbl)
                {
                }
                column(CLEEndDateDocNoCptn; CLEEndDateDocNoCptnLbl)
                {
                }
                column(CLEEndDatePstngDateCptn; CLEEndDatePstngDateCptnLbl)
                {
                }
                column(CLEEndDateDocTypeCptn; CLEEndDateDocTypeCptnLbl)
                {
                }
                column(OriginalAmtCptn; OriginalAmtCptnLbl)
                {
                }
                column(TotalLCYCptn; TotalLCYCptnLbl)
                {
                }
                column(NewPagePercustomer; NewPagePercustomer)
                {
                }
                column(GrandTotalCLE6RemAmt; GrandTotalCustLedgEntry[6]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE5RemAmt; GrandTotalCustLedgEntry[5]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE4RemAmt; GrandTotalCustLedgEntry[4]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE3RemAmt; GrandTotalCustLedgEntry[3]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE2RemAmt; GrandTotalCustLedgEntry[2]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE1RemAmt; GrandTotalCustLedgEntry[1]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLEAmtLCY; GrandTotalCustLedgEntry[1]."Amount (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE1CustRemAmtLCY; Pct(GrandTotalCustLedgEntry[1]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE2CustRemAmtLCY; Pct(GrandTotalCustLedgEntry[2]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE3CustRemAmtLCY; Pct(GrandTotalCustLedgEntry[3]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE4CustRemAmtLCY; Pct(GrandTotalCustLedgEntry[4]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE5CustRemAmtLCY; Pct(GrandTotalCustLedgEntry[5]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE6CustRemAmtLCY; Pct(GrandTotalCustLedgEntry[6]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE1AmtLCY; GrandTotalCustLedgEntry[1]."Amount (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE6PctRemAmtLCY; Pct(GrandTotalCustLedgEntry[6]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE5PctRemAmtLCY; Pct(GrandTotalCustLedgEntry[5]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE4PctRemAmtLCY; Pct(GrandTotalCustLedgEntry[4]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE3PctRemAmtLCY; Pct(GrandTotalCustLedgEntry[3]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE2PctRemAmtLCY; Pct(GrandTotalCustLedgEntry[2]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE1PctRemAmtLCY; Pct(GrandTotalCustLedgEntry[1]."Remaining Amt. (LCY)", GrandTotalCustLedgEntry[1]."Amount (LCY)"))
                {
                }
                column(GrandTotalCLE6RemAmtLCY; GrandTotalCustLedgEntry[6]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE5RemAmtLCY; GrandTotalCustLedgEntry[5]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE4RemAmtLCY; GrandTotalCustLedgEntry[4]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE3RemAmtLCY; GrandTotalCustLedgEntry[3]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE2RemAmtLCY; GrandTotalCustLedgEntry[2]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                column(GrandTotalCLE1RemAmtLCY; GrandTotalCustLedgEntry[1]."Remaining Amt. (LCY)")
                {
                    AutoFormatType = 1;
                }
                dataitem(Customer; Customer)
                {
                    RequestFilterFields = "No.";
                    column(PageGroupNo; PageGroupNo)
                    {
                    }
                    column(CustomerPhoneNoCaption; FieldCaption("Phone No."))
                    {
                    }
                    column(CustomerContactCaption; FieldCaption(Contact))
                    {
                    }
                    dataitem("Cust. Ledger Entry"; "Cust. Ledger Entry")
                    {
                        DataItemLink = "Customer No." = FIELD("No.");
                        DataItemTableView = SORTING("Customer No.", "Posting Date", "Currency Code");
    
                        trigger OnAfterGetRecord()
                        var
                            CustLedgEntry: Record "Cust. Ledger Entry";
                        begin
                            CustLedgEntry.SetCurrentKey("Closed by Entry No.");
                            if "Closed by Entry No." <> 0 then
                                CustLedgEntry.SetFilter("Closed by Entry No.", '%1|%2', "Entry No.", "Closed by Entry No.")
                            else
                                CustLedgEntry.SetRange("Closed by Entry No.", "Entry No.");
                            CustLedgEntry.SetRange("Posting Date", 0D, EndingDate);
                            CopyDimFiltersFromCustomer(CustLedgEntry);
                            if CustLedgEntry.FindSet(false, false) then
                                repeat
                                    InsertTemp(CustLedgEntry);
                                until CustLedgEntry.Next() = 0;
    
                            CustLedgEntry.Reset();
                            CustLedgEntry.SetRange("Entry No.", "Closed by Entry No.");
                            CustLedgEntry.SetRange("Posting Date", 0D, EndingDate);
                            CopyDimFiltersFromCustomer(CustLedgEntry);
                            if CustLedgEntry.FindSet(false, false) then
                                repeat
                                    InsertTemp(CustLedgEntry);
                                until CustLedgEntry.Next() = 0;
                            CurrReport.Skip();
                        end;
    
                        trigger OnPreDataItem()
                        begin
                            SetRange("Posting Date", EndingDate   1, DMY2Date(31, 12, 9999));
                            CopyDimFiltersFromCustomer("Cust. Ledger Entry");
                            Customer.CopyFilter("Currency Filter", "Currency Code");
                        end;
                    }
                    dataitem(OpenCustLedgEntry; "Cust. Ledger Entry")
                    {
                        DataItemLink = "Customer No." = FIELD("No.");
                        DataItemTableView = SORTING("Customer No.", Open, Positive, "Due Date", "Currency Code");
    
                        trigger OnAfterGetRecord()
                        begin
                            InsertTemp(OpenCustLedgEntry);
                            CurrReport.Skip();
                        end;
    
                        trigger OnPreDataItem()
                        begin
                            if AgingBy = AgingBy::"Posting Date" then begin
                                SetRange("Posting Date", 0D, EndingDate);
                                SetRange("Date Filter", 0D, EndingDate);
                                SetAutoCalcFields("Remaining Amt. (LCY)");
                                SetFilter("Remaining Amt. (LCY)", '<>0');
                            end;
                            CopyDimFiltersFromCustomer(OpenCustLedgEntry);
                            Customer.CopyFilter("Currency Filter", "Currency Code");
                        end;
                    }
                    dataitem(CurrencyLoop; "Integer")
                    {
                        DataItemTableView = SORTING(Number) WHERE(Number = FILTER(1 ..));
                        PrintOnlyIfDetail = true;
                        dataitem(TempCustLedgEntryLoop; "Integer")
                        {
                            DataItemTableView = SORTING(Number) WHERE(Number = FILTER(1 ..));
                            column(Name1_Cust; Customer.Name)
                            {
                                IncludeCaption = true;
                            }
                            column(No_Cust; Customer."No.")
                            {
                                IncludeCaption = true;
                            }
                            column(CustomerPhoneNo; Customer."Phone No.")
                            {
                            }
                            column(CustomerContactName; Customer.Contact)
                            {
                            }
                            column(CLEEndDateRemAmtLCY; CustLedgEntryEndingDate."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(AgedCLE1RemAmtLCY; AgedCustLedgEntry[1]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(AgedCLE2RemAmtLCY; AgedCustLedgEntry[2]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(AgedCLE3RemAmtLCY; AgedCustLedgEntry[3]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(AgedCLE4RemAmtLCY; AgedCustLedgEntry[4]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(AgedCLE5RemAmtLCY; AgedCustLedgEntry[5]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            //Modified 
                            column(AgedCLE6RemAmtLCY; AgedCustLedgEntry[6]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(CLEEndDateAmtLCY; CustLedgEntryEndingDate."Amount (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(CLEEndDueDate; Format(CustLedgEntryEndingDate."Due Date"))
                            {
                            }
                            column(CLEEndDateDocNo; CustLedgEntryEndingDate."Document No.")
                            {
                            }
                            column(CLEDocType; Format(CustLedgEntryEndingDate."Document Type"))
                            {
                            }
                            column(CLEPostingDate; Format(CustLedgEntryEndingDate."Posting Date"))
                            {
                            }
                            column(AgedCLE6TempRemAmt; AgedCustLedgEntry[6]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(AgedCLE5TempRemAmt; AgedCustLedgEntry[5]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(AgedCLE4TempRemAmt; AgedCustLedgEntry[4]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(AgedCLE3TempRemAmt; AgedCustLedgEntry[3]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(AgedCLE2TempRemAmt; AgedCustLedgEntry[2]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(AgedCLE1TempRemAmt; AgedCustLedgEntry[1]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(RemAmt_CLEEndDate; CustLedgEntryEndingDate."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(CLEEndDate_ExtDocNo; CustLedgEntryEndingDate."External Document No.")
                            {
    
                            }
                            column(CLEEndDate; CustLedgEntryEndingDate.Amount)
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(Name_Cust; StrSubstNo(Text005, Customer.Name))
                            {
                            }
                            column(TotalCLE1AmtLCY; TotalCustLedgEntry[1]."Amount (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(TotalCLE1RemAmtLCY; TotalCustLedgEntry[1]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(TotalCLE2RemAmtLCY; TotalCustLedgEntry[2]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(TotalCLE3RemAmtLCY; TotalCustLedgEntry[3]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(TotalCLE4RemAmtLCY; TotalCustLedgEntry[4]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(TotalCLE5RemAmtLCY; TotalCustLedgEntry[5]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(TotalCLE6RemAmtLCY; TotalCustLedgEntry[6]."Remaining Amt. (LCY)")
                            {
                                AutoFormatType = 1;
                            }
                            column(CurrrencyCode; CurrencyCode)
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(TotalCLE6RemAmt; TotalCustLedgEntry[6]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(TotalCLE5RemAmt; TotalCustLedgEntry[5]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(TotalCLE4RemAmt; TotalCustLedgEntry[4]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(TotalCLE3RemAmt; TotalCustLedgEntry[3]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(TotalCLE2RemAmt; TotalCustLedgEntry[2]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(TotalCLE1RemAmt; TotalCustLedgEntry[1]."Remaining Amount")
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(TotalCLE1Amt; TotalCustLedgEntry[1].Amount)
                            {
                                AutoFormatExpression = CurrencyCode;
                                AutoFormatType = 1;
                            }
                            column(TotalCheck; CustFilterCheck)
                            {
                            }
    
                            trigger OnAfterGetRecord()
                            var
                                PeriodIndex: Integer;
                            begin
                                if Number = 1 then begin
                                    if not TempCustLedgEntry.FindSet(false, false) then
                                        CurrReport.Break();
                                end else
                                    if TempCustLedgEntry.Next() = 0 then
                                        CurrReport.Break();
    
                                CustLedgEntryEndingDate := TempCustLedgEntry;
                                DetailedCustomerLedgerEntry.SetRange("Cust. Ledger Entry No.", CustLedgEntryEndingDate."Entry No.");
                                OnTempCustLedgEntryGetRecordOnAfterSetDetailedEntryFilters(DetailedCustomerLedgerEntry);
                                if DetailedCustomerLedgerEntry.FindSet(false, false) then
                                    repeat
                                        if (DetailedCustomerLedgerEntry."Entry Type" =
                                            DetailedCustomerLedgerEntry."Entry Type"::"Initial Entry") and
                                           (CustLedgEntryEndingDate."Posting Date" > EndingDate) and
                                           (AgingBy <> AgingBy::"Posting Date")
                                        then begin
                                            if CustLedgEntryEndingDate."Document Date" <= EndingDate then
                                                DetailedCustomerLedgerEntry."Posting Date" :=
                                                  CustLedgEntryEndingDate."Document Date"
                                            else
                                                if (CustLedgEntryEndingDate."Due Date" <= EndingDate) and
                                                   (AgingBy = AgingBy::"Due Date")
                                                then
                                                    DetailedCustomerLedgerEntry."Posting Date" :=
                                                      CustLedgEntryEndingDate."Due Date"
                                        end;
    
                                        if (DetailedCustomerLedgerEntry."Posting Date" <= EndingDate) or
                                           (TempCustLedgEntry.Open and
                                            (AgingBy = AgingBy::"Due Date") and
                                            (CustLedgEntryEndingDate."Due Date" > EndingDate) and
                                            (CustLedgEntryEndingDate."Posting Date" <= EndingDate))
                                        then begin
                                            if DetailedCustomerLedgerEntry."Entry Type" in
                                               [DetailedCustomerLedgerEntry."Entry Type"::"Initial Entry",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Unrealized Loss",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Unrealized Gain",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Realized Loss",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Realized Gain",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount (VAT Excl.)",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount (VAT Adjustment)",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Payment Tolerance",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount Tolerance",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Payment Tolerance (VAT Excl.)",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Payment Tolerance (VAT Adjustment)",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount Tolerance (VAT Excl.)",
                                                DetailedCustomerLedgerEntry."Entry Type"::"Payment Discount Tolerance (VAT Adjustment)"]
                                            then begin
                                                CustLedgEntryEndingDate.Amount := CustLedgEntryEndingDate.Amount   DetailedCustomerLedgerEntry.Amount;
                                                CustLedgEntryEndingDate."Amount (LCY)" :=
                                                  CustLedgEntryEndingDate."Amount (LCY)"   DetailedCustomerLedgerEntry."Amount (LCY)";
                                            end;
                                            if DetailedCustomerLedgerEntry."Posting Date" <= EndingDate then begin
                                                CustLedgEntryEndingDate."Remaining Amount" :=
                                                  CustLedgEntryEndingDate."Remaining Amount"   DetailedCustomerLedgerEntry.Amount;
                                                CustLedgEntryEndingDate."Remaining Amt. (LCY)" :=
                                                  CustLedgEntryEndingDate."Remaining Amt. (LCY)"   DetailedCustomerLedgerEntry."Amount (LCY)";
                                            end;
                                        end;
                                    until DetailedCustomerLedgerEntry.Next() = 0;
    
                                if CustLedgEntryEndingDate."Remaining Amount" = 0 then
                                    CurrReport.Skip();
    
                                case AgingBy of
                                    AgingBy::"Due Date":
                                        PeriodIndex := GetPeriodIndex(CustLedgEntryEndingDate."Due Date");
                                    AgingBy::"Posting Date":
                                        PeriodIndex := GetPeriodIndex(CustLedgEntryEndingDate."Posting Date");
                                    AgingBy::"Document Date":
                                        begin
                                            if CustLedgEntryEndingDate."Document Date" > EndingDate then begin
                                                CustLedgEntryEndingDate."Remaining Amount" := 0;
                                                CustLedgEntryEndingDate."Remaining Amt. (LCY)" := 0;
                                                CustLedgEntryEndingDate."Document Date" := CustLedgEntryEndingDate."Posting Date";
                                            end;
                                            PeriodIndex := GetPeriodIndex(CustLedgEntryEndingDate."Document Date");
                                        end;
                                end;
                                Clear(AgedCustLedgEntry);
                                AgedCustLedgEntry[PeriodIndex]."Remaining Amount" := CustLedgEntryEndingDate."Remaining Amount";
                                AgedCustLedgEntry[PeriodIndex]."Remaining Amt. (LCY)" := CustLedgEntryEndingDate."Remaining Amt. (LCY)";
                                TotalCustLedgEntry[PeriodIndex]."Remaining Amount"  = CustLedgEntryEndingDate."Remaining Amount";
                                TotalCustLedgEntry[PeriodIndex]."Remaining Amt. (LCY)"  = CustLedgEntryEndingDate."Remaining Amt. (LCY)";
                                GrandTotalCustLedgEntry[PeriodIndex]."Remaining Amt. (LCY)"  = CustLedgEntryEndingDate."Remaining Amt. (LCY)";
                                TotalCustLedgEntry[1].Amount  = CustLedgEntryEndingDate."Remaining Amount";
                                TotalCustLedgEntry[1]."Amount (LCY)"  = CustLedgEntryEndingDate."Remaining Amt. (LCY)";
                                GrandTotalCustLedgEntry[1]."Amount (LCY)"  = CustLedgEntryEndingDate."Remaining Amt. (LCY)";
                                NumberOfLines  = 1;
                            end;
    
                            trigger OnPostDataItem()
                            begin
                                if not PrintAmountInLCY then
                                    UpdateCurrencyTotals;
                            end;
    
                            trigger OnPreDataItem()
                            begin
                                if not PrintAmountInLCY then begin
                                    if (TempCurrency.Code = '') or (TempCurrency.Code = GLSetup."LCY Code") then
                                        TempCustLedgEntry.SetFilter("Currency Code", '%1|%2', GLSetup."LCY Code", '')
                                    else
                                        TempCustLedgEntry.SetRange("Currency Code", TempCurrency.Code);
                                end;
    
                                PageGroupNo := NextPageGroupNo;
                                if NewPagePercustomer and (NumberOfCurrencies > 0) then
                                    NextPageGroupNo := PageGroupNo   1;
                            end;
                        }
    
                        trigger OnAfterGetRecord()
                        begin
                            Clear(TotalCustLedgEntry);
    
                            if Number = 1 then begin
                                if not TempCurrency.FindSet(false, false) then begin
                                    CurrReport.Break();
                                    NumberOfLines -= 1;
                                end;
                            end else
                                if TempCurrency.Next() = 0 then begin
                                    CurrReport.Break();
                                    NumberOfLines -= 1;
                                end;
    
                            if TempCurrency.Code <> '' then
                                CurrencyCode := TempCurrency.Code
                            else
                                CurrencyCode := GLSetup."LCY Code";
    
                            NumberOfCurrencies := NumberOfCurrencies   1;
                        end;
    
                        trigger OnPreDataItem()
                        begin
                            NumberOfCurrencies := 0;
                        end;
                    }
    
                    trigger OnAfterGetRecord()
                    begin
                        if NewPagePercustomer then
                            PageGroupNo  = 1;
                        TempCurrency.Reset();
                        TempCurrency.DeleteAll();
                        TempCustLedgEntry.Reset();
                        TempCustLedgEntry.DeleteAll();
                        NumberOfLines  = 1;
                    end;
                }
                dataitem(CurrencyTotals; "Integer")
                {
                    DataItemTableView = SORTING(Number) WHERE(Number = FILTER(1 ..));
                    column(CurrNo; Number = 1)
                    {
                    }
                    column(TempCurrCode; TempCurrency2.Code)
                    {
                        AutoFormatExpression = CurrencyCode;
                        AutoFormatType = 1;
                    }
                    column(AgedCLE6RemAmt; AgedCustLedgEntry[6]."Remaining Amount")
                    {
                        AutoFormatExpression = CurrencyCode;
                        AutoFormatType = 1;
                    }
                    column(AgedCLE1RemAmt; AgedCustLedgEntry[1]."Remaining Amount")
                    {
                        AutoFormatExpression = CurrencyCode;
                        AutoFormatType = 1;
                    }
                    column(AgedCLE2RemAmt; AgedCustLedgEntry[2]."Remaining Amount")
                    {
                        AutoFormatExpression = CurrencyCode;
                        AutoFormatType = 1;
                    }
                    column(AgedCLE3RemAmt; AgedCustLedgEntry[3]."Remaining Amount")
                    {
                        AutoFormatExpression = CurrencyCode;
                        AutoFormatType = 1;
                    }
                    column(AgedCLE4RemAmt; AgedCustLedgEntry[4]."Remaining Amount")
                    {
                        AutoFormatExpression = CurrencyCode;
                        AutoFormatType = 1;
                    }
                    column(AgedCLE5RemAmt; AgedCustLedgEntry[5]."Remaining Amount")
                    {
                        AutoFormatExpression = CurrencyCode;
                        AutoFormatType = 1;
                    }
                    column(CurrSpecificationCptn; CurrSpecificationCptnLbl)
                    {
                    }
    
                    trigger OnAfterGetRecord()
                    begin
                        if Number = 1 then begin
                            if not TempCurrency2.FindSet(false, false) then
                                CurrReport.Break();
                        end else
                            if TempCurrency2.Next() = 0 then
                                CurrReport.Break();
    
                        Clear(AgedCustLedgEntry);
                        TempCurrencyAmount.SetRange("Currency Code", TempCurrency2.Code);
                        if TempCurrencyAmount.FindSet(false, false) then
                            repeat
                                if TempCurrencyAmount.Date <> DMY2Date(31, 12, 9999) then
                                    AgedCustLedgEntry[GetPeriodIndex(TempCurrencyAmount.Date)]."Remaining Amount" :=
                                      TempCurrencyAmount.Amount
                                else
                                    AgedCustLedgEntry[6]."Remaining Amount" := TempCurrencyAmount.Amount;
                            until TempCurrencyAmount.Next() = 0;
                    end;
                }
            }
        }
    
        requestpage
        {
            SaveValues = true;
    
            layout
            {
                area(content)
                {
                    group(Options)
                    {
                        Caption = 'Options';
                        field(AgedAsOf; EndingDate)
                        {
                            ApplicationArea = Basic, Suite;
                            Caption = 'Aged As Of';
                            ToolTip = 'Specifies the date that you want the aging calculated for.';
                        }
                        field(Agingby; AgingBy)
                        {
                            ApplicationArea = Basic, Suite;
                            Caption = 'Aging by';
                            OptionCaption = 'Due Date,Posting Date,Document Date';
                            ToolTip = 'Specifies if the aging will be calculated from the due date, the posting date, or the document date.';
                        }
                        field(PeriodLength; PeriodLength)
                        {
                            ApplicationArea = Basic, Suite;
                            Caption = 'Period Length';
                            ToolTip = 'Specifies the period for which data is shown in the report. For example, enter "1M" for one month, "30D" for thirty days, "3Q" for three quarters, or "5Y" for five years.';
                        }
                        field(AmountsinLCY; PrintAmountInLCY)
                        {
                            ApplicationArea = Basic, Suite;
                            Caption = 'Print Amounts in LCY';
                            ToolTip = 'Specifies if you want the report to specify the aging per customer ledger entry.';
                        }
                        field(PrintDetails; PrintDetails)
                        {
                            ApplicationArea = Basic, Suite;
                            Caption = 'Print Details';
                            ToolTip = 'Specifies if you want the report to show the detailed entries that add up the total balance for each customer.';
                        }
                        field(HeadingType; HeadingType)
                        {
                            ApplicationArea = Basic, Suite;
                            Caption = 'Heading Type';
                            OptionCaption = 'Date Interval,Number of Days';
                            ToolTip = 'Specifies if the column heading for the three periods will indicate a date interval or the number of days overdue.';
                        }
                        field(perCustomer; NewPagePercustomer)
                        {
                            ApplicationArea = Basic, Suite;
                            Caption = 'New Page per Customer';
                            ToolTip = 'Specifies if each customer''s information is printed on a new page if you have chosen two or more customers to be included in the report.';
                        }
                    }
                }
            }
    
            actions
            {
            }
    
            trigger OnOpenPage()
            begin
                if EndingDate = 0D then
                    EndingDate := WorkDate;
                if Format(PeriodLength) = '' then
                    Evaluate(PeriodLength, '');
            end;
        }
    
        labels
        {
            BalanceCaption = 'Balance';
        }
    
        trigger OnPreReport()
        var
            FormatDocument: Codeunit "Format Document";
        begin
            StartDateTime := CurrentDateTime();
            CustFilter := FormatDocument.GetRecordFiltersWithCaptions(Customer);
    
            GLSetup.Get();
    
            CalcDates;
            CreateHeadings;
    
            PageGroupNo := 1;
            NextPageGroupNo := 1;
            CustFilterCheck := (CustFilter <> 'No.');
    
            CompanyDisplayName := COMPANYPROPERTY.DisplayName;
        end;
    
        trigger OnPostReport()
        begin
            FinishDateTime := CurrentDateTime();
            LogReportTelemetry(StartDateTime, FinishDateTime, NumberOfLines);
        end;
    
        var
            GLSetup: Record "General Ledger Setup";
            CustLedgEntryEndingDate: Record "Cust. Ledger Entry";
            TotalCustLedgEntry: array[6] of Record "Cust. Ledger Entry";
            GrandTotalCustLedgEntry: array[6] of Record "Cust. Ledger Entry";
            AgedCustLedgEntry: array[8] of Record "Cust. Ledger Entry";
            TempCurrency: Record Currency temporary;
            TempCurrency2: Record Currency temporary;
            TempCurrencyAmount: Record "Currency Amount" temporary;
            DetailedCustomerLedgerEntry: Record "Detailed Cust. Ledg. Entry";
            CustFilter: Text;
            PrintAmountInLCY: Boolean;
            EndingDate: Date;
            AgingBy: Option "Due Date","Posting Date","Document Date";
            PeriodLength: DateFormula;
            PrintDetails: Boolean;
            HeadingType: Option "Date Interval","Number of Days";
            NewPagePercustomer: Boolean;
            PeriodStartDate: array[6] of Date;
            PeriodEndDate: array[6] of Date;
            HeaderText: array[6] of Text[30];
            Text000: Label 'Not Due';
            BeforeTok: Label 'Before';
            CurrencyCode: Code[10];
            Text002: Label 'days';
            Text004: Label 'Aged by %1';
            Text005: Label 'Total for %1';
            Text006: Label 'Aged as of %1';
            Text007: Label 'Aged by %1';
            NumberOfCurrencies: Integer;
            Text009: Label 'Due Date,Posting Date,Document Date';
            Text010: Label 'The Date Formula %1 cannot be used. Try to restate it. E.g. 1M CM instead of CM 1M.';
            PageGroupNo: Integer;
            NextPageGroupNo: Integer;
            CustFilterCheck: Boolean;
            Text032Txt: Label '-%1', Comment = 'Negating the period length: %1 is the period length';
            AgedAccReceivableCptnLbl: Label 'Aged Accounts Receivable';
            CurrReportPageNoCptnLbl: Label 'Page';
            AllAmtinLCYCptnLbl: Label 'All Amounts in LCY';
            AgedOverdueAmtCptnLbl: Label 'Aged Overdue Amounts';
            CLEEndDateAmtLCYCptnLbl: Label 'Original Amount ';
            CLEEndDateDueDateCptnLbl: Label 'Due Date';
            CLEEndDateDocNoCptnLbl: Label 'Document No.';
            CLEEndDatePstngDateCptnLbl: Label 'Posting Date';
            CLEEndDateDocTypeCptnLbl: Label 'Document Type';
            OriginalAmtCptnLbl: Label 'Currency Code';
            TotalLCYCptnLbl: Label 'Total (LCY)';
            CurrSpecificationCptnLbl: Label 'Currency Specification';
            EnterDateFormulaErr: Label 'Enter a date formula in the Period Length field.';
            CompanyDisplayName: Text;
            TelemetryCategoryTxt: Label 'Report', Locked = true;
            AgedARReportGeneratedTxt: Label 'Aged AR Report generated.', Locked = true;
    
        protected var
            TempCustLedgEntry: Record "Cust. Ledger Entry" temporary;
            NumberOfLines: Integer;
            StartDateTime: DateTime;
            FinishDateTime: DateTime;
    
        local procedure CalcDates()
        var
            i: Integer;
            PeriodLength2: DateFormula;
        begin
            if not Evaluate(PeriodLength2, StrSubstNo(Text032Txt, PeriodLength)) then
                Error(EnterDateFormulaErr);
            if AgingBy = AgingBy::"Due Date" then begin
                PeriodEndDate[1] := DMY2Date(31, 12, 9999);
                PeriodStartDate[1] := EndingDate   1;
            end else begin
                PeriodEndDate[1] := EndingDate;
                PeriodStartDate[1] := CalcDate(PeriodLength2, EndingDate   1);
            end;
            for i := 2 to ArrayLen(PeriodEndDate) do begin
                PeriodEndDate[i] := PeriodStartDate[i - 1] - 1;
                PeriodStartDate[i] := CalcDate(PeriodLength2, PeriodEndDate[i]   1);
            end;
            PeriodStartDate[i] := 0D;
    
            for i := 1 to ArrayLen(PeriodEndDate) do
                if PeriodEndDate[i] < PeriodStartDate[i] then
                    Error(Text010, PeriodLength);
        end;
    
        local procedure CreateHeadings()
        var
            i: Integer;
        begin
            if AgingBy = AgingBy::"Due Date" then begin
                HeaderText[1] := Text000;
                i := 2;
            end else
                i := 1;
            while i < ArrayLen(PeriodEndDate) do begin
                if HeadingType = HeadingType::"Date Interval" then
                    HeaderText[i] := StrSubstNo('%1\..%2', PeriodStartDate[i], PeriodEndDate[i])
                else
                    HeaderText[i] :=
                      StrSubstNo('%1 - %2 %3', EndingDate - PeriodEndDate[i]   1, EndingDate - PeriodStartDate[i]   1, Text002);
                i := i   1;
            end;
            if HeadingType = HeadingType::"Date Interval" then
                HeaderText[i] := StrSubstNo('%1 %2', BeforeTok, PeriodStartDate[i - 1])
            else
                HeaderText[i] := StrSubstNo('%1 %2 %3', BeforeTok, EndingDate - PeriodStartDate[i - 1]   1, Text002);
        end;
    
        local procedure InsertTemp(var CustLedgEntry: Record "Cust. Ledger Entry")
        var
            Currency: Record Currency;
        begin
            if TempCustLedgEntry.Get(CustLedgEntry."Entry No.") then
                exit;
            TempCustLedgEntry := CustLedgEntry;
            TempCustLedgEntry.Insert;
            if PrintAmountInLCY then begin
                Clear(TempCurrency);
                TempCurrency."Amount Rounding Precision" := GLSetup."Amount Rounding Precision";
                if TempCurrency.Insert() then;
                exit;
            end;
            if TempCurrency.Get(TempCustLedgEntry."Currency Code") then
                exit;
            if TempCurrency.Get('') and (TempCustLedgEntry."Currency Code" = GLSetup."LCY Code") then
                exit;
            if TempCurrency.Get(GLSetup."LCY Code") and (TempCustLedgEntry."Currency Code" = '') then
                exit;
            if TempCustLedgEntry."Currency Code" <> '' then
                Currency.Get(TempCustLedgEntry."Currency Code")
            else begin
                Clear(Currency);
                Currency."Amount Rounding Precision" := GLSetup."Amount Rounding Precision";
            end;
            TempCurrency := Currency;
            TempCurrency.Insert();
    
        end;
    
        local procedure GetPeriodIndex(Date: Date): Integer
        var
            i: Integer;
        begin
            for i := 1 to ArrayLen(PeriodEndDate) do
                if Date in [PeriodStartDate[i] .. PeriodEndDate[i]] then
                    exit(i);
        end;
    
        local procedure Pct(a: Decimal; b: Decimal): Text[30]
        begin
            if b <> 0 then
                exit(Format(Round(100 * a / b, 0.1), 0, '')   '%');
        end;
    
        local procedure UpdateCurrencyTotals()
        var
            i: Integer;
        begin
            TempCurrency2.Code := CurrencyCode;
            if TempCurrency2.Insert() then;
            for i := 1 to ArrayLen(TotalCustLedgEntry) do begin
                TempCurrencyAmount."Currency Code" := CurrencyCode;
                TempCurrencyAmount.Date := PeriodStartDate[i];
                if TempCurrencyAmount.Find then begin
                    TempCurrencyAmount.Amount := TempCurrencyAmount.Amount   TotalCustLedgEntry[i]."Remaining Amount";
                    TempCurrencyAmount.Modify;
                end else begin
                    TempCurrencyAmount."Currency Code" := CurrencyCode;
                    TempCurrencyAmount.Date := PeriodStartDate[i];
                    TempCurrencyAmount.Amount := TotalCustLedgEntry[i]."Remaining Amount";
                    TempCurrencyAmount.Insert;
                end;
            end;
            TempCurrencyAmount."Currency Code" := CurrencyCode;
            TempCurrencyAmount.Date := DMY2Date(31, 12, 9999);
            if TempCurrencyAmount.Find then begin
                TempCurrencyAmount.Amount := TempCurrencyAmount.Amount   TotalCustLedgEntry[1].Amount;
                TempCurrencyAmount.Modify;
            end else begin
                TempCurrencyAmount."Currency Code" := CurrencyCode;
                TempCurrencyAmount.Date := DMY2Date(31, 12, 9999);
                TempCurrencyAmount.Amount := TotalCustLedgEntry[1].Amount;
                TempCurrencyAmount.Insert;
            end;
    
        end;
    
        procedure InitializeRequest(NewEndingDate: Date; NewAgingBy: Option; NewPeriodLength: DateFormula; NewPrintAmountInLCY: Boolean; NewPrintDetails: Boolean; NewHeadingType: Option; NewPagePercust: Boolean)
        begin
            EndingDate := NewEndingDate;
            AgingBy := NewAgingBy;
            PeriodLength := NewPeriodLength;
            PrintAmountInLCY := NewPrintAmountInLCY;
            PrintDetails := NewPrintDetails;
            HeadingType := NewHeadingType;
            NewPagePercustomer := NewPagePercust;
        end;
    
        local procedure CopyDimFiltersFromCustomer(var CustLedgerEntry: Record "Cust. Ledger Entry")
        begin
            if Customer.GetFilter("Global Dimension 1 Filter") <> '' then
                CustLedgerEntry.SetFilter("Global Dimension 1 Code", Customer.GetFilter("Global Dimension 1 Filter"));
            if Customer.GetFilter("Global Dimension 2 Filter") <> '' then
                CustLedgerEntry.SetFilter("Global Dimension 2 Code", Customer.GetFilter("Global Dimension 2 Filter"));
        end;
    
        local procedure LogReportTelemetry(StartDateTime: DateTime; FinishDateTime: DateTime; NumberOfLines: Integer)
        var
            Dimensions: Dictionary of [Text, Text];
            ReportDuration: BigInteger;
        begin
            ReportDuration := FinishDateTime - StartDateTime;
            Dimensions.Add('Category', TelemetryCategoryTxt);
            Dimensions.Add('ReportStartTime', Format(StartDateTime, 0, 9));
            Dimensions.Add('ReportFinishTime', Format(FinishDateTime, 0, 9));
            Dimensions.Add('ReportDuration', Format(ReportDuration));
            Dimensions.Add('NumberOfLines', Format(NumberOfLines));
            Session.LogMessage('0000FJM', AgedARReportGeneratedTxt, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, Dimensions);
        end;
    
        [IntegrationEvent(false, false)]
        local procedure OnTempCustLedgEntryGetRecordOnAfterSetDetailedEntryFilters(var DetailedCustLedgEntry: Record "Detailed Cust. Ledg. Entry")
        begin
        end;
    }

  • LearnBC Profile Picture
    190 on at
    RE: Aged Account Receivable

    i completely understand...

    if we modify 2more slots in the existing one..how we can do it. what changes we need to do in the base report after taking the copy

    am new to this development and all. your responses will really helps me alot....

    thanks in advance

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: Aged Account Receivable

    If i was given that task today i do not think i would try to modify the standard report. I would create a new report based on the customer ledger entries and create an Excel layout for my report.

    Then i would let Excel handle the aging intervals in a pivot table or something like that. It would be a much more flexible solution and it would be easy to modify the report layout as needed.

    Just a thought.......

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans