Hub 2.0 step 6: AI cap and markup per church

The cap and markup move from the licence to the customer (migrated), use
is counted over all the church's installs under one lock per church, and
the licence token carries the church's cap. Settings → AI shows product.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 08:55:43 +02:00
co-authored by Claude Opus 5.5
parent 6e51780103
commit 59e6b9f03c
11 changed files with 138 additions and 72 deletions
+3 -2
View File
@@ -8,6 +8,7 @@ import { matches, usePaged } from "@/lib/paging";
import type { AiInstallUse } from "@/lib/types";
import { Loading, Message, PageTitle, Pager, SearchInput, Tabs } from "@/components/ui";
import { BillingSettings } from "@/components/billing/BillingSettings";
import { PRODUCT_NAMES } from "@/lib/products";
type Settings = Record<string, string>;
type AuditRow = { id: string; action: string; target: string | null; metadata: unknown; createdAt: string; actor: { name: string } | null };
@@ -145,11 +146,11 @@ function AiTab({ settings, models, onSaved, setMsg }: { settings: Settings; mode
{!usage ? <Loading /> : usage.installs.length === 0 ? <p className="px-5 pb-5 text-sm text-slate-500">No AI use in {usage.month}.</p> : (
<div className="overflow-x-auto px-5 pb-5">
<table className="w-full text-sm">
<thead><tr className="text-left text-xs text-slate-500"><th className="py-1">Site</th><th>Cap</th><th>Uses</th><th className="text-right">Real cost</th><th className="text-right">Charged</th><th className="text-right">Profit</th></tr></thead>
<thead><tr className="text-left text-xs text-slate-500"><th className="py-1">Site</th><th>Church cap</th><th>Uses</th><th className="text-right">Real cost</th><th className="text-right">Charged</th><th className="text-right">Profit</th></tr></thead>
<tbody>
{usage.installs.map(i => (
<tr key={i.installId} className="border-t border-slate-100">
<td className="py-1"><Link href={`/installs/${i.installId}`} className="text-indigo-700 hover:underline">{i.name}</Link></td>
<td className="py-1"><Link href={`/installs/${i.installId}`} className="text-indigo-700 hover:underline">{i.customer?.name || i.name}</Link> <span className="text-xs text-slate-500">{PRODUCT_NAMES[i.product]}</span></td>
<td>{i.capCents ? rand(i.capCents) : "off"}</td>
<td>{i.calls}</td>
<td className="text-right">{randFine(i.realCents)}</td>