From 4a157d27cbf66b6044d12917408e42ffc7fdb8d7 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 30 Jun 2026 02:52:18 +0000 Subject: [PATCH] fix: vendas no buildPrintHTML e consultaToPrintData, fmtMoneyInput R$, auto-migration no Rust --- src-tauri/src/plugins/supabase.rs | 42 +++++++++++++++++++++++++++++++ src/index.html | 13 +++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/plugins/supabase.rs b/src-tauri/src/plugins/supabase.rs index 2e580a1..5790326 100644 --- a/src-tauri/src/plugins/supabase.rs +++ b/src-tauri/src/plugins/supabase.rs @@ -397,6 +397,48 @@ impl SupabaseClient { } } + /// Tenta forçar PostgREST a recarregar schema com novas colunas (vendas, edited_at, edited_by). + /// Estratégia: INSERT com novas colunas → se PGRST204, espera 1.5s → retry. + /// Fire-and-forget — falha não bloqueia. + pub fn run_migration(&self) { + let payload = serde_json::json!({ + "id_fechamento": "_mig_probe_1900", + "loja": "_probe_", + "data": "1900-01-01", + "operador": "_probe_", + "vendas": 0, + "edited_at": null, + "edited_by": null + }); + let r1 = self.http + .post(&format!("{}/rest/v1/fechamentos_web", self.base_url)) + .headers(self.headers(true)) + .header("Prefer", "resolution=merge-duplicates") + .json(&payload) + .send(); + if let Ok(resp) = r1 { + if resp.status().as_u16() == 400 { + std::thread::sleep(std::time::Duration::from_millis(1500)); + let _ = self.http + .post(&format!("{}/rest/v1/fechamentos_web", self.base_url)) + .headers(self.headers(true)) + .header("Prefer", "resolution=merge-duplicates") + .json(&serde_json::json!({ + "id_fechamento": "_mig_probe_1900", + "vendas": 0, + "edited_at": null, + "edited_by": null + })) + .send(); + } + } + // Limpa probe + let _ = self.http + .delete(&format!("{}/rest/v1/fechamentos_web?id_fechamento=eq._mig_probe_1900", self.base_url)) + .headers(self.headers(true)) + .send(); + } + /// Verifica se está online. pub fn health_check(&self) -> bool { let url = format!("{}/rest/v1/?limit=0", self.base_url); diff --git a/src/index.html b/src/index.html index b04b82a..28ff288 100644 --- a/src/index.html +++ b/src/index.html @@ -433,7 +433,7 @@
- +
@@ -638,6 +638,14 @@ const fmtNum = v => { // Always 2 decimal places for money return n.toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); }; +const fmtMoneyInput = el => { + const raw = parseNum(el.value); + if (raw > 0) el.value = fmtNum(raw); +}; +const unfmtMoneyInput = el => { + const raw = parseNum(el.value); + if (raw > 0) el.value = raw.toString(); +}; // Format time: 4 digits → HH:MM function fmtTime(v) { @@ -1686,6 +1694,7 @@ ${cancLines.map(l => `
${l.label}${fmt(l.valo
CONTADORES
Clientes:${data.clientes || 0}
Frango Assado:${data.frango || 0}
+
Vendas:${fmt(data.vendas || 0)}
${data.observacoes ? `
${data.observacoes}
` : ''} @@ -1904,6 +1913,7 @@ function buildReciboData() { observacoes: estado.observacoes, clientes: estado.clientes, frango: estado.frango, + vendas: estado.vendas || 0, sync_status: estado.sync_status, }; } @@ -2703,6 +2713,7 @@ function consultaToPrintData(full) { observacoes: full.observacoes || '', clientes: full.clientes || 0, frango: full.frango || 0, + vendas: dados.vendas ?? full.vendas ?? 0, }; }