The Tier 1+2+3 work tagged everything with client_id. This release makes those tags pay off in two places: a margin entry form on the deal detail page and a per-client P&L dashboard.
Margin entry on deals (`PATCH /marketplace/deals/{id}/margin`)
Agency-tagged deals now expose a "Margin tracking" panel on the deal detail page showing client_charge_amount (what the agency invoices the client) and creator_payout_amount (what the agency pays the creator). Margin and margin % are computed read-only.
- Visible only to the buyer (agency) on the deal, plus SA. Non-agency deals don't show the panel at all.
- Editable until the deal reaches COMPLETED. Locked once completed to keep historical reports consistent.
- New endpoint
PATCH /marketplace/deals/{id}/marginaccepts{client_charge_amount, creator_payout_amount}. Either field can be omitted to leave that side untouched. Validates ownership and that the deal carries aclient_id.
Client Insights dashboard (`GET /agency/dashboard`)
New page /agency/insights (sidebar entry "Client Insights" under AGENCY mode) showing:
- Top strip — totals across all attributed clients: active client count, bids placed, deals active/completed, margin (₹), margin %.
- Per-client cards — one row per client. Each shows: bids total / won / win rate, deals active / completed, spend, revenue, margin (₹ and %), audience count, campaign count, last activity timestamp.
- Quick links — each card has shortcuts to that client's bids, deals, and campaigns (pre-filtered URLs).
- Unattributed bucket — a separate dashed card for agency-shared work (where
client_id IS NULL).
Backend endpoint GET /agency/dashboard aggregates per-client across marketplace_bids, marketplace_deals, all 4 audience tables, and campaigns. SA can pass ?agency_id=<uuid> to view any agency. AGENCY_ADMIN sees their own tenant only.
Why this slice
Without margin entry the client_charge_amount / creator_payout_amount columns shipped yesterday were inert. Without the dashboard the agency had to bounce across 4 filtered views to assemble what should be one page. Together these turn Tier 1+2+3 from "labels everywhere" into "control tower."
Known limits (intentional)
- Margin entry assumes a single charge / payout per deal. Per-line-item margins on multi-component package deals are not yet split.
- The dashboard is tenant-aggregated by
client_id. Sub-employee scoping (which team member runs which client) is not yet wired. - No date-range filter yet — the dashboard always shows lifetime totals. Date filter is the natural next step.
- No CSV export from the dashboard.
---

