Skip to main content

Notifications

Announcements

No record found.

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

VAT Entry and Cust. Ledger Entry TotalVAT

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? 
  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: VAT Entry and Cust. Ledger Entry TotalVAT

    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;

  • Tony00001 Profile Picture
    Tony00001 50 on at
    RE: VAT Entry and Cust. Ledger Entry TotalVAT

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

  • Tony00001 Profile Picture
    Tony00001 50 on at
    RE: VAT Entry and Cust. Ledger Entry TotalVAT

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

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: VAT Entry and Cust. Ledger Entry TotalVAT

    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?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans