Fix: align frontend commands with backend, fix data model mismatch
- Rename commands: salvar_local→salvar_fechamento, enviar_fechamento→sb_salvar_fechamento, etc. - Fix typo: cartoes.credo→cartoes.credito - storage: accept serde_json::Value instead of FechamentoEstado for flexibility - Add Default derive on FechamentoEstado and SyncStatus - Commands now return simplified JSON for frontend compatibility
This commit is contained in:
+6
-6
@@ -613,7 +613,7 @@ function calcular() {
|
||||
estado.total_despesas = estado.despesas.filter(d => !d.desc.includes('Sangria')).reduce((s,d) => s+d.valor, 0);
|
||||
estado.vales = parseFloat(val('f-vales')) || 0;
|
||||
estado.cartoes = {
|
||||
credo: parseFloat(val('f-credito')) || 0,
|
||||
credito: parseFloat(val('f-credito')) || 0,
|
||||
debito: parseFloat(val('f-debito')) || 0,
|
||||
alimentacao: parseFloat(val('f-alimentacao')) || 0,
|
||||
voucher: parseFloat(val('f-voucher')) || 0,
|
||||
@@ -642,7 +642,7 @@ function updateBadges() {
|
||||
async function salvarRascunho(silent = false) {
|
||||
calcular();
|
||||
try {
|
||||
const result = await invokeSafe('salvar_local', { estado: JSON.stringify(estado) });
|
||||
const result = await invokeSafe('salvar_fechamento', { estado });
|
||||
estado.id_local = result.id;
|
||||
estado.uuid = result.uuid;
|
||||
if (!silent) toast('Rascunho salvo (local)', 'success');
|
||||
@@ -689,7 +689,7 @@ async function enviarFechamento() {
|
||||
if (!estado.loja || !estado.data) { toast('Loja e data so obrigatorios', 'error'); return; }
|
||||
showLoad('Enviando ao servidor…');
|
||||
try {
|
||||
await invokeSafe('enviar_fechamento', { estado: JSON.stringify(estado) });
|
||||
await invokeSafe('sb_salvar_fechamento', { estado });
|
||||
toast('Enviado com sucesso!', 'success');
|
||||
atualizarSyncBadge('synced');
|
||||
} catch(e) { toast(`Erro ao enviar: ${e}`, 'error'); }
|
||||
@@ -739,7 +739,7 @@ async function imprimirAgora() {
|
||||
document.getElementById('modal-print').classList.remove('show');
|
||||
showLoad('Imprimindo…');
|
||||
try {
|
||||
await invokeSafe('imprimir_fechamento', { estado: JSON.stringify(estado) });
|
||||
await invokeSafe('imprimir_recibo', { estado });
|
||||
toast('Impresso com sucesso!', 'success');
|
||||
} catch(e) { toast(`Erro na impressao: ${e}`, 'error'); }
|
||||
hideLoad();
|
||||
@@ -755,7 +755,7 @@ async function listarRecentes() {
|
||||
if (!loja) { toast('Selecione a loja primeiro', 'error'); return; }
|
||||
showLoad('Carregando recentes…');
|
||||
try {
|
||||
const lista = await invokeSafe('listar_recentes', { loja, limite: 20 });
|
||||
const lista = await invokeSafe('sb_listar_recentes', { loja, limite: 20 });
|
||||
const html = lista.map(r => `
|
||||
<tr onclick="selecionarRecente(${r.id})" style="cursor:pointer">
|
||||
<td>${r.data}</td><td>${r.operador||'—'}</td><td>${r.turno}º</td>
|
||||
@@ -785,7 +785,7 @@ async function selecionarRecente(id) {
|
||||
document.getElementById('modal-recentes')?.classList.remove('show');
|
||||
showLoad('Carregando…');
|
||||
try {
|
||||
const r = await invokeSafe('buscar_fechamento', { id });
|
||||
const r = await invokeSafe('buscar_fechamento_por_id', { id });
|
||||
Object.assign(estado, r);
|
||||
document.getElementById('f-saldo-troco').value = r.saldo_troco || '';
|
||||
document.getElementById('f-fechamento').value = r.fechamento || '';
|
||||
|
||||
Reference in New Issue
Block a user