Metrics: MRR and cohorts count only paid invoices
Open (unpaid) invoices no longer count toward MRR, so they don't put a customer in a cohort either; an invoice counts once it's paid. This matches the customer count, which takes only those who have spent more than $0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -46,11 +46,11 @@ func (l line) monthly() float64 {
|
|||||||
return float64(l.amount) / months
|
return float64(l.amount) / months
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadLines reads the recurring lines of billed invoices (paid or open; not
|
// loadLines reads the recurring lines of paid invoices (not open, void or
|
||||||
// void, not uncollectible) in the main currency.
|
// uncollectible) in the main currency.
|
||||||
func loadLines(d *db.DB, currency string) ([]line, error) {
|
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
|
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
|
AND period_end > period_start ORDER BY invoice, id`, currency) // a fixed order: float sums come out the same everywhere
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -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: -2500, proration: true},
|
||||||
ln{cust: "cus_a", from: "2026-04-25", to: "2026-05-10", amount: 4000, 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"))
|
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},
|
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_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"})
|
ln{cust: "cus_u", from: "2026-03-01", to: "2026-04-01", interval: "month", amount: 9900, status: "uncollectible"})
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
{{range .}}<rect x="{{.X}}" y="{{.Y}}" width="{{.W}}" height="{{.H}}"><title>{{.Month}}: {{usd .MRR}}</title></rect>{{if .Label}}<text x="{{.X}}" y="166">{{.Month}}</text>{{end}}{{end}}
|
{{range .}}<rect x="{{.X}}" y="{{.Y}}" width="{{.W}}" height="{{.H}}"><title>{{.Month}}: {{usd .MRR}}</title></rect>{{if .Label}}<text x="{{.X}}" y="166">{{.Month}}</text>{{end}}{{end}}
|
||||||
</svg>
|
</svg>
|
||||||
{{end}}
|
{{end}}
|
||||||
<p class="small muted">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}}</p>
|
<p class="small muted">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}}</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<h2>Month by month</h2>
|
<h2>Month by month</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user