diff --git a/src/index.html b/src/index.html index e709eb5..1b85a6a 100644 --- a/src/index.html +++ b/src/index.html @@ -2165,24 +2165,27 @@ function buildConsultaModal(recentList) { const rows = recentList.map((item, i) => { const total = (parseFloat(item.fechamento_dinheiro)||0) + (parseFloat(item.fechamento_cartoes)||0) + (parseFloat(item.fechamento_areceber)||0); - return ` - ${fmtDate(item.data)} - ${item.operador||'?'} - ${item.turno||'?'} - ${fmtMoney(total)} - ${fmtMoney(item.saldo_esperado)} - ${statusBadge(item.status_diferenca)} - ${syncBadge(item.sync_status)} + return ` + ${fmtDate(item.data)} + ${item.operador||'?'} + ${item.turno||'?'} + ${fmtMoney(total)} + ${fmtMoney(item.saldo_esperado)} + ${statusBadge(item.status_diferenca)} + ${syncBadge(item.sync_status)} + + + `; }).join(''); overlay.innerHTML = ` -
+

📅 Consultar Fechamentos Anteriores

-

Clique em um registro para ver o relatório e, se necessário, editar campos com senha admin.

+

Clique em um registro para ver o relatório ou clique em Editar para abrir a janela de edição.

@@ -2193,6 +2196,7 @@ function buildConsultaModal(recentList) { + ${rows} @@ -2204,6 +2208,40 @@ function buildConsultaModal(recentList) { window._recentList = recentList; } +// Abre a janela de edição completa de um registro pelo índice na lista +window.abrirEditaFechamentoIndex = async function(idx) { + const item = window._recentList ? window._recentList[idx] : null; + if (!item) return; + + const hasTauri = !!(window.__TAURI__ && window.__TAURI__.core); + if (!hasTauri) { alert('Tauri não disponível.'); return; } + + let full = null; + try { + if (item.id) { + try { full = await window.__TAURI__.core.invoke('sb_buscar_por_id', { id: item.id }); } catch(e) {} + } + if (!full && item.uuid) { + try { full = await window.__TAURI__.core.invoke('sb_buscar_por_uuid', { uuid: item.uuid }); } catch(e) {} + } + if (!full && item.id_fechamento) { + try { full = await window.__TAURI__.core.invoke('sb_buscar_por_id_fechamento', { idFechamento: item.id_fechamento }); } catch(e) {} + } + } catch(e) { + console.warn('Erro buscando registro:', e); + } + + if (!full) { alert('Registro não encontrado.'); return; } + + // Adiciona id_fechamento se não vier do banco + if (!full.id_fechamento && full.loja && full.data && full.operador) { + full.id_fechamento = (full.loja + '_' + full.data + '_' + full.operador).toLowerCase().replace(/ /g, '_'); + } + + closeConsultaModal(); + window.abrirEditaFechamento(full); +}; + function closeConsultaModal() { const m = document.getElementById('modal-consulta'); if (m) document.body.removeChild(m); @@ -2897,6 +2935,187 @@ function closeEditModal() { window._editModalOpen = false; } +// ─── Janela separada para edição completa ─────────────────────────────────── +// Abre uma nova janela (window.open) com HTML inline pré-preenchido com todos +// os dados do registro. Permite editar todos os campos e salvar via +// sb_atualizar_fechamento. O botão Cancelar fecha a janela. +window.abrirEditaFechamento = async function(full) { + if (!full) { alert('Registro não fornecido.'); return; } + + // Serializa o registro para passar à popup — usa JSON para preservar tudo + const encoded = encodeURIComponent(JSON.stringify(full)); + + const html = ` + + + +Editar Fechamento — ${(full.data||'').substring(0,10)} ${full.operador||''} + + + +

✏️ Editar Fechamento — ${(full.loja||'').toUpperCase()} · ${(full.data||'').substring(0,10)} · ${full.operador||''}

+ + +
+
Identificação
+
+
+
+ +
+
+ +
+
+
+
+ + +
+ Crédito: R$ ${parseFloat(full.total_cartao_credito||0).toLocaleString('pt-BR',{minimumFractionDigits:2})} + Débito: R$ ${parseFloat(full.total_cartao_debito||0).toLocaleString('pt-BR',{minimumFractionDigits:2})} + Alimentação: R$ ${parseFloat(full.total_cartao_alimentacao||0).toLocaleString('pt-BR',{minimumFractionDigits:2})} + PIX: R$ ${parseFloat(full.total_cartao_pix||0).toLocaleString('pt-BR',{minimumFractionDigits:2})} + PIX CNPJ: R$ ${parseFloat(full.total_pixcnpj||0).toLocaleString('pt-BR',{minimumFractionDigits:2})} + Vales: R$ ${parseFloat(full.total_vales||0).toLocaleString('pt-BR',{minimumFractionDigits:2})} + A Receber: R$ ${parseFloat(full.total_areceber||0).toLocaleString('pt-BR',{minimumFractionDigits:2})} + Sangrias: R$ ${parseFloat(full.total_sangrias||0).toLocaleString('pt-BR',{minimumFractionDigits:2})} + Despesas: R$ ${parseFloat(full.total_despesas||0).toLocaleString('pt-BR',{minimumFractionDigits:2})} +
+ + +
+
💰 Saldo de Caixa
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
📦 Fechamento Contado
+
+
+
+
+
+
+ + +
+
📊 Dados Operacionais
+
+
+
+
+
+
+
+ + +
+
+
+ + +
+ + +
+ +
ESPERADO STATUS SYNCAÇÃO