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);
- overlay.addEventListener('click', e => { if (e.target === overlay) closeConsultaModal(); });
+ window._recentList = recentList;
}
// Abre a janela de edição completa de um registro pelo índice na lista
@@ -2373,79 +2272,6 @@ function closeConsultaModal() {
window._currentConsulta = null;
}
-// Abre o relatório pelo elemento
(evita dependência de índice)
-window.openConsultaRegistroByItem = async function(tr) {
- const dataAttr = tr ? tr.dataset.item : null;
- let item = null;
- if (dataAttr) {
- try { item = JSON.parse(dataAttr); } catch(e) {}
- }
- if (!item) {
- // Fallback: busca pelo texto da primeira célula (data)
- const dataText = tr.cells[0]?.textContent?.trim();
- if (dataText) {
- const [d,m,y] = dataText.split('/');
- const dataKey = `${y}-${m}-${d}`;
- item = window._consultaAll?.find(it => it.data === dataKey);
- }
- }
- if (!item) { alert('Registro não encontrado.'); return; }
- closeConsultaModal();
-
- 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; }
- window._currentConsulta = full;
- buildRelatorioModal(full);
-};
-
-// Abre a edição pelo elemento
(evita dependência de índice)
-window.abrirEditaFechamentoByItem = async function(tr) {
- const dataAttr = tr ? tr.dataset.item : null;
- let item = null;
- if (dataAttr) {
- try { item = JSON.parse(dataAttr); } catch(e) {}
- }
- if (!item) {
- const dataText = tr.cells[0]?.textContent?.trim();
- if (dataText) {
- const [d,m,y] = dataText.split('/');
- const dataKey = `${y}-${m}-${d}`;
- item = window._consultaAll?.find(it => it.data === dataKey);
- }
- }
- if (!item) { alert('Registro não encontrado.'); 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; }
- window._currentConsulta = full;
- closeConsultaModal();
- closeRelatorioModal();
-
- const pw = localStorage.getItem('admin_pw') || '1234';
- const granted = await askPassword(pw);
- if (!granted) return;
-
- openEditModal(full);
-};
-
// Abre o relatório de um registro selecionado
window.openConsultaRegistro = async function(idx) {
const item = window._recentList[idx];
@@ -2890,7 +2716,35 @@ window._recalcEditTotals = function() {
if (el('tot-areceber')) el('tot-areceber').textContent = fmtTot(recv_tot);
if (el('tot-sangrias')) el('tot-sangrias').textContent = fmtTot(sang_tot);
if (el('tot-despesas')) el('tot-despesas').textContent = fmtTot(desp_tot);
- if (el('tot-cancel')) el('tot-cancel').textContent = fmtTot(canc_tot);
+ if (el('tot-cancel')) el('tot-cancel').textContent = fmtTot(canc_tot);
+
+ // Atualiza campos readonly do saldo de caixa com totais calculados
+ const setReadonly = (id, v) => { if (el(id)) el(id).value = fmtTot(v); };
+ setReadonly('edit-sld-credito', cartCred_tot);
+ setReadonly('edit-sld-debito', cartDeb_tot);
+ setReadonly('edit-sld-alimentacao', cartAli_tot);
+ setReadonly('edit-sld-vales', vales_tot);
+ setReadonly('edit-sld-pixcnpj', pixcnpj_tot);
+ setReadonly('edit-sld-areceber', recv_tot);
+ setReadonly('edit-sld-pixcartao', cartPix_tot);
+
+ // Calcula Saldo Caixa e Diferença em tempo real
+ const trocoVal = parseNum(el('edit-troco')?.value || '0');
+ const esperadoVal = parseNum(el('edit-esperado')?.value || '0');
+ const saldoCaixa = trocoVal + cartCred_tot + cartDeb_tot + cartAli_tot + cartPix_tot + pixcnpj_tot + vales_tot + recv_tot;
+ const diferenca = saldoCaixa - esperadoVal - canc_tot;
+
+ if (el('edit-saldo-caixa')) {
+ el('edit-saldo-caixa').textContent = saldoCaixa > 0 ? fmtTot(saldoCaixa) : 'R$ 0,00';
+ }
+ if (el('edit-diferenca')) {
+ const fmtDif = v => v >= 0 ? `R$ ${v.toLocaleString('pt-BR', { minimumFractionDigits: 2 })}` : `-R$ ${Math.abs(v).toLocaleString('pt-BR', { minimumFractionDigits: 2 })}`;
+ el('edit-diferenca').textContent = fmtDif(diferenca);
+ // Alerta visual se diferença != 0
+ if (el('edit-diferenca-box')) {
+ el('edit-diferenca-box').style.background = diferenca === 0 ? '#e8f5e9' : diferenca > 0 ? '#fff3e0' : '#ffebee';
+ }
+ }
};
// Modal de edição completo com todas as grades
@@ -3109,7 +2963,8 @@ function openEditModal(full) {
💰 Saldo de Caixa (apenas Troco é editável)
-
+
+
@@ -3118,14 +2973,23 @@ function openEditModal(full) {
+
+
+ SALDO CAIXA:
+ R$ 0,00
+
+
+ DIFERENÇA:
+ R$ 0,00
+
+
-
+
-
@@ -3141,6 +3005,8 @@ function openEditModal(full) {
`;
document.body.appendChild(overlay);
+ // Calcula totais iniciais após renderizar o DOM
+ setTimeout(() => window._recalcEditTotals(), 50);
}
// Formata campo de dinheiro brasileiro