Reorder summary columns and calculate amount from volume * avg_price

Summary now shows: Produkt | Volym (L) | Snittpris/L | Belopp
Amount is calculated as volume * average_price instead of summing transactions.
This commit is contained in:
2026-03-23 16:16:54 +01:00
parent 611a471bf1
commit 03f643ba82
2 changed files with 11 additions and 10 deletions

View File

@@ -77,8 +77,8 @@ fn clean_csv_file(
struct ProductSummary {
name: String,
volume: String,
amount: String,
avg_price: String,
amount: String,
}
#[derive(Clone)]
@@ -149,11 +149,6 @@ impl PreparedCustomer {
})
.collect();
let grand_total: f64 = cards
.iter()
.map(|c| c.total_amount.parse::<f64>().unwrap())
.sum();
let mut product_totals: HashMap<String, (f64, f64)> = HashMap::new();
for card in &cards {
for tx in &card.transactions {
@@ -171,11 +166,12 @@ impl PreparedCustomer {
.into_iter()
.map(|(name, (volume, amount))| {
let avg_price = if volume > 0.0 { amount / volume } else { 0.0 };
let calculated_amount = volume * avg_price;
ProductSummary {
name,
volume: fmt(volume),
amount: fmt(amount),
avg_price: fmt(avg_price),
amount: fmt(calculated_amount),
}
})
.collect();
@@ -186,6 +182,11 @@ impl PreparedCustomer {
.map(|p| p.volume.parse::<f64>().unwrap())
.sum();
let grand_total: f64 = products
.iter()
.map(|p| p.amount.parse::<f64>().unwrap())
.sum();
let summary = Summary {
total_volume: fmt(total_volume),
grand_total: fmt(grand_total),