From 5e4340adca41ebb93e0a13514ec2bbb24d53eb1b Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jun 2026 02:57:34 +0000 Subject: [PATCH] =?UTF-8?q?v1.3.7:=20s=C3=B3=20nomenclatura=20=E2=80=94=20?= =?UTF-8?q?Fechamento=20de=20Caixa=20/=20Saldo=20de=20Caixa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.html | 271 ++++++++++++------------------------------------- 1 file changed, 66 insertions(+), 205 deletions(-) diff --git a/src/index.html b/src/index.html index 2a18348..c4c2dce 100644 --- a/src/index.html +++ b/src/index.html @@ -1231,20 +1231,12 @@ async function tauriEnviar() { function buildConfirmHTML(data) { const fmt = v => 'R$ ' + (v || 0).toFixed(2).replace('.', ','); - const fmtNeg = v => (v < 0 ? '-' : '') + 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ','); - const sangrias_arr = data.sangrias_arr || data.sangrias || []; - const despesas_arr = data.despesas_arr || data.despesas || []; - const vales_arr = data.vales_arr || data.vales || []; - const receber_arr = data.receber_arr || data.receber || []; - const pixcnpj_arr = data.pixcnpj_arr || data.pixcnpj || []; - const cancelamentos_arr = data.cancelamentos_arr || data.cancelamentos || []; - - const sangrias = sangrias_arr.reduce((s,r) => s+(parseNum(r.retirada)||0)+(parseNum(r.valor)||0), 0); - const despesas = despesas_arr.reduce((s,r) => s+(parseNum(r.valor)||0), 0); - const vales = vales_arr.reduce((s,r) => s+(parseNum(r.valor)||0), 0); - const receber = receber_arr.reduce((s,r) => s+(parseNum(r.valor)||0), 0); - const pixcnpj = pixcnpj_arr.reduce((s,r) => s+(parseNum(r.valor)||0), 0); - const cancelamentos = cancelamentos_arr.reduce((s,c) => s+(parseNum(c.valor)||0), 0); + const sangrias = (data.sangrias_arr || data.sangrias || []).reduce((s,r) => s+(parseNum(r.retirada||r.valor||0)||0), 0); + const despesas = (data.despesas_arr || data.despesas || []).reduce((s,r) => s+(parseNum(r.valor||0)||0), 0); + const vales = (data.vales_arr || data.vales || []).reduce((s,r) => s+(parseNum(r.valor||0)||0), 0); + const receber = (data.receber_arr || data.receber || []).reduce((s,r) => s+(parseNum(r.valor||0)||0), 0); + const pixcnpj = (data.pixcnpj_arr || data.pixcnpj || []).reduce((s,r) => s+(parseNum(r.valor||0)||0), 0); + const cancelamentos = (data.cancelamentos_arr || data.cancelamentos || []).reduce((s,c) => s+(parseNum(c.valor||0)||0), 0); const cartCred = data.credito || 0; const cartDeb = data.debito || 0; const cartAli = data.alimentacao || 0; @@ -1253,79 +1245,6 @@ function buildConfirmHTML(data) { const saldoEsp = data.saldo_esperado || 0; const diferenca = fechamento - saldoEsp; const diffClass = diferenca === 0 ? '#2e7d32' : (diferenca > 0 ? '#e65100' : '#c0272d'); - const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca); - - // Monta linhas de detalhe - let detailSections = ''; - - function detailSection(title, rows, total) { - if (!rows && total <= 0) return ''; - let html = `
${title}
`; - if (rows) html += rows; - html += `
Total:${fmt(total)}
`; - return html; - } - - // Sangrias - let sangriaRows = ''; - sangrias_arr.forEach(s => { - const v = (parseNum(s.retirada)||0) + (parseNum(s.valor)||0); - if (v > 0) { - const hora = s.hora ? ` ${s.hora}` : ''; - const gerente = s.gerente ? ` (${s.gerente})` : ''; - sangriaRows += `
${hora}${gerente}${fmt(v)}
`; - } - }); - detailSections += detailSection('SANGRIAS', sangriaRows, sangrias); - - // Despesas - let despRows = ''; - despesas_arr.forEach(d => { - const v = parseNum(d.valor) || 0; - if (v > 0) { - const obs = d.obs ? ` ${d.obs}` : ''; - despRows += `
${d.desc||''}${obs}${fmt(v)}
`; - } - }); - detailSections += detailSection('DESPESAS', despRows, despesas); - - // Vales - let valesRows = ''; - vales_arr.forEach(v => { - const val = parseNum(v.valor) || 0; - if (val > 0) { - const obs = v.obs ? ` ${v.obs}` : ''; - valesRows += `
${v.nome||''}${obs}${fmt(val)}
`; - } - }); - detailSections += detailSection('VALES', valesRows, vales); - - // A Receber - let recRows = ''; - receber_arr.forEach(r => { - const v = parseNum(r.valor) || 0; - if (v > 0) recRows += `
${r.nome||''}${fmt(v)}
`; - }); - detailSections += detailSection('A RECEBER', recRows, receber); - - // PIX CNPJ - let pixRows = ''; - pixcnpj_arr.forEach(p => { - const v = parseNum(p.valor) || 0; - if (v > 0) pixRows += `
${p.nome||''}${fmt(v)}
`; - }); - detailSections += detailSection('PIX CNPJ', pixRows, pixcnpj); - - // Cancelamentos - let cancRows = ''; - cancelamentos_arr.forEach(c => { - const v = parseNum(c.valor) || 0; - if (c.numero || v > 0) { - const motivo = c.motivo ? ` ${c.motivo}` : ''; - cancRows += `
${c.numero||''}${motivo}${fmt(v)}
`; - } - }); - detailSections += detailSection('CANCELAMENTOS', cancRows, cancelamentos); return ` @@ -1341,11 +1260,6 @@ function buildConfirmHTML(data) { .row { display: flex; justify-content: space-between; padding: 2px 0; } .obs { font-size: 11px; color: #555; margin-top: 6px; white-space: pre-wrap; } .footer { text-align: center; font-size: 11px; color: #555; margin-top: 8px; } - .detail-section { margin: 6px 0; } - .detail-title { font-weight: bold; font-size: 13px; border-top: 1px dashed #b3d9f7; padding-top: 3px; } - .detail-row { display: flex; justify-content: space-between; padding: 1px 0; font-size: 12px; } - .detail-total { display: flex; justify-content: space-between; padding: 1px 0; font-weight: bold; border-top: 1px dotted #b3d9f7; font-size: 12px; } - .c2 { color: #888; } @media print { body { margin: 0; } } @@ -1355,8 +1269,6 @@ function buildConfirmHTML(data) {
📅 Data: ${data.data}   👤 Operador: ${data.operador}   ⏰ Turno: ${data.turno}

-${detailSections} -
💸 Sangrias: ${fmt(sangrias)}
📝 Despesas: ${fmt(despesas)}
💰 Vales: ${fmt(vales)}
@@ -1369,115 +1281,59 @@ ${detailSections}
📋 Fechamento: ${fmt(fechamento)}

🎯 Saldo Esperado: ${fmt(saldoEsp)}
-
📐 Diferença: ${diffStr}
+
📐 Diferença: ${fmt(diferenca)}
ID: ${data.loja}_${data.data}_${data.operador}
`; } -// ─── Print Preview Window - +// ─── Print Preview Window ────────────────────────────────────────────────── function buildPrintHTML(data) { const fmt = v => 'R$ ' + (v || 0).toFixed(2).replace('.', ','); - const fmtNeg = v => (v < 0 ? '-' : '') + 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ','); - const sangrias_arr = data.sangrias_arr || data.sangrias || []; - const despesas_arr = data.despesas_arr || data.despesas || []; - const vales_arr = data.vales_arr || data.vales || []; - const receber_arr = data.receber_arr || data.receber || []; - const pixcnpj_arr = data.pixcnpj_arr || data.pixcnpj || []; - const cancelamentos_arr = data.cancelamentos_arr || data.cancelamentos || []; - - const sangrias = sangrias_arr.reduce((s,r) => s+(parseNum(r.retirada)||0)+(parseNum(r.valor)||0), 0); - const despesas = despesas_arr.reduce((s,r) => s+(parseNum(r.valor)||0), 0); - const vales = vales_arr.reduce((s,r) => s+(parseNum(r.valor)||0), 0); - const receber = receber_arr.reduce((s,r) => s+(parseNum(r.valor)||0), 0); - const pixcnpj = pixcnpj_arr.reduce((s,r) => s+(parseNum(r.valor)||0), 0); - const cancelamentos = cancelamentos_arr.reduce((s,c) => s+(parseNum(c.valor)||0), 0); - const cartCred = data.credito || 0; - const cartDeb = data.debito || 0; - const cartAli = data.alimentacao || 0; - const cartPix = data.voucher || data.pix || 0; - const fechamento = data.fechamento || data.sys_total || 0; - const saldoEsp = data.saldo_esperado || 0; - const diferenca = data.diferenca !== undefined ? data.diferenca : (fechamento - saldoEsp); - const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca); + // Usa a diferenca ja calculada pelo tauriRecibo (sys_total - saldo_esperado), + // igual ao modal de confirmacao — nao recalcula de fechamento. + const diferenca = data.diferenca !== undefined ? data.diferenca + : ((data.sys_total || 0) - (data.saldo_esperado || 0)); + const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmt(diferenca); const diffColor = diferenca === 0 ? '#2e7d32' : (diferenca > 0 ? '#e65100' : '#c0272d'); - let detailSections = ''; - - function detailSection(title, rows, total) { - if (!rows && total <= 0) return ''; - let html = `
${title}
`; - if (rows) html += rows; - html += `
Total:${fmt(total)}
`; - return html; - } - + let rows = ''; + // Cancelamentos (sum the array first — single cancelamentos is a float total, array is from confirm-print) + const cancelTotal = Array.isArray(data.cancelamentos) + ? data.cancelamentos.reduce((s, c) => s + (parseNum(c.valor || 0) || 0), 0) + : (data.cancelamentos || 0); + // PIX total (flat number from tauriRecibo; pixcnpj is also flat total) + const pixTotal = data.pix || data.voucher || 0; + const pixCnpjTotal = typeof data.pixcnpj === 'number' ? data.pixcnpj : 0; // Sangrias - let sangriaRows = ''; - sangrias_arr.forEach(s => { - const v = (parseNum(s.retirada)||0) + (parseNum(s.valor)||0); - if (v > 0) { - const hora = s.hora ? ` ${s.hora}` : ''; - const gerente = s.gerente ? ` (${s.gerente})` : ''; - sangriaRows += `
${hora}${gerente}${fmt(v)}
`; - } - }); - detailSections += detailSection('SANGRIAS', sangriaRows, sangrias); - + if (data.sangrias && data.sangrias.length > 0) { + data.sangrias.forEach(s => { if (s.hora || s.retirada) rows += `${s.hora||''}${fmt(s.retirada)}${s.gerente||''}`; }); + } // Despesas - let despRows = ''; - despesas_arr.forEach(d => { - const v = parseNum(d.valor) || 0; - if (v > 0) { - const obs = d.obs ? ` ${d.obs}` : ''; - despRows += `
${d.desc||''}${obs}${fmt(v)}
`; - } - }); - detailSections += detailSection('DESPESAS', despRows, despesas); - + if (data.despesas && data.despesas.length > 0) { + data.despesas.forEach(d => { if (d.desc || d.valor) rows += `${d.desc||''}${fmt(d.valor)}${d.obs||''}`; }); + } // Vales - let valesRows = ''; - vales_arr.forEach(v => { - const val = parseNum(v.valor) || 0; - if (val > 0) { - const obs = v.obs ? ` ${v.obs}` : ''; - valesRows += `
${v.nome||''}${obs}${fmt(val)}
`; - } - }); - detailSections += detailSection('VALES', valesRows, vales); - - // A Receber - let recRows = ''; - receber_arr.forEach(r => { - const v = parseNum(r.valor) || 0; - if (v > 0) recRows += `
${r.nome||''}${fmt(v)}
`; - }); - detailSections += detailSection('A RECEBER', recRows, receber); - - // PIX CNPJ - let pixRows = ''; - pixcnpj_arr.forEach(p => { - const v = parseNum(p.valor) || 0; - if (v > 0) pixRows += `
${p.nome||''}${fmt(v)}
`; - }); - detailSections += detailSection('PIX CNPJ', pixRows, pixcnpj); - + if (data.vales && data.vales.length > 0) { + data.vales.forEach(v => { if (v.nome || v.valor) rows += `${v.nome||''}${fmt(v.valor)}${v.obs||''}`; }); + } + // Receber + if (data.receber && data.receber.length > 0) { + data.receber.forEach(r => { if (r.nome || r.valor) rows += `${r.nome||''}${fmt(r.valor)}`; }); + } + // PIX CNPJ (flat total, not array) + if (pixCnpjTotal > 0) { + rows += `PIX CNPJ${fmt(pixCnpjTotal)}`; + } // Cancelamentos - let cancRows = ''; - cancelamentos_arr.forEach(c => { - const v = parseNum(c.valor) || 0; - if (c.numero || v > 0) { - const motivo = c.motivo ? ` ${c.motivo}` : ''; - cancRows += `
${c.numero||''}${motivo}${fmt(v)}
`; - } - }); - detailSections += detailSection('CANCELAMENTOS', cancRows, cancelamentos); + if (cancelTotal > 0) { + rows += `Cancelamentos${fmt(cancelTotal)}`; + } return ` -Recibo de Fechamento +Relatório de Fechamento @@ -1507,27 +1366,29 @@ function buildPrintHTML(data) {
Operador:${data.operador}
Turno:${data.turno}
-${detailSections} +
ENTRADAS
+
Saldo Troco:${fmt(data.saldo_troco)}
+
Fechamento:${fmt(data.fechamento)}
+
Saldo Esperado:${fmt(data.saldo_esperado)}
+ +${rows ? `
DETALHES
${rows}
` : ''} + +${data.observacoes ? `
Obs: ${data.observacoes}
` : ''} +
-
💸 Sangrias:${fmt(sangrias)}
-
📝 Despesas:${fmt(despesas)}
-
💰 Vales:${fmt(vales)}
-
👥 À Receber:${fmt(receber)}
-
🔵 PIX CNPJ:${fmt(pixcnpj)}
-
💳 Crédito:${fmt(cartCred)}
-
💳 Débito:${fmt(cartDeb)}
-
💳 Alimentação:${fmt(cartAli)}
-
❌ Cancelamentos:${fmt(cancelamentos)}
+
CARTÕES
+
Crédito:${fmt(data.credito||0)}
+
Débito:${fmt(data.debito||0)}
+
Alimentação:${fmt(data.alimentacao||0)}
+
PIX Cartão:${fmt(pixTotal)}
+
Cancelamentos:${fmt(cancelTotal)}
+
DIFERENÇA: ${diffStr}
-${data.observacoes ? `
Obs: ${data.observacoes}
` : ''} `; } - -} - function openPrintPreview(data, mode) { const html = mode === 'confirm' ? buildConfirmHTML(data) : buildPrintHTML(data); // Remove preview anterior se existir