Actualizar presupuestos.html

This commit is contained in:
2026-03-29 21:30:34 +00:00
parent 4d80f2d013
commit 6716c84cff

View File

@@ -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 = '<p class="text-emerald-600 font-bold text-center py-2 bg-white rounded-lg border border-emerald-100 shadow-sm">Libre: No tienes nada agendado este día.</p>';
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 `
<div class="flex justify-between items-center bg-white p-2.5 rounded-lg border border-blue-100 shadow-sm">
<span class="font-black text-blue-700 bg-blue-50 px-2 py-0.5 rounded border border-blue-100">${time}</span>