|
|
|
@@ -63,8 +63,8 @@
|
|
|
|
|
.meta-select { cursor: pointer; }
|
|
|
|
|
|
|
|
|
|
/* ── MAIN 2 COLUMNS — single scroll, no internal scrollbars ──────────── */
|
|
|
|
|
.main { flex: 1; display: grid; grid-template-columns: 1fr 1fr; overflow: visible; }
|
|
|
|
|
.col { padding: 12px 16px; overflow: visible; }
|
|
|
|
|
.main { flex: 1; display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; min-height: 0; }
|
|
|
|
|
.col { padding: 12px 16px; overflow: hidden; }
|
|
|
|
|
.col-left { border-right: 1px solid var(--border); }
|
|
|
|
|
.col-right { background: var(--surface); display: flex; flex-direction: column; }
|
|
|
|
|
.col-right .section { flex-shrink: 0; }
|
|
|
|
@@ -160,7 +160,7 @@
|
|
|
|
|
padding: 10px 16px; display: flex; justify-content: space-between; align-items: center;
|
|
|
|
|
}
|
|
|
|
|
.dif-label { font-size: 12px; font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: 0.5px; }
|
|
|
|
|
.dif-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
|
|
|
|
|
.dif-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
|
|
|
|
|
.dif-value.pos, .dif-value.zero { color: var(--green); }
|
|
|
|
|
.dif-value.neg { color: var(--red); }
|
|
|
|
|
|
|
|
|
@@ -323,8 +323,8 @@
|
|
|
|
|
<div class="meta-field">
|
|
|
|
|
<span class="meta-label">Loja</span>
|
|
|
|
|
<select class="meta-select" id="f-loja">
|
|
|
|
|
<option value="União">União</option>
|
|
|
|
|
<option value="Aliança">Aliança</option>
|
|
|
|
|
<option value="Uniao">União</option>
|
|
|
|
|
<option value="Alianca">Aliança</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
@@ -543,7 +543,8 @@
|
|
|
|
|
<div class="cfg-section">
|
|
|
|
|
<div class="cfg-section-title">🔐 Senha Admin (editar dias anteriores)</div>
|
|
|
|
|
<div style="display:flex;gap:6px;margin-top:4px">
|
|
|
|
|
<input type="password" id="cfg-admin-password" style="flex:1;padding:6px;border:1px solid #ddd;border-radius:4px;font-size:13px" placeholder="Deixe em branco se não quiser senha">
|
|
|
|
|
<input type="password" id="cfg-admin-password" style="flex:1;padding:6px;border:1px solid #ddd;border-radius:4px;font-size:13px" placeholder="Senha fixa (ou deixe em branco)">
|
|
|
|
|
<input type="password" id="cfg-dynamic-password" style="flex:1;padding:6px;border:1px solid #ddd;border-radius:4px;font-size:13px" placeholder="Dinâmica: 10+dia+mes (ex: 1217)">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
@@ -564,7 +565,7 @@
|
|
|
|
|
<p style="font-size:13px;color:#444;margin-bottom:14px">
|
|
|
|
|
Tem certeza que deseja <strong>enviar este fechamento e encerrar o caixa?</strong>
|
|
|
|
|
</p>
|
|
|
|
|
<div id="confirm-summary" style="border:1px solid #b3d9f7;border-radius:8px;padding:14px;background:#f0f7ff;font-size:14px;font-family:Arial,sans-serif;line-height:1.6">
|
|
|
|
|
<div id="confirm-summary" style="border:1px solid #b3d9f7;border-radius:8px;padding:18px;background:#f0f7ff;font-size:16px;font-family:Arial,sans-serif;line-height:1.8">
|
|
|
|
|
</div>
|
|
|
|
|
<p style="font-size:11px;color:#888;margin-top:10px">
|
|
|
|
|
Após enviar, <strong>não dá pra editar este fechamento</strong> sem a senha do Filipe.
|
|
|
|
@@ -1233,6 +1234,7 @@ function loadConfig() {
|
|
|
|
|
}
|
|
|
|
|
function saveConfig() {
|
|
|
|
|
config.admin_password = document.getElementById('cfg-admin-password').value.trim();
|
|
|
|
|
config.dynamic_password = document.getElementById('cfg-dynamic-password').value.trim();
|
|
|
|
|
try { localStorage.setItem(CFG_KEY, JSON.stringify(config)); } catch(e) {}
|
|
|
|
|
buildDatalists();
|
|
|
|
|
}
|
|
|
|
@@ -1246,6 +1248,7 @@ function openConfig() {
|
|
|
|
|
renderCfgList('clientes', 'cfg-clientes-list');
|
|
|
|
|
renderCfgList('vales_nomes', 'cfg-vales-list');
|
|
|
|
|
document.getElementById('cfg-admin-password').value = config.admin_password || '';
|
|
|
|
|
document.getElementById('cfg-dynamic-password').value = config.dynamic_password || '';
|
|
|
|
|
}
|
|
|
|
|
function closeConfig() { document.getElementById('modal-config').classList.remove('open'); }
|
|
|
|
|
function renderCfgList(key, containerId) {
|
|
|
|
@@ -1320,9 +1323,14 @@ function buildConfirmHTML(data) {
|
|
|
|
|
// Relatório completo — mesmo layout do PDF
|
|
|
|
|
const fmt = v => 'R$ ' + (v || 0).toFixed(2).replace('.', ',');
|
|
|
|
|
const fmtNeg = v => (v < 0 ? '-' : '') + 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ',');
|
|
|
|
|
// Diferença = fechamento - saldo_esperado - cancelamentos
|
|
|
|
|
const diferenca = data.diferenca !== undefined ? data.diferenca
|
|
|
|
|
: ((data.fechamento || 0) - (data.saldo_esperado || 0) - (data.cancelamentos || 0));
|
|
|
|
|
// Cancelamentos: SEMPRE recalcular da array — nunca usar o campo escalar
|
|
|
|
|
const cancelamentos_arr = Array.isArray(data.cancelamentos_arr) ? data.cancelamentos_arr : [];
|
|
|
|
|
const cancelamentosCalc = cancelamentos_arr.reduce((s, r) => s + (r.valor || 0), 0);
|
|
|
|
|
// Diferença = Total Sistema - Saldo Esperado - Cancelamentos
|
|
|
|
|
// ⚠️ buildReciboData retorna snake_case (sys_total, total_cancelamentos)
|
|
|
|
|
const sysTotalCalc = (data.sys_total || data.sysTotal || 0);
|
|
|
|
|
const saldoEsperadoCalc = (data.saldo_esperado || 0);
|
|
|
|
|
const diferenca = sysTotalCalc - saldoEsperadoCalc - cancelamentosCalc;
|
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca);
|
|
|
|
|
const diffOk = diferenca === 0;
|
|
|
|
|
|
|
|
|
@@ -1367,17 +1375,17 @@ function buildConfirmHTML(data) {
|
|
|
|
|
const al = cartAli_arr[i] || 0;
|
|
|
|
|
const px = cartPix_arr[i] || 0;
|
|
|
|
|
cartTableRows += `<tr>
|
|
|
|
|
<td>${cr > 0 ? fmt(cr) : '-'}</td>
|
|
|
|
|
<td>${db > 0 ? fmt(db) : '-'}</td>
|
|
|
|
|
<td>${al > 0 ? fmt(al) : '-'}</td>
|
|
|
|
|
<td>${px > 0 ? fmt(px) : '-'}</td>
|
|
|
|
|
<td>${cr > 0 ? fmt(cr).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${db > 0 ? fmt(db).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${al > 0 ? fmt(al).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${px > 0 ? fmt(px).replace('R$ ','') : '-'}</td>
|
|
|
|
|
</tr>`;
|
|
|
|
|
}
|
|
|
|
|
cartTableRows += `<tr class="total-row">
|
|
|
|
|
<td>${cartCred > 0 ? fmt(cartCred) : '-'}</td>
|
|
|
|
|
<td>${cartDeb > 0 ? fmt(cartDeb) : '-'}</td>
|
|
|
|
|
<td>${cartAli > 0 ? fmt(cartAli) : '-'}</td>
|
|
|
|
|
<td>${cartPix > 0 ? fmt(cartPix) : '-'}</td>
|
|
|
|
|
<td>${cartCred > 0 ? fmt(cartCred).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${cartDeb > 0 ? fmt(cartDeb).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${cartAli > 0 ? fmt(cartAli).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${cartPix > 0 ? fmt(cartPix).replace('R$ ','') : '-'}</td>
|
|
|
|
|
</tr>`;
|
|
|
|
|
|
|
|
|
|
let html = `<!DOCTYPE html>
|
|
|
|
@@ -1386,28 +1394,28 @@ function buildConfirmHTML(data) {
|
|
|
|
|
<title>Fechamento de Caixa</title>
|
|
|
|
|
<style>
|
|
|
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
|
body { font-family: 'Courier New', monospace; font-size: 15px; width: 80mm; margin: 0 auto; padding: 8px; font-weight: bold !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
|
|
|
|
|
body { font-family: 'Courier New', monospace; font-size: 18px; font-weight: bold !important; width: 80mm; margin: 0 auto; padding: 8px; font-weight: bold !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
|
|
|
|
|
.header { text-align: center; margin-bottom: 8px; }
|
|
|
|
|
.header h1 { font-size: 20px; font-weight: bold !important; }
|
|
|
|
|
.header h2 { font-size: 16px; font-weight: bold !important; }
|
|
|
|
|
.header h1 { font-size: 24px; font-weight: bold !important; }
|
|
|
|
|
.header h2 { font-size: 18px; font-weight: bold !important; }
|
|
|
|
|
hr { border: none; border-top: 2px solid #000; margin: 6px 0; }
|
|
|
|
|
.section-title { font-weight: bold !important; font-size: 14px; border-top: 2px solid #000; padding-top: 4px; margin-top: 8px; }
|
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 14px; font-weight: bold !important; }
|
|
|
|
|
.section-title { font-weight: bold !important; font-size: 18px; border-top: 2px solid #000; padding-top: 4px; margin-top: 8px; }
|
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 18px; font-weight: bold !important; }
|
|
|
|
|
.row.total-row { font-weight: bold !important; }
|
|
|
|
|
.cart-table { table-layout: fixed; width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; font-weight: bold !important; }
|
|
|
|
|
.cart-table th { font-weight: bold !important; border-bottom: 2px solid #000; padding: 3px; font-size: 13px; width: 25%; }
|
|
|
|
|
.cart-table td { padding: 3px 5px; text-align: right; font-weight: bold !important; font-size: 13px; }
|
|
|
|
|
.cart-table { table-layout: fixed; width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; font-weight: bold !important; }
|
|
|
|
|
.cart-table th { font-weight: bold !important; border-bottom: 2px solid #000; padding: 2px 3px; font-size: 12px; width: 25%; }
|
|
|
|
|
.cart-table td { padding: 2px 3px; text-align: right; font-weight: bold !important; font-size: 12px; }
|
|
|
|
|
.cart-table td:first-child { text-align: left; }
|
|
|
|
|
.cart-table tr.total-row { font-weight: bold !important; border-top: 2px solid #000; }
|
|
|
|
|
.subtotal { font-size: 13px; margin-top: 4px; }
|
|
|
|
|
.subtotal { font-size: 12px; margin-top: 4px; }
|
|
|
|
|
.subtotal .row { padding: 1px 0; font-weight: bold !important; }
|
|
|
|
|
.diff-ok { color: #2e7d32; font-weight: bold !important; }
|
|
|
|
|
.diff-bad { color: #c0272d; font-weight: bold !important; }
|
|
|
|
|
.obs { font-size: 12px; color: #555; margin-top: 6px; white-space: pre-wrap; font-weight: bold !important; }
|
|
|
|
|
.footer { text-align: center; font-size: 12px; color: #555; margin-top: 8px; font-weight: bold !important; }
|
|
|
|
|
@media print { body { background: #fff; font-weight: bold !important; font-size: 15px !important; } }
|
|
|
|
|
</head><body>
|
|
|
|
|
<div class="header">
|
|
|
|
|
.obs { font-size: 16px; color: #555; margin-top: 6px; white-space: pre-wrap; font-weight: bold !important; }
|
|
|
|
|
.footer { text-align: center; font-size: 14px; color: #555; margin-top: 8px; font-weight: bold !important; }
|
|
|
|
|
@media print { body { background: #fff; font-weight: bold !important; font-size: 18px !important; } }
|
|
|
|
|
</head><body>
|
|
|
|
|
<div class="header">
|
|
|
|
|
<h1>${data.loja}</h1>
|
|
|
|
|
<h2>Fechamento de Caixa</h2>
|
|
|
|
|
</div>
|
|
|
|
@@ -1444,7 +1452,7 @@ ${cancelamentos_arr.map(c => `<div class="row"><span>${c.numero ? `Nº ${c.numer
|
|
|
|
|
<table class="cart-table">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>CRÉDITO</th><th>DÉBITO</th><th>ALIMENT.</th><th>PIX</th>
|
|
|
|
|
<th>CRÉD</th><th>DÉBIT</th><th>ALIM</th><th>PIX</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
@@ -1486,15 +1494,21 @@ ${data.observacoes ? `<div class="obs">${data.observacoes}</div>` : ''}
|
|
|
|
|
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('.', ',');
|
|
|
|
|
// Cancelamentos: SEMPRE recalcular da array — nunca usar o campo escalar
|
|
|
|
|
const cancelamentos_arr = Array.isArray(data.cancelamentos_arr) ? data.cancelamentos_arr : [];
|
|
|
|
|
const cancelamentosCalc = cancelamentos_arr.reduce((s, r) => s + (r.valor || 0), 0);
|
|
|
|
|
// Diferença = Total Sistema - Saldo Esperado - Cancelamentos
|
|
|
|
|
const sysTotalCalc = (data.sysTotal || 0);
|
|
|
|
|
// ⚠️ buildReciboData retorna snake_case (sys_total, total_cancelamentos)
|
|
|
|
|
const sysTotalCalc = (data.sys_total || data.sysTotal || 0);
|
|
|
|
|
const saldoEsperadoCalc = (data.saldo_esperado || 0);
|
|
|
|
|
const cancelamentosCalc = (data.cancelamentos || 0);
|
|
|
|
|
const diferenca = sysTotalCalc - saldoEsperadoCalc - cancelamentosCalc;
|
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca);
|
|
|
|
|
const diffColor = diferenca === 0 ? '#2e7d32' : (diferenca > 0 ? '#e65100' : '#c0272d');
|
|
|
|
|
|
|
|
|
|
// Arrays — support both array-of-objects and flat totals
|
|
|
|
|
const cartCred_arr = Array.isArray(data.cartoes_credito) ? data.cartoes_credito : [];
|
|
|
|
|
const cartDeb_arr = Array.isArray(data.cartoes_debito) ? data.cartoes_debito : [];
|
|
|
|
|
const cartAli_arr = Array.isArray(data.cartoes_alimentacao) ? data.cartoes_alimentacao : [];
|
|
|
|
|
const cartPix_arr = Array.isArray(data.cartoes_pix) ? data.cartoes_pix : [];
|
|
|
|
|
const sangrias_arr = Array.isArray(data.sangrias_arr) ? data.sangrias_arr : [];
|
|
|
|
|
const despesas_arr = Array.isArray(data.despesas_arr) ? data.despesas_arr : [];
|
|
|
|
|
const pixcnpj_arr = Array.isArray(data.pixcnpj_arr) ? data.pixcnpj_arr : [];
|
|
|
|
@@ -1503,10 +1517,7 @@ function buildPrintHTML(data) {
|
|
|
|
|
const cancelamentos_arr = Array.isArray(data.cancelamentos_arr) ? data.cancelamentos_arr : [];
|
|
|
|
|
|
|
|
|
|
// Cartoes arrays from estado
|
|
|
|
|
const cartCred_arr = Array.isArray(data.cartoes_credito) ? data.cartoes_credito : [];
|
|
|
|
|
const cartDeb_arr = Array.isArray(data.cartoes_debito) ? data.cartoes_debito : [];
|
|
|
|
|
const cartAli_arr = Array.isArray(data.cartoes_alimentacao) ? data.cartoes_alimentacao : [];
|
|
|
|
|
const cartPix_arr = Array.isArray(data.cartoes_pix) ? data.cartoes_pix : [];
|
|
|
|
|
// (cartCred_arr etc. already declared above)
|
|
|
|
|
|
|
|
|
|
// Flat totals
|
|
|
|
|
const totalSangrias = sangrias_arr.reduce((s,r) => s+(r.retirada||0)+(r.valor||0), 0);
|
|
|
|
@@ -1582,18 +1593,18 @@ function buildPrintHTML(data) {
|
|
|
|
|
const al = cartAli_arr[i] || 0;
|
|
|
|
|
const px = cartPix_arr[i] || 0;
|
|
|
|
|
cartTableRows += `<tr>
|
|
|
|
|
<td>${cr > 0 ? fmt(cr) : '-'}</td>
|
|
|
|
|
<td>${db > 0 ? fmt(db) : '-'}</td>
|
|
|
|
|
<td>${al > 0 ? fmt(al) : '-'}</td>
|
|
|
|
|
<td>${px > 0 ? fmt(px) : '-'}</td>
|
|
|
|
|
<td>${cr > 0 ? fmt(cr).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${db > 0 ? fmt(db).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${al > 0 ? fmt(al).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${px > 0 ? fmt(px).replace('R$ ','') : '-'}</td>
|
|
|
|
|
</tr>`;
|
|
|
|
|
}
|
|
|
|
|
// Totals row
|
|
|
|
|
cartTableRows += `<tr class="total-row">
|
|
|
|
|
<td>${cartCred > 0 ? fmt(cartCred) : '-'}</td>
|
|
|
|
|
<td>${cartDeb > 0 ? fmt(cartDeb) : '-'}</td>
|
|
|
|
|
<td>${cartAli > 0 ? fmt(cartAli) : '-'}</td>
|
|
|
|
|
<td>${cartPix > 0 ? fmt(cartPix) : '-'}</td>
|
|
|
|
|
<td>${cartCred > 0 ? fmt(cartCred).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${cartDeb > 0 ? fmt(cartDeb).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${cartAli > 0 ? fmt(cartAli).replace('R$ ','') : '-'}</td>
|
|
|
|
|
<td>${cartPix > 0 ? fmt(cartPix).replace('R$ ','') : '-'}</td>
|
|
|
|
|
</tr>`;
|
|
|
|
|
|
|
|
|
|
const sysTotal = data.sys_total || 0;
|
|
|
|
@@ -1606,26 +1617,26 @@ function buildPrintHTML(data) {
|
|
|
|
|
<title>Fechamento de Caixa</title>
|
|
|
|
|
<style>
|
|
|
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
|
body { font-family: 'Courier New', monospace; font-size: 15px; width: 80mm; margin: 0 auto; padding: 8px; font-weight: bold !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
|
|
|
|
|
body { font-family: 'Courier New', monospace; font-size: 18px; font-weight: bold !important; width: 80mm; margin: 0 auto; padding: 8px; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
|
|
|
|
|
.header { text-align: center; margin-bottom: 8px; }
|
|
|
|
|
.header h1 { font-size: 20px; font-weight: bold !important; }
|
|
|
|
|
.header h2 { font-size: 16px; font-weight: bold !important; }
|
|
|
|
|
.header h1 { font-size: 24px; font-weight: bold !important; }
|
|
|
|
|
.header h2 { font-size: 18px; font-weight: bold !important; }
|
|
|
|
|
hr { border: none; border-top: 2px solid #000; margin: 6px 0; }
|
|
|
|
|
.section-title { font-weight: bold !important; font-size: 14px; border-top: 2px solid #000; padding-top: 4px; margin-top: 8px; }
|
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 14px; font-weight: bold !important; }
|
|
|
|
|
.section-title { font-weight: bold !important; font-size: 18px; border-top: 2px solid #000; padding-top: 4px; margin-top: 8px; }
|
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 18px; font-weight: bold !important; }
|
|
|
|
|
.row.total-row { font-weight: bold !important; }
|
|
|
|
|
.cart-table { table-layout: fixed; width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; font-weight: bold !important; }
|
|
|
|
|
.cart-table th { font-weight: bold !important; border-bottom: 2px solid #000; padding: 3px; font-size: 13px; width: 25%; }
|
|
|
|
|
.cart-table td { padding: 3px 5px; text-align: right; font-weight: bold !important; font-size: 13px; }
|
|
|
|
|
.cart-table { table-layout: fixed; width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; font-weight: bold !important; }
|
|
|
|
|
.cart-table th { font-weight: bold !important; border-bottom: 2px solid #000; padding: 2px 3px; font-size: 12px; width: 25%; }
|
|
|
|
|
.cart-table td { padding: 2px 3px; text-align: right; font-weight: bold !important; font-size: 12px; }
|
|
|
|
|
.cart-table td:first-child { text-align: left; }
|
|
|
|
|
.cart-table tr.total-row { font-weight: bold !important; border-top: 2px solid #000; }
|
|
|
|
|
.subtotal { font-size: 13px; margin-top: 4px; }
|
|
|
|
|
.subtotal { font-size: 12px; margin-top: 4px; }
|
|
|
|
|
.subtotal .row { padding: 1px 0; font-weight: bold !important; }
|
|
|
|
|
.diff-ok { color: #2e7d32; font-weight: bold !important; }
|
|
|
|
|
.diff-bad { color: #c0272d; font-weight: bold !important; }
|
|
|
|
|
.obs { font-size: 12px; color: #555; margin-top: 6px; white-space: pre-wrap; font-weight: bold !important; }
|
|
|
|
|
.footer { text-align: center; font-size: 12px; color: #555; margin-top: 8px; font-weight: bold !important; }
|
|
|
|
|
@media print { body { background: #fff; font-weight: bold !important; font-size: 15px !important; } }
|
|
|
|
|
.obs { font-size: 16px; color: #555; margin-top: 6px; white-space: pre-wrap; font-weight: bold !important; }
|
|
|
|
|
.footer { text-align: center; font-size: 14px; color: #555; margin-top: 8px; font-weight: bold !important; }
|
|
|
|
|
@media print { body { background: #fff; font-weight: bold !important; font-size: 18px !important; } }
|
|
|
|
|
</style>
|
|
|
|
|
</head><body>
|
|
|
|
|
<div class="header">
|
|
|
|
@@ -1665,7 +1676,7 @@ ${cancLines.map(l => `<div class="row"><span>${l.label}</span><span>${fmt(l.valo
|
|
|
|
|
<table class="cart-table">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>CRÉDITO</th><th>DÉBITO</th><th>ALIMENT.</th><th>PIX</th>
|
|
|
|
|
<th>CRÉD</th><th>DÉBIT</th><th>ALIM</th><th>PIX</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
@@ -1720,12 +1731,16 @@ function buildReportHTML(data) {
|
|
|
|
|
const vales = data.vales || 0;
|
|
|
|
|
const receber = data.areceber || 0;
|
|
|
|
|
const pixcnpj = data.pixcnpj || 0;
|
|
|
|
|
const cancelamentos = data.cancelamentos || 0;
|
|
|
|
|
// Cancelamentos: SEMPRE recalcular da array — nunca usar o campo escalar (pode estar corrompido de bug anterior)
|
|
|
|
|
const cancelamentos_arr = Array.isArray(data.cancelamentos_arr) ? data.cancelamentos_arr : [];
|
|
|
|
|
const cancelamentosCalc = cancelamentos_arr.reduce((s, r) => s + (r.valor || 0), 0);
|
|
|
|
|
const fechamento = data.fechamento || 0;
|
|
|
|
|
const sysTotal = data.sys_total || 0;
|
|
|
|
|
const saldoEsp = data.saldo_esperado || 0;
|
|
|
|
|
const diferenca = data.diferenca !== undefined ? data.diferenca
|
|
|
|
|
: (fechamento - saldoEsp - cancelamentos);
|
|
|
|
|
// Diferença = Total Sistema - Saldo Esperado - Cancelamentos
|
|
|
|
|
const sysTotalCalc = (data.sys_total || data.sysTotal || 0);
|
|
|
|
|
const saldoEspCalc = (data.saldo_esperado || 0);
|
|
|
|
|
const diferenca = sysTotalCalc - saldoEspCalc - cancelamentosCalc;
|
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca);
|
|
|
|
|
const diffColor = diferenca === 0 ? '#2e7d32' : '#c0272d';
|
|
|
|
|
|
|
|
|
@@ -1735,17 +1750,20 @@ function buildReportHTML(data) {
|
|
|
|
|
<title>Relatório de Fechamento</title>
|
|
|
|
|
<style>
|
|
|
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
|
body { font-family: 'Courier New', monospace; font-size: 13px; width: 80mm; margin: 0 auto; padding: 8px; }
|
|
|
|
|
.header { text-align: center; margin-bottom: 8px; }
|
|
|
|
|
body { font-family: 'Courier New', monospace; font-size: 18px; font-weight: bold; width: 80mm; margin: 0 auto; padding: 8px; }
|
|
|
|
|
.header { text-align: center; margin-bottom: 10px; }
|
|
|
|
|
hr { border: none; border-top: 1px dashed #000; margin: 6px 0; }
|
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 12px; }
|
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 18px; font-weight: bold; }
|
|
|
|
|
.row .val { font-weight: bold; }
|
|
|
|
|
.footer { text-align: center; font-size: 11px; color: #555; margin-top: 8px; }
|
|
|
|
|
@media print { body { margin: 0; } }
|
|
|
|
|
.footer { text-align: center; font-size: 13px; color: #555; margin-top: 8px; }
|
|
|
|
|
@media print { body { margin: 0; font-size: 18px !important; font-weight: bold !important; } }
|
|
|
|
|
</style>
|
|
|
|
|
</head><body>
|
|
|
|
|
<div class="header">
|
|
|
|
|
<div>📅 Data: ${data.data} 👤 Operador: ${data.operador} ⏰ Turno: ${data.turno} 🏪 Loja: ${data.loja}</div>
|
|
|
|
|
<div>📅 Data: ${data.data}</div>
|
|
|
|
|
<div>👤 Operador: ${data.operador}</div>
|
|
|
|
|
<div>⏰ Turno: ${data.turno}</div>
|
|
|
|
|
<div>🏪 Loja: ${data.loja}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<hr>
|
|
|
|
|
<div class="row"><span>💸 Sangrias:</span><span class="val">${fmt(sangrias)}</span></div>
|
|
|
|
@@ -1768,7 +1786,7 @@ function buildReportHTML(data) {
|
|
|
|
|
<div class="row"><span>🍗 Frango Assado:</span><span class="val">${data.frango || 0}</span></div>
|
|
|
|
|
<div class="row"><span>💰 Vendas:</span><span class="val">${fmt(data.vendas || 0)}</span></div>
|
|
|
|
|
<hr>
|
|
|
|
|
<div style="text-align:center;font-size:10px;color:#888">ID: ${data.loja}_${data.data}_${data.operador}</div>
|
|
|
|
|
<div style="text-align:center;font-size:12px;color:#888">ID: ${data.loja}_${data.data}_${data.operador}</div>
|
|
|
|
|
<div class="footer">Gerado em ${new Date().toLocaleString('pt-BR')}</div>
|
|
|
|
|
</body></html>`;
|
|
|
|
|
}
|
|
|
|
@@ -1792,21 +1810,21 @@ function openPrintPreview(data, mode) {
|
|
|
|
|
|
|
|
|
|
const previewStyle = `
|
|
|
|
|
<style>
|
|
|
|
|
body { width: 80mm; margin: 0 auto; font-family: 'Courier New', monospace; font-size: 13px; background: #fff; padding: 10px; }
|
|
|
|
|
body { width: 80mm; margin: 0 auto; font-family: 'Courier New', monospace; font-size: 6px; background: #fff; padding: 10px; font-weight: bold; }
|
|
|
|
|
.header { text-align: center; margin-bottom: 8px; }
|
|
|
|
|
.header h1 { font-size: 18px; }
|
|
|
|
|
.header h2 { font-size: 14px; font-weight: normal; }
|
|
|
|
|
.header h1 { font-size: 18px; font-weight: bold; }
|
|
|
|
|
.header h2 { font-size: 6px; font-weight: bold; }
|
|
|
|
|
hr { border: none; border-top: 1px dashed #000; margin: 6px 0; }
|
|
|
|
|
.section-title { font-weight: bold; font-size: 14px; border-top: 1px dashed #000; padding-top: 4px; margin-top: 6px; }
|
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 2px 0; }
|
|
|
|
|
table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
|
|
|
|
td { padding: 2px 4px; vertical-align: top; }
|
|
|
|
|
.section-title { font-weight: bold; font-size: 6px; border-top: 1px dashed #000; padding-top: 4px; margin-top: 6px; }
|
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 6px; font-weight: bold; }
|
|
|
|
|
table { width: 100%; border-collapse: collapse; font-size: 6px; font-weight: bold; }
|
|
|
|
|
td { padding: 2px 4px; vertical-align: top; font-weight: bold; }
|
|
|
|
|
td:nth-child(2) { text-align: right; }
|
|
|
|
|
td:nth-child(3) { text-align: right; color: #555; font-size: 11px; }
|
|
|
|
|
.grand-total { font-size: 16px; font-weight: bold; text-align: center; padding: 6px; border: 2px solid #000; margin: 8px 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; }
|
|
|
|
|
@media print { body { background: #fff; } }
|
|
|
|
|
td:nth-child(3) { text-align: right; color: #555; font-size: 5px; }
|
|
|
|
|
.grand-total { font-size: 18px; font-weight: bold; text-align: center; padding: 6px; border: 2px solid #000; margin: 8px 0; }
|
|
|
|
|
.obs { font-size: 5px; color: #555; margin-top: 6px; white-space: pre-wrap; font-weight: normal; }
|
|
|
|
|
.footer { text-align: center; font-size: 5px; color: #555; margin-top: 8px; font-weight: normal; }
|
|
|
|
|
@media print { body { background: #fff; font-size: 6px !important; font-weight: bold !important; } }
|
|
|
|
|
</style>
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
@@ -1975,9 +1993,11 @@ async function tauriCarregarRascunho() {
|
|
|
|
|
// ─── Confirm Modal ────────────────────────────────────────────────────────
|
|
|
|
|
function openConfirmModal() {
|
|
|
|
|
console.log('[DEBUG] openConfirmModal chamado');
|
|
|
|
|
const operador = val('f-operador').trim();
|
|
|
|
|
const turno = val('f-turno').trim();
|
|
|
|
|
const loja = val('f-loja').trim();
|
|
|
|
|
// Usa estado (que o boot fixou para builds fixas) em vez de ler DOM
|
|
|
|
|
// — o DOM pode estar vazio se o select está disabled/hidden
|
|
|
|
|
const operador = estado.operador.trim();
|
|
|
|
|
const turno = estado.turno.trim();
|
|
|
|
|
const loja = estado.loja.trim();
|
|
|
|
|
console.log('[DEBUG] openConfirmModal campos:', {operador, turno, loja});
|
|
|
|
|
if (!operador || !turno || !loja) {
|
|
|
|
|
console.log('[DEBUG] openConfirmModal: campos faltando, alert');
|
|
|
|
@@ -2002,26 +2022,26 @@ function openConfirmModal() {
|
|
|
|
|
const diferenca = sysTotal - saldoEsp - cancelamentos;
|
|
|
|
|
const diffClass = diferenca === 0 ? '#2e7d32' : (diferenca > 0 ? '#e65100' : '#c0272d');
|
|
|
|
|
document.getElementById('confirm-summary').innerHTML =
|
|
|
|
|
`<div style="margin-bottom:6px"><strong>📅 Data:</strong> ${estado.data} <strong>👤 Operador:</strong> ${operador} <strong>⏰ Turno:</strong> ${turno} <strong>🏪 Loja:</strong> ${loja}</div>
|
|
|
|
|
`<div style="margin-bottom:6px;font-size:17px"><strong>📅 Data:</strong> ${estado.data} <strong>👤 Operador:</strong> ${operador} <strong>⏰ Turno:</strong> ${turno} <strong>🏪 Loja:</strong> ${loja}</div>
|
|
|
|
|
<hr style="border:none;border-top:1px dashed #b3d9f7;margin:6px 0">
|
|
|
|
|
<div>💸 Sangrias: <strong>${fmt(sangrias)}</strong></div>
|
|
|
|
|
<div>📝 Despesas: <strong>${fmt(despesas)}</strong></div>
|
|
|
|
|
<div>💰 Vales: <strong>${fmt(vales)}</strong></div>
|
|
|
|
|
<div>👥 À Receber: <strong>${fmt(receber)}</strong></div>
|
|
|
|
|
<div>🔵 PIX CNPJ: <strong>${fmt(pixcnpj)}</strong></div>
|
|
|
|
|
<div>💳 Crédito: <strong>${fmt(cartCred)}</strong></div>
|
|
|
|
|
<div>💳 Débito: <strong>${fmt(cartDeb)}</strong></div>
|
|
|
|
|
<div>💳 Alimentação: <strong>${fmt(cartAli)}</strong></div>
|
|
|
|
|
<div>❌ Cancelamentos: <strong>${fmt(cancelamentos)}</strong></div>
|
|
|
|
|
<div>👥 Clientes: <strong>${estado.clientes || 0}</strong></div>
|
|
|
|
|
<div>🍗 Frango Assado: <strong>${estado.frango || 0}</strong></div>
|
|
|
|
|
<div>💰 Vendas: <strong>${fmt(estado.vendas || 0)}</strong></div>
|
|
|
|
|
<div>📋 Fechamento (contado): <strong>${fmt(fechamento)}</strong></div>
|
|
|
|
|
<div>🖥️ Total Sistema: <strong>${fmt(sysTotal)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">💸 Sangrias: <strong>${fmt(sangrias)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">📝 Despesas: <strong>${fmt(despesas)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">💰 Vales: <strong>${fmt(vales)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">👥 À Receber: <strong>${fmt(receber)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">🔵 PIX CNPJ: <strong>${fmt(pixcnpj)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">💳 Crédito: <strong>${fmt(cartCred)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">💳 Débito: <strong>${fmt(cartDeb)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">💳 Alimentação: <strong>${fmt(cartAli)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">❌ Cancelamentos: <strong>${fmt(cancelamentos)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">👥 Clientes: <strong>${estado.clientes || 0}</strong></div>
|
|
|
|
|
<div style="font-size:16px">🍗 Frango Assado: <strong>${estado.frango || 0}</strong></div>
|
|
|
|
|
<div style="font-size:16px">💰 Vendas: <strong>${fmt(estado.vendas || 0)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">📋 Fechamento (contado): <strong>${fmt(fechamento)}</strong></div>
|
|
|
|
|
<div style="font-size:16px">🖥️ Total Sistema: <strong>${fmt(sysTotal)}</strong></div>
|
|
|
|
|
<hr style="border:none;border-top:1px dashed #b3d9f7;margin:6px 0">
|
|
|
|
|
<div>🎯 Saldo Esperado (contado): <strong>${fmt(saldoEsp)}</strong></div>
|
|
|
|
|
<div style="margin-top:4px">📐 Diferença: <strong style="color:${diffClass}">${fmt(diferenca)}</strong></div>
|
|
|
|
|
<div style="margin-top:4px;font-size:10px;color:#888">ID: ${estado.loja}_${estado.data}_${estado.operador}</div>`;
|
|
|
|
|
<div style="font-size:16px">🎯 Saldo Esperado (contado): <strong>${fmt(saldoEsp)}</strong></div>
|
|
|
|
|
<div style="margin-top:4px;font-size:16px">📐 Diferença: <strong style="color:${diffClass}">${fmt(diferenca)}</strong></div>
|
|
|
|
|
<div style="margin-top:8px;font-size:12px;color:#888">ID: ${estado.loja}_${estado.data}_${estado.operador}</div>`;
|
|
|
|
|
console.log('[DEBUG] openConfirmModal: tentando abrir modal');
|
|
|
|
|
document.getElementById('modal-confirm').classList.add('open');
|
|
|
|
|
}
|
|
|
|
@@ -2045,8 +2065,7 @@ document.getElementById('confirm-print').addEventListener('click', async () => {
|
|
|
|
|
alert('Erro ao montar dados do recibo.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Fecha modal APÓS gerar preview (não antes)
|
|
|
|
|
closeConfirmModal();
|
|
|
|
|
// NÃO fecha o modal — o preview de impressão abre POR CIMA (depois de imprimir e fechar, continua no confirm)
|
|
|
|
|
openPrintPreview(data, 'report');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@@ -2102,25 +2121,48 @@ document.getElementById('btn-recibo').addEventListener('click', async () => {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
document.getElementById('btn-limpar').addEventListener('click', () => {
|
|
|
|
|
if (!confirm('Limpar rascunho? Esta acção não pode ser revertida.')) return;
|
|
|
|
|
localStorage.removeItem(LS_KEY);
|
|
|
|
|
estado = {
|
|
|
|
|
uuid: crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(),
|
|
|
|
|
loja: estado.loja, data: estado.data, operador: '', turno: '',
|
|
|
|
|
saldo_troco: 0, fechamento: 0, saldo_esperado: 0, diferenca: 0,
|
|
|
|
|
despesas: [], sangrias: [], pixcnpj: [], vales: [], receber: [], cancelamentos: [],
|
|
|
|
|
cartoes: { credito: [], debito: [], alimentacao: [], pix: [] },
|
|
|
|
|
fechamento_contado: { dinheiro: 0, cartoes: 0, receber: 0 },
|
|
|
|
|
observacoes: '', id_local: null, sync_status: 'local'
|
|
|
|
|
};
|
|
|
|
|
setVal('f-operador', ''); setVal('f-turno', '');
|
|
|
|
|
setVal('f-fech-dinheiro', ''); setVal('f-fech-cartoes', ''); setVal('f-fech-receber', '');
|
|
|
|
|
setVal('f-saldo-esperado', ''); setVal('f-obs', '');
|
|
|
|
|
setVal('sys-troco', '');
|
|
|
|
|
updateTotals();
|
|
|
|
|
renderAllTables();
|
|
|
|
|
syncUI();
|
|
|
|
|
showToast('Rascunho limpo.', 'info');
|
|
|
|
|
const overlay = document.createElement('div');
|
|
|
|
|
overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:999999;display:flex;align-items:center;justify-content:center;';
|
|
|
|
|
overlay.id = 'clear-modal';
|
|
|
|
|
overlay.innerHTML = `
|
|
|
|
|
<div style="background:#fff;border-radius:10px;padding:28px;width:340px;text-align:center">
|
|
|
|
|
<div style="font-size:20px;margin-bottom:12px">⚠️ Limpar Rascunho</div>
|
|
|
|
|
<div style="font-size:13px;color:#555;margin-bottom:20px;line-height:1.5">Tem certeza?<br>Irá <strong>apagar todas as informações</strong> lançadas para iniciar uma nova.</div>
|
|
|
|
|
<div style="display:flex;gap:10px;justify-content:center">
|
|
|
|
|
<button id="clear-cancel-btn" style="padding:9px 20px;background:#888;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px">Cancelar</button>
|
|
|
|
|
<button id="clear-ok-btn" style="padding:9px 20px;background:#c0272d;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px">Apagar tudo</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`;
|
|
|
|
|
document.body.appendChild(overlay);
|
|
|
|
|
document.getElementById('clear-cancel-btn').addEventListener('click', () => overlay.remove());
|
|
|
|
|
document.getElementById('clear-ok-btn').addEventListener('click', () => {
|
|
|
|
|
overlay.remove();
|
|
|
|
|
localStorage.removeItem(LS_KEY);
|
|
|
|
|
estado = {
|
|
|
|
|
uuid: crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(),
|
|
|
|
|
loja: estado.loja, data: estado.data, operador: '', turno: '',
|
|
|
|
|
saldo_troco: 0, fechamento: 0, saldo_esperado: 0, diferenca: 0,
|
|
|
|
|
despesas: [], sangrias: [], pixcnpj: [], vales: [], receber: [], cancelamentos: [],
|
|
|
|
|
cartoes: { credito: [], debito: [], alimentacao: [], pix: [] },
|
|
|
|
|
fechamento_contado: { dinheiro: 0, cartoes: 0, receber: 0 },
|
|
|
|
|
observacoes: '', id_local: null, sync_status: 'local'
|
|
|
|
|
};
|
|
|
|
|
estado.sangrias = []; estado.despesas = []; estado.pixcnpj = [];
|
|
|
|
|
estado.vales = []; estado.receber = []; estado.cancelamentos = [];
|
|
|
|
|
estado.cartoes = { credito: [], debito: [], alimentacao: [], pix: [] };
|
|
|
|
|
estado.fechamento_contado = { dinheiro: 0, cartoes: 0, receber: 0 };
|
|
|
|
|
setVal('f-operador', ''); setVal('f-turno', '');
|
|
|
|
|
setVal('f-fech-dinheiro', ''); setVal('f-fech-cartoes', ''); setVal('f-fech-receber', '');
|
|
|
|
|
setVal('f-saldo-esperado', ''); setVal('f-obs', '');
|
|
|
|
|
setVal('f-vendas', ''); setVal('f-clientes', ''); setVal('f-frango', '');
|
|
|
|
|
setVal('sys-troco', ''); setVal('sys-total', '');
|
|
|
|
|
setVal('sys-credito', ''); setVal('sys-debito', '');
|
|
|
|
|
setVal('sys-alimentacao', ''); setVal('sys-pixcnpj', '');
|
|
|
|
|
Object.keys(TABLES).forEach(renderTable);
|
|
|
|
|
updateTotals();
|
|
|
|
|
syncUI();
|
|
|
|
|
showToast('Rascunho limpo.', 'info');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ─── Dia Anterior — seleção + consulta + edição de registros do Supabase ───
|
|
|
|
@@ -2167,11 +2209,6 @@ function buildConsultaModal(recentList) {
|
|
|
|
|
return `${day}/${m}/${y}`;
|
|
|
|
|
};
|
|
|
|
|
const fmtMoney = v => v != null ? `R$ ${parseFloat(v).toFixed(2).replace('.', ',')}` : 'R$ 0,00';
|
|
|
|
|
const syncBadge = s => {
|
|
|
|
|
const colors = { synced: '#2e7d32', local: '#e65100', syncing: '#f57f17', error: '#c0272d' };
|
|
|
|
|
const labels = { synced: '✓ Sync', local: '⚠ Local', syncing: '⏳ Sync', error: '✗ Erro' };
|
|
|
|
|
return `<span style="background:${colors[s]||'#888'};color:#fff;padding:1px 5px;border-radius:3px;font-size:10px">${labels[s]||s||'?'}</span>`;
|
|
|
|
|
};
|
|
|
|
|
const statusBadge = s => {
|
|
|
|
|
if (s === 'ok') return '<span style="color:#2e7d32;font-weight:bold">✓ OK</span>';
|
|
|
|
|
if (s === 'sobrando') return '<span style="color:#e65100;font-weight:bold">⚠ SOBRANDO</span>';
|
|
|
|
@@ -2179,56 +2216,136 @@ function buildConsultaModal(recentList) {
|
|
|
|
|
return s || '?';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const rows = recentList.map((item, i) => {
|
|
|
|
|
const sysTotal = (parseFloat(item.saldo_troco)||0)
|
|
|
|
|
+ (parseFloat(item.saldo_credito)||0)
|
|
|
|
|
+ (parseFloat(item.saldo_debito)||0)
|
|
|
|
|
+ (parseFloat(item.saldo_alimentacao)||0)
|
|
|
|
|
+ (parseFloat(item.saldo_vales)||0)
|
|
|
|
|
+ (parseFloat(item.saldo_areceber)||0)
|
|
|
|
|
+ (parseFloat(item.total_pixcnpj)||0)
|
|
|
|
|
+ (parseFloat(item.total_cartao_pix)||0);
|
|
|
|
|
return `<tr>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtDate(item.data)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${item.operador||'?'}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${item.turno||'?'}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtMoney(sysTotal)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtMoney(item.saldo_esperado)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${statusBadge(item.status_diferenca)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${syncBadge(item.sync_status)}</td>
|
|
|
|
|
<td style="padding:4px 6px;border-bottom:1px solid #eee;text-align:center">
|
|
|
|
|
<button onclick="event.stopPropagation();window.abrirEditaFechamentoIndex(${i})" style="background:#e65100;color:#fff;border:none;border-radius:4px;padding:4px 10px;cursor:pointer;font-size:11px;white-space:nowrap">✏️ Editar</button>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>`;
|
|
|
|
|
}).join('');
|
|
|
|
|
// Calcula saldo de caixa real (mesma fórmula do relatório)
|
|
|
|
|
// SALDO CAIXA = soma dos campos individuais (total do sistema no relatório)
|
|
|
|
|
// Lê do top-level E do JSON dados (compatibilidade com registros antigos)
|
|
|
|
|
// SALDO CAIXA = soma dos campos individuais (total do sistema no relatório)
|
|
|
|
|
// Prioriza top-level, só usa dados.dados se top-level for 0/missing (compat old records)
|
|
|
|
|
const f = (item, dados, field) => parseFloat(item[field]||dados[field]||0);
|
|
|
|
|
const calcSaldoCaixa = item => {
|
|
|
|
|
const dados = item.dados || {};
|
|
|
|
|
return f(item,dados,'saldo_troco')
|
|
|
|
|
+ f(item,dados,'saldo_credito')
|
|
|
|
|
+ f(item,dados,'saldo_debito')
|
|
|
|
|
+ f(item,dados,'saldo_alimentacao')
|
|
|
|
|
+ f(item,dados,'saldo_vales')
|
|
|
|
|
+ f(item,dados,'saldo_areceber')
|
|
|
|
|
+ f(item,dados,'total_pixcnpj')
|
|
|
|
|
+ f(item,dados,'total_cartao_pix');
|
|
|
|
|
};
|
|
|
|
|
const calcCancelamentos = item => {
|
|
|
|
|
const dados = item.dados || {};
|
|
|
|
|
return (parseFloat(item.total_cancelamentos)||0)
|
|
|
|
|
+ (parseFloat(dados.total_cancelamentos)||0)
|
|
|
|
|
+ (parseFloat(dados.cancelamentos)||0); // old format: array of cancelamentos
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Ordena por data desc e pega os últimos 5 dias distintos
|
|
|
|
|
const sortedDesc = [...recentList].sort((a,b) => b.data.localeCompare(a.data));
|
|
|
|
|
const cincoDias = sortedDesc.slice(0, 5);
|
|
|
|
|
|
|
|
|
|
// Último dia distinto (para placeholder do input)
|
|
|
|
|
const ultimoDia = sortedDesc[0]?.data || '';
|
|
|
|
|
|
|
|
|
|
function renderRows(list) {
|
|
|
|
|
if (!list || list.length === 0) {
|
|
|
|
|
return `<tr><td colspan="8" style="padding:20px;text-align:center;color:#888;font-size:13px">Nenhum registro encontrado.</td></tr>`;
|
|
|
|
|
}
|
|
|
|
|
return list.map((item, i) => {
|
|
|
|
|
const saldoCaixa = calcSaldoCaixa(item);
|
|
|
|
|
const canc = calcCancelamentos(item);
|
|
|
|
|
const diff = saldoCaixa - (parseFloat(item.saldo_esperado)||0) - canc;
|
|
|
|
|
const diffClass = Math.abs(diff) <= 4.50 ? '#2e7d32' : diff > 0 ? '#e65100' : '#c0272d';
|
|
|
|
|
const diffLabel = Math.abs(diff) <= 4.50 ? `✓ OK (${diff===0?'0':(diff>0?'+':'-')+Math.abs(diff).toFixed(2).replace('.',',')})` : diff > 0 ? `+R$ ${diff.toFixed(2).replace('.',',')} SOBRANDO` : `-R$ ${Math.abs(diff).toFixed(2).replace('.',',')} FALTANDO`;
|
|
|
|
|
return `<tr data-idx="${recentList.indexOf(item)}" style="background:${i%2===0?'#fff':'#fafafa'}" onmouseover="this.style.background='#fff3e0'" onmouseout="this.style.background='${i%2===0?'#fff':'#fafafa'}'">
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${fmtDate(item.data)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${item.operador||'?'}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${item.turno||'?'}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${fmtMoney(saldoCaixa)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${fmtMoney(item.saldo_esperado)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${fmtMoney(canc)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:center;cursor:pointer;color:${diffClass};font-weight:bold" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${diffLabel}</td>
|
|
|
|
|
<td style="padding:4px 6px;border-bottom:1px solid #eee;text-align:center">
|
|
|
|
|
<button onclick="event.stopPropagation();window.abrirEditaFechamentoIndex(${recentList.indexOf(item)})" style="background:#e65100;color:#fff;border:none;border-radius:4px;padding:4px 10px;cursor:pointer;font-size:11px;white-space:nowrap">✏️ Editar</button>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>`;
|
|
|
|
|
}).join('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
overlay.innerHTML = `
|
|
|
|
|
<div style="background:#fff;border-radius:10px;padding:20px;max-width:780px;width:95%;max-height:85vh;overflow-y:auto">
|
|
|
|
|
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:12px">
|
|
|
|
|
<h2 style="margin:0;font-size:16px">📅 Consultar Fechamentos Anteriores</h2>
|
|
|
|
|
<button onclick="closeConsultaModal()" style="background:none;border:none;font-size:18px;cursor:pointer">✕</button>
|
|
|
|
|
<div style="background:#fff;border-radius:10px;padding:20px;max-width:900px;width:95%;max-height:85vh;overflow-y:auto">
|
|
|
|
|
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:12px;flex-wrap:wrap;gap:8px">
|
|
|
|
|
<h2 style="margin:0;font-size:16px">📅 Consultar Fechamentos</h2>
|
|
|
|
|
<div style="display:flex;gap:6px;align-items:center;flex-wrap:wrap">
|
|
|
|
|
<span style="font-size:12px;color:#555">De:</span>
|
|
|
|
|
<input type="date" id="consulta-busca-de" value="" max="${ultimoDia}" style="padding:6px 10px;border:1px solid #ccc;border-radius:6px;font-size:13px" />
|
|
|
|
|
<span style="font-size:12px;color:#555">Até:</span>
|
|
|
|
|
<input type="date" id="consulta-busca-ate" value="" max="${ultimoDia}" style="padding:6px 10px;border:1px solid #ccc;border-radius:6px;font-size:13px" />
|
|
|
|
|
<select id="consulta-busca-turno" style="padding:6px 10px;border:1px solid #ccc;border-radius:6px;font-size:13px;background:#fff">
|
|
|
|
|
<option value="">Todos turnos</option>
|
|
|
|
|
<option value="manha">Manhã</option>
|
|
|
|
|
<option value="tarde">Tarde</option>
|
|
|
|
|
<option value="integral">Integral</option>
|
|
|
|
|
</select>
|
|
|
|
|
<button onclick="window._filtrarConsulta()" style="background:#1565c0;color:#fff;border:none;border-radius:6px;padding:6px 14px;cursor:pointer;font-size:13px">🔍 Buscar</button>
|
|
|
|
|
<button onclick="closeConsultaModal()" style="background:none;border:none;font-size:18px;cursor:pointer;padding:4px 8px">✕</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="consulta-info" style="font-size:11px;color:#888;margin-bottom:8px">Mostrando últimos 5 dias</div>
|
|
|
|
|
<div style="max-height:55vh;overflow-y:auto;border:1px solid #eee;border-radius:6px">
|
|
|
|
|
<table style="width:100%;border-collapse:collapse">
|
|
|
|
|
<thead style="position:sticky;top:0;background:#f5f5f5;z-index:1">
|
|
|
|
|
<tr>
|
|
|
|
|
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">DATA</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">OPERADOR</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">TURNO</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">SALDO CAIXA</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">ESPERADO</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">CANCEL.</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">DIFERENÇA</th>
|
|
|
|
|
<th style="padding:4px 6px;text-align:center;font-size:11px;color:#888">AÇÃO</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody id="consulta-tbody">${renderRows(cincoDias)}</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="margin-top:8px;font-size:11px;color:#888;text-align:center">
|
|
|
|
|
Mostrando últimos 5 dias. Use a <strong>busca por data</strong> para encontrar registros mais antigos.
|
|
|
|
|
</div>
|
|
|
|
|
<p style="font-size:12px;color:#666;margin:0 0 10px">Clique em um registro para ver o relatório ou clique em <strong>Editar</strong> para abrir a janela de edição.</p>
|
|
|
|
|
<table style="width:100%;border-collapse:collapse">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr style="background:#f5f5f5">
|
|
|
|
|
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">DATA</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">OPERADOR</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">TURNO</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">SALDO CAIXA</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">ESPERADO</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">STATUS</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">SYNC</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">AÇÃO</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>${rows}</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(overlay);
|
|
|
|
|
|
|
|
|
|
// Função de busca por período
|
|
|
|
|
window._filtrarConsulta = () => {
|
|
|
|
|
const de = document.getElementById('consulta-busca-de')?.value;
|
|
|
|
|
const ate = document.getElementById('consulta-busca-ate')?.value;
|
|
|
|
|
const turno = document.getElementById('consulta-busca-turno')?.value || '';
|
|
|
|
|
const tbody = document.getElementById('consulta-tbody');
|
|
|
|
|
const info = document.getElementById('consulta-info');
|
|
|
|
|
if (!tbody) return;
|
|
|
|
|
let filtrados = [...recentList];
|
|
|
|
|
if (de) filtrados = filtrados.filter(item => item.data >= de);
|
|
|
|
|
if (ate) filtrados = filtrados.filter(item => item.data <= ate);
|
|
|
|
|
if (turno) filtrados = filtrados.filter(item => (item.turno||'').toLowerCase() === turno);
|
|
|
|
|
if (de || ate || turno) {
|
|
|
|
|
tbody.innerHTML = renderRows(filtrados);
|
|
|
|
|
const label = `${filtrados.length} registro${filtrados.length!==1?'s':''}${de&&ate?` de ${fmtDate(de)} a ${fmtDate(ate)}`:de?` a partir de ${fmtDate(de)}`:ate?` até ${fmtDate(ate)}`:''}`;
|
|
|
|
|
if (info) info.textContent = label;
|
|
|
|
|
} else {
|
|
|
|
|
tbody.innerHTML = renderRows(cincoDias);
|
|
|
|
|
if (info) info.textContent = 'Mostrando últimos 5 dias';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Enter na busca
|
|
|
|
|
['consulta-busca-de','consulta-busca-ate'].forEach(id => {
|
|
|
|
|
document.getElementById(id)?.addEventListener('keydown', e => { if (e.key === 'Enter') window._filtrarConsulta(); });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window._recentList = recentList;
|
|
|
|
|
window._consultaAll = recentList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Abre a janela de edição completa de um registro pelo índice na lista
|
|
|
|
@@ -2262,6 +2379,7 @@ window.abrirEditaFechamentoIndex = async function(idx) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closeConsultaModal();
|
|
|
|
|
if (!await askPassword()) return;
|
|
|
|
|
window.abrirEditaFechamento(full);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -2546,25 +2664,26 @@ window.toggleEditConsulta = async function() {
|
|
|
|
|
// Se já está editando, apenas fecha
|
|
|
|
|
if (window._editModalOpen) { closeEditModal(); return; }
|
|
|
|
|
|
|
|
|
|
// Pede senha admin primeiro — sempre, para proteger edições
|
|
|
|
|
const pw = config.admin_password;
|
|
|
|
|
if (pw) {
|
|
|
|
|
const ok = await askPassword();
|
|
|
|
|
if (!ok) return;
|
|
|
|
|
} else {
|
|
|
|
|
// Sem senha configurada — avisa e abre mesmo assim (primeiro uso)
|
|
|
|
|
const ok = await askPassword(); // mostra diálogo vazio para o admin configurar mentalmente
|
|
|
|
|
if (!ok) return;
|
|
|
|
|
}
|
|
|
|
|
// Pede senha — sempre, uma vez (aceita fixa ou dinâmica)
|
|
|
|
|
if (!await askPassword()) return;
|
|
|
|
|
|
|
|
|
|
openEditModal(full);
|
|
|
|
|
closeRelatorioModal();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Pede senha admin — retorna Promise<boolean>
|
|
|
|
|
// Calcula senha dinâmica do dia: dia e mês como 2 dígitos cada, concatenados
|
|
|
|
|
// ex: 17/12 → "1712"
|
|
|
|
|
function getDynamicPw() {
|
|
|
|
|
const d = new Date();
|
|
|
|
|
const day = String(d.getDate()).padStart(2, '0');
|
|
|
|
|
const month = String(d.getMonth() + 1).padStart(2, '0');
|
|
|
|
|
return day + month;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function askPassword() {
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
|
const pw = config.admin_password;
|
|
|
|
|
const fixedPw = config.admin_password;
|
|
|
|
|
const dynPw = getDynamicPw();
|
|
|
|
|
const overlay = document.createElement('div');
|
|
|
|
|
overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:999999;display:flex;align-items:center;justify-content:center;';
|
|
|
|
|
overlay.id = 'pw-modal';
|
|
|
|
@@ -2589,7 +2708,7 @@ function askPassword() {
|
|
|
|
|
inp.addEventListener('keydown', e => { if (e.key === 'Enter') document.getElementById('pw-ok-btn').click(); });
|
|
|
|
|
document.getElementById('pw-ok-btn').addEventListener('click', () => {
|
|
|
|
|
const val = document.getElementById('pw-input').value;
|
|
|
|
|
if (val === pw) {
|
|
|
|
|
if (val === fixedPw || val === dynPw || val === config.dynamic_password) {
|
|
|
|
|
document.getElementById('pw-modal').remove();
|
|
|
|
|
resolve(true);
|
|
|
|
|
} else {
|
|
|
|
@@ -2716,7 +2835,35 @@ window._recalcEditTotals = function() {
|
|
|
|
|
if (el('tot-areceber')) el('tot-areceber').textContent = fmtTot(recv_tot);
|
|
|
|
|
if (el('tot-sangrias')) el('tot-sangrias').textContent = fmtTot(sang_tot);
|
|
|
|
|
if (el('tot-despesas')) el('tot-despesas').textContent = fmtTot(desp_tot);
|
|
|
|
|
if (el('tot-cancel')) el('tot-cancel').textContent = fmtTot(canc_tot);
|
|
|
|
|
if (el('tot-cancel')) el('tot-cancel').textContent = fmtTot(canc_tot);
|
|
|
|
|
|
|
|
|
|
// Atualiza campos readonly do saldo de caixa com totais calculados
|
|
|
|
|
const setReadonly = (id, v) => { if (el(id)) el(id).value = fmtTot(v); };
|
|
|
|
|
setReadonly('edit-sld-credito', cartCred_tot);
|
|
|
|
|
setReadonly('edit-sld-debito', cartDeb_tot);
|
|
|
|
|
setReadonly('edit-sld-alimentacao', cartAli_tot);
|
|
|
|
|
setReadonly('edit-sld-vales', vales_tot);
|
|
|
|
|
setReadonly('edit-sld-pixcnpj', pixcnpj_tot);
|
|
|
|
|
setReadonly('edit-sld-areceber', recv_tot);
|
|
|
|
|
setReadonly('edit-sld-pixcartao', cartPix_tot);
|
|
|
|
|
|
|
|
|
|
// Calcula Saldo Caixa e Diferença em tempo real
|
|
|
|
|
const trocoVal = parseNum(el('edit-troco')?.value || '0');
|
|
|
|
|
const esperadoVal = parseNum(el('edit-esperado')?.value || '0');
|
|
|
|
|
const saldoCaixa = trocoVal + cartCred_tot + cartDeb_tot + cartAli_tot + cartPix_tot + pixcnpj_tot + vales_tot + recv_tot;
|
|
|
|
|
const diferenca = saldoCaixa - esperadoVal - canc_tot;
|
|
|
|
|
|
|
|
|
|
if (el('edit-saldo-caixa')) {
|
|
|
|
|
el('edit-saldo-caixa').textContent = saldoCaixa > 0 ? fmtTot(saldoCaixa) : 'R$ 0,00';
|
|
|
|
|
}
|
|
|
|
|
if (el('edit-diferenca')) {
|
|
|
|
|
const fmtDif = v => v >= 0 ? `R$ ${v.toLocaleString('pt-BR', { minimumFractionDigits: 2 })}` : `-R$ ${Math.abs(v).toLocaleString('pt-BR', { minimumFractionDigits: 2 })}`;
|
|
|
|
|
el('edit-diferenca').textContent = fmtDif(diferenca);
|
|
|
|
|
// Alerta visual se diferença != 0
|
|
|
|
|
if (el('edit-diferenca-box')) {
|
|
|
|
|
el('edit-diferenca-box').style.background = diferenca === 0 ? '#e8f5e9' : diferenca > 0 ? '#fff3e0' : '#ffebee';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Modal de edição completo com todas as grades
|
|
|
|
@@ -2935,7 +3082,8 @@ function openEditModal(full) {
|
|
|
|
|
<div style="margin-bottom:12px;background:#f5f5f5;border-radius:6px;padding:8px">
|
|
|
|
|
<strong style="font-size:12px;color:#333;margin-bottom:4px;display:block">💰 Saldo de Caixa <span style="font-size:10px;color:#888">(apenas Troco é editável)</span></strong>
|
|
|
|
|
<div style="display:grid;grid-template-columns:repeat(4,1fr);gap:6px">
|
|
|
|
|
<div><label style="font-size:10px;color:#555">Troco:</label><input type="text" id="edit-troco" value="${fmtMR(full.saldo_troco)}" style="width:100%;padding:5px;border:1px solid #2e7d32;border-radius:4px;text-align:right" onblur="this.value=fmtBR(this)" /></div>
|
|
|
|
|
<div><label style="font-size:10px;color:#555">Troco:</label><input type="text" id="edit-troco" value="${fmtMR(full.saldo_troco)}" style="width:100%;padding:5px;border:1px solid #2e7d32;border-radius:4px;text-align:right" oninput="window._recalcEditTotals()" onblur="this.value=fmtBR(this)" /></div>
|
|
|
|
|
<div><label style="font-size:10px;color:#555">Saldo Esperado:</label><input type="text" id="edit-esperado" value="${fmtMR(full.saldo_esperado)}" style="width:100%;padding:5px;border:1px solid #e65100;border-radius:4px;text-align:right;font-weight:bold" oninput="window._recalcEditTotals()" onblur="this.value=fmtBR(this)" /></div>
|
|
|
|
|
<div><label style="font-size:10px;color:#888">Crédito:</label><input type="text" id="edit-sld-credito" value="${fmtMR(full.saldo_credito)}" readonly tabindex="-1" style="width:100%;padding:5px;border:1px solid #ddd;border-radius:4px;text-align:right;background:#eee;color:#666" /></div>
|
|
|
|
|
<div><label style="font-size:10px;color:#888">Débito:</label><input type="text" id="edit-sld-debito" value="${fmtMR(full.saldo_debito)}" readonly tabindex="-1" style="width:100%;padding:5px;border:1px solid #ddd;border-radius:4px;text-align:right;background:#eee;color:#666" /></div>
|
|
|
|
|
<div><label style="font-size:10px;color:#888">Alimentação:</label><input type="text" id="edit-sld-alimentacao" value="${fmtMR(full.saldo_alimentacao)}" readonly tabindex="-1" style="width:100%;padding:5px;border:1px solid #ddd;border-radius:4px;text-align:right;background:#eee;color:#666" /></div>
|
|
|
|
@@ -2944,14 +3092,23 @@ function openEditModal(full) {
|
|
|
|
|
<div><label style="font-size:10px;color:#888">À Receber:</label><input type="text" id="edit-sld-areceber" value="${fmtMR(full.saldo_areceber)}" readonly tabindex="-1" style="width:100%;padding:5px;border:1px solid #ddd;border-radius:4px;text-align:right;background:#eee;color:#666" /></div>
|
|
|
|
|
<div><label style="font-size:10px;color:#888">PIX Cartão:</label><input type="text" id="edit-sld-pixcartao" value="${fmtMR(full.total_cartao_pix)}" readonly tabindex="-1" style="width:100%;padding:5px;border:1px solid #ddd;border-radius:4px;text-align:right;background:#eee;color:#666" /></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:6px;margin-top:6px">
|
|
|
|
|
<div style="background:#e3f2fd;border-radius:4px;padding:6px 8px;text-align:right">
|
|
|
|
|
<span style="font-size:11px;color:#1565c0">SALDO CAIXA:</span>
|
|
|
|
|
<span id="edit-saldo-caixa" style="font-size:16px;font-weight:bold;color:#1565c0;margin-left:8px">R$ 0,00</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="edit-diferenca-box" style="background:#fff3e0;border-radius:4px;padding:6px 8px;text-align:right">
|
|
|
|
|
<span style="font-size:11px;color:#e65100">DIFERENÇA:</span>
|
|
|
|
|
<span id="edit-diferenca" style="font-size:16px;font-weight:bold;color:#e65100;margin-left:8px">R$ 0,00</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Contadores -->
|
|
|
|
|
<div style="display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:6px;margin-bottom:12px">
|
|
|
|
|
<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:6px;margin-bottom:12px">
|
|
|
|
|
<div><label style="font-size:10px;color:#555">Clientes:</label><input type="number" id="edit-clientes" value="${dados.clientes||full.clientes||0}" min="0" style="width:100%;padding:5px;border:1px solid #ccc;border-radius:4px" /></div>
|
|
|
|
|
<div><label style="font-size:10px;color:#555">Frango Assado:</label><input type="number" id="edit-frango" value="${dados.frango||full.frango||0}" min="0" style="width:100%;padding:5px;border:1px solid #ccc;border-radius:4px" /></div>
|
|
|
|
|
<div><label style="font-size:10px;color:#555">Vendas (R$):</label><input type="text" id="edit-vendas" value="${fmtMR(dados.vendas||full.vendas||0)}" style="width:100%;padding:5px;border:1px solid #e65100;border-radius:4px;text-align:right;font-weight:bold" onblur="this.value=fmtBR(this)" /></div>
|
|
|
|
|
<div><label style="font-size:10px;color:#555">Saldo Esperado:</label><input type="text" id="edit-esperado" value="${fmtMR(full.saldo_esperado)}" style="width:100%;padding:5px;border:1px solid #e65100;border-radius:4px;text-align:right;font-weight:bold" onblur="this.value=fmtBR(this)" /></div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Observações -->
|
|
|
|
@@ -2967,6 +3124,8 @@ function openEditModal(full) {
|
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(overlay);
|
|
|
|
|
// Calcula totais iniciais após renderizar o DOM
|
|
|
|
|
setTimeout(() => window._recalcEditTotals(), 50);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Formata campo de dinheiro brasileiro
|
|
|
|
@@ -3153,6 +3312,11 @@ window.salvarEdicaoModal = async function() {
|
|
|
|
|
total_pixcnpj: pixcnpj_tot,
|
|
|
|
|
total_areceber: recv_tot,
|
|
|
|
|
total_cancelamentos: canc_tot,
|
|
|
|
|
total_cartao_pix: cartPix_tot,
|
|
|
|
|
|
|
|
|
|
// Diferença calculada
|
|
|
|
|
diferenca: p(inp('edit-troco')) + cartCred_tot + cartDeb_tot + cartAli_tot + cartPix_tot + pixcnpj_tot + vales_tot + recv_tot
|
|
|
|
|
- p(inp('edit-esperado')) - canc_tot,
|
|
|
|
|
|
|
|
|
|
// Fechamento (campos calculados que o formato antigo usava no dados)
|
|
|
|
|
fechamento_dinheiro: p(inp('edit-troco')) + vales_tot + sang_tot - desp_tot - canc_tot,
|
|
|
|
@@ -3402,26 +3566,26 @@ window.printRelatorio = function() {
|
|
|
|
|
<title>Fechamento de Caixa</title>
|
|
|
|
|
<style>
|
|
|
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
|
body { font-family: 'Courier New', monospace; font-size: 14px; width: 80mm; margin: 0 auto; padding: 8px; font-weight: bold; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
|
|
|
|
|
body { font-family: 'Courier New', monospace; font-size: 18px; width: 80mm; margin: 0 auto; padding: 8px; font-weight: bold; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
|
|
|
|
|
.header { text-align: center; margin-bottom: 8px; }
|
|
|
|
|
.header h1 { font-size: 20px; font-weight: bold; }
|
|
|
|
|
.header h2 { font-size: 15px; font-weight: normal; }
|
|
|
|
|
.header h1 { font-size: 24px; font-weight: bold; }
|
|
|
|
|
.header h2 { font-size: 18px; font-weight: normal; }
|
|
|
|
|
hr { border: none; border-top: 2px solid #000; margin: 6px 0; }
|
|
|
|
|
.section-title { font-weight: bold; font-size: 14px; border-top: 2px solid #000; padding-top: 4px; margin-top: 8px; }
|
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 13px; font-weight: bold; }
|
|
|
|
|
.section-title { font-weight: bold; font-size: 17px; border-top: 2px solid #000; padding-top: 4px; margin-top: 8px; }
|
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 16px; font-weight: bold; }
|
|
|
|
|
.row.total-row { font-weight: bold; }
|
|
|
|
|
.cart-table { table-layout: fixed; width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; font-weight: bold; }
|
|
|
|
|
.cart-table { table-layout: fixed; width: 100%; border-collapse: collapse; font-size: 16px; margin-top: 4px; font-weight: bold; }
|
|
|
|
|
.cart-table th { font-weight: bold; border-bottom: 2px solid #000; padding: 2px; width: 25%; }
|
|
|
|
|
.cart-table td { padding: 2px 4px; text-align: right; font-weight: bold; }
|
|
|
|
|
.cart-table td:first-child { text-align: left; }
|
|
|
|
|
.cart-table tr.total-row { font-weight: bold; border-top: 2px solid #000; }
|
|
|
|
|
.subtotal { font-size: 13px; margin-top: 4px; }
|
|
|
|
|
.subtotal { font-size: 16px; margin-top: 4px; }
|
|
|
|
|
.subtotal .row { padding: 2px 0; }
|
|
|
|
|
.diff-ok { color: #2e7d32; font-weight: bold; }
|
|
|
|
|
.diff-bad { color: #c0272d; font-weight: bold; }
|
|
|
|
|
.obs { font-size: 11px; color: #555; margin-top: 6px; white-space: pre-wrap; font-weight: normal; }
|
|
|
|
|
.footer { text-align: center; font-size: 11px; color: #555; margin-top: 8px; }
|
|
|
|
|
@media print { body { background: #fff; font-weight: bold !important; } }
|
|
|
|
|
.obs { font-size: 13px; color: #555; margin-top: 6px; white-space: pre-wrap; font-weight: normal; }
|
|
|
|
|
.footer { text-align: center; font-size: 13px; color: #555; margin-top: 8px; }
|
|
|
|
|
@media print { body { background: #fff; font-weight: bold !important; font-size: 18px !important; } }
|
|
|
|
|
</style>
|
|
|
|
|
</head><body>
|
|
|
|
|
${buildPrintHTML(data)}
|
|
|
|
@@ -3516,10 +3680,40 @@ async function salvarEdicaoSupabase() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Boot ─────────────────────────────────────────────────────────────────
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
|
// Detecta se é build com loja fixa (União ou Aliança)
|
|
|
|
|
try {
|
|
|
|
|
const fixa = await window.__TAURI__.core.invoke('get_loja_fixa');
|
|
|
|
|
if (fixa) {
|
|
|
|
|
// Build fixa: marca global, esconde e bloqueia o seletor de loja
|
|
|
|
|
window.__LOJA_FIXA__ = fixa;
|
|
|
|
|
estado.loja = fixa;
|
|
|
|
|
|
|
|
|
|
const sel = document.getElementById('f-loja');
|
|
|
|
|
if (sel) {
|
|
|
|
|
sel.value = fixa;
|
|
|
|
|
sel.disabled = true;
|
|
|
|
|
sel.style.display = 'none';
|
|
|
|
|
}
|
|
|
|
|
// Esconde o label "Loja" (procura pelo texto, não pela posição)
|
|
|
|
|
document.querySelectorAll('.meta-label').forEach(l => {
|
|
|
|
|
if (l.textContent.trim() === 'Loja') l.style.display = 'none';
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch(e) {
|
|
|
|
|
console.warn('get_loja_fixa não disponível:', e);
|
|
|
|
|
}
|
|
|
|
|
loadConfig();
|
|
|
|
|
buildDatalists();
|
|
|
|
|
if (!loadState()) init();
|
|
|
|
|
|
|
|
|
|
// ⚠️ Segurança extra: se build fixa, garante que o valor do select está correto
|
|
|
|
|
// e que estado.loja nunca fica vazio (independentemente do que init() fez)
|
|
|
|
|
if (window.__LOJA_FIXA__) {
|
|
|
|
|
const sel = document.getElementById('f-loja');
|
|
|
|
|
if (sel) sel.value = window.__LOJA_FIXA__;
|
|
|
|
|
estado.loja = window.__LOJA_FIXA__;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
|