Files
davidandClaude Opus 5.5 739f85fde1 Metrics: total spend from Stripe's charges, as Stripe counts it
Customers who paid without an invoice (one-off Checkout payments) were
missed, and the Stripe card counted every customer record, deleted ones
too. The sync now reads charges (and follows their events); a customer's
total spend is their successful charges, captured less refunded. A
database synced before reads everything once (sync state version 2).
Until charges are in, paid invoices less refunds stand in.

The Stripe card's Customers now counts those who spent more than $0, "of
N in Stripe", and a Payments count is added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 12:35:00 -07:00

53 lines
4.4 KiB
HTML

{{define "content"}}{{with .Data}}{{$d := .}}
<div class="heading"><h1>Customers and the CRM</h1></div>
<p class="lede">Each Stripe customer who has spent more than $0 (their payments, less refunds, as Stripe counts total spend; trials and unpaid invoices don't count), matched to its EspoCRM Account: first by a stored ID (a Stripe customer ID in the Account, or an EspoCRM ID in Stripe's metadata), then by email (the Account's, or one of its Contacts'), then by the email's domain (free mail like Gmail doesn't count). Fix what it gets wrong; your choice is kept. Pipeline influence and per-account numbers build on this.</p>
<section class="card">
{{if not .CRMCount}}
<p class="warn-text">No CRM Accounts copied yet, so nothing can be matched. Hermes copies them once the CRM bridge works (see <a href="/crm">CRM queue</a>); until then you can say which customers aren't in the CRM, or queue them to be added.</p>
{{else}}<p class="small muted">{{num .CRMCount}} Accounts copied from the CRM{{if not .Synced.IsZero}} {{ago .Synced}}{{end}}.</p>{{end}}
{{$s := .Summary}}
<div class="funnel">
<div class="step"><span class="label">Customers</span><strong>{{num .Total}}</strong></div>
<div class="step"><span class="label">By stored ID</span><strong>{{or (index $s "stored ID") 0}}</strong></div>
<div class="step"><span class="label">By email</span><strong>{{or (index $s "email") 0}}</strong></div>
<div class="step"><span class="label">By domain</span><strong>{{or (index $s "domain") 0}}</strong></div>
<div class="step"><span class="label">By you</span><strong>{{or (index $s "by you") 0}}</strong></div>
<div class="step"><span class="label">To choose</span><strong>{{or (index $s "several") 0}}</strong></div>
<div class="step"><span class="label">No match</span><strong>{{or (index $s "") 0}}</strong></div>
<div class="step"><span class="label">Not in the CRM</span><strong>{{or (index $s "not in the CRM") 0}}</strong></div>
</div>
</section>
<p class="small"><a href="/metrics/export/customers.csv">Download every customer as CSV</a></p>
<nav class="tabs">
<a href="/metrics/customers" {{if eq .Show ""}}aria-current="page"{{end}}>To fix</a>
<a href="/metrics/customers?show=paying" {{if eq .Show "paying"}}aria-current="page"{{end}}>Paying now</a>
<a href="/metrics/customers?show=all" {{if eq .Show "all"}}aria-current="page"{{end}}>All</a>
</nav>
<datalist id="accounts">{{range .Accounts}}<option value="{{.Name}}">{{.Domain}}</option>{{end}}</datalist>
{{if .Matches}}
<div class="table-wrap"><table class="list compact">
<thead><tr><th>Customer</th><th class="num">MRR now</th><th>Account</th><th></th></tr></thead>
<tbody>{{range .Matches}}<tr>
<td>{{or .Customer.Name .Customer.Email .Customer.ID}}{{if and .Customer.Name .Customer.Email}}<br><span class="muted small">{{.Customer.Email}}</span>{{end}}{{if .Prospect}}<br><span class="badge">a prospect</span>{{end}}</td>
<td class="num">{{if .MRR}}{{usd .MRR}}{{else}}<span class="muted">·</span>{{end}}</td>
<td>{{if .Account.ID}}{{.Account.Name}} <span class="muted small">{{.How}}</span>
{{else if eq .How "several"}}<span class="warn-text small">Several fit:</span> {{range $i, $a := .Candidates}}{{if $i}}, {{end}}{{$a.Name}}{{end}}
{{else if eq .How "not in the CRM"}}<span class="muted">not in the CRM</span>
{{else}}<span class="muted">no match</span>{{if index $d.Queued .Customer.ID}} <span class="badge draft">queued for the CRM</span>{{end}}{{end}}</td>
<td>
<form method="post" action="/metrics/customers/{{.Customer.ID}}" class="row wrap">
<input type="hidden" name="show" value="{{$d.Show}}">
{{if $d.Accounts}}<input name="account" list="accounts" placeholder="an Account" size="16"><button type="submit" name="do" value="account" class="secondary small">Match</button>{{end}}
{{if or .Account.ID (eq .How "not in the CRM")}}{{if or (eq .How "by you") (eq .How "not in the CRM")}}<button type="submit" name="do" value="auto" class="link small">automatic</button>{{end}}
{{else}}<button type="submit" name="do" value="none" class="link small">not in the CRM</button>
{{if and .MRR (not (index $d.Queued .Customer.ID))}}<button type="submit" name="do" value="add" class="link small">add to the CRM</button>{{end}}{{end}}
</form>
</td>
</tr>{{end}}</tbody>
</table></div>
{{else}}<section class="card empty"><p>{{if eq .Show ""}}Nothing to fix.{{else}}No customers.{{end}}</p></section>{{end}}
{{end}}{{end}}