Compare commits

...

4 Commits

Author SHA1 Message Date
root 7a3a4b221b fix: saldo caixa = fechamento_dinheiro+fechamento_cartoes+fechamento_areceber (total sistema)
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-07-02 14:06:41 +00:00
root 94bb8840ea fix: select completo no sb_listar + busca por periodo (de/ate/turno)
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-07-02 13:44:08 +00:00
root dba7eb3856 fix: saldo caixa via dados JSON + coluna cancelamento + diferenca correta
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-07-02 13:31:00 +00:00
root 7b3b7a9f1d feat: modal consulta com busca por data, ultimos 5 dias, coluna diferenca
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-07-01 20:23:11 +00:00
2 changed files with 118 additions and 48 deletions
+1 -1
View File
@@ -312,7 +312,7 @@ impl SupabaseClient {
pub fn listar_recentes(&self, loja: &str, limite: i64) -> Result<Vec<Value>, SupabaseError> {
let loja_normalized = sem_acento(&loja.to_lowercase());
let url = format!(
"{}/rest/v1/fechamentos_web?loja=eq.{}&order=data.desc,atualizado_em.desc&limit={}&select=id,id_fechamento,data,operador,turno,saldo_troco,saldo_esperado,fechamento_dinheiro,fechamento_cartoes,fechamento_areceber,diferenca,status_diferenca,observacoes,atualizado_em,dados",
"{}/rest/v1/fechamentos_web?loja=eq.{}&order=data.desc,atualizado_em.desc&limit={}&select=id,id_fechamento,data,operador,turno,saldo_troco,saldo_credito,saldo_debito,saldo_alimentacao,saldo_vales,saldo_areceber,saldo_esperado,total_pixcnpj,total_cartao_credito,total_cartao_debito,total_cartao_alimentacao,total_cartao_pix,total_cancelamentos,fechamento_dinheiro,fechamento_cartoes,fechamento_areceber,diferenca,status_diferenca,observacoes,atualizado_em,dados",
self.base_url,
urlencoding::encode(&loja_normalized),
limite,
+117 -47
View File
@@ -2167,11 +2167,6 @@ function buildConsultaModal(recentList) {
return `${day}/${m}/${y}`;
};
const fmtMoney = v => v != null ? `R$ ${parseFloat(v).toFixed(2).replace('.', ',')}` : 'R$ 0,00';
const syncBadge = s => {
const colors = { synced: '#2e7d32', local: '#e65100', syncing: '#f57f17', error: '#c0272d' };
const labels = { synced: '✓ Sync', local: '⚠ Local', syncing: '⏳ Sync', error: '✗ Erro' };
return `<span style="background:${colors[s]||'#888'};color:#fff;padding:1px 5px;border-radius:3px;font-size:10px">${labels[s]||s||'?'}</span>`;
};
const statusBadge = s => {
if (s === 'ok') return '<span style="color:#2e7d32;font-weight:bold">✓ OK</span>';
if (s === 'sobrando') return '<span style="color:#e65100;font-weight:bold">⚠ SOBRANDO</span>';
@@ -2179,56 +2174,131 @@ function buildConsultaModal(recentList) {
return s || '?';
};
const rows = recentList.map((item, i) => {
const sysTotal = (parseFloat(item.saldo_troco)||0)
+ (parseFloat(item.saldo_credito)||0)
+ (parseFloat(item.saldo_debito)||0)
+ (parseFloat(item.saldo_alimentacao)||0)
+ (parseFloat(item.saldo_vales)||0)
+ (parseFloat(item.saldo_areceber)||0)
+ (parseFloat(item.total_pixcnpj)||0)
+ (parseFloat(item.total_cartao_pix)||0);
return `<tr>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtDate(item.data)}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${item.operador||'?'}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${item.turno||'?'}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtMoney(sysTotal)}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtMoney(item.saldo_esperado)}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${statusBadge(item.status_diferenca)}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${syncBadge(item.sync_status)}</td>
<td style="padding:4px 6px;border-bottom:1px solid #eee;text-align:center">
<button onclick="event.stopPropagation();window.abrirEditaFechamentoIndex(${i})" style="background:#e65100;color:#fff;border:none;border-radius:4px;padding:4px 10px;cursor:pointer;font-size:11px;white-space:nowrap">✏️ Editar</button>
</td>
</tr>`;
}).join('');
// Calcula saldo de caixa real (mesma fórmula do relatório)
// SALDO CAIXA = total do sistema = fechamento_dinheiro + fechamento_cartoes + fechamento_areceber
// (mesma fórmula do relatório impresso)
const calcSaldoCaixa = item => {
const dados = item.dados || {};
return (parseFloat(item.fechamento_dinheiro)||0)
+ (parseFloat(item.fechamento_cartoes)||0)
+ (parseFloat(item.fechamento_areceber)||0)
+ (parseFloat(dados.fechamento_dinheiro)||0)
+ (parseFloat(dados.fechamento_cartoes)||0)
+ (parseFloat(dados.fechamento_areceber)||0);
};
const calcCancelamentos = item => {
const dados = item.dados || {};
return (parseFloat(item.total_cancelamentos)||0)
+ (parseFloat(dados.total_cancelamentos)||0)
+ (parseFloat(dados.cancelamentos)||0); // old format: array of cancelamentos
};
// Ordena por data desc e pega os últimos 5 dias distintos
const sortedDesc = [...recentList].sort((a,b) => b.data.localeCompare(a.data));
const cincoDias = sortedDesc.slice(0, 5);
// Último dia distinto (para placeholder do input)
const ultimoDia = sortedDesc[0]?.data || '';
function renderRows(list) {
if (!list || list.length === 0) {
return `<tr><td colspan="8" style="padding:20px;text-align:center;color:#888;font-size:13px">Nenhum registro encontrado.</td></tr>`;
}
return list.map((item, i) => {
const saldoCaixa = calcSaldoCaixa(item);
const canc = calcCancelamentos(item);
const diff = saldoCaixa - (parseFloat(item.saldo_esperado)||0) - canc;
const diffClass = diff === 0 ? '#2e7d32' : diff > 0 ? '#e65100' : '#c0272d';
const diffLabel = diff === 0 ? '✓ OK' : diff > 0 ? `+R$ ${diff.toFixed(2).replace('.',',')}` : `-R$ ${Math.abs(diff).toFixed(2).replace('.',',')}`;
return `<tr data-idx="${recentList.indexOf(item)}" style="background:${i%2===0?'#fff':'#fafafa'}" onmouseover="this.style.background='#fff3e0'" onmouseout="this.style.background='${i%2===0?'#fff':'#fafafa'}'">
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${fmtDate(item.data)}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${item.operador||'?'}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${item.turno||'?'}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${fmtMoney(saldoCaixa)}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${fmtMoney(item.saldo_esperado)}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${fmtMoney(canc)}</td>
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:center;cursor:pointer;color:${diffClass};font-weight:bold" onclick="openConsultaRegistro(${recentList.indexOf(item)})">${diffLabel}</td>
<td style="padding:4px 6px;border-bottom:1px solid #eee;text-align:center">
<button onclick="event.stopPropagation();window.abrirEditaFechamentoIndex(${recentList.indexOf(item)})" style="background:#e65100;color:#fff;border:none;border-radius:4px;padding:4px 10px;cursor:pointer;font-size:11px;white-space:nowrap">✏️ Editar</button>
</td>
</tr>`;
}).join('');
}
overlay.innerHTML = `
<div style="background:#fff;border-radius:10px;padding:20px;max-width:780px;width:95%;max-height:85vh;overflow-y:auto">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:12px">
<h2 style="margin:0;font-size:16px">📅 Consultar Fechamentos Anteriores</h2>
<button onclick="closeConsultaModal()" style="background:none;border:none;font-size:18px;cursor:pointer">✕</button>
<div style="background:#fff;border-radius:10px;padding:20px;max-width:900px;width:95%;max-height:85vh;overflow-y:auto">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:12px;flex-wrap:wrap;gap:8px">
<h2 style="margin:0;font-size:16px">📅 Consultar Fechamentos</h2>
<div style="display:flex;gap:6px;align-items:center;flex-wrap:wrap">
<span style="font-size:12px;color:#555">De:</span>
<input type="date" id="consulta-busca-de" value="" max="${ultimoDia}" style="padding:6px 10px;border:1px solid #ccc;border-radius:6px;font-size:13px" />
<span style="font-size:12px;color:#555">Até:</span>
<input type="date" id="consulta-busca-ate" value="" max="${ultimoDia}" style="padding:6px 10px;border:1px solid #ccc;border-radius:6px;font-size:13px" />
<select id="consulta-busca-turno" style="padding:6px 10px;border:1px solid #ccc;border-radius:6px;font-size:13px;background:#fff">
<option value="">Todos turnos</option>
<option value="manha">Manhã</option>
<option value="tarde">Tarde</option>
<option value="integral">Integral</option>
</select>
<button onclick="window._filtrarConsulta()" style="background:#1565c0;color:#fff;border:none;border-radius:6px;padding:6px 14px;cursor:pointer;font-size:13px">🔍 Buscar</button>
<button onclick="closeConsultaModal()" style="background:none;border:none;font-size:18px;cursor:pointer;padding:4px 8px">✕</button>
</div>
</div>
<div id="consulta-info" style="font-size:11px;color:#888;margin-bottom:8px">Mostrando últimos 5 dias</div>
<div style="max-height:55vh;overflow-y:auto;border:1px solid #eee;border-radius:6px">
<table style="width:100%;border-collapse:collapse">
<thead style="position:sticky;top:0;background:#f5f5f5;z-index:1">
<tr>
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">DATA</th>
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">OPERADOR</th>
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">TURNO</th>
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">SALDO CAIXA</th>
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">ESPERADO</th>
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">CANCEL.</th>
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">DIFERENÇA</th>
<th style="padding:4px 6px;text-align:center;font-size:11px;color:#888">AÇÃO</th>
</tr>
</thead>
<tbody id="consulta-tbody">${renderRows(cincoDias)}</tbody>
</table>
</div>
<div style="margin-top:8px;font-size:11px;color:#888;text-align:center">
Mostrando últimos 5 dias. Use a <strong>busca por data</strong> para encontrar registros mais antigos.
</div>
<p style="font-size:12px;color:#666;margin:0 0 10px">Clique em um registro para ver o relatório ou clique em <strong>Editar</strong> para abrir a janela de edição.</p>
<table style="width:100%;border-collapse:collapse">
<thead>
<tr style="background:#f5f5f5">
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">DATA</th>
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">OPERADOR</th>
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">TURNO</th>
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">SALDO CAIXA</th>
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">ESPERADO</th>
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">STATUS</th>
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">SYNC</th>
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">AÇÃO</th>
</tr>
</thead>
<tbody>${rows}</tbody>
</table>
</div>
`;
document.body.appendChild(overlay);
// Função de busca por período
window._filtrarConsulta = () => {
const de = document.getElementById('consulta-busca-de')?.value;
const ate = document.getElementById('consulta-busca-ate')?.value;
const turno = document.getElementById('consulta-busca-turno')?.value || '';
const tbody = document.getElementById('consulta-tbody');
const info = document.getElementById('consulta-info');
if (!tbody) return;
let filtrados = [...recentList];
if (de) filtrados = filtrados.filter(item => item.data >= de);
if (ate) filtrados = filtrados.filter(item => item.data <= ate);
if (turno) filtrados = filtrados.filter(item => (item.turno||'').toLowerCase() === turno);
if (de || ate || turno) {
tbody.innerHTML = renderRows(filtrados);
const label = `${filtrados.length} registro${filtrados.length!==1?'s':''}${de&&ate?` de ${fmtDate(de)} a ${fmtDate(ate)}`:de?` a partir de ${fmtDate(de)}`:ate?` até ${fmtDate(ate)}`:''}`;
if (info) info.textContent = label;
} else {
tbody.innerHTML = renderRows(cincoDias);
if (info) info.textContent = 'Mostrando últimos 5 dias';
}
};
// Enter na busca
['consulta-busca-de','consulta-busca-ate'].forEach(id => {
document.getElementById(id)?.addEventListener('keydown', e => { if (e.key === 'Enter') window._filtrarConsulta(); });
});
window._recentList = recentList;
window._consultaAll = recentList;
}
// Abre a janela de edição completa de um registro pelo índice na lista