# 04 — Costing Layer

> Money. Translates all operations into financial figures and reveals problems. Inherits all rules from `00`. Four components. The most valuable output is **Variance Analysis**.

---

## 4.1 Component: Costing Method

**Purpose:** Strategic decision on how inventory & production are valued. Set once; hard to change. Configurable **per item**.

```
costing_method ∈ { Standard, Actual, Average, FIFO }   (Item.costing_method)
```

| Method | Philosophy | Suits |
|---|---|---|
| Standard | Pre-set standard cost; difference = variance | Stable mass production |
| Actual | Real cost per order | Job shops |
| Average | Moving average | Volatile prices |
| FIFO | Oldest issued first | Products with shelf life |

### Formulas
```
Average:  new_avg = (existing_qty×old_cost + new_qty×new_cost) / total_qty
FIFO:     issue at oldest batch prices in order
```

### Standard cost build-up
```
Standard_Cost: { std_material_cost, std_labor_cost, std_overhead_cost,
                 std_total_cost, last_updated, update_frequency }
```

### Generic-design note
System must support **mixed methods**: e.g. Standard for finished products (enables variances + stable inventory), Average for volatile raw materials. Per-item `costing_method`.

### Melamine test case
Powder (volatile price) → Average. Dishes → Standard.

---

## 4.2 Component: Cost Elements

**Purpose:** Total product cost = three elements, each with its own source and calculation.

```
Total Cost = Direct Material + Direct Labor + Manufacturing Overhead
```

### 1. Direct Material
```
= Σ(BOM_qty × material_price)
source: BOM (quantities) + Material Master (price per costing_method)
POST: Debit WIP / Credit Raw Materials
```

### 2. Direct Labor — generalized by `labor_calc`
```
Hourly:    labor_hours × labor_rate
PieceRate: quantity × piece_rate
POST: Debit WIP / Credit Labor Applied
```
**Critical rule:** only labor whose pay **varies with output** is Direct Labor. Fixed-salary workers (even if on the line) → Overhead. Test: does pay change with production? Yes→Direct, No→Overhead.

### 3. Manufacturing Overhead
```
overhead_rate = total_annual_overhead / total_annual_cost_driver
cost_driver ∈ { LaborHours, MachineHours, DirectMaterialCost, UnitsProduced }
POST (at confirmation): Debit WIP / Credit MOH Applied
month-end: applied vs actual → over/under-applied → P&L
```
Types: Variable OH (electricity, consumables), Fixed OH (rent, depreciation, salaries), Semi-variable (maintenance).

### Generic-design notes
- **Negligible consumables → overhead pool**, not BOM lines (e.g. sprayed glaze, tape).
- **Usage-based depreciation** for tools (by cycles, not calendar) — only running tools wear. Allocated per piece per its specific tool, so expensive/large items carry more.

### Melamine cost model
```
piece cost = material(powder + decor if printed)   [direct, varies/unit]
           + press labor (piece_rate)              [direct, varies/unit]
           + everything else (overhead rate)       [fixed pool]
           + that shape's mold depreciation
Only material & press-labor vary per piece; all else is overhead.
```

---

## 4.3 Component: Cost Center

**Purpose:** Accounting unit that accumulates costs for a part of the plant. Enables "pressing cost X, assembly cost Y".

```
Cost_Center: { cc_id, type∈{Production,Service,Auxiliary}, parent_cc,
               manager_id, budget_amount, actual_amount, status }
```

### Allocation methods (service → production)
```
Direct:     service → production only
Step-Down:  service → other services + production, sequentially
Reciprocal: all services allocate mutually + to production
```

### Generic-design note
Service costs allocate by **cause**, not evenly. Maintenance of presses → allocate mainly to the pressing center, not split equally (assembly shouldn't bear press maintenance).

### Melamine test case
```
Maintenance 8000 (Direct method): CC-PRESS 90% → 7200, CC-FINISH 10% → 800,
CC-ASSEMBLY 0% (no presses).
```

---

## 4.4 Component: Variance Analysis

**Purpose:** THE key output — reveals production problems. Variance = actual − standard. The total is useless alone; value is in **decomposition**, each type pointing to a problem and an owner.

### The seven variances
```
1. Material Price Variance  MPV = (actual_price − std_price) × actual_qty       → Purchasing
2. Material Usage Variance  MUV = (actual_qty − std_qty) × std_price            → Production (waste)
3. Labor Rate Variance      LRV = (actual_rate − std_rate) × actual_hours       → (n/a if piece-rate)
4. Labor Efficiency Var.    LEV = (actual_hours − std_hours) × std_rate         → Production
5. Variable OH Spending     VOSV = actual_var_OH − (actual_hours × std_VOH_rate)→ Management
6. Variable OH Efficiency   VOEV = (actual_hours − std_hours) × std_VOH_rate
7. Fixed OH Volume Variance FOVV = (actual_production − budgeted) × std_fixed_OH/unit
```

### Generic-design notes
- Under **PieceRate**, traditional LRV/LEV don't apply (slow worker costs himself); deviation shifts to machine/overhead.
- **FOVV is critical when fixed costs are large**: lower output spreads fixed cost over fewer units → higher unit cost. Drives the "run at full capacity" insight.

### Variance tolerance
```
< 2%   → Normal, no investigation
2–5%   → Monitor
> 5%   → Investigation Required
```

### Analysis logic
```
monthly, for each closed order:
  compute the 7 variances
  for each variance > tolerance:
      classify (material/labor/overhead) ; route to owner
  generate Pareto report (biggest causes)
```

### Owner mapping (output)
```
Material Price ↑    → Purchasing
Material Usage ↑    → Production (waste)
Labor Efficiency ↑  → Production
Overhead ↑          → Management
Volume Variance     → Sales/Management (output dropped)
```

### Joint-products (recap from execution)
```
total_sale_value = Σ(grade.qty × grade.price)
grade.cost = total_cost × (grade.qty × grade.price) / total_sale_value
```
Cost follows value, not equal split. Grade A (priciest) absorbs most cost/unit.
