From 03f643ba822ce10ba21d9c711d286ca6d09fe152 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 23 Mar 2026 16:16:54 +0100 Subject: [PATCH] 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. --- src/main.rs | 15 ++++++++------- templates/customer.html | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index ed61b77..2085f59 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::().unwrap()) - .sum(); - let mut product_totals: HashMap = 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::().unwrap()) .sum(); + let grand_total: f64 = products + .iter() + .map(|p| p.amount.parse::().unwrap()) + .sum(); + let summary = Summary { total_volume: fmt(total_volume), grand_total: fmt(grand_total), diff --git a/templates/customer.html b/templates/customer.html index 6538601..5dea08b 100644 --- a/templates/customer.html +++ b/templates/customer.html @@ -152,8 +152,8 @@ Produkt Volym (L) - Belopp Snittpris/L + Belopp @@ -161,15 +161,15 @@ {{ product.name }} {{ product.volume }} - {{ product.amount }} Kr {{ product.avg_price }} Kr + {{ product.amount }} Kr {% endfor %} Totalt {{ customer.summary.total_volume }} - {{ customer.summary.grand_total }} Kr + {{ customer.summary.grand_total }} Kr