Actualizar contabilidad.html
This commit is contained in:
@@ -866,16 +866,28 @@
|
|||||||
|
|
||||||
const editId = document.getElementById('editBudgetId').value;
|
const editId = document.getElementById('editBudgetId').value;
|
||||||
|
|
||||||
if (editId) {
|
try {
|
||||||
await fetch(`${API_URL}/budgets/${editId}`, { method: 'PUT', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify(payload) });
|
let res;
|
||||||
showToast("Presupuesto actualizado");
|
if (editId) {
|
||||||
} else {
|
res = await fetch(`${API_URL}/budgets/${editId}`, { method: 'PUT', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify(payload) });
|
||||||
await fetch(`${API_URL}/budgets`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify(payload) });
|
} else {
|
||||||
showToast("Presupuesto guardado");
|
res = await fetch(`${API_URL}/budgets`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify(payload) });
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('budgetModal').classList.add('hidden');
|
|
||||||
loadBudgets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function openArticlesModal() {
|
function openArticlesModal() {
|
||||||
|
|||||||
Reference in New Issue
Block a user