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