web
You’re offline. This is a read only version of the page.
close
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

VAT Entry and Cust. Ledger Entry TotalVAT

(0) ShareShare
ReportReport
Posted on by 50

Hi,

i want to add function which sum Total VAT Amount from VAT Entry filtered by Customer (Cust. Ledger Entry). 

I struggle with filter Amount per Customer. Below is my code.

var
        CustLedgerEntry: Record "Cust. Ledger Entry";
        TotalVAT: Decimal;
        VatEntry: Record "VAT Entry";
 procedure TotalVAT()
    begin
        CustLedgerEntry.CalcFields("Remaining Amt. (LCY)", "Remaining Amount", CustLedgerEntry."Original Amt. (LCY)");
        TotalVAT := 0;
        VatEntry.Reset();
        VatEntry.SetRange("Document No.", CustLedgerEntry."Document No.");
        VatEntry.SetRange("Transaction No.", CustLedgerEntry."Transaction No.");
        if VatEntry.FindSet() then begin
                VatEntry.CalcFields("ITI VAT Base");
                TotalVAT += -VatEntry."ITI VAT Amount" - VatEntry."Unrealized Amount";
            until VatEntry.Next() = 0;
        end;
Any ideas? 
I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    Hi,

    Please do the yellow mark

    var

           CustLedgerEntry: Record "Cust. Ledger Entry";

           TotalVAT: Decimal;

           VatEntry: Record "VAT Entry";

    procedure TotalVAT()

       begin

           CustLedgerEntry.reset;

           CustLedgerEntry.setrange("Customer No.",Customer."No.");

            CustLedgerEntry.findset;

            repeat

           CustLedgerEntry.CalcFields("Remaining Amt. (LCY)", "Remaining Amount", CustLedgerEntry."Original Amt. (LCY)");

           TotalVAT := 0;

           VatEntry.Reset();

           VatEntry.SetRange("Document No.", CustLedgerEntry."Document No.");

           VatEntry.SetRange("Transaction No.", CustLedgerEntry."Transaction No.");

           if VatEntry.FindSet() then begin

                   VatEntry.CalcFields("ITI VAT Base");

                   TotalVAT += -VatEntry."ITI VAT Amount" - VatEntry."Unrealized Amount";

               until VatEntry.Next() = 0;

           end;

            until         CustLedgerEntry.next = 0;

    Any ideas?

  • Tony00001 Profile Picture
    50 on at

    It doesn't work right. I get on every customer record the same result.

  • Tony00001 Profile Picture
    50 on at

    It only get last record in VAT Entry, doesnt sum.

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,111 Moderator on at

    Hi Tony00001

    Try this code instead. You were missing the repeat while looping through the VAT entries-

    if VatEntry.FindSet() then repeat

                   VatEntry.CalcFields("ITI VAT Base");

                   TotalVAT += -VatEntry."ITI VAT Amount" - VatEntry."Unrealized Amount";

               until VatEntry.Next() = 0;

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,135

#2
YUN ZHU Profile Picture

YUN ZHU 733 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 612

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans