microsoft / ALAppExtensions

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

[Event Request] Codeunit 333 "Req. Wksh.-Make Order". InsertHeader #27673

Open fridrichovsky opened 19 hours ago

fridrichovsky commented 19 hours ago

Describe the request

Please add new parameter to event.

local procedure InsertHeader(var ReqLine2: Record "Requisition Line")
    var
        SalesHeader: Record "Sales Header";
        Vendor: Record Vendor;
        SpecialOrder: Boolean;
        ShouldValidateSellToCustNo: Boolean;
        ShouldSetShipToForSpecOrder: Boolean;
    begin
    //----------------------------------------------------------------OnBeforeInsertHeader:BEGIN
        //OnBeforeInsertHeader(ReqLine2, PurchOrderHeader, OrderDateReq, PostingDateReq, ReceiveDateReq, ReferenceReq);
      OnBeforeInsertHeader(ReqLine2, PurchOrderHeader, OrderDateReq, PostingDateReq, ReceiveDateReq, ReferenceReq, NameAddressDetails); 
    //----------------------------------------------------------------OnBeforeInsertHeader:END

        OrderCounter := OrderCounter + 1;
        if not PlanningResiliency then
            if not HideProgressWindow then
                Window.Update(3, OrderCounter);

        PurchSetup.Get();
        PurchSetup.TestField("Order Nos.");
        Clear(PurchOrderHeader);
        PurchOrderHeader.Init();
        PurchOrderHeader."Document Type" := PurchOrderHeader."Document Type"::Order;
        PurchOrderHeader."No." := '';
        PurchOrderHeader."Posting Date" := PostingDateReq;
        OnBeforePurchOrderHeaderInsert(PurchOrderHeader, ReqLine2, ReceiveDateReq, OrderDateReq, PostingDateReq, ReferenceReq);
        PurchOrderHeader.Insert(true);
        PurchOrderHeader."Your Reference" := ReferenceReq;
        PurchOrderHeader."Order Date" := OrderDateReq;
        PurchOrderHeader."Expected Receipt Date" := ReceiveDateReq;
        ValidateBuyFromVendorNo(PurchOrderHeader, ReqLine2);
        if ReqLine2."Order Address Code" <> '' then
            PurchOrderHeader.Validate("Order Address Code", ReqLine2."Order Address Code");

        ShouldValidateSellToCustNo := ReqLine2."Sell-to Customer No." <> '';
        OnInsertHeaderOnBeforeValidateSellToCustNoFromReqLine(PurchOrderHeader, ReqLine2, ShouldValidateSellToCustNo);
        if ShouldValidateSellToCustNo then
            PurchOrderHeader.Validate("Sell-to Customer No.", ReqLine2."Sell-to Customer No.");

        PurchOrderHeader.Validate("Currency Code", ReqLine2."Currency Code");

        if PurchasingCode.Get(ReqLine2."Purchasing Code") then
            if PurchasingCode."Special Order" then
                SpecialOrder := true;

        if not SpecialOrder then
            UpdateShipToOrLocationCode(ReqLine2, PurchOrderHeader)
        else begin
            PurchOrderHeader.Validate("Location Code", ReqLine2."Location Code");
            ShouldSetShipToForSpecOrder := true;
            OnInsertHeaderOnBeforeSetShipToForSpecOrder(PurchOrderHeader, ReqLine2, ShouldSetShipToForSpecOrder);
            if ShouldSetShipToForSpecOrder then
                PurchOrderHeader.SetShipToForSpecOrder();
            if Vendor.Get(PurchOrderHeader."Buy-from Vendor No.") then
                PurchOrderHeader.Validate("Shipment Method Code", Vendor."Shipment Method Code");
        end;
        if not SpecialOrder then
            if SalesHeader.Get(SalesHeader."Document Type"::Order, ReqLine2."Sales Order No.") then begin
                PurchOrderHeader."Ship-to Name" := SalesHeader."Ship-to Name";
                PurchOrderHeader."Ship-to Name 2" := SalesHeader."Ship-to Name 2";
                PurchOrderHeader."Ship-to Address" := SalesHeader."Ship-to Address";
                PurchOrderHeader."Ship-to Address 2" := SalesHeader."Ship-to Address 2";
                PurchOrderHeader."Ship-to Post Code" := SalesHeader."Ship-to Post Code";
                PurchOrderHeader."Ship-to City" := SalesHeader."Ship-to City";
                PurchOrderHeader."Ship-to Contact" := SalesHeader."Ship-to Contact";
                PurchOrderHeader."Ship-to County" := SalesHeader."Ship-to County";
                PurchOrderHeader."Ship-to Country/Region Code" := SalesHeader."Ship-to Country/Region Code";
                PurchOrderHeader."Ship-to Phone No." := SalesHeader."Ship-to Phone No.";
            end;
        if SpecialOrder then
            if Vendor.Get(PurchOrderHeader."Buy-from Vendor No.") then
                PurchOrderHeader."Shipment Method Code" := Vendor."Shipment Method Code";
        OnAfterInsertPurchOrderHeader(ReqLine2, PurchOrderHeader, SuppressCommit, SpecialOrder);
        PurchOrderHeader.Modify();
        PurchOrderHeader.Mark(true);
        TempDocumentEntry.Init();
        TempDocumentEntry."Table ID" := Database::"Purchase Header";
        TempDocumentEntry."Document Type" := PurchOrderHeader."Document Type"::Order;
        TempDocumentEntry."Document No." := PurchOrderHeader."No.";
        TempDocumentEntry."Entry No." := TempDocumentEntry.Count + 1;
        TempDocumentEntry.Insert();
    end;

    //----------------------------------------------------------------OnBeforeInsertHeader:BEGIN
    [IntegrationEvent(false, false)]
    //local procedure OnBeforeInsertHeader(RequisitionLine: Record "Requisition Line"; PurchaseHeader: Record "Purchase Header"; var OrderDateReq: Date; var PostingDateReq: Date; var ReceiveDateReq: Date; var ReferenceReq: Text[35])
      local procedure OnBeforeInsertHeader(RequisitionLine: Record "Requisition Line"; PurchaseHeader: Record "Purchase Header"; var OrderDateReq: Date; var PostingDateReq: Date; var ReceiveDateReq: Date; var ReferenceReq: Text[35]; var NameAddressDetails: Text) 
    begin
    end;
    //----------------------------------------------------------------OnBeforeInsertHeader:END

Additional context

we need change variable content