diff --git a/contabilidad.html b/contabilidad.html index bea7822..c544999 100644 --- a/contabilidad.html +++ b/contabilidad.html @@ -545,59 +545,85 @@ function renderBudgets() { const list = document.getElementById('budgetsList'); list.innerHTML = ""; - if(myBudgets.length === 0) { list.innerHTML = `
Sin presupuestos
`; return; } + if(myBudgets.length === 0) { + list.innerHTML = `
Sin presupuestos generados aún.
`; + return; + } myBudgets.forEach(b => { - const date = new Date(b.created_at).toLocaleDateString('es-ES'); + const bDate = new Date(b.created_at); + const dateDisplay = bDate.toLocaleDateString('es-ES'); + // 🔴 LÓGICA DE CADUCIDAD (30 DÍAS) + const diffDays = Math.ceil(Math.abs(new Date() - bDate) / (1000 * 60 * 60 * 24)); + const isExpired = diffDays > 30; + let bStatus = ''; let isAnulado = false; if (b.linked_service_status_name && b.linked_service_status_name.toLowerCase().includes('anulado')) { isAnulado = true; } - if(b.status === 'pending') { - bStatus = ` Pte. Resolver`; - } else if(b.status === 'rejected') { - bStatus = ` Rechazado`; - } else if(b.status === 'accepted') { - bStatus = ` Aceptado`; - } else if(b.status === 'converted') { + // 🎨 DEFINICIÓN DE ETIQUETAS UNIFICADAS + if (b.status === 'paid') { + bStatus = ` Pagado Online`; + } else if (isExpired && b.status !== 'rejected' && b.status !== 'converted') { + bStatus = ` Caducado`; + } else if (b.status === 'pending') { + bStatus = ` Pte. Resolver`; + } else if (b.status === 'rejected') { + bStatus = ` Rechazado`; + } else if (b.status === 'accepted') { + bStatus = ` Aceptado`; + } else if (b.status === 'converted') { if (isAnulado) { - bStatus = ` Servicio Anulado`; + bStatus = ` Servicio Anulado`; } else { const sName = b.linked_service_status_name || 'En gestión'; - bStatus = ` ${sName}`; + bStatus = ` ${sName}`; } } + // 🛠️ LÓGICA DE ACCIONES (Botón de "Crear Servicio") let actions = ''; - if(b.status === 'pending') { + if(b.status === 'pending' && !isExpired) { actions = ` - - + + `; - } else if(b.status === 'accepted') { - actions = ``; + } else if((b.status === 'accepted' || b.status === 'paid') && !isExpired) { + // El botón de crear servicio aparece tanto si está aceptado por firma como si ya está PAGADO + actions = ``; } - // Botón de PDF - actions += ``; - - // Botón de Borrar - actions += ``; + // Botones fijos (PDF y Borrar) + let utilityButtons = ` + + + `; list.innerHTML += ` -
+
-

- #PRE-${b.id} ${b.client_name} +

+ #PRE-${b.id} ${b.client_name} +

+

+ ${dateDisplay} + + ${b.client_phone}

-

${date} - 📞 ${b.client_phone}

-

${b.client_address}

-

${b.total}€

-
${bStatus} ${actions}
+
+

${b.client_address || 'Sin dirección'}

+
+
+

${parseFloat(b.total).toFixed(2)}€

+
+
+
${bStatus}
+
${actions} ${utilityButtons}
+
`; });