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] Codeunit 13 "Gen. Jnl.-Post Batch" - OnProcessBalanceOfLinesOnBeforeCheckLine #26998

Open RZ440 opened 1 month ago

RZ440 commented 1 month ago

Describe the request

Hello, can you please add a new event OnProcessBalanceOfLinesOnBeforeCheckLine in codeunit 13 "Gen. Jnl.-Post Batch"?

local procedure ProcessBalanceOfLines(var GenJnlLine: Record "Gen. Journal Line"; var GenJnlLineVATInfoSource: Record "Gen. Journal Line"; var VATInfoSourceLineIsInserted: Boolean; var LastLineNo: Integer; CurrentICPartner: Code[20])
.
.
.
        repeat
            LineCount := LineCount + 1;
            UpdateDialog(RefPostingState::"Checking balance", LineCount, NoOfRecords);

        IsHandled := false;
            OnProcessBalanceOfLinesOnBeforeCheckLine(GenJnlLine, IsHandled);
            if not IsHandled then begin
           if not GenJnlLine.EmptyLine() then begin
                    ShouldCheckDocNoBasedOnNoSeries := not PreviewMode and (GenJnlBatch."No. Series" <> '') and (LastDocNo <> GenJnlLine."Document No.");
                    SkipCheckingPostingNoSeries := false;
                    OnProcessBalanceOfLinesOnAfterCalcShouldCheckDocNoBasedOnNoSeries(GenJnlLine, GenJnlBatch, ShouldCheckDocNoBasedOnNoSeries, SkipCheckingPostingNoSeries);
                    if ShouldCheckDocNoBasedOnNoSeries then begin
#if not CLEAN24
#pragma warning disable AL0432
                        // raises the old event.
                        GenJnlLine.ObsoleteCheckDocNoBasedOnNoSeries(LastDocNo, GenJnlBatch."No. Series", NoSeriesMgt);
#pragma warning restore AL0432
#endif
                        if GenJnlLine."Document No." = NoSeriesBatch.PeekNextNo(GenJnlBatch."No. Series", GenJnlLine."Posting Date") then
                            // No. used is same as peek so need to save it.
                            NoSeriesBatch.GetNextNo(GenJnlBatch."No. Series", GenJnlLine."Posting Date")
                        else
                            // manual nos should be allowed.
                            NoSeriesBatch.TestManual(GenJnlBatch."No. Series", GenJnlLine."Document No.");
                    end;
                    if not SkipCheckingPostingNoSeries then
                        if GenJnlLine."Posting No. Series" <> '' then
                            GenJnlLine.TestField("Posting No. Series", GenJnlBatch."Posting No. Series");
                    CheckCorrection(GenJnlLine, PaymentApplication, PaymentBalanceVAT, LastGenJournalLine);
                end;
                LastDocTypeOption := LastDocType.AsInteger();
                OnBeforeIfCheckBalance(GenJnlTemplate, GenJnlLine, LastDocTypeOption, LastDocNo, LastDate, ForceCheckBalance, SuppressCommit, IsHandled);
                LastDocType := "Gen. Journal Document Type".FromInteger(LastDocTypeOption);
                if not IsHandled then
                    if ForceCheckBalance or (GenJnlLine."Posting Date" <> LastDate) or GenJnlTemplate."Force Doc. Balance" and
                       ((GenJnlLine."Document Type" <> LastDocType) or (GenJnlLine."Document No." <> LastDocNo))
                    then begin
                        CheckBalance(GenJnlLine);
                        CheckPmtApplnAllowed(PaymentApplication, PaymentBalanceVAT, GenJnlLine);
                        CurrencyBalance := 0;
                        LastCurrencyCode := GenJnlLine."Currency Code";
                        TempGenJnlLine3.Reset();
                        TempGenJnlLine3.DeleteAll();
                    end;
                GetGenJnlLineParameters(PaymentApplication, PaymentBalanceVAT, GenJnlLine);

                if IsNonZeroAmount(GenJnlLine) then begin
                    if LastFAAddCurrExchRate <> GenJnlLine."FA Add.-Currency Factor" then
                        CheckAddExchRateBalance(GenJnlLine);
                    if (CurrentBalance = 0) and (CurrentICPartner = '') then begin
                        TempGenJnlLine3.Reset();
                        TempGenJnlLine3.DeleteAll();
                        if VATEntryCreated and VATInfoSourceLineIsInserted then
                            UpdateGenJnlLineWithVATInfo(GenJnlLine, GenJnlLineVATInfoSource, StartLineNo, LastLineNo);
                        VATEntryCreated := false;
                        VATInfoSourceLineIsInserted := false;
                        StartLineNo := GenJnlLine."Line No.";
                    end;
                    if CurrentBalanceReverse = 0 then
                        StartLineNoReverse := GenJnlLine."Line No.";
                    GenJnlLine.UpdateLineBalance();
                    OnAfterUpdateLineBalance(GenJnlLine);
                    CurrentBalance := CurrentBalance + GenJnlLine."Balance (LCY)";
                    if GenJnlLine."Recurring Method".AsInteger() >= GenJnlLine."Recurring Method"::"RF Reversing Fixed".AsInteger() then
                        CurrentBalanceReverse := CurrentBalanceReverse + GenJnlLine."Balance (LCY)";

                    UpdateCurrencyBalanceForRecurringLine(GenJnlLine);
                end;

                LastDate := GenJnlLine."Posting Date";
                LastDocType := GenJnlLine."Document Type";
                if not GenJnlLine.EmptyLine() then
                    LastDocNo := GenJnlLine."Document No.";
                LastFAAddCurrExchRate := GenJnlLine."FA Add.-Currency Factor";
                if GenJnlTemplate."Force Doc. Balance" then begin
                    if not VATPostingSetup.Get(GenJnlLine."VAT Bus. Posting Group", GenJnlLine."VAT Prod. Posting Group") then
                        Clear(VATPostingSetup);
                    if not BalVATPostingSetup.Get(GenJnlLine."Bal. VAT Bus. Posting Group", GenJnlLine."Bal. VAT Prod. Posting Group") then
                        Clear(BalVATPostingSetup);
                    VATEntryCreated :=
                      VATEntryCreated or
                      ((GenJnlLine."Account Type" = GenJnlLine."Account Type"::"G/L Account") and (GenJnlLine."Account No." <> '') and
                       (GenJnlLine."Gen. Posting Type" in [GenJnlLine."Gen. Posting Type"::Purchase, GenJnlLine."Gen. Posting Type"::Sale]) and
                       (VATPostingSetup."VAT %" <> 0)) or
                      ((GenJnlLine."Bal. Account Type" = GenJnlLine."Bal. Account Type"::"G/L Account") and (GenJnlLine."Bal. Account No." <> '') and
                       (GenJnlLine."Bal. Gen. Posting Type" in [GenJnlLine."Bal. Gen. Posting Type"::Purchase, GenJnlLine."Bal. Gen. Posting Type"::Sale]) and
                       (BalVATPostingSetup."VAT %" <> 0));
                    if TempGenJnlLine3.IsCustVendICAdded(GenJnlLine) then begin
                        GenJnlLineVATInfoSource := GenJnlLine;
                        VATInfoSourceLineIsInserted := true;
                    end;
                    if (TempGenJnlLine3.Count > 1) and VATEntryCreated then begin
                        ErrorMessage := Text009 + Text010;
                        Error(ErrorMessage, GenJnlLine."Document Type", GenJnlLine."Document No.", GenJnlLine."Posting Date");
                    end;
                    if (TempGenJnlLine3.Count > 1) and (CurrentICPartner <> '') and
                       (GenJnlTemplate.Type = GenJnlTemplate.Type::Intercompany)
                    then
                        Error(
                          Text029,
                          GenJnlLine."Document Type", GenJnlLine."Document No.", GenJnlLine."Posting Date");
                    LastLineNo := GenJnlLine."Line No.";
                end;
        end;
        LastGenJournalLine := GenJnlLine;
    until GenJnlLine.Next() = 0;

    [IntegrationEvent(false, false)]
    local procedure OnProcessBalanceOfLinesOnBeforeCheckLine(GenJournalLine: Record "Gen. Journal Line"; var IsHandled: Boolean)
    begin
    end;

Additional context

We would like to skip some lines that cannot easily be filtered. Internal work item: AB#545273