carlos / platform Public

plan: billing dashboard 1-2, Astra round 1 fixes

Plan 1: one payment row per balance movement (charge, refund debit,
failed-refund reversal, fee), keyed by the provider's balance
transaction; refunds and reversals tax-exclusive, domain refunds inherit
the charge's tax share; unknown yearly amounts carried as AmountsKnown
through totals, snapshots and the CLI; no ARR rebuild (spec 4.2 amended:
history starts on the day this ships); today's snapshot replaceable,
earlier days frozen, incompleteness flags stored; a per-account daily
snapshot; a fee-inclusive Payments read (Kind "all").

Plan 2: per-account earnings for a past month from the daily account
snapshots (unknown before the first one); profit and cash need complete
revenue conversion as well as Platform.OK; the money table reads fee
rows; an ARR-over-time chart under the overview tiles; no dependency on
Plan 3's slice B.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 630cf52ceaf8fe2aa8928bcd8163bc97a5857cab parent f4812e8
3 files changed, +293 −134
  • docs/superpowers/plans/2026-11-09-billing-dashboard-1-data.md +170 −93
  • docs/superpowers/plans/2026-11-09-billing-dashboard-2-pages.md +122 −38
  • docs/superpowers/specs/2026-11-09-billing-dashboard-design.md +1 −3
diff --git a/docs/superpowers/plans/2026-11-09-billing-dashboard-1-data.md b/docs/superpowers/plans/2026-11-09-billing-dashboard-1-data.md
index c3013dd17..3456b5238 100644
--- a/docs/superpowers/plans/2026-11-09-billing-dashboard-1-data.md
+++ b/docs/superpowers/plans/2026-11-09-billing-dashboard-1-data.md
@@ -5,7 +5,7 @@
**Goal:** On a console with billing on, record every payment, refund and
provider fee from the billing provider, store each subscription's yearly
amount, sort every account into one group, keep daily euro reference rates
-and a daily ARR snapshot, and show the result through `carlos billing
+and daily ARR and per-account snapshots, and show the result through `carlos billing
revenue` and `carlos billing payments`.
**Architecture:** Neutral records and three new read-only `billing.Provider`
@@ -39,8 +39,20 @@ and §5; Plan 3 (written separately) covers §4.5.
- **Never gate readiness on the new reads.** A restricted key without the
new permissions fails the money pass (logged, `jobFailed`), never
`Check`, the webhook's other kinds or the subscription sync.
-- **Idempotent on the provider id.** `billing_payments.provider_id` is the
- primary key; a second record of the same id writes nothing.
+- **One row per balance movement, recorded once.** `billing_payments` is
+ keyed by the provider's balance-movement id (Stripe's balance
+ transaction): a charge, a refund's debit, a failed refund's reversal and
+ a provider fee are each their own row; a second record of the same
+ movement writes nothing.
+- **Revenue is tax-exclusive in every direction.** Charges, refunds and
+ reversals all carry their tax share (`Tax`, `SettledTax`), so revenue
+ before tax is `Settled − SettledTax` for every kind: a fully refunded
+ €120 charge with €20 tax nets 0 before fees.
+- **Completeness travels with every total.** A total that leaves something
+ out says so: `EURKnown` (a rate is missing), `AmountsKnown` (a paying
+ account's yearly amount is unknown) and `PaymentsCurrent` (the reconcile
+ did not finish) are carried through totals, snapshots, the CLI and the
+ pages. Nothing shows a figure as complete when one of them is false.
- **Integer minor units everywhere stored.** Converting to euros happens on
read, for display only; no converted figure is stored back into billing
state (spec §3). Rates are stored as the ECB publishes them (units per
@@ -50,7 +62,11 @@ and §5; Plan 3 (written separately) covers §4.5.
current subscription. `billing_accounts.state` is not used for it.
- **ARR** (spec §4.2): yearly amount after discounts, before tax, over paying
accounts, excluding any with `cancel_at_period_end` and the exempt
- account. `past_due` stays in.
+ account. `past_due` stays in. ARR history starts at the first real
+ snapshot; nothing rebuilds earlier days (spec §4.2, amended on this
+ branch 2026-11-09: "History starts on the day this ships").
+- **Snapshots:** today's (UTC) rows are replaced on every pass until the
+ day ends; earlier days are frozen.
- **Groups** (spec §4.7), first match wins: Ours (`planExempt`), Paying
(paying and yearly amount not 0; unknown counts as not 0), House
(`billing_house` row), Sponsored (`account_plans.source = 'sponsored'` or
@@ -93,17 +109,20 @@ and §5; Plan 3 (written separately) covers §4.5.
list fits; the cursor never passes a movement that was not recorded
(Task 5 `TestReconcileHalvesWindowOnIncomplete`,
`TestReconcileCursorHoldsOnError`).
-3. **A refund whose charge was never recorded** (refunded before the
- backfill read it, or the webhook lost). The refund is recorded against
- the same account, from the charge read the refund triggers (Task 5
+3. **A refund that failed, none of it recorded locally** (the backfill
+ meets it after the fact). The charge, the refund's debit and its
+ reversal are each recorded once, so the money nets to the charge (Task 5
+ `TestReconcileFailedRefundNeverRecorded`); a refund whose charge was
+ never recorded lands on the charge's account (Task 5
`TestReconcileRefundOfUnrecordedCharge`).
4. **The ECB is down or answers nonsense.** The last good rates stay; a
rate of 0, a negative rate or an empty set is refused, never stored
(Task 6 `TestECBRefusesBadRates`, `TestRatesPassKeepsLastGood`).
-5. **A house account (100% coupon) and a cancel-at-renewal account.** The
- house account has yearly amount 0 and no payment, so it is House, not
- Paying; the cancelling account is Paying but outside ARR (Task 1
- `TestAnnualOf`, Task 7 `TestARROf`).
+5. **A paid subscription whose yearly amount is unknown** (an unsupported
+ discount). It is Paying, its amount is left out of ARR, and every ARR
+ figure says it is incomplete (Task 7 `TestARROfUnknownAmount`). A house
+ account (100% coupon) is House, and a cancelling one is Paying outside
+ ARR (Task 1 `TestAnnualOf`, Task 7 `TestARROf`).
---
@@ -202,21 +221,23 @@ and §5; Plan 3 (written separately) covers §4.5.
- Reasons: `ReasonFirst "first"`, `ReasonRenewal "renewal"`,
`ReasonChange "change"`, `ReasonDomain "domain"`, `ReasonOther "other"`,
`ReasonReversed "reversed"` (a refund that failed and came back).
- - `type Payment struct { ID, Movement string; Kind PaymentKind; Reason
- string; Customer, Subscription, PaymentIntent, Charge string; Amount,
- Tax int64; Currency string /* as charged, signed: negative for refunds
- and fees */; Settled, Fee, SettledTax int64; SettledCurrency string; At
- time.Time; LiveMode bool }`. `ID` is the provider id of what was paid
- or refunded, or the movement id for a fee or a reversal.
+ - `type Payment struct { Movement string /* the provider's balance-movement
+ id: the record's key */; Source string /* the charge or refund it
+ settles; "" for a fee */; Kind PaymentKind; Reason string; Customer,
+ Subscription, PaymentIntent, Charge string; Amount, Tax int64; Currency
+ string /* as charged, signed: negative for refund debits and fees,
+ positive for reversals */; Settled, Fee, SettledTax int64;
+ SettledCurrency string; At time.Time; LiveMode bool }`.
- `type ChargeRecord struct { Captured bool; Charge Payment; Refunds
- []Payment }` (refunds already settled, each `Kind PaymentRefund`).
+ []Payment }` — `Refunds` holds, per refund, its debit (`Kind refund`,
+ negative) and, when the refund failed, its reversal (`Kind refund`,
+ `Reason reversed`, positive, the debit's tax negated), each with its
+ own `Movement`.
- `func SettledShare(part, whole, settled int64) int64` — `round(part ×
settled / whole)`, 0 when `whole` is 0 (settled tax, and a refund's
- tax share).
- - `func FeePayment(m Movement, live bool) Payment` and
- `func ReversalPayment(m Movement, refunded *Payment, live bool) Payment`
- (copy customer, subscription and charge from the refunded row when
- known).
+ tax share; the sign follows `settled`).
+ - `func FeePayment(m Movement, live bool) Payment` (`Movement m.ID`,
+ `Source ""`, `Kind fee`, `Settled m.Amount`, `Fee 0`).
- `EventPayment EventKind = "payment"`: `Event.Object` is a charge id.
- Produces (`billingtest.Fake`): fields `Movements []billing.Movement`,
`Charges map[string]billing.ChargeRecord`, `AccountOpened time.Time`, and
@@ -229,10 +250,8 @@ and §5; Plan 3 (written separately) covers §4.5.
- [ ] **Step 1: Write the failing tests**: `TestSettledShare` (tax 400 of
2800 charged, 2610 settled → 373; whole 0 → 0; negative settled keeps
- its sign); `TestFeePaymentAndReversal` (fee movement -45 eur →
- `Kind fee, Settled -45, Fee 0, ID == movement id`; reversal copies the
- refunded row's customer and charge, `Reason reversed`, positive
- `Settled`); `TestFakeMoneyMovementsWindowAndPages` (five movements, a
+ its sign); `TestFeePayment` (fee movement -45 eur → `Kind fee, Settled
+ -45, Fee 0, Movement == m.ID, Source ""`); `TestFakeMoneyMovementsWindowAndPages` (five movements, a
window holding three returns those three oldest first; `PageSize 1` and
eleven movements → `ErrIncomplete`); `TestFakeParsesPaymentEvent`.
- [ ] **Step 2: Run** `go test ./internal/billing/... -run 'TestSettledShare|TestFeePayment|TestFakeMoney|TestFakeParsesPayment' -count=1` → FAIL.
@@ -268,7 +287,8 @@ and §5; Plan 3 (written separately) covers §4.5.
`MovementOther`.
- `ChargePayments(ctx context.Context, charge string) (billing.ChargeRecord, error)`
— `GET /v1/charges/<id>` with `expand[]` `balance_transaction`,
- `invoice`, `refunds`, `refunds.data.balance_transaction`; refunds past
+ `invoice`, `refunds`, `refunds.data.balance_transaction`,
+ `refunds.data.failure_balance_transaction`; refunds past
the first page through `GET /v1/refunds?charge=<id>` (`listAll`, same
expansion). 404 → `billing.ErrNotFound`. `Captured` is
`captured && balance_transaction != null`. Kind and reason from the
@@ -276,10 +296,15 @@ and §5; Plan 3 (written separately) covers §4.5.
`subscription_cycle` → subscription/renewal, `subscription_update` →
once-off/change, other or no invoice → once-off/other. `Tax` is the
invoice's `tax` (0 without an invoice); `Subscription` the invoice's
- subscription; `SettledTax` by `billing.SettledShare`. A refund is
- `Kind refund`, `Amount` and `Settled` negative, `Tax` its share of the
- charge's tax, refunds without a balance transaction or with status
- `failed` or `canceled` left out.
+ subscription; `SettledTax` by `billing.SettledShare`; `Movement` the
+ charge's balance transaction, `Source` the charge. Every refund with a
+ balance transaction gives its debit (`Kind refund`, `Amount` and
+ `Settled` negative, `Tax` its share of the charge's tax, `Movement` its
+ balance transaction, `Source` the refund), whatever its status now; a
+ refund with a `failure_balance_transaction` also gives the reversal
+ (`Reason reversed`, positive, the debit's tax negated, `Movement` the
+ failure transaction). A refund with neither (pending without a
+ movement yet, canceled) gives nothing.
- `AccountCreated(ctx context.Context) (time.Time, error)` — `created`
of `GET /v1/account`.
- `ParseEvent`: `charge.succeeded`, `charge.captured`, `charge.refunded`
@@ -301,7 +326,12 @@ and §5; Plan 3 (written separately) covers §4.5.
"sub_1"`, `Settled 2610`, `Fee 106`, `SettledCurrency "eur"`.
- `TestChargePaymentsTaxAndRefund`: eur charge 2904 with invoice tax 504
and one 2904 refund → charge `Tax 504`, `SettledTax 504`; refund
- `Amount -2904`, `Tax -504`, `Kind refund`, `Charge` set.
+ `Amount -2904`, `Tax -504`, `SettledTax -504`, `Kind refund`, `Charge`
+ set, `Movement` the refund's balance transaction.
+ - `TestChargePaymentsFailedRefund`: a refund with status `failed`, a
+ `balance_transaction` (-2904) and a `failure_balance_transaction`
+ (+2904) → two refund rows, debit and reversal, distinct `Movement`s,
+ taxes `-504` and `+504`; they sum to 0.
- `TestChargePaymentsUpdateIsOnceOff`: `subscription_update` →
once-off/change; a charge with no invoice → once-off/other, `Tax 0`.
- `TestChargePaymentsUncaptured`: `captured false` → `Captured false`,
@@ -334,7 +364,7 @@ and §5; Plan 3 (written separately) covers §4.5.
- Consumes: Task 2 `billing.Payment`.
- Produces:
- `func (s *Store) migrateBillingMoney() error` creating
- `billing_payments (provider_id TEXT PRIMARY KEY, movement_id TEXT NOT
+ `billing_payments (movement_id TEXT PRIMARY KEY, source_id TEXT NOT
NULL, kind TEXT NOT NULL, reason TEXT NOT NULL, account_id INTEGER NOT
NULL DEFAULT 0, customer, subscription, payment_intent, charge TEXT NOT
NULL DEFAULT '', amount INTEGER NOT NULL, tax INTEGER NOT NULL,
@@ -348,48 +378,57 @@ and §5; Plan 3 (written separately) covers §4.5.
- `type paymentRow struct { billing.Payment; AccountID int64; Detail
string; RecordedAt time.Time }` (`AccountID` 0: unmatched).
- `func (s *Store) RecordPayment(p billing.Payment, now time.Time) (bool, error)`
- — one transaction: match, then `INSERT ... ON CONFLICT(provider_id) DO
- NOTHING`; true when a row was written. Matching, first hit wins:
+ — one transaction: match, inherit tax, then `INSERT ... ON
+ CONFLICT(movement_id) DO NOTHING`; true when a row was written.
+ Matching, first hit wins:
1. `p.PaymentIntent` equals a `domain_purchases.payment_intent` → that
purchase's account, `Reason domain`, `Detail` the domain; when
`p.Tax == 0`, the purchase's currency is `p.Currency` and `p.Amount
> purchase.amount`, `Tax = p.Amount − amount` and `SettledTax` by
`billing.SettledShare`;
2. `p.Customer` equals a `billing_accounts.customer` → that account;
- 3. `p.Charge` names a recorded row → that row's account (and its
- subscription when `p.Subscription` is empty);
+ 3. `p.Charge` is the `source_id` of a recorded charge row → that
+ row's account (and its subscription when `p.Subscription` is empty);
4. otherwise 0.
- - `func (s *Store) HasPayment(providerID string) (bool, error)`
- - `func (s *Store) PaymentByID(providerID string) (*paymentRow, error)` (nil when none)
+ Then, for a refund or reversal whose `Tax` is 0 when the refunded
+ charge's row has `Tax ≠ 0` (a domain charge's derived tax among them):
+ `Tax = SettledShare(charge.Tax, charge.Amount, p.Amount)` and
+ `SettledTax = SettledShare(Tax, p.Amount, p.Settled)`, so a refund
+ leaves the same share of tax as its charge carried.
+ - `func (s *Store) HasPayment(movement string) (bool, error)`
- `func (s *Store) RematchPayments() (int, error)` — re-runs rules 1-3 for
rows with `account_id = 0`; returns how many matched.
- `type paymentFilter struct { From, To time.Time /* zero: open */; Kind
- string /* "": every kind but fee; "subscription", "once_off",
+ string /* "": every kind but fee (the payment lists); "all": every
+ row, fees included (the money sums); "subscription", "once_off",
"refund", "fee", "unmatched" (account 0, fees excluded) */; AccountID
int64 /* 0: all */; Offset, Limit int /* Limit 0: no limit */ }`
- `func (s *Store) Payments(f paymentFilter) ([]paymentRow, int, error)`
- — newest first by `at` then `provider_id`, and the count matching.
+ — newest first by `at` then `movement_id`, and the count matching.
- `func (s *Store) PaymentCursor() (through time.Time, ok bool, err error)`
and `func (s *Store) SetPaymentCursor(through time.Time) error`.
- Gate rows: `billing_payments` {NonApp: "money received, refunded or
- kept as fees, keyed by the provider's id and the account; names no
+ kept as fees, one row per provider balance movement, with the account; names no
app"}, `billing_payment_cursor` {NonApp: "how far the payment
reconcile has read; names no app"}.
- Account deletion leaves payment rows alone: they are the money record.
- [ ] **Step 1: Write the failing tests**
- `TestRecordPaymentIdempotent`: the same `billing.Payment` twice → true
- then false, one row; a second record with other amounts does not
- change the first.
+ then false, one row; a second record of the same `Movement` with other
+ amounts does not change the first.
- `TestRecordPaymentMatchesCustomer`, `TestRecordPaymentMatchesDomainPurchase`
(purchase amount 1500 usd, charge 1800 usd, tax 0 → `Tax 300`,
`Reason domain`, `Detail` the domain), `TestRecordPaymentRefundFollowsCharge`
(refund with no customer, `Charge` recorded on account A → A),
+ `TestRecordPaymentDomainRefundInheritsTax` (a 12000 eur domain charge
+ whose derived tax is 2000, fully refunded with `Tax 0` → refund `Tax
+ -2000`; charge plus refund `Settled − SettledTax` sums to 0),
`TestRecordPaymentUnmatched` (→ 0, listed by `Kind "unmatched"`).
- `TestRematchPayments`: unmatched row, then the customer is bound →
`RematchPayments` returns 1 and the row has the account.
- `TestPaymentsFilter`: month bounds, each kind, `""` leaving out fee
- rows, account, offset/limit, total, newest first.
+ rows, `"all"` including them, account, offset/limit, total, newest first.
- `TestPaymentCursorRoundTrip`: none → `ok false`; set, read back.
- `TestPaymentsSurviveAccountReap`: `ReapAccount` keeps the rows.
- [ ] **Step 2: Run** `go test ./internal/console -run 'TestRecordPayment|TestRematchPayments|TestPaymentsFilter|TestPaymentCursor|TestPaymentsSurvive' -count=1` → FAIL.
@@ -419,8 +458,10 @@ and §5; Plan 3 (written separately) covers §4.5.
- `func (s *Server) billingMoneyPass(ctx context.Context, now time.Time)`
— returns at once unless billing is on and ready; under
`s.billingClock(ctx)`, runs `reconcilePayments`, then
- `billingRatesPass` (Task 6), then `billingSnapshotPass` (Task 7), each
- failure logged and passed to `jobFailed`, none stopping the next.
+ `billingRatesPass` (Task 6), then `billingSnapshotPass(ctx, now,
+ reconciled)` (Task 7) with `reconciled` true only when the reconcile
+ returned nil; each failure logged and passed to `jobFailed`, none
+ stopping the next.
- `func (s *Server) reconcilePayments(ctx context.Context, now time.Time) error`:
1. `through, ok := PaymentCursor()`; with no cursor this is the
backfill: `from = AccountCreated(ctx)`; else `from = through −
@@ -429,11 +470,11 @@ and §5; Plan 3 (written separately) covers §4.5.
`MoneyMovements(from, to)`. On `billing.ErrIncomplete` halve the
window and retry the same `from`; below `billingMoneyMinWindow`
return the error. Any other error returns it.
- 3. For the window's movements, oldest first: charge and refund kinds
- whose `Source` is not yet recorded add `Charge` to a set; fee →
- `RecordPayment(billing.FeePayment(m, live))`; refund failure →
- `RecordPayment(billing.ReversalPayment(m, PaymentByID(m.Source), live))`;
- other → logged once per type per run.
+ 3. For the window's movements not yet recorded (`HasPayment(m.ID)`),
+ oldest first: charge, refund and refund-failure kinds add `m.Charge`
+ to a set (the charge read records every movement of that charge);
+ fee → `RecordPayment(billing.FeePayment(m, live))`; other → logged
+ once per type per run.
4. `recordCharge` for each charge in the set; the first error returns
it, leaving the cursor where it was.
5. `SetPaymentCursor(to)`, `from = to`, window back to
@@ -442,7 +483,8 @@ and §5; Plan 3 (written separately) covers §4.5.
- `func (s *Server) recordCharge(ctx context.Context, charge string, now time.Time) error`
— `ChargePayments`; `billing.ErrNotFound` or `!Captured` → nil; a
record whose `LiveMode` is not the console's → logged and skipped,
- nil; else `RecordPayment` for the charge and every refund.
+ nil; else `RecordPayment` for the charge, then every refund row (the
+ charge first, so refunds can inherit its account and tax).
- Webhook: `case billing.EventPayment:` → `recordCharge(s.billingClock(r.Context()), ev.Object, now)`;
error → 503 (the provider redelivers); success → 204. Its doc comment
gains the case.
@@ -463,8 +505,14 @@ and §5; Plan 3 (written separately) covers §4.5.
- `TestReconcileRefundOfUnrecordedCharge`: only a refund movement in the
window, its charge never recorded → charge and refund recorded, refund
on the charge's account.
- - `TestReconcileFeesAndReversals`: a fee movement → one fee row; a
- refund failure → a reversal row with the refunded row's account.
+ - `TestReconcileFailedRefundNeverRecorded`: nothing recorded locally;
+ the window holds the charge, the refund debit and the refund-failure
+ movements; the fake's charge record carries the failed refund → three
+ rows (charge, debit, reversal), each keyed by its movement, on the
+ charge's account; `Settled` sums to the charge's; a second run adds
+ nothing.
+ - `TestReconcileFees`: a fee movement → one fee row; a second run adds
+ nothing.
- `TestReconcileSkipsOtherMode`: a charge record with the other
`LiveMode` → nothing recorded, no error.
- `TestWebhookPaymentEventRecords` (204, row present),
@@ -571,28 +619,45 @@ and §5; Plan 3 (written separately) covers §4.5.
- `func inARR(f billingFact, exemptID int64) bool` — paying, not
cancelling, `Annual > 0`, not exempt.
- `type arrTotals struct { ByCurrency map[string]int64; EUR int64;
- EURKnown bool; RateDay string; Paying, Attention int }` — `Attention`
- counts paying accounts that are `past_due` or cancelling; `EURKnown`
- false when a currency in `ByCurrency` has no rate.
+ EURKnown, AmountsKnown bool; Unknown int; RateDay string; Paying,
+ Attention int }` — `Attention` counts paying accounts that are
+ `past_due` or cancelling; `EURKnown` false when a currency in
+ `ByCurrency` has no rate; `AmountsKnown` false and `Unknown` the count
+ when a paying, non-cancelling, non-exempt account has `Annual == -1`
+ (its amount is left out of every sum).
+ - `func (a arrTotals) Complete() bool` — `EURKnown && AmountsKnown`.
- `func arrOf(facts []billingFact, exemptID int64, r eurRates) arrTotals`
- Table `billing_arr_daily (day TEXT PRIMARY KEY, arr TEXT NOT NULL /*
JSON currency → minor */, arr_eur INTEGER NOT NULL, eur_known INTEGER
- NOT NULL, rate_day TEXT NOT NULL, paying INTEGER NOT NULL, rebuilt
- INTEGER NOT NULL DEFAULT 0, written_at INTEGER NOT NULL)`; gate
- {NonApp: "daily recurring revenue totals; names no app"}.
+ NOT NULL, amounts_known INTEGER NOT NULL, unknown INTEGER NOT NULL,
+ payments_current INTEGER NOT NULL, rate_day TEXT NOT NULL, paying
+ INTEGER NOT NULL, written_at INTEGER NOT NULL)`; gate {NonApp: "daily
+ recurring revenue totals; names no app"}.
+ - Table `billing_account_daily (day TEXT NOT NULL, account_id INTEGER NOT
+ NULL, annual INTEGER NOT NULL /* -1 unknown */, currency TEXT NOT NULL,
+ annual_eur INTEGER NOT NULL, eur_known INTEGER NOT NULL, paying INTEGER
+ NOT NULL, in_arr INTEGER NOT NULL, PRIMARY KEY (day, account_id))` —
+ one row per non-exempt account with a subscription on that day; gate
+ {NonApp: "each account's yearly amount per day; names no app"}.
- `type arrSnapshot struct { Day string; ARR map[string]int64; EUR int64;
- EURKnown bool; RateDay string; Paying int; Rebuilt bool }`
- - `func (s *Store) PutARRSnapshot(a arrSnapshot, now time.Time) (bool, error)` (insert or ignore)
+ EURKnown, AmountsKnown bool; Unknown int; PaymentsCurrent bool; RateDay
+ string; Paying int }` and `func (a arrSnapshot) Complete() bool` (all
+ three flags).
+ - `type accountDay struct { Day string; AccountID int64; Annual int64;
+ Currency string; AnnualEUR int64; EURKnown, Paying, InARR bool }`
+ - `func (s *Store) PutDailySnapshot(a arrSnapshot, accounts []accountDay, today string, now time.Time) error`
+ — one transaction. `a.Day == today`: upsert the ARR row and replace
+ every account row of that day. `a.Day` before `today`: refused with
+ an error (earlier days are frozen). `a.Day` after `today`: refused.
- `func (s *Store) ARRSnapshots(fromDay, toDay string) ([]arrSnapshot, error)` (inclusive, oldest first)
- - `func rebuildARR(rows []paymentRow, days []time.Time, r eurRates) []arrSnapshot`
- — pure, for each day: per currency, the pre-tax amounts (`Amount −
- Tax`) of subscription payments in the 365 days up to that day, less
- refunds of those charges; `Paying` the distinct accounts among them;
- `Rebuilt true`.
- - `func (s *Server) billingSnapshotPass(ctx context.Context, now time.Time) error`
- — writes today's (UTC) row once. When the table is empty it first
- writes rebuilt rows for the first of each month from the month of the
- earliest subscription payment through this month, skipping today.
+ - `func (s *Store) AccountDays(fromDay, toDay string) ([]accountDay, error)` (inclusive, by day then account)
+ - `func (s *Store) FirstSnapshotDay() (string, error)` (`""` when none)
+ - `func (s *Server) billingSnapshotPass(ctx context.Context, now time.Time, reconciled bool) error`
+ — builds today's (UTC) `arrSnapshot` from `arrOf` with
+ `PaymentsCurrent = reconciled`, and the account rows from the same
+ facts and rates, and writes them with `PutDailySnapshot`. Every hourly
+ pass rewrites today; the last pass of the day is what stays. No
+ earlier day is ever written, so history starts at the first pass.
- `type billingRevenue struct { arrTotals; Groups map[billingGroup]int;
Accounts int; MonthStart *arrSnapshot /* first snapshot on or after
the 1st of this month, nil when none */; TestMode bool }`
@@ -610,18 +675,27 @@ and §5; Plan 3 (written separately) covers §4.5.
sponsored; operator source with sponsored limits → sponsored;
otherwise free.
- `TestARROf`: eur 2400 + usd 2800 at usd 1.12 → `ByCurrency
- {eur:2400, usd:2800}`, `EUR 4900`, `EURKnown`; a cancelling account adds
- nothing to ARR and 1 to `Attention`; a past_due one adds to both; gbp
- with no rate → `EURKnown false`.
+ {eur:2400, usd:2800}`, `EUR 4900`, `EURKnown`, `AmountsKnown`; a
+ cancelling account adds nothing to ARR and 1 to `Attention`; a past_due
+ one adds to both; gbp with no rate → `EURKnown false`.
+ - `TestARROfUnknownAmount`: an active, paid subscription with `Annual
+ -1` beside a known eur 2400 → `Paying 2`, `EUR 2400`, `AmountsKnown
+ false`, `Unknown 1`, `Complete()` false; its snapshot stores
+ `amounts_known 0`.
- `TestBillingFactsQuery`: an account per group, a deleted account
(absent), apps counted, `FirstPaid` the earliest subscription payment.
- - `TestRebuildARR`: one 2400 eur first payment on 7 Oct, a refunded 1000
- usd payment → the 1 Nov point is `{eur:2400}`, `Paying 1`; the 1 Sep
- point is empty.
- - `TestSnapshotPassOncePerDay`: two passes on one day → one row; the
- next day → a second row; first ever pass with old payments → rebuilt
- month rows plus today's.
-- [ ] **Step 2: Run** `go test ./internal/console -run 'TestPayingNow|TestBillingGroupOf|TestARROf|TestBillingFactsQuery|TestRebuildARR|TestSnapshotPass' -count=1` → FAIL.
+ - `TestSnapshotTodayReplaceable`: a pass with `reconciled false` then
+ one with `reconciled true` on the same day → one ARR row,
+ `payments_current 1`, the second pass's figures; an account that
+ stopped paying between them has no row for today.
+ - `TestSnapshotEarlierDaysFrozen`: `PutDailySnapshot` for yesterday →
+ error, yesterday's rows unchanged; the next day's pass adds a second
+ day and leaves the first alone.
+ - `TestSnapshotStartsAtFirstPass`: old payments, no snapshot → the first
+ pass writes today only; `FirstSnapshotDay` is today.
+ - `TestSnapshotIncompleteFlags`: no rate for a gbp account, an unknown
+ amount and `reconciled false` → each flag stored false and read back.
+- [ ] **Step 2: Run** `go test ./internal/console -run 'TestPayingNow|TestBillingGroupOf|TestARROf|TestBillingFactsQuery|TestSnapshot' -count=1` → FAIL.
- [ ] **Step 3: Implement** and wire `billingSnapshotPass` into `billingMoneyPass` (after rates).
- [ ] **Step 4: Run** the same → PASS.
- [ ] **Step 5: Commit** `console: paying accounts, groups, ARR and its daily snapshot`.
@@ -637,7 +711,8 @@ and §5; Plan 3 (written separately) covers §4.5.
- `billing_cli_copy.go`: the usage line with the two new verbs; flag help
for `-month` and `-kind`; the revenue lines (ARR with the per-currency
note and the rate date, MRR, paying of all accounts, needs attention,
- one line of group counts, the test-mode line, "no rate yet"); the
+ one line of group counts, the test-mode line, "no rate yet", the line
+ saying ARR leaves out %d accounts whose yearly amount is unknown); the
payments head and its empty line; "unmatched"; the kind words; the bad
`-month` and bad `-kind` refusals.
- `internal/console` door refusals for a bad month or kind (JSON errors).
@@ -677,13 +752,14 @@ and §5; Plan 3 (written separately) covers §4.5.
- Consumes: Task 4 `Payments`, Task 7 `billingRevenueNow`, Task 8 copy.
- Produces:
- `GET /api/cli/billing/revenue` (`billingDoor`): `{"arr":{"eur":2400},
- "arr_eur":2400,"eur_known":true,"rate_day":"2026-11-06","mrr_eur":200,
- "paying":1,"accounts":38,"attention":0,"groups":{"paying":1,...},
- "test_mode":false}`; amounts in minor units; `mrr_eur` is `arr_eur / 12`
- rounded.
+ "arr_eur":2400,"eur_known":true,"amounts_known":true,"unknown_amounts":0,
+ "rate_day":"2026-11-06","mrr_eur":200,"paying":1,"accounts":38,
+ "attention":0,"groups":{"paying":1,...},"test_mode":false}`; amounts in
+ minor units; `mrr_eur` is `arr_eur / 12` rounded. The CLI prints the
+ unknown-amounts line whenever `amounts_known` is false.
- `GET /api/cli/billing/payments?month=YYYY-MM&kind=K` (`billingDoor`;
- `kind` as `paymentFilter.Kind`, limit 500): an array of `{"id","at",
- "account","kind","reason","detail","amount","tax","currency","settled",
+ `kind` as `paymentFilter.Kind`, limit 500): an array of `{"movement",
+ "source","at","account","kind","reason","detail","amount","tax","currency","settled",
"fee","settled_currency"}`, newest first; `account` the sqid, "" when
unmatched or deleted. A bad month or kind is 400 with the approved text.
- `carlos billing revenue` and `carlos billing payments [-month YYYY-MM]
@@ -696,13 +772,14 @@ and §5; Plan 3 (written separately) covers §4.5.
- [ ] **Step 1: Write the failing tests**
- `TestAPIBillingRevenue`: billing world with one paying eur account and
- a stored rate → the JSON above; a member (not operator) → 404; billing
+ a stored rate → the JSON above; a second paying account with an
+ unknown amount → `amounts_known false`, `unknown_amounts 1`; a member (not operator) → 404; billing
off → 409 like `problems`.
- `TestAPIBillingPayments`: month and kind filters, unmatched shows `""`;
`month=2026-13` and `kind=x` → 400.
- `TestBillingRevenueCLI` and `TestBillingPaymentsCLI` (beside the
- `problems` CLI tests): output lines equal the approved copy; `-kind
- once-off` sends `once_off`.
+ `problems` CLI tests): output lines equal the approved copy, the
+ unknown-amounts line among them; `-kind once-off` sends `once_off`.
- `TestApprovedBillingDashboardCopy` (inventory and built rows).
- The `internal/docsite` gate over `docs/site/cli.md`.
- [ ] **Step 2: Run** `go test . ./internal/console ./internal/docsite -run 'TestAPIBilling|TestBilling.*CLI|TestApprovedBillingDashboardCopy|TestClaimConsoleMutationInvariant|Docsite' -count=1` → FAIL.
diff --git a/docs/superpowers/plans/2026-11-09-billing-dashboard-2-pages.md b/docs/superpowers/plans/2026-11-09-billing-dashboard-2-pages.md
index 483d94f55..ba0c8f366 100644
--- a/docs/superpowers/plans/2026-11-09-billing-dashboard-2-pages.md
+++ b/docs/superpowers/plans/2026-11-09-billing-dashboard-2-pages.md
@@ -24,8 +24,10 @@ deployment bucket (Economics bills).
(approved 2026-11-09): §4.1, §4.5 (display side), §4.6, §5. Final mockup:
the brainstorm's `billing-v4` (banner removed; whole rows clickable).
**Depends on** Plan 1 (`2026-11-09-billing-dashboard-1-data.md`) and Plan 3
-slice A (`2026-11-09-billing-dashboard-3-carlos-only-cost.md`, Tasks 1-4)
-merged (AGENTS.md stopping rule 4).
+slice A (`2026-11-09-billing-dashboard-3-carlos-only-cost.md`: the
+account-only setting, the basis on bills and the `carlosPlatformCostUSD`
+seam) merged (AGENTS.md stopping rule 4). Nothing here uses Plan 3's slice
+B (tag mode, the untagged inventory, copy C5), which is deferred.
## Global Constraints
@@ -47,8 +49,17 @@ merged (AGENTS.md stopping rule 4).
§4.5), always with its `Label`. Otherwise the platform cost, profit,
cash after costs and "Shared and idle" are hidden and its `Hint` shows
in their place.
-- **Revenue is before tax** everywhere; tax collected is its own column of
- the money table and never counted as revenue or profit.
+- **Revenue is before tax** everywhere, in both directions: every row
+ counts `Settled − SettledTax`, refunds and reversals included, so a fully
+ refunded charge nets 0 before fees. Tax collected (net of refunded tax)
+ is its own column of the money table and never counted as revenue or
+ profit.
+- **Incomplete is never shown as complete.** A figure built from an
+ `arrTotals` or `arrSnapshot` that is not `Complete()`, from a month whose
+ `EURKnown` is false, or from earnings that are not known, carries the
+ approved incomplete or unknown text in place of (or beside, where the
+ record says) the number. Profit and cash after costs need complete
+ revenue as well as `Platform.OK`.
- **Lists show at most 5 rows** with a link to the full list; **every row is
clickable across its whole width** (`co-rowlink`, Task 4). Account rows
open `/fleet/activity?account=<sqid>` (the operator pages' account view,
@@ -82,12 +93,17 @@ merged (AGENTS.md stopping rule 4).
`billingRevenueNow(now) (billingRevenue, []billingFact, error)`;
`billingRevenue{arrTotals; Groups; Accounts; MonthStart; TestMode}`;
-`arrTotals{ByCurrency; EUR; EURKnown; RateDay; Paying; Attention}`;
+`arrTotals{ByCurrency; EUR; EURKnown; AmountsKnown; Unknown; RateDay;
+Paying; Attention}` and `Complete()`; `arrSnapshot` (with `EURKnown`,
+`AmountsKnown`, `Unknown`, `PaymentsCurrent`, `Complete()`);
+`accountDay`; `Store.AccountDays(fromDay, toDay)`; `Store.FirstSnapshotDay()`;
`billingFact` (fields as Plan 1 Task 7); `payingNow`, `billingGroupOf`,
`inARR`, `billingGroup` and `billingGroupOrder`; `Store.Payments(paymentFilter)`
and `paymentRow`; `billing.Payment`, `billing.PaymentKind` constants and
reasons; `Store.LatestEURRates()`, `eurRates.eurCents`;
`Store.ARRSnapshots(fromDay, toDay)`; `s.store.planExemptID`.
+`Payments` with `Kind ""` (the lists: no fee rows) and `Kind "all"` (the
+money sums: fee rows included); a row's key is `Movement`.
## The platform cost: one function over Plan 3's seam
@@ -118,8 +134,9 @@ type platformCost struct {
func (s *Server) platformCostEUR(ctx context.Context, month string, r eurRates) platformCost
```
-So Plan 2 is built after Plan 3's slice A (its Tasks 1-4) merges, as well as
-Plan 1. The basis lines and hints are Plan 3's approved copy; Plan 2's
+So Plan 2 is built after Plan 3's slice A merges, as well as Plan 1. With
+no basis set (no `CONSOLE_COST_ACCOUNT_CARLOS_ONLY`), `ok` is false and
+every cost figure is hidden behind the hint. The basis lines and hints are Plan 3's approved copy; Plan 2's
record does not repeat them.
## Review Focus
@@ -138,7 +155,10 @@ record does not repeat them.
4. **Nothing yet.** No payments, no paying accounts, no Economics data: the
page renders its empty states, percentages do not divide by zero, and
the six month rows show €0.00 (Task 4 `TestOverviewEmpty`).
-5. **Payments of a deleted or unknown account.** An unmatched row shows the
+5. **Earnings for a month before the history.** October, when the first
+ snapshot is 9 November, shows per-account earnings and margins as
+ unknown, never as today's MRR (Task 3 `TestAccountEarningsBeforeHistory`).
+6. **Payments of a deleted or unknown account.** An unmatched row shows the
approved Unmatched label and is not a link; a deleted account's row
shows the approved deleted label and is not a link (Task 6
`TestPaymentsUnmatchedAndDeleted`).
@@ -157,11 +177,16 @@ reviewer's):
- Rail label `Billing`; the three pages' subheads; the Accounts and
Payments page titles.
- Test-mode line; rate note (`at ECB rates of %s`); "no rate yet";
- estimate label; "unknown" (no Economics figure). The basis lines and the
+ estimate label; "unknown" (no Economics figure, or earnings before the
+ history); the incomplete note (`leaves out %d accounts whose yearly
+ amount is unknown`); "earnings start on %s" (the first snapshot day);
+ the partial-month note. The basis lines and the
hidden-cost hints are Plan 3's C1-C6, not rows here.
- Overview tiles: ARR (with `+%s this month` and the per-currency note),
MRR (`ARR ÷ 12`), Received this month (net, its note), Paying accounts
(`%s of %s (%s)` and its change), Needs attention (its note).
+- ARR over time: heading, axis words (first day, today), the
+ screen-reader caption and column heads, the note counting incomplete days.
- Paying accounts list: heading, link, column heads, statuses (Paid,
Cancels at renewal, Payment failing), the footnote, "paying since %s".
- Earned panel: heading per month (`%s so far, earned`), lines (Recurring
@@ -261,7 +286,7 @@ Every later task takes its strings from this record through
**Interfaces:**
- Consumes: Plan 1 `paymentRow`, `billingFact`, `eurRates`, `payingNow`,
- `billingGroupOf`; Plan 3 `carlosPlatformCostUSD`, `costBasisLabel`,
+ `billingGroupOf`, `arrTotals`, `arrSnapshot`, `accountDay`; Plan 3 `carlosPlatformCostUSD`, `costBasisLabel`,
`costBasisHint`, `s.cfg.CostScope`.
- Produces:
- `platformCost` and `platformCostEUR` exactly as above. Plan 3's `ok`
@@ -278,26 +303,42 @@ Every later task takes its strings from this record through
- `func moneyByMonth(rows []paymentRow, months []string, r eurRates, platform map[string]platformCost) []moneyMonth`
— per row, in euros from `Settled`/`SettledTax`/`Fee` and
`SettledCurrency`: subscription and once-off rows add `Settled −
- SettledTax` to their column; refunds and reversals to `Refunds`
- (signed); `SettledTax` of every row to `Tax`; `Fee` of every row plus
+ SettledTax` to their column; refunds and reversals add `Settled −
+ SettledTax` to `Refunds` (signed, so tax never leaks into revenue);
+ `SettledTax` of every row to `Tax` (refund tax negative); `Fee` of every row plus
`−Settled` of fee rows to `Fees`; `Net = Subscriptions + OnceOff +
- Refunds − Fees`. `CashShown` only with `Platform.OK`;
+ Refunds − Fees`. `CashShown` only with `Platform.OK` and `EURKnown`;
`Cash = Net − Platform.Cents`. A row whose currency has no rate makes
`EURKnown` false.
- `type earnedView struct { Month string; MRR, OnceOff, Refunds int64;
Platform platformCost; Profit int64; ProfitShown bool }`.
- - `func earnedSoFar(arrEUR int64, m moneyMonth, now time.Time) earnedView`
- — `MRR = round(arrEUR / 12 × day-of-month / days-in-month)`;
- `Profit = MRR + OnceOff + Refunds − Platform.Cents`, shown only with
- `Platform.OK`.
+ - `func earnedSoFar(arr arrTotals, m moneyMonth, now time.Time) earnedView`
+ — `MRR = round(arr.EUR / 12 × day-of-month / days-in-month)`, marked
+ incomplete unless `arr.Complete()`; `Profit = MRR + OnceOff + Refunds −
+ Platform.Cents`, shown only with `Platform.OK && arr.Complete() &&
+ m.EURKnown`.
+ - `type monthEarning struct { Recurring int64 /* euro cents */; Known,
+ Partial bool }`
+ - `func accountEarnings(month string, days []accountDay, snaps []arrSnapshot, firstDay string) (by map[int64]monthEarning, covered bool)`
+ — pure. `covered` is false when `firstDay` is `""` or after the
+ month's last day: every account's earnings are unknown. Otherwise, for
+ each day of the month on or after `firstDay`, the rows of that day's
+ snapshot (or, for a day with none, of the latest earlier snapshot day)
+ add `AnnualEUR / 365` (summed exactly, rounded once at the end) to each
+ `Paying` account's `Recurring`; a used row with `!EURKnown` or `Annual
+ == -1` makes that account `Known false`; days before `firstDay` make
+ every account `Partial`. An account with no rows in a covered month
+ earned 0 recurring (`Known true`).
- `type accountMoney struct { Fact billingFact; Group billingGroup;
Earns, Costs, Margin int64 /* euro cents, the month */; CostKnown,
EURKnown bool; NearUsed, NearLimit int64; NearCap capID }`.
- - `func accountMoneyRows(facts []billingFact, exemptID int64, monthRows []paymentRow, costUSD map[string]float64, near map[int64]capState, r eurRates) []accountMoney`
- — per account: `Group` by `billingGroupOf`; `Earns` = (`Annual / 12`
- in euros when `payingNow` and `Annual > 0`, cancelling accounts
- included: they paid for this year) plus that month's once-off less
- refunds, before tax; `Costs` = `costUSD[sqid]` in euros (`CostKnown`
+ - `accountMoney` gains `EarnsKnown, EarnsPartial bool`.
+ - `func accountMoneyRows(facts []billingFact, exemptID int64, earned map[int64]monthEarning, covered bool, monthRows []paymentRow, costUSD map[string]float64, near map[int64]capState, r eurRates) []accountMoney`
+ — per account: `Group` by `billingGroupOf` (today's group); `Earns` =
+ its `earned[id].Recurring` plus that month's once-off less refunds,
+ each `Settled − SettledTax`; `EarnsKnown` = `covered` and the
+ account's `Known` and every once-off row converted; `EarnsPartial`
+ from `Partial`; `Margin` unknown whenever `Earns` or `Costs` is; `Costs` = `costUSD[sqid]` in euros (`CostKnown`
false when `costUSD` is nil; an account absent from a non-nil map
costs 0); `Margin = Earns − Costs`; `NearCap`, `NearUsed`, `NearLimit`
from `near` (zero when absent). `monthRows` is the last complete
@@ -312,17 +353,33 @@ Every later task takes its strings from this record through
exact columns; an empty month → zeros; `CashShown` false with a
platform cost that is not `OK`, true with one that is.
- `TestEarnedSoFar`: ARR 2400 on 9 Nov → MRR `round(200 × 9 / 30) = 60`;
- `TestEarnedHiddenWithoutBasis`.
- - `TestAccountMoneyRows`: paying eur 2400 with an October once-off 1000
- and cost 1.10 usd at 1.10 → `Earns 1200`, `Costs 100`, `Margin 1100`;
- a cancelling paying account still earns its MRR; a free account earns
- 0; `costUSD` nil → `CostKnown false`; a `near` row fills `NearCap`.
+ `TestEarnedHiddenWithoutBasis`; `TestEarnedHiddenWithPartialRates`
+ (rates hold usd but not gbp, a gbp paying account: `arr.EURKnown`
+ false → profit hidden though `Platform.OK`; a month holding a gbp
+ payment → `EURKnown` false, cash hidden).
+ - `TestMoneyByMonthRefundTaxExclusive`: a 12000 eur charge with 2000 tax,
+ fully refunded with refund tax -2000 → `OnceOff 10000`, `Refunds
+ -10000`, `Tax 0`, `Net` = −fees.
+ - `TestAccountEarningsNovemberSignup`: October fully covered by
+ snapshots without account A, A first paid 7 Nov → A's October
+ recurring 0, `Known`.
+ - `TestAccountEarningsNovemberTermination`: October snapshots carry B
+ paying eur 3650 every day, B ended on 3 Nov (today's fact not paying)
+ → B's October recurring `31 × 3650 / 365 = 310`.
+ - `TestAccountEarningsBeforeHistory`: first snapshot 9 Nov → October not
+ `covered`; November partial; a day missing in a covered month carries
+ the previous day forward.
+ - `TestAccountMoneyRows`: October recurring 200 from `earned`, an
+ October once-off 1000 (tax 0) and cost 1.10 usd at 1.10 → `Earns
+ 1200`, `Costs 100`, `Margin 1100`; not `covered` → `EarnsKnown false`
+ and margin unknown; `costUSD` nil → `CostKnown false`; a `near` row
+ fills `NearCap`.
- `TestPlatformCostEUR` (bills seeded as Plan 3's tests seed them): a
110 usd bill under `CostScope{AccountCarlosOnly: true}` at usd 1.10 →
`OK`, `Cents 10000`, `Label` C2; the zero scope → not `OK`, `Hint` C4;
no bill → not `OK`, `Hint` C6; no usd rate → not `OK`, `Hint` "no rate
yet".
-- [ ] **Step 2: Run** `go test ./internal/console -run 'TestEURText|TestMinorText|TestMoneyByMonth|TestEarned|TestAccountMoneyRows|TestPlatformCostEUR' -count=1` → FAIL.
+- [ ] **Step 2: Run** `go test ./internal/console -run 'TestEURText|TestMinorText|TestMoneyByMonth|TestEarned|TestAccountEarnings|TestAccountMoneyRows|TestPlatformCostEUR' -count=1` → FAIL.
- [ ] **Step 3: Implement.**
- [ ] **Step 4: Run** the same → PASS.
- [ ] **Step 5: Commit** `console: billing page money, and the platform cost seam`.
@@ -351,7 +408,10 @@ Every later task takes its strings from this record through
- `type opBillingInput struct { Now time.Time; Rev billingRevenue; Facts
[]billingFact; ExemptID int64; Rates eurRates; Months []moneyMonth /*
6, newest first */; LastMonth string; LastRows []paymentRow /* last
- complete month */; Recent []paymentRow /* 5 */; CostUSD
+ complete month, Kind "" */; MonthsRows []paymentRow /* the six
+ months, Kind "all": fee rows included */; Snaps []arrSnapshot /* the
+ last 90 days */; Earned map[int64]monthEarning; Covered bool; FirstDay
+ string; Recent []paymentRow /* 5 */; CostUSD
map[string]float64; Platform map[string]platformCost; Funnel [3]int;
Near map[int64]capState }`
- Row types the later tasks reuse: `type opBillingAccountRow struct {
@@ -365,11 +425,20 @@ Every later task takes its strings from this record through
"no rate yet").
- `func buildOpBillingView(in opBillingInput) *opBillingView` (pure) and
`opBillingView`'s sections, in the mockup's order (spec §5.2):
- 1. `Tiles []opStat`: ARR (EUR; delta = now − `MonthStart.EUR`; note =
- each currency in `ByCurrency`, `minorText`, joined, plus the rate
- note), MRR (`EUR / 12`), Received this month (`Months[0].Net`),
+ 1. `Tiles []opStat`: ARR (EUR; delta = now − `MonthStart.EUR`, shown
+ only when both are `Complete()`; note = each currency in
+ `ByCurrency`, `minorText`, joined, plus the rate note, plus the
+ incomplete note when `!Complete()`), MRR (`EUR / 12`, the same
+ incomplete marking), Received this month (`Months[0].Net`),
Paying accounts (`Paying of Accounts (pct)`, change vs
`MonthStart.Paying`), Needs attention (`Attention`).
+ 1a. **ARR over time** (new section, directly under the tiles and
+ above Paying accounts; nothing moves or goes): `ARRBars
+ []dashBar` from `Snaps`, one bar per snapshot day, `N` the euro ARR,
+ scaled as `dashBars` scales; the `co-bars` markup and screen-reader
+ table of the Dashboard's new-people chart, with an "incomplete"
+ column; a note counting the days that are not `Complete()`. With no
+ snapshot yet, `op_empty` with the approved line.
2. `Paying []opBillingAccountRow`: the 5 most recent `FirstPaid` among
paying accounts, with plan, packs and seats, earns, costs
(estimate), margin, renews (`PeriodEnd`), status (Payment failing
@@ -390,7 +459,12 @@ Every later task takes its strings from this record through
8. `NearLimits`: Free accounts in `Near`, highest ratio first, 5, with
the cap's label (`billingCopy["usage.label.*"]` as
`billingusage.go:193` maps them) and `capAmount` for used and limit.
- - `handleOpBilling` gathers the inputs (`LoadEconomics` failure → logged,
+ - `handleOpBilling` gathers the inputs: `Payments(paymentFilter{From:
+ six months back, To: now, Kind: "all"})` for the money table and the
+ current month, `Payments(paymentFilter{From, To: last month, Kind:
+ ""})` for per-account once-off, `ARRSnapshots` for 90 days,
+ `AccountDays` and `FirstSnapshotDay` for `accountEarnings` over the
+ last complete month, `LoadEconomics(ctx, "last")` (failure → logged,
`CostUSD` nil, costs show "unknown"); renders `ops_billing`.
- `static/ops.css`: `[co-rowlink]` rows are `position: relative` with a
hover tint, and their first `a.rst-nm::after` covers the row
@@ -407,6 +481,14 @@ Every later task takes its strings from this record through
- `TestOverviewHidesCostWithoutBasis`: a whole-account bill under the zero scope → no AWS bill line,
no profit, no cash column values, no Shared and idle, Plan 3's C4
hint present.
+ - `TestOverviewMoneyIncludesFeeRows` (handler to store): a stored fee
+ row of −45 eur and nothing else in the month → the month's Stripe fees
+ cell is €0.45 and Net −€0.45.
+ - `TestOverviewARRChart`: three snapshot days, the middle one with
+ `amounts_known 0` → three bars, the note counts one incomplete day; no
+ snapshots → the empty line.
+ - `TestOverviewUnknownAmount`: a paying account with `Annual -1` → the
+ ARR and MRR tiles carry the incomplete note; the delta is not shown.
- `TestOverviewNoRate`: no rates → converted tiles show "no rate yet";
the per-currency note is present.
- `TestOverviewEmpty`: no payments, no paying accounts, no Economics →
@@ -430,7 +512,8 @@ Every later task takes its strings from this record through
- Test: `internal/console/opbilling_test.go`
**Interfaces:**
-- Consumes: Task 3 `accountMoneyRows`, Task 4 `NearestCaps`.
+- Consumes: Task 3 `accountEarnings` and `accountMoneyRows` (for the last
+ complete month, as on the overview), Task 4 `NearestCaps`.
- Produces:
- Query `tab` (a `billingGroup`, default `paying`), `sort` (`earns`,
`costs`, `margin`, `joined`, `limit`; default `costs`), `page` (1-based).
@@ -439,8 +522,8 @@ Every later task takes its strings from this record through
Prev, Next string; TestMode bool; RateNote string; MonthName string }`
- `func buildOpBillingAccounts(rows []accountMoney, group billingGroup, sort string, page int, q url.Values) opBillingAccountsView`
— 50 per page; sorts descending except `joined` (newest first) and
- `limit` (highest ratio first, accounts with no cap row last); ties by
- account id. Columns: account, plan, apps, earns, costs (estimate),
+ `limit` (highest ratio first, accounts with no cap row last); unknown
+ earns, costs or margins sort last; ties by account id. Columns: account, plan, apps, earns, costs (estimate),
margin, joined. An unknown `tab` or `sort` falls back to the default.
- [ ] **Step 1: Write the failing tests**: `TestBillingAccountsTabsAndCounts`,
@@ -470,7 +553,8 @@ Every later task takes its strings from this record through
Rows []opBillingPaymentRow; Prev, Next string; Total int; TestMode
bool; RateNote string }`; a row: when, account (link unless unmatched or
deleted), what, charged (`minorText(Amount, Currency)`), net in euros
- (`Settled − SettledTax − Fee`), fee, status.
+ (`Settled − SettledTax − Fee`, refunds and reversals alike), fee,
+ status. Reads `Payments` with `Kind ""` (no fee rows).
- 50 per page, newest first.
- [ ] **Step 1: Write the failing tests**: `TestBillingPaymentsFilters`
@@ -494,7 +578,7 @@ Every later task takes its strings from this record through
- Consumes: Plan 1 `billingRevenueNow`.
- Produces: `func billingDashStat(rev billingRevenue) opStat` — label
Paying accounts, value the paying count, note the ARR in euros `a year`
- (or "no rate yet"), the test-mode word when `TestMode`, `Href:
+ (or "no rate yet"; with the incomplete marking unless `Complete()`), the test-mode word when `TestMode`, `Href:
"/fleet/billing"`. `handleDashboard` appends it to `d.Stats` only when
`s.billing != nil`; a `billingRevenueNow` error is logged and the tile
left out.
diff --git a/docs/superpowers/specs/2026-11-09-billing-dashboard-design.md b/docs/superpowers/specs/2026-11-09-billing-dashboard-design.md
index a2354c64f..5d5e0927c 100644
--- a/docs/superpowers/specs/2026-11-09-billing-dashboard-design.md
+++ b/docs/superpowers/specs/2026-11-09-billing-dashboard-design.md
@@ -128,9 +128,7 @@ euro total).
- **MRR** = ARR ÷ 12.
- **ARR history.** A daily snapshot (date, ARR per currency, ARR in
euros, paying-account count) is written once a day, so ARR over time and
- "+€X this month" can be shown. History starts on the day this ships;
- older months are rebuilt where the recorded payments allow, otherwise
- the chart starts at the first snapshot.
+ "+€X this month" can be shown. History starts on the day this ships.
### 4.3 Money received