Actualizar servicios.html
This commit is contained in:
@@ -375,40 +375,44 @@
|
|||||||
// ==========================================
|
// ==========================================
|
||||||
function getServiceStateInfo(s) {
|
function getServiceStateInfo(s) {
|
||||||
const raw = s.raw_data || {};
|
const raw = s.raw_data || {};
|
||||||
const dbStat = raw.status_operativo; // Aquí viene el ID del estado (ej: "42") o texto antiguo
|
const dbStat = raw.status_operativo; // Aquí viene el ID del estado o texto antiguo
|
||||||
|
|
||||||
// 1. Prioridad Máxima: Bolsa de Trabajo / Robot WhatsApp
|
// 1. Prioridad Máxima: Bolsa de Trabajo / Robot WhatsApp
|
||||||
if (!s.assigned_name && (s.automation_status === 'in_progress' || s.automation_status === 'failed')) {
|
if (!s.assigned_name && (s.automation_status === 'in_progress' || s.automation_status === 'failed')) {
|
||||||
return { id: 'bolsa', name: s.automation_status === 'in_progress' ? 'Buscando Operario' : 'Fallo en Bolsa', color: s.automation_status === 'in_progress' ? 'amber' : 'red', isBlocked: true, is_final: false };
|
return { id: 'bolsa', name: s.automation_status === 'in_progress' ? 'Buscando Operario' : 'Fallo en Bolsa', color: s.automation_status === 'in_progress' ? 'amber' : 'red', isBlocked: true, is_final: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Match Directo por ID (La forma más segura para que los filtros de los botones no fallen)
|
// 2. Si viene limpio del scraper sin estado -> Pendiente de Asignar
|
||||||
// Si dbStat es un ID que existe en nuestra lista de estados, lo usamos directamente.
|
if (!s.assigned_name && (!dbStat || dbStat === 'sin_asignar')) {
|
||||||
const foundById = systemStatuses.find(st => String(st.id) === String(dbStat));
|
|
||||||
if (foundById) return { ...foundById, isBlocked: false };
|
|
||||||
|
|
||||||
// 3. Lógica de "La pelota en el tejado": Si tiene operario pero NO tiene fecha agendada
|
|
||||||
if (s.assigned_name && (!raw.scheduled_date || raw.scheduled_date === "")) {
|
|
||||||
const asignado = systemStatuses.find(st => st.name.toLowerCase() === 'asignado');
|
|
||||||
const esperando = systemStatuses.find(st => st.name.toLowerCase().includes('esperando'));
|
|
||||||
|
|
||||||
// Si en la base de datos el texto coincide con "esperando" (compatibilidad)
|
|
||||||
if (dbStat === 'esperando_cliente' && esperando) return { ...esperando, isBlocked: false };
|
|
||||||
|
|
||||||
// Por defecto, si tiene técnico asignado pero no hay fecha ni estado específico de "esperando",
|
|
||||||
// lo mandamos a la columna "ASIGNADO" (Oficina debe gestionar).
|
|
||||||
if (asignado) return { ...asignado, isBlocked: false };
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Si viene nuevo del scraper (Sin operario y sin estado)
|
|
||||||
if (!s.assigned_name || dbStat === 'sin_asignar') {
|
|
||||||
const found = systemStatuses.find(st => st.name.toLowerCase().includes('pendiente de asignar')) || systemStatuses[0];
|
const found = systemStatuses.find(st => st.name.toLowerCase().includes('pendiente de asignar')) || systemStatuses[0];
|
||||||
return { ...found, isBlocked: false };
|
return { ...found, isBlocked: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. Match Directo por ID (Si ya se guardó con el nuevo sistema de IDs numéricos)
|
||||||
|
const foundById = systemStatuses.find(st => String(st.id) === String(dbStat));
|
||||||
|
if (foundById) return { ...foundById, isBlocked: false };
|
||||||
|
|
||||||
|
// 4. Lógica de "Asignado" vs "Esperando Cliente" (Si tiene operario pero NO fecha)
|
||||||
|
if (s.assigned_name && (!raw.scheduled_date || raw.scheduled_date === "")) {
|
||||||
|
const asignado = systemStatuses.find(st => st.name.toLowerCase() === 'asignado');
|
||||||
|
const esperando = systemStatuses.find(st => st.name.toLowerCase().includes('esperando'));
|
||||||
|
|
||||||
|
// Si en BD es el texto antiguo 'esperando_cliente'
|
||||||
|
if (dbStat === 'esperando_cliente' && esperando) return { ...esperando, isBlocked: false };
|
||||||
|
|
||||||
|
// Si es el texto antiguo 'asignado_operario' o no tiene estado definido pero sí tiene operario
|
||||||
|
if ((dbStat === 'asignado_operario' || !dbStat) && asignado) return { ...asignado, isBlocked: false };
|
||||||
|
|
||||||
|
// Fallback por defecto si no encaja en lo anterior
|
||||||
|
if (asignado) return { ...asignado, isBlocked: false };
|
||||||
|
}
|
||||||
|
|
||||||
// 5. Fallbacks históricos de texto (Para que los servicios antiguos no se rompan)
|
// 5. Fallbacks históricos de texto (Para que los servicios antiguos no se rompan)
|
||||||
const stLower = String(dbStat).toLowerCase();
|
const stLower = String(dbStat).toLowerCase();
|
||||||
if (stLower === 'citado') return { ...systemStatuses.find(st => st.name.toLowerCase().includes('citado')), isBlocked: false };
|
if (stLower === 'citado' || (s.assigned_name && raw.scheduled_date && !dbStat)) {
|
||||||
|
const citado = systemStatuses.find(st => st.name.toLowerCase().includes('citado'));
|
||||||
|
if(citado) return { ...citado, isBlocked: false };
|
||||||
|
}
|
||||||
if (stLower === 'de_camino') return { ...systemStatuses.find(st => st.name.toLowerCase().includes('camino')), isBlocked: false };
|
if (stLower === 'de_camino') return { ...systemStatuses.find(st => st.name.toLowerCase().includes('camino')), isBlocked: false };
|
||||||
if (stLower === 'trabajando') return { ...systemStatuses.find(st => st.name.toLowerCase().includes('trabajando')), isBlocked: false };
|
if (stLower === 'trabajando') return { ...systemStatuses.find(st => st.name.toLowerCase().includes('trabajando')), isBlocked: false };
|
||||||
if (stLower === 'incidencia') return { ...systemStatuses.find(st => st.name.toLowerCase().includes('incidencia')), isBlocked: false };
|
if (stLower === 'incidencia') return { ...systemStatuses.find(st => st.name.toLowerCase().includes('incidencia')), isBlocked: false };
|
||||||
|
|||||||
Reference in New Issue
Block a user