Fix grand_total calculation from card totals

Calculate grand_total from card totals instead of products to ensure consistency.
This commit is contained in:
2026-03-23 16:21:58 +01:00
parent 03f643ba82
commit 3bb65ca7f6

View File

@@ -149,6 +149,11 @@ impl PreparedCustomer {
}) })
.collect(); .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(); let mut product_totals: HashMap<String, (f64, f64)> = HashMap::new();
for card in &cards { for card in &cards {
for tx in &card.transactions { for tx in &card.transactions {
@@ -182,11 +187,6 @@ impl PreparedCustomer {
.map(|p| p.volume.parse::<f64>().unwrap()) .map(|p| p.volume.parse::<f64>().unwrap())
.sum(); .sum();
let grand_total: f64 = products
.iter()
.map(|p| p.amount.parse::<f64>().unwrap())
.sum();
let summary = Summary { let summary = Summary {
total_volume: fmt(total_volume), total_volume: fmt(total_volume),
grand_total: fmt(grand_total), grand_total: fmt(grand_total),