diff --git a/internal/metrics/mrr.go b/internal/metrics/mrr.go index 6dc4c5b..41068a3 100644 --- a/internal/metrics/mrr.go +++ b/internal/metrics/mrr.go @@ -46,11 +46,11 @@ func (l line) monthly() float64 { return float64(l.amount) / months } -// loadLines reads the recurring lines of billed invoices (paid or open; not -// void, not uncollectible) in the main currency. +// loadLines reads the recurring lines of paid invoices (not open, void or +// uncollectible) in the main currency. func loadLines(d *db.DB, currency string) ([]line, error) { rows, err := d.Query(`SELECT customer, amount, period_start, period_end, interval, interval_count, proration, product - FROM stripe_invoice_lines WHERE recurring = 1 AND status IN ('paid', 'open') AND currency = ? AND customer != '' + FROM stripe_invoice_lines WHERE recurring = 1 AND status = 'paid' AND currency = ? AND customer != '' AND period_end > period_start ORDER BY invoice, id`, currency) // a fixed order: float sums come out the same everywhere if err != nil { return nil, err diff --git a/internal/metrics/mrr_test.go b/internal/metrics/mrr_test.go index 5c5e6d1..09b50f2 100644 --- a/internal/metrics/mrr_test.go +++ b/internal/metrics/mrr_test.go @@ -67,8 +67,10 @@ func TestBuild(t *testing.T) { ln{cust: "cus_a", from: "2026-04-25", to: "2026-05-10", amount: -2500, proration: true}, ln{cust: "cus_a", from: "2026-04-25", to: "2026-05-10", amount: 4000, proration: true}) d.Exec(`UPDATE stripe_invoice_lines SET amount = 8000 WHERE customer = 'cus_a' AND period_start >= ?`, day("2026-05-10")) - // A trial, a void invoice and an uncollectible one count for nothing. + // A trial, an unpaid (open) invoice, a void one and an uncollectible + // one count for nothing. addLines(t, d, ln{cust: "cus_t", from: "2026-03-01", to: "2026-04-01", interval: "month", amount: 0}, + ln{cust: "cus_o", from: "2026-03-01", to: "2026-04-01", interval: "month", amount: 9900, status: "open"}, ln{cust: "cus_v", from: "2026-03-01", to: "2026-04-01", interval: "month", amount: 9900, status: "void"}, ln{cust: "cus_u", from: "2026-03-01", to: "2026-04-01", interval: "month", amount: 9900, status: "uncollectible"}) diff --git a/internal/web/templates/metrics.html b/internal/web/templates/metrics.html index 768777e..9ead580 100644 --- a/internal/web/templates/metrics.html +++ b/internal/web/templates/metrics.html @@ -40,7 +40,7 @@ {{range .}}{{.Month}}: {{usd .MRR}}{{if .Label}}{{.Month}}{{end}}{{end}} {{end}} -

From the invoice lines of paid and open invoices, in {{$d.Model.Currency}}: each recurring line's amount after discounts, spread over its billing period. Trials ($0), one-off charges, void and uncollectible invoices don't count.{{with $d.Model.Start}}{{if ne . "all"}} Counted from {{.}}.{{end}}{{end}}

+

From the invoice lines of paid invoices (an unpaid one counts once it's paid), in {{$d.Model.Currency}}: each recurring line's amount after discounts, spread over its billing period. Trials ($0), one-off charges, void and uncollectible invoices don't count.{{with $d.Model.Start}}{{if ne . "all"}} Counted from {{.}}.{{end}}{{end}}

Month by month