From a6b295a6d05f5c8bd5f25d6b7911a9308ca4f5ab Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jun 2026 02:41:37 +0000 Subject: [PATCH] =?UTF-8?q?v1.3.5:=20to=5Fescpos=20completo=20=E2=80=94=20?= =?UTF-8?q?totais=20por=20se=C3=A7=C3=A3o,=20diferenca=20via=20self.difere?= =?UTF-8?q?nca;=20confirm=20antes=20de=20dia=20anterior;=20sem=20senha?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/plugins/printer.rs | 90 +++++++++++++++++++++++--------- src/index.html | 19 +++++-- 2 files changed, 82 insertions(+), 27 deletions(-) diff --git a/src-tauri/src/plugins/printer.rs b/src-tauri/src/plugins/printer.rs index 6e79a09..233bec2 100644 --- a/src-tauri/src/plugins/printer.rs +++ b/src-tauri/src/plugins/printer.rs @@ -156,24 +156,10 @@ impl ReciboData { out.extend(escpos::divider()); // ── SANGRIAS ── - out.extend(escpos::line_bold("SANGRIAS")); - for linha in &self.sangrias_arr { - if linha.retirada.is_some() || linha.valor.is_some() { - let label = linha.label(); - let obs = linha.obs(); - out.extend(escpos::kv(&label, &linha.fmt_v())); - if !obs.is_empty() { - out.extend(escpos::line_center(&format!(" {}", obs))); - } - } - } - out.extend(escpos::divider()); - - // ── DESPESAS ── - if !self.despesas_arr.is_empty() { - out.extend(escpos::line_bold("DESPESAS")); - for linha in &self.despesas_arr { - if linha.valor.is_some() { + if !self.sangrias_arr.is_empty() { + out.extend(escpos::line_bold("SANGRIAS")); + for linha in &self.sangrias_arr { + if linha.retirada.unwrap_or(0.0) > 0.0 || linha.valor.unwrap_or(0.0) > 0.0 { let label = linha.label(); let obs = linha.obs(); out.extend(escpos::kv(&label, &linha.fmt_v())); @@ -182,18 +168,53 @@ impl ReciboData { } } } + // Total sangrias + let total_sangrias: f64 = self.sangrias_arr.iter() + .map(|l| l.retirada.unwrap_or(0.0) + l.valor.unwrap_or(0.0)) + .sum(); + if total_sangrias > 0.0 { + out.extend(escpos::kv("Total:", &self.fmt_money(total_sangrias))); + } + out.extend(escpos::divider()); + } + + // ── DESPESAS ── + if !self.despesas_arr.is_empty() { + out.extend(escpos::line_bold("DESPESAS")); + for linha in &self.despesas_arr { + if linha.valor.unwrap_or(0.0) > 0.0 { + let label = linha.label(); + let obs = linha.obs(); + out.extend(escpos::kv(&label, &linha.fmt_v())); + if !obs.is_empty() { + out.extend(escpos::line_center(&format!(" {}", obs))); + } + } + } + // Total despesas + let total_despesas: f64 = self.despesas_arr.iter() + .map(|l| l.valor.unwrap_or(0.0)) + .sum(); + out.extend(escpos::kv("Total:", &self.fmt_money(total_despesas))); out.extend(escpos::divider()); } // ── PIX CNPJ ── - if !self.pixcnpj_arr.is_empty() || self.pixcnpj > 0.0 { + if !self.pixcnpj_arr.is_empty() { out.extend(escpos::line_bold("PIX CNPJ")); for linha in &self.pixcnpj_arr { - if linha.valor.is_some() { + if linha.valor.unwrap_or(0.0) > 0.0 { let label = linha.nome.clone().unwrap_or_else(|| "PIX CNPJ".to_string()); out.extend(escpos::kv(&label, &linha.fmt_v())); } } + // Total PIX CNPJ + let total_pixcnpj: f64 = self.pixcnpj_arr.iter() + .map(|l| l.valor.unwrap_or(0.0)) + .sum(); + if total_pixcnpj > 0.0 { + out.extend(escpos::kv("Total:", &self.fmt_money(total_pixcnpj))); + } out.extend(escpos::divider()); } @@ -201,7 +222,7 @@ impl ReciboData { if !self.vales_arr.is_empty() { out.extend(escpos::line_bold("VALES")); for linha in &self.vales_arr { - if linha.valor.is_some() { + if linha.valor.unwrap_or(0.0) > 0.0 { let label = linha.label(); let obs = linha.obs(); out.extend(escpos::kv(&label, &linha.fmt_v())); @@ -210,6 +231,13 @@ impl ReciboData { } } } + // Total vales + let total_vales: f64 = self.vales_arr.iter() + .map(|l| l.valor.unwrap_or(0.0)) + .sum(); + if total_vales > 0.0 { + out.extend(escpos::kv("Total:", &self.fmt_money(total_vales))); + } out.extend(escpos::divider()); } @@ -217,11 +245,18 @@ impl ReciboData { if !self.receber_arr.is_empty() { out.extend(escpos::line_bold("A RECEBER")); for linha in &self.receber_arr { - if linha.valor.is_some() { + if linha.valor.unwrap_or(0.0) > 0.0 { let label = linha.label(); out.extend(escpos::kv(&label, &linha.fmt_v())); } } + // Total a receber + let total_receber: f64 = self.receber_arr.iter() + .map(|l| l.valor.unwrap_or(0.0)) + .sum(); + if total_receber > 0.0 { + out.extend(escpos::kv("Total:", &self.fmt_money(total_receber))); + } out.extend(escpos::divider()); } @@ -229,7 +264,7 @@ impl ReciboData { if !self.cancelamentos_arr.is_empty() { out.extend(escpos::line_bold("CANCELAMENTOS")); for linha in &self.cancelamentos_arr { - if linha.valor.is_some() { + if linha.numero.is_some() || linha.valor.unwrap_or(0.0) > 0.0 { let num = linha.numero.clone().unwrap_or_default(); out.extend(escpos::kv(&num, &linha.fmt_v())); if let Some(ref m) = linha.motivo { @@ -239,6 +274,13 @@ impl ReciboData { } } } + // Total cancelamentos + let total_cancel: f64 = self.cancelamentos_arr.iter() + .map(|l| l.valor.unwrap_or(0.0)) + .sum(); + if total_cancel > 0.0 { + out.extend(escpos::kv("Total:", &self.fmt_money(total_cancel))); + } out.extend(escpos::divider()); } @@ -277,7 +319,7 @@ impl ReciboData { // ── DIFERENÇA ── out.extend(escpos::line_bold("DIFERENCA")); - let diff = self.sys_total - self.saldo_esperado; + let diff = self.diferenca; let diff_str = if diff >= 0.0 { format!("+{}", self.fmt_money(diff)) } else { diff --git a/src/index.html b/src/index.html index 30f2346..6e70cef 100644 --- a/src/index.html +++ b/src/index.html @@ -1710,6 +1710,21 @@ if (btnAnterior) { const loja = val('f-loja') || 'União'; console.log('[DEBUG] btn-anterior loja:', loja); + // Salva rascunho atual antes de tudo + await tauriSaveLocal(); + + // Calcula dia anterior + const prevDate = new Date(estado.data); + prevDate.setDate(prevDate.getDate() - 1); + const prevDateStr = prevDate.toISOString().split('T')[0]; + + // Confirmação explícita antes de trocar de dia + const confirmMsg = `ATENÇÃO: vai carregar o fechamento de ${prevDateStr}.\n\nO formulário atual será LIMPO caso não tenha enviado.\n\nContinuar?`; + if (!confirm(confirmMsg)) { + console.log('[DEBUG] btn-anterior cancelado pelo usuário'); + return; + } + // Carrega lista de fechamentos recentes do Supabase com uuid let recentList = []; try { @@ -1749,12 +1764,10 @@ if (btnAnterior) { // Se não escolheu data, usa dia anterior automático (sem id — carrega por data) if (!selectedDate) { - const d = new Date(estado.data); d.setDate(d.getDate() - 1); - selectedDate = d.toISOString().split('T')[0]; + selectedDate = prevDateStr; } console.log('[DEBUG] selectedDate:', selectedDate, 'selectedId:', selectedId); - await tauriSaveLocal(); setVal('f-data', selectedDate); estado.data = selectedDate; estado.uuid = crypto.randomUUID ? crypto.randomUUID() : Date.now().toString();