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 56 "Sales - Calc Discount By Type" for procedure ShouldRedistributeInvoiceDiscountAmount #26392

Open
innonav-dev opened this issue Apr 30, 2024 · 0 comments
Labels
event-request Request for adding an event

Comments

@innonav-dev
Copy link

Describe the request

We could use an new Event Publisher for procedure ShouldRedistributeInvoiceDiscountAmount.

Existing Code ist following:

    procedure ShouldRedistributeInvoiceDiscountAmount(var SalesHeader: Record "Sales Header"): Boolean
    var
        ApplicationAreaMgmtFacade: Codeunit "Application Area Mgmt. Facade";
        IsHandled: Boolean;
    begin
        IsHandled := false;
        OnBeforeShouldRedistributeInvoiceDiscountAmount(SalesHeader, IsHandled);
        if IsHandled then
            exit(true);

        SalesHeader.CalcFields("Recalculate Invoice Disc.");
        if not SalesHeader."Recalculate Invoice Disc." then
            exit(false);

        case SalesHeader."Invoice Discount Calculation" of
            SalesHeader."Invoice Discount Calculation"::Amount:
                exit(SalesHeader."Invoice Discount Value" <> 0);
            SalesHeader."Invoice Discount Calculation"::"%":
                exit(true);
            SalesHeader."Invoice Discount Calculation"::None:
                begin
                    if ApplicationAreaMgmtFacade.IsFoundationEnabled() then
                        exit(true);

                    exit(not InvoiceDiscIsAllowed(SalesHeader."Invoice Disc. Code"));
                end;
            else
                exit(true);
        end;
    end;

Our suggestion:

    procedure ShouldRedistributeInvoiceDiscountAmount(var SalesHeader: Record "Sales Header"): Boolean
    var
        ApplicationAreaMgmtFacade: Codeunit "Application Area Mgmt. Facade";
        IsHandled: Boolean;
        ExitValue: Boolean;
    begin
        IsHandled := false;
        OnBeforeShouldRedistributeInvoiceDiscountAmount(SalesHeader, IsHandled);
        if IsHandled then
            exit(true);

        SalesHeader.CalcFields("Recalculate Invoice Disc.");
        if not SalesHeader."Recalculate Invoice Disc." then
            exit(false);

        case SalesHeader."Invoice Discount Calculation" of
            SalesHeader."Invoice Discount Calculation"::Amount:
                exit(SalesHeader."Invoice Discount Value" <> 0);
            SalesHeader."Invoice Discount Calculation"::"%":
                exit(true);
            SalesHeader."Invoice Discount Calculation"::None:
                begin
                    if ApplicationAreaMgmtFacade.IsFoundationEnabled() then
                        exit(true);

                    ExitValue := not InvoiceDiscIsAllowed(SalesHeader."Invoice Disc. Code");
                    OnShouldRedistributeInvoiceDiscountAmountCaseInvDiscCalcNone(SalesHeader, ExitValue);
                    exit(ExitValue);
                end;
            else
                exit(true);
        end;
    end;

    [IntegrationEvent(false, false)]
    local procedure OnShouldRedistributeInvoiceDiscountAmountCaseInvDiscCalcNone(SalesHeader: Record "Sales Header"; var ExitValue: Boolean)
    begin
    end;

Additional context

In some cases we need to bee able to edit the exit value by our own.

@darjoo darjoo added the event-request Request for adding an event label May 3, 2024
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
Projects
None yet
Development

No branches or pull requests

2 participants