microsoft / ALAppExtensions

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

[Event Request] - New events in procedures ValuationExists ,GetValuationPeriod & UpdateNextValuations in "Avg. Cost Adjmt. Entry Point" table. #26785

Open minaskats opened 5 days ago

minaskats commented 5 days ago

Describe the request

Events Declaration:

[IntegrationEvent(false, false)] local procedure OnBeforeExitValuationExists(var AvgCostAdjmtEntryPoint: Record "Avg. Cost Adjmt. Entry Point") begin end;

[IntegrationEvent(false, false)] local procedure OnBeforeGetValuationPeriod(var AvgCostAdjmtEntryPoint: Record "Avg. Cost Adjmt. Entry Point",var CalendarPeriod: Record Date,var IsHandled) begin end;

[IntegrationEvent(false, false)] local procedure OnAfterUpdateNextValuations(var AvgCostAdjmtEntryPoint: Record "Avg. Cost Adjmt. Entry Point",Item : Record Item) begin end;

Additional context

Hello MSTeam,

We would like to request an event for the ValuationExists procedure to update the Valuation Date with the CalendarPeriod."Period End", regardless of whether the item has a "Costing Method"::Average.

Additionally, we would like an event handler for the entire GetValuationPeriod procedure.

Furthermore, we request an OnAfterUpdateNextValuations event at the end of the UpdateNextValuations procedure to allow for additional updates in the table following that calculation.

Event Call per procedure :

procedure ValuationExists(ValueEntry: Record "Value Entry"): Boolean var CalendarPeriod: Record Date; begin Reset(); "Item No." := ValueEntry."Item No."; "Valuation Date" := ValueEntry."Valuation Date"; GetItem(ValueEntry."Item No."); OnValuationExistsOnAfterGetItem(Item, ValueEntry); if Item."Costing Method" = Item."Costing Method"::Average then begin CalendarPeriod."Period Start" := "Valuation Date"; GetValuationPeriod(CalendarPeriod); "Valuation Date" := CalendarPeriod."Period End"; end; if (Item."Costing Method" = Item."Costing Method"::Average) and IsAvgCostCalcTypeItem("Valuation Date") then begin "Location Code" := ''; "Variant Code" := ''; end else begin "Variant Code" := ValueEntry."Variant Code"; "Location Code" := ValueEntry."Location Code"; end;

OnBeforeExitValuationExists(Rec)
    exit(Find());
end;

procedure GetValuationPeriod(var CalendarPeriod: Record Date) var PeriodMgt: Codeunit PeriodPageManagement; begin IsHandled := false; OnBeforeGetValuationPeriod(rec,CalendarPeriod,IsHandled) if not IsHandled then begin

    GetFiscalYearAccPeriod("Valuation Date");

    if FiscalYearAccPeriod."Average Cost Period" = FiscalYearAccPeriod."Average Cost Period"::" " then
        FiscalYearAccPeriod.FieldError("Average Cost Period");

    if CalendarPeriod."Period Start" = 0D then begin
        CalendarPeriod."Period End" := 0D;
        exit;
    end;

    if not PeriodMgt.FindDate('', CalendarPeriod, "Analysis Period Type".FromInteger(FiscalYearAccPeriod."Average Cost Period" - 1)) then
        FiscalYearAccPeriod.Get(CalendarPeriod."Period Start");

    if FiscalYearAccPeriod."Average Cost Period" in
       [FiscalYearAccPeriod."Average Cost Period"::Day,
        FiscalYearAccPeriod."Average Cost Period"::"Accounting Period"]
    then
        exit;

    GetFiscalYearAccPeriod(CalendarPeriod."Period End");
    if FiscalYearAccPeriod."Starting Date" in [CalendarPeriod."Period Start" .. CalendarPeriod."Period End"] then
        if "Valuation Date" < FiscalYearAccPeriod."Starting Date" then
            CalendarPeriod."Period End" := CalcDate('<-1D>', FiscalYearAccPeriod."Starting Date")
        else
            CalendarPeriod."Period Start" := FiscalYearAccPeriod."Starting Date";
end;
end;

local procedure UpdateNextValuations() var CopyOfAvgCostAdjmtPoint: Record "Avg. Cost Adjmt. Entry Point"; begin CopyOfAvgCostAdjmtPoint.Copy(Rec); SetCurrentKey("Item No.", "Cost Is Adjusted"); SetRange("Item No.", "Item No."); SetRange("Cost Is Adjusted", true); if true in [Item."Costing Method" <> Item."Costing Method"::Average, not (IsAvgCostCalcTypeItem("Valuation Date") or AvgCostCalcTypeIsChanged("Valuation Date"))] then begin SetRange("Location Code", "Location Code"); SetRange("Variant Code", "Variant Code"); end; SetFilter("Valuation Date", '>%1', "Valuation Date"); ModifyAll("Cost Is Adjusted", false); Copy(CopyOfAvgCostAdjmtPoint); OnAfterUpdateNextValuations(rec,item); end;