Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d9e28a6f2 | |||
| ecb9ce3926 | |||
| de5d5aaafb | |||
| a11db54ffc |
@@ -247,11 +247,11 @@ impl SupabaseClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Atualiza campos específicos de um fechamento pelo id (PATCH).
|
/// Atualiza campos específicos de um fechamento pelo id numérico (PATCH).
|
||||||
pub fn atualizar_fechamento(&self, uuid: &str, updates: &serde_json::Value) -> Result<Value, SupabaseError> {
|
pub fn atualizar_fechamento(&self, id: i64, updates: &serde_json::Value) -> Result<Value, SupabaseError> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/rest/v1/fechamentos_web?id=eq.{}",
|
"{}/rest/v1/fechamentos_web?id=eq.{}",
|
||||||
self.base_url, uuid
|
self.base_url, id
|
||||||
);
|
);
|
||||||
|
|
||||||
let resp = self
|
let resp = self
|
||||||
@@ -262,7 +262,7 @@ impl SupabaseClient {
|
|||||||
.send()?;
|
.send()?;
|
||||||
|
|
||||||
if resp.status().is_success() {
|
if resp.status().is_success() {
|
||||||
Ok(serde_json::json!({ "ok": true, "uuid": uuid }))
|
Ok(serde_json::json!({ "ok": true, "id": id }))
|
||||||
} else {
|
} else {
|
||||||
let status = resp.status();
|
let status = resp.status();
|
||||||
let body = resp.text().unwrap_or_default();
|
let body = resp.text().unwrap_or_default();
|
||||||
@@ -437,9 +437,9 @@ pub fn sb_listar_recentes(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn sb_buscar_por_id(
|
pub fn sb_buscar_por_id(
|
||||||
sb: State<'_, SupabaseClient>,
|
sb: State<'_, SupabaseClient>,
|
||||||
id: String,
|
id: i64,
|
||||||
) -> Result<Option<serde_json::Value>, SupabaseError> {
|
) -> Result<Option<serde_json::Value>, SupabaseError> {
|
||||||
sb.buscar_por_uuid(&id)
|
sb.buscar_por_id(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -462,10 +462,10 @@ pub fn sb_buscar_por_id_fechamento(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn sb_atualizar_fechamento(
|
pub fn sb_atualizar_fechamento(
|
||||||
sb: State<'_, SupabaseClient>,
|
sb: State<'_, SupabaseClient>,
|
||||||
uuid: String,
|
id: i64,
|
||||||
updates: serde_json::Value,
|
updates: serde_json::Value,
|
||||||
) -> Result<serde_json::Value, SupabaseError> {
|
) -> Result<serde_json::Value, SupabaseError> {
|
||||||
sb.atualizar_fechamento(&uuid, &updates)
|
sb.atualizar_fechamento(id, &updates)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
|||||||
+17
-17
@@ -2179,14 +2179,17 @@ window.openConsultaRegistro = async function(idx) {
|
|||||||
|
|
||||||
let full = null;
|
let full = null;
|
||||||
try {
|
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) {}
|
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) {
|
if (!full && item.id_fechamento) {
|
||||||
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_id_fechamento', { id_fechamento: item.id_fechamento }); } catch(e) {}
|
try { full = await window.__TAURI__.core.invoke('sb_buscar_por_id_fechamento', { idFechamento: 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) {}
|
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.warn('Erro buscando registro:', e);
|
console.warn('Erro buscando registro:', e);
|
||||||
@@ -2194,7 +2197,9 @@ window.openConsultaRegistro = async function(idx) {
|
|||||||
|
|
||||||
if (!full) { alert('Registro não encontrado.'); return; }
|
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._currentConsulta = full;
|
||||||
|
window._currentConsultaId = item.id;
|
||||||
buildRelatorioModal(full);
|
buildRelatorioModal(full);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2422,16 +2427,10 @@ window.salvarEdicaoConsulta = async function() {
|
|||||||
if (!hasTauri) { alert('Tauri não disponível.'); return; }
|
if (!hasTauri) { alert('Tauri não disponível.'); return; }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let uuid = full.uuid;
|
const id = window._currentConsultaId;
|
||||||
if (!uuid && full.id_fechamento) {
|
if (!id) { alert('ID do registro não encontrado. Não é possível atualizar.'); return; }
|
||||||
// Buscar uuid pelo id_fechamento primeiro
|
|
||||||
const found = await window.__TAURI__.core.invoke('sb_buscar_por_id_fechamento', { id_fechamento: full.id_fechamento });
|
|
||||||
if (found && found.uuid) uuid = found.uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!uuid) { alert('UUID do registro não encontrado. Não é possível atualizar.'); return; }
|
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id, updates });
|
||||||
|
|
||||||
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { uuid, updates });
|
|
||||||
alert('✅ Atualizado com sucesso!');
|
alert('✅ Atualizado com sucesso!');
|
||||||
closeRelatorioModal();
|
closeRelatorioModal();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
@@ -2442,6 +2441,10 @@ window.salvarEdicaoConsulta = async function() {
|
|||||||
|
|
||||||
// Converte o registro "full" do Supabase para o formato usado pelo buildPrintHTML
|
// Converte o registro "full" do Supabase para o formato usado pelo buildPrintHTML
|
||||||
function consultaToPrintData(full) {
|
function consultaToPrintData(full) {
|
||||||
|
const fmtDiff = v => 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ',');
|
||||||
|
const fmtDiffNeg = v => (v < 0 ? '-' : '') + 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ',');
|
||||||
|
const fmt = v => 'R$ ' + (v || 0).toFixed(2).replace('.', ',');
|
||||||
|
|
||||||
const cartCred = parseFloat(full.saldo_credito || 0);
|
const cartCred = parseFloat(full.saldo_credito || 0);
|
||||||
const cartDeb = parseFloat(full.saldo_debito || 0);
|
const cartDeb = parseFloat(full.saldo_debito || 0);
|
||||||
const cartAli = parseFloat(full.saldo_alimentacao || 0);
|
const cartAli = parseFloat(full.saldo_alimentacao || 0);
|
||||||
@@ -2460,9 +2463,6 @@ function consultaToPrintData(full) {
|
|||||||
const diffOk = diferenca === 0;
|
const diffOk = diferenca === 0;
|
||||||
const diffStr = diferenca >= 0 ? `+${fmtDiff(diferenca)}` : fmtDiffNeg(diferenca);
|
const diffStr = diferenca >= 0 ? `+${fmtDiff(diferenca)}` : fmtDiffNeg(diferenca);
|
||||||
const dados = full.dados || {};
|
const dados = full.dados || {};
|
||||||
const fmtDiff = v => 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ',');
|
|
||||||
const fmtDiffNeg = v => (v < 0 ? '-' : '') + 'R$ ' + Math.abs(v || 0).toFixed(2).replace('.', ',');
|
|
||||||
const fmt = v => 'R$ ' + (v || 0).toFixed(2).replace('.', ',');
|
|
||||||
|
|
||||||
const despesas_arr = (dados.despesas || []).map(d => ({ desc: d.desc || '', obs: d.obs || '', valor: parseFloat(d.valor || 0) }));
|
const despesas_arr = (dados.despesas || []).map(d => ({ desc: d.desc || '', obs: d.obs || '', valor: parseFloat(d.valor || 0) }));
|
||||||
const sangrias_arr = (dados.sangrias || []).map(s => ({ hora: s.hora || '', retirada: parseFloat(s.retirada || 0), gerente: s.gerente || '', valor: parseFloat(s.valor || 0) }));
|
const sangrias_arr = (dados.sangrias || []).map(s => ({ hora: s.hora || '', retirada: parseFloat(s.retirada || 0), gerente: s.gerente || '', valor: parseFloat(s.valor || 0) }));
|
||||||
|
|||||||
Reference in New Issue
Block a user