# CostLayer

## Description

CostLayer tracks costed quantity: one row per costed receipt of an item within a company, carrying the received quantity and the unconsumed remaining quantity. Layers carry no money; prices live in each costing method's own table ([StandardCost](./StandardCost.md), [FifoCost](./FifoCost.md), [AverageCost](./AverageCost.md)).

A layer is created by every costed IN movement; every costed OUT movement consumes layers in first-in-first-out order, decrementing the remaining quantity and recording a [CostLayerConsumption](./CostLayerConsumption.md) per consumed layer. FIFO consumption is an accounting assumption: stock need not physically leave in receipt order.

Layers track costed quantity, not physical quantity (that is StockLevel): stock that moves without costing never enters a layer, so an issue that exceeds the company's layered stock fails rather than valuing stock that is not on the books.

## Domain Model Definitions

### Model type

Standard

### Command Definitions

- Layers are created and consumed internally by [postInventoryLedger](../command/PostInventoryLedger.md); no direct command

### Query Definitions

- Cost layers are resolved internally by costing; no read query yet

### Models

- CostLayer

### Invariants

- Received quantity is greater than zero
- Remaining quantity is between zero and the received quantity, and equals the received quantity minus the sum of the layer's consumptions
- Belongs to the item and the company of the receiving location's site
- Issues consume layers with remaining quantity in FIFO order: earliest effective date first, creation order breaking ties

### Relationships

- **References Item**: Each cost layer belongs to an Item from the item-management module
- **References Company**: Each cost layer belongs to a Company from the organization module
- **References InventoryLedger**: Each cost layer originates from the IN ledger entry that received the stock
- **Has many CostLayerConsumption**: Every consumption of the layer is recorded as a [CostLayerConsumption](./CostLayerConsumption.md)
- **Has many FifoCost**: Under FIFO policies the layer's price history lives in [FifoCost](./FifoCost.md) rows
- **Has many AcquisitionCostAdjustmentAllocation**: Invoice-driven cost corrections record their per-layer allocations in [AcquisitionCostAdjustment](./AcquisitionCostAdjustment.md) allocations
