Actualizar contabilidad.html

This commit is contained in:
2026-08-02 13:37:36 +00:00
parent 4a6c2bebe8
commit d87c83cea5

View File

@@ -866,16 +866,28 @@
const editId = document.getElementById('editBudgetId').value;
if (editId) {
await fetch(`${API_URL}/budgets/${editId}`, { method: 'PUT', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify(payload) });
showToast("Presupuesto actualizado");
} else {
await fetch(`${API_URL}/budgets`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify(payload) });
showToast("Presupuesto guardado");
}
try {
let res;
if (editId) {
res = await fetch(`${API_URL}/budgets/${editId}`, { method: 'PUT', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify(payload) });
} else {
res = await fetch(`${API_URL}/budgets`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify(payload) });
}
document.getElementById('budgetModal').classList.add('hidden');
loadBudgets();
const data = await res.json();
if (res.ok && data.ok !== false) {
document.getElementById('budgetModal').classList.add('hidden');
showToast(editId ? "✅ Presupuesto actualizado" : "✅ Presupuesto guardado");
loadBudgets();
} else {
showToast("❌ Error: " + (data.error || "El servidor no lo actualizó"));
console.error("Respuesta del servidor:", data);
}
} catch (error) {
showToast("❌ Error de conexión al guardar.");
console.error(error);
}
}
function openArticlesModal() {