Compare commits
12 Commits
v1.4.0
...
v1.4.12-fix
| Author | SHA1 | Date | |
|---|---|---|---|
| 313c740470 | |||
| d21cb0a98d | |||
| 16bee1eacb | |||
| c8016f076d | |||
| b1a9f94231 | |||
| 42aadcca2c | |||
| a8319d96a6 | |||
| bf878545b3 | |||
| 22cda312cf | |||
| d112ad061e | |||
| be917f8fb7 | |||
| cb48afeb9c |
@@ -250,21 +250,44 @@ impl SupabaseClient {
|
|||||||
|
|
||||||
/// Atualiza campos específicos de um fechamento pelo id_fechamento.
|
/// Atualiza campos específicos de um fechamento pelo id_fechamento.
|
||||||
pub fn atualizar_fechamento(&self, id_fechamento: &str, updates: &serde_json::Value) -> Result<Value, SupabaseError> {
|
pub fn atualizar_fechamento(&self, id_fechamento: &str, updates: &serde_json::Value) -> Result<Value, SupabaseError> {
|
||||||
|
// Campos que o frontend envia mas NÃO existem como colunas na tabela.
|
||||||
|
// Arrays e objetos são guardados no JSONB `dados` — não em colunas escalar.
|
||||||
|
static BLOCKED: &[&str] = &[
|
||||||
|
"id", "uuid", "criado_em", "atualizado_em", "enviado_por",
|
||||||
|
"ip_origem", "user_agent", "id_fechamento",
|
||||||
|
// arrays e objetos que existem dentro do JSONB `dados`
|
||||||
|
"vales", "despesas", "sangrias", "cancelamentos",
|
||||||
|
"pixcnpj", "receber",
|
||||||
|
"cartoes_credito", "cartoes_debito",
|
||||||
|
"cartoes_alimentacao", "cartoes_pix",
|
||||||
|
];
|
||||||
|
|
||||||
|
let map = updates.as_object().cloned().unwrap_or_default();
|
||||||
|
|
||||||
|
// Remove campos bloqueados
|
||||||
|
let filtered: serde_json::Map<String, serde_json::Value> = map
|
||||||
|
.into_iter()
|
||||||
|
.filter(|(k, _)| !BLOCKED.contains(&k.as_str()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if filtered.is_empty() {
|
||||||
|
return Err(SupabaseError::Api("Nenhum campo para atualizar".into()));
|
||||||
|
}
|
||||||
|
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/rest/v1/fechamentos_web?id_fechamento=eq.{}",
|
"{}/rest/v1/fechamentos_web?id_fechamento=eq.{}",
|
||||||
self.base_url,
|
self.base_url,
|
||||||
urlencoding::encode(id_fechamento)
|
urlencoding::encode(id_fechamento)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Log do que está sendo enviado (debug)
|
log::info!("[PATCH] url={} body={:#?}", url, filtered);
|
||||||
log::info!("[PATCH] url={} body={}", url, updates);
|
|
||||||
|
|
||||||
let resp = self
|
let resp = self
|
||||||
.http
|
.http
|
||||||
.patch(&url)
|
.patch(&url)
|
||||||
.headers(self.headers(true))
|
.headers(self.headers(true))
|
||||||
.header("Prefer", "return=representation")
|
.header("Prefer", "return=representation")
|
||||||
.json(updates)
|
.json(&filtered)
|
||||||
.send()?;
|
.send()?;
|
||||||
|
|
||||||
let status = resp.status();
|
let status = resp.status();
|
||||||
|
|||||||
+218
-211
@@ -613,7 +613,7 @@ const fmt = v => 'R$ ' + (parseFloat(v) || 0).toLocaleString('pt-BR', { minimumF
|
|||||||
const parseNum = v => {
|
const parseNum = v => {
|
||||||
// Already a number? Return directly (don't treat '.' as thousand separator)
|
// Already a number? Return directly (don't treat '.' as thousand separator)
|
||||||
if (typeof v === 'number') return isNaN(v) ? 0 : v;
|
if (typeof v === 'number') return isNaN(v) ? 0 : v;
|
||||||
const s = String(v || '0').trim();
|
const s = String(v || '0').trim().replace(/^R\$\s*/, ''); // strip currency prefix first
|
||||||
if (!s) return 0;
|
if (!s) return 0;
|
||||||
// Brazilian format: 1.234,56 → 1234.56
|
// Brazilian format: 1.234,56 → 1234.56
|
||||||
// Strategy: if string has comma, treat as BRL (decimal comma)
|
// Strategy: if string has comma, treat as BRL (decimal comma)
|
||||||
@@ -1871,12 +1871,28 @@ function buildReciboData() {
|
|||||||
const valesTotal = estado.vales.reduce((s,r) => s+(parseNum(r.valor||0)||0), 0);
|
const valesTotal = estado.vales.reduce((s,r) => s+(parseNum(r.valor||0)||0), 0);
|
||||||
const receberTotal = estado.receber.reduce((s,r) => s+(parseNum(r.valor||0)||0), 0);
|
const receberTotal = estado.receber.reduce((s,r) => s+(parseNum(r.valor||0)||0), 0);
|
||||||
const cancelTotal = estado.cancelamentos.reduce((s,r) => s+(parseNum(r.valor||0)||0), 0);
|
const cancelTotal = estado.cancelamentos.reduce((s,r) => s+(parseNum(r.valor||0)||0), 0);
|
||||||
const fechamentoCounted = parseNum(val('f-fech-dinheiro')) + parseNum(val('f-fech-cartoes')) + parseNum(val('f-fech-receber'));
|
|
||||||
const saldoEsp = parseNum(val('f-saldo-esperado'));
|
// Lê do DOM — mas se estiver vazio usa estado (registro anterior)
|
||||||
|
const trocoDom = parseNum(val('sys-troco'));
|
||||||
|
const saldoTroco = trocoDom || estado.saldo_troco || 0;
|
||||||
|
const saldoCred = parseNum(val('sys-credito')) || cartCred;
|
||||||
|
const saldoDeb = parseNum(val('sys-debito')) || cartDeb;
|
||||||
|
const saldoAli = parseNum(val('sys-alimentacao')) || cartAli;
|
||||||
|
const saldoPixCartao = parseNum(val('sys-pix')) || cartPix;
|
||||||
|
const saldoPixCnpj = parseNum(val('sys-pixcnpj')) || pixCnpjTotal;
|
||||||
|
const saldoVales = parseNum(val('sys-vales')) || valesTotal;
|
||||||
|
const saldoReceber = parseNum(val('sys-receber')) || receberTotal;
|
||||||
|
|
||||||
|
const fechamentoDinheiro = parseNum(val('f-fech-dinheiro')) || estado.fechamento_contado?.dinheiro || 0;
|
||||||
|
const fechamentoCartoes = parseNum(val('f-fech-cartoes')) || estado.fechamento_contado?.cartoes || 0;
|
||||||
|
const fechamentoReceber = parseNum(val('f-fech-receber')) || estado.fechamento_contado?.receber || 0;
|
||||||
|
const fechamentoCounted = fechamentoDinheiro + fechamentoCartoes + fechamentoReceber;
|
||||||
|
const saldoEsperado = parseNum(val('f-saldo-esperado')) || estado.saldo_esperado || 0;
|
||||||
|
|
||||||
// Saldo de Caixa (Sistema) = troco + crédito + débito + alimentação + voucher pix + pixcnpj + vales + receber
|
// Saldo de Caixa (Sistema) = troco + crédito + débito + alimentação + voucher pix + pixcnpj + vales + receber
|
||||||
const sysTotal = parseNum(val('sys-troco')) + cartCred + cartDeb + cartAli + cartPix + pixCnpjTotal + valesTotal + receberTotal;
|
const sysTotal = saldoTroco + cartCred + cartDeb + cartAli + cartPix + pixCnpjTotal + valesTotal + receberTotal;
|
||||||
// Diferença = saldo de caixa (sistema) - saldo_esperado - cancelamentos
|
// Diferença = saldo de caixa (sistema) - saldo_esperado - cancelamentos
|
||||||
const diferenca = sysTotal - saldoEsp - cancelTotal;
|
const diferenca = sysTotal - saldoEsperado - cancelTotal;
|
||||||
return {
|
return {
|
||||||
uuid: estado.uuid,
|
uuid: estado.uuid,
|
||||||
id_local: estado.id_local,
|
id_local: estado.id_local,
|
||||||
@@ -1885,14 +1901,14 @@ function buildReciboData() {
|
|||||||
data: estado.data,
|
data: estado.data,
|
||||||
operador: estado.operador,
|
operador: estado.operador,
|
||||||
turno: estado.turno,
|
turno: estado.turno,
|
||||||
saldo_troco: parseNum(val('sys-troco')),
|
saldo_troco: saldoTroco,
|
||||||
saldo_esperado: saldoEsp,
|
saldo_esperado: saldoEsperado,
|
||||||
fechamento: fechamentoCounted,
|
fechamento: fechamentoCounted,
|
||||||
diferenca: diferenca,
|
diferenca: diferenca,
|
||||||
sys_total: sysTotal,
|
sys_total: sysTotal,
|
||||||
fechamento_dinheiro: parseNum(val('f-fech-dinheiro')),
|
fechamento_dinheiro: fechamentoDinheiro,
|
||||||
fechamento_cartoes: parseNum(val('f-fech-cartoes')),
|
fechamento_cartoes: fechamentoCartoes,
|
||||||
fechamento_receber: parseNum(val('f-fech-receber')),
|
fechamento_receber: fechamentoReceber,
|
||||||
// Flat totals for ReciboData struct (Rust) — must be numbers
|
// Flat totals for ReciboData struct (Rust) — must be numbers
|
||||||
credito: cartCred,
|
credito: cartCred,
|
||||||
debito: cartDeb,
|
debito: cartDeb,
|
||||||
@@ -2164,12 +2180,19 @@ function buildConsultaModal(recentList) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const rows = recentList.map((item, i) => {
|
const rows = recentList.map((item, i) => {
|
||||||
const total = (parseFloat(item.fechamento_dinheiro)||0) + (parseFloat(item.fechamento_cartoes)||0) + (parseFloat(item.fechamento_areceber)||0);
|
const sysTotal = (parseFloat(item.saldo_troco)||0)
|
||||||
|
+ (parseFloat(item.saldo_credito)||0)
|
||||||
|
+ (parseFloat(item.saldo_debito)||0)
|
||||||
|
+ (parseFloat(item.saldo_alimentacao)||0)
|
||||||
|
+ (parseFloat(item.saldo_vales)||0)
|
||||||
|
+ (parseFloat(item.saldo_areceber)||0)
|
||||||
|
+ (parseFloat(item.total_pixcnpj)||0)
|
||||||
|
+ (parseFloat(item.total_cartao_pix)||0);
|
||||||
return `<tr>
|
return `<tr>
|
||||||
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtDate(item.data)}</td>
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtDate(item.data)}</td>
|
||||||
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${item.operador||'?'}</td>
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${item.operador||'?'}</td>
|
||||||
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${item.turno||'?'}</td>
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${item.turno||'?'}</td>
|
||||||
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtMoney(total)}</td>
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtMoney(sysTotal)}</td>
|
||||||
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtMoney(item.saldo_esperado)}</td>
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;text-align:right;cursor:pointer" onclick="openConsultaRegistro(${i})">${fmtMoney(item.saldo_esperado)}</td>
|
||||||
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${statusBadge(item.status_diferenca)}</td>
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${statusBadge(item.status_diferenca)}</td>
|
||||||
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${syncBadge(item.sync_status)}</td>
|
<td style="padding:6px 8px;border-bottom:1px solid #eee;font-size:12px;cursor:pointer" onclick="openConsultaRegistro(${i})">${syncBadge(item.sync_status)}</td>
|
||||||
@@ -2192,7 +2215,7 @@ function buildConsultaModal(recentList) {
|
|||||||
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">DATA</th>
|
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">DATA</th>
|
||||||
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">OPERADOR</th>
|
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">OPERADOR</th>
|
||||||
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">TURNO</th>
|
<th style="padding:6px 8px;text-align:left;font-size:11px;color:#888">TURNO</th>
|
||||||
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">FECHAMENTO</th>
|
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">SALDO CAIXA</th>
|
||||||
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">ESPERADO</th>
|
<th style="padding:6px 8px;text-align:right;font-size:11px;color:#888">ESPERADO</th>
|
||||||
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">STATUS</th>
|
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">STATUS</th>
|
||||||
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">SYNC</th>
|
<th style="padding:6px 8px;text-align:center;font-size:11px;color:#888">SYNC</th>
|
||||||
@@ -2672,6 +2695,7 @@ window._recalcEditTotals = function() {
|
|||||||
const el = id => document.getElementById(id);
|
const el = id => document.getElementById(id);
|
||||||
const fmtTot = v => v > 0 ? 'R$ ' + v.toLocaleString('pt-BR', { minimumFractionDigits: 2 }) : '—';
|
const fmtTot = v => v > 0 ? 'R$ ' + v.toLocaleString('pt-BR', { minimumFractionDigits: 2 }) : '—';
|
||||||
|
|
||||||
|
// Atualiza spans do total-box (prefixo "edit-total-") E do resumo rápido (prefixo "tot-")
|
||||||
if (el('edit-total-credito')) el('edit-total-credito').textContent = fmtTot(cartCred_tot);
|
if (el('edit-total-credito')) el('edit-total-credito').textContent = fmtTot(cartCred_tot);
|
||||||
if (el('edit-total-debito')) el('edit-total-debito').textContent = fmtTot(cartDeb_tot);
|
if (el('edit-total-debito')) el('edit-total-debito').textContent = fmtTot(cartDeb_tot);
|
||||||
if (el('edit-total-alimentacao')) el('edit-total-alimentacao').textContent = fmtTot(cartAli_tot);
|
if (el('edit-total-alimentacao')) el('edit-total-alimentacao').textContent = fmtTot(cartAli_tot);
|
||||||
@@ -2679,9 +2703,20 @@ window._recalcEditTotals = function() {
|
|||||||
if (el('edit-total-vales')) el('edit-total-vales').textContent = fmtTot(vales_tot);
|
if (el('edit-total-vales')) el('edit-total-vales').textContent = fmtTot(vales_tot);
|
||||||
if (el('edit-total-despesas')) el('edit-total-despesas').textContent = fmtTot(desp_tot);
|
if (el('edit-total-despesas')) el('edit-total-despesas').textContent = fmtTot(desp_tot);
|
||||||
if (el('edit-total-sangrias')) el('edit-total-sangrias').textContent = fmtTot(sang_tot);
|
if (el('edit-total-sangrias')) el('edit-total-sangrias').textContent = fmtTot(sang_tot);
|
||||||
if (el('edit-total-pixcnpj')) el('edit-total-pixcnpj').textContent = fmtTot(pixcnpj_tot);
|
if (el('edit-total-pixcnpj')) el('edit-total-pixcnpj').textContent = fmtTot(pixcnpj_tot);
|
||||||
if (el('edit-total-receber')) el('edit-total-receber').textContent = fmtTot(recv_tot);
|
if (el('edit-total-receber')) el('edit-total-receber').textContent = fmtTot(recv_tot);
|
||||||
if (el('edit-total-cancel')) el('edit-total-cancel').textContent = fmtTot(canc_tot);
|
if (el('edit-total-cancel')) el('edit-total-cancel').textContent = fmtTot(canc_tot);
|
||||||
|
// Atualiza também os spans do total-box da popup (prefixo "tot-")
|
||||||
|
if (el('tot-credito')) el('tot-credito').textContent = fmtTot(cartCred_tot);
|
||||||
|
if (el('tot-debito')) el('tot-debito').textContent = fmtTot(cartDeb_tot);
|
||||||
|
if (el('tot-ali')) el('tot-ali').textContent = fmtTot(cartAli_tot);
|
||||||
|
if (el('tot-pix')) el('tot-pix').textContent = fmtTot(cartPix_tot);
|
||||||
|
if (el('tot-pixcnpj')) el('tot-pixcnpj').textContent = fmtTot(pixcnpj_tot);
|
||||||
|
if (el('tot-vales')) el('tot-vales').textContent = fmtTot(vales_tot);
|
||||||
|
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Modal de edição completo com todas as grades
|
// Modal de edição completo com todas as grades
|
||||||
@@ -2695,7 +2730,8 @@ function openEditModal(full) {
|
|||||||
// helper para fmt dinheiro
|
// helper para fmt dinheiro
|
||||||
const fmtMR = v => {
|
const fmtMR = v => {
|
||||||
const n = parseFloat(v||0);
|
const n = parseFloat(v||0);
|
||||||
if (isNaN(n) || n === 0) return '';
|
if (isNaN(n)) return '';
|
||||||
|
if (n === 0) return 'R$ 0,00';
|
||||||
return 'R$ ' + n.toLocaleString('pt-BR', { minimumFractionDigits: 2 });
|
return 'R$ ' + n.toLocaleString('pt-BR', { minimumFractionDigits: 2 });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2742,20 +2778,32 @@ function openEditModal(full) {
|
|||||||
const receber_rows = (dados.receber || []).map(r => [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) — calcula dos dados reais ---
|
||||||
const totaisInfo = `
|
const totaisInfo = (() => {
|
||||||
|
const calcCred = (dados.cartoes?.credito || full.cartoes_credito || []).reduce((s,r) => s+(parseFloat(typeof r==='object'?r.valor:r)||0), 0);
|
||||||
|
const calcDeb = (dados.cartoes?.debito || full.cartoes_debito || []).reduce((s,r) => s+(parseFloat(typeof r==='object'?r.valor:r)||0), 0);
|
||||||
|
const calcAli = (dados.cartoes?.alimentacao || full.cartoes_alimentacao || []).reduce((s,r) => s+(parseFloat(typeof r==='object'?r.valor:r)||0), 0);
|
||||||
|
const calcPix = (dados.cartoes?.pix || full.cartoes_pix || []).reduce((s,r) => s+(parseFloat(typeof r==='object'?r.valor:r)||0), 0);
|
||||||
|
const calcSang = (dados.sangrias || []).reduce((s,r) => s+(parseFloat(r.retirada||r.valor||0)||0), 0);
|
||||||
|
const calcDesp = (dados.despesas || []).reduce((s,r) => s+(parseFloat(r.valor||0)||0), 0);
|
||||||
|
const calcVales = (dados.vales || []).reduce((s,r) => s+(parseFloat(r.valor||0)||0), 0);
|
||||||
|
const calcPixCnpj = (dados.pixcnpj || []).reduce((s,r) => s+(parseFloat(r.valor||0)||0), 0);
|
||||||
|
const calcRecv = (dados.receber || []).reduce((s,r) => s+(parseFloat(r.valor||0)||0), 0);
|
||||||
|
const calcCanc = (dados.cancelamentos || []).reduce((s,r) => s+(parseFloat(r.valor||0)||0), 0);
|
||||||
|
return `
|
||||||
<div style="display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:4px;background:#f5f5f5;border-radius:6px;padding:8px;margin-bottom:8px;font-size:11px">
|
<div style="display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:4px;background:#f5f5f5;border-radius:6px;padding:8px;margin-bottom:8px;font-size:11px">
|
||||||
<div><strong>Total Crédito:</strong> <span id="edit-total-credito">${fmtMR(full.total_cartao_credito||0)}</span></div>
|
<div><strong>Total Crédito:</strong> <span id="edit-total-credito">${fmtMR(calcCred)}</span></div>
|
||||||
<div><strong>Total Débito:</strong> <span id="edit-total-debito">${fmtMR(full.total_cartao_debito||0)}</span></div>
|
<div><strong>Total Débito:</strong> <span id="edit-total-debito">${fmtMR(calcDeb)}</span></div>
|
||||||
<div><strong>Total Alimentação:</strong> <span id="edit-total-alimentacao">${fmtMR(full.total_cartao_alimentacao||0)}</span></div>
|
<div><strong>Total Alimentação:</strong> <span id="edit-total-alimentacao">${fmtMR(calcAli)}</span></div>
|
||||||
<div><strong>Total PIX:</strong> <span id="edit-total-pix">${fmtMR(full.total_cartao_pix||0)}</span></div>
|
<div><strong>Total PIX:</strong> <span id="edit-total-pix">${fmtMR(calcPix)}</span></div>
|
||||||
<div><strong>Total Sangrias:</strong> <span id="edit-total-sangrias">${fmtMR(full.total_sangrias||0)}</span></div>
|
<div><strong>Total Sangrias:</strong> <span id="edit-total-sangrias">${fmtMR(calcSang)}</span></div>
|
||||||
<div><strong>Total Despesas:</strong> <span id="edit-total-despesas">${fmtMR(full.total_despesas||0)}</span></div>
|
<div><strong>Total Despesas:</strong> <span id="edit-total-despesas">${fmtMR(calcDesp)}</span></div>
|
||||||
<div><strong>Total Vales:</strong> <span id="edit-total-vales">${fmtMR(full.total_vales||0)}</span></div>
|
<div><strong>Total Vales:</strong> <span id="edit-total-vales">${fmtMR(calcVales)}</span></div>
|
||||||
<div><strong>Total PIX CNPJ:</strong> <span id="edit-total-pixcnpj">${fmtMR(full.total_pixcnpj||0)}</span></div>
|
<div><strong>Total PIX CNPJ:</strong> <span id="edit-total-pixcnpj">${fmtMR(calcPixCnpj)}</span></div>
|
||||||
<div><strong>Total Receber:</strong> <span id="edit-total-receber">${fmtMR(full.total_areceber||0)}</span></div>
|
<div><strong>Total Receber:</strong> <span id="edit-total-receber">${fmtMR(calcRecv)}</span></div>
|
||||||
<div><strong>Total Cancel:</strong> <span id="edit-total-cancel">${fmtMR(full.total_cancelamentos||0)}</span></div>
|
<div><strong>Total Cancel:</strong> <span id="edit-total-cancel">${fmtMR(calcCanc)}</span></div>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
})();
|
||||||
|
|
||||||
const overlay = document.createElement('div');
|
const overlay = document.createElement('div');
|
||||||
overlay.id = 'modal-edit';
|
overlay.id = 'modal-edit';
|
||||||
@@ -2924,7 +2972,8 @@ function openEditModal(full) {
|
|||||||
// Formata campo de dinheiro brasileiro
|
// Formata campo de dinheiro brasileiro
|
||||||
function fmtBR(inp) {
|
function fmtBR(inp) {
|
||||||
const v = parseNum(inp.value);
|
const v = parseNum(inp.value);
|
||||||
if (isNaN(v) || v === 0) return '';
|
if (isNaN(v)) return '';
|
||||||
|
if (v === 0) return 'R$ 0,00';
|
||||||
return 'R$ ' + v.toLocaleString('pt-BR', { minimumFractionDigits: 2 });
|
return 'R$ ' + v.toLocaleString('pt-BR', { minimumFractionDigits: 2 });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2935,185 +2984,93 @@ function closeEditModal() {
|
|||||||
window._editModalOpen = false;
|
window._editModalOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Janela separada para edição completa ───────────────────────────────────
|
// ─── Janela de edição completa (usa modal interno, não popup) ─────────────────
|
||||||
// Abre uma nova janela (window.open) com HTML inline pré-preenchido com todos
|
// Reaproveita openEditModal que já tem todas as tabelas editáveis,
|
||||||
// os dados do registro. Permite editar todos os campos e salvar via
|
// grades de cartões/vales/despesas/sangrias/pixcnjp/receber/cancelamentos,
|
||||||
// sb_atualizar_fechamento. O botão Cancelar fecha a janela.
|
// e conexão Tauri funcionando. Apenas pré-preenche o registro e abre.
|
||||||
window.abrirEditaFechamento = async function(full) {
|
window.abrirEditaFechamento = async function(full) {
|
||||||
if (!full) { alert('Registro não fornecido.'); return; }
|
if (!full) { alert('Registro não fornecido.'); return; }
|
||||||
|
// Garante id_fechamento
|
||||||
// Serializa o registro para passar à popup — usa JSON para preservar tudo
|
if (!full.id_fechamento && full.loja && full.data && full.operador) {
|
||||||
const encoded = encodeURIComponent(JSON.stringify(full));
|
full.id_fechamento = (full.loja + '_' + full.data + '_' + full.operador).toLowerCase().replace(/ /g, '_');
|
||||||
|
|
||||||
const html = `<!DOCTYPE html>
|
|
||||||
<html lang="pt-BR">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Editar Fechamento — ${(full.data||'').substring(0,10)} ${full.operador||''}</title>
|
|
||||||
<style>
|
|
||||||
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
|
||||||
body{font-family:'Segoe UI',system-ui,sans-serif;background:#f7f7f7;padding:16px;font-size:13px}
|
|
||||||
h2{background:linear-gradient(135deg,#bf360c,#e65100);color:#fff;padding:10px 16px;border-radius:8px 8px 0 0;margin:-16px -16px 16px;font-size:15px}
|
|
||||||
.linha{margin-bottom:12px}
|
|
||||||
.linha label{display:block;font-size:10px;color:#555;margin-bottom:2px;font-weight:700;text-transform:uppercase}
|
|
||||||
.linha input,.linha select,.linha textarea{width:100%;padding:6px 8px;border:1px solid #ccc;border-radius:4px;font-size:13px;font-family:inherit}
|
|
||||||
.linha input[readonly]{background:#eee;color:#666;border-color:#ddd}
|
|
||||||
.linha input[type=number]{text-align:right}
|
|
||||||
.secao{background:#fff;border-radius:8px;padding:12px;margin-bottom:12px;box-shadow:0 1px 4px rgba(0,0,0,.08)}
|
|
||||||
.secao-titulo{font-size:11px;font-weight:700;color:#e65100;text-transform:uppercase;letter-spacing:.5px;margin-bottom:8px;padding-bottom:4px;border-bottom:2px solid #e65100}
|
|
||||||
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:8px}
|
|
||||||
.grid3{display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px}
|
|
||||||
.grid4{display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:6px}
|
|
||||||
table{width:100%;border-collapse:collapse;font-size:12px}
|
|
||||||
th{background:#f0f0f0;font-size:10px;text-transform:uppercase;color:#777;padding:4px 6px;text-align:left}
|
|
||||||
td{padding:2px 4px;border-bottom:1px solid #eee}
|
|
||||||
td input{width:100%;padding:4px 2px;border:1px solid #ccc;border-radius:3px;font-size:12px}
|
|
||||||
td input[type=number],td input.num{text-align:right}
|
|
||||||
.btn-row{display:flex;gap:8px;flex-wrap:wrap}
|
|
||||||
.btn-row button{flex:1;padding:10px;border:none;border-radius:6px;cursor:pointer;font-size:13px;font-weight:700}
|
|
||||||
.btn-salvar{background:#2e7d32;color:#fff}
|
|
||||||
.btn-cancelar{background:#888;color:#fff}
|
|
||||||
.total-box{background:#fff8e1;border-radius:6px;padding:8px;margin-bottom:8px;font-size:11px;display:grid;grid-template-columns:repeat(3,1fr);gap:4px}
|
|
||||||
.total-box span{display:block}
|
|
||||||
.total-box strong{color:#e65100}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h2>✏️ Editar Fechamento — ${(full.loja||'').toUpperCase()} · ${(full.data||'').substring(0,10)} · ${full.operador||''}</h2>
|
|
||||||
|
|
||||||
<!-- Identificação -->
|
|
||||||
<div class="secao">
|
|
||||||
<div class="secao-titulo">Identificação</div>
|
|
||||||
<div class="grid4">
|
|
||||||
<div class="linha"><label>Data</label><input type="date" id="f-data" value="${full.data||''}"></div>
|
|
||||||
<div class="linha"><label>Loja</label>
|
|
||||||
<select id="f-loja"><option value="alianca" ${(full.loja||'').toLowerCase()==='alianca'?'selected':''}>Aliança</option><option value="uniao" ${(full.loja||'').toLowerCase()==='uniao'?'selected':''}>União</option></select>
|
|
||||||
</div>
|
|
||||||
<div class="linha"><label>Turno</label>
|
|
||||||
<select id="f-turno"><option value="manha" ${(full.turno||'')==='manha'?'selected':''}>Manhã</option><option value="tarde" ${(full.turno||'')==='tarde'?'selected':''}>Tarde</option><option value="integral" ${(full.turno||'')==='integral'?'selected':''}>Integral</option></select>
|
|
||||||
</div>
|
|
||||||
<div class="linha"><label>Operador</label><input type="text" id="f-operador" value="${full.operador||''}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Totais (readonly) -->
|
|
||||||
<div class="total-box">
|
|
||||||
<span><strong>Crédito:</strong> <span id="tot-credito">R$ ${parseFloat(full.total_cartao_credito||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
||||||
<span><strong>Débito:</strong> <span id="tot-debito">R$ ${parseFloat(full.total_cartao_debito||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
||||||
<span><strong>Alimentação:</strong> <span id="tot-ali">R$ ${parseFloat(full.total_cartao_alimentacao||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
||||||
<span><strong>PIX:</strong> <span id="tot-pix">R$ ${parseFloat(full.total_cartao_pix||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
||||||
<span><strong>PIX CNPJ:</strong> <span id="tot-pixcnpj">R$ ${parseFloat(full.total_pixcnpj||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
||||||
<span><strong>Vales:</strong> <span id="tot-vales">R$ ${parseFloat(full.total_vales||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
||||||
<span><strong>A Receber:</strong> <span id="tot-areceber">R$ ${parseFloat(full.total_areceber||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
||||||
<span><strong>Sangrias:</strong> <span id="tot-sangrias">R$ ${parseFloat(full.total_sangrias||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
||||||
<span><strong>Despesas:</strong> <span id="tot-despesas">R$ ${parseFloat(full.total_despesas||0).toLocaleString('pt-BR',{minimumFractionDigits:2})}</span></span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Saldo de Caixa -->
|
|
||||||
<div class="secao">
|
|
||||||
<div class="secao-titulo">💰 Saldo de Caixa</div>
|
|
||||||
<div class="grid4">
|
|
||||||
<div class="linha"><label>Troco (R$)</label><input type="number" step="0.01" id="f-saldo_troco" value="${parseFloat(full.saldo_troco||0)}"></div>
|
|
||||||
<div class="linha"><label>Crédito (R$)</label><input type="number" step="0.01" id="f-saldo_credito" value="${parseFloat(full.saldo_credito||0)}"></div>
|
|
||||||
<div class="linha"><label>Débito (R$)</label><input type="number" step="0.01" id="f-saldo_debito" value="${parseFloat(full.saldo_debito||0)}"></div>
|
|
||||||
<div class="linha"><label>Alimentação (R$)</label><input type="number" step="0.01" id="f-saldo_alimentacao" value="${parseFloat(full.saldo_alimentacao||0)}"></div>
|
|
||||||
<div class="linha"><label>Vales (R$)</label><input type="number" step="0.01" id="f-saldo_vales" value="${parseFloat(full.saldo_vales||0)}"></div>
|
|
||||||
<div class="linha"><label>PIX Cartão (R$)</label><input type="number" step="0.01" id="f-total_cartao_pix" value="${parseFloat(full.total_cartao_pix||0)}"></div>
|
|
||||||
<div class="linha"><label>PIX CNPJ (R$)</label><input type="number" step="0.01" id="f-total_pixcnpj" value="${parseFloat(full.total_pixcnpj||0)}"></div>
|
|
||||||
<div class="linha"><label>A Receber (R$)</label><input type="number" step="0.01" id="f-saldo_areceber" value="${parseFloat(full.saldo_areceber||0)}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Fechamento Contado -->
|
|
||||||
<div class="secao">
|
|
||||||
<div class="secao-titulo">📦 Fechamento Contado</div>
|
|
||||||
<div class="grid3">
|
|
||||||
<div class="linha"><label>Dinheiro (R$)</label><input type="number" step="0.01" id="f-fechamento_dinheiro" value="${parseFloat(full.fechamento_dinheiro||0)}"></div>
|
|
||||||
<div class="linha"><label>Cartões (R$)</label><input type="number" step="0.01" id="f-fechamento_cartoes" value="${parseFloat(full.fechamento_cartoes||0)}"></div>
|
|
||||||
<div class="linha"><label>A Receber (R$)</label><input type="number" step="0.01" id="f-fechamento_areceber" value="${parseFloat(full.fechamento_areceber||0)}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Dados operacionais -->
|
|
||||||
<div class="secao">
|
|
||||||
<div class="secao-titulo">📊 Dados Operacionais</div>
|
|
||||||
<div class="grid4">
|
|
||||||
<div class="linha"><label>Clientes</label><input type="number" id="f-clientes" value="${parseInt(full.clientes||0)}"></div>
|
|
||||||
<div class="linha"><label>Frango Assado</label><input type="number" id="f-frango" value="${parseInt(full.frango||0)}"></div>
|
|
||||||
<div class="linha"><label>Vendas (R$)</label><input type="number" step="0.01" id="f-vendas" value="${parseFloat(full.vendas||0)}"></div>
|
|
||||||
<div class="linha"><label>Saldo Esperado (R$)</label><input type="number" step="0.01" id="f-saldo_esperado" value="${parseFloat(full.saldo_esperado||0)}"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Observações -->
|
|
||||||
<div class="secao">
|
|
||||||
<div class="linha"><label>Observações</label><textarea id="f-observacoes" rows="3">${(full.observacoes||'').replace(/`/g,'`').replace(/</g,'<').replace(/>/g,'>')}</textarea></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Botões -->
|
|
||||||
<div class="btn-row">
|
|
||||||
<button class="btn-salvar" onclick="salvar()">💾 Salvar Alterações</button>
|
|
||||||
<button class="btn-cancelar" onclick="window.close()">Cancelar</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
var _rec = null;
|
|
||||||
try { _rec = JSON.parse(decodeURIComponent('${encoded}')); } catch(e) { console.error(e); }
|
|
||||||
|
|
||||||
function num(v) { return parseFloat((v||'0').toString().replace(',','.')) || 0; }
|
|
||||||
function inp(id) { var el = document.getElementById(id); return el ? el.value : ''; }
|
|
||||||
|
|
||||||
async function salvar() {
|
|
||||||
if (!window.__TAURI__ || !window.__TAURI__.core) {
|
|
||||||
alert('Tauri não disponível nesta janela.'); return;
|
|
||||||
}
|
}
|
||||||
var updates = {
|
|
||||||
data: inp('f-data'),
|
// Atualiza estado com o registro carregado para que buildReciboData funcione corretamente
|
||||||
loja: inp('f-loja'),
|
const dados = full.dados || {};
|
||||||
turno: inp('f-turno'),
|
estado = {
|
||||||
operador: inp('f-operador'),
|
uuid: full.uuid || crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(),
|
||||||
saldo_troco: num(inp('f-saldo_troco')),
|
id_local: full.id_local || null,
|
||||||
saldo_credito: num(inp('f-saldo_credito')),
|
id: full.id || null,
|
||||||
saldo_debito: num(inp('f-saldo_debito')),
|
loja: full.loja || estado.loja,
|
||||||
saldo_alimentacao: num(inp('f-saldo_alimentacao')),
|
data: full.data || estado.data,
|
||||||
saldo_vales: num(inp('f-saldo_vales')),
|
operador: full.operador || '',
|
||||||
saldo_areceber: num(inp('f-saldo_areceber')),
|
turno: full.turno || 'manha',
|
||||||
total_cartao_pix: num(inp('f-total_cartao_pix')),
|
saldo_troco: parseNum(full.saldo_troco || 0),
|
||||||
total_pixcnpj: num(inp('f-total_pixcnpj')),
|
fechamento: parseNum(full.fechamento_dinheiro || 0) + parseNum(full.fechamento_cartoes || 0) + parseNum(full.fechamento_areceber || 0),
|
||||||
fechamento_dinheiro: num(inp('f-fechamento_dinheiro')),
|
saldo_esperado: parseNum(full.saldo_esperado || 0),
|
||||||
fechamento_cartoes: num(inp('f-fechamento_cartoes')),
|
diferenca: parseNum(full.diferenca || 0),
|
||||||
fechamento_areceber: num(inp('f-fechamento_areceber')),
|
clientes: parseInt(full.clientes || 0),
|
||||||
clientes: parseInt(inp('f-clientes')||'0'),
|
frango: parseInt(full.frango || 0),
|
||||||
frango: parseInt(inp('f-frango')||'0'),
|
vendas: parseNum(full.vendas || 0),
|
||||||
vendas: num(inp('f-vendas')),
|
observacoes: full.observacoes || '',
|
||||||
saldo_esperado: num(inp('f-saldo_esperado')),
|
sync_status: full.sync_status || 'synced',
|
||||||
observacoes: inp('f-observacoes')
|
// Cartões
|
||||||
|
cartoes: {
|
||||||
|
credito: (dados.cartoes?.credito || full.cartoes_credito || []).map(v => ({ valor: parseNum(v) || 0 })),
|
||||||
|
debito: (dados.cartoes?.debito || full.cartoes_debito || []).map(v => ({ valor: parseNum(v) || 0 })),
|
||||||
|
alimentacao: (dados.cartoes?.alimentacao || full.cartoes_alimentacao || []).map(v => ({ valor: parseNum(v) || 0 })),
|
||||||
|
pix: (dados.cartoes?.pix || full.cartoes_pix || []).map(v => ({ valor: parseNum(v) || 0 })),
|
||||||
|
},
|
||||||
|
// Demais arrays
|
||||||
|
vales: (dados.vales || full.vales || []).map(r => ({ nome: r.nome||'', valor: parseNum(r.valor)||0, obs: r.obs||'' })),
|
||||||
|
despesas: (dados.despesas || full.despesas || []).map(r => ({ desc: r.desc||'', obs: r.obs||'', valor: parseNum(r.valor)||0 })),
|
||||||
|
sangrias: (dados.sangrias || full.sangrias || []).map(r => ({ hora: r.hora||'', retirada: parseNum(r.retirada||r.valor)||0, gerente: r.gerente||'' })),
|
||||||
|
cancelamentos: (dados.cancelamentos || full.cancelamentos || []).map(r => ({ numero: r.numero||'', valor: parseNum(r.valor)||0, motivo: r.motivo||'' })),
|
||||||
|
pixcnpj: (dados.pixcnpj || full.pixcnpj || []).map(r => ({ nome: r.nome||'', valor: parseNum(r.valor)||0 })),
|
||||||
|
receber: (dados.receber || full.receber || []).map(r => ({ nome: r.nome||'', valor: parseNum(r.valor)||0 })),
|
||||||
|
fechamento_contado: {
|
||||||
|
dinheiro: parseNum(full.fechamento_dinheiro || 0),
|
||||||
|
cartoes: parseNum(full.fechamento_cartoes || 0),
|
||||||
|
receber: parseNum(full.fechamento_areceber || 0),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// id_fechamento = chave natural do registro
|
// Preenche os campos do formulário principal para que o botão Recibo funcione
|
||||||
var id_fechamento = _rec && _rec.id_fechamento ? _rec.id_fechamento
|
setVal('sys-troco', fmtNum(estado.saldo_troco));
|
||||||
: (inp('f-loja') + '_' + inp('f-data') + '_' + inp('f-operador')).toLowerCase().replace(/ /g,'_');
|
setVal('sys-credito', fmtNum(estado.saldo_credito));
|
||||||
|
setVal('sys-debito', fmtNum(estado.saldo_debito));
|
||||||
|
setVal('sys-alimentacao', fmtNum(estado.saldo_alimentacao));
|
||||||
|
setVal('sys-pixcnpj', fmtNum(estado.total_pixcnpj));
|
||||||
|
setVal('f-saldo-esperado', estado.saldo_esperado || '');
|
||||||
|
setVal('f-obs', estado.observacoes || '');
|
||||||
|
setVal('f-operador', estado.operador || '');
|
||||||
|
setVal('f-turno', estado.turno || '');
|
||||||
|
setVal('f-clientes', estado.clientes || '');
|
||||||
|
setVal('f-frango', estado.frango || '');
|
||||||
|
setVal('f-vendas', estado.vendas || '');
|
||||||
|
setVal('f-loja', estado.loja || '');
|
||||||
|
setVal('f-data', estado.data || '');
|
||||||
|
setVal('f-fech-dinheiro', estado.fechamento_contado?.dinheiro || '');
|
||||||
|
setVal('f-fech-cartoes', estado.fechamento_contado?.cartoes || '');
|
||||||
|
setVal('f-fech-receber', estado.fechamento_contado?.receber || '');
|
||||||
|
|
||||||
try {
|
// Renderiza todas as grades
|
||||||
var idFech = inp('f-loja') + '_' + inp('f-data') + '_' + inp('f-operador');
|
renderTable('tbl-sangrias', estado.sangrias);
|
||||||
idFech = idFech.toLowerCase().replace(/ /g, '_');
|
renderTable('tbl-despesas', estado.despesas);
|
||||||
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id_fechamento: idFech, updates: JSON.stringify(updates) });
|
renderTable('tbl-vales', estado.vales);
|
||||||
alert('✅ Atualizado com sucesso!');
|
renderTable('tbl-pix', estado.pixcnpj);
|
||||||
if (window.opener && window.opener.location) { try { window.opener.location.reload(); } catch(e){} }
|
renderTable('tbl-receber', estado.receber);
|
||||||
window.close();
|
renderTable('tbl-cancelamentos', estado.cancelamentos);
|
||||||
} catch(e) {
|
renderTable('tbl-cartao-credito', estado.cartoes.credito);
|
||||||
console.error(e);
|
renderTable('tbl-cartao-debito', estado.cartoes.debito);
|
||||||
alert('Erro ao salvar: ' + (e.message||e));
|
renderTable('tbl-cartao-alimentacao',estado.cartoes.alimentacao);
|
||||||
}
|
renderTable('tbl-cartao-pix', estado.cartoes.pix);
|
||||||
}
|
|
||||||
<\/script>
|
|
||||||
</body>
|
|
||||||
</html>`;
|
|
||||||
|
|
||||||
var win = window.open('', '_blank', 'width=720,height=' + screen.availHeight + ',scrollbars=yes,resizable=yes');
|
// Atualiza totais
|
||||||
if (!win) { alert('Bloqueador de popup detectado. Permita popups para este site.'); return; }
|
updateTotals();
|
||||||
win.document.write(html);
|
|
||||||
win.document.close();
|
// Usa o mesmo modal de edição completo que já funciona — só abre com o registro
|
||||||
|
openEditModal(full);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Salva edições do modal de edição completo
|
// Salva edições do modal de edição completo
|
||||||
@@ -3187,23 +3144,71 @@ window.salvarEdicaoModal = async function() {
|
|||||||
saldo_debito: cartDeb_tot,
|
saldo_debito: cartDeb_tot,
|
||||||
saldo_alimentacao: cartAli_tot,
|
saldo_alimentacao: cartAli_tot,
|
||||||
saldo_vales: vales_tot,
|
saldo_vales: vales_tot,
|
||||||
total_pixcnpj: pixcnpj_tot,
|
|
||||||
saldo_areceber: recv_tot,
|
saldo_areceber: recv_tot,
|
||||||
|
|
||||||
// Totais
|
// Totais
|
||||||
total_vales: vales_tot,
|
total_vales: vales_tot,
|
||||||
total_despesas: desp_tot,
|
total_despesas: desp_tot,
|
||||||
total_sangrias: sang_tot,
|
total_sangrias: sang_tot,
|
||||||
total_areceber: recv_tot,
|
total_pixcnpj: pixcnpj_tot,
|
||||||
|
total_areceber: recv_tot,
|
||||||
total_cancelamentos: canc_tot,
|
total_cancelamentos: canc_tot,
|
||||||
|
|
||||||
// Lançamentos detalhados
|
// Fechamento (campos calculados que o formato antigo usava no dados)
|
||||||
vales: vales,
|
fechamento_dinheiro: p(inp('edit-troco')) + vales_tot + sang_tot - desp_tot - canc_tot,
|
||||||
despesas: despesas,
|
fechamento_cartoes: cartCred_tot + cartDeb_tot + cartAli_tot + cartPix_tot,
|
||||||
sangrias: sangrias,
|
fechamento_areceber: recv_tot,
|
||||||
cancelamentos: cancelamentos,
|
|
||||||
pixcnpj: pixcnpj,
|
// Lançamentos detalhados (JSONB — gravados no campo `dados`)
|
||||||
receber: receber,
|
// Merge completo com dados existentes para preservar campos antigos (fc, fd, fr,
|
||||||
|
// uuid, id_local, sync_status, fechamento, etc.) e sobrepor com valores atuais.
|
||||||
|
dados: (() => {
|
||||||
|
const existing = full.dados;
|
||||||
|
const base = {
|
||||||
|
cartoes,
|
||||||
|
vales,
|
||||||
|
despesas,
|
||||||
|
sangrias,
|
||||||
|
cancelamentos,
|
||||||
|
pixcnpj,
|
||||||
|
receber,
|
||||||
|
clientes: parseInt(inp('edit-clientes') || '0'),
|
||||||
|
frango: parseInt(inp('edit-frango') || '0'),
|
||||||
|
vendas: p(inp('edit-vendas')),
|
||||||
|
// Campos que o formato antigo gravava no dados
|
||||||
|
credito: cartCred_tot,
|
||||||
|
debito: cartDeb_tot,
|
||||||
|
alimentacao: cartAli_tot,
|
||||||
|
fc: cartCred_tot + cartDeb_tot + cartAli_tot + cartPix_tot,
|
||||||
|
fd: sang_tot,
|
||||||
|
fr: vales_tot,
|
||||||
|
fechamento: p(inp('edit-troco')) + vales_tot + sang_tot - desp_tot - canc_tot,
|
||||||
|
saldo_troco: p(inp('edit-troco')),
|
||||||
|
total_vales: vales_tot,
|
||||||
|
total_despesas: desp_tot,
|
||||||
|
total_sangrias: sang_tot,
|
||||||
|
total_pixcnpj: pixcnpj_tot,
|
||||||
|
total_areceber: recv_tot,
|
||||||
|
total_cancelamentos: canc_tot,
|
||||||
|
total_cartao_credito: cartCred_tot,
|
||||||
|
total_cartao_debito: cartDeb_tot,
|
||||||
|
total_cartao_alimentacao: cartAli_tot,
|
||||||
|
total_cartao_pix: cartPix_tot,
|
||||||
|
saldo_esperado: p(inp('edit-esperado')),
|
||||||
|
observacoes: inp('edit-obs') || '',
|
||||||
|
data: inp('edit-data') || full.data || '',
|
||||||
|
loja: inp('edit-loja') || full.loja || '',
|
||||||
|
turno: inp('edit-turno') || full.turno || '',
|
||||||
|
operador: inp('edit-operador') || full.operador || '',
|
||||||
|
};
|
||||||
|
if (typeof existing === 'string') {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(existing);
|
||||||
|
return { ...parsed, ...base };
|
||||||
|
} catch { return base; }
|
||||||
|
}
|
||||||
|
return { ...(existing || {}), ...base };
|
||||||
|
})(),
|
||||||
|
|
||||||
// Contadores
|
// Contadores
|
||||||
clientes: parseInt(inp('edit-clientes') || '0'),
|
clientes: parseInt(inp('edit-clientes') || '0'),
|
||||||
@@ -3231,7 +3236,7 @@ window.salvarEdicaoModal = async function() {
|
|||||||
console.log('[DEBUG] salvarEdicaoModal id_fechamento:', id_fechamento, 'updates:', JSON.stringify(updates));
|
console.log('[DEBUG] salvarEdicaoModal id_fechamento:', id_fechamento, 'updates:', JSON.stringify(updates));
|
||||||
|
|
||||||
console.log('[DEBUG] invoking sb_atualizar_fechamento...');
|
console.log('[DEBUG] invoking sb_atualizar_fechamento...');
|
||||||
const result = await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id_fechamento, updates: JSON.stringify(updates) });
|
const result = await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id_fechamento, updates });
|
||||||
console.log('[DEBUG] invoke result:', result);
|
console.log('[DEBUG] invoke result:', result);
|
||||||
closeEditModal();
|
closeEditModal();
|
||||||
closeRelatorioModal();
|
closeRelatorioModal();
|
||||||
@@ -3268,7 +3273,9 @@ window.salvarEdicaoConsulta = async function() {
|
|||||||
frango: parseInt(inp('edit-frango') || '0'),
|
frango: parseInt(inp('edit-frango') || '0'),
|
||||||
vendas: p(inp('edit-vendas')),
|
vendas: p(inp('edit-vendas')),
|
||||||
saldo_esperado: p(inp('edit-esperado')),
|
saldo_esperado: p(inp('edit-esperado')),
|
||||||
observacoes: inp('edit-obs')
|
observacoes: inp('edit-obs'),
|
||||||
|
edited_at: new Date().toISOString(),
|
||||||
|
edited_by: full.operador || '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasTauri = !!(window.__TAURI__ && window.__TAURI__.core);
|
const hasTauri = !!(window.__TAURI__ && window.__TAURI__.core);
|
||||||
|
|||||||
Reference in New Issue
Block a user