microsoft / ALAppExtensions

Repository for collaboration on Microsoft AL application add-on and localization extensions for Microsoft Dynamics 365 Business Central.
MIT License
785 stars 621 forks source link

[EventRequest] Page 31141 "VIES Declaration Lines CZL".CopyLineToDeclaration #18805

Closed fridrichovsky closed 2 years ago

fridrichovsky commented 2 years ago

Please do change in events. If is it possible do it by option A it will be great. Bellow is option B also.

OptionA

    //-------------------------------------OnBeforeVIESDeclarationLineInsert:END
    begin
        CurrPage.SetSelectionFilter(FirstVIESDeclarationLineCZL);
        if FirstVIESDeclarationLineCZL.FindSet() then
            repeat
                SecondVIESDeclarationLineCZL.Init();
                SecondVIESDeclarationLineCZL."VIES Declaration No." := VIESDeclarationHeaderCZL."No.";
                LastLineNo += 10000;
                SecondVIESDeclarationLineCZL."Line No." := LastLineNo;
                SecondVIESDeclarationLineCZL."Trade Type" := FirstVIESDeclarationLineCZL."Trade Type";
                SecondVIESDeclarationLineCZL."Line Type" := FirstVIESDeclarationLineCZL."Line Type"::Cancellation;
                SecondVIESDeclarationLineCZL."Related Line No." := FirstVIESDeclarationLineCZL."Line No.";
                SecondVIESDeclarationLineCZL."Country/Region Code" := FirstVIESDeclarationLineCZL."Country/Region Code";
                SecondVIESDeclarationLineCZL."VAT Registration No." := FirstVIESDeclarationLineCZL."VAT Registration No.";
                SecondVIESDeclarationLineCZL."Amount (LCY)" := FirstVIESDeclarationLineCZL."Amount (LCY)";
                SecondVIESDeclarationLineCZL."EU 3-Party Trade" := FirstVIESDeclarationLineCZL."EU 3-Party Trade";
                SecondVIESDeclarationLineCZL."EU Service" := FirstVIESDeclarationLineCZL."EU Service";
                SecondVIESDeclarationLineCZL."EU 3-Party Intermediate Role" := FirstVIESDeclarationLineCZL."EU 3-Party Intermediate Role";
                SecondVIESDeclarationLineCZL."Trade Role Type" := FirstVIESDeclarationLineCZL."Trade Role Type";
                SecondVIESDeclarationLineCZL."Number of Supplies" := FirstVIESDeclarationLineCZL."Number of Supplies";
                SecondVIESDeclarationLineCZL."System-Created" := true;
                //----------------------------------------OnBeforeVIESDeclarationLineCorrectionInsert:BEGIN
                // move calling the event here
                OnBeforeVIESDeclarationLineInsert(FirstVIESDeclarationLineCZL, SecondVIESDeclarationLineCZL);
                //----------------------------------------OnBeforeVIESDeclarationLineCorrectionInsert:END               
                SecondVIESDeclarationLineCZL.Insert();
                SecondVIESDeclarationLineCZL."Line No." := LastLineNo + 10000;
                LastLineNo += 10000;
                SecondVIESDeclarationLineCZL."Line Type" := FirstVIESDeclarationLineCZL."Line Type"::Correction;
                SecondVIESDeclarationLineCZL."System-Created" := false;
                OnBeforeVIESDeclarationLineInsert(FirstVIESDeclarationLineCZL, SecondVIESDeclarationLineCZL);
                //-------------------------------------OnBeforeVIESDeclarationLineCorrectionInsert:BEGIN
                // move calling the event from this position
                //OnBeforeVIESDeclarationLineInsert(FirstVIESDeclarationLineCZL, SecondVIESDeclarationLineCZL);
                OnBeforeVIESDeclarationLineCorrectionInsert(SecondVIESDeclarationLineCZL, LastLineNo, IsHandled);
                if not IsHandled then
                //-------------------------------------OnBeforeVIESDeclarationLineCorrectionInsert:END
                  SecondVIESDeclarationLineCZL.Insert();
                OnAfterVIESDeclarationLineInsert(SecondVIESDeclarationLineCZL, LastLineNo);
            until FirstVIESDeclarationLineCZL.Next() = 0;
    end;
    //----------------------------------------OnBeforeVIESDeclarationLineCorrectionInsert:BEGIN
    [IntegrationEvent(true, false)]
    local OnBeforeVIESDeclarationLineCorrectionInsert(var VIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; var LastLineNo: Integer; var IsHandled: Boolean)
    begin
    end;
    //----------------------------------------OnBeforeVIESDeclarationLineCorrectionInsert:END               

OptionB

    procedure CopyLineToDeclaration()
    //-------------------------------------OnBeforeVIESDeclarationLineCancellationInsert:BEGIN
    var
        IsHandled: Boolean;
    //-------------------------------------OnBeforeVIESDeclarationLineCancellationInsert:END
    begin
        CurrPage.SetSelectionFilter(FirstVIESDeclarationLineCZL);
        if FirstVIESDeclarationLineCZL.FindSet() then
            repeat
                SecondVIESDeclarationLineCZL.Init();
                SecondVIESDeclarationLineCZL."VIES Declaration No." := VIESDeclarationHeaderCZL."No.";
                LastLineNo += 10000;
                SecondVIESDeclarationLineCZL."Line No." := LastLineNo;
                SecondVIESDeclarationLineCZL."Trade Type" := FirstVIESDeclarationLineCZL."Trade Type";
                SecondVIESDeclarationLineCZL."Line Type" := FirstVIESDeclarationLineCZL."Line Type"::Cancellation;
                SecondVIESDeclarationLineCZL."Related Line No." := FirstVIESDeclarationLineCZL."Line No.";
                SecondVIESDeclarationLineCZL."Country/Region Code" := FirstVIESDeclarationLineCZL."Country/Region Code";
                SecondVIESDeclarationLineCZL."VAT Registration No." := FirstVIESDeclarationLineCZL."VAT Registration No.";
                SecondVIESDeclarationLineCZL."Amount (LCY)" := FirstVIESDeclarationLineCZL."Amount (LCY)";
                SecondVIESDeclarationLineCZL."EU 3-Party Trade" := FirstVIESDeclarationLineCZL."EU 3-Party Trade";
                SecondVIESDeclarationLineCZL."EU Service" := FirstVIESDeclarationLineCZL."EU Service";
                SecondVIESDeclarationLineCZL."EU 3-Party Intermediate Role" := FirstVIESDeclarationLineCZL."EU 3-Party Intermediate Role";
                SecondVIESDeclarationLineCZL."Trade Role Type" := FirstVIESDeclarationLineCZL."Trade Role Type";
                SecondVIESDeclarationLineCZL."Number of Supplies" := FirstVIESDeclarationLineCZL."Number of Supplies";
                SecondVIESDeclarationLineCZL."System-Created" := true;
                //----------------------------------------OnBeforeVIESDeclarationLineCancellationInsert:BEGIN
                OnBeforeVIESDeclarationLineCancellationInsert(FirstVIESDeclarationLineCZL, SecondVIESDeclarationLineCZL);
                //----------------------------------------OnBeforeVIESDeclarationLineCancellationInsert:END               
                SecondVIESDeclarationLineCZL.Insert();
                SecondVIESDeclarationLineCZL."Line No." := LastLineNo + 10000;
                LastLineNo += 10000;
                SecondVIESDeclarationLineCZL."Line Type" := FirstVIESDeclarationLineCZL."Line Type"::Correction;
                SecondVIESDeclarationLineCZL."System-Created" := false;
                OnBeforeVIESDeclarationLineInsert(FirstVIESDeclarationLineCZL, SecondVIESDeclarationLineCZL);
                //-------------------------------------OnBeforeVIESDeclarationLineCancellationInsert:BEGIN
                //OnBeforeVIESDeclarationLineInsert(FirstVIESDeclarationLineCZL, SecondVIESDeclarationLineCZL);
                OnBeforeVIESDeclarationLineInsert(FirstVIESDeclarationLineCZL, SecondVIESDeclarationLineCZL, LastLineNo, IsHandled);
                if not IsHandled then
                //-------------------------------------OnBeforeVIESDeclarationLineCancellationInsert:END
                  SecondVIESDeclarationLineCZL.Insert();
                OnAfterVIESDeclarationLineInsert(SecondVIESDeclarationLineCZL, LastLineNo);
            until FirstVIESDeclarationLineCZL.Next() = 0;
    end;
    //----------------------------------------OnBeforeVIESDeclarationLineCancellationInsert:BEGIN
    [IntegrationEvent(true, false)]
    local OnBeforeVIESDeclarationLineCancellationInsert(FirstVIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; var SecondVIESDeclarationLineCZL: Record "VIES Declaration Line CZL")
    begin
    end;
    //----------------------------------------OnBeforeVIESDeclarationLineCancellationInsert:END               

    [IntegrationEvent(false, false)]
    local procedure OnBeforeVIESDeclarationLineInsert(FirstVIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; var SecondVIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; var LastLineNo: Integer; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnAfterVIESDeclarationLineInsert(SecondVIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; var LastLineNo: Integer)
    begin
    end;
DavidHolusa commented 2 years ago

Hi @fridrichovsky. The OptionA changes the semantic of OnBeforeVIESDeclarationLineInsert event and OptionB implements handle pattern inside the function which is not the best solution. Here is the my optionC.

    procedure CopyLineToDeclaration()
    begin
        CurrPage.SetSelectionFilter(FirstVIESDeclarationLineCZL);
        if FirstVIESDeclarationLineCZL.FindSet() then
            repeat
                CreateLine(FirstVIESDeclarationLineCZL."Line Type"::Cancellation);
                CreateLine(FirstVIESDeclarationLineCZL."Line Type"::Correction);
            until FirstVIESDeclarationLineCZL.Next() = 0;
    end;

    local procedure CreateLine(LineType: Option)
    var
        SecondVIESDeclarationLineCZL: Record "VIES Declaration Line CZL";
        IsHandled: Boolean;
    begin
        OnBeforeCreateLine(FirstVIESDeclarationLineCZL, LineType, LastLineNo, IsHandled);
        if IsHandled then
            exit;

        LastLineNo += 10000;
        SecondVIESDeclarationLineCZL.Init();
        SecondVIESDeclarationLineCZL."VIES Declaration No." := VIESDeclarationHeaderCZL."No.";
        SecondVIESDeclarationLineCZL."Line No." := LastLineNo;
        SecondVIESDeclarationLineCZL."Trade Type" := FirstVIESDeclarationLineCZL."Trade Type";
        SecondVIESDeclarationLineCZL."Line Type" := LineType;
        SecondVIESDeclarationLineCZL."Related Line No." := FirstVIESDeclarationLineCZL."Line No.";
        SecondVIESDeclarationLineCZL."Country/Region Code" := FirstVIESDeclarationLineCZL."Country/Region Code";
        SecondVIESDeclarationLineCZL."VAT Registration No." := FirstVIESDeclarationLineCZL."VAT Registration No.";
        SecondVIESDeclarationLineCZL."Amount (LCY)" := FirstVIESDeclarationLineCZL."Amount (LCY)";
        SecondVIESDeclarationLineCZL."EU 3-Party Trade" := FirstVIESDeclarationLineCZL."EU 3-Party Trade";
        SecondVIESDeclarationLineCZL."EU Service" := FirstVIESDeclarationLineCZL."EU Service";
        SecondVIESDeclarationLineCZL."EU 3-Party Intermediate Role" := FirstVIESDeclarationLineCZL."EU 3-Party Intermediate Role";
        SecondVIESDeclarationLineCZL."Trade Role Type" := FirstVIESDeclarationLineCZL."Trade Role Type";
        SecondVIESDeclarationLineCZL."Number of Supplies" := FirstVIESDeclarationLineCZL."Number of Supplies";
        SecondVIESDeclarationLineCZL."System-Created" :=
            SecondVIESDeclarationLineCZL."Line Type" = SecondVIESDeclarationLineCZL."Line Type"::Cancellation;
#if not CLEAN21
#pragma warning disable AL0432
        if SecondVIESDeclarationLineCZL."Line Type" = SecondVIESDeclarationLineCZL."Line Type"::Correction then
            OnBeforeVIESDeclarationLineInsert(FirstVIESDeclarationLineCZL, SecondVIESDeclarationLineCZL);
#pragma warning restore AL0432
#endif
        OnBeforeInsertVIESDeclarationLine(FirstVIESDeclarationLineCZL, SecondVIESDeclarationLineCZL);
        SecondVIESDeclarationLineCZL.Insert();
#if not CLEAN21
#pragma warning disable AL0432
        if SecondVIESDeclarationLineCZL."Line Type" = SecondVIESDeclarationLineCZL."Line Type"::Correction then
            OnAfterVIESDeclarationLineInsert(SecondVIESDeclarationLineCZL, LastLineNo);
#pragma warning restore AL0432
#endif
        OnAfterCreateLine(SecondVIESDeclarationLineCZL, LastLineNo);
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeCreateLine(FromVIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; LineType: Option; var LastLineNo: Integer; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforeInsertVIESDeclarationLine(FromVIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; var VIESDeclarationLineCZL: Record "VIES Declaration Line CZL")
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnAfterCreateLine(VIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; var LastLineNo: Integer)
    begin
    end;
#if not CLEAN21
    [Obsolete('Replaced by OnBeforeInsertVIESDeclarationLine function.', '21.0')]
    [IntegrationEvent(false, false)]
    local procedure OnBeforeVIESDeclarationLineInsert(FirstVIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; var SecondVIESDeclarationLineCZL: Record "VIES Declaration Line CZL")
    begin
    end;

    [Obsolete('Replaced by OnAfterCreateLine function.', '21.0')]
    [IntegrationEvent(false, false)]
    local procedure OnAfterVIESDeclarationLineInsert(SecondVIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; var LastLineNo: Integer)
    begin
    end;
#endif

is it ok for you?

JesperSchulz commented 2 years ago

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. 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.

Build ID: 42968.

fridrichovsky commented 2 years ago

Yes it can be done by your Option C.