From e70f31e00fe7258bd3b411b340ca7522de219033 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jun 2026 01:44:15 +0000 Subject: [PATCH] debug: btn-anterior logs; cartoes.norm guard --- src/index.html | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.html b/src/index.html index eda1ab7..df9b85c 100644 --- a/src/index.html +++ b/src/index.html @@ -1701,12 +1701,15 @@ document.getElementById('btn-limpar').addEventListener('click', () => { }); document.getElementById('btn-anterior').addEventListener('click', async () => { + console.log('[DEBUG] btn-anterior clicado'); const loja = val('f-loja') || 'União'; + console.log('[DEBUG] btn-anterior loja:', loja); // Carrega lista de fechamentos recentes do Supabase com uuid let recentList = []; try { recentList = await window.__TAURI__.core.invoke('sb_listar_recentes', { loja, limite: 20 }); + console.log('[DEBUG] sb_listar_recentes retornou:', recentList?.length, 'itens'); } catch(e) { console.warn('sb_listar_recentes falhou:', e); } @@ -1723,6 +1726,7 @@ document.getElementById('btn-anterior').addEventListener('click', async () => { }); dateList.sort().reverse(); } + console.log('[DEBUG] dateList:', dateList); let selectedDate = null; let selectedId = null; @@ -1743,6 +1747,7 @@ document.getElementById('btn-anterior').addEventListener('click', async () => { const d = new Date(estado.data); d.setDate(d.getDate() - 1); selectedDate = d.toISOString().split('T')[0]; } + console.log('[DEBUG] selectedDate:', selectedDate, 'selectedId:', selectedId); await tauriSaveLocal(); setVal('f-data', selectedDate); @@ -1754,24 +1759,27 @@ document.getElementById('btn-anterior').addEventListener('click', async () => { // Tenta Supabase primeiro (com id se disponível), senão local let rascunho = null; if (selectedId) { - // Usa sb_buscar_por_id para buscar por id numérico do Supabase try { rascunho = await window.__TAURI__.core.invoke('sb_buscar_por_id', { id: selectedId }); + console.log('[DEBUG] sb_buscar_por_id retornou:', !!rascunho); } catch(e) { console.warn('sb_buscar_por_id falhou:', e); } } if (!rascunho) { try { rascunho = await window.__TAURI__.core.invoke('sb_carregar_rascunho', { loja, data: selectedDate }); + console.log('[DEBUG] sb_carregar_rascunho retornou:', !!rascunho); } catch(e) { console.warn('sb_carregar_rascunho falhou:', e); } } if (!rascunho) { try { rascunho = await window.__TAURI__.core.invoke('carregar_rascunho', { loja, data: selectedDate }); + console.log('[DEBUG] carregar_rascunho local retornou:', !!rascunho); } catch(e) { console.warn('carregar_rascunho local falhou:', e); } } if (rascunho) { + console.log('[DEBUG] rascunho carregado com sucesso'); if (rascunho.operador) { setVal('f-operador', rascunho.operador); estado.operador = rascunho.operador; } if (rascunho.turno) { setVal('f-turno', rascunho.turno); estado.turno = rascunho.turno; } if (rascunho.saldo_troco) setVal('sys-troco', fmtNum(rascunho.saldo_troco)); @@ -1803,19 +1811,20 @@ document.getElementById('btn-anterior').addEventListener('click', async () => { estado.cartoes.pix = norm(rascunho.cartoes.pix); } } else { + console.log('[DEBUG] nenhum rascunho encontrado para esta data'); estado.despesas = []; estado.sangrias = []; estado.pixcnpj = []; estado.vales = []; estado.receber = []; estado.cancelamentos = []; estado.cartoes = { credito: [], debito: [], alimentacao: [], pix: [] }; setVal('sys-troco', ''); setVal('f-saldo-esperado', ''); setVal('f-obs', ''); } - // Marcar que este é um rascunho carregado (não novo) estado.sync_status = rascunho ? 'loaded' : 'local'; PRE_FILL_TABLES.forEach(ensureOneRow); Object.keys(TABLES).forEach(renderTable); updateTotals(); scheduleSave(); + console.log('[DEBUG] btn-anterior concluído'); }); document.getElementById('f-obs').addEventListener('input', e => { estado.observacoes = e.target.value; scheduleSave(); });