Functional Weave
Code in Rust

inventory.valuation-fifo@1.0.0

README.md

1,705 bytes · view raw

# inventory.valuation-fifo

First in, first out: each issue is costed from the oldest stock still on hand,
so what remains is valued at the most recent purchase prices. This is the
method IAS 2 and FRS 102 section 13 allow alongside weighted average cost (LIFO
is not permitted under either).

The ledger is one item's movements in date order: receipts carry a unit cost,
issues carry none and take their cost from the layers they consume. An issue
that spans several receipts is costed from each in turn, oldest first, and a
receipt that is partly used stays as a smaller layer. The result gives the
closing quantity and value, the remaining layers, the cost of sales, and the
cost of each issue in ledger order (to post each one to the ledger).

**Exact money.** Unit costs are `Money` in minor units and every cost is
quantity times unit cost, so nothing is rounded and closing value plus cost of
sales always equals the total of the receipts. A unit cost that has fractions of
a penny cannot be expressed; use `inventory.valuation-weighted-average`, or cost
in a smaller unit (per 100) and scale the quantities.

**Errors, not guesses.** An issue larger than the stock on hand is an error
rather than negative stock: FIFO has no cost for units that were never
received. So are a ledger out of date order, a zero quantity, a receipt with no
unit cost or a negative one, an issue with a unit cost, and a cost in another
currency. Returns to supplier and customer returns are not modelled: post a
customer return as a receipt at the cost it was issued at.

Sources: IAS 2 *Inventories*, paragraphs 25-27 (IFRS Foundation); FRS 102
section 13 *Inventories*, paragraph 13.18 (Financial Reporting Council).