|
|
@@ -1320,12 +1320,9 @@ function buildConfirmHTML(data) {
|
|
|
|
// Relatório completo — mesmo layout do PDF
|
|
|
|
// Relatório completo — mesmo layout do PDF
|
|
|
|
const fmt = v => 'R$ ' + (v || 0).toFixed(2).replace('.', ',');
|
|
|
|
const fmt = v => 'R$ ' + (v || 0).toFixed(2).replace('.', ',');
|
|
|
|
const fmtNeg = v => (v < 0 ? '-' : '') + 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ',');
|
|
|
|
const fmtNeg = v => (v < 0 ? '-' : '') + 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ',');
|
|
|
|
// Diferença = Total Sistema - Saldo Esperado - Cancelamentos
|
|
|
|
// Diferença = fechamento - saldo_esperado - cancelamentos
|
|
|
|
// sys_total = troco + crédito + débito + alimentação + pix + vales + pixcnpj + receber (lançamentos do sistema)
|
|
|
|
const diferenca = data.diferenca !== undefined ? data.diferenca
|
|
|
|
const sysTotal = data.sys_total || 0;
|
|
|
|
: ((data.fechamento || 0) - (data.saldo_esperado || 0) - (data.cancelamentos || 0));
|
|
|
|
const saldoEsperado = data.saldo_esperado || 0;
|
|
|
|
|
|
|
|
const cancelamentos = data.cancelamentos || 0;
|
|
|
|
|
|
|
|
const diferenca = sysTotal - saldoEsperado - cancelamentos;
|
|
|
|
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca);
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca);
|
|
|
|
const diffOk = diferenca === 0;
|
|
|
|
const diffOk = diferenca === 0;
|
|
|
|
|
|
|
|
|
|
|
@@ -1490,12 +1487,10 @@ function buildPrintHTML(data) {
|
|
|
|
const fmt = v => 'R$ ' + (v || 0).toFixed(2).replace('.', ',');
|
|
|
|
const fmt = v => 'R$ ' + (v || 0).toFixed(2).replace('.', ',');
|
|
|
|
const fmtNeg = v => (v < 0 ? '-' : '') + 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ',');
|
|
|
|
const fmtNeg = v => (v < 0 ? '-' : '') + 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ',');
|
|
|
|
// Diferença = Total Sistema - Saldo Esperado - Cancelamentos
|
|
|
|
// Diferença = Total Sistema - Saldo Esperado - Cancelamentos
|
|
|
|
// data.fechaemento = fechamento contado (dinheiro + cartões + receber)
|
|
|
|
const sysTotalCalc = (data.sysTotal || 0);
|
|
|
|
// data.sys_total = troco + crédito + débito + alimentação + pix + vales + pixcnpj + receber (do sistema)
|
|
|
|
const saldoEsperadoCalc = (data.saldo_esperado || 0);
|
|
|
|
const sysTotal = (data.sys_total || 0);
|
|
|
|
const cancelamentosCalc = (data.cancelamentos || 0);
|
|
|
|
const saldoEsperado = (data.saldo_esperado || 0);
|
|
|
|
const diferenca = sysTotalCalc - saldoEsperadoCalc - cancelamentosCalc;
|
|
|
|
const cancelamentos = (data.cancelamentos || 0);
|
|
|
|
|
|
|
|
const diferenca = sysTotal - saldoEsperado - cancelamentos;
|
|
|
|
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca);
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca);
|
|
|
|
const diffColor = diferenca === 0 ? '#2e7d32' : (diferenca > 0 ? '#e65100' : '#c0272d');
|
|
|
|
const diffColor = diferenca === 0 ? '#2e7d32' : (diferenca > 0 ? '#e65100' : '#c0272d');
|
|
|
|
|
|
|
|
|
|
|
@@ -1729,7 +1724,8 @@ function buildReportHTML(data) {
|
|
|
|
const fechamento = data.fechamento || 0;
|
|
|
|
const fechamento = data.fechamento || 0;
|
|
|
|
const sysTotal = data.sys_total || 0;
|
|
|
|
const sysTotal = data.sys_total || 0;
|
|
|
|
const saldoEsp = data.saldo_esperado || 0;
|
|
|
|
const saldoEsp = data.saldo_esperado || 0;
|
|
|
|
const diferenca = sysTotal - saldoEsp - cancelamentos;
|
|
|
|
const diferenca = data.diferenca !== undefined ? data.diferenca
|
|
|
|
|
|
|
|
: (fechamento - saldoEsp - cancelamentos);
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca);
|
|
|
|
const diffStr = diferenca >= 0 ? `+${fmt(diferenca)}` : fmtNeg(diferenca);
|
|
|
|
const diffColor = diferenca === 0 ? '#2e7d32' : '#c0272d';
|
|
|
|
const diffColor = diferenca === 0 ? '#2e7d32' : '#c0272d';
|
|
|
|
|
|
|
|
|
|
|
@@ -2653,6 +2649,8 @@ window._recalcEditTotals = function() {
|
|
|
|
// Modal de edição completo com todas as grades
|
|
|
|
// Modal de edição completo com todas as grades
|
|
|
|
function openEditModal(full) {
|
|
|
|
function openEditModal(full) {
|
|
|
|
window._editModalOpen = true;
|
|
|
|
window._editModalOpen = true;
|
|
|
|
|
|
|
|
// Salva o registro ANTES de fechar o modal de relatório — usa variável separada para não conflitar
|
|
|
|
|
|
|
|
window._editingRecord = full;
|
|
|
|
|
|
|
|
|
|
|
|
const dados = full.dados || {};
|
|
|
|
const dados = full.dados || {};
|
|
|
|
|
|
|
|
|
|
|
@@ -2683,27 +2681,27 @@ function openEditModal(full) {
|
|
|
|
const cartPixHTML = editTableHTML('pix', ['Valor (R$)'], cartPix_rows.length ? cartPix_rows : [['']], [0]);
|
|
|
|
const cartPixHTML = editTableHTML('pix', ['Valor (R$)'], cartPix_rows.length ? cartPix_rows : [['']], [0]);
|
|
|
|
|
|
|
|
|
|
|
|
// --- Vales ---
|
|
|
|
// --- Vales ---
|
|
|
|
const vales_rows = (full.vales_arr || []).map(r => [r.nome||r.Nome||'', r.valor||0, r.obs||r.Obs||'']);
|
|
|
|
const vales_rows = (dados.vales || []).map(r => [r.nome||'', r.valor||0, r.obs||'']);
|
|
|
|
const valesHTML = editTableHTML('vales', ['Nome', 'Valor (R$)', 'Obs'], vales_rows.length ? vales_rows : [['','','']], [1]);
|
|
|
|
const valesHTML = editTableHTML('vales', ['Nome', 'Valor (R$)', 'Obs'], vales_rows.length ? vales_rows : [['','','']], [1]);
|
|
|
|
|
|
|
|
|
|
|
|
// --- Despesas ---
|
|
|
|
// --- Despesas ---
|
|
|
|
const despesas_rows = (full.despesas_arr || []).map(r => [r.desc||r.Desc||'', r.obs||r.Obs||'', r.valor||0]);
|
|
|
|
const despesas_rows = (dados.despesas || []).map(r => [r.desc||'', r.obs||'', r.valor||0]);
|
|
|
|
const despesasHTML = editTableHTML('despesas', ['Descrição', 'Obs', 'Valor (R$)'], despesas_rows.length ? despesas_rows : [['','','']], [2]);
|
|
|
|
const despesasHTML = editTableHTML('despesas', ['Descrição', 'Obs', 'Valor (R$)'], despesas_rows.length ? despesas_rows : [['','','']], [2]);
|
|
|
|
|
|
|
|
|
|
|
|
// --- Sangrias ---
|
|
|
|
// --- Sangrias ---
|
|
|
|
const sangrias_rows = (full.sangrias_arr || []).map(r => [r.hora||r.Hora||'', r.retirada||r.valor||0, r.gerente||r.Gerente||'']);
|
|
|
|
const sangrias_rows = (dados.sangrias || []).map(r => [r.hora||'', r.retirada||r.valor||0, r.gerente||'']);
|
|
|
|
const sangriasHTML = editTableHTML('sangrias', ['Hora', 'Valor (R$)', 'Gerente'], sangrias_rows.length ? sangrias_rows : [['','','']], [1]);
|
|
|
|
const sangriasHTML = editTableHTML('sangrias', ['Hora', 'Valor (R$)', 'Gerente'], sangrias_rows.length ? sangrias_rows : [['','','']], [1]);
|
|
|
|
|
|
|
|
|
|
|
|
// --- Cancelamentos ---
|
|
|
|
// --- Cancelamentos ---
|
|
|
|
const cancel_rows = (full.cancelamentos_arr || []).map(r => [r.numero||r.Numero||'', r.valor||0, r.motivo||r.Motivo||'']);
|
|
|
|
const cancel_rows = (dados.cancelamentos || []).map(r => [r.numero||'', r.valor||0, r.motivo||'']);
|
|
|
|
const cancelHTML = editTableHTML('cancelamentos', ['Número', 'Valor (R$)', 'Motivo'], cancel_rows.length ? cancel_rows : [['','','']], [1]);
|
|
|
|
const cancelHTML = editTableHTML('cancelamentos', ['Número', 'Valor (R$)', 'Motivo'], cancel_rows.length ? cancel_rows : [['','','']], [1]);
|
|
|
|
|
|
|
|
|
|
|
|
// --- PIX CNPJ ---
|
|
|
|
// --- PIX CNPJ ---
|
|
|
|
const pixcnpj_rows = (full.pixcnpj_arr || []).map(r => [r.nome||r.desc||r.Desc||'', r.valor||0]);
|
|
|
|
const pixcnpj_rows = (dados.pixcnpj || []).map(r => [r.nome||r.desc||'', r.valor||0]);
|
|
|
|
const pixcnpjHTML = editTableHTML('pixcnpj', ['Nome', 'Valor (R$)'], pixcnpj_rows.length ? pixcnpj_rows : [['','']], [1]);
|
|
|
|
const pixcnpjHTML = editTableHTML('pixcnpj', ['Nome', 'Valor (R$)'], pixcnpj_rows.length ? pixcnpj_rows : [['','']], [1]);
|
|
|
|
|
|
|
|
|
|
|
|
// --- A Receber ---
|
|
|
|
// --- A Receber ---
|
|
|
|
const receber_rows = (full.receber_arr || []).map(r => [r.nome||r.Nome||'', r.valor||0]);
|
|
|
|
const receber_rows = (dados.receber || []).map(r => [r.nome||'', r.valor||0]);
|
|
|
|
const receberHTML = editTableHTML('receber', ['Nome', 'Valor (R$)'], receber_rows.length ? receber_rows : [['','']], [1]);
|
|
|
|
const receberHTML = editTableHTML('receber', ['Nome', 'Valor (R$)'], receber_rows.length ? receber_rows : [['','']], [1]);
|
|
|
|
|
|
|
|
|
|
|
|
// --- Totais (só leitura formatado) ---
|
|
|
|
// --- Totais (só leitura formatado) ---
|
|
|
@@ -2901,8 +2899,10 @@ function closeEditModal() {
|
|
|
|
|
|
|
|
|
|
|
|
// Salva edições do modal de edição completo
|
|
|
|
// Salva edições do modal de edição completo
|
|
|
|
window.salvarEdicaoModal = async function() {
|
|
|
|
window.salvarEdicaoModal = async function() {
|
|
|
|
const full = window._currentConsulta;
|
|
|
|
console.log('[DEBUG] salvarEdicaoModal called');
|
|
|
|
if (!full) return;
|
|
|
|
const full = window._editingRecord;
|
|
|
|
|
|
|
|
if (!full) { console.log('[DEBUG] _editingRecord is null'); alert('Nenhum registro selecionado.'); return; }
|
|
|
|
|
|
|
|
console.log('[DEBUG] full.uuid:', full.uuid, 'full.id:', full.id);
|
|
|
|
|
|
|
|
|
|
|
|
const p = v => parseNum(v);
|
|
|
|
const p = v => parseNum(v);
|
|
|
|
const inp = id => { const el = document.getElementById(id); return el ? el.value : ''; };
|
|
|
|
const inp = id => { const el = document.getElementById(id); return el ? el.value : ''; };
|
|
|
@@ -2941,6 +2941,9 @@ window.salvarEdicaoModal = async function() {
|
|
|
|
const operador = estado.operador || full.operador || '';
|
|
|
|
const operador = estado.operador || full.operador || '';
|
|
|
|
|
|
|
|
|
|
|
|
const updates = {
|
|
|
|
const updates = {
|
|
|
|
|
|
|
|
// Chave natural — essencial para o Supabase encontrar o registro
|
|
|
|
|
|
|
|
id_fechamento: inp('edit-loja') + '_' + inp('edit-data') + '_' + inp('edit-operador'),
|
|
|
|
|
|
|
|
|
|
|
|
// Identificação
|
|
|
|
// Identificação
|
|
|
|
loja: inp('edit-loja'),
|
|
|
|
loja: inp('edit-loja'),
|
|
|
|
data: inp('edit-data'),
|
|
|
|
data: inp('edit-data'),
|
|
|
@@ -3001,12 +3004,16 @@ window.salvarEdicaoModal = async function() {
|
|
|
|
if (!hasTauri) { alert('Tauri não disponível.'); return; }
|
|
|
|
if (!hasTauri) { alert('Tauri não disponível.'); return; }
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// Usa uuid (string) — que é o id externo do registro no Supabase
|
|
|
|
// Usa id_fechamento que é a chave natural do registro
|
|
|
|
const uuid = full.uuid || full.id;
|
|
|
|
const id_fechamento = full.id_fechamento || (full.loja && full.data && full.operador
|
|
|
|
if (!uuid) { alert('UUID do registro não encontrado.'); return; }
|
|
|
|
? `${full.loja}_${full.data}_${full.operador}`.toLowerCase().replace(/ /g, '_')
|
|
|
|
console.log('[DEBUG] salvarEdicaoModal uuid:', uuid, 'updates:', JSON.stringify(updates));
|
|
|
|
: null);
|
|
|
|
|
|
|
|
if (!id_fechamento) { alert('id_fechamento não encontrado.'); return; }
|
|
|
|
|
|
|
|
console.log('[DEBUG] salvarEdicaoModal id_fechamento:', id_fechamento, 'updates:', JSON.stringify(updates));
|
|
|
|
|
|
|
|
|
|
|
|
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id: uuid, updates: JSON.stringify(updates) });
|
|
|
|
console.log('[DEBUG] invoking sb_atualizar_fechamento...');
|
|
|
|
|
|
|
|
const result = await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id_fechamento, updates: JSON.stringify(updates) });
|
|
|
|
|
|
|
|
console.log('[DEBUG] invoke result:', result);
|
|
|
|
closeEditModal();
|
|
|
|
closeEditModal();
|
|
|
|
closeRelatorioModal();
|
|
|
|
closeRelatorioModal();
|
|
|
|
alert('✅ Atualizado com sucesso!');
|
|
|
|
alert('✅ Atualizado com sucesso!');
|
|
|
@@ -3169,26 +3176,26 @@ window.printRelatorio = function() {
|
|
|
|
<title>Fechamento de Caixa</title>
|
|
|
|
<title>Fechamento de Caixa</title>
|
|
|
|
<style>
|
|
|
|
<style>
|
|
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
body { font-family: 'Courier New', monospace; font-size: 17px; width: 80mm; margin: 0 auto; padding: 10px 12px; font-weight: bold; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
|
|
|
|
body { font-family: 'Courier New', monospace; font-size: 14px; width: 80mm; margin: 0 auto; padding: 8px; font-weight: bold; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
|
|
|
|
.header { text-align: center; margin-bottom: 10px; }
|
|
|
|
.header { text-align: center; margin-bottom: 8px; }
|
|
|
|
.header h1 { font-size: 22px; font-weight: bold; }
|
|
|
|
.header h1 { font-size: 20px; font-weight: bold; }
|
|
|
|
.header h2 { font-size: 17px; font-weight: normal; }
|
|
|
|
.header h2 { font-size: 15px; font-weight: normal; }
|
|
|
|
hr { border: none; border-top: 2px solid #000; margin: 8px 0; }
|
|
|
|
hr { border: none; border-top: 2px solid #000; margin: 6px 0; }
|
|
|
|
.section-title { font-weight: bold; font-size: 16px; border-top: 2px solid #000; padding-top: 6px; margin-top: 10px; }
|
|
|
|
.section-title { font-weight: bold; font-size: 14px; border-top: 2px solid #000; padding-top: 4px; margin-top: 8px; }
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 15px; font-weight: bold; }
|
|
|
|
.row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 13px; font-weight: bold; }
|
|
|
|
.row.total-row { font-weight: bold; }
|
|
|
|
.row.total-row { font-weight: bold; }
|
|
|
|
.cart-table { table-layout: fixed; width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; font-weight: bold; }
|
|
|
|
.cart-table { table-layout: fixed; width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; font-weight: bold; }
|
|
|
|
.cart-table th { font-weight: bold; border-bottom: 2px solid #000; padding: 3px 4px; width: 25%; font-size: 14px; }
|
|
|
|
.cart-table th { font-weight: bold; border-bottom: 2px solid #000; padding: 2px; width: 25%; }
|
|
|
|
.cart-table td { padding: 3px 6px; text-align: right; font-weight: bold; font-size: 14px; }
|
|
|
|
.cart-table td { padding: 2px 4px; text-align: right; font-weight: bold; }
|
|
|
|
.cart-table td:first-child { text-align: left; }
|
|
|
|
.cart-table td:first-child { text-align: left; }
|
|
|
|
.cart-table tr.total-row { font-weight: bold; border-top: 2px solid #000; }
|
|
|
|
.cart-table tr.total-row { font-weight: bold; border-top: 2px solid #000; }
|
|
|
|
.subtotal { font-size: 15px; margin-top: 6px; }
|
|
|
|
.subtotal { font-size: 13px; margin-top: 4px; }
|
|
|
|
.subtotal .row { padding: 3px 0; }
|
|
|
|
.subtotal .row { padding: 2px 0; }
|
|
|
|
.diff-ok { color: #2e7d32; font-weight: bold; }
|
|
|
|
.diff-ok { color: #2e7d32; font-weight: bold; }
|
|
|
|
.diff-bad { color: #c0272d; font-weight: bold; }
|
|
|
|
.diff-bad { color: #c0272d; font-weight: bold; }
|
|
|
|
.obs { font-size: 13px; color: #555; margin-top: 8px; white-space: pre-wrap; font-weight: normal; }
|
|
|
|
.obs { font-size: 11px; color: #555; margin-top: 6px; white-space: pre-wrap; font-weight: normal; }
|
|
|
|
.footer { text-align: center; font-size: 13px; color: #555; margin-top: 10px; }
|
|
|
|
.footer { text-align: center; font-size: 11px; color: #555; margin-top: 8px; }
|
|
|
|
@media print { body { background: #fff; font-weight: bold !important; font-size: 17px !important; } }
|
|
|
|
@media print { body { background: #fff; font-weight: bold !important; } }
|
|
|
|
</style>
|
|
|
|
</style>
|
|
|
|
</head><body>
|
|
|
|
</head><body>
|
|
|
|
${buildPrintHTML(data)}
|
|
|
|
${buildPrintHTML(data)}
|
|
|
|