From 08c5d5d796958be11f1c34d35bf949d7935c56c3 Mon Sep 17 00:00:00 2001 From: marsalva Date: Sun, 1 Mar 2026 20:27:45 +0000 Subject: [PATCH] Actualizar contabilidad.html --- contabilidad.html | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/contabilidad.html b/contabilidad.html index 727a27f..56e0987 100644 --- a/contabilidad.html +++ b/contabilidad.html @@ -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) // ==========================================