Skip to content

[Event Request] Codeunit 6620 "Copy Document Mgt." - OnBeforeUpdateVendLedgEntry #27967

Open
@Athon-dev

Description

Describe the request

Hello, we would like to have more parameters in the aforementioned event (same as in the sales process for event OnBeforeUpdateCustLedgEntry).

procedure UpdateVendLedgEntry(var ToPurchHeader: Record "Purchase Header"; FromDocType: Enum "Gen. Journal Document Type"; FromDocNo: Code[20])
    var
        VendLedgEntry: Record "Vendor Ledger Entry";
        IsHandled: Boolean;
    begin
        IsHandled := false;
        //> NEW EVENT
        //OLD CODE: OnBeforeUpdateVendLedgEntry(ToPurchHeader, VendLedgEntry, IsHandled);
        OnBeforeUpdateVendLedgEntry(ToPurchHeader, VendLedgEntry, IsHandled, FromDocType, FromDocNo);
        //< NEW EVENT
        if not IsHandled then begin
            VendLedgEntry.SetCurrentKey("Document No.");
            if FromDocType = "Purchase Document Type From"::"Posted Invoice" then
                VendLedgEntry.SetRange("Document Type", VendLedgEntry."Document Type"::Invoice)
            else
                VendLedgEntry.SetRange("Document Type", VendLedgEntry."Document Type"::"Credit Memo");
            VendLedgEntry.SetRange("Document No.", FromDocNo);
            VendLedgEntry.SetRange("Vendor No.", ToPurchHeader."Pay-to Vendor No.");
            VendLedgEntry.SetRange(Open, true);
            if VendLedgEntry.FindFirst() then begin
                if FromDocType = "Purchase Document Type From"::"Posted Invoice" then begin
                    ToPurchHeader."Applies-to Doc. Type" := ToPurchHeader."Applies-to Doc. Type"::Invoice;
                    ToPurchHeader."Applies-to Doc. No." := FromDocNo;
                end else begin
                    ToPurchHeader."Applies-to Doc. Type" := ToPurchHeader."Applies-to Doc. Type"::"Credit Memo";
                    ToPurchHeader."Applies-to Doc. No." := FromDocNo;
                end;
                VendLedgEntry.CalcFields("Remaining Amount");
                VendLedgEntry."Amount to Apply" := VendLedgEntry."Remaining Amount";
                VendLedgEntry."Accepted Payment Tolerance" := 0;
                VendLedgEntry."Accepted Pmt. Disc. Tolerance" := false;
                CODEUNIT.Run(CODEUNIT::"Vend. Entry-Edit", VendLedgEntry);
            end;
        end;

        OnAfterUpdateVendLedgEntry(ToPurchHeader, FromDocNo);
    end;
    
   [IntegrationEvent(false, false)]
   //> NEW EVENT
   //OLD CODE: local procedure OnBeforeUpdateVendLedgEntry(var ToPurchaseHeader: Record "Purchase Header"; VendorLedgerEntry: Record "Vendor Ledger Entry"; var IsHandled: Boolean)
   local procedure OnBeforeUpdateVendLedgEntry(var ToPurchaseHeader: Record "Purchase Header"; VendorLedgerEntry: Record "Vendor Ledger Entry"; var IsHandled: Boolean; FromDocType: Enum "Gen. Journal Document Type"; FromDocNo: Code[20])
   //< NEW EVENT
   begin
   end;

Additional context

We need the same behavior as the sales process to apply the same logic to the purchase process as well.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions