Functional Weave
Code in Rust

energy.bill-calculate@1.0.0

README.md

2,955 bytes · view raw

# energy.bill-calculate

A GB electricity or gas bill from the reads at the start and end of the
period, as a supplier's bill sets it out:

1. **Units**: closing read less opening read, allowing for the register
   rolling over (`energy.meter-advance`).
2. **kWh**: electricity meters read kWh; gas units are converted with the
   calorific value and the 1.02264 correction factor (`energy.gas-kwh`),
   kept to the watt-hour.
3. **Energy charge**: kWh x unit rate, rounded once to a penny by `mode`.
4. **Standing charge**: days x daily charge, rounded once by `mode`. The days
   are those between the two read dates (`dates.days-between`).
5. **Climate Change Levy**, unless the supply is for qualifying use
   (`energy.climate-change-levy`, at the rate on the closing read date).
6. **VAT** on the sum of those three lines, CCL included (the levy is part
   of the price for VAT), via `finance.tax.add-vat` at the rate for
   `vatCategory` on the closing read date, rounded half-up.

## VAT: the category is the caller's

`finance.tax.vat-rate` has no energy-specific category, and this capability
does not add one: it takes the GB category from the caller and looks the
rate up by date, so it follows the rate table rather than hard-coding 5%.

- **REDUCED (5%)**: fuel and power for qualifying use: domestic, charity
  non-business, and business supplies within the de minimis limits (33 kWh a
  day of electricity, 145 kWh a day of gas).
- **STANDARD (20%)**: other business supplies.
- **ZERO**: domestic electricity in Great Britain from 1 October 2026 to
  31 March 2027, under the temporary zero rate. `finance.tax.vat-rate` does
  not yet carry that as a dated rule for REDUCED, so pass ZERO for a qualifying
  electricity supply in that window; gas stays REDUCED.

`qualifyingUse` is asked separately because it also decides the Climate
Change Levy, and because the same qualifying supply can be REDUCED or ZERO
depending on the fuel and date. Keep the two consistent: a qualifying supply
is REDUCED or ZERO, a non-qualifying one STANDARD.

## Rates

Unit rate and standing charge are **excluding VAT**, in thousandths of a
penny, as business tariffs are quoted. Ofgem's price cap figures
(`energy.price-cap`) include VAT; divide by 1.05 first.

## Not covered

A single rate for the whole period: split a bill across a tariff change, a
CCL rate change (1 April) or a VAT change into two calls. Economy 7 and
half-hourly pricing are `energy.tariff-time-of-use`.

## Sources

- HMRC, "VAT on fuel and power (VAT Notice 701/19)",
  https://www.gov.uk/guidance/vat-on-fuel-and-power-notice-70119 (qualifying
  use, de minimis limits; paragraph 2.8 on the Climate Change Levy).
- HM Treasury / HMRC, "Temporary zero rate of VAT for domestic electricity in
  Great Britain",
  https://www.gov.uk/government/publications/temporary-zero-rate-of-vat-for-domestic-electricity-in-great-britain
- The capabilities this one uses carry their own sources.