ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Event Request] Codeunit 12 "Sales-Post".InitVAT

Open Softstore opened this issue 5 years ago • 1 comments

Include BEGIN END in the handled after call OnInitVATOnBeforeVATPostingSetupCheck

table 81 "Gen. Journal Line" local procedure InitVAT(var GenJnlLine: Record "Gen. Journal Line"; var GLEntry: Record "G/L Entry"; var VATPostingSetup: Record "VAT Posting Setup") var LCYCurrency: Record Currency; SalesTaxCalculate: Codeunit "Sales Tax Calculate"; IsHandled: Boolean; begin OnBeforeInitVAT(GenJnlLine, GLEntry, VATPostingSetup);

    LCYCurrency.InitRoundingPrecision();
    with GenJnlLine do
        if "Gen. Posting Type" <> "Gen. Posting Type"::" " then begin // None
            VATPostingSetup.Get("VAT Bus. Posting Group", "VAT Prod. Posting Group");
            IsHandled := false;
            OnInitVATOnBeforeVATPostingSetupCheck(GenJnlLine, GLEntry, VATPostingSetup, IsHandled);
            **//------------------------------------------------- 
            //if not IsHandled then
            if not IsHandled then BEGIN
            //-------------------------------------------------** 
                TestField("VAT Calculation Type", VATPostingSetup."VAT Calculation Type");
            case "VAT Posting" of
                "VAT Posting"::"Automatic VAT Entry":
                    begin
                        GLEntry.CopyPostingGroupsFromGenJnlLine(GenJnlLine);
                        case "VAT Calculation Type" of
                            "VAT Calculation Type"::"Normal VAT":
                                if "VAT Difference" <> 0 then begin
                                    GLEntry.Amount := "VAT Base Amount (LCY)";
                                    GLEntry."VAT Amount" := "Amount (LCY)" - GLEntry.Amount;
                                    GLEntry."Additional-Currency Amount" := "Source Curr. VAT Base Amount";
                                    if "Source Currency Code" = AddCurrencyCode then
                                        AddCurrGLEntryVATAmt := "Source Curr. VAT Amount"
                                    else
                                        AddCurrGLEntryVATAmt := CalcLCYToAddCurr(GLEntry."VAT Amount");
                                end else begin
                                    GLEntry."VAT Amount" :=
                                      Round(
                                        "Amount (LCY)" * VATPostingSetup."VAT %" / (100 + VATPostingSetup."VAT %"),
                                        LCYCurrency."Amount Rounding Precision", LCYCurrency.VATRoundingDirection);
                                    GLEntry.Amount := "Amount (LCY)" - GLEntry."VAT Amount";
                                    if "Source Currency Code" = AddCurrencyCode then
                                        AddCurrGLEntryVATAmt :=
                                          Round(
                                            "Source Currency Amount" * VATPostingSetup."VAT %" / (100 + VATPostingSetup."VAT %"),
                                            AddCurrency."Amount Rounding Precision", AddCurrency.VATRoundingDirection)
                                    else
                                        AddCurrGLEntryVATAmt := CalcLCYToAddCurr(GLEntry."VAT Amount");
                                    GLEntry."Additional-Currency Amount" := "Source Currency Amount" - AddCurrGLEntryVATAmt;
                                end;
                            "VAT Calculation Type"::"Reverse Charge VAT":
                                case "Gen. Posting Type" of
                                    "Gen. Posting Type"::Purchase:
                                        if "VAT Difference" <> 0 then begin
                                            GLEntry."VAT Amount" := "VAT Amount (LCY)";
                                            if "Source Currency Code" = AddCurrencyCode then
                                                AddCurrGLEntryVATAmt := "Source Curr. VAT Amount"
                                            else
                                                AddCurrGLEntryVATAmt := CalcLCYToAddCurr(GLEntry."VAT Amount");
                                        end else begin
                                            GLEntry."VAT Amount" :=
                                              Round(
                                                GLEntry.Amount * VATPostingSetup."VAT %" / 100,
                                                LCYCurrency."Amount Rounding Precision", LCYCurrency.VATRoundingDirection);
                                            if "Source Currency Code" = AddCurrencyCode then
                                                AddCurrGLEntryVATAmt :=
                                                  Round(
                                                    GLEntry."Additional-Currency Amount" * VATPostingSetup."VAT %" / 100,
                                                    AddCurrency."Amount Rounding Precision", AddCurrency.VATRoundingDirection)
                                            else
                                                AddCurrGLEntryVATAmt := CalcLCYToAddCurr(GLEntry."VAT Amount");
                                        end;
                                    "Gen. Posting Type"::Sale:
                                        begin
                                            GLEntry."VAT Amount" := 0;
                                            AddCurrGLEntryVATAmt := 0;
                                        end;
                                end;
                            "VAT Calculation Type"::"Full VAT":
                                begin
                                    IsHandled := false;
                                    OnInitVATOnBeforeTestFullVATAccount(GenJnlLine, GLEntry, VATPostingSetup, IsHandled);
                                    if not IsHandled then
                                        case "Gen. Posting Type" of
                                            "Gen. Posting Type"::Sale:
                                                TestField("Account No.", VATPostingSetup.GetSalesAccount(false));
                                            "Gen. Posting Type"::Purchase:
                                                TestField("Account No.", VATPostingSetup.GetPurchAccount(false));
                                        end;
                                    GLEntry.Amount := 0;
                                    GLEntry."Additional-Currency Amount" := 0;
                                    GLEntry."VAT Amount" := "Amount (LCY)";
                                    if "Source Currency Code" = AddCurrencyCode then
                                        AddCurrGLEntryVATAmt := "Source Currency Amount"
                                    else
                                        AddCurrGLEntryVATAmt := CalcLCYToAddCurr("Amount (LCY)");
                                end;
                            "VAT Calculation Type"::"Sales Tax":
                                begin
                                    if ("Gen. Posting Type" = "Gen. Posting Type"::Purchase) and
                                       "Use Tax"
                                    then begin
                                        GLEntry."VAT Amount" :=
                                          Round(
                                            SalesTaxCalculate.CalculateTax(
                                              "Tax Area Code", "Tax Group Code", "Tax Liable",
                                              "Posting Date", "Amount (LCY)", Quantity, 0));
                                        OnAfterSalesTaxCalculateCalculateTax(GenJnlLine, GLEntry, LCYCurrency);
                                        GLEntry.Amount := "Amount (LCY)";
                                    end else begin
                                        GLEntry.Amount :=
                                          Round(
                                            SalesTaxCalculate.ReverseCalculateTax(
                                              "Tax Area Code", "Tax Group Code", "Tax Liable",
                                              "Posting Date", "Amount (LCY)", Quantity, 0));
                                        OnAfterSalesTaxCalculateReverseCalculateTax(GenJnlLine, GLEntry, LCYCurrency);
                                        GLEntry."VAT Amount" := "Amount (LCY)" - GLEntry.Amount;
                                    end;
                                    GLEntry."Additional-Currency Amount" := "Source Currency Amount";
                                    if "Source Currency Code" = AddCurrencyCode then
                                        AddCurrGLEntryVATAmt := "Source Curr. VAT Amount"
                                    else
                                        AddCurrGLEntryVATAmt := CalcLCYToAddCurr(GLEntry."VAT Amount");
                                end;
                        end;
                    end;
                "VAT Posting"::"Manual VAT Entry":
                    if "Gen. Posting Type" <> "Gen. Posting Type"::Settlement then begin
                        GLEntry.CopyPostingGroupsFromGenJnlLine(GenJnlLine);
                        GLEntry."VAT Amount" := "VAT Amount (LCY)";
                        if "Source Currency Code" = AddCurrencyCode then
                            AddCurrGLEntryVATAmt := "Source Curr. VAT Amount"
                        else
                            AddCurrGLEntryVATAmt := CalcLCYToAddCurr("VAT Amount (LCY)");
                    end;
            end;
           **END; //-------------------------------------------------  END IF**
        end;

    **GLEntry."Additional-Currency Amount" :=
      GLCalcAddCurrency(GLEntry.Amount, GLEntry."Additional-Currency Amount", GLEntry."Additional-Currency Amount", true, GenJnlLine);

    OnAfterInitVAT(GenJnlLine, GLEntry, VATPostingSetup, AddCurrGLEntryVATAmt);
end;**

Softstore avatar Jan 27 '21 22:01 Softstore

Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. We will update this issue with information about availability. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.

JesperSchulz avatar Feb 01 '21 15:02 JesperSchulz