feat: adicionar gerenciamento de configuração para arquivos DMED
This commit is contained in:
Vendored
BIN
Binary file not shown.
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"ultimo_arquivo_txt": "P:\\ProEmp00\\LFSM2026\\Dmed2026\\LfsIssDmed073225.txt",
|
||||
"ultimo_arquivo_xls": "Z:\\Fiscal\\FELIPE\\RELATORIO\\RELATORIO_PROSOFT_MOD_51.XLS"
|
||||
}
|
||||
+141
-88
@@ -3,6 +3,42 @@
|
||||
use eframe::egui;
|
||||
use dmed::{processar_arquivo, xls::processar_xls, Pessoa};
|
||||
use std::collections::HashMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use std::fs;
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
struct Config {
|
||||
ultimo_arquivo_txt: Option<String>,
|
||||
ultimo_arquivo_xls: Option<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
fn carregar() -> Self {
|
||||
let config_path = Self::caminho_config();
|
||||
if config_path.exists() {
|
||||
if let Ok(conteudo) = fs::read_to_string(&config_path) {
|
||||
if let Ok(config) = serde_json::from_str(&conteudo) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
fn salvar(&self) {
|
||||
if let Ok(json) = serde_json::to_string_pretty(self) {
|
||||
let _ = fs::write(Self::caminho_config(), json);
|
||||
}
|
||||
}
|
||||
|
||||
fn caminho_config() -> PathBuf {
|
||||
let mut path = std::env::current_exe().unwrap_or_default();
|
||||
path.pop();
|
||||
path.push("dmed_config.json");
|
||||
path
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> eframe::Result {
|
||||
let options = eframe::NativeOptions {
|
||||
@@ -15,11 +51,13 @@ fn main() -> eframe::Result {
|
||||
eframe::run_native(
|
||||
"DMED Comparador",
|
||||
options,
|
||||
Box::new(|_cc| Ok(Box::new(ComparadorApp::default()))),
|
||||
Box::new(|_cc| {
|
||||
let config = Config::carregar();
|
||||
Ok(Box::new(ComparadorApp::from_config(config)))
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ComparadorApp {
|
||||
arquivo_txt: Option<String>,
|
||||
arquivo_xls: Option<String>,
|
||||
@@ -32,6 +70,30 @@ struct ComparadorApp {
|
||||
mostrar_confirmacao_saida: bool,
|
||||
}
|
||||
|
||||
impl ComparadorApp {
|
||||
fn from_config(config: Config) -> Self {
|
||||
Self {
|
||||
arquivo_txt: config.ultimo_arquivo_txt,
|
||||
arquivo_xls: config.ultimo_arquivo_xls,
|
||||
resultado: String::new(),
|
||||
divergencias: Vec::new(),
|
||||
cpfs_so_txt: Vec::new(),
|
||||
cpfs_so_xls: Vec::new(),
|
||||
erros_validacao: Vec::new(),
|
||||
processando: false,
|
||||
mostrar_confirmacao_saida: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn salvar_config(&self) {
|
||||
let config = Config {
|
||||
ultimo_arquivo_txt: self.arquivo_txt.clone(),
|
||||
ultimo_arquivo_xls: self.arquivo_xls.clone(),
|
||||
};
|
||||
config.salvar();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ErroValidacao {
|
||||
cpf: String,
|
||||
@@ -105,6 +167,7 @@ impl eframe::App for ComparadorApp {
|
||||
self.arquivo_txt = Some(path.display().to_string());
|
||||
self.resultado.clear();
|
||||
self.divergencias.clear();
|
||||
self.salvar_config();
|
||||
}
|
||||
}
|
||||
if let Some(ref path) = self.arquivo_txt {
|
||||
@@ -124,6 +187,7 @@ impl eframe::App for ComparadorApp {
|
||||
self.arquivo_xls = Some(path.display().to_string());
|
||||
self.resultado.clear();
|
||||
self.divergencias.clear();
|
||||
self.salvar_config();
|
||||
}
|
||||
}
|
||||
if let Some(ref path) = self.arquivo_xls {
|
||||
@@ -157,6 +221,10 @@ impl eframe::App for ComparadorApp {
|
||||
ui.separator();
|
||||
ui.add_space(10.0);
|
||||
|
||||
// Scroll global para todos os resultados
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink([false, false])
|
||||
.show(ui, |ui| {
|
||||
// Resultados
|
||||
if !self.resultado.is_empty() {
|
||||
ui.label(&self.resultado);
|
||||
@@ -168,39 +236,35 @@ impl eframe::App for ComparadorApp {
|
||||
ui.heading(format!("📋 Divergências de valores: {}", self.divergencias.len()));
|
||||
ui.add_space(5.0);
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(200.0)
|
||||
egui::Grid::new("divergencias_grid")
|
||||
.striped(true)
|
||||
.min_col_width(100.0)
|
||||
.show(ui, |ui| {
|
||||
egui::Grid::new("divergencias_grid")
|
||||
.striped(true)
|
||||
.min_col_width(100.0)
|
||||
.show(ui, |ui| {
|
||||
// Cabeçalho
|
||||
ui.strong("CPF");
|
||||
ui.strong("Nome");
|
||||
ui.strong("TXT (R$)");
|
||||
ui.strong("XLS (R$)");
|
||||
ui.strong("Diferença (R$)");
|
||||
ui.strong("Diferença (%)");
|
||||
ui.end_row();
|
||||
|
||||
// Dados
|
||||
for div in &self.divergencias {
|
||||
ui.label(&div.cpf);
|
||||
ui.label(&div.nome);
|
||||
ui.label(Self::formatar_valor(div.valor_txt));
|
||||
ui.label(Self::formatar_valor(div.valor_xls));
|
||||
|
||||
let cor = if div.diferenca > 0.0 {
|
||||
egui::Color32::RED
|
||||
} else {
|
||||
egui::Color32::GREEN
|
||||
};
|
||||
ui.colored_label(cor, Self::formatar_valor(div.diferenca));
|
||||
ui.colored_label(cor, format!("{:+.1}%", div.percentual));
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
// Cabeçalho
|
||||
ui.strong("CPF");
|
||||
ui.strong("Nome");
|
||||
ui.strong("TXT (R$)");
|
||||
ui.strong("XLS (R$)");
|
||||
ui.strong("Diferença (R$)");
|
||||
ui.strong("Diferença (%)");
|
||||
ui.end_row();
|
||||
|
||||
// Dados
|
||||
for div in &self.divergencias {
|
||||
ui.label(&div.cpf);
|
||||
ui.label(&div.nome);
|
||||
ui.label(Self::formatar_valor(div.valor_txt));
|
||||
ui.label(Self::formatar_valor(div.valor_xls));
|
||||
|
||||
let cor = if div.diferenca > 0.0 {
|
||||
egui::Color32::RED
|
||||
} else {
|
||||
egui::Color32::GREEN
|
||||
};
|
||||
ui.colored_label(cor, Self::formatar_valor(div.diferenca));
|
||||
ui.colored_label(cor, format!("{:+.1}%", div.percentual));
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(10.0);
|
||||
@@ -214,25 +278,21 @@ impl eframe::App for ComparadorApp {
|
||||
ui.label("Estes CPFs estão no DMED mas não aparecem no Prosoft");
|
||||
ui.add_space(5.0);
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(150.0)
|
||||
egui::Grid::new("cpfs_txt_grid")
|
||||
.striped(true)
|
||||
.min_col_width(100.0)
|
||||
.show(ui, |ui| {
|
||||
egui::Grid::new("cpfs_txt_grid")
|
||||
.striped(true)
|
||||
.min_col_width(100.0)
|
||||
.show(ui, |ui| {
|
||||
ui.strong("CPF");
|
||||
ui.strong("Nome");
|
||||
ui.strong("Valor (R$)");
|
||||
ui.end_row();
|
||||
|
||||
for cpf in &self.cpfs_so_txt {
|
||||
ui.label(&cpf.cpf);
|
||||
ui.label(&cpf.nome);
|
||||
ui.label(Self::formatar_valor(cpf.valor));
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
ui.strong("CPF");
|
||||
ui.strong("Nome");
|
||||
ui.strong("Valor (R$)");
|
||||
ui.end_row();
|
||||
|
||||
for cpf in &self.cpfs_so_txt {
|
||||
ui.label(&cpf.cpf);
|
||||
ui.label(&cpf.nome);
|
||||
ui.label(Self::formatar_valor(cpf.valor));
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(10.0);
|
||||
@@ -246,23 +306,19 @@ impl eframe::App for ComparadorApp {
|
||||
ui.label("Estes CPFs estão no Prosoft mas não aparecem no DMED");
|
||||
ui.add_space(5.0);
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(150.0)
|
||||
egui::Grid::new("cpfs_xls_grid")
|
||||
.striped(true)
|
||||
.min_col_width(100.0)
|
||||
.show(ui, |ui| {
|
||||
egui::Grid::new("cpfs_xls_grid")
|
||||
.striped(true)
|
||||
.min_col_width(100.0)
|
||||
.show(ui, |ui| {
|
||||
ui.strong("CPF");
|
||||
ui.strong("Valor (R$)");
|
||||
ui.end_row();
|
||||
|
||||
for cpf in &self.cpfs_so_xls {
|
||||
ui.label(&cpf.cpf);
|
||||
ui.label(Self::formatar_valor(cpf.valor));
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
ui.strong("CPF");
|
||||
ui.strong("Valor (R$)");
|
||||
ui.end_row();
|
||||
|
||||
for cpf in &self.cpfs_so_xls {
|
||||
ui.label(&cpf.cpf);
|
||||
ui.label(Self::formatar_valor(cpf.valor));
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(10.0);
|
||||
@@ -276,27 +332,23 @@ impl eframe::App for ComparadorApp {
|
||||
ui.label("Estes registros possuem problemas que precisam ser corrigidos");
|
||||
ui.add_space(5.0);
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(150.0)
|
||||
egui::Grid::new("erros_validacao_grid")
|
||||
.striped(true)
|
||||
.min_col_width(100.0)
|
||||
.show(ui, |ui| {
|
||||
egui::Grid::new("erros_validacao_grid")
|
||||
.striped(true)
|
||||
.min_col_width(100.0)
|
||||
.show(ui, |ui| {
|
||||
ui.strong("CPF");
|
||||
ui.strong("Nome");
|
||||
ui.strong("Valor (R$)");
|
||||
ui.strong("Erro");
|
||||
ui.end_row();
|
||||
|
||||
for erro in &self.erros_validacao {
|
||||
ui.label(&erro.cpf);
|
||||
ui.label(&erro.nome);
|
||||
ui.label(Self::formatar_valor(erro.valor));
|
||||
ui.colored_label(egui::Color32::RED, &erro.tipo_erro);
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
ui.strong("CPF");
|
||||
ui.strong("Nome");
|
||||
ui.strong("Valor (R$)");
|
||||
ui.strong("Erro");
|
||||
ui.end_row();
|
||||
|
||||
for erro in &self.erros_validacao {
|
||||
ui.label(&erro.cpf);
|
||||
ui.label(&erro.nome);
|
||||
ui.label(Self::formatar_valor(erro.valor));
|
||||
ui.colored_label(egui::Color32::RED, &erro.tipo_erro);
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(10.0);
|
||||
@@ -321,6 +373,7 @@ impl eframe::App for ComparadorApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
}); // Fecha o ScrollArea
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user