Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bd867e8419 | |||
| da861ef964 | |||
| 8e642f2e0c | |||
| 7473db6b1f | |||
| 13489d58cf | |||
| 5ad8c1f395 | |||
| 103cd31e50 | |||
| 06783de4e2 | |||
| 11abac8daf | |||
| fea957dfb9 | |||
| 130b2b6da7 | |||
| b47d7766ad | |||
| 78fa778197 | |||
| 5e4340adca | |||
| c01133f39c |
@@ -96,6 +96,8 @@ fn main() {
|
||||
plugins::supabase::sb_carregar_rascunho,
|
||||
plugins::supabase::sb_listar_recentes,
|
||||
plugins::supabase::sb_buscar_por_id,
|
||||
plugins::supabase::sb_buscar_por_uuid,
|
||||
plugins::supabase::sb_atualizar_fechamento,
|
||||
plugins::supabase::sb_salvar_listas,
|
||||
plugins::supabase::sb_carregar_listas,
|
||||
plugins::supabase::sb_online,
|
||||
|
||||
@@ -127,6 +127,10 @@ pub struct ReciboData {
|
||||
pub cancelamentos_arr: Vec<ReciboLinha>,
|
||||
#[serde(default)]
|
||||
pub observacoes: Option<String>,
|
||||
#[serde(default)]
|
||||
pub clientes: i32,
|
||||
#[serde(default)]
|
||||
pub frango: i32,
|
||||
}
|
||||
|
||||
impl ReciboData {
|
||||
@@ -318,6 +322,8 @@ impl ReciboData {
|
||||
out.extend(escpos::divider());
|
||||
|
||||
// ── DIFERENÇA ──
|
||||
// Usa self.diferenca que o frontend calcula como sys_total - saldo_esperado
|
||||
// (não recalcula de fechamento, que é o valor contado e não deve ser usado na diferença)
|
||||
out.extend(escpos::line_bold("DIFERENCA"));
|
||||
let diff = self.diferenca;
|
||||
let diff_str = if diff >= 0.0 {
|
||||
@@ -327,6 +333,12 @@ impl ReciboData {
|
||||
};
|
||||
out.extend(escpos::title(&diff_str));
|
||||
|
||||
// ── CONTADORES ──
|
||||
out.extend(escpos::line_bold("CONTADORES"));
|
||||
out.extend(escpos::kv("Clientes:", &self.clientes.to_string()));
|
||||
out.extend(escpos::kv("Frango Assado:", &self.frango.to_string()));
|
||||
out.extend(escpos::divider());
|
||||
|
||||
// ── OBSERVAÇÕES ──
|
||||
if let Some(ref obs) = self.observacoes {
|
||||
if !obs.trim().is_empty() {
|
||||
|
||||
@@ -153,7 +153,59 @@ impl SupabaseClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Lista fechamentos recentes de uma loja.
|
||||
/// Busca um fechamento pelo UUID.
|
||||
pub fn buscar_por_uuid(&self, uuid: &str) -> Result<Option<Value>, SupabaseError> {
|
||||
let url = format!(
|
||||
"{}/rest/v1/fechamentos_web?uuid=eq.{}&select=*",
|
||||
self.base_url, uuid
|
||||
);
|
||||
|
||||
let resp = self
|
||||
.http
|
||||
.get(&url)
|
||||
.headers(self.headers(false))
|
||||
.send()?;
|
||||
|
||||
if resp.status().is_success() {
|
||||
let arr: Vec<Value> = resp.json()?;
|
||||
Ok(arr.into_iter().next())
|
||||
} else {
|
||||
let status = resp.status();
|
||||
let body = resp.text().unwrap_or_default();
|
||||
Err(SupabaseError::Api(format!(
|
||||
"HTTP {}: {}",
|
||||
status.as_u16(),
|
||||
body
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Atualiza campos específicos de um fechamento pelo UUID (PATCH).
|
||||
pub fn atualizar_fechamento(&self, uuid: &str, updates: &serde_json::Value) -> Result<Value, SupabaseError> {
|
||||
let url = format!(
|
||||
"{}/rest/v1/fechamentos_web?uuid=eq.{}",
|
||||
self.base_url, uuid
|
||||
);
|
||||
|
||||
let resp = self
|
||||
.http
|
||||
.patch(&url)
|
||||
.headers(self.headers(true))
|
||||
.json(updates)
|
||||
.send()?;
|
||||
|
||||
if resp.status().is_success() {
|
||||
Ok(serde_json::json!({ "ok": true, "uuid": uuid }))
|
||||
} else {
|
||||
let status = resp.status();
|
||||
let body = resp.text().unwrap_or_default();
|
||||
Err(SupabaseError::Api(format!(
|
||||
"HTTP {}: {}",
|
||||
status.as_u16(),
|
||||
body
|
||||
)))
|
||||
}
|
||||
}
|
||||
pub fn listar_recentes(&self, loja: &str, limite: i64) -> Result<Vec<Value>, SupabaseError> {
|
||||
let url = format!(
|
||||
"{}/rest/v1/fechamentos_web?loja=eq.{}&order=data.desc,atualizado_em.desc&limit={}&select=id,uuid,data,operador,turno,saldo_troco,saldo_esperado,fechamento,sync_status,observacoes,atualizado_em",
|
||||
@@ -322,6 +374,23 @@ pub fn sb_buscar_por_id(
|
||||
sb.buscar_por_id(id)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn sb_buscar_por_uuid(
|
||||
sb: State<'_, SupabaseClient>,
|
||||
uuid: String,
|
||||
) -> Result<Option<serde_json::Value>, SupabaseError> {
|
||||
sb.buscar_por_uuid(&uuid)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn sb_atualizar_fechamento(
|
||||
sb: State<'_, SupabaseClient>,
|
||||
uuid: String,
|
||||
updates: serde_json::Value,
|
||||
) -> Result<serde_json::Value, SupabaseError> {
|
||||
sb.atualizar_fechamento(&uuid, &updates)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn sb_salvar_listas(
|
||||
sb: State<'_, SupabaseClient>,
|
||||
|
||||
+732
-306
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user