Actualizar servicios.html
This commit is contained in:
@@ -570,52 +570,54 @@
|
|||||||
|
|
||||||
const searchTerm = document.getElementById('searchFilter').value.toLowerCase();
|
const searchTerm = document.getElementById('searchFilter').value.toLowerCase();
|
||||||
const selectedOp = document.getElementById('opFilter').value;
|
const selectedOp = document.getElementById('opFilter').value;
|
||||||
const weekValue = document.getElementById('weekFilter').value;
|
|
||||||
|
|
||||||
// Inicializamos contadores reales
|
// 1. Añadimos la variable para el nuevo KPI
|
||||||
let kpiUnassigned = 0;
|
let kpiUnassigned = 0, kpiAssignedNoDate = 0, kpiScheduled = 0, kpiWaiting = 0, kpiIncident = 0;
|
||||||
let kpiScheduled = 0;
|
|
||||||
let kpiWaiting = 0;
|
|
||||||
let kpiIncident = 0;
|
|
||||||
|
|
||||||
const filteredData = localData.filter(s => {
|
const filteredData = localData.filter(s => {
|
||||||
const raw = s.raw_data || {};
|
const raw = s.raw_data || {};
|
||||||
const stateInfo = getServiceStateInfo(s);
|
const stateInfo = getServiceStateInfo(s);
|
||||||
s._stateInfo = stateInfo;
|
s._stateInfo = stateInfo;
|
||||||
|
|
||||||
const stName = stateInfo.name.toLowerCase();
|
const stName = stateInfo.name.toLowerCase();
|
||||||
|
|
||||||
if (!s.assigned_name || stateInfo.id === 'bolsa' || stName.includes('asignar')) {
|
// --- LÓGICA REVISADA DE CONTADORES ---
|
||||||
|
|
||||||
|
if (!s.assigned_name || stateInfo.id === 'bolsa' || stName.includes('asignar') || stName.includes('desasignado')) {
|
||||||
|
// Si no tiene operario, o está en bolsa, o el estado dice explícitamente sin asignar
|
||||||
kpiUnassigned++;
|
kpiUnassigned++;
|
||||||
}
|
}
|
||||||
else if (stName.includes('incidencia') || stName.includes('pausa')) {
|
else if (stName.includes('incidencia') || stName.includes('pausa')) {
|
||||||
|
// Si hay un problema
|
||||||
kpiIncident++;
|
kpiIncident++;
|
||||||
}
|
}
|
||||||
|
else if (stName.includes('espera')) {
|
||||||
|
// SOLUCIONADO: Ahora solo cuenta aquí si el estado se llama literalmente "Esperando al cliente"
|
||||||
|
kpiWaiting++;
|
||||||
|
}
|
||||||
else if (raw.scheduled_date && raw.scheduled_date !== "" && !stateInfo.is_final) {
|
else if (raw.scheduled_date && raw.scheduled_date !== "" && !stateInfo.is_final) {
|
||||||
|
// Citados: Tiene operario (ya pasó el primer filtro) y SÍ tiene fecha
|
||||||
kpiScheduled++;
|
kpiScheduled++;
|
||||||
}
|
}
|
||||||
else if (!stateInfo.is_final && !raw.scheduled_date) {
|
else if (!stateInfo.is_final && (!raw.scheduled_date || raw.scheduled_date === "")) {
|
||||||
kpiWaiting++;
|
// Asignado sin cita: Tiene operario, no es incidencia, no es espera, y NO tiene fecha
|
||||||
|
kpiAssignedNoDate++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = (raw["Nombre Cliente"] || raw["CLIENTE"] || "").toLowerCase();
|
// Filtro de búsqueda visual (esto no cambia)
|
||||||
const ref = (s.service_ref || "").toLowerCase();
|
const matchesSearch = searchTerm === "" ||
|
||||||
const matchesSearch = searchTerm === "" || name.includes(searchTerm) || ref.includes(searchTerm);
|
(raw["Nombre Cliente"] || "").toLowerCase().includes(searchTerm) ||
|
||||||
|
(s.service_ref || "").toLowerCase().includes(searchTerm) ||
|
||||||
|
(raw["Teléfono"] || "").toLowerCase().includes(searchTerm);
|
||||||
|
|
||||||
const matchesOp = selectedOp === "ALL" || s.assigned_name === selectedOp;
|
const matchesOp = selectedOp === "ALL" || s.assigned_name === selectedOp;
|
||||||
|
const matchesStatus = (activeStatusFilter === "ALL") ? true : String(stateInfo.id) === activeStatusFilter;
|
||||||
let matchesWeek = true;
|
|
||||||
if (weekValue !== "" && raw.scheduled_date) {
|
|
||||||
matchesWeek = isDateInWeekString(raw.scheduled_date, weekValue);
|
|
||||||
} else if (weekValue !== "") {
|
|
||||||
matchesWeek = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let matchesStatus = (activeStatusFilter === "ALL") ? true : String(stateInfo.id) === activeStatusFilter;
|
|
||||||
|
|
||||||
return matchesSearch && matchesOp && matchesWeek && matchesStatus;
|
return matchesSearch && matchesOp && matchesStatus;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 2. Mandamos los números calculados a los círculos del HTML
|
||||||
document.getElementById('kpi-unassigned').innerText = kpiUnassigned;
|
document.getElementById('kpi-unassigned').innerText = kpiUnassigned;
|
||||||
|
document.getElementById('kpi-assigned-no-date').innerText = kpiAssignedNoDate; // <- NUEVO
|
||||||
document.getElementById('kpi-scheduled').innerText = kpiScheduled;
|
document.getElementById('kpi-scheduled').innerText = kpiScheduled;
|
||||||
document.getElementById('kpi-waiting').innerText = kpiWaiting;
|
document.getElementById('kpi-waiting').innerText = kpiWaiting;
|
||||||
document.getElementById('kpi-incident').innerText = kpiIncident;
|
document.getElementById('kpi-incident').innerText = kpiIncident;
|
||||||
@@ -623,10 +625,7 @@
|
|||||||
const grid = document.getElementById('servicesGrid');
|
const grid = document.getElementById('servicesGrid');
|
||||||
grid.innerHTML = filteredData.length > 0
|
grid.innerHTML = filteredData.length > 0
|
||||||
? filteredData.map(s => buildGridCard(s)).join('')
|
? filteredData.map(s => buildGridCard(s)).join('')
|
||||||
: `<div class="col-span-full py-20 text-center bg-white rounded-[2rem] border-2 border-dashed border-slate-200">
|
: `<div class="col-span-full py-20 text-center text-slate-400 font-bold uppercase tracking-widest text-sm">No hay servicios con estos filtros</div>`;
|
||||||
<i data-lucide="layout-grid" class="w-12 h-12 text-slate-300 mx-auto mb-3"></i>
|
|
||||||
<p class="text-slate-400 font-bold uppercase tracking-widest text-sm">No hay servicios que coincidan</p>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user