Documentation

How to rate usage, attach VAT, derive EN 16931 totals, split documents exactly and settle them — with the rules cited so you can check them.

billing is a calculation library: you state what was supplied, at what price and under which VAT treatment; it derives the line nets, the VAT breakdown and every EN 16931 total. No I/O.

These pages are the guide; docs.rs is the API reference. Every Rust example here is compiled and run against the crate.

🔗Where to start

Every rule id cited here exists in the pinned CEN, Peppol or KoSIT Schematron and is hash-locked in citations.lock. This is not legal or tax advice.

  • Getting started Install billing, rate a tiered water tariff, attach VAT, and read every EN 16931 total from a document that derived them once.
  • Money and rounding Amount<P>, the four sign-symmetric rounding modes, AmountScale and reducing once, and why a Price is not money until it is multiplied by a quantity.
  • Metering Readings reduced to a billable quantity as data — sum, count, unique count, min, max, latest, mean, weighted sum, weighted mean and percentile — exactly, with averages kept as fractions all the way into the invoice line.
  • Pricing Tariffs as data — per-unit, graduated, volume and package — plus interval series rated exactly, a tariff per key, transaction fees, progressive billing and nearest-rank percentiles.
  • VAT VAT as an attribute of every line and adjustment: the ten UNCL 5305 categories, exemption reasons, and the BG-23 breakdown derived by grouping with the tax rounded once per group.
  • Gross prices Consumer prices are quoted gross and EN 16931 is net. split_gross applies the VAT fraction once — and the invoice still will not always total the shelf prices.
  • Allowances, charges and levies Line allowances and charges (BG-27/28), document allowances and charges (BG-20/21), apportioning a discount across VAT groups, and per-unit levies as ordinary lines.
  • The totals chain BT-106 to BT-115 mapped onto Document's accessors, the order they are derived in, and which EN 16931 rules therefore hold by construction rather than by a check.
  • Splitting Exact largest-remainder splits — split, split_matrix, Document::split and Line::segments — what they guarantee and what they cannot.
  • Corrections and bounds Document::negated for credits, Document::concat for merging with VAT rounded once over the union, and minimum and maximum bounds settled into an ordinary line.
  • Settlement BT-113 payments and advances, BT-114 cash rounding, BT-111 VAT in an accounting currency, customer credits drawn before or after tax, and the residual VAT of a final invoice.
  • Payment terms The arithmetic of payment terms: the Skonto amount and the per-group VAT correction it implies, and statutory late-payment interest rounded once across rate changes. The BT-20 text is the format's.
  • Errors One Error type: kind() says why, location() says where (0-based), rule() names the EN 16931 or Peppol rule it enforces. Match on those, not on the text.
  • EN 16931 and scope Why rounding at the serialiser cannot work, how a Document rounds the leaves once, why BT-146 must never be rounded, and what belongs to en16931 instead.
  • Design The model — inputs in, every total derived once, nothing stored that a caller could edit — the invariants the crate holds itself to, and how correctness is checked.
  • Migrating What to change when upgrading: 0.16 → 0.17, then 0.15 → 0.16. Breaking releases have no deprecation shims; the CHANGELOG has the full old → new tables.