microsoft / ALAppExtensions

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

[Event Request] Codeunit 12 "Gen. Jnl.-Post Line" - OnCreateGLEntryVATCollectAdjOnBeforeInsertGLEntry #27013

Closed RZ440 closed 1 month ago

RZ440 commented 2 months ago

Describe the request

In the Event Request #26835 we asked for a new event OnCreateGLEntryVATCollectAdjOnBeforeInsertGLEntry in Codeunit 12 "Gen. Jnl.-Post Line".

    procedure CreateGLEntryVATCollectAdj(GenJnlLine: Record "Gen. Journal Line"; AccNo: Code[20]; Amount: Decimal; AmountAddCurr: Decimal; VATAmount: Decimal; DtldCVLedgEntryBuf: Record "Detailed CV Ledg. Entry Buffer"; var AdjAmount: array[4] of Decimal)
    var
        GLEntry: Record "G/L Entry";
    begin
        OnBeforeCreateGLEntryVATCollectAdj(GenJnlLine, DtldCVLedgEntryBuf);
        InitGLEntry(GenJnlLine, GLEntry, AccNo, Amount, 0, false, true);
        GLEntry."Additional-Currency Amount" := AmountAddCurr;
        GLEntry."VAT Amount" := VATAmount;
        GlEntry."Non-Deductible VAT Amount" := -DtldCVLedgEntryBuf."Non-Deductible VAT Amount LCY";
        GlEntry."Non-Deductible VAT Amount ACY" := -DtldCVLedgEntryBuf."Non-Deductible VAT Amount ACY";

        GLEntry.CopyPostingGroupsFromDtldCVBuf(DtldCVLedgEntryBuf, DtldCVLedgEntryBuf."Gen. Posting Type".AsInteger());
        OnCreateGLEntryVATCollectAdjOnBeforeInsertGLEntry(GenJnlLine, GLEntry);
        InsertGLEntry(GenJnlLine, GLEntry, true);
        CollectAdjustment(AdjAmount, GLEntry.Amount, GLEntry."Additional-Currency Amount");
        InsertVATEntriesFromTemp(DtldCVLedgEntryBuf, GLEntry);
    end;
    [IntegrationEvent(false, false)]
    local procedure OnCreateGLEntryVATCollectAdjOnBeforeInsertGLEntry(GenJournalLine: Record "Gen. Journal Line"; var GLEntry: Record "G/L Entry")
    begin
    end;

Additional context

You rejected the request recommending to use OnBeforeInsertGlEntry. But we would like to set some fields only in G/L Entries created in CreateGLEntryVATCollectAdj, but in InsertGLEntry we do not know where it is called from. Internal work item: AB#544387

AndersLarsenMicrosoft commented 1 month ago

use OnBeforeInsertGlEntry(GenJnlLine, GLEntry, IsHandled); in InsertGLEntry there you have both parameters, you should know by the data