# ManufacturingCostSummary

## Description

ManufacturingCostSummary stores the planned-versus-actual cost view for one production order without taking ownership of journal posting. It owns the frozen release-time baseline, accumulated actual material or resource evidence, variance-line classification, review lifecycle, and downstream settlement-acknowledgment traceability that gates final administrative close.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> COLLECTING: releaseProductionOrder
    COLLECTING --> COLLECTING: recordInventoryIssueOutcome
    COLLECTING --> PENDING_VARIANCE_REVIEW: technicallyCompleteProductionOrder
    PENDING_VARIANCE_REVIEW --> VARIANCE_REVIEWED: reviewManufacturingCostSummary
    PENDING_VARIANCE_REVIEW --> COLLECTING: reopenProductionOrder
    VARIANCE_REVIEWED --> COLLECTING: reopenProductionOrder
    VARIANCE_REVIEWED --> SETTLED: recordManufacturingCostSettlementAcknowledgment
```

### Command Definitions

- [releaseProductionOrder](../commands/ReleaseProductionOrder.md) - Create the frozen planned baseline when the order is released.
- [recordInventoryIssueOutcome](../commands/RecordInventoryIssueOutcome.md) - Apply inventory-valued material issue outcomes to actual cost accumulation.
- [technicallyCompleteProductionOrder](../commands/TechnicallyCompleteProductionOrder.md) - Move the summary into variance-review status when execution is frozen.
- [reviewManufacturingCostSummary](../commands/ReviewManufacturingCostSummary.md) - Recalculate and approve the final variance breakdown.
- [reopenProductionOrder](../commands/ReopenProductionOrder.md) - Return the summary to active collection when execution is resumed.
- [recordManufacturingCostSettlementAcknowledgment](../commands/RecordManufacturingCostSettlementAcknowledgment.md) - Persist downstream settlement evidence and unlock order close.

### Query Definitions

- [getManufacturingCostSummary](../queries/GetManufacturingCostSummary.md) - Retrieve one production order cost summary with planned, actual, and variance data.
- [listManufacturingCostSummariesByStatus](../queries/ListManufacturingCostSummariesByStatus.md) - List summaries waiting for review or settlement queues.

### Models

- ManufacturingCostSummary
- ManufacturingCostLine
- CostVarianceLine
- ManufacturingCostSettlementRecord

### Invariants

- Every production order owns exactly one manufacturing cost summary.
- The planned material, labor, machine, and overhead baseline is frozen at release and never recomputed from later master-data changes.
- Actual material cost enters the summary only through the named inventory-owned outcome contract after inventory valuation is final.
- `PENDING_VARIANCE_REVIEW` and `VARIANCE_REVIEWED` summaries belong only to production orders that have already reached `TECHNICALLY_COMPLETE`.
- `VARIANCE_REVIEWED` requires an explicit reviewer action and a frozen variance breakdown.
- `SETTLED` requires a valid downstream acknowledgment whose order, summary, and currency match the reviewed handoff.
- `COLLECTING` is the only state that accepts new actual cost accumulation from execution evidence.
- If execution is reopened after review, the summary must return to `COLLECTING` rather than accumulating against a settled baseline.
- Variance classification must keep at least `MATERIAL_PRICE`, `MATERIAL_USAGE`, `LABOR_RATE`, `LABOR_EFFICIENCY`, `MACHINE_RATE`, `MACHINE_EFFICIENCY`, `SCRAP`, and `YIELD` distinct.

### Relationships

- **Belongs To ProductionOrder**: summary lifecycle is subordinate to one [ProductionOrder](./ProductionOrder.md).
- **Consumes WorkOrder evidence**: actual labor, machine, quantity, and scrap signals originate from [WorkOrder](./WorkOrder.md) execution.
- **Consumes InventoryIssueOutcomeEvent**: actual material cost arrives from the named inventory-owned issue valuation contract.
- **Consumes settlement acknowledgment**: the reviewed handoff is settled through the named `ManufacturingCostSettlementAcknowledgment` contract from downstream accounting or financial close.
- **References WorkCenter and BOM snapshots**: planned baseline uses released [WorkCenter](./WorkCenter.md) rates and [BillOfMaterial](./BillOfMaterial.md) component assumptions.
- **References coa-management**: reviewed variance lines carry downstream account references from coa-management for settlement handoff.
