Skip to main content

Notifications

Announcements

No record found.

Business Central forum
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,744 Moderator 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,025 Moderator 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,570 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,683 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans