Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[W1][Codeunit][5986][Serv-Amounts Mgt.] new OnAfterUpdateInvoiceRounding event #28981

@RadoArvay

Description

@RadoArvay

Why do you need this change?

We need to do an additional service document rounding after the last lines was retrieved and an invoice rounding was done; similar to an after-rounding when sales documents are posting.

So, please, add a new event OnAfterUpdateInvoiceRounding (or use any suitable name; this one is taken from the sales posting) to codeunit "Serv-Amounts Mgt.".
The event will be called from 2 places (like the sales one is), so we also need an event runner method.

Describe the request

+   [IntegrationEvent(true, false)]
+   local procedure OnAfterUpdateInvoiceRounding(ServiceHeader: Record "Service Header"; var ServiceLine: Record "Service Line"; var TotalServiceLine: Record "Service Line"; Currency: Record Currency; UseTempData: Boolean; var BiggestLineNo: Integer; var LastLineRetrieved: Boolean; var RoundingLineIsInserted: Boolean; var RoundingLineNo: Integer)
+   begin
+   end;

Event runner, also in codeunit "Serv-Amounts Mgt.":

+   internal procedure RunOnAfterUpdateInvoiceRounding(ServiceHeader: Record "Service Header"; var ServiceLine: Record "Service Line"; var TotalServiceLine: Record "Service Line"; UseTempData: Boolean; var BiggestLineNo: Integer; var LastLineRetrieved: Boolean)
+   begin
+       OnAfterUpdateInvoiceRounding(ServiceHeader, ServiceLine, TotalServiceLine, Currency, UseTempData, BiggestLineNo, LastLineRetrieved, RoundingLineIsInserted, RoundingLineNo)
+   end;

And the code modifications in 2 codeunits:

1 - codeunit 5986 "Serv-Amounts Mgt."

    local procedure SumServiceLines2(.....)
    var
        .....
    begin
        .....
        RoundingLineIsInserted := false;
        if OldServLine.Find('-') then
            repeat
                if not RoundingLineInserted() then
                    .....
                IsHandled := false;
                OnSumServiceLines2OnBeforeInvoiceRounding(ServHeader, ServLine, OldServLine, TotalServiceLine, QtyType, LastLineRetrieved, IsHandled);
+-              if not IsHandled then begin
                    if RoundingLineInserted() then
                        LastLineRetrieved := true
                    else begin
                        BiggestLineNo := MAX(BiggestLineNo, OldServLine."Line No.");
                        LastLineRetrieved := OldServLine.Next() = 0;
                        if LastLineRetrieved and SalesSetup."Invoice Rounding" then
                            InvoiceRounding(ServHeader, ServLine, TotalServiceLine,
                              LastLineRetrieved, true, BiggestLineNo);
                    end;
+                   RunOnAfterUpdateInvoiceRounding(ServHeader, ServLine, TotalServiceLine, true, BiggestLineNo, LastLineRetrieved);
+               end;
            until LastLineRetrieved;
    end;

2 - codeunit 5988 "Serv-Documents Mgt."

    procedure PostDocumentLines(.....)
    var
        .....
    begin
        .....
                if ServAmountsMgt.RoundingLineInserted() then
                    LastLineRetrieved := true
                else begin
                    BiggestLineNo := ServAmountsMgt.MAX(ServAmountsMgt.GetLastLineNo(ServLine), ServLine."Line No.");
                    LastLineRetrieved := ServLine.Next() = 0;

                    // ServLine
                    IsHandled := false;
                    OnPostDocumentLinesOnBeforeInvoiceRounding(ServHeader, ServLine, TotalServiceLine, ServAmountsMgt, LastLineRetrieved, BiggestLineNo, IsHandled);
                    if not IsHandled then
                        if LastLineRetrieved and SalesSetup."Invoice Rounding" then
                            ServAmountsMgt.InvoiceRounding(ServHeader, ServLine, TotalServiceLine,
                              LastLineRetrieved, false, BiggestLineNo);
                end;
+               ServAmountsMgt.RunOnAfterUpdateInvoiceRounding(ServHeader, ServLine, TotalServiceLine, false, BiggestLineNo, LastLineRetrieved);
                ErrorMessageMgt.PopContext(ErrorContextElementPostLine);
            until LastLineRetrieved;
        .....
    end;

Internal work item: AB#596407

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM areaevent-requestRequest for adding an eventships-in-future-updateFix ships in a future update

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions