Ensure grand_total is consistent with product calculations
Calculate grand_total from products (volume * avg_price), matching the product row calculations.
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -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 {
|
||||
@@ -187,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),
|
||||
|
||||
Reference in New Issue
Block a user