diff --git a/servicios.html b/servicios.html index 1e063da..099761e 100644 --- a/servicios.html +++ b/servicios.html @@ -544,6 +544,7 @@ const selectedOp = document.getElementById('opFilter').value; const weekValue = document.getElementById('weekFilter').value; + // Inicializamos contadores reales let kpiUnassigned = 0; let kpiScheduled = 0; let kpiWaiting = 0; @@ -551,46 +552,48 @@ const filteredData = localData.filter(s => { const raw = s.raw_data || {}; - const name = (raw["Nombre Cliente"] || raw["CLIENTE"] || "").toLowerCase(); - const addr = (raw["Dirección"] || raw["DOMICILIO"] || "").toLowerCase(); - const pop = (raw["Población"] || raw["POBLACION-PROVINCIA"] || "").toLowerCase(); - const phone = (raw["Teléfono"] || raw["TELEFONO"] || "").toLowerCase(); - const comp = (raw["Compañía"] || raw["COMPAÑIA"] || raw["Procedencia"] || "").toLowerCase(); - const ref = (s.service_ref || "").toLowerCase(); - const assigned = s.assigned_name || ""; - const dateRaw = raw.scheduled_date || ""; - const stateInfo = getServiceStateInfo(s); - s._stateInfo = stateInfo; + s._stateInfo = stateInfo; // Guardamos info para el render + // LÓGICA DE CONTADORES REVOLUCIONADA: const stName = stateInfo.name.toLowerCase(); - if (stateInfo.id === 'bolsa' || stName.includes('pendiente de asignar') || stName.includes('desasignado')) { + // 1. SIN ASIGNAR: No tiene nombre de operario O está en bolsa + if (!s.assigned_name || stateInfo.id === 'bolsa' || stName.includes('asignar')) { kpiUnassigned++; - } else if (stName.includes('incidencia') || stName.includes('pausa')) { + } + // 2. INCIDENCIA: El estado tiene la palabra clave + else if (stName.includes('incidencia') || stName.includes('pausa')) { kpiIncident++; - } else if (dateRaw !== "") { + } + // 3. AGENDADOS: Tiene fecha puesta y no es un estado final + else if (raw.scheduled_date && raw.scheduled_date !== "" && !stateInfo.is_final) { kpiScheduled++; - } else if (!stateInfo.is_final && !stName.includes('terminado')) { + } + // 4. ESPERA CLIENTE: No tiene cita pero ya tiene técnico (o estado específico) + else if (!stateInfo.is_final && (!raw.scheduled_date || stName.includes('espera'))) { kpiWaiting++; } - const matchesSearch = searchTerm === "" || name.includes(searchTerm) || ref.includes(searchTerm) || addr.includes(searchTerm) || pop.includes(searchTerm) || phone.includes(searchTerm) || comp.includes(searchTerm); - const matchesOp = selectedOp === "ALL" || assigned === selectedOp; + // Filtros de búsqueda + const name = (raw["Nombre Cliente"] || raw["CLIENTE"] || "").toLowerCase(); + const ref = (s.service_ref || "").toLowerCase(); + const matchesSearch = searchTerm === "" || name.includes(searchTerm) || ref.includes(searchTerm); + const matchesOp = selectedOp === "ALL" || s.assigned_name === selectedOp; let matchesWeek = true; - if (weekValue !== "") { - if (dateRaw) matchesWeek = isDateInWeekString(dateRaw, weekValue); - else matchesWeek = false; + if (weekValue !== "" && raw.scheduled_date) { + matchesWeek = isDateInWeekString(raw.scheduled_date, weekValue); + } else if (weekValue !== "") { + matchesWeek = false; } - let matchesStatus = false; - if (activeStatusFilter === "ALL") matchesStatus = true; - else matchesStatus = String(stateInfo.id) === activeStatusFilter; + let matchesStatus = (activeStatusFilter === "ALL") ? true : String(stateInfo.id) === activeStatusFilter; return matchesSearch && matchesOp && matchesWeek && matchesStatus; }); + // Actualizamos la vista con los números reales document.getElementById('kpi-unassigned').innerText = kpiUnassigned; document.getElementById('kpi-scheduled').innerText = kpiScheduled; document.getElementById('kpi-waiting').innerText = kpiWaiting; @@ -601,7 +604,7 @@ ? filteredData.map(s => buildGridCard(s)).join('') : `
No hay servicios que coincidan con los filtros
+No hay servicios que coincidan