feat: adicionar formatação de valores e estatísticas no comparador DMED
This commit is contained in:
Vendored
BIN
Binary file not shown.
@@ -165,6 +165,8 @@ fn salvar_relatorio(
|
||||
cpfs_so_txt: usize,
|
||||
cpfs_so_xls: usize,
|
||||
) -> std::io::Result<()> {
|
||||
let _ = mapa_xls;
|
||||
let _ = mapa_txt;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
|
||||
+45
-8
@@ -150,15 +150,15 @@ impl eframe::App for ComparadorApp {
|
||||
for div in &self.divergencias {
|
||||
ui.label(&div.cpf);
|
||||
ui.label(&div.nome);
|
||||
ui.label(format!("{:.2}", div.valor_txt));
|
||||
ui.label(format!("{:.2}", div.valor_xls));
|
||||
|
||||
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, format!("{:.2}", div.diferenca));
|
||||
ui.colored_label(cor, Self::formatar_valor(div.diferenca));
|
||||
ui.colored_label(cor, format!("{:+.1}%", div.percentual));
|
||||
ui.end_row();
|
||||
}
|
||||
@@ -191,7 +191,7 @@ impl eframe::App for ComparadorApp {
|
||||
for cpf in &self.cpfs_so_txt {
|
||||
ui.label(&cpf.cpf);
|
||||
ui.label(&cpf.nome);
|
||||
ui.label(format!("{:.2}", cpf.valor));
|
||||
ui.label(Self::formatar_valor(cpf.valor));
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
@@ -221,7 +221,7 @@ impl eframe::App for ComparadorApp {
|
||||
|
||||
for cpf in &self.cpfs_so_xls {
|
||||
ui.label(&cpf.cpf);
|
||||
ui.label(format!("{:.2}", cpf.valor));
|
||||
ui.label(Self::formatar_valor(cpf.valor));
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
@@ -254,6 +254,31 @@ impl eframe::App for ComparadorApp {
|
||||
}
|
||||
|
||||
impl ComparadorApp {
|
||||
fn formatar_valor(valor: f64) -> String {
|
||||
let valor_abs = valor.abs();
|
||||
let inteiro = valor_abs.trunc() as u64;
|
||||
let decimal = ((valor_abs - inteiro as f64) * 100.0).round() as u64;
|
||||
|
||||
// Formata a parte inteira com separador de milhares
|
||||
let inteiro_str = inteiro.to_string();
|
||||
let mut formatado = String::new();
|
||||
let len = inteiro_str.len();
|
||||
|
||||
for (i, c) in inteiro_str.chars().enumerate() {
|
||||
if i > 0 && (len - i) % 3 == 0 {
|
||||
formatado.push('.');
|
||||
}
|
||||
formatado.push(c);
|
||||
}
|
||||
|
||||
// Adiciona o sinal se for negativo
|
||||
if valor < 0.0 {
|
||||
format!("-{},{:02}", formatado, decimal)
|
||||
} else {
|
||||
format!("{},{:02}", formatado, decimal)
|
||||
}
|
||||
}
|
||||
|
||||
fn comparar(&mut self) {
|
||||
self.processando = true;
|
||||
self.resultado.clear();
|
||||
@@ -295,6 +320,9 @@ impl ComparadorApp {
|
||||
.collect();
|
||||
|
||||
// Estatísticas
|
||||
let total_txt: f64 = pessoas_txt.iter().map(|p| p.valor).sum();
|
||||
let total_xls: f64 = pessoas_xls.iter().map(|p| p.valor).sum();
|
||||
|
||||
let cpfs_ambos = mapa_txt.keys()
|
||||
.filter(|cpf| mapa_xls.contains_key(**cpf))
|
||||
.count();
|
||||
@@ -361,6 +389,7 @@ impl ComparadorApp {
|
||||
self.cpfs_so_xls.sort_by(|a, b| a.cpf.cmp(&b.cpf));
|
||||
|
||||
// Resultado
|
||||
let diferenca_total = total_txt - total_xls;
|
||||
self.resultado = format!(
|
||||
"📊 Estatísticas:\n\
|
||||
• Total TXT: {} registros\n\
|
||||
@@ -368,13 +397,21 @@ impl ComparadorApp {
|
||||
• CPFs em ambos: {}\n\
|
||||
• Apenas no TXT: {}\n\
|
||||
• Apenas no XLS: {}\n\
|
||||
• Divergências: {} CPFs com diferenças",
|
||||
• Divergências: {} CPFs com diferenças\n\
|
||||
\n\
|
||||
💰 Valores Totais:\n\
|
||||
• Soma TXT: R$ {}\n\
|
||||
• Soma XLS: R$ {}\n\
|
||||
• Diferença: R$ {}",
|
||||
pessoas_txt.len(),
|
||||
pessoas_xls.len(),
|
||||
cpfs_ambos,
|
||||
cpfs_so_txt,
|
||||
cpfs_so_xls,
|
||||
self.divergencias.len()
|
||||
self.divergencias.len(),
|
||||
Self::formatar_valor(total_txt),
|
||||
Self::formatar_valor(total_xls),
|
||||
Self::formatar_valor(diferenca_total)
|
||||
);
|
||||
|
||||
self.processando = false;
|
||||
|
||||
Reference in New Issue
Block a user