Skip to main content
Microsoft Dynamics NAV forum
Unanswered

Round problem Sales Line

editSubscribe (0) ShareShare
ReportReport
Posted on by UG Leader

So Hi everyone, I've created a page where I use a list of sales order. Here the source table of my page is "Sales Line" and when i enter the same item twice (or more times) the round of the price in the column "Amount Including VAT" is not right, shpuld be always the same value but for each line have differences.

Here's the image below.

round.png

I try to comment this code in Sales Line table

Amount Including VAT - OnValidate()
GetPurchHeader;
"Amount Including VAT" := ROUND("Amount Including VAT",Currency."Amount Rounding Precision");

But everything stay the same... any idea?

Categories:
  • Hannes Holst Profile Picture
    Hannes Holst 5,763 on at
    RE: Round problem Sales Line

    I can't help you any further. Next step would be to debugg the problem.

  • Community Member Profile Picture
    Community Member UG Leader on at
    RE: Round problem Sales Line

    The code dind't work... it's the same

  • Community Member Profile Picture
    Community Member UG Leader on at
    RE: Round problem Sales Line

    I will try your code, thanks. I don't know why this is modified

  • Hannes Holst Profile Picture
    Hannes Holst 5,763 on at
    RE: Round problem Sales Line

    HI,

    This is the standard code of the OnValidate-Trigger of field "Amount Including VAT" of NAV2017:

    "Amount Including VAT" := ROUND("Amount Including VAT",Currency."Amount Rounding Precision");
    CASE "VAT Calculation Type" OF
      "VAT Calculation Type"::"Normal VAT",
      "VAT Calculation Type"::"Reverse Charge VAT":
        BEGIN
          Amount :=
            ROUND(
              "Amount Including VAT" /
              (1 + (1 - SalesHeader."VAT Base Discount %" / 100) * "VAT %" / 100),
              Currency."Amount Rounding Precision");
          "VAT Base Amount" :=
            ROUND(Amount * (1 - SalesHeader."VAT Base Discount %" / 100),Currency."Amount Rounding Precision");
        END;
      "VAT Calculation Type"::"Full VAT":
        BEGIN
          Amount := 0;
          "VAT Base Amount" := 0;
        END;
      "VAT Calculation Type"::"Sales Tax":
        BEGIN
          SalesHeader.TESTFIELD("VAT Base Discount %",0);
          Amount :=
            SalesTaxCalculate.ReverseCalculateTax(
              "Tax Area Code","Tax Group Code","Tax Liable",SalesHeader."Posting Date",
              "Amount Including VAT","Quantity (Base)",SalesHeader."Currency Factor");
          IF Amount <> 0 THEN
            "VAT %" :=
              ROUND(100 * ("Amount Including VAT" - Amount) / Amount,0.00001)
          ELSE
            "VAT %" := 0;
          Amount := ROUND(Amount,Currency."Amount Rounding Precision");
          "VAT Base Amount" := Amount;
        END;
    END;
    
    InitOutstandingAmount;


    As you can see, you have some modifications in your code:

     (1 + (1 - SalesHeader."VAT Base Discount %" / 100) * ("VAT %" + "ND %") / 100), //soft,n

    This could be a reason for the problem.
    What is the relation to the "Purchase Quote Subform"?

    It's difficult to troubleshoot the problem because it possible was created due to customized code.
    When you create a clean database without customization, you will notice that this problem will not occur.

  • Community Member Profile Picture
    Community Member UG Leader on at
    RE: Round problem Sales Line

    In table "Sales Line" I have this code for "Amout Including Vat" field

    Amount Including VAT - OnValidate()
    //"Amount Including VAT" := ROUND("Amount Including VAT",Currency."Amount Rounding Precision");
    CASE "VAT Calculation Type" OF
      "VAT Calculation Type"::"Normal VAT",
      "VAT Calculation Type"::"Reverse Charge VAT",
      "VAT Calculation Type"::"No Taxable VAT": //soft,n
        BEGIN
          Amount :=
            ROUND(
              "Amount Including VAT" /
    
              //soft,o (1 + (1 - SalesHeader."VAT Base Discount %" / 100) * "VAT %" / 100),
              (1 + (1 - SalesHeader."VAT Base Discount %" / 100) * ("VAT %" + "ND %") / 100), //soft,n
    
              Currency."Amount Rounding Precision");
          "VAT Base Amount" :=
            ROUND(Amount * (1 - SalesHeader."VAT Base Discount %" / 100),Currency."Amount Rounding Precision");
        END;
      "VAT Calculation Type"::"Full VAT":
        BEGIN
          Amount := 0;
          "VAT Base Amount" := 0;
        END;
      "VAT Calculation Type"::"Sales Tax":
        BEGIN
          SalesHeader.TESTFIELD("VAT Base Discount %",0);
          Amount :=
            SalesTaxCalculate.ReverseCalculateTax(
              "Tax Area Code","Tax Group Code","Tax Liable",SalesHeader."Posting Date",
              "Amount Including VAT","Quantity (Base)",SalesHeader."Currency Factor");
          IF Amount <> 0 THEN
            "VAT %" :=
              ROUND(100 * ("Amount Including VAT" - Amount) / Amount,0.00001)
          ELSE
            //soft,o "VAT %" := 0;
            //soft,sn
            BEGIN
              "VAT %" := 0;
              "ND %" := 0;
            END;
            //soft,en
          Amount := ROUND(Amount,Currency."Amount Rounding Precision");
          "VAT Base Amount" := Amount;
        END;
    END;
    
    "Pmt. Disc. Given Amount" := 0; //soft,n
    
    InitOutstandingAmount;


    In my page "Purchase Quote Subform" I have this function called several times, to recalculate the amounts RedistributeTotalsOnAfterValidate

    LOCAL RedistributeTotalsOnAfterValidate
    
    CurrPage.SAVERECORD;
    
    PurchHeader.GET("Document Type","Document No.");
    IF DocumentTotals.PurchaseCheckNumberOfLinesLimit(PurchHeader) THEN
    DocumentTotals.PurchaseRedistributeInvoiceDiscountAmounts(Rec,VATAmount,TotalPurchaseLine);
    CurrPage.UPDATE;


  • Hannes Holst Profile Picture
    Hannes Holst 5,763 on at
    RE: Round problem Sales Line

    Hi,

    sorry, I did misunderstand your question.

    The field "Amount Including VAT" is calculated in the Table "Sales Line" and not in the page.

    Are you sure you do not have any customization in the table "Sales Line"?

    I'm not sure for NAV2016, but in NAV2017 there is no function called "GetPurchHeader" in that table.

  • Community Member Profile Picture
    Community Member UG Leader on at
    RE: Round problem Sales Line

    This page is new and use Sales Header table and another page linekd to sales Line

    posproblem.png

  • Hannes Holst Profile Picture
    Hannes Holst 5,763 on at
    RE: Round problem Sales Line

    Did you create a new Subpage or do you use an existing one?

  • Community Member Profile Picture
    Community Member UG Leader on at
    RE: Round problem Sales Line

    which variables? Can you ellaborate pls?

  • Hannes Holst Profile Picture
    Hannes Holst 5,763 on at
    RE: Round problem Sales Line

    Hi,

    Maybe you didn't reset the variables for the new line?

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,066 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,585 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans