{{define "content"}}{{with .Data}}{{$d := .}}

Customers and the CRM

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.

{{if not .CRMCount}}

No CRM Accounts copied yet, so nothing can be matched. Hermes copies them once the CRM bridge works (see CRM queue); until then you can say which customers aren't in the CRM, or queue them to be added.

{{else}}

{{num .CRMCount}} Accounts copied from the CRM{{if not .Synced.IsZero}} {{ago .Synced}}{{end}}.

{{end}} {{$s := .Summary}}
Customers{{num .Total}}
By stored ID{{or (index $s "stored ID") 0}}
By email{{or (index $s "email") 0}}
By domain{{or (index $s "domain") 0}}
By you{{or (index $s "by you") 0}}
To choose{{or (index $s "several") 0}}
No match{{or (index $s "") 0}}
Not in the CRM{{or (index $s "not in the CRM") 0}}

Download every customer as CSV

{{range .Accounts}}{{end}} {{if .Matches}}
{{range .Matches}}{{end}}
CustomerMRR nowAccount
{{or .Customer.Name .Customer.Email .Customer.ID}}{{if and .Customer.Name .Customer.Email}}
{{.Customer.Email}}{{end}}{{if .Prospect}}
a prospect{{end}}
{{if .MRR}}{{usd .MRR}}{{else}}ยท{{end}} {{if .Account.ID}}{{.Account.Name}} {{.How}} {{else if eq .How "several"}}Several fit: {{range $i, $a := .Candidates}}{{if $i}}, {{end}}{{$a.Name}}{{end}} {{else if eq .How "not in the CRM"}}not in the CRM {{else}}no match{{if index $d.Queued .Customer.ID}} queued for the CRM{{end}}{{end}}
{{if $d.Accounts}}{{end}} {{if or .Account.ID (eq .How "not in the CRM")}}{{if or (eq .How "by you") (eq .How "not in the CRM")}}{{end}} {{else}} {{if and .MRR (not (index $d.Queued .Customer.ID))}}{{end}}{{end}}
{{else}}

{{if eq .Show ""}}Nothing to fix.{{else}}No customers.{{end}}

{{end}} {{end}}{{end}}