diff --git a/src/index.html b/src/index.html
index c3960ec..c7d7981 100644
--- a/src/index.html
+++ b/src/index.html
@@ -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 `${labels[s]||s||'?'}`;
- };
const statusBadge = s => {
if (s === 'ok') return '✓ OK';
if (s === 'sobrando') return '⚠ SOBRANDO';
@@ -2179,56 +2174,104 @@ 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 `
- | ${fmtDate(item.data)} |
- ${item.operador||'?'} |
- ${item.turno||'?'} |
- ${fmtMoney(sysTotal)} |
- ${fmtMoney(item.saldo_esperado)} |
- ${statusBadge(item.status_diferenca)} |
- ${syncBadge(item.sync_status)} |
-
-
- |
-
`;
- }).join('');
+ // Calcula saldo de caixa real (mesma fórmula do relatório)
+ const calcSaldoCaixa = item => (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);
+
+ // 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 `| Nenhum registro encontrado. |
`;
+ }
+ return list.map((item, i) => {
+ const saldoCaixa = calcSaldoCaixa(item);
+ const diff = saldoCaixa - (parseFloat(item.saldo_esperado)||0);
+ 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 `
+ | ${fmtDate(item.data)} |
+ ${item.operador||'?'} |
+ ${item.turno||'?'} |
+ ${fmtMoney(saldoCaixa)} |
+ ${fmtMoney(item.saldo_esperado)} |
+ ${diffLabel} |
+
+
+ |
+
`;
+ }).join('');
+ }
overlay.innerHTML = `
-
-
-
📅 Consultar Fechamentos Anteriores
-
+
+
+
📅 Consultar Fechamentos
+
+
+
+
+
+
+
+
+
+
+
+ | DATA |
+ OPERADOR |
+ TURNO |
+ SALDO CAIXA |
+ ESPERADO |
+ DIFERENÇA |
+ AÇÃO |
+
+
+ ${renderRows(cincoDias)}
+
+
+
+ Mostrando últimos 5 dias. Use a busca por data para encontrar registros mais antigos.
-
Clique em um registro para ver o relatório ou clique em Editar para abrir a janela de edição.
-
-
-
- | DATA |
- OPERADOR |
- TURNO |
- SALDO CAIXA |
- ESPERADO |
- STATUS |
- SYNC |
- AÇÃO |
-
-
- ${rows}
-
`;
document.body.appendChild(overlay);
+
+ // Função de busca por data
+ window._filtrarConsulta = () => {
+ const dataBusca = document.getElementById('consulta-busca-data')?.value;
+ const tbody = document.getElementById('consulta-tbody');
+ const info = document.getElementById('consulta-info');
+ if (!tbody) return;
+ if (!dataBusca) {
+ tbody.innerHTML = renderRows(cincoDias);
+ if (info) info.textContent = 'Mostrando últimos 5 dias';
+ return;
+ }
+ const filtrados = recentList.filter(item => item.data === dataBusca);
+ tbody.innerHTML = renderRows(filtrados);
+ if (info) info.textContent = filtrados.length ? `${filtrados.length} registro${filtrados.length!==1?'s':''} em ${fmtDate(dataBusca)}` : `Nenhum registro em ${fmtDate(dataBusca)}`;
+ };
+
+ // Enter na busca
+ document.getElementById('consulta-busca-data')?.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