# `billing@1`: subscription revenue and invoicing

Version **1.1.0** · published 2026-11-30 · MIT · boards: saas-metrics, invoices-receivables · [changelog](../CHANGELOG.md)

Customers subscribe to prices. What each subscription bills is kept as **state over time**: `subscription_items` has one
row per stretch of days during which one item kept the same price, quantity and recurring discount, and
`subscription_pauses` holds the stretches when collection was paused. MRR and its movements are computed from that
state, never from invoices alone (an invoice tells you what was billed for a period, including prorations and one-off
charges; it is not the recurring value). Invoices, payments, refunds and credit notes are the money that actually moved,
for payments, dunning and refund views.

## Conventions
- **Money** is REAL in major units, with a `currency` (ISO 4217) on every money row. Amounts are **positive**; a refund
  or credit note is a positive amount that reduces revenue collected. Zero-decimal currencies (JPY) are whole units.
- **Instants** are ISO 8601 UTC (`2026-03-12T09:00:00Z`). **State dates** (`subscription_items`, `subscription_pauses`)
  are days, `YYYY-MM-DD`: a row covers `"start" <= day < "end"`, `end` NULL = still running. Quote `"start"` and `"end"`
  in SQL.
- **Ids** are the source's own, namespaced by connector and account: `stripe:<account>:sub_...`. The same object read
  through the Stripe CSV exports or the Stripe API gets the same id, so a person can move between lane 1 and lane 2.
  A row without a source id uses `<parent id>:<kind>:<start>` (a state row: `<subscription>:<item>:<start>`).
- **Provenance** on every fact table: `source` (`stripe`, `stripe-csv`, `billing-csv`, `manual`), `source_ref`
  (`subscriptions.csv:12`, or the API object id), `imported_at` (left out of `meta.data_hash`), and `confidence`
  where a value is inferred (`detected`: e.g. a quantity change rebuilt from invoices, shown for review).
- **People:** never an email address. `customers.email_hash` is the first 16 hex characters of
  sha256(lowercase, trimmed email). `customers.name` is optional (a company name, as the source has it); a name that
  is an email address is dropped by the importer.
- meta required keys: `schema`, `schema_version`, `as_of`, `data_hash`, `source_built_at`, `base_currency` (the
  reporting currency).

## MRR: the rules (every board and connector follows these; the board recomputes them in Python)

**MRR of one state row** (a `subscription_items` row on day *d*):
`(COALESCE(unit_amount, plans.unit_amount) x quantity x (1 - COALESCE(discount_pct, 0)) - COALESCE(discount_amount, 0))`,
never below zero, normalised to a month: `month` / interval_count; `year` / (12 x interval_count); `week` x 52 / 12 /
interval_count; `day` x 365 / 12 / interval_count. **Annual plans count 1/12 of their price every month**, from the
first day (not the month they were paid).

**A subscription counts on day *d*** when all of these hold:
1. it has started (`started_at` <= *d*) and has not ended (`ended_at` NULL or after *d*). Churn happens at `ended_at`,
   the day service stopped (a cancellation at period end keeps counting until then), never at `canceled_at`;
2. it is not in a free trial (`trial_end` NULL or on or before *d*). A trial is worth 0. A trial **converts only when
   its first invoice after the trial is paid** (`trial_converted = 1`); it then counts from the trial's end (as *new*
   MRR). A trial cancelled before it ends, or whose first invoice is never paid (`trial_converted = 0`), never counts and
   is never churn ("trial not converted"). `NULL` means no invoice was seen: it counts;
3. it is not paused on *d* (`subscription_pauses`). A paused subscription is worth 0 but is kept apart (`paused`);
4. its status is not `incomplete` or `incomplete_expired` (the first payment never succeeded);
5. its price is `licensed` (a `metered` price is billed on usage after the fact and is not MRR; boards list it).

`past_due` and `unpaid` subscriptions still count until they end (Stripe cancels them, or marks them unpaid, after
its retries): a failed payment is not churn until the subscription ends (dunning is shown on its own). The one
exception is a trial's first invoice (rule 2).

**Discounts:** only recurring discounts (coupon `duration` `repeating` or `forever`) are carried onto state rows and
reduce MRR. A repeating coupon that runs out closes its row; the higher MRR after it is *expansion*. A once-only coupon
is a one-off on one invoice: it never moves MRR. **An amount off the whole subscription** (`amount_off`) is shared
across the items billing at the time in proportion to their pre-discount amounts (two items of 50 and 20 with 10 off:
7.14 and 2.86 off, MRR 60), so it is subtracted once, never once per item. Earlier coupons that have since run out or
been removed are rebuilt from the invoices' discounts (discount / subtotal for each period), counted when known to
recur or seen on a neighbouring renewal too.

**History and change dates** (one builder for every source, `lib/py/dashremix_board/billing/state.py`): earlier states
come from full-period invoices (`detected`). A change is dated by its evidence and never backdated: a proration line's
period start, a subscription_update invoice, or (totals only) the day a renewal's proration implies. With no evidence the
current state counts from the as-of date and the change is listed. Pauses: a run of void renewals ended by a paid one is
a past pause; a current pause starts at the first renewal after the last paid one that was not paid. **Refunds and credit notes never move MRR** (they are cash, shown on
the board's payments page).

**Monthly snapshot:** a customer's MRR for a month is read on the month's **last day** (for the current month, the
as-of date). Something that starts and ends inside one month never shows in MRR.

**Currencies:** each customer's MRR is first summed in its own currency (`mrr_native`), then converted at the rate
recorded in `fx_rates` for the snapshot day (the latest rate on or before it). **A currency with no rate stops the
import** (nothing is guessed, the previous data is kept).

**Movements** compare each customer's MRR at one snapshot with the previous one, at **constant currency**: the
previous month's native MRR is re-priced at this month's rate (`prev_cc`), so a rate change alone is never expansion.

| Movement | When (per customer, totals across its currencies) | Amount |
|---|---|---|
| `new` | prev_cc = 0, now > 0, and the customer never had MRR before | now |
| `reactivation` | prev_cc = 0, now > 0, the customer had MRR in an earlier month, and nothing was paused last month | now |
| `resume` | prev_cc = 0, now > 0, and last month's MRR was 0 only because of a pause | now |
| `expansion` | prev_cc > 0 and now > prev_cc | now - prev_cc |
| `contraction` | now > 0 and now < prev_cc | now - prev_cc (negative) |
| `pause` | prev_cc > 0, now = 0, and a paused subscription holds its MRR now | -prev_cc |
| `churn` | prev_cc > 0, now = 0, nothing paused | -prev_cc |
| `fx` | every customer with MRR last month | prev_cc - prev (the rate change on last month's MRR) |

So for every month: **MRR(this month) - MRR(last month) = new + reactivation + resume + expansion + contraction + pause
+ churn + fx**, exactly (each amount is rounded to cents before it is summed). The board checks this every month.

The worked example is in `fixtures/`: `mrr_monthly.csv` holds the golden MRR for each case (a monthly plan, seats up
and down, an annual plan with a forever coupon, a euro customer whose rate changes and who cancels at period end, a
trial that converts then pauses, a trial cancelled before it ends, a churn and later reactivation with a repeating
coupon that runs out, and a metered-only customer who never has MRR).

## Invoicing (1.1): sent invoices, receivables and partial payments

For people who send invoices (freelancers, studios, small businesses) rather than run subscriptions. The same tables
hold them: `invoices` (one row per invoice, `subscription_id` NULL), `invoice_lines`, `payments` and `customers` (the
clients). The rules every board and connector follows:

- **Status.** `status` keeps its five values. The tools' own words map onto them: draft → `draft`; sent, viewed,
  partial, overdue, disputed → `open`; paid → `paid`; void, deleted, cancelled → `void`; written off, bad debt →
  `uncollectible`. The tool's word is kept in `source_status`. *Overdue* (open with `due_on` before today) and *partly
  paid* (open with `amount_paid` > 0) are derived, never stored.
- **Balance.** For a sent invoice: `total = amount_paid + amount_remaining + written_off`. A void invoice counts nowhere;
  a draft is not yet owed.
- **Local dates.** `issue_date`, `due_on`, `sent_on`, `paid_on`, `closed_on` and `payments.paid_on` are days in the
  seller's calendar, the IANA zone in `tz`. A source that gives a date keeps that date as is (never read as midnight UTC);
  a source that gives an instant (Stripe's UTC times) is converted into `tz` first, so a payment at 23:30 in New York is
  that day, not the next. Day counts (days late, aging) subtract dates, never instants, so a daylight-saving change never
  moves an invoice into another bucket.
- **Partial payments** are one `payments` row each, with `paid_on`. A source that has only an invoice's paid date and
  amount paid gives one payment with `confidence = detected`; a source with neither a payment row nor a paid date gives no
  payment row (pay speed for that invoice is unknown, never guessed).
- **Ids** are the source's own invoice id or number, namespaced by connector and account
  (`stripe:<account>:in_...`, `xero:<account>:INV-0042`), never a file name or a row number, so a re-downloaded file
  gives the same ids. The same invoice exported by two tools is one invoice: a board counts it once (exact identity:
  same number, currency, total and issue date) and lists the copy as a duplicate; same number and currency with a
  different total or date is a conflict shown for the person to settle, never summed.
- **Currencies** are never added together without a recorded rate: totals are per currency.
- **People.** Clients are companies or people: `customers.name` is shown on the person's own board and blanked in
  anything shared; emails only as `email_hash`.

## Sources that fill it
| Source | Lane | Fills |
|---|---|---|
| Stripe Dashboard CSV exports: Customers, Subscriptions, Invoices (and optionally Payments), mapped by header name | 1 | customers, plans (from the subscription rows), subscriptions, subscription_items (the current state from the subscriptions file; earlier changes rebuilt from full-period invoices, `confidence = detected`), invoices, payments |
| A billing@1 CSV folder: one CSV per table in the columns below (the fixtures here are an example) | 1 | every table |
| Stripe REST API with a **read-only restricted key** (`dashremix connect stripe`; `connectors/stripe/api.py`) | 2 | customers, plans, coupons, subscriptions, subscription_items (current items, plus earlier state rebuilt from invoice lines, `detected`), subscription_pauses, subscription_events, invoices, payments, refunds, credit_notes |
| Stripe MCP (lookups by the assistant only, with consent; agent-tagged restricted keys from December 2026) | 3 | nothing written here |
| Paddle, Lemon Squeezy, Chargebee, RevenueCat | 1/2 | wave 2 mappers |
| Invoicing exports (Stripe Invoicing, Xero, FreshBooks, QuickBooks, Wave, Harvest), mapped by header name (Invoices & Receivables) | 1 | customers, invoices, invoice_lines, payments |

`mrr_monthly` is **derived by a board's importer** from the tables above (never written by a connector). Wave-2 boards
(Founder Weekly, Cash Runway, Customer Health) read it instead of re-deriving MRR.

## Compatibility
- A board that declares `billing@1 >=1.0` keeps working on any later 1.x database; one that reads the invoicing fields
  declares `>=1.1`.
- A remix that adds only metrics, pages and `x_<owner>_` tables survives every minor.
- Changing a movement rule above changes meaning, so it is a **major** (billing@2), with a codemod.

## Fields

<!-- fields:begin (generated from schema.sql by spec/build.py; edit the DDL comments) -->

### `meta` (required table)

Key/value facts about this database. Required: schema, schema_version, as_of, data_hash, source_built_at, base_currency.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `key` | TEXT | no |  |
| `value` | TEXT | no |  |

### `customers` (required table)

One customer (a person or a company that pays). Never the email address: only a hash of it.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `customer_id` | TEXT | **yes** | stripe:<account>:cus_... or the source's own id, namespaced |
| `name` | TEXT | no | display name as the source has it (company or description); optional, boards blur it under privacy |
| `created_at` | TEXT (instant) | no | ISO 8601 UTC instant the customer was created at the source |
| `country` | TEXT (country) | no | ISO 3166-1 alpha-2 billing country, when known |
| `currency` | TEXT (currency) | no | ISO 4217 currency the customer is billed in (e.g. EUR) |
| `segment` | TEXT | no | free label the person sets (SMB, mid-market ...); never inferred |
| `email_hash` | TEXT | no | first 16 hex of sha256(lower(trim(email))); never the email itself |
| `payment_terms_days` | INTEGER | no | (1.1) the customer's usual payment terms in days (30 = net 30), when the source has them |
| `source` | TEXT | no | connector id that wrote the row: stripe \| stripe-csv \| billing-csv \| manual |
| `source_ref` | TEXT | no | where in the source: file:line (customers.csv:12) or the API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import (left out of meta.data_hash) |

### `plans` (required table)

A price customers subscribe to (Stripe price, older Stripe plan). unit_amount is per interval_count intervals.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `price_id` | TEXT | **yes** | stripe:<account>:price_... |
| `product` | TEXT | no | product id the price belongs to |
| `product_name` | TEXT | no | product display name (Growth) |
| `nickname` | TEXT | no | price nickname (Growth yearly) |
| `interval` | TEXT (vocab `intervals`) | **yes** | month \| year \| week \| day (vocab intervals) |
| `interval_count` | INTEGER | **yes** | bills every interval_count intervals (3 + month = quarterly) |
| `unit_amount` | REAL | no | major units per unit per billing period; NULL for tiered or metered prices |
| `currency` | TEXT (currency) | **yes** | ISO 4217 |
| `usage_type` | TEXT (vocab `usage_types`) | no | licensed (quantity known upfront: counts in MRR) \| metered (billed on usage: not in MRR) |
| `active` | INTEGER | no | 1 = can still be sold |
| `source` | TEXT | no | connector id |
| `source_ref` | TEXT | no | file:line or API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant |

### `coupons`

A coupon. Only discounts that recur (duration repeating or forever) are carried onto subscription_items and so reduce MRR; a once-only coupon is a one-off on one invoice and never moves MRR.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `coupon_id` | TEXT | **yes** | stripe:<account>:<coupon id> |
| `name` | TEXT | no | display name |
| `percent_off` | REAL | no | share off, as a decimal (0.2 = 20%); NULL when amount_off is set |
| `amount_off` | REAL | no | major units off each invoice; NULL when percent_off is set |
| `currency` | TEXT (currency) | no | ISO 4217 of amount_off |
| `duration` | TEXT (vocab `coupon_durations`) | **yes** | once \| repeating \| forever (vocab coupon_durations) |
| `duration_in_months` | INTEGER | no | repeating: how many months it applies from when it is applied |
| `source` | TEXT | no | connector id |
| `source_ref` | TEXT | no | file:line or API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant |

### `subscriptions` (required table)

One subscription of one customer. Its status is the source's current status; what it billed over time is in subscription_items, pauses in subscription_pauses. A subscription stops counting in MRR at ended_at (the day the service ended, e.g. the end of the paid period after a cancellation), not at canceled_at (the day it was cancelled).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `subscription_id` | TEXT | **yes** | stripe:<account>:sub_... |
| `customer_id` | TEXT | **yes** |  |
| `status` | TEXT (vocab `subscription_status`) | **yes** | trialing \| active \| past_due \| unpaid \| paused \| canceled \| incomplete \| incomplete_expired (vocab) |
| `created_at` | TEXT (instant) | no | ISO 8601 UTC instant it was created |
| `started_at` | TEXT (instant) | **yes** | ISO 8601 UTC instant it started (trial included) |
| `trial_start` | TEXT (instant) | no | ISO 8601 UTC instant a free trial began, if any |
| `trial_end` | TEXT (instant) | no | ISO 8601 UTC instant the trial ended (or ends); no MRR before it |
| `trial_converted` | INTEGER | no | after a trial: 1 = its first invoice was paid (MRR from trial_end), 0 = invoiced but never paid (never MRR), NULL = no invoice seen (counts) |
| `cancel_at_period_end` | INTEGER | no | 1 = cancelled, ends at the end of the paid period |
| `canceled_at` | TEXT (instant) | no | ISO 8601 UTC instant the cancellation was made |
| `ended_at` | TEXT (instant) | no | ISO 8601 UTC instant it stopped (no MRR from this day on) |
| `cancel_reason` | TEXT | no | as the source gives it (cancellation_requested, payment_failed ...) |
| `collection` | TEXT (vocab `collection_methods`) | no | auto (card charged) \| invoice (sent to pay) |
| `currency` | TEXT (currency) | no | ISO 4217 the subscription bills in |
| `confidence` | TEXT (vocab `confidence`) | no | source (as delivered) \| detected (inferred, e.g. from invoices) \| manual |
| `source` | TEXT | no | connector id |
| `source_ref` | TEXT | no | file:line or API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant |

### `subscription_items` (required table)

What a subscription billed, over time: one row per stretch during which one item kept the same price, quantity and recurring discount. A change (upgrade, seats, a coupon starting or ending) closes one row and opens the next. Dates are days: a row covers "start" <= day < "end" ("end" NULL = still running). Monthly value of a row: (COALESCE(unit_amount, plans.unit_amount) x quantity x (1 - discount_pct) - discount_amount) normalised to a month (year / 12, week x 52 / 12, day x 365 / 12, divided by interval_count), never below zero.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `segment_id` | TEXT | **yes** | <subscription_id>:<item>:<start>, stable for the same state |
| `subscription_id` | TEXT | **yes** |  |
| `item_id` | TEXT | no | the source's subscription item id (stripe:<account>:si_...), when known |
| `price_id` | TEXT | **yes** |  |
| `quantity` | REAL | **yes** | seats or units |
| `unit_amount` | REAL | no | price per unit per billing period when it differs from the plan's (custom or legacy price); NULL = plans.unit_amount |
| `discount_pct` | REAL | no | recurring share off, decimal (0.2 = 20%) |
| `discount_amount` | REAL | no | recurring amount off each billing period, major units of the price currency |
| `coupon_id` | TEXT | no | the coupon behind the discount, when known |
| `start` | TEXT (date) | **yes** | YYYY-MM-DD first day of this state |
| `end` | TEXT (date) | no | YYYY-MM-DD first day it no longer held (exclusive); NULL = still running |
| `confidence` | TEXT (vocab `confidence`) | no | source \| detected (rebuilt from invoices: check on the board) \| manual |
| `source` | TEXT | no | connector id |
| `source_ref` | TEXT | no | file:line or API object id (si_..., in_... for a row rebuilt from an invoice) |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant |

### `subscription_pauses`

A pause in collection (Stripe pause_collection, a paused subscription). No MRR while paused: boards show it as its own movement (pause / resume), never as churn.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `pause_id` | TEXT | **yes** | <subscription_id>:pause:<start> |
| `subscription_id` | TEXT | **yes** |  |
| `start` | TEXT (date) | **yes** | YYYY-MM-DD first paused day |
| `end` | TEXT (date) | no | YYYY-MM-DD first day collected again (exclusive); NULL = still paused |
| `behavior` | TEXT | no | the source's pause behaviour (void, keep_as_draft, mark_uncollectible) |
| `source` | TEXT | no | connector id |
| `source_ref` | TEXT | no | file:line or API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant |

### `subscription_events`

The change log behind subscription state (the events MRR movements are made of): when a subscription started, a trial ended, an item changed, it paused, resumed, was cancelled or ended. Optional and descriptive: MRR comes from subscriptions, subscription_items and subscription_pauses; this table lets a board show why.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `event_id` | TEXT | **yes** | the source's event id, or <subscription_id>:<kind>:<at> |
| `subscription_id` | TEXT | **yes** |  |
| `customer_id` | TEXT | no | the subscription's customer |
| `at` | TEXT | **yes** | ISO 8601 UTC instant (or YYYY-MM-DD) it took effect |
| `kind` | TEXT (vocab `event_kinds`) | **yes** | vocab event_kinds: started, trial_ended, item_changed, discount_changed, paused, resumed, cancel_scheduled, canceled, ended |
| `price_id` | TEXT | no | the price after the change, when it is about one |
| `quantity` | REAL | no | the quantity after the change |
| `detail` | TEXT | no | short words from the source (never personal data) |
| `confidence` | TEXT (vocab `confidence`) | no | source \| detected \| manual |
| `source` | TEXT | no | connector id |
| `source_ref` | TEXT | no | file:line or API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant |

### `invoices`

An invoice. total is what was billed after discounts and tax; amount_paid what was collected.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `invoice_id` | TEXT | **yes** | stripe:<account>:in_... |
| `number` | TEXT | no | the invoice number shown to the customer |
| `customer_id` | TEXT | no |  |
| `subscription_id` | TEXT | no | the subscription it bills, NULL for a one-off invoice |
| `created_at` | TEXT (instant) | **yes** | ISO 8601 UTC instant |
| `period_start` | TEXT (instant) | no | ISO 8601 UTC instant the billed period starts |
| `period_end` | TEXT (instant) | no | ISO 8601 UTC instant the billed period ends |
| `billing_reason` | TEXT | no | subscription_create \| subscription_cycle \| subscription_update \| manual ... |
| `subtotal` | REAL | no | before discounts and tax |
| `discount` | REAL | no | discounts on this invoice (positive) |
| `tax` | REAL | no | tax on this invoice |
| `total` | REAL | **yes** | billed: subtotal - discount + tax |
| `amount_due` | REAL | no | left to collect when it was finalised |
| `amount_paid` | REAL | no | collected |
| `amount_remaining` | REAL | no | still open |
| `currency` | TEXT (currency) | **yes** | ISO 4217 |
| `status` | TEXT (vocab `invoice_status`) | **yes** | draft \| open \| paid \| uncollectible \| void (vocab invoice_status) |
| `attempt_count` | INTEGER | no | payment attempts so far (more than 1 = dunning) |
| `paid_at` | TEXT (instant) | no | ISO 8601 UTC instant it was paid |
| `due_date` | TEXT (instant) | no | ISO 8601 UTC instant it is due (invoice collection) |
| `issue_date` | TEXT (date) | no | (1.1) YYYY-MM-DD date printed on the invoice, in the seller's calendar (tz) |
| `due_on` | TEXT (date) | no | (1.1) YYYY-MM-DD local due date (a date-only source keeps its date; an instant is converted in tz, never via UTC) |
| `sent_on` | TEXT (date) | no | (1.1) YYYY-MM-DD local day it was first sent; NULL = not sent or not known |
| `paid_on` | TEXT (date) | no | (1.1) YYYY-MM-DD local day it was paid in full; NULL = not paid in full or the source has no paid date |
| `closed_on` | TEXT (date) | no | (1.1) YYYY-MM-DD local day it was voided or written off |
| `written_off` | REAL | no | (1.1) amount written off as uncollectible (positive), so total = amount_paid + amount_remaining + written_off |
| `source_status` | TEXT | no | (1.1) the tool's own status word (sent, viewed, partial, overdue, written off ...); status keeps the five standard values |
| `reference` | TEXT | no | (1.1) purchase order or project reference printed on the invoice |
| `tz` | TEXT | no | (1.1) IANA time zone the local dates are in (Europe/London) |
| `source` | TEXT | no | connector id |
| `source_ref` | TEXT | no | file:line or API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant |

### `invoice_lines`

(1.1) the lines of an invoice (services, time, products, expenses, discounts). amount is the line total before tax (quantity x unit_amount less any line discount; negative for a discount line); the invoice's subtotal is their sum.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `line_id` | TEXT | **yes** | <invoice_id>:<position>, or the source's line id |
| `invoice_id` | TEXT | **yes** |  |
| `position` | INTEGER | no | 1-based order on the invoice |
| `description` | TEXT | no | the line text (private: boards blank it in shared copies) |
| `kind` | TEXT (vocab `line_kinds`) | no | service \| time \| product \| expense \| discount \| other (vocab line_kinds) |
| `quantity` | REAL | no | hours, days or units |
| `unit_amount` | REAL | no | price per unit, major units |
| `amount` | REAL | **yes** | line total before tax, major units |
| `tax_rate` | REAL | no | decimal (0.2 = 20%) |
| `tax_amount` | REAL | no | tax on this line |
| `currency` | TEXT (currency) | **yes** | ISO 4217, the invoice's currency |
| `source` | TEXT | no | connector id |
| `source_ref` | TEXT | no | file:line or API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant |

### `payments`

A payment attempt (Stripe charge): succeeded, failed or pending. A failed attempt is a row too (dunning).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `payment_id` | TEXT | **yes** | stripe:<account>:ch_... or py_... |
| `invoice_id` | TEXT | no | the invoice it pays |
| `customer_id` | TEXT | no | the customer |
| `created_at` | TEXT (instant) | **yes** | ISO 8601 UTC instant of the attempt |
| `amount` | REAL | **yes** | attempted amount, major units (positive) |
| `amount_refunded` | REAL | no | refunded so far (refunds holds each refund) |
| `fee` | REAL | no | processor fee, when known |
| `net` | REAL | no | amount - fee, when known |
| `currency` | TEXT (currency) | **yes** | ISO 4217 |
| `status` | TEXT (vocab `payment_status`) | **yes** | succeeded \| failed \| pending (vocab payment_status) |
| `failure_code` | TEXT | no | card_declined, insufficient_funds, expired_card ... when failed |
| `refunded` | INTEGER | no | 1 = fully refunded |
| `paid_on` | TEXT (date) | no | (1.1) YYYY-MM-DD local day the money arrived (partial payments: one row each) |
| `method` | TEXT (vocab `payment_methods`) | no | (1.1) bank_transfer \| card \| cash \| check \| other (vocab payment_methods) |
| `confidence` | TEXT (vocab `confidence`) | no | (1.1) source (a payment row in the source) \| detected (one payment built from an invoice's paid date and amount paid) |
| `source` | TEXT | no | connector id |
| `source_ref` | TEXT | no | file:line or API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant |

### `refunds`

A refund of a payment. Refunds and credit notes reduce revenue collected; they never move MRR (MRR is the recurring value of subscriptions, not cash).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `refund_id` | TEXT | **yes** | stripe:<account>:re_... |
| `payment_id` | TEXT | no | the payment refunded |
| `customer_id` | TEXT | no | the customer |
| `created_at` | TEXT (instant) | **yes** | ISO 8601 UTC instant |
| `amount` | REAL | **yes** | refunded, major units (positive) |
| `currency` | TEXT (currency) | **yes** | ISO 4217 |
| `reason` | TEXT | no | duplicate \| fraudulent \| requested_by_customer \| other |
| `status` | TEXT | no | succeeded \| pending \| failed \| canceled |
| `source` | TEXT | no | connector id |
| `source_ref` | TEXT | no | file:line or API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant |

### `credit_notes`

A credit note against an invoice (money owed back or credited to the customer's balance).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `credit_note_id` | TEXT | **yes** | stripe:<account>:cn_... |
| `invoice_id` | TEXT | no | the invoice it credits |
| `customer_id` | TEXT | no | the customer |
| `created_at` | TEXT (instant) | **yes** | ISO 8601 UTC instant |
| `amount` | REAL | **yes** | credited, major units (positive) |
| `currency` | TEXT (currency) | **yes** | ISO 4217 |
| `reason` | TEXT | no | duplicate \| fraudulent \| order_change \| product_unsatisfactory \| other |
| `status` | TEXT | no | issued \| void |
| `source` | TEXT | no | connector id |
| `source_ref` | TEXT | no | file:line or API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant |

### `fx_rates`

Recorded exchange rates into the reporting currency. Boards use the latest rate on or before a date and stop (never guess) when a currency has no rate. The person records them (inputs) or a connector delivers them.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `date` | TEXT (date) | **yes** | YYYY-MM-DD the rate applies from |
| `ccy` | TEXT (currency) | **yes** | ISO 4217 currency converted |
| `base_ccy` | TEXT (currency) | **yes** | ISO 4217 reporting currency |
| `base_per_unit` | REAL | **yes** | units of base_ccy for one unit of ccy (EUR->USD 1.08) |
| `source` | TEXT | no | where the rate comes from (inputs.yaml, ECB reference rate ...) |

### `mrr_monthly`

Derived by a board's importer from the tables above (never written by a connector): each customer's MRR at each month's snapshot (the month's last day, or the as-of date for the current month), one row per customer, currency and month from the customer's first MRR month to the as-of month, zeros included (so a month-to-month diff finds churn). Trials, ended subscriptions, metered prices and paused subscriptions count 0 (paused_native keeps what the paused ones would bill).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `customer_id` | TEXT | **yes** | the customer |
| `month` | TEXT (month) | **yes** | YYYY-MM |
| `currency` | TEXT (currency) | **yes** | ISO 4217 of mrr_native |
| `snapshot` | TEXT (date) | **yes** | YYYY-MM-DD the state was read at |
| `mrr_native` | REAL | **yes** | MRR in currency, major units, rounded to cents |
| `paused_native` | REAL | **yes** | what paused subscriptions would add, in currency |
| `fx_rate` | REAL | **yes** | base units per unit of currency on the snapshot day (1 for the base currency) |
| `mrr` | REAL | **yes** | round(mrr_native x fx_rate, 2), in meta.base_currency |
| `n_subscriptions` | INTEGER | **yes** | subscriptions counting in MRR at the snapshot |
| `price_ids` | TEXT | no | JSON list of the prices counting at the snapshot (plan mix) |

### `import_issues`

Rows the importer or a connector could not read, or left out on purpose (platform table).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `issue_id` | TEXT | **yes** | stable id: <file>:<line> or <file>:<kind> |
| `severity` | TEXT (vocab `severities`) | **yes** | info \| warn \| error |
| `kind` | TEXT | **yes** | skipped_row \| missing_column \| fx_missing \| metered_price \| detected_history ... |
| `file` | TEXT | no | the source file name (never its contents) |
| `line` | INTEGER | no | 1-based line in that file, when the issue is one row |
| `detail` | TEXT | **yes** | what happened |
| `handling` | TEXT | **yes** | what was done about it |
| `source` | TEXT | no | connector id |

### `overrides`

Corrections the person made to imported values, with the reason (platform table).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `override_id` | TEXT | **yes** | stable id |
| `target` | TEXT | **yes** | table.key.column the override applies to |
| `field` | TEXT | no | column name |
| `old_value` | TEXT | no | value before |
| `new_value` | TEXT | no | value after |
| `reason` | TEXT | **yes** | why, in the person's words |
| `evidence` | TEXT | no | where it comes from |
| `author` | TEXT | no | person or assistant |
| `created_at` | TEXT | no | ISO 8601 instant |

### `annotations`

Notes on metrics and pages (platform table). Numbers only through {{metric:...}} placeholders.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `annotation_id` | TEXT | **yes** | stable id |
| `target` | TEXT | **yes** | metric id or page id |
| `kind` | TEXT | **yes** | note \| caveat \| flag \| decision \| open_item |
| `body` | TEXT | **yes** | the note text |
| `author` | TEXT | no | person or assistant |
| `source_ref` | TEXT | no | where it came from |
| `created_at` | TEXT | no | ISO 8601 instant |
| `data_hash` | TEXT | no | hash of the cited metric values when written (stale when they change) |
| `status` | TEXT | no | active \| stale \| retired |

### `metric_registry`

The board's metrics, installed from metrics.sql by the importer (platform table).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `metric_id` | TEXT | **yes** | e.g. kpi.mrr |
| `version` | INTEGER | no | the metric's own version |
| `unit` | TEXT | no | usd \| rows \| pct \| date \| count ... |
| `params` | TEXT | no | comma list of parameters it honours |
| `description` | TEXT | no | the @desc line |
| `sql` | TEXT | no | expanded SQL |
| `test` | TEXT | no | the @test line (check that covers it) |

<!-- fields:end -->
