Phase 4 part 1: the full Stripe sync, and margins per product
Customers, invoices with all their lines (both of Stripe's line shapes), credit notes, refunds (with their customer) and products: a backfill, then the Events API every hour, and a new backfill when events have expired. Metrics page with sync status. Gross margin per product: a default (60%) and overrides, with names from Stripe's products or the invoice lines. Schemas 18 and 19. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
{{define "content"}}{{with .Data}}
|
||||
<div class="heading">
|
||||
<h1>Metrics</h1>
|
||||
{{if .Stripe}}<div class="buttons">
|
||||
<form method="post" action="/metrics/sync" data-busy="Syncing…"><button type="submit" class="secondary">Sync now</button></form>
|
||||
</div>{{end}}
|
||||
</div>
|
||||
<p class="lede">MRR and its movements, NRR, CAC and CLV, computed from your Stripe data: every customer, invoice, credit note and refund. MRR comes from the invoice lines (what each customer was billed, for which period), so past months are exact. Supermarket only reads Stripe.</p>
|
||||
|
||||
<section class="card">
|
||||
<h2>Stripe</h2>
|
||||
{{if not .Stripe}}
|
||||
<p class="warn-text">Save a restricted Stripe key under <a href="/settings/tracking#stripe">Settings → Website & sales</a>. For the metrics it needs read access to Customers, Invoices, Credit notes, Charges and Refunds, and Events, on top of Checkout Sessions.</p>
|
||||
{{else}}
|
||||
{{with .Last}}
|
||||
<p class="small {{if .Error}}error-text{{else}}muted{{end}}">Synced {{ago .At}}{{if .Full}} (everything read){{else}} ({{.Events}} changes since the last sync){{end}}{{with .Error}}: {{.}}{{end}}.{{with .Currency}} Currencies: {{range $i, $c := .}}{{if $i}}, {{end}}{{$c}}{{end}}.{{end}}</p>
|
||||
{{else}}<p class="help">Not synced yet: the first sync reads all your Stripe history, which can take a few minutes.</p>{{end}}
|
||||
<div class="funnel">
|
||||
<div class="step"><span class="label">Customers</span><strong>{{num (or (index .Counts "customer") 0)}}</strong></div>
|
||||
<div class="step"><span class="label">Invoices</span><strong>{{num (or (index .Counts "invoice") 0)}}</strong></div>
|
||||
<div class="step"><span class="label">Credit notes</span><strong>{{num (or (index .Counts "credit_note") 0)}}</strong></div>
|
||||
<div class="step"><span class="label">Refunds</span><strong>{{num (or (index .Counts "refund") 0)}}</strong></div>
|
||||
</div>
|
||||
<form method="post" action="/metrics/sync" data-busy="Reading everything…" class="inline"><input type="hidden" name="full" value="1"><button type="submit" class="link small">Read everything again</button></form>
|
||||
{{with .Last}}{{range .Notes}}<p class="small muted">{{.}}</p>{{end}}{{end}}
|
||||
{{end}}
|
||||
</section>
|
||||
|
||||
{{if .Products}}{{$m := .Margins}}
|
||||
<form method="post" action="/metrics/margins" class="card" id="margins">
|
||||
<h2>Gross margin by product</h2>
|
||||
<p class="small">What you keep of each dollar a product brings in, after what it costs you to deliver (hosting, licences, support). CLV weighs each customer's revenue by the margin of what they buy. An empty box uses the default.</p>
|
||||
<label>Default <input name="default" value="{{$m.Default}}" inputmode="decimal" size="5"> %</label>
|
||||
<table class="list">
|
||||
<thead><tr><th>Product</th><th class="num">Billed, last 12 months</th><th class="num">Invoices</th><th class="num">Margin</th></tr></thead>
|
||||
<tbody>{{range .Products}}<tr>
|
||||
<td>{{.Name}}{{if and .ID (ne .Name .ID)}} <span class="muted small">{{.ID}}</span>{{end}}</td>
|
||||
<td class="num">{{money .Revenue}}</td><td class="num">{{num .Invoices}}</td>
|
||||
<td class="num">{{if .ID}}<input name="margin:{{.ID}}" value="{{if .Own}}{{.Margin}}{{end}}" placeholder="{{$m.Default}}" inputmode="decimal" size="5"> %{{else}}<span class="muted">default</span>{{end}}</td>
|
||||
</tr>{{end}}</tbody>
|
||||
</table>
|
||||
<div class="actions"><button type="submit">Save margins</button></div>
|
||||
</form>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
Reference in New Issue
Block a user