diff --git a/src/index.html b/src/index.html index 6eff590..91ac001 100644 --- a/src/index.html +++ b/src/index.html @@ -2527,7 +2527,10 @@ function editTableHTML(id, headers, rows, numericCols) { const displayVal = (val !== null && val !== undefined && val !== '') ? (isNum ? fmtNum(val) : val) : ''; - return ``; + const extra = isNum + ? `oninput="window._recalcEditTotals()" onblur="this.value=fmtBR(this)" ` + : ''; + return ``; }).join(''); return `${cells}`; }).join(''); @@ -2586,6 +2589,35 @@ function readEditTables() { return tables; } +// Recalcula todos os totais do modal de edição e atualiza o display +window._recalcEditTotals = function() { + const tables = readEditTables(); + const cartCred_tot = (tables.credito || []).reduce((s, r) => s + (r[0] || 0), 0); + const cartDeb_tot = (tables.debito || []).reduce((s, r) => s + (r[0] || 0), 0); + const cartAli_tot = (tables.alimentacao || []).reduce((s, r) => s + (r[0] || 0), 0); + const cartPix_tot = (tables.pix || []).reduce((s, r) => s + (r[0] || 0), 0); + const vales_tot = (tables.vales || []).reduce((s, r) => s + (r[1] || 0), 0); + const desp_tot = (tables.despesas || []).reduce((s, r) => s + (r[2] || 0), 0); + const sang_tot = (tables.sangrias || []).reduce((s, r) => s + (r[1] || 0), 0); + const pixcnpj_tot = (tables.pixcnpj || []).reduce((s, r) => s + (r[1] || 0), 0); + const recv_tot = (tables.receber || []).reduce((s, r) => s + (r[1] || 0), 0); + const canc_tot = (tables.cancelamentos || []).reduce((s, r) => s + (r[1] || 0), 0); + + const el = id => document.getElementById(id); + const fmtTot = v => v > 0 ? 'R$ ' + v.toLocaleString('pt-BR', { minimumFractionDigits: 2 }) : '—'; + + if (el('edit-total-credito')) el('edit-total-credito').textContent = fmtTot(cartCred_tot); + if (el('edit-total-debito')) el('edit-total-debito').textContent = fmtTot(cartDeb_tot); + if (el('edit-total-alimentacao')) el('edit-total-alimentacao').textContent = fmtTot(cartAli_tot); + if (el('edit-total-pix')) el('edit-total-pix').textContent = fmtTot(cartPix_tot); + if (el('edit-total-vales')) el('edit-total-vales').textContent = fmtTot(vales_tot); + if (el('edit-total-despesas')) el('edit-total-despesas').textContent = fmtTot(desp_tot); + if (el('edit-total-sangrias')) el('edit-total-sangrias').textContent = fmtTot(sang_tot); + if (el('edit-total-pixcnpj')) el('edit-total-pixcnpj').textContent = fmtTot(pixcnpj_tot); + if (el('edit-total-receber')) el('edit-total-receber').textContent = fmtTot(recv_tot); + if (el('edit-total-cancel')) el('edit-total-cancel').textContent = fmtTot(canc_tot); +}; + // Modal de edição completo com todas as grades function openEditModal(full) { window._editModalOpen = true; @@ -2649,10 +2681,12 @@ function openEditModal(full) {
Total Débito: ${fmtMR(full.total_cartao_debito||0)}
Total Alimentação: ${fmtMR(full.total_cartao_alimentacao||0)}
Total PIX: ${fmtMR(full.total_cartao_pix||0)}
-
Total Sangrias: ${fmtMR(full.total_sangrias||0)}
-
Total Despesas: ${fmtMR(full.total_despesas||0)}
-
Total Vales: ${fmtMR(full.total_vales||0)}
-
Total PIX CNPJ: ${fmtMR(full.total_pixcnpj||0)}
+
Total Sangrias: ${fmtMR(full.total_sangrias||0)}
+
Total Despesas: ${fmtMR(full.total_despesas||0)}
+
Total Vales: ${fmtMR(full.total_vales||0)}
+
Total PIX CNPJ: ${fmtMR(full.total_pixcnpj||0)}
+
Total Receber: ${fmtMR(full.total_areceber||0)}
+
Total Cancel: ${fmtMR(full.total_cancelamentos||0)}
`; const overlay = document.createElement('div');