Skip to content

[Event Request] Codeunit 5812 "Calculate Standard Cost" - CalcMfgItem procedure #30101

@MaricaPiazzalungaActionNet

Description

Why do you need this change?

Dear support, for a customer we need to manage a custom field ("Single-Level Labour Cost MPM") in "Standard Cost" field calculation of Item table.
In the procedure CalcMfgItem after the valorization of field "Standard Cost" there is not way to modify it, by adding the custom field value to standard cost. For this reason we need a new integration event.

Describe the request

Add a new integration event OnCalcMfgItemOnAfterCalculateCosts() in Codeunit 5812 "Calculate Standard Cost", so extensions can react after the item's costs are calculated.

Location in CalcMfgItem(ItemNo: Code[20]; var Item: Record Item; Level: Integer) procedure (at line 652):

begin

    OnBeforeCalcMfgItem(Item, LogErrors, StdCostWkshName);

    if Level > MaxLevel then
        Error(Text000, MaxLevel);

    if GetItem(ItemNo, Item) then
        exit;

    if not CalcMultiLevel and (Level <> 0) then
        exit;

    LotSize := 1;

    if Item.IsMfgItem() then begin
        if Item."Lot Size" <> 0 then
            LotSize := Item."Lot Size";
        MfgItemQtyBase := MfgCostCalcMgt.CalcQtyAdjdForBOMScrap(LotSize, Item."Scrap %");
        OnCalcMfgItemOnBeforeCalcRtngCost(Item, Level, LotSize, MfgItemQtyBase, SLCap);
        CalcRtngCost(Item."Routing No.", MfgItemQtyBase, SLCap, SLSub, SLCapOvhd, Item);
        CalcProdBOMCost(
          Item, Item."Production BOM No.", Item."Routing No.",
          MfgItemQtyBase, true, Level, SLMat, RUMat, RUCap, RUSub, RUCapOvhd, RUMfgOvhd, SLNonInvMat, RUNonInvMat, Item);

        if not MfgCostCalcMgt.CanIncNonInvCostIntoProductionItem() then
            SLMfgOvhd :=
              CostCalcMgt.CalcOvhdCost(
                SLMat + SLCap + SLSub + SLCapOvhd,
                Item."Indirect Cost %", Item."Overhead Rate", LotSize)
        else
            SLMfgOvhd :=
              CostCalcMgt.CalcOvhdCost(
                SLMat + SLCap + SLSub + SLCapOvhd + SLNonInvMat,
                Item."Indirect Cost %", Item."Overhead Rate", LotSize);

        Item."Last Unit Cost Calc. Date" := CalculationDate;
    end else
        if Item.IsAssemblyItem() then begin
            CalcAssemblyItem(ItemNo, Item, Level, true);
            exit
        end else begin
            SLMat := Item."Unit Cost";
            RUMat := Item."Unit Cost";
        end;

    OnCalcMfgItemOnBeforeCalculateCosts(
        SLMat, SLCap, SLSub, SLCapOvhd, SLMfgOvhd, Item, LotSize, MfgItemQtyBase, Level, CalculationDate, RUMat);

    Item."Single-Level Material Cost" := CalcCostPerUnit(SLMat, LotSize);
    Item."Single-Level Capacity Cost" := CalcCostPerUnit(SLCap, LotSize);
    Item."Single-Level Subcontrd. Cost" := CalcCostPerUnit(SLSub, LotSize);
    Item."Single-Level Cap. Ovhd Cost" := CalcCostPerUnit(SLCapOvhd, LotSize);
    Item."Single-Level Mfg. Ovhd Cost" := CalcCostPerUnit(SLMfgOvhd, LotSize);
    Item."Rolled-up Material Cost" := CalcCostPerUnit(RUMat, LotSize);
    Item."Rolled-up Capacity Cost" := CalcCostPerUnit(RUCap + SLCap, LotSize);
    Item."Rolled-up Subcontracted Cost" := CalcCostPerUnit(RUSub + SLSub, LotSize);
    Item."Rolled-up Cap. Overhead Cost" := CalcCostPerUnit(RUCapOvhd + SLCapOvhd, LotSize);
    Item."Rolled-up Mfg. Ovhd Cost" := CalcCostPerUnit(RUMfgOvhd + SLMfgOvhd, LotSize);
    if MfgCostCalcMgt.CanIncNonInvCostIntoProductionItem() then begin
        Item."Rolled-up Mat. Non-Invt. Cost" := CalcCostPerUnit(RUNonInvMat, LotSize);
        Item."Single-Lvl Mat. Non-Invt. Cost" := CalcCostPerUnit(SLNonInvMat, LotSize);
    end else begin
        Item."Rolled-up Mat. Non-Invt. Cost" := 0;
        Item."Single-Lvl Mat. Non-Invt. Cost" := 0;
    end;
    Item."Standard Cost" :=
      Item."Single-Level Material Cost" +
      Item."Single-Level Capacity Cost" +
      Item."Single-Level Subcontrd. Cost" +
      Item."Single-Level Cap. Ovhd Cost" +
      Item."Single-Level Mfg. Ovhd Cost" +
      Item."Single-Lvl Mat. Non-Invt. Cost";

    -->OnCalcMfgItemOnAfterCalculateCosts(SLMat, SLCap, SLSub, SLCapOvhd, SLMfgOvhd, Item, LotSize, MfgItemQtyBase, Level, CalculationDate, RUMat)
    TempItem := Item;
    TempItem.Insert();
end;

Event Publisher

[IntegrationEvent(false, false)]
local procedure OnCalcMfgItemOnAfterCalculateCosts(SLMat: Decimal; SLCap: Decimal; SLSub: Decimal; SLCapOvhd: Decimal; SLMfgOvhd: Decimal; var Item: Record Item; LotSize: Decimal; MfgItemQtyBase: Decimal; Level: Integer; CalculationDate: Date; RUMat: Decimal)
begin
end;

Internal work item: AB#636083

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM areaevent-requestRequest for adding an event

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions