|
|
|
@@ -1320,12 +1320,9 @@ 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 = Total Sistema - Saldo Esperado - Cancelamentos
|
|
|
|
|
// sys_total = troco + crédito + débito + alimentação + pix + vales + pixcnpj + receber (lançamentos do sistema)
|
|
|
|
|
const sysTotal = data.sys_total || 0;
|
|
|
|
|
const saldoEsperado = data.saldo_esperado || 0;
|
|
|
|
|
const cancelamentos = data.cancelamentos || 0;
|
|
|
|
|
const diferenca = sysTotal - saldoEsperado - cancelamentos;
|
|
|
|
|
// Diferença = fechamento - saldo_esperado - cancelamentos
|
|
|
|
|
const diferenca = data.diferenca !== undefined ? data.diferenca
|
|
|
|
|
: ((data.fechamento || 0) - (data.saldo_esperado || 0) - (data.cancelamentos || 0));
|
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca);
|
|
|
|
|
const diffOk = diferenca === 0;
|
|
|
|
|
|
|
|
|
@@ -1490,12 +1487,10 @@ 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('.', ',');
|
|
|
|
|
// Diferença = Total Sistema - Saldo Esperado - Cancelamentos
|
|
|
|
|
// data.fechaemento = fechamento contado (dinheiro + cartões + receber)
|
|
|
|
|
// data.sys_total = troco + crédito + débito + alimentação + pix + vales + pixcnpj + receber (do sistema)
|
|
|
|
|
const sysTotal = (data.sys_total || 0);
|
|
|
|
|
const saldoEsperado = (data.saldo_esperado || 0);
|
|
|
|
|
const cancelamentos = (data.cancelamentos || 0);
|
|
|
|
|
const diferenca = sysTotal - saldoEsperado - cancelamentos;
|
|
|
|
|
const sysTotalCalc = (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');
|
|
|
|
|
|
|
|
|
@@ -1729,7 +1724,8 @@ function buildReportHTML(data) {
|
|
|
|
|
const fechamento = data.fechamento || 0;
|
|
|
|
|
const sysTotal = data.sys_total || 0;
|
|
|
|
|
const saldoEsp = data.saldo_esperado || 0;
|
|
|
|
|
const diferenca = sysTotal - saldoEsp - cancelamentos;
|
|
|
|
|
const diferenca = data.diferenca !== undefined ? data.diferenca
|
|
|
|
|
: (fechamento - saldoEsp - cancelamentos);
|
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca);
|
|
|
|
|
const diffColor = diferenca === 0 ? '#2e7d32' : '#c0272d';
|
|
|
|
|
|
|
|
|
@@ -2169,24 +2165,27 @@ function buildConsultaModal(recentList) {
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
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(total)}</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('');
|
|
|
|
|
|
|
|
|
|
overlay.innerHTML = `
|
|
|
|
|
<div style="background:#fff;border-radius:10px;padding:20px;max-width:700px;width:95%;max-height:85vh;overflow-y:auto">
|
|
|
|
|
<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>
|
|
|
|
|
<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>
|
|
|
|
|
<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">
|
|
|
|
@@ -2197,6 +2196,7 @@ function buildConsultaModal(recentList) {
|
|
|
|
|
<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>
|
|
|
|
@@ -2208,6 +2208,40 @@ function buildConsultaModal(recentList) {
|
|
|
|
|
window._recentList = recentList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Abre a janela de edição completa de um registro pelo índice na lista
|
|
|
|
|
window.abrirEditaFechamentoIndex = async function(idx) {
|
|
|
|
|
const item = window._recentList ? window._recentList[idx] : null;
|
|
|
|
|
if (!item) return;
|
|
|
|
|
|
|
|
|
|
const hasTauri = !!(window.__TAURI__ && window.__TAURI__.core);
|
|
|
|
|
if (!hasTauri) { alert('Tauri não disponível.'); return; }
|
|
|
|
|
|
|
|
|
|
let full = null;
|
|
|
|
|
try {
|
|
|
|
|
if (item.id) {
|
|
|
|
|
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_id', { id: item.id }); } catch(e) {}
|
|
|
|
|
}
|
|
|
|
|
if (!full && item.uuid) {
|
|
|
|
|
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_uuid', { uuid: item.uuid }); } catch(e) {}
|
|
|
|
|
}
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|
|
// Adiciona id_fechamento se não vier do banco
|
|
|
|
|
if (!full.id_fechamento && full.loja && full.data && full.operador) {
|
|
|
|
|
full.id_fechamento = (full.loja + '_' + full.data + '_' + full.operador).toLowerCase().replace(/ /g, '_');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closeConsultaModal();
|
|
|
|
|
window.abrirEditaFechamento(full);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function closeConsultaModal() {
|
|
|
|
|
const m = document.getElementById('modal-consulta');
|
|
|
|
|
if (m) document.body.removeChild(m);
|
|
|
|
@@ -2653,6 +2687,8 @@ window._recalcEditTotals = function() {
|
|
|
|
|
// Modal de edição completo com todas as grades
|
|
|
|
|
function openEditModal(full) {
|
|
|
|
|
window._editModalOpen = true;
|
|
|
|
|
// Salva o registro ANTES de fechar o modal de relatório — usa variável separada para não conflitar
|
|
|
|
|
window._editingRecord = full;
|
|
|
|
|
|
|
|
|
|
const dados = full.dados || {};
|
|
|
|
|
|
|
|
|
@@ -2683,27 +2719,27 @@ function openEditModal(full) {
|
|
|
|
|
const cartPixHTML = editTableHTML('pix', ['Valor (R$)'], cartPix_rows.length ? cartPix_rows : [['']], [0]);
|
|
|
|
|
|
|
|
|
|
// --- Vales ---
|
|
|
|
|
const vales_rows = (full.vales_arr || []).map(r => [r.nome||r.Nome||'', r.valor||0, r.obs||r.Obs||'']);
|
|
|
|
|
const vales_rows = (dados.vales || []).map(r => [r.nome||'', r.valor||0, r.obs||'']);
|
|
|
|
|
const valesHTML = editTableHTML('vales', ['Nome', 'Valor (R$)', 'Obs'], vales_rows.length ? vales_rows : [['','','']], [1]);
|
|
|
|
|
|
|
|
|
|
// --- Despesas ---
|
|
|
|
|
const despesas_rows = (full.despesas_arr || []).map(r => [r.desc||r.Desc||'', r.obs||r.Obs||'', r.valor||0]);
|
|
|
|
|
const despesas_rows = (dados.despesas || []).map(r => [r.desc||'', 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_arr || []).map(r => [r.hora||r.Hora||'', r.retirada||r.valor||0, r.gerente||r.Gerente||'']);
|
|
|
|
|
const sangrias_rows = (dados.sangrias || []).map(r => [r.hora||'', r.retirada||r.valor||0, r.gerente||'']);
|
|
|
|
|
const sangriasHTML = editTableHTML('sangrias', ['Hora', 'Valor (R$)', 'Gerente'], sangrias_rows.length ? sangrias_rows : [['','','']], [1]);
|
|
|
|
|
|
|
|
|
|
// --- Cancelamentos ---
|
|
|
|
|
const cancel_rows = (full.cancelamentos_arr || []).map(r => [r.numero||r.Numero||'', r.valor||0, r.motivo||r.Motivo||'']);
|
|
|
|
|
const cancel_rows = (dados.cancelamentos || []).map(r => [r.numero||'', r.valor||0, r.motivo||'']);
|
|
|
|
|
const cancelHTML = editTableHTML('cancelamentos', ['Número', 'Valor (R$)', 'Motivo'], cancel_rows.length ? cancel_rows : [['','','']], [1]);
|
|
|
|
|
|
|
|
|
|
// --- PIX CNPJ ---
|
|
|
|
|
const pixcnpj_rows = (full.pixcnpj_arr || []).map(r => [r.nome||r.desc||r.Desc||'', r.valor||0]);
|
|
|
|
|
const pixcnpj_rows = (dados.pixcnpj || []).map(r => [r.nome||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_arr || []).map(r => [r.nome||r.Nome||'', r.valor||0]);
|
|
|
|
|
const receber_rows = (dados.receber || []).map(r => [r.nome||'', r.valor||0]);
|
|
|
|
|
const receberHTML = editTableHTML('receber', ['Nome', 'Valor (R$)'], receber_rows.length ? receber_rows : [['','']], [1]);
|
|
|
|
|
|
|
|
|
|
// --- Totais (só leitura formatado) ---
|
|
|
|
@@ -2899,10 +2935,193 @@ function closeEditModal() {
|
|
|
|
|
window._editModalOpen = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Janela separada para edição completa ───────────────────────────────────
|
|
|
|
|
// Abre uma nova janela (window.open) com HTML inline pré-preenchido com todos
|
|
|
|
|
// os dados do registro. Permite editar todos os campos e salvar via
|
|
|
|
|
// sb_atualizar_fechamento. O botão Cancelar fecha a janela.
|
|
|
|
|
window.abrirEditaFechamento = async function(full) {
|
|
|
|
|
if (!full) { alert('Registro não fornecido.'); return; }
|
|
|
|
|
|
|
|
|
|
// Serializa o registro para passar à popup — usa JSON para preservar tudo
|
|
|
|
|
const encoded = encodeURIComponent(JSON.stringify(full));
|
|
|
|
|
|
|
|
|
|
const html = `<!DOCTYPE html>
|
|
|
|
|
<html lang="pt-BR">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<title>Editar Fechamento — ${(full.data||'').substring(0,10)} ${full.operador||''}</title>
|
|
|
|
|
<style>
|
|
|
|
|
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
|
|
|
|
body{font-family:'Segoe UI',system-ui,sans-serif;background:#f7f7f7;padding:16px;font-size:13px}
|
|
|
|
|
h2{background:linear-gradient(135deg,#bf360c,#e65100);color:#fff;padding:10px 16px;border-radius:8px 8px 0 0;margin:-16px -16px 16px;font-size:15px}
|
|
|
|
|
.linha{margin-bottom:12px}
|
|
|
|
|
.linha label{display:block;font-size:10px;color:#555;margin-bottom:2px;font-weight:700;text-transform:uppercase}
|
|
|
|
|
.linha input,.linha select,.linha textarea{width:100%;padding:6px 8px;border:1px solid #ccc;border-radius:4px;font-size:13px;font-family:inherit}
|
|
|
|
|
.linha input[readonly]{background:#eee;color:#666;border-color:#ddd}
|
|
|
|
|
.linha input[type=number]{text-align:right}
|
|
|
|
|
.secao{background:#fff;border-radius:8px;padding:12px;margin-bottom:12px;box-shadow:0 1px 4px rgba(0,0,0,.08)}
|
|
|
|
|
.secao-titulo{font-size:11px;font-weight:700;color:#e65100;text-transform:uppercase;letter-spacing:.5px;margin-bottom:8px;padding-bottom:4px;border-bottom:2px solid #e65100}
|
|
|
|
|
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:8px}
|
|
|
|
|
.grid3{display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px}
|
|
|
|
|
.grid4{display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:6px}
|
|
|
|
|
table{width:100%;border-collapse:collapse;font-size:12px}
|
|
|
|
|
th{background:#f0f0f0;font-size:10px;text-transform:uppercase;color:#777;padding:4px 6px;text-align:left}
|
|
|
|
|
td{padding:2px 4px;border-bottom:1px solid #eee}
|
|
|
|
|
td input{width:100%;padding:4px 2px;border:1px solid #ccc;border-radius:3px;font-size:12px}
|
|
|
|
|
td input[type=number],td input.num{text-align:right}
|
|
|
|
|
.btn-row{display:flex;gap:8px;flex-wrap:wrap}
|
|
|
|
|
.btn-row button{flex:1;padding:10px;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:700}
|
|
|
|
|
.btn-salvar{background:#2e7d32;color:#fff}
|
|
|
|
|
.btn-cancelar{background:#888;color:#fff}
|
|
|
|
|
.total-box{background:#fff8e1;border-radius:6px;padding:8px;margin-bottom:8px;font-size:11px;display:grid;grid-template-columns:repeat(3,1fr);gap:4px}
|
|
|
|
|
.total-box span{display:block}
|
|
|
|
|
.total-box strong{color:#e65100}
|
|
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<h2>✏️ Editar Fechamento — ${(full.loja||'').toUpperCase()} · ${(full.data||'').substring(0,10)} · ${full.operador||''}</h2>
|
|
|
|
|
|
|
|
|
|
<!-- Identificação -->
|
|
|
|
|
<div class="secao">
|
|
|
|
|
<div class="secao-titulo">Identificação</div>
|
|
|
|
|
<div class="grid4">
|
|
|
|
|
<div class="linha"><label>Data</label><input type="date" id="f-data" value="${full.data||''}"></div>
|
|
|
|
|
<div class="linha"><label>Loja</label>
|
|
|
|
|
<select id="f-loja"><option value="alianca" ${(full.loja||'').toLowerCase()==='alianca'?'selected':''}>Aliança</option><option value="uniao" ${(full.loja||'').toLowerCase()==='uniao'?'selected':''}>União</option></select>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="linha"><label>Turno</label>
|
|
|
|
|
<select id="f-turno"><option value="manha" ${(full.turno||'')==='manha'?'selected':''}>Manhã</option><option value="tarde" ${(full.turno||'')==='tarde'?'selected':''}>Tarde</option><option value="integral" ${(full.turno||'')==='integral'?'selected':''}>Integral</option></select>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="linha"><label>Operador</label><input type="text" id="f-operador" value="${full.operador||''}"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Totais (readonly) -->
|
|
|
|
|
<div class="total-box">
|
|
|
|
|
<span><strong>Crédito:</strong> <span id="tot-credito">R$ ${parseFloat(full.total_cartao_credito||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
|
|
|
<span><strong>Débito:</strong> <span id="tot-debito">R$ ${parseFloat(full.total_cartao_debito||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
|
|
|
<span><strong>Alimentação:</strong> <span id="tot-ali">R$ ${parseFloat(full.total_cartao_alimentacao||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
|
|
|
<span><strong>PIX:</strong> <span id="tot-pix">R$ ${parseFloat(full.total_cartao_pix||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
|
|
|
<span><strong>PIX CNPJ:</strong> <span id="tot-pixcnpj">R$ ${parseFloat(full.total_pixcnpj||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
|
|
|
<span><strong>Vales:</strong> <span id="tot-vales">R$ ${parseFloat(full.total_vales||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
|
|
|
<span><strong>A Receber:</strong> <span id="tot-areceber">R$ ${parseFloat(full.total_areceber||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
|
|
|
<span><strong>Sangrias:</strong> <span id="tot-sangrias">R$ ${parseFloat(full.total_sangrias||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
|
|
|
<span><strong>Despesas:</strong> <span id="tot-despesas">R$ ${parseFloat(full.total_despesas||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Saldo de Caixa -->
|
|
|
|
|
<div class="secao">
|
|
|
|
|
<div class="secao-titulo">💰 Saldo de Caixa</div>
|
|
|
|
|
<div class="grid4">
|
|
|
|
|
<div class="linha"><label>Troco (R$)</label><input type="number" step="0.01" id="f-saldo_troco" value="${parseFloat(full.saldo_troco||0)}"></div>
|
|
|
|
|
<div class="linha"><label>Crédito (R$)</label><input type="number" step="0.01" id="f-saldo_credito" value="${parseFloat(full.saldo_credito||0)}"></div>
|
|
|
|
|
<div class="linha"><label>Débito (R$)</label><input type="number" step="0.01" id="f-saldo_debito" value="${parseFloat(full.saldo_debito||0)}"></div>
|
|
|
|
|
<div class="linha"><label>Alimentação (R$)</label><input type="number" step="0.01" id="f-saldo_alimentacao" value="${parseFloat(full.saldo_alimentacao||0)}"></div>
|
|
|
|
|
<div class="linha"><label>Vales (R$)</label><input type="number" step="0.01" id="f-saldo_vales" value="${parseFloat(full.saldo_vales||0)}"></div>
|
|
|
|
|
<div class="linha"><label>PIX Cartão (R$)</label><input type="number" step="0.01" id="f-total_cartao_pix" value="${parseFloat(full.total_cartao_pix||0)}"></div>
|
|
|
|
|
<div class="linha"><label>PIX CNPJ (R$)</label><input type="number" step="0.01" id="f-total_pixcnpj" value="${parseFloat(full.total_pixcnpj||0)}"></div>
|
|
|
|
|
<div class="linha"><label>A Receber (R$)</label><input type="number" step="0.01" id="f-saldo_areceber" value="${parseFloat(full.saldo_areceber||0)}"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Fechamento Contado -->
|
|
|
|
|
<div class="secao">
|
|
|
|
|
<div class="secao-titulo">📦 Fechamento Contado</div>
|
|
|
|
|
<div class="grid3">
|
|
|
|
|
<div class="linha"><label>Dinheiro (R$)</label><input type="number" step="0.01" id="f-fechamento_dinheiro" value="${parseFloat(full.fechamento_dinheiro||0)}"></div>
|
|
|
|
|
<div class="linha"><label>Cartões (R$)</label><input type="number" step="0.01" id="f-fechamento_cartoes" value="${parseFloat(full.fechamento_cartoes||0)}"></div>
|
|
|
|
|
<div class="linha"><label>A Receber (R$)</label><input type="number" step="0.01" id="f-fechamento_areceber" value="${parseFloat(full.fechamento_areceber||0)}"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Dados operacionais -->
|
|
|
|
|
<div class="secao">
|
|
|
|
|
<div class="secao-titulo">📊 Dados Operacionais</div>
|
|
|
|
|
<div class="grid4">
|
|
|
|
|
<div class="linha"><label>Clientes</label><input type="number" id="f-clientes" value="${parseInt(full.clientes||0)}"></div>
|
|
|
|
|
<div class="linha"><label>Frango Assado</label><input type="number" id="f-frango" value="${parseInt(full.frango||0)}"></div>
|
|
|
|
|
<div class="linha"><label>Vendas (R$)</label><input type="number" step="0.01" id="f-vendas" value="${parseFloat(full.vendas||0)}"></div>
|
|
|
|
|
<div class="linha"><label>Saldo Esperado (R$)</label><input type="number" step="0.01" id="f-saldo_esperado" value="${parseFloat(full.saldo_esperado||0)}"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Observações -->
|
|
|
|
|
<div class="secao">
|
|
|
|
|
<div class="linha"><label>Observações</label><textarea id="f-observacoes" rows="3">${(full.observacoes||'').replace(/`/g,'`').replace(/</g,'<').replace(/>/g,'>')}</textarea></div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Botões -->
|
|
|
|
|
<div class="btn-row">
|
|
|
|
|
<button class="btn-salvar" onclick="salvar()">💾 Salvar Alterações</button>
|
|
|
|
|
<button class="btn-cancelar" onclick="window.close()">Cancelar</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
var _rec = null;
|
|
|
|
|
try { _rec = JSON.parse(decodeURIComponent('${encoded}')); } catch(e) { console.error(e); }
|
|
|
|
|
|
|
|
|
|
function num(v) { return parseFloat((v||'0').toString().replace(',','.')) || 0; }
|
|
|
|
|
function inp(id) { var el = document.getElementById(id); return el ? el.value : ''; }
|
|
|
|
|
|
|
|
|
|
async function salvar() {
|
|
|
|
|
if (!window.__TAURI__ || !window.__TAURI__.core) {
|
|
|
|
|
alert('Tauri não disponível nesta janela.'); return;
|
|
|
|
|
}
|
|
|
|
|
var updates = {
|
|
|
|
|
data: inp('f-data'),
|
|
|
|
|
loja: inp('f-loja'),
|
|
|
|
|
turno: inp('f-turno'),
|
|
|
|
|
operador: inp('f-operador'),
|
|
|
|
|
saldo_troco: num(inp('f-saldo_troco')),
|
|
|
|
|
saldo_credito: num(inp('f-saldo_credito')),
|
|
|
|
|
saldo_debito: num(inp('f-saldo_debito')),
|
|
|
|
|
saldo_alimentacao: num(inp('f-saldo_alimentacao')),
|
|
|
|
|
saldo_vales: num(inp('f-saldo_vales')),
|
|
|
|
|
saldo_areceber: num(inp('f-saldo_areceber')),
|
|
|
|
|
total_cartao_pix: num(inp('f-total_cartao_pix')),
|
|
|
|
|
total_pixcnpj: num(inp('f-total_pixcnpj')),
|
|
|
|
|
fechamento_dinheiro: num(inp('f-fechamento_dinheiro')),
|
|
|
|
|
fechamento_cartoes: num(inp('f-fechamento_cartoes')),
|
|
|
|
|
fechamento_areceber: num(inp('f-fechamento_areceber')),
|
|
|
|
|
clientes: parseInt(inp('f-clientes')||'0'),
|
|
|
|
|
frango: parseInt(inp('f-frango')||'0'),
|
|
|
|
|
vendas: num(inp('f-vendas')),
|
|
|
|
|
saldo_esperado: num(inp('f-saldo_esperado')),
|
|
|
|
|
observacoes: inp('f-observacoes')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// id_fechamento = chave natural do registro
|
|
|
|
|
var id_fechamento = _rec && _rec.id_fechamento ? _rec.id_fechamento
|
|
|
|
|
: (inp('f-loja') + '_' + inp('f-data') + '_' + inp('f-operador')).toLowerCase().replace(/ /g,'_');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
var idFech = inp('f-loja') + '_' + inp('f-data') + '_' + inp('f-operador');
|
|
|
|
|
idFech = idFech.toLowerCase().replace(/ /g, '_');
|
|
|
|
|
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id_fechamento: idFech, updates: JSON.stringify(updates) });
|
|
|
|
|
alert('✅ Atualizado com sucesso!');
|
|
|
|
|
if (window.opener && window.opener.location) { try { window.opener.location.reload(); } catch(e){} }
|
|
|
|
|
window.close();
|
|
|
|
|
} catch(e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
alert('Erro ao salvar: ' + (e.message||e));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
<\/script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>`;
|
|
|
|
|
|
|
|
|
|
var win = window.open('', '_blank', 'width=720,height=' + screen.availHeight + ',scrollbars=yes,resizable=yes');
|
|
|
|
|
if (!win) { alert('Bloqueador de popup detectado. Permita popups para este site.'); return; }
|
|
|
|
|
win.document.write(html);
|
|
|
|
|
win.document.close();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Salva edições do modal de edição completo
|
|
|
|
|
window.salvarEdicaoModal = async function() {
|
|
|
|
|
const full = window._currentConsulta;
|
|
|
|
|
if (!full) return;
|
|
|
|
|
console.log('[DEBUG] salvarEdicaoModal called');
|
|
|
|
|
const full = window._editingRecord;
|
|
|
|
|
if (!full) { console.log('[DEBUG] _editingRecord is null'); alert('Nenhum registro selecionado.'); return; }
|
|
|
|
|
console.log('[DEBUG] full.uuid:', full.uuid, 'full.id:', full.id);
|
|
|
|
|
|
|
|
|
|
const p = v => parseNum(v);
|
|
|
|
|
const inp = id => { const el = document.getElementById(id); return el ? el.value : ''; };
|
|
|
|
@@ -2941,6 +3160,9 @@ window.salvarEdicaoModal = async function() {
|
|
|
|
|
const operador = estado.operador || full.operador || '';
|
|
|
|
|
|
|
|
|
|
const updates = {
|
|
|
|
|
// Chave natural — essencial para o Supabase encontrar o registro
|
|
|
|
|
id_fechamento: inp('edit-loja') + '_' + inp('edit-data') + '_' + inp('edit-operador'),
|
|
|
|
|
|
|
|
|
|
// Identificação
|
|
|
|
|
loja: inp('edit-loja'),
|
|
|
|
|
data: inp('edit-data'),
|
|
|
|
@@ -3001,12 +3223,16 @@ window.salvarEdicaoModal = async function() {
|
|
|
|
|
if (!hasTauri) { alert('Tauri não disponível.'); return; }
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 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));
|
|
|
|
|
// Usa id_fechamento que é a chave natural do registro
|
|
|
|
|
const id_fechamento = full.id_fechamento || (full.loja && full.data && full.operador
|
|
|
|
|
? `${full.loja}_${full.data}_${full.operador}`.toLowerCase().replace(/ /g, '_')
|
|
|
|
|
: null);
|
|
|
|
|
if (!id_fechamento) { alert('id_fechamento não encontrado.'); return; }
|
|
|
|
|
console.log('[DEBUG] salvarEdicaoModal id_fechamento:', id_fechamento, 'updates:', JSON.stringify(updates));
|
|
|
|
|
|
|
|
|
|
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id: uuid, updates: JSON.stringify(updates) });
|
|
|
|
|
console.log('[DEBUG] invoking sb_atualizar_fechamento...');
|
|
|
|
|
const result = await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id_fechamento, updates: JSON.stringify(updates) });
|
|
|
|
|
console.log('[DEBUG] invoke result:', result);
|
|
|
|
|
closeEditModal();
|
|
|
|
|
closeRelatorioModal();
|
|
|
|
|
alert('✅ Atualizado com sucesso!');
|
|
|
|
@@ -3169,26 +3395,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: 17px; width: 80mm; margin: 0 auto; padding: 10px 12px; font-weight: bold; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
|
|
|
|
|
.header { text-align: center; margin-bottom: 10px; }
|
|
|
|
|
.header h1 { font-size: 22px; font-weight: bold; }
|
|
|
|
|
.header h2 { font-size: 17px; font-weight: normal; }
|
|
|
|
|
hr { border: none; border-top: 2px solid #000; margin: 8px 0; }
|
|
|
|
|
.section-title { font-weight: bold; font-size: 16px; border-top: 2px solid #000; padding-top: 6px; margin-top: 10px; }
|
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 15px; font-weight: bold; }
|
|
|
|
|
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 { table-layout: fixed; width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; font-weight: bold; }
|
|
|
|
|
.cart-table th { font-weight: bold; border-bottom: 2px solid #000; padding: 3px 4px; width: 25%; font-size: 14px; }
|
|
|
|
|
.cart-table td { padding: 3px 6px; text-align: right; font-weight: bold; font-size: 14px; }
|
|
|
|
|
.cart-table { table-layout: fixed; width: 100%; border-collapse: collapse; font-size: 13px; 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: 15px; margin-top: 6px; }
|
|
|
|
|
.subtotal .row { padding: 3px 0; }
|
|
|
|
|
.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: 13px; color: #555; margin-top: 8px; white-space: pre-wrap; font-weight: normal; }
|
|
|
|
|
.footer { text-align: center; font-size: 13px; color: #555; margin-top: 10px; }
|
|
|
|
|
@media print { body { background: #fff; font-weight: bold !important; font-size: 17px !important; } }
|
|
|
|
|
.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)}
|
|
|
|
|