microsoft / ALAppExtensions

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

[Event Request] Table 31076 "VIES Declaration Line CZL".DrillDownAmountLCY #13885

Closed fridrichovsky closed 3 years ago

fridrichovsky commented 3 years ago

Please add new events

procedure DrillDownAmountLCY()
    var
        VATEntry: Record "VAT Entry";
        TempVATEntry: Record "VAT Entry" temporary;
        VATPostingSetup: Record "VAT Posting Setup";
        AddToDrillDown: Boolean;
        //----------------------------------------OnDrillDownAmountLCYOnBeforeVATPostSetupGet:BEGIN
    IsHandled: Boolean;
        //----------------------------------------OnDrillDownAmountLCYOnBeforeVATPostSetupGet:END
    begin
        VIESDeclarationHeaderCZL.Get("VIES Declaration No.");

        VATEntry.SetCurrentKey(Type, "Country/Region Code");
        VATEntry.SetRange(Type, "Trade Type" + 1);
        VATEntry.SetRange("Country/Region Code", "Country/Region Code");
        VATEntry.SetRange("VAT Registration No.", "VAT Registration No.");
        case "Trade Role Type" of
            "Trade Role Type"::"Direct Trade":
                VATEntry.SetRange("EU 3-Party Trade", false);
            "Trade Role Type"::"Intermediate Trade":
                VATEntry.SetRange("EU 3-Party Trade", true);
            "Trade Role Type"::"Property Movement":
                exit;
        end;
        VATEntry.SetRange("VAT Date CZL", VIESDeclarationHeaderCZL."Start Date", VIESDeclarationHeaderCZL."End Date");
        VATEntry.SetRange("EU Service", "EU Service");
    //----------------------------------------OnDrillDownAmountLCYOnBeforeVATEntryFind:BEGIN
    OnDrillDownAmountLCYOnBeforeVATEntryFind(Rec, VIESDeclarationHeaderCZL, VATEntry);
    //----------------------------------------OnDrillDownAmountLCYOnBeforeVATEntryFind:END
        if VATEntry.FindSet() then
            repeat
                AddToDrillDown := false;
            //----------------------------------------OnDrillDownAmountLCYOnBeforeVATPostSetupGet:BEGIN
            IsHandled := false;
                OnDrillDownAmountLCYOnBeforeVATPostSetupGet(Rec, VIESDeclarationHeaderCZL, VATEntry, IsHandled);
        if not IsHandled then begin
            //----------------------------------------OnDrillDownAmountLCYOnBeforeVATPostSetupGet:END
                  if VATPostingSetup.Get(VATEntry."VAT Bus. Posting Group", VATEntry."VAT Prod. Posting Group") then begin
                      case "Trade Type" of
                          "Trade Type"::Sales:
                              AddToDrillDown := VATPostingSetup."VIES Sales CZL";
                          "Trade Type"::Purchase:
                              AddToDrillDown := VATPostingSetup."VIES Purchase CZL";
                      end;
                      if AddToDrillDown then begin
                          TempVATEntry := VATEntry;
                          TempVATEntry.Insert();
                      end;
                  end;
            //----------------------------------------OnDrillDownAmountLCYOnBeforeVATPostSetupGet:BEGIN
            end;
            //----------------------------------------OnDrillDownAmountLCYOnBeforeVATPostSetupGet:END
            until VATEntry.Next() = 0;

        Page.Run(0, TempVATEntry);
    end;

    //----------------------------------------OnDrillDownAmountLCYOnBeforeVATEntryFind:BEGIN
    [IntegrationEvent(false, false)]
    local OnDrillDownAmountLCYOnBeforeVATEntryFind(VIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; VIESDeclarationHeaderCZL: Record "VIES Declaration Header CZL"; var VATEntry: Record "VAT Entry")
    begin
    end;
    //----------------------------------------OnDrillDownAmountLCYOnBeforeVATEntryFind:END

    //----------------------------------------OnDrillDownAmountLCYOnBeforeVATPostSetupGet:BEGIN
    [IntegrationEvent(false, false)]
    local OnDrillDownAmountLCYOnBeforeVATPostSetupGet(VIESDeclarationLineCZL: Record "VIES Declaration Line CZL"; VIESDeclarationHeaderCZL: Record "VIES Declaration Header CZL"; VATEntry: Record "VAT Entry"; var IsHandled: Boolean)
    begin
    end;
    //----------------------------------------OnDrillDownAmountLCYOnBeforeVATPostSetupGet:END
Jiribu73 commented 3 years ago

@AlexanderYakunin - we need any reaction. It is blocking our business and we need to resolve it as soon as possible. Thanks Jiří Bureš CEO

DavidHolusa commented 3 years ago

Hi @fridrichovsky. Could you describe me what purpose of OnDrillDownAmountLCYOnBeforeVATPostSetupGet event? Could you provide me scenario of using? In this case is handled pattern used a little bit inconveniently so maybe we could find another solution for your scenario. Thanks

fridrichovsky commented 3 years ago

Hi @DavidHolusa. I found problem in our code. There should not be exit:

if IsHandled then
  exit(true);

I fixed code in my first comment. Main point is that we would like skip some vat entries. I hope that it is more clear now.

DavidHolusa commented 3 years ago

Hi @fridrichovsky. Yes it looks better and it's more clear now. I would like to redesign the code a bit and create a new function for adding the vat entry to buffer. In this new function should be implemented handled pattern. But I would create this function with two parameters. First vat entry and second temporary vat entry. But in your requested event you have variable VIESDeclarationHeaderCZL. What is the purpose? Do you need some information from VIES Declaration Header?

fridrichovsky commented 3 years ago

Hello, yes we need information from header where we added new field that say which VAT Entries we use.

DavidHolusa commented 3 years ago

Couldn't you use the information from header as filter for VAT entry?

DavidHolusa commented 3 years ago

Is the following new function ok for you?

    local procedure IsVATEntryIncludedToDrillDown(VATEntry: Record "VAT Entry") IsIncluded: Boolean
    var
        VATPostingSetup: Record "VAT Posting Setup";
        IsHandled: Boolean;
    begin
        GetHeader();
        OnBeforeIsVATEntryIncludedToDrillDown(VATEntry, Rec, VIESDeclarationHeaderCZL, IsIncluded, IsHandled);
        if IsHandled then
            exit(IsIncluded);

        if not VATPostingSetup.Get(VATEntry."VAT Bus. Posting Group", VATEntry."VAT Prod. Posting Group") then
            exit(false);

        case "Trade Type" of
            "Trade Type"::Sales:
                exit(VATPostingSetup."VIES Sales CZL");
            "Trade Type"::Purchase:
                exit(VATPostingSetup."VIES Purchase CZL");
        end;

        exit(false);
    end;
DavidHolusa commented 3 years ago

The DrillDownAmountLCY function looks like this:

    procedure DrillDownAmountLCY()
    var
        VATEntry: Record "VAT Entry";
        TempVATEntry: Record "VAT Entry" temporary;
    begin
        GetHeader();

        VATEntry.SetCurrentKey(Type, "Country/Region Code");
        VATEntry.SetRange(Type, "Trade Type" + 1);
        VATEntry.SetRange("Country/Region Code", "Country/Region Code");
        VATEntry.SetRange("VAT Registration No.", "VAT Registration No.");
        case "Trade Role Type" of
            "Trade Role Type"::"Direct Trade":
                VATEntry.SetRange("EU 3-Party Trade", false);
            "Trade Role Type"::"Intermediate Trade":
                VATEntry.SetRange("EU 3-Party Trade", true);
            "Trade Role Type"::"Property Movement":
                exit;
        end;
        VATEntry.SetRange("VAT Date CZL", VIESDeclarationHeaderCZL."Start Date", VIESDeclarationHeaderCZL."End Date");
        VATEntry.SetRange("EU Service", "EU Service");
        OnDrillDownAmountLCYOnBeforeVATEntryFind(Rec, VIESDeclarationHeaderCZL, VATEntry);
        if VATEntry.FindSet() then
            repeat
                if IsVATEntryIncludedToDrillDown(VATEntry) then begin
                    TempVATEntry := VATEntry;
                    TempVATEntry.Insert();
                end
            until VATEntry.Next() = 0;

        Page.Run(0, TempVATEntry);
    end;
JesperSchulz commented 3 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.