Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EventRequest] Report 1307 "Standard Sales - Credit Memo" OnBeforeVATAmountLineInsertLine #28154

Open
fvanderhek opened this issue Feb 14, 2025 · 0 comments

Comments

@fvanderhek
Copy link

Describe the request

Requesting a new event publisher on Report 1307 "Standard Sales - Credit Memo"

Event
OnBeforeVATAmountLineInsertLine(var VATAmountLine: Record "VAT Amount Line"; SalesInvoiceLine: Record "Sales Invoice Line"; var IsHandled: Boolean)

In Report 1306 "Standard Sales - Invoice" this is already done and avilable:

Code

OnAfterGetRecord() ("Sales Invoice Line" Data-item)

begin
    InitializeShipmentLine();
    if Type = Type::"G/L Account" then
        "No." := '';

    OnBeforeLineOnAfterGetRecord(Header, Line);

    if "Line Discount %" = 0 then
        LineDiscountPctText := ''
    else
        LineDiscountPctText := StrSubstNo('%1%', -Round("Line Discount %", 0.1));

This procedure call is added!

    InsertVATAmountLine(VATAmountLine, Line);
        TransHeaderAmount += PrevLineAmount;
        PrevLineAmount := "Line Amount";
        TotalSubTotal += "Line Amount";
        TotalInvDiscAmount -= "Inv. Discount Amount";
        TotalAmount += Amount;
        TotalAmountVAT += "Amount Including VAT" - Amount;
        TotalAmountInclVAT += "Amount Including VAT";
        TotalPaymentDiscOnVAT += -("Line Amount" - "Inv. Discount Amount" - "Amount Including VAT");

        if FormatDocument.HideDocumentLine(HideLinesWithZeroQuantity, Line, FieldNo(Quantity)) then
            CurrReport.Skip();
        if FirstLineHasBeenOutput then
            Clear(DummyCompanyInfo.Picture);
        FirstLineHasBeenOutput := true;

        JobNo := "Job No.";
        JobTaskNo := "Job Task No.";

        if JobTaskNo <> '' then begin
            JobTaskNoLbl := JobTaskNoLbl2;
            JobTaskDescription := GetJobTaskDescription(JobNo, JobTaskNo);
        end else begin
            JobTaskDescription := '';
            JobTaskNoLbl := '';
        end;

        if JobNo <> '' then
            JobNoLbl := JobNoLbl2
        else
            JobNoLbl := '';

        FormatLineValues(Line);
    end;

The Below defined procedure and Integration event can be copied from Report 1306 "Standard Sales - Invoice"

local procedure InsertVATAmountLine(var VATAmountLine2: Record "VAT Amount Line"; SalesInvoiceLine: Record "Sales Invoice Line")
var
    IsHandled: Boolean;
begin
    IsHandled := false;
    OnBeforeVATAmountLineInsertLine(VATAmountLine2, SalesInvoiceLine, IsHandled);
    if IsHandled then
        exit;

    VATAmountLine2.Init();
    VATAmountLine2."VAT Identifier" := SalesInvoiceLine."VAT Identifier";
    VATAmountLine2."VAT Calculation Type" := SalesInvoiceLine."VAT Calculation Type";
    VATAmountLine2."Tax Group Code" := SalesInvoiceLine."Tax Group Code";
    VATAmountLine2."VAT %" := SalesInvoiceLine."VAT %";
    VATAmountLine2."VAT Base" := SalesInvoiceLine.Amount;
    VATAmountLine2."Amount Including VAT" := SalesInvoiceLine."Amount Including VAT";
    VATAmountLine2."Line Amount" := SalesInvoiceLine."Line Amount";
    if SalesInvoiceLine."Allow Invoice Disc." then
        VATAmountLine2."Inv. Disc. Base Amount" := SalesInvoiceLine."Line Amount";
    VATAmountLine2."Invoice Discount Amount" := SalesInvoiceLine."Inv. Discount Amount";
    VATAmountLine2."VAT Clause Code" := SalesInvoiceLine."VAT Clause Code";
    VATAmountLine2.InsertLine();
end;

And Integration Event:

[IntegrationEvent(false, false)]
local procedure OnBeforeVATAmountLineInsertLine(var VATAmountLine: Record "VAT Amount Line"; SalesInvoiceLine: Record "Sales Invoice Line"; var IsHandled: Boolean)
begin
end;

The Above defined integration event we also need in Report 1307 "Standard Sales - Credit Memo

So in Report report 1307 "Standard Sales - Credit Memo" the code is now as shown below:

trigger OnAfterGetRecord()
begin
    InitializeSalesShipmentLine();
    if Type = Type::"G/L Account" then
        "No." := '';

    OnLineOnAfterGetRecordOnBeforeCheckLineDiscount(Line, Header);
    if "Line Discount %" = 0 then
        LineDiscountPctText := ''
    else
        LineDiscountPctText := StrSubstNo('%1%', -Round("Line Discount %", 0.1));

Copy below written code to new to add procedure InsertVATAmountLine(VATAmountLine, Line)

    VATAmountLine.Init();
    VATAmountLine."VAT Identifier" := "VAT Identifier";
    VATAmountLine."VAT Calculation Type" := "VAT Calculation Type";
    VATAmountLine."Tax Group Code" := "Tax Group Code";
    VATAmountLine."VAT %" := "VAT %";
    VATAmountLine."VAT Base" := Amount;
    VATAmountLine."Amount Including VAT" := "Amount Including VAT";
    VATAmountLine."Line Amount" := "Line Amount";
    if "Allow Invoice Disc." then
        VATAmountLine."Inv. Disc. Base Amount" := "Line Amount";
    VATAmountLine."Invoice Discount Amount" := "Inv. Discount Amount";
    VATAmountLine."VAT Clause Code" := "VAT Clause Code";
    VATAmountLine.InsertLine();

Rest of Code

Additional context

Please make the handling of writing VATAmountLines consistent between de Sales Reports 1306 and 1307. We now encounter the issue that a VATAmountLine is inserted also for Text Lines in Report 1307 "Standard Sales - Credit Memo". With the above mentioned change we can subscribe and skip the creation of VATAmountLines for Text Sales Credit Memo Lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant