/
home
/
oxicore
/
public_html
/
Upload File
HOME
<!DOCTYPE html> <html lang="pt-PT"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Impacto SDR IA - Detalhe de Funil</title> <script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <script> tailwind.config = { theme: { extend: { colors: { ia: '#8B5CF6', humano: '#94A3B8', dark: '#0F172A', card: '#1E293B' } } } } </script> <style> body { background-color: #0F172A; color: #F8FAFC; font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; } .glass-panel { background: rgba(30, 41, 59, 0.7); backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 1rem; } .highlight-ia { background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, rgba(30, 41, 59, 0.8) 100%); border: 1px solid rgba(139, 92, 246, 0.4); box-shadow: 0 0 20px rgba(139, 92, 246, 0.1); } .tab-btn { transition: all 0.3s ease; } .tab-active { background-color: #8B5CF6; color: white; border-color: #8B5CF6; } .tab-inactive { background-color: transparent; color: #94A3B8; border-color: #334155; } .tab-inactive:hover { background-color: #1E293B; color: white; } /* Custom scrollbar para a tabela */ ::-webkit-scrollbar { width: 8px; height: 8px; } ::-webkit-scrollbar-track { background: #1E293B; border-radius: 4px; } ::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; } ::-webkit-scrollbar-thumb:hover { background: #64748B; } </style> </head> <body class="p-4 md:p-8 min-h-screen"> <div class="max-w-7xl mx-auto space-y-8"> <!-- Header --> <header class="text-center md:text-left flex flex-col md:flex-row justify-between items-center"> <div> <h1 class="text-3xl md:text-4xl font-extrabold tracking-tight mb-2"> <span class="text-transparent bg-clip-text bg-gradient-to-r from-purple-400 to-ia">Resultados de Vendas</span> <span class="text-slate-300">Pós-IA</span> </h1> <p class="text-slate-400 text-sm md:text-base">Análise baseada na data de fecho da venda (<i class="fa-regular fa-calendar text-ia"></i> Fechada em)</p> </div> <!-- Controlo de Filtro Mensal --> <div class="mt-4 md:mt-0 glass-panel px-6 py-3 flex items-center gap-4"> <i class="fa-solid fa-filter text-ia text-xl"></i> <div class="text-left flex flex-col w-full min-w-[200px]"> <label for="monthFilter" class="text-xs text-slate-400 uppercase tracking-wider font-semibold">Filtrar por Mês</label> <select id="monthFilter" class="bg-slate-800 text-white font-bold text-sm border border-slate-600 outline-none cursor-pointer rounded mt-1 p-1.5 hover:border-ia transition-colors"> <option value="all">Todos os Meses</option> <!-- As opções serão inseridas via JavaScript --> </select> </div> </div> </header> <!-- KPI Globais (IA, Humano e Total) --> <div class="grid grid-cols-1 md:grid-cols-3 gap-6"> <!-- Faturação Global --> <div class="glass-panel p-5 flex flex-col justify-between"> <h3 class="text-slate-400 text-xs font-bold uppercase tracking-wider mb-4"><i class="fa-solid fa-money-bill-wave mr-2"></i>Faturamento Total</h3> <div class="space-y-3"> <div class="flex justify-between items-end border-b border-slate-700/50 pb-2"> <span class="text-ia font-semibold text-sm">SDR IA</span> <span class="text-xl font-bold text-white" id="kpi-rev-ia">-</span> </div> <div class="flex justify-between items-end border-b border-slate-700/50 pb-2"> <span class="text-slate-400 text-sm">Humano/Outros</span> <span class="text-lg font-semibold text-slate-300" id="kpi-rev-hum">-</span> </div> <div class="flex justify-between items-end pt-1"> <span class="text-white font-bold text-sm">TOTAL</span> <span class="text-2xl font-extrabold text-emerald-400" id="kpi-rev-tot">-</span> </div> </div> </div> <!-- Vendas Qtd Global --> <div class="glass-panel p-5 flex flex-col justify-between"> <h3 class="text-slate-400 text-xs font-bold uppercase tracking-wider mb-4"><i class="fa-solid fa-handshake mr-2"></i>Volume de Vendas (Qtd)</h3> <div class="space-y-3"> <div class="flex justify-between items-end border-b border-slate-700/50 pb-2"> <span class="text-ia font-semibold text-sm">SDR IA</span> <span class="text-xl font-bold text-white" id="kpi-vol-ia">-</span> </div> <div class="flex justify-between items-end border-b border-slate-700/50 pb-2"> <span class="text-slate-400 text-sm">Humano/Outros</span> <span class="text-lg font-semibold text-slate-300" id="kpi-vol-hum">-</span> </div> <div class="flex justify-between items-end pt-1"> <span class="text-white font-bold text-sm">TOTAL</span> <span class="text-2xl font-extrabold text-emerald-400" id="kpi-vol-tot">-</span> </div> </div> </div> <!-- Ticket Médio Global --> <div class="glass-panel highlight-ia p-5 flex flex-col justify-between"> <h3 class="text-ia text-xs font-bold uppercase tracking-wider mb-4"><i class="fa-solid fa-gem mr-2"></i>Ticket Médio</h3> <div class="space-y-3"> <div class="flex justify-between items-end border-b border-ia/30 pb-2"> <span class="text-ia font-semibold text-sm">SDR IA</span> <span class="text-xl font-bold text-white" id="kpi-tkt-ia">-</span> </div> <div class="flex justify-between items-end border-b border-slate-700/50 pb-2"> <span class="text-slate-400 text-sm">Humano/Outros</span> <span class="text-lg font-semibold text-slate-300" id="kpi-tkt-hum">-</span> </div> <div class="flex justify-between items-end pt-1"> <span class="text-white font-bold text-sm">MÉDIA GERAL</span> <span class="text-2xl font-extrabold text-white" id="kpi-tkt-tot">-</span> </div> </div> </div> </div> <!-- Secção do Gráfico --> <div class="glass-panel p-6 flex flex-col"> <div class="flex flex-col md:flex-row justify-between items-start md:items-center mb-6 gap-4"> <h2 class="text-xl font-bold text-slate-100" id="chartTitle"> <i class="fa-solid fa-chart-line text-ia mr-2"></i>Performance de Vendas </h2> <!-- Botões de Troca de Métrica --> <div class="flex bg-slate-800 rounded-lg p-1 border border-slate-700 text-sm"> <button onclick="setMetric('faturamento')" id="btn-faturamento" class="tab-btn tab-active px-4 py-1.5 rounded-md font-medium"> Faturamento </button> <button onclick="setMetric('ticket')" id="btn-ticket" class="tab-btn tab-inactive px-4 py-1.5 rounded-md font-medium"> Ticket Médio </button> <button onclick="setMetric('vendas')" id="btn-vendas" class="tab-btn tab-inactive px-4 py-1.5 rounded-md font-medium"> Vendas (Qtd) </button> </div> </div> <div class="relative flex-grow h-[350px] w-full"> <canvas id="mainChart"></canvas> </div> </div> <!-- Tabela de Detalhe por Funil --> <div class="glass-panel overflow-hidden"> <div class="p-6 border-b border-slate-700/50 flex justify-between items-center"> <h2 class="text-xl font-bold text-slate-100"><i class="fa-solid fa-filter text-ia mr-2"></i>Detalhe por Funil de Vendas</h2> <span class="text-xs font-semibold px-2 py-1 bg-slate-800 text-slate-400 rounded">Ordenado por Faturamento Total</span> </div> <div class="overflow-x-auto"> <table class="w-full text-sm text-left whitespace-nowrap" id="funnelTable"> <thead class="text-xs text-slate-400 uppercase bg-slate-800/50"> <tr> <th scope="col" class="px-6 py-4 font-bold text-white" rowspan="2">Funil de Vendas</th> <th scope="col" class="px-6 py-2 text-center border-l border-slate-700/50" colspan="3">Faturamento (R$)</th> <th scope="col" class="px-6 py-2 text-center border-l border-slate-700/50" colspan="3">Vendas (Qtd)</th> <th scope="col" class="px-6 py-2 text-center border-l border-slate-700/50" colspan="3">Ticket Médio (R$)</th> </tr> <tr class="border-b border-slate-700/50 bg-slate-800/30"> <!-- Faturação --> <th scope="col" class="px-3 py-2 text-right text-ia border-l border-slate-700/50 w-24">IA</th> <th scope="col" class="px-3 py-2 text-right w-24">Humano</th> <th scope="col" class="px-3 py-2 text-right text-white bg-slate-700/20 w-24">Total</th> <!-- Vendas --> <th scope="col" class="px-3 py-2 text-right text-ia border-l border-slate-700/50 w-20">IA</th> <th scope="col" class="px-3 py-2 text-right w-20">Humano</th> <th scope="col" class="px-3 py-2 text-right text-white bg-slate-700/20 w-20">Total</th> <!-- Ticket --> <th scope="col" class="px-3 py-2 text-right text-ia border-l border-slate-700/50 w-24">IA</th> <th scope="col" class="px-3 py-2 text-right w-24">Humano</th> <th scope="col" class="px-3 py-2 text-right text-white bg-slate-700/20 w-24">Total</th> </tr> </thead> <tbody id="funnelTableBody" class="divide-y divide-slate-700/50"> <!-- Preenchido via JS --> </tbody> </table> </div> </div> </div> <script> // === 1. DADOS BRUTOS AGREGADOS DO PYTHON === // Os dados baseiam-se rigorosamente na data de "Fechada em" const rawData = { "2025-09": { "label": "Set/25", "funnels": { "Caiçara": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 1270.0, "vol": 3}}, "Serra do Mar": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 14220.0, "vol": 6}} } }, "2025-10": { "label": "Out/25", "funnels": { "B2B Serra do Mar": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 8454.0, "vol": 6}}, "Caiçara": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 5181.0, "vol": 16}}, "Serra do Mar": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 28184.0, "vol": 43}}, "Termas": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 262.0, "vol": 1}}, "Vale Europeu": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 0.0, "vol": 1}} } }, "2025-11": { "label": "Nov/25", "funnels": { "B2B Serra do Mar": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 3970.0, "vol": 7}}, "Caiçara": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 11002.0, "vol": 20}}, "Central": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 362.0, "vol": 1}}, "NSB RS": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 7860.0, "vol": 2}}, "Serra do Mar": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 14703.0, "vol": 20}}, "Termas": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 1198.0, "vol": 4}} } }, "2025-12": { "label": "Dez/25", "funnels": { "B2B Serra do Mar": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 5264.0, "vol": 4}}, "Caiçara": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 1704.0, "vol": 5}}, "NSB RS": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 62741.0, "vol": 24}}, "Serra do Mar": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 45661.0, "vol": 66}}, "Termas": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 5306.0, "vol": 6}}, "Vale Europeu": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 14770.0, "vol": 53}} } }, "2026-01": { "label": "Jan/26", "funnels": { "Atendimento IA": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 3213.0, "vol": 2}}, "B2B Serra do Mar": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 574.0, "vol": 1}}, "Caiçara": {"ia": {"rev": 4676.0, "vol": 18}, "humano": {"rev": 57617.0, "vol": 89}}, "Serra do Mar": {"ia": {"rev": 18679.0, "vol": 18}, "humano": {"rev": 13844.0, "vol": 18}}, "Termas": {"ia": {"rev": 36842.0, "vol": 51}, "humano": {"rev": 14189.0, "vol": 24}} } }, "2026-02": { "label": "Fev/26", "funnels": { "Atendimento IA": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 618.0, "vol": 1}}, "Caiçara": {"ia": {"rev": 2619.0, "vol": 12}, "humano": {"rev": 1407.0, "vol": 13}}, "Serra do Mar": {"ia": {"rev": 26749.0, "vol": 27}, "humano": {"rev": 14234.0, "vol": 22}}, "Termas": {"ia": {"rev": 23554.0, "vol": 24}, "humano": {"rev": 4028.0, "vol": 9}}, "Vale Europeu": {"ia": {"rev": 1980.0, "vol": 10}, "humano": {"rev": 594.0, "vol": 3}} } }, "2026-03": { "label": "Mar/26", "funnels": { "Caiçara": {"ia": {"rev": 913.0, "vol": 5}, "humano": {"rev": 421.0, "vol": 7}}, "NSB RS": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 12450.0, "vol": 4}}, "Serra do Mar": {"ia": {"rev": 19286.0, "vol": 23}, "humano": {"rev": 16752.0, "vol": 14}}, "Termas": {"ia": {"rev": 21859.0, "vol": 31}, "humano": {"rev": 6922.0, "vol": 14}}, "Vale Europeu": {"ia": {"rev": 4290.0, "vol": 23}, "humano": {"rev": 8940.0, "vol": 47}} } }, "2026-04": { "label": "Abr/26", "funnels": { "NSB RS": {"ia": {"rev": 0, "vol": 0}, "humano": {"rev": 16768.0, "vol": 4}}, "Serra do Mar": {"ia": {"rev": 4477.0, "vol": 5}, "humano": {"rev": 6066.0, "vol": 7}}, "Termas": {"ia": {"rev": 6509.0, "vol": 9}, "humano": {"rev": 6147.0, "vol": 6}} } } }; // === 2. ESTADO GLOBAL === let currentMonth = 'all'; // Pode ser 'all' ou a chave do mês (ex: '2025-09') let currentMetric = 'faturamento'; let myChart = null; // Formatadores const formatMoney = (val) => new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(val || 0); const formatNumber = (val) => new Intl.NumberFormat('pt-BR').format(val || 0); // Inicializar opções do Select (Dropdown) function initMonthSelect() { const select = document.getElementById('monthFilter'); Object.keys(rawData).sort().forEach(mKey => { const opt = document.createElement('option'); opt.value = mKey; opt.text = rawData[mKey].label; select.appendChild(opt); }); select.addEventListener('change', (e) => { currentMonth = e.target.value; updateDashboard(); }); } // Alterar Métrica via Botões function setMetric(metric) { currentMetric = metric; document.querySelectorAll('.tab-btn').forEach(btn => { btn.classList.remove('tab-active'); btn.classList.add('tab-inactive'); }); document.getElementById('btn-' + metric).classList.remove('tab-inactive'); document.getElementById('btn-' + metric).classList.add('tab-active'); updateDashboard(); } // === 3. MOTOR PRINCIPAL: ATUALIZAR DASHBOARD === function updateDashboard() { const monthsToProcess = currentMonth === 'all' ? Object.keys(rawData).sort() : [currentMonth]; let globRevIA = 0, globRevHum = 0, globVolIA = 0, globVolHum = 0; let funnelAgg = {}; // { 'Serra do Mar': { rev_ia: 0, ... } } // 3.1. Agregar Dados monthsToProcess.forEach(mKey => { const fData = rawData[mKey].funnels; Object.entries(fData).forEach(([fName, metrics]) => { // Globais globRevIA += metrics.ia.rev; globRevHum += metrics.humano.rev; globVolIA += metrics.ia.vol; globVolHum += metrics.humano.vol; // Funis if (!funnelAgg[fName]) funnelAgg[fName] = { rev_ia: 0, rev_hum: 0, vol_ia: 0, vol_hum: 0 }; funnelAgg[fName].rev_ia += metrics.ia.rev; funnelAgg[fName].rev_hum += metrics.humano.rev; funnelAgg[fName].vol_ia += metrics.ia.vol; funnelAgg[fName].vol_hum += metrics.humano.vol; }); }); // 3.2. Atualizar KPIs const globRevTot = globRevIA + globRevHum; const globVolTot = globVolIA + globVolHum; const tktIA = globVolIA > 0 ? globRevIA / globVolIA : 0; const tktHum = globVolHum > 0 ? globRevHum / globVolHum : 0; const tktTot = globVolTot > 0 ? globRevTot / globVolTot : 0; document.getElementById('kpi-rev-ia').innerText = formatMoney(globRevIA); document.getElementById('kpi-rev-hum').innerText = formatMoney(globRevHum); document.getElementById('kpi-rev-tot').innerText = formatMoney(globRevTot); document.getElementById('kpi-vol-ia').innerText = formatNumber(globVolIA); document.getElementById('kpi-vol-hum').innerText = formatNumber(globVolHum); document.getElementById('kpi-vol-tot').innerText = formatNumber(globVolTot); document.getElementById('kpi-tkt-ia').innerText = formatMoney(tktIA); document.getElementById('kpi-tkt-hum').innerText = formatMoney(tktHum); document.getElementById('kpi-tkt-tot').innerText = formatMoney(tktTot); // 3.3. Atualizar Tabela de Funil renderFunnelTable(funnelAgg, globRevIA, globRevHum, globVolIA, globVolHum); // 3.4. Atualizar Gráfico (Chart.js) renderChart(monthsToProcess); } // Renderizar a Tabela Agrupada function renderFunnelTable(funnelAgg, totRevIA, totRevHum, totVolIA, totVolHum) { const tbody = document.getElementById('funnelTableBody'); tbody.innerHTML = ''; // Limpar anterior // Converter para Array e ordenar por Faturação Total const arrFunnels = Object.keys(funnelAgg).map(name => { return { name, ...funnelAgg[name], total_rev: funnelAgg[name].rev_ia + funnelAgg[name].rev_hum }; }).sort((a, b) => b.total_rev - a.total_rev); arrFunnels.forEach(f => { const revTot = f.rev_ia + f.rev_hum; const volTot = f.vol_ia + f.vol_hum; const tktIA = f.vol_ia > 0 ? f.rev_ia / f.vol_ia : 0; const tktHum = f.vol_hum > 0 ? f.rev_hum / f.vol_hum : 0; const tktTot = volTot > 0 ? revTot / volTot : 0; // Só mostra o funil se teve alguma atividade if (volTot === 0) return; const tr = document.createElement('tr'); tr.className = 'hover:bg-slate-800/30 transition-colors'; tr.innerHTML = ` <td class="px-6 py-4 font-medium text-white">${f.name}</td> <td class="px-3 py-3 text-right text-ia font-semibold border-l border-slate-700/50">${f.rev_ia > 0 ? formatMoney(f.rev_ia) : '-'}</td> <td class="px-3 py-3 text-right text-slate-300">${f.rev_hum > 0 ? formatMoney(f.rev_hum) : '-'}</td> <td class="px-3 py-3 text-right text-emerald-400 font-bold bg-slate-700/10">${formatMoney(revTot)}</td> <td class="px-3 py-3 text-right text-ia border-l border-slate-700/50">${f.vol_ia > 0 ? f.vol_ia : '-'}</td> <td class="px-3 py-3 text-right text-slate-300">${f.vol_hum > 0 ? f.vol_hum : '-'}</td> <td class="px-3 py-3 text-right text-white font-bold bg-slate-700/10">${volTot}</td> <td class="px-3 py-3 text-right text-ia border-l border-slate-700/50">${tktIA > 0 ? formatMoney(tktIA) : '-'}</td> <td class="px-3 py-3 text-right text-slate-300">${tktHum > 0 ? formatMoney(tktHum) : '-'}</td> <td class="px-3 py-3 text-right text-white font-bold bg-slate-700/10">${formatMoney(tktTot)}</td> `; tbody.appendChild(tr); }); // Adicionar Linha de Total const finalRevTot = totRevIA + totRevHum; const finalVolTot = totVolIA + totVolHum; const finalTktIA = totVolIA > 0 ? totRevIA / totVolIA : 0; const finalTktHum = totVolHum > 0 ? totRevHum / totVolHum : 0; const finalTktTot = finalVolTot > 0 ? finalRevTot / finalVolTot : 0; const trTotal = document.createElement('tr'); trTotal.className = 'bg-slate-800 font-bold border-t-2 border-slate-600'; trTotal.innerHTML = ` <td class="px-6 py-4 text-white uppercase">Total Filtrado</td> <td class="px-3 py-4 text-right text-ia border-l border-slate-700/50">${formatMoney(totRevIA)}</td> <td class="px-3 py-4 text-right text-slate-300">${formatMoney(totRevHum)}</td> <td class="px-3 py-4 text-right text-emerald-400 bg-slate-700/30">${formatMoney(finalRevTot)}</td> <td class="px-3 py-4 text-right text-ia border-l border-slate-700/50">${totVolIA}</td> <td class="px-3 py-4 text-right text-slate-300">${totVolHum}</td> <td class="px-3 py-4 text-right text-white bg-slate-700/30">${finalVolTot}</td> <td class="px-3 py-4 text-right text-ia border-l border-slate-700/50">${formatMoney(finalTktIA)}</td> <td class="px-3 py-4 text-right text-slate-300">${formatMoney(finalTktHum)}</td> <td class="px-3 py-4 text-right text-white bg-slate-700/30">${formatMoney(finalTktTot)}</td> `; tbody.appendChild(trTotal); } // Renderizar ou Atualizar o Gráfico function renderChart(monthsToProcess) { const ctx = document.getElementById('mainChart').getContext('2d'); let chartLabels = []; let chartDataIA = []; let chartDataHum = []; let chartType = 'line'; let titlePrefix = 'Evolução ao longo do tempo'; if (currentMonth === 'all') { // LINHA DO TEMPO chartType = 'line'; titlePrefix = 'Evolução Mensal'; monthsToProcess.forEach(mKey => { chartLabels.push(rawData[mKey].label); let mRevIA = 0, mRevHum = 0, mVolIA = 0, mVolHum = 0; Object.values(rawData[mKey].funnels).forEach(f => { mRevIA += f.ia.rev; mRevHum += f.humano.rev; mVolIA += f.ia.vol; mVolHum += f.humano.vol; }); let valIA = 0, valHum = 0; if (currentMetric === 'faturamento') { valIA = mRevIA; valHum = mRevHum; } if (currentMetric === 'vendas') { valIA = mVolIA; valHum = mVolHum; } if (currentMetric === 'ticket') { valIA = mVolIA > 0 ? mRevIA / mVolIA : null; valHum = mVolHum > 0 ? mRevHum / mVolHum : 0; } // Previne a IA de descer ao Zero antes de existir de facto (antes de Jan/26) if (mKey < '2026-01' && (valIA === 0 || valIA === null)) valIA = null; chartDataIA.push(valIA); chartDataHum.push(valHum); }); } else { // BARRAS POR FUNIL (Porque a vista de um único mês num gráfico de linhas é só 1 ponto) chartType = 'bar'; titlePrefix = `Comparativo de Funis (${rawData[currentMonth].label})`; const mFunnels = rawData[currentMonth].funnels; // Extrair apenas os funis que tiveram dados neste mês específico Object.entries(mFunnels).forEach(([fName, f]) => { const revTot = f.ia.rev + f.humano.rev; if (revTot === 0) return; // ignora os funis vazios chartLabels.push(fName); let valIA = 0, valHum = 0; if (currentMetric === 'faturamento') { valIA = f.ia.rev; valHum = f.humano.rev; } if (currentMetric === 'vendas') { valIA = f.ia.vol; valHum = f.humano.vol; } if (currentMetric === 'ticket') { valIA = f.ia.vol > 0 ? f.ia.rev / f.ia.vol : 0; valHum = f.humano.vol > 0 ? f.humano.rev / f.humano.vol : 0; } chartDataIA.push(valIA); chartDataHum.push(valHum); }); } // Textos do Título const metricNames = { 'faturamento': 'Faturamento (R$)', 'ticket': 'Ticket Médio (R$)', 'vendas': 'Volume de Vendas (Qtd)' }; document.getElementById('chartTitle').innerHTML = `<i class="fa-solid ${chartType === 'line' ? 'fa-chart-line' : 'fa-chart-simple'} text-ia mr-2"></i>${titlePrefix} - ${metricNames[currentMetric]}`; // Destruir instância anterior para evitar conflitos na mudança de Tipo do Gráfico if (myChart) myChart.destroy(); // Configuração dos Gradientes let gradientIA = ctx.createLinearGradient(0, 0, 0, 400); gradientIA.addColorStop(0, 'rgba(139, 92, 246, 0.8)'); gradientIA.addColorStop(1, 'rgba(139, 92, 246, 0.1)'); let gradientHumano = ctx.createLinearGradient(0, 0, 0, 400); gradientHumano.addColorStop(0, 'rgba(148, 163, 184, 0.6)'); gradientHumano.addColorStop(1, 'rgba(148, 163, 184, 0.1)'); myChart = new Chart(ctx, { type: chartType, data: { labels: chartLabels, datasets: [ { label: 'SDR IA', data: chartDataIA, borderColor: '#8B5CF6', backgroundColor: chartType === 'line' ? gradientIA : '#8B5CF6', borderWidth: chartType === 'line' ? 3 : 0, borderRadius: chartType === 'bar' ? 4 : 0, pointBackgroundColor: '#8B5CF6', pointBorderColor: '#fff', pointBorderWidth: 2, pointRadius: 5, spanGaps: false, fill: true, tension: 0.4 }, { label: 'Humano/Outros', data: chartDataHum, borderColor: '#94A3B8', backgroundColor: chartType === 'line' ? gradientHumano : '#94A3B8', borderWidth: chartType === 'line' ? 2 : 0, borderRadius: chartType === 'bar' ? 4 : 0, pointBackgroundColor: '#94A3B8', pointBorderColor: '#1E293B', pointBorderWidth: 2, pointRadius: 4, fill: true, tension: 0.4 } ] }, options: { responsive: true, maintainAspectRatio: false, interaction: { mode: 'index', intersect: false }, plugins: { legend: { position: 'top', labels: { usePointStyle: true, boxWidth: 8, padding: 20, font: { size: 13, weight: 'bold', family: "'Inter', sans-serif" }, color: '#94A3B8' } }, tooltip: { backgroundColor: 'rgba(15, 23, 42, 0.9)', titleColor: '#fff', bodyColor: '#cbd5e1', borderColor: 'rgba(255,255,255,0.1)', borderWidth: 1, padding: 12, callbacks: { label: function(context) { let label = context.dataset.label || ''; if (label) label += ': '; if (context.parsed.y !== null) { if (currentMetric !== 'vendas') { label += formatMoney(context.parsed.y); } else { label += formatNumber(context.parsed.y) + ' Vendas'; } } return label; } } } }, scales: { x: { grid: { color: 'rgba(255, 255, 255, 0.05)', drawBorder: false }, ticks: { color: '#94A3B8' } }, y: { grid: { color: 'rgba(255, 255, 255, 0.05)', drawBorder: false }, ticks: { color: '#94A3B8', callback: function(value) { if (currentMetric !== 'vendas') { if (value >= 1000000) return 'R$ ' + (value / 1000000).toFixed(1) + 'M'; if (value >= 1000) return 'R$ ' + (value / 1000) + 'k'; return 'R$ ' + value; } return value; } } } } } }); } // === 4. INICIALIZAÇÃO === Chart.defaults.color = '#94A3B8'; Chart.defaults.font.family = "'Inter', sans-serif"; document.addEventListener('DOMContentLoaded', () => { initMonthSelect(); updateDashboard(); // Processa os dados de 'all' pela primeira vez }); </script> </body> </html>