Compare commits

...

4 Commits

Author SHA1 Message Date
root 60ec60bf29 fix: sb_atualizar_fechamento aceita id numerico ou UUID string
Build Fechamento de Caixa / build (macos-14, app) (push) Has been cancelled
Build Fechamento de Caixa / build (ubuntu-22.04, deb) (push) Has been cancelled
Build Fechamento de Caixa / build (windows-2022, msi) (push) Has been cancelled
2026-06-29 12:39:50 +00:00
root 6d9e28a6f2 fix: salvar usa _currentConsultaId (id numerico), nao full.id
Build Fechamento de Caixa / build (macos-14, app) (push) Has been cancelled
Build Fechamento de Caixa / build (ubuntu-22.04, deb) (push) Has been cancelled
Build Fechamento de Caixa / build (windows-2022, msi) (push) Has been cancelled
2026-06-29 12:06:32 +00:00
root ecb9ce3926 fix: sb_buscar_por_id chama metodo correto (id numerico), tenta id primeiro no openConsultaRegistro
Build Fechamento de Caixa / build (macos-14, app) (push) Has been cancelled
Build Fechamento de Caixa / build (ubuntu-22.04, deb) (push) Has been cancelled
Build Fechamento de Caixa / build (windows-2022, msi) (push) Has been cancelled
2026-06-28 13:54:45 +00:00
root de5d5aaafb fix: salvar edicao com id numerico, relatorio cartoes detalhado
Build Fechamento de Caixa / build (macos-14, app) (push) Has been cancelled
Build Fechamento de Caixa / build (ubuntu-22.04, deb) (push) Has been cancelled
Build Fechamento de Caixa / build (windows-2022, msi) (push) Has been cancelled
2026-06-28 13:44:08 +00:00
2 changed files with 29 additions and 25 deletions
+16 -11
View File
@@ -247,12 +247,14 @@ impl SupabaseClient {
}
}
/// Atualiza campos específicos de um fechamento pelo id (PATCH).
pub fn atualizar_fechamento(&self, uuid: &str, updates: &serde_json::Value) -> Result<Value, SupabaseError> {
let url = format!(
"{}/rest/v1/fechamentos_web?id=eq.{}",
self.base_url, uuid
);
/// Atualiza campos específicos de um fechamento pelo id numérico (pk) ou UUID.
pub fn atualizar_fechamento(&self, id: Option<i64>, uuid: &str, updates: &serde_json::Value) -> Result<Value, SupabaseError> {
// Se temos id numerico, usa id=eq.; senao usa id=eq.UUID
let url = if let Some(num) = id {
format!("{}/rest/v1/fechamentos_web?id=eq.{}", self.base_url, num)
} else {
format!("{}/rest/v1/fechamentos_web?id=eq.{}", self.base_url, uuid)
};
let resp = self
.http
@@ -262,7 +264,7 @@ impl SupabaseClient {
.send()?;
if resp.status().is_success() {
Ok(serde_json::json!({ "ok": true, "uuid": uuid }))
Ok(serde_json::json!({ "ok": true, "id": id.unwrap_or(0) }))
} else {
let status = resp.status();
let body = resp.text().unwrap_or_default();
@@ -437,9 +439,9 @@ pub fn sb_listar_recentes(
#[tauri::command]
pub fn sb_buscar_por_id(
sb: State<'_, SupabaseClient>,
id: String,
id: i64,
) -> Result<Option<serde_json::Value>, SupabaseError> {
sb.buscar_por_uuid(&id)
sb.buscar_por_id(id)
}
#[tauri::command]
@@ -462,10 +464,13 @@ pub fn sb_buscar_por_id_fechamento(
#[tauri::command]
pub fn sb_atualizar_fechamento(
sb: State<'_, SupabaseClient>,
uuid: String,
id: String,
updates: serde_json::Value,
) -> Result<serde_json::Value, SupabaseError> {
sb.atualizar_fechamento(&uuid, &updates)
// Tenta primeiro como i64 (id numerico), depois como String (UUID)
let id_i64 = id.parse::<i64>().ok();
let id_str = &id;
sb.atualizar_fechamento(id_i64, id_str, &updates)
}
#[tauri::command]
+13 -14
View File
@@ -2179,14 +2179,17 @@ window.openConsultaRegistro = async function(idx) {
let full = null;
try {
if (item.uuid) {
// 1. Tentar por id numérico (campo "id" da tabela, pk)
if (item.id) {
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_id', { id: item.id }); } catch(e) {}
}
// 2. Tentar por uuid externo
if (!full && item.uuid) {
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_uuid', { uuid: item.uuid }); } catch(e) {}
}
// 3. Tentar por id_fechamento (ex: uniao_2026-06-11_filipe)
if (!full && item.id_fechamento) {
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_id_fechamento', { id_fechamento: item.id_fechamento }); } catch(e) {}
}
if (!full && item.id) {
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_id', { id: String(item.id) }); } catch(e) {}
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);
@@ -2194,7 +2197,9 @@ window.openConsultaRegistro = async function(idx) {
if (!full) { alert('Registro não encontrado.'); return; }
// Preserva o id numerico (pk da tabela) antes de guardar o registro completo
window._currentConsulta = full;
window._currentConsultaId = item.id;
buildRelatorioModal(full);
};
@@ -2422,16 +2427,10 @@ window.salvarEdicaoConsulta = async function() {
if (!hasTauri) { alert('Tauri não disponível.'); return; }
try {
let uuid = full.uuid;
if (!uuid && full.id_fechamento) {
// Buscar uuid pelo id_fechamento primeiro
const found = await window.__TAURI__.core.invoke('sb_buscar_por_id_fechamento', { idFechamento: full.id_fechamento });
if (found && found.uuid) uuid = found.uuid;
}
const id = window._currentConsultaId;
if (!id) { alert('ID do registro não encontrado. Não é possível atualizar.'); return; }
if (!uuid) { alert('UUID do registro não encontrado. Não é possível atualizar.'); return; }
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { uuid, updates });
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id, updates });
alert('✅ Atualizado com sucesso!');
closeRelatorioModal();
} catch(e) {