From c01133f39c89ac448df2832310294c1025a2e351 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jun 2026 02:52:08 +0000 Subject: [PATCH] =?UTF-8?q?v1.3.6:=20nomenclatura=20trocada;=20relat=C3=B3?= =?UTF-8?q?rios=20com=20todos=20os=20lan=C3=A7amentos=20detalhados=20por?= =?UTF-8?q?=20se=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.html | 275 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 207 insertions(+), 68 deletions(-) diff --git a/src/index.html b/src/index.html index 6e70cef..2a18348 100644 --- a/src/index.html +++ b/src/index.html @@ -384,7 +384,7 @@
-
🖥️ Saldo de Caixa (Valores do Sistema)
+
🖥️ Fechamento de Caixa
Troco (+)
Crédito (+)
@@ -415,7 +415,7 @@
-
🛒 Fechamento (Valores Contados)
+
🛒 Saldo de Caixa
Dinheiro
Cartões
@@ -1231,12 +1231,20 @@ async function tauriEnviar() { function buildConfirmHTML(data) { const fmt = v => 'R$ ' + (v || 0).toFixed(2).replace('.', ','); - 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 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; @@ -1245,6 +1253,79 @@ 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 ` @@ -1260,6 +1341,11 @@ 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; } } @@ -1269,6 +1355,8 @@ function buildConfirmHTML(data) {
📅 Data: ${data.data}   👤 Operador: ${data.operador}   ⏰ Turno: ${data.turno}

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

🎯 Saldo Esperado: ${fmt(saldoEsp)}
-
📐 Diferença: ${fmt(diferenca)}
+
📐 Diferença: ${diffStr}
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('.', ','); - // 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 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); const diffColor = diferenca === 0 ? '#2e7d32' : (diferenca > 0 ? '#e65100' : '#c0272d'); - 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; + 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 - if (data.sangrias && data.sangrias.length > 0) { - data.sangrias.forEach(s => { if (s.hora || s.retirada) rows += `${s.hora||''}${fmt(s.retirada)}${s.gerente||''}`; }); - } + 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 - if (data.despesas && data.despesas.length > 0) { - data.despesas.forEach(d => { if (d.desc || d.valor) rows += `${d.desc||''}${fmt(d.valor)}${d.obs||''}`; }); - } + 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 - 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)}`; - } + 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 - if (cancelTotal > 0) { - rows += `Cancelamentos${fmt(cancelTotal)}`; - } + 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 ` -Relatório de Fechamento +Recibo de Fechamento @@ -1366,29 +1507,27 @@ function buildPrintHTML(data) {
Operador:${data.operador}
Turno:${data.turno}
-
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}
` : ''} - +${detailSections}
-
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)}
- +
💸 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)}

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