Actualizar presupuestos.html
This commit is contained in:
@@ -720,20 +720,33 @@
|
|||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
|
||||||
try {
|
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 res = await fetch(`${API_URL}/services/active`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if(data.ok && data.services) {
|
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) {
|
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>';
|
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;
|
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 => {
|
list.innerHTML = dayServices.map(s => {
|
||||||
const raw = s.raw_data || {};
|
const raw = s.raw_data || {};
|
||||||
const pob = raw['Población'] || raw['POBLACION-PROVINCIA'] || raw['Dirección'] || 'Sin ubicación';
|
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 `
|
return `
|
||||||
<div class="flex justify-between items-center bg-white p-2.5 rounded-lg border border-blue-100 shadow-sm">
|
<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>
|
<span class="font-black text-blue-700 bg-blue-50 px-2 py-0.5 rounded border border-blue-100">${time}</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user