diff --git a/servicios.html b/servicios.html
index c5b64c7..3b7d4f1 100644
--- a/servicios.html
+++ b/servicios.html
@@ -80,9 +80,15 @@
-
+
-
-
Guardado correctamente
+
+
+
+
+
+
+
Servicios Atrasados
+
Citas pasadas que siguen activas (Ayer o anteriores)
+
+
+
+
+
+
+
@@ -618,6 +639,7 @@
localData = data.services.filter(s => s.provider !== 'SYSTEM_BLOCK');
updateOperatorFilter();
renderLists();
+ checkOldServices(); // 👈 Lanzamos el detector de atrasados al recargar
}
} catch (e) { console.error(e); }
}
@@ -1417,6 +1439,110 @@
input.focus();
}
}
+
+ // =====================================
+ // PANEL DE SERVICIOS ATRASADOS
+ // =====================================
+ function checkOldServices() {
+ const hoy = new Date();
+ hoy.setHours(0, 0, 0, 0);
+
+ const targetStates = ['citado', 'trabajando', 'incidencia', 'compañÃa', 'perito', 'espera cia'];
+
+ const atrasados = localData.filter(s => {
+ const stateInfo = getServiceStateInfo(s);
+ const stName = (stateInfo.name || "").toLowerCase();
+
+ // Filtramos que estén en los estados problemáticos y que NO estén finalizados/anulados
+ const isTargetState = targetStates.some(ts => stName.includes(ts));
+ if (!isTargetState || stateInfo.is_final) return false;
+
+ const raw = s.raw_data || {};
+ let targetDateStr = raw.scheduled_date;
+
+ // Si no tiene fecha programada pero está en incidencia o perito, usamos la fecha de creación
+ if (!targetDateStr) {
+ targetDateStr = s.created_at ? s.created_at.split('T')[0] : null;
+ }
+
+ if (targetDateStr) {
+ const svcDate = new Date(targetDateStr);
+ svcDate.setHours(0, 0, 0, 0);
+ return svcDate < hoy; // Es estrictamente menor que hoy (ayer o antes)
+ }
+
+ return false;
+ });
+
+ // Actualizamos el número rojo en el botón
+ const badge = document.getElementById('badgeOldServices');
+ if (badge) {
+ if (atrasados.length > 0) {
+ badge.innerText = atrasados.length;
+ badge.classList.remove('hidden');
+ } else {
+ badge.classList.add('hidden');
+ }
+ }
+
+ return atrasados.sort((a, b) => {
+ const dA = new Date((a.raw_data && a.raw_data.scheduled_date) || a.created_at);
+ const dB = new Date((b.raw_data && b.raw_data.scheduled_date) || b.created_at);
+ return dA - dB;
+ });
+ }
+
+ function openOldServicesModal() {
+ const list = checkOldServices();
+ const container = document.getElementById('oldServicesList');
+
+ if (list.length === 0) {
+ container.innerHTML = '
Todo al dÃa
No hay servicios atrasados pendientes.
';
+ } else {
+ container.innerHTML = list.map(s => {
+ const raw = s.raw_data || {};
+ const stateInfo = getServiceStateInfo(s);
+ const colorData = colorDict[stateInfo.color] || colorDict['gray'];
+ const clientName = raw["Nombre Cliente"] || raw["CLIENTE"] || "Sin Nombre";
+ const dateStr = raw.scheduled_date ? raw.scheduled_date.split('-').reverse().join('/') : new Date(s.created_at).toLocaleDateString('es-ES');
+
+ return `
+
+
+
+
+
+
+
+ #${s.service_ref}
+ Cita: ${dateStr}
+
+
${clientName}
+
${s.assigned_name || 'Sin operario asignado'}
+
+
+
+
+ ${stateInfo.name}
+
+
+
+
+ `;
+ }).join('');
+ }
+
+ document.getElementById('oldServicesModal').classList.remove('hidden');
+ lucide.createIcons();
+ }
+
+ function closeOldServicesModal() {
+ document.getElementById('oldServicesModal').classList.add('hidden');
+ }
+
+