Actualizar contabilidad.html
This commit is contained in:
@@ -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)
|
||||
// ==========================================
|
||||
|
||||
Reference in New Issue
Block a user