/* AAU CRM — Marketing Hub part 1: Overview (Command Center) + Data Sources */ function MarketingOverview() { const t = useTimeRange('30d'); const [dim, setDim] = useState('course'); const [metric, setMetric] = useState('spend'); const { total } = AAU.mktSummary('channel'); const b = AAU.mktBudget; const revenue = total.won * 14900000; const roas = revenue / total.spend; const pacePlan = Math.round(b.pacingDay / b.daysInMonth * 100); const paceReal = Math.round(b.spentMTD / b.monthlyBudget * 100); const kpis = [ { l: 'Tổng chi (Spend)', v: AAU.fmtVNDm(total.spend), d: 12, dd: 'up' }, { l: 'Σ Lead (org + ads)', v: total.leads, d: 18, dd: 'up', sub: total.leadsOrg + ' organic · ' + total.leadsAds + ' ads' }, { l: 'CPL trung bình', v: AAU.fmtVND(total.cplBlended), d: 9, dd: 'down', crm: true }, { l: 'Cost / Message', v: AAU.fmtVND(total.costMsg), d: 5, dd: 'down' }, { l: 'Doanh thu attributed', v: AAU.fmtVNDm(revenue), d: 15, dd: 'up', crm: true }, { l: 'ROAS', v: roas.toFixed(1) + '×', d: 7, dd: 'up', crm: true }, ]; const mt = AAU.mktTrend; const metricCfg = { spend: { data: mt.spend, color: '#0084ff', fmt: v => v.toFixed(1) + 'tr', label: 'Chi tiêu (triệu ₫)' }, leads: { data: mt.leads, color: '#7c3aed', fmt: v => Math.round(v), label: 'Lead' }, cpl: { data: mt.cpl, color: '#0a9e6e', fmt: v => v.toFixed(2) + 'tr', label: 'CPL (triệu ₫)' }, msgs: { data: mt.msgs, color: '#d97706', fmt: v => Math.round(v), label: 'Messages' }, }[metric]; const split = AAU.channelSplit; const donut = split.map(s => ({ l: AAU.mktChannelById(s.channel).label, v: s.leads, color: AAU.mktChannelById(s.channel).color })); return (
| Nguồn | Tài khoản | Trạng thái | Loại dữ liệu | Sync gần nhất | Bài | Lead | Chi 30N | |
|---|---|---|---|---|---|---|---|---|
| {c.account}{c.note && {c.note} } |
{c.kinds.map(k => {k})} |
{c.lastSync} | {c.posts || '—'} | {c.leads || '—'} | {c.spend ? AAU.fmtVNDm(c.spend) : '—'} | {c.status === 'not_connected' ? : |