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

[Event Request] Codeunit 225 "Gen. Jnl.-Apply".ApplyVendorLedgerEntry #27931

Open
fridrichovsky opened this issue Jan 13, 2025 · 0 comments
Open
Labels
event-request Request for adding an event SCM GitHub request for SCM area

Comments

@fridrichovsky
Copy link
Contributor

fridrichovsky commented Jan 13, 2025

Describe the request

Please add new parameter to event

local procedure ApplyVendorLedgerEntry(var GenJnlLine: Record "Gen. Journal Line")
    var
        VendLedgEntry: Record "Vendor Ledger Entry";
        TempVendorLedgerEntry: Record "Vendor Ledger Entry" temporary;
        CustomAppliesToId: Code[50];
        IsHandled: Boolean;
    begin
        GetAppliedVendorEntries(TempVendorLedgerEntry, GenJnlLine);
        EntrySelected := SelectVendLedgEntry(GenJnlLine, CustomAppliesToId);
        if not EntrySelected then
            exit;

        VendLedgEntry.Reset();
        VendLedgEntry.SetCurrentKey("Vendor No.", Open, Positive);
        VendLedgEntry.SetRange("Vendor No.", AccNo);
        VendLedgEntry.SetRange(Open, true);
        VendLedgEntry.SetRange("Applies-to ID", GenJnlLine."Applies-to ID");
        OnAfterVendLedgEntrySetFilters(VendLedgEntry, GenJnlLine, AccNo);
        if VendLedgEntry.Find('-') then begin
            CurrencyCode2 := VendLedgEntry."Currency Code";
            if GenJnlLine.Amount = 0 then begin
                repeat
                    if not TempVendorLedgerEntry.Get(VendLedgEntry."Entry No.") then begin
                        PaymentToleranceMgt.DelPmtTolApllnDocNo(GenJnlLine, VendLedgEntry."Document No.");
                        OnApplyVendorLedgerEntryOnBeforeCheckAgainstApplnCurrency(GenJnlLine, VendLedgEntry);
                        CheckAgainstApplnCurrency(CurrencyCode2, VendLedgEntry."Currency Code", AccType::Vendor, true);
                        UpdateVendLedgEntry(VendLedgEntry);
                        IsHandled := false;
                        OnBeforeFindVendApply(GenJnlLine, VendLedgEntry, GenJnlLine.Amount, IsHandled);
                        if not IsHandled then
                            if PaymentToleranceMgt.CheckCalcPmtDiscGenJnlVend(GenJnlLine, VendLedgEntry, 0, false) and
                               (Abs(VendLedgEntry."Amount to Apply") >=
                                Abs(VendLedgEntry."Remaining Amount" - VendLedgEntry.GetRemainingPmtDiscPossible(GenJnlLine."Posting Date")))
                            then
                                GenJnlLine.Amount := GenJnlLine.Amount - (VendLedgEntry."Amount to Apply" - VendLedgEntry.GetRemainingPmtDiscPossible(GenJnlLine."Posting Date"))
                            else
                                GenJnlLine.Amount := GenJnlLine.Amount - VendLedgEntry."Amount to Apply";
                        GenJnlLine."Remit-to Code" := VendLedgEntry."Remit-to Code";
                    end;
                until VendLedgEntry.Next() = 0;
                TempVendorLedgerEntry.DeleteAll();
                if (GenJnlLine."Bal. Account Type" = GenJnlLine."Bal. Account Type"::Customer) or (GenJnlLine."Bal. Account Type" = GenJnlLine."Bal. Account Type"::Vendor) then
                    GenJnlLine.Amount := -GenJnlLine.Amount;
                //----------------------------------------------------------OnApplyVendorLedgerEntryOnBeforeValidateAmount:BEGIN
                //OnApplyVendorLedgerEntryOnBeforeValidateAmount(GenJnlLine);
                OnApplyVendorLedgerEntryOnBeforeValidateAmount(GenJnlLine, VendLedgEntry);
                //----------------------------------------------------------OnApplyVendorLedgerEntryOnBeforeValidateAmount:END
                GenJnlLine.Validate(Amount);
            end else
                repeat
                    OnApplyVendorLedgerEntryOnBeforeCheckAgainstApplnCurrencyAmountNotZero(GenJnlLine, VendLedgEntry);
                    CheckAgainstApplnCurrency(CurrencyCode2, VendLedgEntry."Currency Code", AccType::Vendor, true);
                until VendLedgEntry.Next() = 0;
            if GenJnlLine."Currency Code" <> CurrencyCode2 then
                if GenJnlLine.Amount = 0 then begin
                    IsHandled := false;
                    OnApplyVendorLedgerEntryOnBeforeConfirmUpdateCurrency(GenJnlLine, VendLedgEntry."Currency Code", IsHandled);
                    if not IsHandled then begin
                        ConfirmCurrencyUpdate(GenJnlLine, VendLedgEntry."Currency Code");
                        GenJnlLine."Currency Code" := VendLedgEntry."Currency Code";
                    end;
                end else begin
                    OnApplyVendorLedgerEntryOnBeforeCheckAgainstApplnCurrencyDifferentCurrenciesAmountNotZero(GenJnlLine, VendLedgEntry);
                    CheckAgainstApplnCurrency(GenJnlLine."Currency Code", VendLedgEntry."Currency Code", AccType::Vendor, true);
                end;
            GenJnlLine."Applies-to Doc. Type" := GenJnlLine."Applies-to Doc. Type"::" ";
            GenJnlLine."Applies-to Doc. No." := '';
            OnApplyVendorLedgerEntryOnAfterSetGenJnlLineAppliesToDocNo(GenJnlLine, VendLedgEntry);
        end else
            GenJnlLine."Applies-to ID" := '';

        if (GenJnlLine."Applies-to ID" = '') and (CustomAppliesToId <> '') then
            GenJnlLine."Applies-to ID" := CustomAppliesToId;

        GenJnlLine.SetJournalLineFieldsFromApplication();

        OnApplyVendorLedgerEntryOnBeforeModify(GenJnlLine, TempVendorLedgerEntry, VendLedgEntry);
        if GenJnlLine.Modify() then;
        if GenJnlLine.Amount <> 0 then
            if not PaymentToleranceMgt.PmtTolGenJnl(GenJnlLine) then
                exit;
    end;

    //----------------------------------------------------------OnApplyVendorLedgerEntryOnBeforeValidateAmount:BEGIN
    //[IntegrationEvent(false, false)]
    //local procedure OnApplyVendorLedgerEntryOnBeforeValidateAmount(var GenJournalLine: Record "Gen. Journal Line")
    [IntegrationEvent(true, false)]
    local procedure OnApplyVendorLedgerEntryOnBeforeValidateAmount(var GenJournalLine: Record "Gen. Journal Line"; var VendLedgEntry: Record "Vendor Ledger Entry")
    begin
    end;
    //----------------------------------------------------------OnApplyVendorLedgerEntryOnBeforeValidateAmount:END

Additional context

We need work with vendor ledger entry and GenJournal before amoutnts are calculated.
Internal work item: AB#562608

@JesperSchulz JesperSchulz added event-request Request for adding an event SCM GitHub request for SCM area labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
event-request Request for adding an event SCM GitHub request for SCM area
Projects
None yet
Development

No branches or pull requests

2 participants