Why do you need this change?
We need to replace the standard routing cost per unit calculation in CalcRtngLineCost in Codeunit 5812 "Calculate Standard Cost" with ABC-cost-aware logic that first attempts CalcABCRtngCostPerUnit and falls back to the standard CalcRoutingCostPerUnit only when ABC costs are not available. The standard procedure always calls CalcRoutingCostPerUnit using RoutingLine."Unit Cost per" as the starting value and does not consider ABC overhead rates from the production BOM.
Describe the request
Add an integration event OnCalcRtngLineCostOnBeforeCalcRoutingCostPerUnit in CalcRtngLineCost in Codeunit 5812 "Calculate Standard Cost" after OnBeforeCalcRtngLineCost and before the work center lookup and routing cost per unit calculation.
begin
OnBeforeCalcRtngLineCost(RoutingLine, MfgItemQtyBase);
IsHandled := false;
OnCalcRtngLineCostOnBeforeCalcRoutingCostPerUnit( // <---- New Event
RoutingLine, MfgItemQtyBase, WorkCenter,
DirUnitCost, IndirCostPct, OvhdRate, UnitCost, UnitCostCalculation,
ParentItem, IsHandled);
if not IsHandled then begin
if (RoutingLine.Type = RoutingLine.Type::"Work Center") and (RoutingLine."No." <> '') then
WorkCenter.Get(RoutingLine."No.");
UnitCost := RoutingLine."Unit Cost per";
CalcRoutingCostPerUnit(RoutingLine.Type, RoutingLine."No.", DirUnitCost, IndirCostPct, OvhdRate, UnitCost, UnitCostCalculation);
end;
OnCalcRtngLineCostOnAfterCalcRoutingCostPerUnit(RoutingLine, WorkCenter, MfgItemQtyBase, UnitCostCalculation);
CostTime :=
MfgCostCalcMgt.CalculateCostTime(
MfgItemQtyBase,
RoutingLine."Setup Time", RoutingLine."Setup Time Unit of Meas. Code",
RoutingLine."Run Time", RoutingLine."Run Time Unit of Meas. Code", RoutingLine."Lot Size",
RoutingLine."Scrap Factor % (Accumulated)", RoutingLine."Fixed Scrap Qty. (Accum.)",
RoutingLine."Work Center No.", UnitCostCalculation, MfgSetup."Cost Incl. Setup",
RoutingLine."Concurrent Capacities");
if (RoutingLine.Type = RoutingLine.Type::"Work Center") and (WorkCenter."Subcontractor No." <> '') then
IncrCost(SLSub, DirUnitCost, CostTime)
else
IncrCost(SLCap, DirUnitCost, CostTime);
IncrCost(SLCapOvhd, CostCalcMgt.CalcOvhdCost(DirUnitCost, IndirCostPct, OvhdRate, 1), CostTime);
OnAfterCalcRtngLineCost(RoutingLine, MfgItemQtyBase, SLCap, SLSub, SLCapOvhd, StdCostWkshName, ParentItem, CostTime);
end;
Event Signature:
[IntegrationEvent(false, false)]
local procedure OnCalcRtngLineCostOnBeforeCalcRoutingCostPerUnit(var RoutingLine: Record "Routing Line"; MfgItemQtyBase: Decimal; var WorkCenter: Record "Work Center"; var DirUnitCost: Decimal; var IndirCostPct: Decimal; var OvhdRate: Decimal; var UnitCost: Decimal; var UnitCostCalculation: Enum "Unit Cost Calculation Type"; var ParentItem: Record Item; var IsHandled: Boolean)
begin
end;
Alternatives evaluated: OnBeforeCalcRtngLineCost fires at the very start of the procedure before the work center is retrieved and before UnitCost is initialized from RoutingLine."Unit Cost per". A subscriber there cannot supply ABC-derived cost values because the event fires before the routing line context is set up for cost calculation. OnCalcRtngLineCostOnAfterCalcRoutingCostPerUnit fires after CalcRoutingCostPerUnit has already completed and all four cost output variables have been written, too late to influence the inputs or replace the standard calculation with CalcABCRtngCostPerUnit. No event fires between OnBeforeCalcRtngLineCost and the UnitCost assignment that would allow a subscriber to replace the CalcRoutingCostPerUnit call.
Why do you need this change?
We need to replace the standard routing cost per unit calculation in CalcRtngLineCost in Codeunit 5812 "Calculate Standard Cost" with ABC-cost-aware logic that first attempts CalcABCRtngCostPerUnit and falls back to the standard CalcRoutingCostPerUnit only when ABC costs are not available. The standard procedure always calls CalcRoutingCostPerUnit using RoutingLine."Unit Cost per" as the starting value and does not consider ABC overhead rates from the production BOM.
Describe the request
Add an integration event OnCalcRtngLineCostOnBeforeCalcRoutingCostPerUnit in CalcRtngLineCost in Codeunit 5812 "Calculate Standard Cost" after OnBeforeCalcRtngLineCost and before the work center lookup and routing cost per unit calculation.
Event Signature:
Alternatives evaluated: OnBeforeCalcRtngLineCost fires at the very start of the procedure before the work center is retrieved and before UnitCost is initialized from RoutingLine."Unit Cost per". A subscriber there cannot supply ABC-derived cost values because the event fires before the routing line context is set up for cost calculation. OnCalcRtngLineCostOnAfterCalcRoutingCostPerUnit fires after CalcRoutingCostPerUnit has already completed and all four cost output variables have been written, too late to influence the inputs or replace the standard calculation with CalcABCRtngCostPerUnit. No event fires between OnBeforeCalcRtngLineCost and the UnitCost assignment that would allow a subscriber to replace the CalcRoutingCostPerUnit call.