# inventory-cost-tracking

## Overview

Tracks inventory costs under standard costing. Each item carries date-effective, append-only `StandardCost` generations published via `publishStandardCost`; each item is attached to a company-scoped `ValuationPolicy` (carrying the company's eight posting accounts) either explicitly via `setItemValuationPolicy` or auto-assigned the movement company's default policy on its first valuation-affecting movement. Every valuation-affecting movement (inbound shipment settle, outbound shipment settle, stock adjustment confirm) creates and posts a balanced journal entry in financial-accounting within the same transaction — receipts post inventory at standard against the accrual account with the actual-vs-standard difference to PPV, issues relieve COGS at standard, adjustments post gains/losses/scrap against the adjustment account. Publishing a new standard revalues on-hand stock against the standard cost adjustment account. Policy assignment and standard cost publication are API-level operations (no dedicated screens); the Purchaser views the current standard in the stock-level cost drawer.

## Actors Involved

- [Purchaser](../../actor/purchaser.md) — assigns valuation policies, publishes standard costs, and views standard cost history

## Flow Diagram

```mermaid
sequenceDiagram
    participant P as Purchaser
    participant S as System

    P->>S: Assign valuation policy to item (setItemValuationPolicy)
    S-->>P: ItemValuation created (item ↔ policy per company)

    P->>S: Publish standard cost (publishStandardCost)
    S->>S: Append StandardCost generation (effective today)
    S->>S: Revalue on-hand — (new − previous) × on-hand — posted against the standard cost adjustment account (skipped for the first generation)
    S-->>P: StandardCost generation ID

    Note over S: Valuation-affecting movement settles (receipt / issue / adjustment)
    S->>S: Cost movement at the item's effective standard
    S->>S: Create and post journal entry in financial-accounting (same transaction)

    P->>S: Query standard cost generations for item
    S-->>P: Generations ordered by version
```

## Stories

- [Assign Valuation Policy](./story/purchaser--assign-valuation-policy.md)
- [Publish Standard Cost](./story/purchaser--publish-standard-cost.md)
- [View Standard Costs](./story/purchaser--view-standard-costs.md)
