# Manufacturing Cost and Variance

## Overview

Manufacturing Cost and Variance captures the planned and actual cost footprint of a production order without taking ownership of accounting postings. At release time, the module snapshots expected component, labor, machine, and overhead assumptions based on the selected BOM, routing, work-center rates, and inventory-owned planned material cost resolution. During execution, it accumulates actual material consumption values sourced from the named `InventoryIssueOutcomeEvent` contract plus actual time and quantity data from work orders.

The feature compares actual results against the plan and classifies manufacturing variance so downstream accounting can decide how to post it. Manufacturing owns cost visibility at the order and operation level, including WIP-oriented progress context, but it does not create journal entries, settle balances, or close accounting periods. Those responsibilities remain outside the module. Manufacturing does, however, own the operational review lifecycle that blocks order close until variance review is complete and downstream accounting has acknowledged the settlement handoff.

Planned overhead is not entered ad hoc per production order. It is derived from the overhead absorption policy configured on each referenced `WorkCenter`, then snapshotted onto the production order at release alongside labor and machine assumptions. This keeps overhead calculation deterministic and aligned to the capacity resource that drives the cost.

Planned material cost is also not maintained as an editable manufacturing-owned field on BOM component lines in the initial scope. Manufacturing resolves the planned unit cost for each component from inventory-owned valuation data at release time, snapshots the resolved amount onto the production order cost baseline, and preserves that baseline even if valuation settings later change.

## Business Purpose

- Give planners and supervisors visibility into whether production is running to expected cost
- Preserve the standard or planned cost assumptions that were in force when work was released
- Distinguish price, usage, rate, efficiency, scrap, and yield-related variances at a level that downstream accounting can map to separate review or posting treatment
- Support WIP-style progress visibility without forcing manufacturing to own general-ledger behavior
- Provide a downstream accounting handoff contract backed by operational evidence rather than manual spreadsheet reconciliation
- Make post-order review and continuous improvement possible through cost and variance history
- Use an explicit overhead absorption rule so planned and actual overhead can be reproduced consistently during review

## Process Flow

```mermaid
flowchart TD
    A[Release Production Order] --> B[Snapshot planned material, labor, machine, and overhead cost]
    B --> C[Execute material issues through inventory]
    C --> D[Inventory emits InventoryIssueOutcomeEvent when issue valuation is final]
    D --> E[Collect actual time and quantity from work orders]
    E --> F[Accumulate actual cost by production order]
    F --> G{Order completed?}
    G -->|No| H[Show in-progress WIP-style cost view]
    G -->|Yes| I[Order becomes TECHNICALLY_COMPLETE]
    I --> J[PENDING_VARIANCE_REVIEW]
    J --> K[Compare planned vs actual]
    K --> L[Classify price, usage, rate, efficiency, scrap, and yield variance]
    L --> M[VARIANCE_REVIEWED]
    M --> N[Publish reviewed manufacturing cost summary for downstream accounting]
    N --> O[SETTLED after downstream settlement acknowledgment]
```

Each production order owns one manufacturing cost summary that moves through a named lifecycle after execution is frozen. The initial scope uses these states:

- `COLLECTING`: Planned baseline is snapshotted and actual material, labor, machine, and overhead evidence is still accumulating while the order is `RELEASED`, `IN_PROGRESS`, or `COMPLETED`
- `PENDING_VARIANCE_REVIEW`: The production order has reached `TECHNICALLY_COMPLETE`, final variance can be calculated, and review is required before administrative close
- `VARIANCE_REVIEWED`: An authorized reviewer has approved the final planned-versus-actual comparison, variance classification, and downstream handoff payload
- `SETTLED`: Downstream accounting or financial close processing has acknowledged the reviewed handoff and the order is now eligible for final administrative close

The allowed transitions are:

- `COLLECTING -> PENDING_VARIANCE_REVIEW`
- `PENDING_VARIANCE_REVIEW -> VARIANCE_REVIEWED`
- `VARIANCE_REVIEWED -> SETTLED`

The following enforcement rules apply:

- A production order entering `TECHNICALLY_COMPLETE` must move its linked cost summary to `PENDING_VARIANCE_REVIEW`
- `VARIANCE_REVIEWED` requires final variance recalculation against the frozen order baseline and an explicit reviewer action by a manufacturing or finance-review role
- `SETTLED` requires a named downstream acknowledgment that the reviewed variance or WIP handoff was consumed by the accounting-owned settlement process; manufacturing records the acknowledgment but does not post the settlement itself
- A production order must not transition from `TECHNICALLY_COMPLETE` to `CLOSED` until the linked cost summary is `SETTLED`
- If execution must resume after review begins, the production order must be reopened and the cost summary must return to `COLLECTING` or a superseded draft state through a controlled workflow

## Scenario Patterns

- **Standard-cost comparison**: A production order is released using standard component and work-center assumptions, then reviewed against actual execution cost after completion
- **Labor rate change**: Actual labor is booked at a different rate than the snapped standard, and the delta is isolated from pure time-overrun effects
- **Labor or machine overrun**: An operation takes materially longer than its standard time, and the excess resource consumption is exposed as an efficiency variance instead of being mixed into a rate variance
- **Material price change**: Inventory issues the same planned quantity at a different actual unit valuation than the snapped standard, and the delta is tracked separately from quantity over-consumption
- **Material loss variance**: Actual issued component quantity exceeds the BOM expectation because of setup loss, damage, or poor yield, and the excess is tracked as usage rather than price variance
- **Scrap-heavy production run**: Scrap reported during execution inflates actual cost per good unit and is classified separately from normal usage
- **In-progress cost visibility**: Supervisors review cost accumulation on an order that has started but not yet completed to see whether it is trending off plan
- **Accounting handoff after review**: Manufacturing finishes variance review, publishes summarized planned-versus-actual results for downstream accounting, and waits for settlement acknowledgment before the order can close
- **Work-center overhead absorption**: Each work center may define one active overhead absorption rule, and released orders snapshot that rule so planned and actual overhead remain reproducible even if work-center master data changes later

Manufacturing resolves each component's planned material cost through inventory-owned valuation contracts at release time. The required source rules are:

- Manufacturing must query inventory for the component item's active valuation context at the production order's site or company scope
- If the item's `ValuationPolicy.costingMethod` is `STANDARD`, the planned unit cost must come from inventory's currently effective per-item `StandardCost` generation
- AVCO and FIFO costing are not yet available in inventory; their planned-cost resolution rules return with those costing phases
- Manufacturing must snapshot the returned unit cost, currency, valuation method, and source valuation reference onto the released production order and must not recompute the baseline from later inventory changes
- If inventory cannot resolve planned material cost for a required component, production-order release must be rejected rather than allowing manufacturing to invent a fallback cost

This makes inventory the source of truth for planned material valuation while allowing manufacturing to own the frozen release-time baseline used for later variance comparison.

Manufacturing consumes actual material cost only through the named `InventoryIssueOutcomeEvent` contract emitted by inventory after a goods issue or backflush movement reaches its inventory-owned final valuation state. The minimum payload is:

- `productionOrderReference`
- `workOrderReference`: optional for issue transactions recorded at order level rather than operation level
- `inventoryIssueReference`
- `itemReference`
- `issuedQuantity`
- `unitOfMeasure`
- `actualUnitCost`
- `actualExtendedCost`
- `currency`
- `valuationMethod`
- `postingDate`
- `siteReference`

Optional and conditional fields:

- `costLayerReferences`: optional list of cost-layer identifiers when valuation methods such as FIFO require traceability to multiple inventory layers
- `issueMode`: optional classification such as `MANUAL_ISSUE` or `BACKFLUSH` for cost analysis without changing the financial result

Inventory emits `InventoryIssueOutcomeEvent` only after the issue transaction is accepted, executed, and valued by inventory-owned logic. Manufacturing must not infer actual material cost from the issue request itself, from open stock movements, or from duplicated valuation formulas. If inventory rejects or has not yet valued the issue, manufacturing keeps the material cost pending rather than manufacturing its own fallback amount.

When a cost summary reaches `VARIANCE_REVIEWED`, manufacturing publishes the reviewed settlement handoff to downstream accounting and waits for the named `ManufacturingCostSettlementAcknowledgment` contract before allowing the summary to move to `SETTLED`. The acknowledgment contract is owned and emitted by the downstream accounting or financial-close module or service, not by manufacturing. Manufacturing may persist the received acknowledgment for auditability, but it must not fabricate, edit, or mark the acknowledgment as received through a manufacturing-only toggle.

The minimum `ManufacturingCostSettlementAcknowledgment` payload is:

- `productionOrderReference`
- `costSummaryReference`
- `settledByReference`
- `settlementDate`
- `currency`

Optional and conditional fields:

- `settlementReference`: optional downstream settlement batch, journal, or close-run identifier used to trace the accounting-side action
- `settledAmount`: optional when accounting settles an explicit amount and required if downstream policy allows partial or currency-translated settlement evidence
- `companyReference`: optional when company scope is derivable from the production order and required otherwise
- `siteReference`: optional when the settlement applies at company scope rather than site scope
- `variancePostingReference`: optional identifier for the downstream posting or variance document created from the reviewed handoff

The following contract rules apply:

- `ManufacturingCostSettlementAcknowledgment` must reference a cost summary already in `VARIANCE_REVIEWED`; an acknowledgment for any earlier lifecycle state is invalid
- The payload must match the reviewed handoff's `productionOrderReference`, `costSummaryReference`, and settlement currency before manufacturing can transition the cost summary to `SETTLED`
- If downstream accounting rejects, reverses, or supersedes the reviewed handoff, the cost summary must remain `VARIANCE_REVIEWED` until a valid replacement acknowledgment is received
- `TECHNICALLY_COMPLETE -> CLOSED` remains blocked until manufacturing records a valid `ManufacturingCostSettlementAcknowledgment` for the linked cost summary

The `CostVariance` taxonomy must be granular enough to avoid mixing price deltas with usage or efficiency deltas. The initial scope replaces the coarse `material` and `labor_machine` buckets with the following categories:

- `MATERIAL_PRICE`: Actual material unit valuation differs from the snapped planned unit cost for the consumed quantity
- `MATERIAL_USAGE`: Actual material quantity consumed differs from the BOM-based planned quantity after normalizing to the snapped planned unit cost
- `LABOR_RATE`: Actual labor cost-per-hour differs from the snapped labor rate for the reported hours
- `LABOR_EFFICIENCY`: Actual labor hours differ from the snapped standard hours after normalizing to the snapped labor rate
- `MACHINE_RATE`: Actual machine rate differs from the snapped machine cost rate for the reported machine hours
- `MACHINE_EFFICIENCY`: Actual machine hours differ from the snapped standard machine hours after normalizing to the snapped machine rate
- `SCRAP`: Cost attributable to reported scrap transactions that should remain visible separately from normal material usage
- `YIELD`: Cost impact caused by producing fewer good units than planned after material and resource consumption are applied

Each variance category must support a distinct downstream variance-account reference from `coa-management`. Manufacturing owns the classification and reference data needed for handoff, while downstream accounting decides whether to post, aggregate, or settle those balances.

Manufacturing supports a single active overhead absorption rule per `WorkCenter`. The policy is owned by manufacturing as part of `WorkCenter` master data because the rate follows the resource or line used to perform work, not the warehouse or financial-accounting module. A work center may define:

- `overheadAbsorptionMethod`: one of `PERCENT_OF_LABOR_COST`, `PERCENT_OF_MACHINE_COST`, or `FIXED_AMOUNT_PER_GOOD_UNIT`
- `overheadAbsorptionRate`: the numeric rate or amount interpreted by the selected method
- `overheadAbsorptionCurrency`: required when the method is `FIXED_AMOUNT_PER_GOOD_UNIT`

The initial scope uses these rules:

- `PERCENT_OF_LABOR_COST`: planned or actual overhead equals labor cost multiplied by the configured percentage
- `PERCENT_OF_MACHINE_COST`: planned or actual overhead equals machine cost multiplied by the configured percentage
- `FIXED_AMOUNT_PER_GOOD_UNIT`: planned or actual overhead equals good quantity reported multiplied by the configured amount per unit

When a production order is released, manufacturing snapshots the resolved work-center overhead method, rate, and currency onto the order or operation cost baseline. Later edits to the work center must not mutate released orders. During execution, actual overhead uses the same snapped method with actual reported labor cost, machine cost, or completed good quantity as the driver. Work centers without an overhead absorption rule contribute zero planned and zero actual overhead.

## Test Cases

- Releasing a production order must snapshot the planned material and routing-based cost assumptions used for later variance comparison
- Releasing a production order must resolve each component's planned unit cost from inventory-owned valuation data rather than from a manufacturing-edited BOM cost field
- A STANDARD component must snapshot inventory's currently effective per-item `StandardCost` as its planned unit cost at release
- AVCO and FIFO component baselines return with those inventory costing phases
- Production-order release must be rejected when inventory cannot resolve planned material cost for a required component
- Actual material cost used by manufacturing must come from `InventoryIssueOutcomeEvent` rather than duplicated manufacturing-owned valuation logic
- `InventoryIssueOutcomeEvent` must not be accepted as actual material cost input until the referenced inventory issue has completed inventory-owned valuation
- Actual labor or machine cost should derive from reported time and the applicable work-center rates in force for the order snapshot
- Moving a cost summary to `PENDING_VARIANCE_REVIEW` should require that the parent production order is `TECHNICALLY_COMPLETE`
- Moving a cost summary to `VARIANCE_REVIEWED` should require an explicit reviewer approval and freeze the reviewed variance breakdown unless the order is reopened
- Moving a cost summary to `SETTLED` should require a valid `ManufacturingCostSettlementAcknowledgment` rather than a manufacturing-only toggle
- Planned overhead must derive from the released work center's snapped `overheadAbsorptionMethod` and `overheadAbsorptionRate`
- Editing a work center's overhead absorption rule after release must not change the planned overhead baseline of an already released production order
- Actual overhead must use the same snapped absorption method as the plan, substituting actual labor cost, machine cost, or completed good quantity as the driver
- Planned and actual cost must be tracked independently per production order and company
- Completing additional work after an order is marked closed should be rejected or require a controlled reopening workflow
- Variance calculation should separate at minimum `MATERIAL_PRICE`, `MATERIAL_USAGE`, `LABOR_RATE`, `LABOR_EFFICIENCY`, and distinct scrap or yield-related causes rather than combining them into a single material or labor bucket
- Variance handoff data must retain the variance category and its mapped variance-account reference for every published variance line
- An in-progress production order should expose accumulated actual cost even before full completion
- Manufacturing must not create journal entries or mutate GL balances directly as part of variance calculation
- Downstream accounting handoff data should retain references to the production order, site, finished item, completed quantity, and variance breakdown
- Manufacturing must not transition a reviewed cost summary to `SETTLED` until `ManufacturingCostSettlementAcknowledgment` is received from the accounting-owned settlement process with matching order and cost-summary references
- Only authorized manufacturing or finance-review users should be able to finalize cost review, mark the summary `VARIANCE_REVIEWED`, and advance the order toward administrative close

## Reference Links

- [Oracle work orders overview](https://docs.oracle.com/en/cloud/saas/supply-chain-and-manufacturing/25d/faumf/overview-of-work-orders.html)
- [MRPeasy manufacturing scheduling and costing overview](https://www.mrpeasy.com/manufacturing-scheduling-software/)
- [Rootstock manufacturing ERP overview](https://www.rootstock.com/manufacturing-erp-software/)
