|
|
|
@@ -427,6 +427,17 @@
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- CONTADORES -->
|
|
|
|
|
<div class="section">
|
|
|
|
|
<div class="section-header">📦 Vendas</div>
|
|
|
|
|
<div style="display:flex;gap:12px">
|
|
|
|
|
<div style="flex:1">
|
|
|
|
|
<label style="font-size:12px;color:#666">Vendas (R$)</label>
|
|
|
|
|
<input type="number" id="f-vendas" min="0" step="0.01" placeholder="0,00" style="width:100%;padding:8px;border:1px solid var(--border);border-radius:var(--radius);font-size:15px" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- CONTADORES -->
|
|
|
|
|
<div class="section">
|
|
|
|
|
<div class="section-header">👥 Clientes & Frango Assado</div>
|
|
|
|
@@ -593,7 +604,7 @@ let estado = {
|
|
|
|
|
despesas: [], sangrias: [], pixcnpj: [], vales: [], receber: [], cancelamentos: [],
|
|
|
|
|
cartoes: { credito: [], debito: [], alimentacao: [], pix: [] },
|
|
|
|
|
fechamento_contado: { dinheiro: 0, cartoes: 0, receber: 0 },
|
|
|
|
|
clientes: 0, frango: 0, // contadores
|
|
|
|
|
clientes: 0, frango: 0, vendas: 0, // contadores
|
|
|
|
|
observacoes: '', id_local: null, sync_status: 'local'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -873,10 +884,9 @@ function updateTotals() {
|
|
|
|
|
const fr = receberTotal;
|
|
|
|
|
setText('fech-total', fmt(fd + fc + fr));
|
|
|
|
|
|
|
|
|
|
// Diferença = fechamento - saldo_esperado - cancelamentos
|
|
|
|
|
const fechamentoTotal = fd + fc + fr;
|
|
|
|
|
// Diferença = total_fechamento (sysTotal: troco+credito+debito+alimentacao+vales+receber+pixCartao+pixCnpj) - saldo_esperado - cancelamentos
|
|
|
|
|
const cancelTotal = estado.cancelamentos.reduce((s,r) => s+(parseNum(r.valor||0)||0), 0);
|
|
|
|
|
const diff = fechamentoTotal - parseNum(val('f-saldo-esperado')) - cancelTotal;
|
|
|
|
|
const diff = sysTotal - parseNum(val('f-saldo-esperado')) - cancelTotal;
|
|
|
|
|
const difEl = document.getElementById('diferenca');
|
|
|
|
|
const badgeEl = document.getElementById('dif-badge');
|
|
|
|
|
if (difEl) {
|
|
|
|
@@ -1060,6 +1070,18 @@ const LS_KEY = 'fc_v7';
|
|
|
|
|
const CFG_KEY = 'fc_cfg';
|
|
|
|
|
|
|
|
|
|
function buildEstadoForBackend() {
|
|
|
|
|
// Calcula totais das tabelas (mesma lógica do updateTotals)
|
|
|
|
|
const sangriasTotal = estado.sangrias.reduce((s, r) => s + (parseNum(r['retirada'] || 0) || 0), 0);
|
|
|
|
|
const despesasTotal = estado.despesas.reduce((s, r) => s + (parseNum(r['valor'] || 0) || 0), 0);
|
|
|
|
|
const pixcnpjTotal = estado.pixcnpj.reduce((s, r) => s + (parseNum(r['valor'] || 0) || 0), 0);
|
|
|
|
|
const valesTotal = estado.vales.reduce((s, r) => s + (parseNum(r['valor'] || 0) || 0), 0);
|
|
|
|
|
const receberTotal = estado.receber.reduce((s, r) => s + (parseNum(r['valor'] || 0) || 0), 0);
|
|
|
|
|
const cancelTotal = estado.cancelamentos.reduce((s, r) => s + (parseNum(r['valor'] || 0) || 0), 0);
|
|
|
|
|
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);
|
|
|
|
|
const cartAli = estado.cartoes.alimentacao.reduce((s, r) => s + (r.valor || 0), 0);
|
|
|
|
|
const cartPix = estado.cartoes.pix.reduce((s, r) => s + (r.valor || 0), 0);
|
|
|
|
|
|
|
|
|
|
// Monta o objeto exactly as o backend espera (storage.rs → salvar_fechamento)
|
|
|
|
|
return {
|
|
|
|
|
uuid: estado.uuid,
|
|
|
|
@@ -1068,9 +1090,31 @@ function buildEstadoForBackend() {
|
|
|
|
|
data: estado.data,
|
|
|
|
|
operador: estado.operador,
|
|
|
|
|
turno: estado.turno,
|
|
|
|
|
saldo_troco: parseNum(val('sys-troco')), // troco do sistema
|
|
|
|
|
saldo_troco: parseNum(val('sys-troco')),
|
|
|
|
|
saldo_esperado: parseNum(val('f-saldo-esperado')),
|
|
|
|
|
fechamento: parseNum(val('f-fech-dinheiro')) + parseNum(val('f-fech-cartoes')) + parseNum(val('f-fech-receber')),
|
|
|
|
|
// Saldos de cartões (do Sys / Saldo de Caixa)
|
|
|
|
|
credito: parseNum(val('sys-credito')) || cartCred,
|
|
|
|
|
debito: parseNum(val('sys-debito')) || cartDeb,
|
|
|
|
|
alimentacao: parseNum(val('sys-alimentacao')) || cartAli,
|
|
|
|
|
pixcnpj: parseNum(val('sys-pixcnpj')) || pixcnpjTotal,
|
|
|
|
|
vales: parseNum(val('sys-vales')) || valesTotal,
|
|
|
|
|
receber: parseNum(val('sys-receber')) || receberTotal,
|
|
|
|
|
// Totais para colunas SQL
|
|
|
|
|
total_sangrias: sangriasTotal,
|
|
|
|
|
total_despesas: despesasTotal,
|
|
|
|
|
total_pixcnpj: pixcnpjTotal,
|
|
|
|
|
total_vales: valesTotal,
|
|
|
|
|
total_areceber: receberTotal,
|
|
|
|
|
total_cancelamentos: cancelTotal,
|
|
|
|
|
total_cartao_credito: cartCred,
|
|
|
|
|
total_cartao_debito: cartDeb,
|
|
|
|
|
total_cartao_alimentacao: cartAli,
|
|
|
|
|
total_cartao_pix: cartPix,
|
|
|
|
|
// Fechamento contado
|
|
|
|
|
fd: parseNum(val('f-fech-dinheiro')),
|
|
|
|
|
fc: parseNum(val('f-fech-cartoes')),
|
|
|
|
|
fr: parseNum(val('f-fech-receber')),
|
|
|
|
|
despesas: estado.despesas.map(r => ({ desc: r.desc || '', obs: r.obs || '', valor: r.valor || 0 })),
|
|
|
|
|
sangrias: estado.sangrias.map(r => ({ hora: r.hora || '', retirada: r.retirada || 0, gerente: r.gerente || '' })),
|
|
|
|
|
pixcnpj: estado.pixcnpj.map(r => ({ nome: r.nome || '', valor: r.valor || 0 })),
|
|
|
|
@@ -1086,6 +1130,7 @@ function buildEstadoForBackend() {
|
|
|
|
|
observacoes: estado.observacoes,
|
|
|
|
|
clientes: estado.clientes,
|
|
|
|
|
frango: estado.frango,
|
|
|
|
|
vendas: estado.vendas,
|
|
|
|
|
sync_status: estado.sync_status,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
@@ -1104,6 +1149,7 @@ function saveState() {
|
|
|
|
|
};
|
|
|
|
|
estado.clientes = parseInt(document.getElementById('f-clientes').value) || 0;
|
|
|
|
|
estado.frango = parseInt(document.getElementById('f-frango').value) || 0;
|
|
|
|
|
estado.vendas = parseFloat(document.getElementById('f-vendas').value) || 0;
|
|
|
|
|
estado.updatedAt = new Date().toISOString();
|
|
|
|
|
try { localStorage.setItem(LS_KEY, JSON.stringify(estado)); } catch(e) {}
|
|
|
|
|
}
|
|
|
|
@@ -1125,6 +1171,7 @@ function loadState() {
|
|
|
|
|
estado.observacoes = saved.observacoes || '';
|
|
|
|
|
estado.clientes = saved.clientes || 0;
|
|
|
|
|
estado.frango = saved.frango || 0;
|
|
|
|
|
estado.vendas = saved.vendas || 0;
|
|
|
|
|
estado.sync_status = saved.sync_status || 'local';
|
|
|
|
|
// Restore tables (always as arrays of objects)
|
|
|
|
|
estado.despesas = Array.isArray(saved.despesas) ? saved.despesas : [];
|
|
|
|
@@ -1636,6 +1683,10 @@ ${cancLines.map(l => `<div class="row"><span>${l.label}</span><span>${fmt(l.valo
|
|
|
|
|
<div class="row"><span>À Receber:</span><span>${fmt(frec)}</span></div>
|
|
|
|
|
<div class="row total-row"><span>TOTAL:</span><span>${fmt(ftotal)}</span></div>
|
|
|
|
|
|
|
|
|
|
<div class="section-title">CONTADORES</div>
|
|
|
|
|
<div class="row"><span>Clientes:</span><span>${data.clientes || 0}</span></div>
|
|
|
|
|
<div class="row"><span>Frango Assado:</span><span>${data.frango || 0}</span></div>
|
|
|
|
|
|
|
|
|
|
${data.observacoes ? `<div class="obs">${data.observacoes}</div>` : ''}
|
|
|
|
|
|
|
|
|
|
<div class="footer">Gerado em ${new Date().toLocaleString('pt-BR')}</div>
|
|
|
|
@@ -1695,8 +1746,6 @@ function buildReportHTML(data) {
|
|
|
|
|
<div class="row"><span>💳 Débito:</span><span class="val">${fmt(cartDeb)}</span></div>
|
|
|
|
|
<div class="row"><span>💳 Alimentação:</span><span class="val">${fmt(cartAli)}</span></div>
|
|
|
|
|
<div class="row"><span>❌ Cancelamentos:</span><span class="val">${fmt(cancelamentos)}</span></div>
|
|
|
|
|
<div class="row"><span>👥 Clientes:</span><span class="val">${data.clientes || 0}</span></div>
|
|
|
|
|
<div class="row"><span>🍗 Frango Assado:</span><span class="val">${data.frango || 0}</span></div>
|
|
|
|
|
<hr>
|
|
|
|
|
<div class="row"><span>📋 Fechamento (contado):</span><span class="val">${fmt(fechamento)}</span></div>
|
|
|
|
|
<div class="row"><span>🖥️ Total Sistema:</span><span class="val">${fmt(sysTotal)}</span></div>
|
|
|
|
@@ -1704,6 +1753,10 @@ function buildReportHTML(data) {
|
|
|
|
|
<div class="row"><span>🎯 Saldo Esperado (contado):</span><span class="val">${fmt(saldoEsp)}</span></div>
|
|
|
|
|
<div class="row"><span>📐 Diferença:</span><span class="val" style="color:${diffColor}">${diffStr}</span></div>
|
|
|
|
|
<hr>
|
|
|
|
|
<div class="row"><span>👥 Clientes:</span><span class="val">${data.clientes || 0}</span></div>
|
|
|
|
|
<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 class="footer">Gerado em ${new Date().toLocaleString('pt-BR')}</div>
|
|
|
|
|
</body></html>`;
|
|
|
|
@@ -1919,6 +1972,7 @@ function openConfirmModal() {
|
|
|
|
|
<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>
|
|
|
|
|
<hr style="border:none;border-top:1px dashed #b3d9f7;margin:6px 0">
|
|
|
|
@@ -2026,20 +2080,17 @@ document.getElementById('btn-limpar').addEventListener('click', () => {
|
|
|
|
|
showToast('Rascunho limpo.', 'info');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ─── Dia Anterior — seleção de registro do Supabase ────────────────────────
|
|
|
|
|
// ─── Dia Anterior — seleção + consulta + edição de registros do Supabase ───
|
|
|
|
|
const btnAnterior = document.getElementById('btn-anterior');
|
|
|
|
|
if (btnAnterior) {
|
|
|
|
|
btnAnterior.addEventListener('click', async () => {
|
|
|
|
|
console.log('[DEBUG] btn-anterior clicado');
|
|
|
|
|
const hasTauri = !!(window.__TAURI__ && window.__TAURI__.core);
|
|
|
|
|
|
|
|
|
|
// Pega lista do Supabase
|
|
|
|
|
let recentList = [];
|
|
|
|
|
if (hasTauri) {
|
|
|
|
|
try {
|
|
|
|
|
const loja = val('f-loja') || 'União';
|
|
|
|
|
recentList = await window.__TAURI__.core.invoke('sb_listar_recentes', { loja, limite: 50 });
|
|
|
|
|
console.log('[DEBUG] sb_listar_recentes retornou:', recentList?.length, 'itens');
|
|
|
|
|
} catch(e) {
|
|
|
|
|
console.warn('sb_listar_recentes falhou:', e);
|
|
|
|
|
}
|
|
|
|
@@ -2050,19 +2101,17 @@ if (btnAnterior) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mostra modal de seleção com datas
|
|
|
|
|
buildAnteriorModal(recentList);
|
|
|
|
|
buildConsultaModal(recentList);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Monta e abre o modal de seleção de dia anterior
|
|
|
|
|
function buildAnteriorModal(recentList) {
|
|
|
|
|
// Remove modal anterior
|
|
|
|
|
const old = document.getElementById('modal-anterior');
|
|
|
|
|
// Monta o modal de consulta — lista de fechamentos do Supabase
|
|
|
|
|
function buildConsultaModal(recentList) {
|
|
|
|
|
const old = document.getElementById('modal-consulta');
|
|
|
|
|
if (old) document.body.removeChild(old);
|
|
|
|
|
|
|
|
|
|
const overlay = document.createElement('div');
|
|
|
|
|
overlay.id = 'modal-anterior';
|
|
|
|
|
overlay.id = 'modal-consulta';
|
|
|
|
|
overlay.style.cssText = `
|
|
|
|
|
position:fixed;top:0;left:0;right:0;bottom:0;
|
|
|
|
|
background:rgba(0,0,0,0.6);z-index:99998;
|
|
|
|
@@ -2074,35 +2123,49 @@ function buildAnteriorModal(recentList) {
|
|
|
|
|
const [y,m,day] = d.split('-');
|
|
|
|
|
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>';
|
|
|
|
|
if (s === 'faltando') return '<span style="color:#c0272d;font-weight:bold">⚠ FALTANDO</span>';
|
|
|
|
|
return s || '?';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const rows = recentList.map((item, i) => `
|
|
|
|
|
<tr style="cursor:pointer" onclick="selectDiaAnterior(${i})">
|
|
|
|
|
const rows = recentList.map((item, i) => {
|
|
|
|
|
const total = (parseFloat(item.fechamento_dinheiro)||0) + (parseFloat(item.fechamento_cartoes)||0) + (parseFloat(item.fechamento_areceber)||0);
|
|
|
|
|
return `<tr style="cursor:pointer" onclick="openConsultaRegistro(${i})">
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px">${fmtDate(item.data)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px">${item.operador||'?'}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px">${item.turno||'?'}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right">${fmtMoney(total)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right">${fmtMoney(item.saldo_esperado)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px">${statusBadge(item.status_diferenca)}</td>
|
|
|
|
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px">${syncBadge(item.sync_status)}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
`).join('');
|
|
|
|
|
</tr>`;
|
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
overlay.innerHTML = `
|
|
|
|
|
<div style="background:#fff;border-radius:10px;padding:20px;max-width:480px;width:90%;max-height:80vh;overflow-y:auto">
|
|
|
|
|
<div style="background:#fff;border-radius:10px;padding:20px;max-width:700px;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">📅 Selecionar Dia Anterior</h2>
|
|
|
|
|
<button onclick="closeAnteriorModal()" style="background:none;border:none;font-size:18px;cursor:pointer">✕</button>
|
|
|
|
|
<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>
|
|
|
|
|
<p style="font-size:12px;color:#666;margin:0 0 10px">Clique em um registro para carregar. Dados do Supabase.</p>
|
|
|
|
|
<p style="font-size:12px;color:#666;margin:0 0 10px">Clique em um registro para ver o relatório e, se necessário, editar campos com senha admin.</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:left;font-size:11px;color:#888">STATUS</th>
|
|
|
|
|
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">FECHAMENTO</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>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>${rows}</tbody>
|
|
|
|
@@ -2114,102 +2177,588 @@ function buildAnteriorModal(recentList) {
|
|
|
|
|
window._recentList = recentList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeAnteriorModal() {
|
|
|
|
|
const m = document.getElementById('modal-anterior');
|
|
|
|
|
function closeConsultaModal() {
|
|
|
|
|
const m = document.getElementById('modal-consulta');
|
|
|
|
|
if (m) document.body.removeChild(m);
|
|
|
|
|
window._recentList = null;
|
|
|
|
|
window._currentConsulta = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Usuário clicou numa linha — pede senha se configurada
|
|
|
|
|
window.selectDiaAnterior = async function(idx) {
|
|
|
|
|
// Abre o relatório de um registro selecionado
|
|
|
|
|
window.openConsultaRegistro = async function(idx) {
|
|
|
|
|
const item = window._recentList[idx];
|
|
|
|
|
if (!item) return;
|
|
|
|
|
closeAnteriorModal();
|
|
|
|
|
closeConsultaModal();
|
|
|
|
|
|
|
|
|
|
const hasTauri = !!(window.__TAURI__ && window.__TAURI__.core);
|
|
|
|
|
if (!hasTauri) { alert('Tauri não disponível.'); return; }
|
|
|
|
|
|
|
|
|
|
let full = null;
|
|
|
|
|
try {
|
|
|
|
|
// 1. Tentar por id numérico (campo "id" da tabela, pk)
|
|
|
|
|
if (item.id) {
|
|
|
|
|
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_id', { id: item.id }); } catch(e) {}
|
|
|
|
|
}
|
|
|
|
|
// 2. Tentar por uuid externo
|
|
|
|
|
if (!full && item.uuid) {
|
|
|
|
|
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_uuid', { uuid: item.uuid }); } catch(e) {}
|
|
|
|
|
}
|
|
|
|
|
// 3. Tentar por id_fechamento (ex: uniao_2026-06-11_filipe)
|
|
|
|
|
if (!full && item.id_fechamento) {
|
|
|
|
|
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_id_fechamento', { idFechamento: item.id_fechamento }); } catch(e) {}
|
|
|
|
|
}
|
|
|
|
|
} catch(e) {
|
|
|
|
|
console.warn('Erro buscando registro:', e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!full) { alert('Registro não encontrado.'); return; }
|
|
|
|
|
|
|
|
|
|
// Preserva o id numerico (pk da tabela) antes de guardar o registro completo
|
|
|
|
|
window._currentConsulta = full;
|
|
|
|
|
window._currentConsultaId = item.id;
|
|
|
|
|
buildRelatorioModal(full);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Monta o modal de relatório (readonly) com opção de editar
|
|
|
|
|
function buildRelatorioModal(full) {
|
|
|
|
|
const old = document.getElementById('modal-relatorio');
|
|
|
|
|
if (old) document.body.removeChild(old);
|
|
|
|
|
|
|
|
|
|
const overlay = document.createElement('div');
|
|
|
|
|
overlay.id = 'modal-relatorio';
|
|
|
|
|
overlay.style.cssText = `
|
|
|
|
|
position:fixed;top:0;left:0;right:0;bottom:0;
|
|
|
|
|
background:rgba(0,0,0,0.6);z-index:99998;
|
|
|
|
|
display:flex;align-items:center;justify-content:center;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const fmt = v => v != null ? parseFloat(v).toFixed(2).replace('.', ',') : '0,00';
|
|
|
|
|
const fmtMoney = v => `R$ ${fmt(v)}`;
|
|
|
|
|
|
|
|
|
|
const dados = full.dados || {};
|
|
|
|
|
|
|
|
|
|
// Campos do sistema
|
|
|
|
|
const troco = parseFloat(full.saldo_troco || 0);
|
|
|
|
|
const credito = parseFloat(full.saldo_credito || 0);
|
|
|
|
|
const debito = parseFloat(full.saldo_debito || 0);
|
|
|
|
|
const alimentacao = parseFloat(full.saldo_alimentacao || 0);
|
|
|
|
|
const vales = parseFloat(full.saldo_vales || 0);
|
|
|
|
|
const pixCartao = parseFloat(full.total_cartao_pix || 0);
|
|
|
|
|
const pixCnpj = parseFloat(full.total_pixcnpj || 0);
|
|
|
|
|
const sysTotal = troco + credito + debito + alimentacao + vales + (parseFloat(full.saldo_areceber)||0) + pixCartao + pixCnpj;
|
|
|
|
|
|
|
|
|
|
// Campos contados
|
|
|
|
|
const fd = parseFloat(full.fechamento_dinheiro || 0);
|
|
|
|
|
const fc = parseFloat(full.fechamento_cartoes || 0);
|
|
|
|
|
const fr = parseFloat(full.fechamento_areceber || 0);
|
|
|
|
|
const fechamentoContado = fd + fc + fr;
|
|
|
|
|
|
|
|
|
|
// Despesas e sangrias
|
|
|
|
|
const totalDespesas = parseFloat(full.total_despesas || 0);
|
|
|
|
|
const totalSangrias = parseFloat(full.total_sangrias || 0);
|
|
|
|
|
const totalCancelamentos = parseFloat(full.total_cancelamentos || 0);
|
|
|
|
|
|
|
|
|
|
// Esperado e diferença
|
|
|
|
|
const saldoEsperado = parseFloat(full.saldo_esperado || 0);
|
|
|
|
|
const diferenca = parseFloat(full.diferenca || 0);
|
|
|
|
|
const statusDif = full.status_diferenca || '?';
|
|
|
|
|
|
|
|
|
|
const diffClass = statusDif === 'ok' ? '#2e7d32' : (statusDif === 'sobrando' ? '#e65100' : '#c0272d');
|
|
|
|
|
const diffLabel = statusDif === 'ok' ? '✓ OK' : (statusDif === 'sobrando' ? '⚠ SOBRANDO' : (statusDif === 'faltando' ? '⚠ FALTANDO' : statusDif));
|
|
|
|
|
|
|
|
|
|
const operador = full.operador || '?';
|
|
|
|
|
const turno = full.turno || '?';
|
|
|
|
|
const data = full.data || '?';
|
|
|
|
|
const loja = full.loja || '?';
|
|
|
|
|
const obs = full.observacoes || '';
|
|
|
|
|
const clientes = full.clientes || 0;
|
|
|
|
|
const frango = full.frango || 0;
|
|
|
|
|
const atualizado = full.atualizado_em ? new Date(full.atualizado_em).toLocaleString('pt-BR') : '?';
|
|
|
|
|
|
|
|
|
|
const totalGeral = fd + fc + fr;
|
|
|
|
|
|
|
|
|
|
overlay.innerHTML = `
|
|
|
|
|
<div id="relatorio-inner" style="background:#fff;border-radius:10px;padding:20px;max-width:520px;width:95%;max-height:90vh;overflow-y:auto;font-family:monospace;font-size:13px">
|
|
|
|
|
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:10px">
|
|
|
|
|
<h2 style="margin:0;font-size:15px">🧾 Relatório — ${loja.toUpperCase()}</h2>
|
|
|
|
|
<button onclick="closeRelatorioModal()" style="background:none;border:none;font-size:18px;cursor:pointer">✕</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div style="background:#f8f8f8;border-radius:6px;padding:10px;margin-bottom:10px;font-size:12px">
|
|
|
|
|
<div><strong>📅 Data:</strong> ${data} <strong>Turno:</strong> ${turno} <strong>Operador:</strong> ${operador}</div>
|
|
|
|
|
<div><strong>Atualizado:</strong> ${atualizado}</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div style="border:1px solid #ddd;border-radius:6px;overflow:hidden;margin-bottom:10px">
|
|
|
|
|
<div style="background:#e65100;color:#fff;padding:4px 8px;font-weight:bold;font-size:12px">FECHAMENTO DE CAIXA</div>
|
|
|
|
|
<div style="padding:8px">
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Troco (+)</span><span>${fmtMoney(troco)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Credito (+)</span><span>${fmtMoney(credito)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Debito (+)</span><span>${fmtMoney(debito)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Alimentacao (+)</span><span>${fmtMoney(alimentacao)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Vales (+)</span><span>${fmtMoney(vales)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>A Receber (+)</span><span>${fmtMoney(parseFloat(full.saldo_areceber||0))}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>PIX Cartao (+)</span><span>${fmtMoney(pixCartao)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>PIX CNPJ (+)</span><span>${fmtMoney(pixCnpj)}</span></div>
|
|
|
|
|
<div style="border-top:1px solid #ddd;margin-top:4px;padding-top:4px;display:flex;justify-content:space-between;font-weight:bold"><span>TOTAL SISTEMA</span><span style="color:#e65100">${fmtMoney(sysTotal)}</span></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div style="border:1px solid #ddd;border-radius:6px;overflow:hidden;margin-bottom:10px">
|
|
|
|
|
<div style="background:#1565c0;color:#fff;padding:4px 8px;font-weight:bold;font-size:12px">SALDO DE CAIXA (CONTADO)</div>
|
|
|
|
|
<div style="padding:8px">
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Dinheiro</span><span>${fmtMoney(fd)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Cartoes</span><span>${fmtMoney(fc)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>A Receber</span><span>${fmtMoney(fr)}</span></div>
|
|
|
|
|
<div style="border-top:1px solid #ddd;margin-top:4px;padding-top:4px;display:flex;justify-content:space-between;font-weight:bold"><span>TOTAL CONTADO</span><span>${fmtMoney(totalGeral)}</span></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div style="border:1px solid #ddd;border-radius:6px;overflow:hidden;margin-bottom:10px">
|
|
|
|
|
<div style="background:#333;color:#fff;padding:4px 8px;font-weight:bold;font-size:12px">RESULTADO</div>
|
|
|
|
|
<div style="padding:8px">
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Saldo Esperado</span><span>${fmtMoney(saldoEsperado)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Cancelamentos</span><span>- ${fmtMoney(totalCancelamentos)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between;border-top:1px solid #ddd;margin-top:4px;padding-top:4px">
|
|
|
|
|
<span>Diferenca</span>
|
|
|
|
|
<span style="color:${diffClass};font-weight:bold">${fmtMoney(Math.abs(diferenca))} ${diferenca >= 0 ? '(+)' : '(-)'}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="text-align:center;margin-top:4px;font-weight:bold;color:${diffClass}">${diffLabel}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div style="border:1px solid #ddd;border-radius:6px;overflow:hidden;margin-bottom:10px">
|
|
|
|
|
<div style="background:#555;color:#fff;padding:4px 8px;font-weight:bold;font-size:12px">DEMAIS TOTAIS</div>
|
|
|
|
|
<div style="padding:8px">
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Total Sangrias</span><span>${fmtMoney(totalSangrias)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Total Despesas</span><span>${fmtMoney(totalDespesas)}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Clientes</span><span>${clientes}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Frango Assado</span><span>${frango}</span></div>
|
|
|
|
|
<div style="display:flex;justify-content:space-between"><span>Vendas</span><span>${fmtMoney(full.vendas || 0)}</span></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
${obs ? `<div style="background:#fff8e1;border-radius:6px;padding:8px;margin-bottom:10px;font-size:12px"><strong>Obs:</strong> ${obs}</div>` : ''}
|
|
|
|
|
|
|
|
|
|
<div id="edit-section" style="display:none;margin-bottom:10px">
|
|
|
|
|
<input type="hidden" id="edit-id" value="${full.id || ''}" />
|
|
|
|
|
<div style="font-size:12px;color:#666;margin-bottom:6px;font-weight:bold">✏️ Editar valores do caixa (requer senha admin):</div>
|
|
|
|
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:6px;margin-bottom:8px">
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Troco:</label>
|
|
|
|
|
<input type="text" id="edit-troco" value="${fmtMoney(troco)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Credito:</label>
|
|
|
|
|
<input type="text" id="edit-credito" value="${fmtMoney(credito)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Debito:</label>
|
|
|
|
|
<input type="text" id="edit-debito" value="${fmtMoney(debito)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Alimentacao:</label>
|
|
|
|
|
<input type="text" id="edit-alimentacao" value="${fmtMoney(alimentacao)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Vales:</label>
|
|
|
|
|
<input type="text" id="edit-vales" value="${fmtMoney(vales)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">PIX Cartao:</label>
|
|
|
|
|
<input type="text" id="edit-pixcartao" value="${fmtMoney(pixCartao)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">PIX CNPJ:</label>
|
|
|
|
|
<input type="text" id="edit-pixcnpj" value="${fmtMoney(pixCnpj)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">A Receber:</label>
|
|
|
|
|
<input type="text" id="edit-areceber" value="${fmtMoney(parseFloat(full.saldo_areceber||0))}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="font-size:12px;color:#666;margin-bottom:4px;font-weight:bold;margin-top:6px">💰 Valores Contados:</div>
|
|
|
|
|
<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:6px;margin-bottom:8px">
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Dinheiro:</label>
|
|
|
|
|
<input type="text" id="edit-fd" value="${fmtMoney(fd)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Cartoes:</label>
|
|
|
|
|
<input type="text" id="edit-fc" value="${fmtMoney(fc)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">A Receber:</label>
|
|
|
|
|
<input type="text" id="edit-fr" value="${fmtMoney(fr)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:6px;margin-bottom:8px">
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Sangrias:</label>
|
|
|
|
|
<input type="text" id="edit-sangrias" value="${fmtMoney(totalSangrias)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Despesas:</label>
|
|
|
|
|
<input type="text" id="edit-despesas" value="${fmtMoney(totalDespesas)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Clientes:</label>
|
|
|
|
|
<input type="number" id="edit-clientes" value="${clientes}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Frango:</label>
|
|
|
|
|
<input type="number" id="edit-frango" value="${frango}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label style="font-size:10px;color:#555">Vendas:</label>
|
|
|
|
|
<input type="text" id="edit-vendas" value="${fmtMoney(full.vendas || 0)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div style="font-size:12px;color:#666;margin-bottom:4px;font-weight:bold;margin-top:6px">📋 Meta / Observacoes:</div>
|
|
|
|
|
<div style="margin-bottom:6px">
|
|
|
|
|
<label style="font-size:10px;color:#555">Saldo Esperado:</label>
|
|
|
|
|
<input type="text" id="edit-esperado" value="${fmtMoney(saldoEsperado)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
|
|
|
|
</div>
|
|
|
|
|
<div style="margin-bottom:6px">
|
|
|
|
|
<label style="font-size:10px;color:#555">Observacoes:</label>
|
|
|
|
|
<textarea id="edit-obs" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px;height:50px">${obs}</textarea>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div style="display:flex;gap:8px;flex-wrap:wrap">
|
|
|
|
|
<button onclick="window.printRelatorio()" style="flex:1;padding:8px;background:#1565c0;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px">🖨️ Imprimir</button>
|
|
|
|
|
<button onclick="(function(f){window.abrirFechamentoEdicao(f)})(window._currentConsulta)" style="flex:1;padding:8px;background:#7b1fa2;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px">✏️ Editar caixa completo</button>
|
|
|
|
|
<button onclick="window.toggleEditConsulta()" style="flex:1;padding:8px;background:#e65100;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px" id="btn-edit-consulta">✏️ Editar totais (senha)</button>
|
|
|
|
|
<button onclick="window.salvarEdicaoConsulta()" style="flex:1;padding:8px;background:#2e7d32;color:#fff;border:none;border-radius:6px;cursor:pointer;font-size:13px;display:none" id="btn-salvar-consulta">💾 Salvar</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(overlay);
|
|
|
|
|
window._editMode = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fecha o modal de relatório
|
|
|
|
|
function closeRelatorioModal() {
|
|
|
|
|
const m = document.getElementById('modal-relatorio');
|
|
|
|
|
if (m) document.body.removeChild(m);
|
|
|
|
|
window._currentConsulta = null;
|
|
|
|
|
window._editMode = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Restaura o estado completo do JSONB 'dados' e volta ao formulário em modo de edição
|
|
|
|
|
window.abrirFechamentoEdicao = function(full) {
|
|
|
|
|
const dados = full.dados || full;
|
|
|
|
|
if (!dados) { alert('Dados detalhados não encontrados neste registro.'); return; }
|
|
|
|
|
|
|
|
|
|
// Preenche o estado global com todos os campos do JSONB
|
|
|
|
|
estado.loja = dados.loja || full.loja || '';
|
|
|
|
|
estado.data = dados.data || full.data || '';
|
|
|
|
|
estado.operador = dados.operador || full.operador || '';
|
|
|
|
|
estado.turno = dados.turno || full.turno || '';
|
|
|
|
|
estado.clientes = dados.clientes ?? full.clientes ?? 0;
|
|
|
|
|
estado.frango = dados.frango ?? full.frango ?? 0;
|
|
|
|
|
estado.vendas = dados.vendas ?? full.vendas ?? 0;
|
|
|
|
|
estado.observacoes = dados.observacoes || full.observacoes || '';
|
|
|
|
|
estado.saldo_esperado = dados.saldo_esperado ?? full.saldo_esperado ?? 0;
|
|
|
|
|
|
|
|
|
|
// Listas detalhadas
|
|
|
|
|
estado.sangrias = (dados.sangrias || []).map(r => ({ hora: r.hora||r.Hora||'', retirada: r.retirada||r.Retirada||r.valor||0, gerente: r.gerente||r.Gerente||'' }));
|
|
|
|
|
estado.despesas = (dados.despesas || []).map(r => ({ desc: r.desc||r.Desc||'', obs: r.obs||r.Obs||'', valor: r.valor||r.Valor||0 }));
|
|
|
|
|
estado.vales = (dados.vales || []).map(r => ({ nome: r.nome||r.Nome||'', valor: r.valor||r.Valor||0 }));
|
|
|
|
|
estado.pixcnpj = (dados.pixcnpj || []).map(r => ({ desc: r.desc||'', valor: r.valor||r.Valor||0 }));
|
|
|
|
|
estado.receber = (dados.receber || []).map(r => ({ nome: r.nome||r.Nome||'', valor: r.valor||r.Valor||0 }));
|
|
|
|
|
estado.cancelamentos = (dados.cancelamentos || []).map(r => ({ numero: r.numero||r.Numero||'', valor: r.valor||r.Valor||0 }));
|
|
|
|
|
estado.cartoes = {
|
|
|
|
|
credito: (dados.cartoes?.credito || dados.cartoes_credito || []).map(r => ({ valor: r.valor||r.Valor||0 })),
|
|
|
|
|
debito: (dados.cartoes?.debito || dados.cartoes_debito || []).map(r => ({ valor: r.valor||r.Valor||0 })),
|
|
|
|
|
alimentacao:(dados.cartoes?.alimentacao|| dados.cartoes_alimentacao || []).map(r => ({ valor: r.valor||r.Valor||0 })),
|
|
|
|
|
pix: (dados.cartoes?.pix || dados.cartoes_pix || []).map(r => ({ valor: r.valor||r.Valor||0 }))
|
|
|
|
|
};
|
|
|
|
|
estado.fechamento_contado = dados.fechamento_contado || { dinheiro: 0, cartoes: 0, receber: 0 };
|
|
|
|
|
|
|
|
|
|
// Fecha o modal de consulta
|
|
|
|
|
closeRelatorioModal();
|
|
|
|
|
closeConsultaModal();
|
|
|
|
|
|
|
|
|
|
// Preenche os campos do formulário
|
|
|
|
|
setVal('f-loja', estado.loja);
|
|
|
|
|
setVal('f-data', estado.data);
|
|
|
|
|
setVal('f-operador', estado.operador);
|
|
|
|
|
setVal('f-turno', estado.turno);
|
|
|
|
|
setVal('f-clientes', estado.clientes);
|
|
|
|
|
setVal('f-frango', estado.frango);
|
|
|
|
|
setVal('f-vendas', estado.vendas);
|
|
|
|
|
|
|
|
|
|
// Renderiza todas as tabelas com os dados restaurados
|
|
|
|
|
renderTable('tbl-sangrias', estado.sangrias);
|
|
|
|
|
renderTable('tbl-despesas', estado.despesas);
|
|
|
|
|
renderTable('tbl-vales', estado.vales);
|
|
|
|
|
renderTable('tbl-pix', estado.pixcnpj);
|
|
|
|
|
renderTable('tbl-receber', estado.receber);
|
|
|
|
|
renderTable('tbl-cancelamentos',estado.cancelamentos);
|
|
|
|
|
renderTable('tbl-cartao-credito', estado.cartoes.credito);
|
|
|
|
|
renderTable('tbl-cartao-debito', estado.cartoes.debito);
|
|
|
|
|
renderTable('tbl-cartao-alimentacao',estado.cartoes.alimentacao);
|
|
|
|
|
renderTable('tbl-cartao-pix', estado.cartoes.pix);
|
|
|
|
|
|
|
|
|
|
// Recalcula totais
|
|
|
|
|
calcAll();
|
|
|
|
|
|
|
|
|
|
// Rola para o topo do formulário
|
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
|
|
|
|
|
|
alert('✅ Caixa carregado para edição. Verifique todos os valores antes de enviar.');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Toggle modo de edição — pede senha admin via modal (não via prompt)
|
|
|
|
|
window.toggleEditConsulta = async function() {
|
|
|
|
|
if (window._editMode) {
|
|
|
|
|
// Cancela edição
|
|
|
|
|
window._editMode = false;
|
|
|
|
|
document.getElementById('edit-section').style.display = 'none';
|
|
|
|
|
document.getElementById('btn-salvar-consulta').style.display = 'none';
|
|
|
|
|
document.getElementById('btn-edit-consulta').textContent = '✏️ Editar (senha)';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pw = config.admin_password;
|
|
|
|
|
if (pw) {
|
|
|
|
|
const input = prompt('🔐 Digite a senha admin para editar este registro:');
|
|
|
|
|
if (input !== pw) {
|
|
|
|
|
alert('Senha incorreta. Acesso negado.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!pw) {
|
|
|
|
|
window._editMode = true;
|
|
|
|
|
document.getElementById('edit-section').style.display = 'block';
|
|
|
|
|
document.getElementById('btn-salvar-consulta').style.display = 'block';
|
|
|
|
|
document.getElementById('btn-edit-consulta').textContent = '✕ Cancelar';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Modal com senha oculta
|
|
|
|
|
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';
|
|
|
|
|
overlay.innerHTML = `
|
|
|
|
|
<div style="background:#fff;border-radius:10px;padding:24px;width:300px;text-align:center">
|
|
|
|
|
<div style="font-size:18px;margin-bottom:16px">🔐 Senha Admin</div>
|
|
|
|
|
<input type="password" id="pw-input" placeholder="Digite a senha..." style="width:100%;padding:10px;font-size:14px;border:1px solid #ccc;border-radius:6px;box-sizing:border-box;margin-bottom:12px" />
|
|
|
|
|
<div id="pw-error" style="color:#c0272d;font-size:12px;margin-bottom:8px;display:none">Senha incorreta</div>
|
|
|
|
|
<div style="display:flex;gap:8px;justify-content:center">
|
|
|
|
|
<button onclick="document.getElementById('pw-modal').remove()" style="padding:8px 16px;background:#888;color:#fff;border:none;border-radius:6px;cursor:pointer">Cancelar</button>
|
|
|
|
|
<button id="pw-ok-btn" style="padding:8px 16px;background:#e65100;color:#fff;border:none;border-radius:6px;cursor:pointer">OK</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`;
|
|
|
|
|
document.body.appendChild(overlay);
|
|
|
|
|
const inp = document.getElementById('pw-input');
|
|
|
|
|
inp.focus();
|
|
|
|
|
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;
|
|
|
|
|
const err = document.getElementById('pw-error');
|
|
|
|
|
if (val === pw) {
|
|
|
|
|
document.getElementById('pw-modal').remove();
|
|
|
|
|
window._editMode = true;
|
|
|
|
|
document.getElementById('edit-section').style.display = 'block';
|
|
|
|
|
document.getElementById('btn-salvar-consulta').style.display = 'block';
|
|
|
|
|
document.getElementById('btn-edit-consulta').textContent = '✕ Cancelar';
|
|
|
|
|
} else {
|
|
|
|
|
err.style.display = 'block';
|
|
|
|
|
inp.value = '';
|
|
|
|
|
inp.focus();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Salva edições de volta ao Supabase
|
|
|
|
|
window.salvarEdicaoConsulta = async function() {
|
|
|
|
|
const full = window._currentConsulta;
|
|
|
|
|
if (!full) return;
|
|
|
|
|
|
|
|
|
|
const p = v => parseFloat((v || '0').replace(',', '.') || '0');
|
|
|
|
|
const inp = id => document.getElementById(id).value;
|
|
|
|
|
|
|
|
|
|
const updates = {
|
|
|
|
|
saldo_troco: p(inp('edit-troco')),
|
|
|
|
|
saldo_credito: p(inp('edit-credito')),
|
|
|
|
|
saldo_debito: p(inp('edit-debito')),
|
|
|
|
|
saldo_alimentacao: p(inp('edit-alimentacao')),
|
|
|
|
|
saldo_vales: p(inp('edit-vales')),
|
|
|
|
|
total_cartao_pix: p(inp('edit-pixcartao')),
|
|
|
|
|
total_pixcnpj: p(inp('edit-pixcnpj')),
|
|
|
|
|
saldo_areceber: p(inp('edit-areceber')),
|
|
|
|
|
fechamento_dinheiro: p(inp('edit-fd')),
|
|
|
|
|
fechamento_cartoes: p(inp('edit-fc')),
|
|
|
|
|
fechamento_areceber: p(inp('edit-fr')),
|
|
|
|
|
total_sangrias: p(inp('edit-sangrias')),
|
|
|
|
|
total_despesas: p(inp('edit-despesas')),
|
|
|
|
|
clientes: parseInt(inp('edit-clientes') || '0'),
|
|
|
|
|
frango: parseInt(inp('edit-frango') || '0'),
|
|
|
|
|
vendas: p(inp('edit-vendas')),
|
|
|
|
|
saldo_esperado: p(inp('edit-esperado')),
|
|
|
|
|
observacoes: inp('edit-obs')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const hasTauri = !!(window.__TAURI__ && window.__TAURI__.core);
|
|
|
|
|
if (!hasTauri) { alert('Tauri não disponível.'); return; }
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Primeiro tenta buscar por id (retorna registro completo)
|
|
|
|
|
let full = null;
|
|
|
|
|
if (item.id) {
|
|
|
|
|
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_id', { id: item.id }); } catch(e) {}
|
|
|
|
|
}
|
|
|
|
|
// Fallback: buscar por uuid
|
|
|
|
|
if (!full && item.uuid) {
|
|
|
|
|
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_uuid', { uuid: item.uuid }); } catch(e) {}
|
|
|
|
|
}
|
|
|
|
|
// Último fallback: carregar por loja+data
|
|
|
|
|
if (!full) {
|
|
|
|
|
const loja = val('f-loja') || 'União';
|
|
|
|
|
full = await window.__TAURI__.core.invoke('sb_carregar_rascunho', { loja, data: item.data });
|
|
|
|
|
}
|
|
|
|
|
const id = document.getElementById('edit-id').value || window._currentConsultaId || full.id;
|
|
|
|
|
if (!id) { alert('ID do registro não encontrado. Não é possível atualizar.'); return; }
|
|
|
|
|
|
|
|
|
|
if (!full) { alert('Registro não encontrado.'); return; }
|
|
|
|
|
|
|
|
|
|
// Aplica dados ao estado
|
|
|
|
|
if (full.data) { setVal('f-data', full.data); estado.data = full.data; }
|
|
|
|
|
if (full.operador) { setVal('f-operador', full.operador); estado.operador = full.operador; }
|
|
|
|
|
if (full.turno) { setVal('f-turno', full.turno); estado.turno = full.turno; }
|
|
|
|
|
if (full.saldo_troco != null) setVal('sys-troco', fmtNum(full.saldo_troco));
|
|
|
|
|
if (full.saldo_esperado != null) setVal('f-saldo-esperado', fmtNum(full.saldo_esperado));
|
|
|
|
|
if (full.observacoes) { setVal('f-obs', full.observacoes); estado.observacoes = full.observacoes; }
|
|
|
|
|
|
|
|
|
|
// Tenta carregar campos aninhados do campo "dados" (jsonb)
|
|
|
|
|
const dados = full.dados || full;
|
|
|
|
|
if (dados.despesas && Array.isArray(dados.despesas)) {
|
|
|
|
|
estado.despesas = dados.despesas.map(d => ({ desc: d.desc||d.descricao||'', obs: d.obs||'', valor: parseNum(d.valor)||0 }));
|
|
|
|
|
}
|
|
|
|
|
if (dados.sangrias && Array.isArray(dados.sangrias)) {
|
|
|
|
|
estado.sangrias = dados.sangrias.map(s => ({ hora: s.hora||'', retirada: parseNum(s.retirada)||0, gerente: s.gerente||'' }));
|
|
|
|
|
}
|
|
|
|
|
if (dados.pixcnpj && Array.isArray(dados.pixcnpj)) {
|
|
|
|
|
estado.pixcnpj = dados.pixcnpj.map(p => ({ nome: p.nome||'', valor: parseNum(p.valor)||0 }));
|
|
|
|
|
}
|
|
|
|
|
if (dados.vales && Array.isArray(dados.vales)) {
|
|
|
|
|
estado.vales = dados.vales.map(v => ({ nome: v.nome||'', obs: v.obs||'', valor: parseNum(v.valor)||0 }));
|
|
|
|
|
}
|
|
|
|
|
if (dados.receber && Array.isArray(dados.receber)) {
|
|
|
|
|
estado.receber = dados.receber.map(r => ({ nome: r.nome||'', valor: parseNum(r.valor)||0 }));
|
|
|
|
|
}
|
|
|
|
|
if (dados.cancelamentos && Array.isArray(dados.cancelamentos)) {
|
|
|
|
|
estado.cancelamentos = dados.cancelamentos.map(c => ({ numero: c.numero||'', valor: parseNum(c.valor)||0, motivo: c.motivo||'' }));
|
|
|
|
|
}
|
|
|
|
|
if (dados.cartoes) {
|
|
|
|
|
const norm = arr => Array.isArray(arr) ? arr.map(v => ({ valor: (typeof v === 'object') ? (parseNum(v.valor)||0) : (parseNum(v)||0) })) : [];
|
|
|
|
|
estado.cartoes.credito = norm(dados.cartoes.credito);
|
|
|
|
|
estado.cartoes.debito = norm(dados.cartoes.debito);
|
|
|
|
|
estado.cartoes.alimentacao = norm(dados.cartoes.alimentacao);
|
|
|
|
|
estado.cartoes.pix = norm(dados.cartoes.pix);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Marca como modo de edição — ao clicar Enviar vai fazer PATCH, não POST
|
|
|
|
|
estado.uuid = full.uuid || item.uuid || estado.uuid;
|
|
|
|
|
estado.id_local = full.id || item.id || null;
|
|
|
|
|
estado.sync_status = 'editing'; // flag: editar registro existente
|
|
|
|
|
|
|
|
|
|
PRE_FILL_TABLES.forEach(ensureOneRow);
|
|
|
|
|
Object.keys(TABLES).forEach(renderTable);
|
|
|
|
|
updateTotals();
|
|
|
|
|
syncUI();
|
|
|
|
|
scheduleSave();
|
|
|
|
|
|
|
|
|
|
alert(`✅ Registro carregado!\n\n📅 ${item.data}\n👤 ${item.operador||'?'} — ${item.turno||'?'}\n\nAo clicar "Enviar Fechamento", o registro será ATUALIZADO no Supabase (não criado novamente).`);
|
|
|
|
|
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id, updates });
|
|
|
|
|
alert('✅ Atualizado com sucesso!');
|
|
|
|
|
closeRelatorioModal();
|
|
|
|
|
} catch(e) {
|
|
|
|
|
console.error('Erro ao carregar registro:', e);
|
|
|
|
|
alert('Erro ao carregar registro: ' + (e?.message || e));
|
|
|
|
|
console.error('Erro ao salvar:', e);
|
|
|
|
|
alert('Erro ao salvar: ' + (e?.message || e));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Converte o registro "full" do Supabase para o formato usado pelo buildPrintHTML
|
|
|
|
|
function consultaToPrintData(full) {
|
|
|
|
|
const fmtDiff = v => 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ',');
|
|
|
|
|
const fmtDiffNeg = v => (v < 0 ? '-' : '') + 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ',');
|
|
|
|
|
const fmt = v => 'R$ ' + (v || 0).toFixed(2).replace('.', ',');
|
|
|
|
|
|
|
|
|
|
const cartCred = parseFloat(full.saldo_credito || 0);
|
|
|
|
|
const cartDeb = parseFloat(full.saldo_debito || 0);
|
|
|
|
|
const cartAli = parseFloat(full.saldo_alimentacao || 0);
|
|
|
|
|
const cartPix = parseFloat(full.total_cartao_pix || 0);
|
|
|
|
|
const pixCnpj = parseFloat(full.total_pixcnpj || 0);
|
|
|
|
|
const vales = parseFloat(full.saldo_vales || 0);
|
|
|
|
|
const receber = parseFloat(full.saldo_areceber || 0);
|
|
|
|
|
const troco = parseFloat(full.saldo_troco || 0);
|
|
|
|
|
const sysTotal = troco + cartCred + cartDeb + cartAli + cartPix + pixCnpj + vales + receber;
|
|
|
|
|
const fd = parseFloat(full.fechamento_dinheiro || 0);
|
|
|
|
|
const fc = parseFloat(full.fechamento_cartoes || 0);
|
|
|
|
|
const fr = parseFloat(full.fechamento_areceber || 0);
|
|
|
|
|
const ftotal = fd + fc + fr;
|
|
|
|
|
const saldoEsp = parseFloat(full.saldo_esperado || 0);
|
|
|
|
|
const diferenca = parseFloat(full.diferenca || 0);
|
|
|
|
|
const diffOk = diferenca === 0;
|
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmtDiff(diferenca)}` : fmtDiffNeg(diferenca);
|
|
|
|
|
const dados = full.dados || {};
|
|
|
|
|
|
|
|
|
|
const despesas_arr = (dados.despesas || []).map(d => ({ desc: d.desc || '', obs: d.obs || '', valor: parseFloat(d.valor || 0) }));
|
|
|
|
|
const sangrias_arr = (dados.sangrias || []).map(s => ({ hora: s.hora || '', retirada: parseFloat(s.retirada || 0), gerente: s.gerente || '', valor: parseFloat(s.valor || 0) }));
|
|
|
|
|
const pixcnpj_arr = (dados.pixcnpj || []).map(p => ({ nome: p.nome || '', valor: parseFloat(p.valor || 0) }));
|
|
|
|
|
const vales_arr = (dados.vales || []).map(v => ({ nome: v.nome || '', obs: v.obs || '', valor: parseFloat(v.valor || 0) }));
|
|
|
|
|
const receber_arr = (dados.receber || []).map(r => ({ nome: r.nome || '', valor: parseFloat(r.valor || 0) }));
|
|
|
|
|
const cancelamentos_arr = (dados.cancelamentos || []).map(c => ({ numero: c.numero || '', valor: parseFloat(c.valor || 0), motivo: c.motivo || '' }));
|
|
|
|
|
const cartoes_credito = (full.cartoes_credito || []).map(v => parseFloat(v || 0));
|
|
|
|
|
const cartoes_debito = (full.cartoes_debito || []).map(v => parseFloat(v || 0));
|
|
|
|
|
const cartoes_alimentacao = (full.cartoes_alimentacao || []).map(v => parseFloat(v || 0));
|
|
|
|
|
const cartoes_pix = (full.cartoes_pix || []).map(v => parseFloat(v || 0));
|
|
|
|
|
const totalSangrias = sangrias_arr.reduce((s, r) => s + r.retirada + r.valor, 0);
|
|
|
|
|
const totalDespesas = despesas_arr.reduce((s, r) => s + r.valor, 0);
|
|
|
|
|
const totalPixCnpj = pixcnpj_arr.reduce((s, r) => s + r.valor, 0);
|
|
|
|
|
const totalVales = vales_arr.reduce((s, r) => s + r.valor, 0);
|
|
|
|
|
const totalReceber = receber_arr.reduce((s, r) => s + r.valor, 0);
|
|
|
|
|
const totalCancel = cancelamentos_arr.reduce((s, r) => s + r.valor, 0);
|
|
|
|
|
const totalCartoes = cartCred + cartDeb + cartAli + cartPix;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
loja: full.loja || '?',
|
|
|
|
|
data: full.data || '?',
|
|
|
|
|
operador: full.operador || '?',
|
|
|
|
|
turno: full.turno || '?',
|
|
|
|
|
saldo_troco: troco,
|
|
|
|
|
saldo_esperado: saldoEsp,
|
|
|
|
|
fechamento: ftotal,
|
|
|
|
|
diferenca: diferenca,
|
|
|
|
|
sys_total: sysTotal,
|
|
|
|
|
fechamento_dinheiro: fd,
|
|
|
|
|
fechamento_cartoes: fc,
|
|
|
|
|
fechamento_areceber: fr,
|
|
|
|
|
credito: cartCred,
|
|
|
|
|
debito: cartDeb,
|
|
|
|
|
alimentacao: cartAli,
|
|
|
|
|
voucher: cartPix,
|
|
|
|
|
pixcnpj: pixCnpj,
|
|
|
|
|
vales: vales,
|
|
|
|
|
areceber: receber,
|
|
|
|
|
cancelamentos: totalCancel,
|
|
|
|
|
despesas_arr,
|
|
|
|
|
sangrias_arr,
|
|
|
|
|
pixcnpj_arr,
|
|
|
|
|
vales_arr,
|
|
|
|
|
receber_arr,
|
|
|
|
|
cancelamentos_arr,
|
|
|
|
|
cartoes_credito,
|
|
|
|
|
cartoes_debito,
|
|
|
|
|
cartoes_alimentacao,
|
|
|
|
|
cartoes_pix,
|
|
|
|
|
totalSangrias,
|
|
|
|
|
totalDespesas,
|
|
|
|
|
totalPixCnpj,
|
|
|
|
|
totalVales,
|
|
|
|
|
totalReceber,
|
|
|
|
|
totalCancel,
|
|
|
|
|
totalCartoes,
|
|
|
|
|
sysTotal,
|
|
|
|
|
saldoEsperado: saldoEsp,
|
|
|
|
|
diffStr,
|
|
|
|
|
diffOk,
|
|
|
|
|
fdin: fd,
|
|
|
|
|
fcarts: fc,
|
|
|
|
|
frec: fr,
|
|
|
|
|
ftotal,
|
|
|
|
|
observacoes: full.observacoes || '',
|
|
|
|
|
clientes: full.clientes || 0,
|
|
|
|
|
frango: full.frango || 0,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Imprime o relatório — usa iframe como openPrintPreview (Tauri não bloqueia)
|
|
|
|
|
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>`;
|
|
|
|
|
|
|
|
|
|
const existing = document.getElementById('print-preview-overlay');
|
|
|
|
|
if (existing) document.body.removeChild(existing);
|
|
|
|
|
const overlay = document.createElement('div');
|
|
|
|
|
overlay.id = 'print-preview-overlay';
|
|
|
|
|
overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.85);z-index:99999;display:flex;flex-direction:column;align-items:center;font-family:\'Courier New\',monospace;';
|
|
|
|
|
const iframe = document.createElement('iframe');
|
|
|
|
|
iframe.style.cssText = 'width:360px;height:600px;border:2px solid #555;margin-top:16px;background:#fff;';
|
|
|
|
|
iframe.id = 'print-iframe';
|
|
|
|
|
const btnFechar = document.createElement('button');
|
|
|
|
|
btnFechar.textContent = '✕ Fechar';
|
|
|
|
|
btnFechar.style.cssText = 'margin-top:12px;padding:10px 32px;background:#444;color:#fff;border:none;border-radius:6px;font-size:15px;cursor:pointer;';
|
|
|
|
|
btnFechar.onclick = () => document.body.removeChild(overlay);
|
|
|
|
|
const btnImprimir = document.createElement('button');
|
|
|
|
|
btnImprimir.textContent = '🖨️ Imprimir';
|
|
|
|
|
btnImprimir.style.cssText = 'margin-top:8px;padding:10px 32px;background:#e65100;color:#fff;border:none;border-radius:6px;font-size:15px;cursor:pointer;';
|
|
|
|
|
btnImprimir.onclick = () => { iframe.contentWindow.focus(); iframe.contentWindow.print(); };
|
|
|
|
|
overlay.appendChild(iframe);
|
|
|
|
|
overlay.appendChild(btnFechar);
|
|
|
|
|
overlay.appendChild(btnImprimir);
|
|
|
|
|
document.body.appendChild(overlay);
|
|
|
|
|
iframe.srcdoc = fullHtml;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Intercepta o envio — se sync_status=editing, faz PATCH
|
|
|
|
|
const _originalBtnEnviarHandler = () => {
|
|
|
|
|
const operador = val('f-operador').trim();
|
|
|
|
|