Actualizar contabilidad.html
This commit is contained in:
@@ -481,18 +481,23 @@
|
|||||||
|
|
||||||
let bStatus = '';
|
let bStatus = '';
|
||||||
// Comprobamos si nos viene el estado del servicio como anulado desde el backend
|
// Comprobamos si nos viene el estado del servicio como anulado desde el backend
|
||||||
let isAnulado = b.linked_service_status_name && b.linked_service_status_name.toLowerCase().includes('anulado');
|
let isAnulado = false;
|
||||||
|
if (b.linked_service_status_name && b.linked_service_status_name.toLowerCase().includes('anulado')) {
|
||||||
|
isAnulado = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(b.status === 'pending') bStatus = `<span class="bg-amber-100 text-amber-700 px-2 py-1 rounded text-[10px] font-black uppercase"><i data-lucide="clock" class="w-3 h-3 inline"></i> Pte. Resolver</span>`;
|
if(b.status === 'pending') {
|
||||||
else if(b.status === 'rejected') bStatus = `<span class="bg-red-100 text-red-700 px-2 py-1 rounded text-[10px] font-black uppercase"><i data-lucide="x" class="w-3 h-3 inline"></i> Rechazado</span>`;
|
bStatus = `<span class="bg-amber-100 text-amber-700 px-2 py-1 rounded text-[10px] font-black uppercase"><i data-lucide="clock" class="w-3 h-3 inline"></i> Pte. Resolver</span>`;
|
||||||
else if(b.status === 'accepted') bStatus = `<span class="bg-blue-100 text-blue-700 px-2 py-1 rounded text-[10px] font-black uppercase"><i data-lucide="check" class="w-3 h-3 inline"></i> Aceptado</span>`;
|
} else if(b.status === 'rejected') {
|
||||||
else if(b.status === 'converted') {
|
bStatus = `<span class="bg-red-100 text-red-700 px-2 py-1 rounded text-[10px] font-black uppercase"><i data-lucide="x" class="w-3 h-3 inline"></i> Rechazado</span>`;
|
||||||
|
} else if(b.status === 'accepted') {
|
||||||
|
bStatus = `<span class="bg-blue-100 text-blue-700 px-2 py-1 rounded text-[10px] font-black uppercase"><i data-lucide="check" class="w-3 h-3 inline"></i> Aceptado</span>`;
|
||||||
|
} else if(b.status === 'converted') {
|
||||||
if (isAnulado) {
|
if (isAnulado) {
|
||||||
bStatus = `<span class="bg-red-100 text-red-700 px-2 py-1 rounded text-[10px] font-black uppercase shadow-sm"><i data-lucide="x-circle" class="w-3 h-3 inline"></i> Servicio Anulado</span>`;
|
bStatus = `<span class="bg-red-100 text-red-700 px-2 py-1 rounded text-[10px] font-black uppercase shadow-sm border border-red-200"><i data-lucide="x-circle" class="w-3 h-3 inline"></i> Servicio Anulado</span>`;
|
||||||
} else {
|
} else {
|
||||||
// Si está convertido y NO está anulado, mostramos el estado real del panel operativo
|
|
||||||
const sName = b.linked_service_status_name || 'En gestión';
|
const sName = b.linked_service_status_name || 'En gestión';
|
||||||
bStatus = `<span class="bg-emerald-100 text-emerald-700 px-2 py-1 rounded text-[10px] font-black uppercase shadow-sm" title="Estado del Servicio en Operativa"><i data-lucide="briefcase" class="w-3 h-3 inline"></i> ${sName}</span>`;
|
bStatus = `<span class="bg-emerald-100 text-emerald-700 px-2 py-1 rounded text-[10px] font-black uppercase shadow-sm border border-emerald-200" title="Estado en Operativa"><i data-lucide="briefcase" class="w-3 h-3 inline"></i> ${sName}</span>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,7 +511,7 @@
|
|||||||
actions = `<button onclick="openConvertModal(${b.id})" class="bg-emerald-500 text-white px-3 py-1.5 rounded font-black text-[10px] uppercase tracking-widest shadow-md hover:bg-emerald-600">Crear Servicio</button>`;
|
actions = `<button onclick="openConvertModal(${b.id})" class="bg-emerald-500 text-white px-3 py-1.5 rounded font-black text-[10px] uppercase tracking-widest shadow-md hover:bg-emerald-600">Crear Servicio</button>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// La papelera de borrar se muestra siempre, y le pasamos a la función si está anulado
|
// La papelera de borrar se muestra siempre, y le pasamos el estado 'isAnulado'
|
||||||
actions += `<button onclick="deleteBudget(${b.id}, '${b.status}', ${isAnulado})" class="text-slate-300 hover:text-red-500 p-2 ml-2 transition-colors" title="Borrar Presupuesto"><i data-lucide="trash-2" class="w-4 h-4"></i></button>`;
|
actions += `<button onclick="deleteBudget(${b.id}, '${b.status}', ${isAnulado})" class="text-slate-300 hover:text-red-500 p-2 ml-2 transition-colors" title="Borrar Presupuesto"><i data-lucide="trash-2" class="w-4 h-4"></i></button>`;
|
||||||
|
|
||||||
list.innerHTML += `
|
list.innerHTML += `
|
||||||
@@ -526,17 +531,10 @@
|
|||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateBudgetStatus(id, status) {
|
async function deleteBudget(id, status, isAnulado) {
|
||||||
if(!confirm("¿Actualizar estado?")) return;
|
// Si está convertido/aceptado, Y NO ESTÁ anulado, bloqueamos
|
||||||
await fetch(`${API_URL}/budgets/${id}/status`, { method: 'PATCH', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify({status}) });
|
if ((status === 'accepted' || status === 'converted') && !isAnulado) {
|
||||||
loadBudgets();
|
return showToast("⚠️ Para borrar el presupuesto, el servicio vinculado debe estar Anulado.");
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async function deleteBudget(id, status) {
|
|
||||||
// Protección en el lado del cliente (Frontend)
|
|
||||||
if (status === 'accepted' || status === 'converted') {
|
|
||||||
return showToast("⚠️ Para borrar el presupuesto, primero debes rechazarlo/anularlo.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!confirm("¿Seguro que quieres borrar este presupuesto definitivamente?")) return;
|
if (!confirm("¿Seguro que quieres borrar este presupuesto definitivamente?")) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user