Compare commits

...

3 Commits

Author SHA1 Message Date
root f45d1e8170 fix: somatório atualiza após add linha; saldo caixa só troco editável; printRelatorio fixed; salvamento via uuid; edited_at/by; totales completos
Build Fechamento de Caixa / build (macos-14, app) (push) Has been cancelled
Build Fechamento de Caixa / build (ubuntu-22.04, deb) (push) Has been cancelled
Build Fechamento de Caixa / build (windows-2022, msi) (push) Has been cancelled
2026-06-30 18:33:38 +00:00
root 8ea5ba771a feat: impressao bold; JSON vales/sangrias/despesas/pixcnpj/receber/cancelamentos; recalc on add row
Build Fechamento de Caixa / build (macos-14, app) (push) Has been cancelled
Build Fechamento de Caixa / build (ubuntu-22.04, deb) (push) Has been cancelled
Build Fechamento de Caixa / build (windows-2022, msi) (push) Has been cancelled
2026-06-30 18:08:19 +00:00
root 84578fe43d feat: _recalcEditTotals oninput; fmtBR onblur; IDs nos spans de totais
Build Fechamento de Caixa / build (macos-14, app) (push) Has been cancelled
Build Fechamento de Caixa / build (ubuntu-22.04, deb) (push) Has been cancelled
Build Fechamento de Caixa / build (windows-2022, msi) (push) Has been cancelled
2026-06-30 14:58:42 +00:00
+141 -77
View File
@@ -1380,32 +1380,32 @@ function buildConfirmHTML(data) {
<td>${cartPix > 0 ? fmt(cartPix) : '-'}</td>
</tr>`;
return `<!DOCTYPE html>
let html = `<!DOCTYPE html>
<html><head>
<meta charset="UTF-8">
<title>Fechamento de Caixa</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; }
body { font-family: 'Courier New', monospace; font-size: 13px; 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: 18px; }
.header h1 { font-size: 18px; font-weight: bold; }
.header h2 { font-size: 14px; font-weight: normal; }
hr { border: none; border-top: 1px dashed #000; margin: 5px 0; }
.section-title { font-weight: bold; font-size: 13px; border-top: 1px dashed #000; padding-top: 3px; margin-top: 6px; }
.row { display: flex; justify-content: space-between; padding: 1px 0; font-size: 12px; }
.row { display: flex; justify-content: space-between; padding: 1px 0; font-size: 12px; font-weight: bold; }
.row.total-row { font-weight: bold; }
.cart-table { width: 100%; border-collapse: collapse; font-size: 11px; margin-top: 4px; }
.cart-table { width: 100%; border-collapse: collapse; font-size: 11px; margin-top: 4px; font-weight: bold; }
.cart-table th { font-weight: bold; border-bottom: 1px solid #000; padding: 2px; }
.cart-table td { padding: 2px 4px; text-align: right; }
.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: 1px dashed #000; }
.subtotal { font-size: 12px; margin-top: 4px; }
.diff-ok { color: #2e7d32; }
.diff-bad { color: #c0272d; }
.obs { font-size: 11px; color: #555; margin-top: 6px; white-space: pre-wrap; }
.subtotal .row { padding: 1px 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 { margin: 0; } }
</style>
@media print { body { background: #fff; font-weight: bold !important; } }
</head><body>
<div class="header">
<h1>${data.loja}</h1>
@@ -1604,26 +1604,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: 13px; width: 80mm; margin: 0 auto; padding: 8px; }
body { font-family: 'Courier New', monospace; font-size: 13px; 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: 18px; }
.header h1 { font-size: 18px; font-weight: bold; }
.header h2 { font-size: 14px; font-weight: normal; }
hr { border: none; border-top: 1px dashed #000; margin: 5px 0; }
.section-title { font-weight: bold; font-size: 13px; border-top: 1px dashed #000; padding-top: 3px; margin-top: 6px; }
.row { display: flex; justify-content: space-between; padding: 1px 0; font-size: 12px; }
.row { display: flex; justify-content: space-between; padding: 1px 0; font-size: 12px; font-weight: bold; }
.row.total-row { font-weight: bold; }
.cart-table { width: 100%; border-collapse: collapse; font-size: 11px; margin-top: 4px; }
.cart-table { width: 100%; border-collapse: collapse; font-size: 11px; margin-top: 4px; font-weight: bold; }
.cart-table th { font-weight: bold; border-bottom: 1px solid #000; padding: 2px; }
.cart-table td { padding: 2px 4px; text-align: right; }
.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: 1px dashed #000; }
.subtotal { font-size: 12px; margin-top: 4px; }
.subtotal .row { padding: 1px 0; }
.diff-ok { color: #2e7d32; }
.diff-bad { color: #c0272d; }
.obs { font-size: 11px; color: #555; margin-top: 6px; white-space: pre-wrap; }
.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 { margin: 0; } }
@media print { body { background: #fff; font-weight: bold !important; } }
</style>
</head><body>
<div class="header">
@@ -1853,9 +1853,11 @@ function triggerWindowPrint() {
window.print();
}
// ─── Recibo 80mm via Tauri (ESC/POS USB) ─────────────────────────────────
// ─── Recibo 80mm via Tauri (ESC/POS USB) ─────────────────────────────────
// Build data object shared by both ESC/POS and preview
// ─── buildReciboData — lê do FORMULÁRIO principal (não do estado carregado do BD) ───
// Importante: quando editing, o estado estápopulado pelo abrirFechamentoEdicao, não do BD
// ─── buildReciboData — lê do FORMULÁRIO principal ───────────────────────────
// usado tanto para novo fechamento quanto para edição
function buildReciboData() {
const cartCred = estado.cartoes.credito.reduce((s,r) => s+(r.valor||0), 0);
const cartDeb = estado.cartoes.debito.reduce((s,r) => s+(r.valor||0), 0);
@@ -1876,6 +1878,7 @@ function buildReciboData() {
return {
uuid: estado.uuid,
id_local: estado.id_local,
id: estado.id,
loja: estado.loja,
data: estado.data,
operador: estado.operador,
@@ -1899,7 +1902,7 @@ function buildReciboData() {
vales: valesTotal,
areceber: receberTotal,
cancelamentos: cancelTotal,
// Full arrays for preview
// Full arrays for preview / Supabase
despesas_arr: estado.despesas.map(r => ({ desc: r.desc||'', obs: r.obs||'', valor: r.valor||0 })),
sangrias_arr: estado.sangrias.map(r => ({ hora: r.hora||'', retirada: parseNum(r.retirada)||0, gerente: r.gerente||'' })),
pixcnpj_arr: estado.pixcnpj.map(r => ({ nome: r.nome||'', valor: r.valor||0 })),
@@ -1910,10 +1913,22 @@ function buildReciboData() {
cartoes_debito: estado.cartoes.debito.map(r => r.valor || 0),
cartoes_alimentacao: estado.cartoes.alimentacao.map(r => r.valor || 0),
cartoes_pix: estado.cartoes.pix.map(r => r.valor || 0),
total_cartao_credito: cartCred,
total_cartao_debito: cartDeb,
total_cartao_alimentacao: cartAli,
total_cartao_pix: cartPix,
total_pixcnpj: pixCnpjTotal,
total_sangrias: sangriasTotal,
total_despesas: despesasTotal,
total_vales: valesTotal,
total_areceber: receberTotal,
total_cancelamentos: cancelTotal,
observacoes: estado.observacoes,
clientes: estado.clientes,
frango: estado.frango,
vendas: estado.vendas || 0,
edited_at: new Date().toISOString(),
edited_by: config.admin_user || 'admin',
sync_status: estado.sync_status,
};
}
@@ -2527,7 +2542,10 @@ function editTableHTML(id, headers, rows, numericCols) {
const displayVal = (val !== null && val !== undefined && val !== '')
? (isNum ? fmtNum(val) : val)
: '';
return `<td style="padding:1px 2px"><input data-tbl="${id}" data-row="${ri}" data-col="${ci}" value="${displayVal}" ${isNum ? `style="width:100%;padding:2px;font-size:11px;text-align:right;border:1px solid #ccc;border-radius:2px"` : `style="width:100%;padding:2px;font-size:11px;border:1px solid #ccc;border-radius:2px"`} /></td>`;
const extra = isNum
? `oninput="window._recalcEditTotals()" onblur="this.value=fmtBR(this)" `
: '';
return `<td style="padding:1px 2px"><input data-tbl="${id}" data-row="${ri}" data-col="${ci}" value="${displayVal}" ${extra}${isNum ? `style="width:100%;padding:2px;font-size:11px;text-align:right;border:1px solid #ccc;border-radius:2px"` : `style="width:100%;padding:2px;font-size:11px;border:1px solid #ccc;border-radius:2px"`} /></td>`;
}).join('');
return `<tr>${cells}</tr>`;
}).join('');
@@ -2553,8 +2571,10 @@ window._editAddRow = function(tblId) {
for (let c = 0; c < cols; c++) {
const td = row.insertCell(-1);
const isNum = numericCols.includes(c);
td.innerHTML = `<input data-tbl="${tblId}" data-row="${newRowIdx}" data-col="${c}" value="" ${isNum ? `style="width:100%;padding:2px;font-size:11px;text-align:right;border:1px solid #ccc;border-radius:2px"` : `style="width:100%;padding:2px;font-size:11px;border:1px solid #ccc;border-radius:2px"`} />`;
td.innerHTML = `<input data-tbl="${tblId}" data-row="${newRowIdx}" data-col="${c}" value="" ${isNum ? `oninput="window._recalcEditTotals()" onblur="this.value=fmtBR(this)" style="width:100%;padding:2px;font-size:11px;text-align:right;border:1px solid #ccc;border-radius:2px"` : `style="width:100%;padding:2px;font-size:11px;border:1px solid #ccc;border-radius:2px"`} />`;
}
// Recalcula após adicionar
window._recalcEditTotals();
};
// Lê todos os dados das grades editáveis do modal
@@ -2586,6 +2606,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;
@@ -2619,27 +2668,27 @@ function openEditModal(full) {
const cartPixHTML = editTableHTML('pix', ['Valor (R$)'], cartPix_rows.length ? cartPix_rows : [['']], [0]);
// --- Vales ---
const vales_rows = (full.vales || []).map(r => [r.nome||r.Nome||'', r.valor, r.obs||r.Obs||'']);
const vales_rows = (full.vales_arr || []).map(r => [r.nome||r.Nome||'', r.valor||0, r.obs||r.Obs||'']);
const valesHTML = editTableHTML('vales', ['Nome', 'Valor (R$)', 'Obs'], vales_rows.length ? vales_rows : [['','','']], [1]);
// --- Despesas ---
const despesas_rows = (full.despesas || []).map(r => [r.desc||r.Desc||'', r.obs||r.Obs||'', r.valor]);
const despesas_rows = (full.despesas_arr || []).map(r => [r.desc||r.Desc||'', r.obs||r.Obs||'', r.valor||0]);
const despesasHTML = editTableHTML('despesas', ['Descrição', 'Obs', 'Valor (R$)'], despesas_rows.length ? despesas_rows : [['','','']], [2]);
// --- Sangrias ---
const sangrias_rows = (full.sangrias || []).map(r => [r.hora||r.Hora||'', r.retirada, r.gerente||r.Gerente||'']);
const sangrias_rows = (full.sangrias_arr || []).map(r => [r.hora||r.Hora||'', r.retirada||r.valor||0, r.gerente||r.Gerente||'']);
const sangriasHTML = editTableHTML('sangrias', ['Hora', 'Valor (R$)', 'Gerente'], sangrias_rows.length ? sangrias_rows : [['','','']], [1]);
// --- Cancelamentos ---
const cancel_rows = (full.cancelamentos || []).map(r => [r.numero||r.Numero||'', r.valor, r.motivo||r.Motivo||'']);
const cancel_rows = (full.cancelamentos_arr || []).map(r => [r.numero||r.Numero||'', r.valor||0, r.motivo||r.Motivo||'']);
const cancelHTML = editTableHTML('cancelamentos', ['Número', 'Valor (R$)', 'Motivo'], cancel_rows.length ? cancel_rows : [['','','']], [1]);
// --- PIX CNPJ ---
const pixcnpj_rows = (full.pixcnpj || []).map(r => [r.nome||r.Nome||'', r.valor]);
const pixcnpj_rows = (full.pixcnpj_arr || []).map(r => [r.nome||r.desc||r.Desc||'', r.valor||0]);
const pixcnpjHTML = editTableHTML('pixcnpj', ['Nome', 'Valor (R$)'], pixcnpj_rows.length ? pixcnpj_rows : [['','']], [1]);
// --- A Receber ---
const receber_rows = (full.receber || []).map(r => [r.nome||r.Nome||'', r.valor]);
const receber_rows = (full.receber_arr || []).map(r => [r.nome||r.Nome||'', r.valor||0]);
const receberHTML = editTableHTML('receber', ['Nome', 'Valor (R$)'], receber_rows.length ? receber_rows : [['','']], [1]);
// --- Totais (só leitura formatado) ---
@@ -2649,10 +2698,12 @@ function openEditModal(full) {
<div><strong>Total Débito:</strong> <span id="edit-total-debito">${fmtMR(full.total_cartao_debito||0)}</span></div>
<div><strong>Total Alimentação:</strong> <span id="edit-total-alimentacao">${fmtMR(full.total_cartao_alimentacao||0)}</span></div>
<div><strong>Total PIX:</strong> <span id="edit-total-pix">${fmtMR(full.total_cartao_pix||0)}</span></div>
<div><strong>Total Sangrias:</strong> ${fmtMR(full.total_sangrias||0)}</div>
<div><strong>Total Despesas:</strong> ${fmtMR(full.total_despesas||0)}</div>
<div><strong>Total Vales:</strong> ${fmtMR(full.total_vales||0)}</div>
<div><strong>Total PIX CNPJ:</strong> ${fmtMR(full.total_pixcnpj||0)}</div>
<div><strong>Total Sangrias:</strong> <span id="edit-total-sangrias">${fmtMR(full.total_sangrias||0)}</span></div>
<div><strong>Total Despesas:</strong> <span id="edit-total-despesas">${fmtMR(full.total_despesas||0)}</span></div>
<div><strong>Total Vales:</strong> <span id="edit-total-vales">${fmtMR(full.total_vales||0)}</span></div>
<div><strong>Total PIX CNPJ:</strong> <span id="edit-total-pixcnpj">${fmtMR(full.total_pixcnpj||0)}</span></div>
<div><strong>Total Receber:</strong> <span id="edit-total-receber">${fmtMR(full.total_areceber||0)}</span></div>
<div><strong>Total Cancel:</strong> <span id="edit-total-cancel">${fmtMR(full.total_cancelamentos||0)}</span></div>
</div>`;
const overlay = document.createElement('div');
@@ -2781,25 +2832,26 @@ function openEditModal(full) {
<div id="tbl-edit-cancelamentos" data-numeric="[1]">${cancelHTML}</div>
</div>
<!-- Saldo de Caixa (editável) -->
<div style="margin-bottom:12px">
<strong style="font-size:12px;color:#333;margin-bottom:4px;display:block">💰 Saldo de Caixa</strong>
<!-- Saldo de Caixa (SÓ TROCO é editável — restante é soma automática) -->
<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 #ccc;border-radius:4px;text-align:right" onblur="this.value=fmtBR(this)" /></div>
<div><label style="font-size:10px;color:#555">Crédito:</label><input type="text" id="edit-sld-credito" value="${fmtMR(full.saldo_credito)}" style="width:100%;padding:5px;border:1px solid #ccc;border-radius:4px;text-align:right" onblur="this.value=fmtBR(this)" /></div>
<div><label style="font-size:10px;color:#555">Débito:</label><input type="text" id="edit-sld-debito" value="${fmtMR(full.saldo_debito)}" style="width:100%;padding:5px;border:1px solid #ccc;border-radius:4px;text-align:right" onblur="this.value=fmtBR(this)" /></div>
<div><label style="font-size:10px;color:#555">Alimentação:</label><input type="text" id="edit-sld-alimentacao" value="${fmtMR(full.saldo_alimentacao)}" style="width:100%;padding:5px;border:1px solid #ccc;border-radius:4px;text-align:right" onblur="this.value=fmtBR(this)" /></div>
<div><label style="font-size:10px;color:#555">Vales:</label><input type="text" id="edit-sld-vales" value="${fmtMR(full.saldo_vales)}" style="width:100%;padding:5px;border:1px solid #ccc;border-radius:4px;text-align:right" onblur="this.value=fmtBR(this)" /></div>
<div><label style="font-size:10px;color:#555">PIX CNPJ:</label><input type="text" id="edit-sld-pixcnpj" value="${fmtMR(full.total_pixcnpj)}" style="width:100%;padding:5px;border:1px solid #ccc;border-radius:4px;text-align:right" onblur="this.value=fmtBR(this)" /></div>
<div><label style="font-size:10px;color:#555">À Receber:</label><input type="text" id="edit-sld-areceber" value="${fmtMR(full.saldo_areceber)}" style="width:100%;padding:5px;border:1px solid #ccc;border-radius:4px;text-align:right" onblur="this.value=fmtBR(this)" /></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">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:#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>
<div><label style="font-size:10px;color:#888">Vales:</label><input type="text" id="edit-sld-vales" value="${fmtMR(full.saldo_vales)}" 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 CNPJ:</label><input type="text" id="edit-sld-pixcnpj" value="${fmtMR(full.total_pixcnpj)}" 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">À 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>
<!-- Contadores -->
<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:6px;margin-bottom:12px">
<div style="display:grid;grid-template-columns:1fr 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>
@@ -2934,10 +2986,12 @@ window.salvarEdicaoModal = async function() {
if (!hasTauri) { alert('Tauri não disponível.'); return; }
try {
const id = inp('edit-id') || full.id;
if (!id) { alert('ID do registro não encontrado.'); return; }
// Usa uuid (string) — que é o id externo do registro no Supabase
const uuid = full.uuid || full.id;
if (!uuid) { alert('UUID do registro não encontrado.'); return; }
console.log('[DEBUG] salvarEdicaoModal uuid:', uuid, 'updates:', JSON.stringify(updates));
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id, updates });
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { uuid, updates: JSON.stringify(updates) });
closeEditModal();
closeRelatorioModal();
alert('✅ Atualizado com sucesso!');
@@ -3093,30 +3147,37 @@ window.printRelatorio = function() {
const full = window._currentConsulta;
if (!full) return;
const data = consultaToPrintData(full);
const html = buildPrintHTML(data);
const previewStyle = `
<style>
body { width: 80mm; margin: 0 auto; font-family: 'Courier New', monospace; font-size: 13px; background: #fff; padding: 10px; }
.header { text-align: center; margin-bottom: 8px; }
.header h1 { font-size: 18px; }
.header h2 { font-size: 14px; font-weight: normal; }
hr { border: none; border-top: 1px dashed #000; margin: 5px 0; }
.section-title { font-weight: bold; font-size: 13px; border-top: 1px dashed #000; padding-top: 3px; margin-top: 6px; }
.row { display: flex; justify-content: space-between; padding: 1px 0; font-size: 12px; }
.row.total-row { font-weight: bold; }
.cart-table { width: 100%; border-collapse: collapse; font-size: 11px; margin-top: 4px; }
.cart-table th { font-weight: bold; border-bottom: 1px solid #000; padding: 2px; }
.cart-table td { padding: 2px 4px; text-align: right; }
.cart-table td:first-child { text-align: left; }
.cart-table tr.total-row { font-weight: bold; border-top: 1px dashed #000; }
.subtotal { font-size: 12px; margin-top: 4px; }
.diff-ok { color: #2e7d32; }
.diff-bad { color: #c0272d; }
.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; } }
</style>`;
const fullHtml = `<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Recibo</title>${previewStyle}</head><body>${html}</body></html>`;
let html = `<!DOCTYPE html>
<html><head>
<meta charset="UTF-8">
<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; }
.header { text-align: center; margin-bottom: 8px; }
.header h1 { font-size: 20px; font-weight: bold; }
.header h2 { font-size: 15px; 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; }
.row.total-row { font-weight: bold; }
.cart-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; font-weight: bold; }
.cart-table th { font-weight: bold; border-bottom: 2px solid #000; padding: 2px; }
.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 .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; } }
</style>
</head><body>
${buildPrintHTML(data)}
</body></html>`;
const existing = document.getElementById('print-preview-overlay');
if (existing) document.body.removeChild(existing);
@@ -3138,7 +3199,7 @@ window.printRelatorio = function() {
overlay.appendChild(btnFechar);
overlay.appendChild(btnImprimir);
document.body.appendChild(overlay);
iframe.srcdoc = fullHtml;
iframe.srcdoc = html;
};
// Intercepta o envio — se sync_status=editing, faz PATCH
@@ -3187,8 +3248,11 @@ async function salvarEdicaoSupabase() {
// Remove campos que não devem ir no PATCH
delete data.uuid;
delete data.id_local;
// Usa o id numérico se disponível, senão usa uuid
const id = estado.id || estado.uuid;
console.log('[DEBUG] salvando id:', id, 'data:', JSON.stringify(data));
const result = await window.__TAURI__.core.invoke('sb_atualizar_fechamento', {
uuid: estado.uuid,
uuid: id,
updates: JSON.stringify(data)
});
console.log('[DEBUG] sb_atualizar_fechamento result:', result);