diff --git a/calendario.html b/calendario.html index a3e519b..4114710 100644 --- a/calendario.html +++ b/calendario.html @@ -85,6 +85,12 @@

+ +
+

Datos del Servicio

+
+
+
@@ -140,16 +146,16 @@ let localServices = []; let systemStatuses = []; + let systemGuilds = []; + let currentWeekStart = new Date(); let selectedDateStr = ""; - // Helper seguro para iconos function safeLoadIcons() { try { if (typeof lucide !== 'undefined') lucide.createIcons(); } catch(e) { console.warn("Iconos no cargados aún"); } } - // Helper seguro para fechas function toISODate(dateObj) { try { if (!dateObj || isNaN(dateObj)) return ""; @@ -167,7 +173,7 @@ return new Date(date.setDate(diff)); } - document.addEventListener("DOMContentLoaded", () => { + document.addEventListener("DOMContentLoaded", async () => { if (!localStorage.getItem("token") || localStorage.getItem("role") !== 'operario') { window.location.href = "index.html"; return; } @@ -179,13 +185,25 @@ currentWeekStart = getMonday(today); selectedDateStr = toISODate(today); buildWeekCalendar(); + + // Cargar datos paralelos loadStatuses(); + await loadGuilds(); refreshData(); } catch(error) { alert("Error iniciando calendario: " + error.message); } }); + // Cargar gremios para saber los nombres + async function loadGuilds() { + try { + const res = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); + const data = await res.json(); + if(data.ok) systemGuilds = data.guilds; + } catch(e){} + } + function buildWeekCalendar() { try { const strip = document.getElementById('weekStrip'); @@ -296,7 +314,6 @@ return d === selectedDateStr; }); - // Ordenación segura a prueba de fallos de formato dayServices.sort((a, b) => { const timeA = String(a.raw_data.scheduled_time || "23:59"); const timeB = String(b.raw_data.scheduled_time || "23:59"); @@ -318,6 +335,7 @@ const raw = s.raw_data || {}; const time = raw.scheduled_time || "A convenir"; + // BLOQUEOS if (s.provider === 'SYSTEM_BLOCK') { const desc = raw["Descripción"] || "Operario no disponible"; return ` @@ -333,21 +351,42 @@
`; } + // SERVICIOS NORMALES const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado"; const addr = raw["Dirección"] || "Sin dirección"; const pop = raw["Población"] || ""; const isUrgent = s.is_urgent; + // Extracción Compañía y Gremio + let compRaw = raw["Compañía"] || raw["COMPAÑIA"] || raw["Procedencia"] || "Particular"; + let compShort = compRaw.split('-')[0].trim().substring(0, 15); + if(compRaw.includes("MULTI")) compShort = "MULTIASISTENCIA"; + if(compRaw.includes("HOME")) compShort = "HOMESERVE"; + + const rawGuildId = s.guild_id || raw.guild_id || raw['guild_id']; + const guildObj = systemGuilds.find(g => String(g.id) === String(rawGuildId)); + const guildName = guildObj ? guildObj.name : "Reparación"; + return ` -
-
- - ${time} +
+ ${isUrgent ? '
Urgente
' : ''} + +
+ + ${time}
+
-

${name}

-

${addr}, ${pop}

- ${isUrgent ? 'Urgente' : ''} +
+ ${compShort} + ${guildName} +
+ +

${name}

+ +

+ ${addr}, ${pop} +

`; }).join(''); @@ -374,10 +413,37 @@ const fullAddress = `${raw["Dirección"] || ""}, ${raw["Código Postal"] || ""} ${raw["Población"] || ""}`; document.getElementById('detAddress').innerText = fullAddress; + // VOLCAR TODOS LOS DATOS EXTRA + const detailsContainer = document.getElementById('detExtraInfo'); + let detailsHtml = ''; + + // Ignoramos los campos que ya están enseñados arriba por defecto + const skipKeys = ["Nombre Cliente", "CLIENTE", "Dirección", "DOMICILIO", "Población", "POBLACION-PROVINCIA", "scheduled_date", "scheduled_time", "status_operativo", "assigned_to", "guild_id", "Código Postal"]; + + for(let key in raw) { + if(skipKeys.includes(key)) continue; + + let val = raw[key]; + if(typeof val === 'object') val = JSON.stringify(val); // Por si es un JSON anidado + if(!val || val.trim() === "") continue; + + detailsHtml += ` +
+

${key}

+

${val}

+
+ `; + } + + if(detailsHtml === '') detailsHtml = '

No hay más datos proporcionados.

'; + detailsContainer.innerHTML = detailsHtml; + + // Mostrar modal const modal = document.getElementById('serviceModal'); modal.classList.remove('hidden'); setTimeout(() => modal.classList.remove('translate-y-full'), 10); + // Iniciar GPS automático calculateDistance(fullAddress); }