Actualizar contabilidad.html

This commit is contained in:
2026-03-01 20:27:45 +00:00
parent f57204786e
commit 08c5d5d796

View File

@@ -517,6 +517,33 @@
loadBudgets();
}
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;
try {
const res = await fetch(`${API_URL}/budgets/${id}`, {
method: 'DELETE',
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
});
const data = await res.json();
if (data.ok) {
showToast("🗑️ Presupuesto eliminado");
loadBudgets();
} else {
showToast("❌ " + (data.error || "Error al borrar"));
}
} catch (e) {
showToast("❌ Error de conexión");
}
}
// ==========================================
// LÓGICA DE CONVERSIÓN A SERVICIO (MODAL)
// ==========================================