Actualizar contabilidad.html
This commit is contained in:
@@ -850,7 +850,7 @@
|
||||
|
||||
const items = [];
|
||||
document.querySelectorAll('#budgetLines > div').forEach(line => {
|
||||
const idEl = line.querySelector('.b-item-id'); // Por si lograste poner el input oculto
|
||||
const idEl = line.querySelector('.b-item-id');
|
||||
const conceptEl = line.querySelector('.b-concept');
|
||||
const qtyEl = line.querySelector('.b-qty');
|
||||
const priceEl = line.querySelector('.b-price');
|
||||
@@ -911,50 +911,6 @@
|
||||
console.error("Error en fetch:", error);
|
||||
}
|
||||
}
|
||||
const name = document.getElementById('bName').value;
|
||||
if(!name) return showToast("El nombre es obligatorio");
|
||||
|
||||
const items = [];
|
||||
document.querySelectorAll('#budgetLines > div').forEach(line => {
|
||||
const c = line.querySelector('.b-concept').value;
|
||||
const q = parseFloat(line.querySelector('.b-qty').value) || 0;
|
||||
const p = parseFloat(line.querySelector('.b-price').value) || 0;
|
||||
if(c && q > 0) items.push({concept: c, qty: q, price: p});
|
||||
});
|
||||
|
||||
if(items.length === 0) return showToast("Añade al menos un concepto");
|
||||
|
||||
const sub = parseFloat(document.getElementById('bSubtotal').innerText);
|
||||
const tax = parseFloat(document.getElementById('bTax').innerText);
|
||||
const tot = parseFloat(document.getElementById('bTotal').innerText);
|
||||
|
||||
const payload = { client_phone: phone, client_name: name, client_address: document.getElementById('bAddress').value, items, subtotal: sub, tax, total: tot };
|
||||
|
||||
const editId = document.getElementById('editBudgetId').value;
|
||||
|
||||
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) });
|
||||
}
|
||||
|
||||
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() {
|
||||
renderArticles();
|
||||
|
||||
Reference in New Issue
Block a user