diff --git a/presupuestos.html b/presupuestos.html index 6b8096c..cf20f77 100644 --- a/presupuestos.html +++ b/presupuestos.html @@ -720,20 +720,33 @@ lucide.createIcons(); try { - // Descargamos las averías desde el dashboard del técnico const res = await fetch(`${API_URL}/services/active`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); const data = await res.json(); + if(data.ok && data.services) { - const dayServices = data.services.filter(s => s.scheduled_date === dateStr && s.status !== 'archived'); + // 🛑 FIX: Buscamos la fecha DENTRO de raw_data + const dayServices = data.services.filter(s => { + const raw = s.raw_data || {}; + return raw.scheduled_date === dateStr && s.status !== 'archived'; + }); + if(dayServices.length === 0) { list.innerHTML = '

Libre: No tienes nada agendado este día.

'; return; } - dayServices.sort((a, b) => (a.scheduled_time || "23:59").localeCompare(b.scheduled_time || "23:59")); + + // 🛑 FIX: Ordenamos leyendo la hora DENTRO de raw_data + dayServices.sort((a, b) => { + const timeA = (a.raw_data && a.raw_data.scheduled_time) ? a.raw_data.scheduled_time : "23:59"; + const timeB = (b.raw_data && b.raw_data.scheduled_time) ? b.raw_data.scheduled_time : "23:59"; + return timeA.localeCompare(timeB); + }); + list.innerHTML = dayServices.map(s => { const raw = s.raw_data || {}; const pob = raw['Población'] || raw['POBLACION-PROVINCIA'] || raw['Dirección'] || 'Sin ubicación'; - const time = s.scheduled_time ? s.scheduled_time.substring(0,5) : 'S/H'; + // 🛑 FIX: Leemos la hora a pintar DENTRO de raw_data + const time = raw.scheduled_time ? raw.scheduled_time.substring(0,5) : 'S/H'; return `
${time}