Actualizar panel.html

This commit is contained in:
2026-02-17 22:16:54 +00:00
parent 14744a5ff7
commit 153bc3ce9f

View File

@@ -193,32 +193,49 @@
function processDashboard(scrapedList, activeList) { function processDashboard(scrapedList, activeList) {
const todayStr = new Date().toISOString().split('T')[0]; const todayStr = new Date().toISOString().split('T')[0];
// 1. LIMPIAR DATOS // 1. FUSIÓN INTELIGENTE SIN DUPLICADOS (Usamos un Map basado en el ID)
// Filtramos los archivados y los que ya están importados del Scraped (porque los importados ya vienen en activeList) const allServicesMap = new Map();
const trueScraped = scrapedList.filter(s => s.status !== 'archived' && s.status !== 'imported');
const trueActive = activeList.filter(s => s.status !== 'archived');
// Unimos todo en una gran lista para los gráficos globales
const allServices = [...trueScraped, ...trueActive];
// --- CÁLCULO DE KPIs --- // Primero cargamos los servicios que vienen de la bandeja
scrapedList.forEach(s => {
if (s.status !== 'archived') {
allServicesMap.set(s.id, s);
}
});
// Luego sobrescribimos/agregamos con los de activos (que traen info más actualizada sobre el operario)
activeList.forEach(s => {
if (s.status !== 'archived') {
if (allServicesMap.has(s.id)) {
// Si ya existe, combinamos para no perder datos
allServicesMap.set(s.id, { ...allServicesMap.get(s.id), ...s });
} else {
allServicesMap.set(s.id, s);
}
}
});
// Convertimos el mapa final en una lista pura y sin duplicados
const allServices = Array.from(allServicesMap.values());
// --- CÁLCULO DE KPIs CORRECTO ---
// 1. Total (La suma de los dos mundos) // 1. Total (Sin duplicados)
const totalActive = allServices.length; const totalActive = allServices.length;
// 2. Sin Asignar (Los de scraped que no están en rueda) // 2. Sin Asignar (Nadie asignado y no está buscando en la rueda)
const unassignedCount = trueScraped.filter(s => s.automation_status !== 'in_progress').length; const unassignedCount = allServices.filter(s => !s.assigned_name && s.automation_status !== 'in_progress').length;
// 3. En Rueda (Los de scraped buscando operario) // 3. En Rueda (Nadie asignado pero SÍ está en la rueda)
const queueCount = trueScraped.filter(s => s.automation_status === 'in_progress').length; const queueCount = allServices.filter(s => !s.assigned_name && s.automation_status === 'in_progress').length;
// 4. Asignados sin cita (Los activos que no tienen fecha agendada) // 4. Asignados sin cita (Tienen operario asignado pero no hay fecha)
const pendingCount = trueActive.filter(s => !s.raw_data.scheduled_date || s.raw_data.scheduled_date === "").length; const pendingCount = allServices.filter(s => s.assigned_name && (!s.raw_data.scheduled_date || s.raw_data.scheduled_date === "")).length;
// 5. Citas de hoy (Los activos con fecha de hoy) // 5. Citas de hoy (La fecha es hoy)
const todayVisits = trueActive.filter(s => s.raw_data.scheduled_date === todayStr); const todayVisits = allServices.filter(s => s.raw_data && s.raw_data.scheduled_date === todayStr);
// 6. Urgencias (Cualquiera que tenga la palabra URGENTE) // 6. Urgencias (Cualquiera marcado como urgente)
const urgentVisits = allServices.filter(s => { const urgentVisits = allServices.filter(s => {
const raw = s.raw_data || {}; const raw = s.raw_data || {};
return raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI'; return raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI';
@@ -358,7 +375,7 @@
container.innerHTML = latest.map(s => { container.innerHTML = latest.map(s => {
const name = s.raw_data['Nombre Cliente'] || s.raw_data['CLIENTE'] || "Nuevo Cliente"; const name = s.raw_data['Nombre Cliente'] || s.raw_data['CLIENTE'] || "Nuevo Cliente";
const isNew = s.status === 'pending'; const isNew = !s.assigned_name && s.automation_status !== 'in_progress';
const icon = isNew ? '<i data-lucide="download-cloud" class="w-3.5 h-3.5 text-blue-400"></i>' : '<i data-lucide="check" class="w-3.5 h-3.5 text-emerald-400"></i>'; const icon = isNew ? '<i data-lucide="download-cloud" class="w-3.5 h-3.5 text-blue-400"></i>' : '<i data-lucide="check" class="w-3.5 h-3.5 text-emerald-400"></i>';
return ` return `
<div class="flex gap-3 items-start border-b border-slate-700/50 pb-3 last:border-0 last:pb-0"> <div class="flex gap-3 items-start border-b border-slate-700/50 pb-3 last:border-0 last:pb-0">