ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Event Request] codeunit 1002 "Job Create-Invoice" - New event "OnBeforeFindJobPlanningLineInvoice"

Open petmoe opened this issue 2 years ago • 1 comments

Describe the request

In codeunit 1002 "Job Create-Invoice", local procedure SalesInvoiceExistForMultipleCustomerBillingMethod, we would like a new integration event

OnBeforeFindJobPlanningLineInvoice placed just before the FindFirst statement as shown below. The event should implement a IsHandled pattern to allow for exiting further processing.


local procedure SalesInvoiceExistForMultipleCustomerBillingMethod(Job: Record Job): Boolean
var
    JobTask: Record "Job Task";
    JobTask2: Record "Job Task";
    JobPlanningLineInvoice: Record "Job Planning Line Invoice";
    TempJobPlanningLine3: Record "Job Planning Line" temporary;
    SelectionFilterMgt: Codeunit SelectionFilterManagement;
    RecRef: RecordRef;
    JobTaskFilter: Text;
    //>>New Code Begin
    ExitCode: Boolean;
    IsHandled: Boolean;
    //<< New Code End
begin
    if Job."Task Billing Method" = Job."Task Billing Method"::"One customer" then
        exit;

    TempJobPlanningLine3.Copy(TempJobPlanningLine2, true);
    TempJobPlanningLine3.Reset();
    TempJobPlanningLine3.SetFilter("Job Contract Entry No.", '<>%1', TempJobPlanningLine."Job Contract Entry No.");
    RecRef.GetTable(TempJobPlanningLine3);
    JobTaskFilter := SelectionFilterMgt.GetSelectionFilter(RecRef, TempJobPlanningLine3.FieldNo("Job Task No."));
    if JobTaskFilter = '' then
        exit;

    if JobTask.Get(TempJobPlanningLine."Job No.", TempJobPlanningLine."Job Task No.") then begin
        JobTask2.SetRange("Job No.", Job."No.");
        JobTask2.SetFilter("Job Task No.", JobTaskFilter);
        JobTask2.SetRange("Sell-to Customer No.", JobTask."Sell-to Customer No.");
        JobTask2.SetRange("Bill-to Customer No.", JobTask."Bill-to Customer No.");
        JobTask2.SetRange("Invoice Currency Code", JobTask."Invoice Currency Code");
        if JobTask2.FindFirst() then begin
            JobPlanningLineInvoice.SetRange("Job No.", Job."No.");
            JobPlanningLineInvoice.SetRange("Job Task No.", JobTask2."Job Task No.");
            JobPlanningLineInvoice.SetRange("Document Type", JobPlanningLineInvoice."Document Type"::Invoice);
            //>> New Code Begin
            OnBeforeFindJobPlanningLineInvoice(JobTask, JobPlanningLineInvoice, SalesHeader, ExitValue, Ishandled);
            if IsHandled then
                exit(ExitValue);
            //<< New Code End
            if JobPlanningLineInvoice.FindFirst() then begin
                SalesHeader.Get(SalesHeader."Document Type"::Invoice, JobPlanningLineInvoice."Document No.");
                exit(true);
            end;
        end;
    end;
end;
//>> New Code Begin
[IntegrationEvent(false, false)]
local procedure OnBeforeFindJobPlanningLineInvoice(JobTask: Record "JobTask"; var JobPlanningLineInvoice: Record "Job Planning Line Invoice", var SalesHeader: Record "Sales Header", var ExitValue: Boolean, var IsHandled: Boolean, )
begin
end;
//<< New Code End

Additional context

We want to interact with the filters put on JobPlanningLineInvoice and the logic for finding SalesHeader. Internal work item: AB#557546

petmoe avatar Nov 11 '24 10:11 petmoe

Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.

Build ID: 27687.

JesperSchulz avatar Jan 30 '25 09:01 JesperSchulz