Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 96a84ec194 | |||
| 7d0c416248 | |||
| 60ec60bf29 | |||
| 6d9e28a6f2 | |||
| ecb9ce3926 | |||
| de5d5aaafb |
@@ -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]
|
||||
|
||||
+106
-23
@@ -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);
|
||||
};
|
||||
|
||||
@@ -2319,14 +2324,83 @@ function buildRelatorioModal(full) {
|
||||
${obs ? `<div style="background:#fff8e1;border-radius:6px;padding:8px;margin-bottom:10px;font-size:12px"><strong>Obs:</strong> ${obs}</div>` : ''}
|
||||
|
||||
<div id="edit-section" style="display:none;margin-bottom:10px">
|
||||
<div style="font-size:12px;color:#666;margin-bottom:6px">Editar campos (requer senha admin):</div>
|
||||
<input type="hidden" id="edit-id" value="${full.id || ''}" />
|
||||
<div style="font-size:12px;color:#666;margin-bottom:6px;font-weight:bold">✏️ Editar valores do caixa (requer senha admin):</div>
|
||||
<div style="display:grid;grid-template-columns:1fr 1fr;gap:6px;margin-bottom:8px">
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">Troco:</label>
|
||||
<input type="text" id="edit-troco" value="${fmtMoney(troco)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">Credito:</label>
|
||||
<input type="text" id="edit-credito" value="${fmtMoney(credito)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">Debito:</label>
|
||||
<input type="text" id="edit-debito" value="${fmtMoney(debito)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">Alimentacao:</label>
|
||||
<input type="text" id="edit-alimentacao" value="${fmtMoney(alimentacao)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">Vales:</label>
|
||||
<input type="text" id="edit-vales" value="${fmtMoney(vales)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">PIX Cartao:</label>
|
||||
<input type="text" id="edit-pixcartao" value="${fmtMoney(pixCartao)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">PIX CNPJ:</label>
|
||||
<input type="text" id="edit-pixcnpj" value="${fmtMoney(pixCnpj)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">A Receber:</label>
|
||||
<input type="text" id="edit-areceber" value="${fmtMoney(parseFloat(full.saldo_areceber||0))}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
</div>
|
||||
<div style="font-size:12px;color:#666;margin-bottom:4px;font-weight:bold;margin-top:6px">💰 Valores Contados:</div>
|
||||
<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:6px;margin-bottom:8px">
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">Dinheiro:</label>
|
||||
<input type="text" id="edit-fd" value="${fmtMoney(fd)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">Cartoes:</label>
|
||||
<input type="text" id="edit-fc" value="${fmtMoney(fc)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">A Receber:</label>
|
||||
<input type="text" id="edit-fr" value="${fmtMoney(fr)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
</div>
|
||||
<div style="display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:6px;margin-bottom:8px">
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">Sangrias:</label>
|
||||
<input type="text" id="edit-sangrias" value="${fmtMoney(totalSangrias)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">Despesas:</label>
|
||||
<input type="text" id="edit-despesas" value="${fmtMoney(totalDespesas)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">Clientes:</label>
|
||||
<input type="number" id="edit-clientes" value="${clientes}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size:10px;color:#555">Frango:</label>
|
||||
<input type="number" id="edit-frango" value="${frango}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
</div>
|
||||
<div style="font-size:12px;color:#666;margin-bottom:4px;font-weight:bold;margin-top:6px">📋 Meta / Observacoes:</div>
|
||||
<div style="margin-bottom:6px">
|
||||
<label style="font-size:11px;color:#555">Saldo Esperado:</label><br>
|
||||
<input type="text" id="edit-esperado" value="${fmtMoney(saldoEsperado)}" style="width:100%;padding:4px;border:1px solid #ccc;border-radius:4px" />
|
||||
<label style="font-size:10px;color:#555">Saldo Esperado:</label>
|
||||
<input type="text" id="edit-esperado" value="${fmtMoney(saldoEsperado)}" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px" />
|
||||
</div>
|
||||
<div style="margin-bottom:6px">
|
||||
<label style="font-size:11px;color:#555">Observacoes:</label><br>
|
||||
<textarea id="edit-obs" style="width:100%;padding:4px;border:1px solid #ccc;border-radius:4px;height:60px">${obs}</textarea>
|
||||
<label style="font-size:10px;color:#555">Observacoes:</label>
|
||||
<textarea id="edit-obs" style="width:100%;padding:3px;border:1px solid #ccc;border-radius:3px;font-size:12px;height:50px">${obs}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2410,28 +2484,37 @@ window.salvarEdicaoConsulta = async function() {
|
||||
const full = window._currentConsulta;
|
||||
if (!full) return;
|
||||
|
||||
const newEsperado = parseNum(document.getElementById('edit-esperado').value);
|
||||
const newObs = document.getElementById('edit-obs').value;
|
||||
const p = v => parseFloat((v || '0').replace(',', '.') || '0');
|
||||
const inp = id => document.getElementById(id).value;
|
||||
|
||||
const updates = {
|
||||
saldo_esperado: newEsperado,
|
||||
observacoes: newObs
|
||||
saldo_troco: p(inp('edit-troco')),
|
||||
saldo_credito: p(inp('edit-credito')),
|
||||
saldo_debito: p(inp('edit-debito')),
|
||||
saldo_alimentacao: p(inp('edit-alimentacao')),
|
||||
saldo_vales: p(inp('edit-vales')),
|
||||
total_cartao_pix: p(inp('edit-pixcartao')),
|
||||
total_pixcnpj: p(inp('edit-pixcnpj')),
|
||||
saldo_areceber: p(inp('edit-areceber')),
|
||||
fechamento_dinheiro: p(inp('edit-fd')),
|
||||
fechamento_cartoes: p(inp('edit-fc')),
|
||||
fechamento_areceber: p(inp('edit-fr')),
|
||||
total_sangrias: p(inp('edit-sangrias')),
|
||||
total_despesas: p(inp('edit-despesas')),
|
||||
clientes: parseInt(inp('edit-clientes') || '0'),
|
||||
frango: parseInt(inp('edit-frango') || '0'),
|
||||
saldo_esperado: p(inp('edit-esperado')),
|
||||
observacoes: inp('edit-obs')
|
||||
};
|
||||
|
||||
const hasTauri = !!(window.__TAURI__ && window.__TAURI__.core);
|
||||
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 = document.getElementById('edit-id').value || window._currentConsultaId || full.id;
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user