debug: btn-anterior logs; cartoes.norm guard
This commit is contained in:
+11
-2
@@ -1701,12 +1701,15 @@ document.getElementById('btn-limpar').addEventListener('click', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('btn-anterior').addEventListener('click', async () => {
|
document.getElementById('btn-anterior').addEventListener('click', async () => {
|
||||||
|
console.log('[DEBUG] btn-anterior clicado');
|
||||||
const loja = val('f-loja') || 'União';
|
const loja = val('f-loja') || 'União';
|
||||||
|
console.log('[DEBUG] btn-anterior loja:', loja);
|
||||||
|
|
||||||
// Carrega lista de fechamentos recentes do Supabase com uuid
|
// Carrega lista de fechamentos recentes do Supabase com uuid
|
||||||
let recentList = [];
|
let recentList = [];
|
||||||
try {
|
try {
|
||||||
recentList = await window.__TAURI__.core.invoke('sb_listar_recentes', { loja, limite: 20 });
|
recentList = await window.__TAURI__.core.invoke('sb_listar_recentes', { loja, limite: 20 });
|
||||||
|
console.log('[DEBUG] sb_listar_recentes retornou:', recentList?.length, 'itens');
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.warn('sb_listar_recentes falhou:', e);
|
console.warn('sb_listar_recentes falhou:', e);
|
||||||
}
|
}
|
||||||
@@ -1723,6 +1726,7 @@ document.getElementById('btn-anterior').addEventListener('click', async () => {
|
|||||||
});
|
});
|
||||||
dateList.sort().reverse();
|
dateList.sort().reverse();
|
||||||
}
|
}
|
||||||
|
console.log('[DEBUG] dateList:', dateList);
|
||||||
|
|
||||||
let selectedDate = null;
|
let selectedDate = null;
|
||||||
let selectedId = 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);
|
const d = new Date(estado.data); d.setDate(d.getDate() - 1);
|
||||||
selectedDate = d.toISOString().split('T')[0];
|
selectedDate = d.toISOString().split('T')[0];
|
||||||
}
|
}
|
||||||
|
console.log('[DEBUG] selectedDate:', selectedDate, 'selectedId:', selectedId);
|
||||||
|
|
||||||
await tauriSaveLocal();
|
await tauriSaveLocal();
|
||||||
setVal('f-data', selectedDate);
|
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
|
// Tenta Supabase primeiro (com id se disponível), senão local
|
||||||
let rascunho = null;
|
let rascunho = null;
|
||||||
if (selectedId) {
|
if (selectedId) {
|
||||||
// Usa sb_buscar_por_id para buscar por id numérico do Supabase
|
|
||||||
try {
|
try {
|
||||||
rascunho = await window.__TAURI__.core.invoke('sb_buscar_por_id', { id: selectedId });
|
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); }
|
} catch(e) { console.warn('sb_buscar_por_id falhou:', e); }
|
||||||
}
|
}
|
||||||
if (!rascunho) {
|
if (!rascunho) {
|
||||||
try {
|
try {
|
||||||
rascunho = await window.__TAURI__.core.invoke('sb_carregar_rascunho', { loja, data: selectedDate });
|
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); }
|
} catch(e) { console.warn('sb_carregar_rascunho falhou:', e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rascunho) {
|
if (!rascunho) {
|
||||||
try {
|
try {
|
||||||
rascunho = await window.__TAURI__.core.invoke('carregar_rascunho', { loja, data: selectedDate });
|
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); }
|
} catch(e) { console.warn('carregar_rascunho local falhou:', e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rascunho) {
|
if (rascunho) {
|
||||||
|
console.log('[DEBUG] rascunho carregado com sucesso');
|
||||||
if (rascunho.operador) { setVal('f-operador', rascunho.operador); estado.operador = rascunho.operador; }
|
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.turno) { setVal('f-turno', rascunho.turno); estado.turno = rascunho.turno; }
|
||||||
if (rascunho.saldo_troco) setVal('sys-troco', fmtNum(rascunho.saldo_troco));
|
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);
|
estado.cartoes.pix = norm(rascunho.cartoes.pix);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
console.log('[DEBUG] nenhum rascunho encontrado para esta data');
|
||||||
estado.despesas = []; estado.sangrias = []; estado.pixcnpj = [];
|
estado.despesas = []; estado.sangrias = []; estado.pixcnpj = [];
|
||||||
estado.vales = []; estado.receber = []; estado.cancelamentos = [];
|
estado.vales = []; estado.receber = []; estado.cancelamentos = [];
|
||||||
estado.cartoes = { credito: [], debito: [], alimentacao: [], pix: [] };
|
estado.cartoes = { credito: [], debito: [], alimentacao: [], pix: [] };
|
||||||
setVal('sys-troco', ''); setVal('f-saldo-esperado', ''); setVal('f-obs', '');
|
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';
|
estado.sync_status = rascunho ? 'loaded' : 'local';
|
||||||
|
|
||||||
PRE_FILL_TABLES.forEach(ensureOneRow);
|
PRE_FILL_TABLES.forEach(ensureOneRow);
|
||||||
Object.keys(TABLES).forEach(renderTable);
|
Object.keys(TABLES).forEach(renderTable);
|
||||||
updateTotals();
|
updateTotals();
|
||||||
scheduleSave();
|
scheduleSave();
|
||||||
|
console.log('[DEBUG] btn-anterior concluído');
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('f-obs').addEventListener('input', e => { estado.observacoes = e.target.value; scheduleSave(); });
|
document.getElementById('f-obs').addEventListener('input', e => { estado.observacoes = e.target.value; scheduleSave(); });
|
||||||
|
|||||||
Reference in New Issue
Block a user