Phase 4 part 3: Stripe customers matched to EspoCRM Accounts

Every customer with billing is matched to an Account copied from the
CRM: the user's choice, then an Account Hermes created from here, a
stored ID on either side, an email (the Account's or a Contact's), or
the email's domain (not free mail). Several candidates wait for a
choice. Metrics → Customers and the CRM fixes matches, marks customers
not in the CRM, and queues paying ones as new Accounts. Schema 20.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 12:22:05 -07:00
co-authored by Claude Opus 5.5
parent 5e799c7541
commit 6ba524295b
13 changed files with 675 additions and 2 deletions
+6
View File
@@ -50,6 +50,12 @@
<a href="/seo/engines" {{if eq $nav "seo/engines"}}aria-current="page"{{end}}>Search engines</a>
</div>
{{end}}
{{if eq .ID "metrics"}}
<div class="subnav">
<a href="/metrics" {{if eq $nav "metrics/overview"}}aria-current="page"{{end}}>MRR and NRR</a>
<a href="/metrics/customers" {{if eq $nav "metrics/customers"}}aria-current="page"{{end}}>Customers and the CRM</a>
</div>
{{end}}
{{if eq .ID "prospects"}}
<div class="subnav">
<a href="/signals" {{if eq $nav "prospects/signals"}}aria-current="page"{{end}}>Signals</a>
@@ -0,0 +1,51 @@
{{define "content"}}{{with .Data}}{{$d := .}}
<div class="heading"><h1>Customers and the CRM</h1></div>
<p class="lede">Each Stripe customer with billing, 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>
<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}}