# Lines, totals and VAT

> How charges become bill lines rounded once, and how VAT is extracted from gross totals or added to net totals so the bill matches what the customer was promised.


`totals` turns charges into bill lines and a VAT breakdown.

- **One rounding per line**, to the cent, half away from zero (kaufmännisch). Charges
  stay unrounded until then: 1 000 one-second calls at 0,19 € per minute in the 1/1
  Takt are one line of 3,17 €.
- **Gross books** (consumer brands): line amounts include VAT. Per rate, VAT is
  extracted from the gross sum once — `tax = round(gross × r / (100 + r))`, `net =
  gross − tax` — so 59,97 € stays 59,97 € and holds 9,58 € VAT and 50,39 € net. A
  net-based calculation would print 59,96 € or 59,98 €: a one-cent gap on every
  consumer bill.
- **Net books** (business brands): VAT is computed once per rate on the net sum, as
  EN 16931 does for an e-invoice.

In both, `net + vat == gross` exactly.

```rust
use telco_core::{PeriodState, Subscription, compile, rate, totals};
use time::macros::date;

let book = compile(&[("book.toml".to_owned(), br#"
[book]
id = "fibre"
version = "1"
prices = "gross"
currency = "EUR"
[tax.standard]
rates = [{ from = "2021-01-01", percent = "19" }]
[plan.p]
name = "Glasfaser"
tax = "standard"
recurring.base = { label = "Glasfaser 1000", amount = "49.99" }
recurring.phone = { label = "Telefon-Flat", amount = "4.99" }
recurring.router = { label = "Router", amount = "4.99" }
"#.to_vec())])?;

let sub = Subscription { window: None, plan: "p".into(), start: date!(2026 - 01 - 01), end: None };
let rated = rate(&book, &sub, &PeriodState::new("2026-11".parse()?), &[])?;
let t = totals(&book, &rated.charges)?;

assert_eq!(t.gross.to_string(), "59.97");
assert_eq!(t.vat.to_string(), "9.58");
assert_eq!(t.net.to_string(), "50.39");
assert_eq!(t.net + t.vat, t.gross);
# Ok::<(), telco_core::Refusal>(())
```

The extraction is `billing::split_gross` from the
[billing](https://hupe1980.github.io/billing) crate.

## Which charges become lines

Every charge becomes one line, except included usage (in a flat) and usage fully
covered by an allowance. Their charges remain in the result with their traces, so
nothing disappears from the evidence.
