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 { struct ProductSummary {
name: String, name: String,
volume: String, volume: String,
amount: String,
avg_price: String, avg_price: String,
amount: String,
} }
#[derive(Clone)] #[derive(Clone)]
@@ -149,11 +149,6 @@ 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 {
@@ -171,11 +166,12 @@ impl PreparedCustomer {
.into_iter() .into_iter()
.map(|(name, (volume, amount))| { .map(|(name, (volume, amount))| {
let avg_price = if volume > 0.0 { amount / volume } else { 0.0 }; let avg_price = if volume > 0.0 { amount / volume } else { 0.0 };
let calculated_amount = volume * avg_price;
ProductSummary { ProductSummary {
name, name,
volume: fmt(volume), volume: fmt(volume),
amount: fmt(amount),
avg_price: fmt(avg_price), avg_price: fmt(avg_price),
amount: fmt(calculated_amount),
} }
}) })
.collect(); .collect();
@@ -186,6 +182,11 @@ 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),

View File

@@ -152,8 +152,8 @@
<tr> <tr>
<th>Produkt</th> <th>Produkt</th>
<th>Volym (L)</th> <th>Volym (L)</th>
<th>Belopp</th>
<th>Snittpris/L</th> <th>Snittpris/L</th>
<th>Belopp</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -161,15 +161,15 @@
<tr> <tr>
<td>{{ product.name }}</td> <td>{{ product.name }}</td>
<td>{{ product.volume }}</td> <td>{{ product.volume }}</td>
<td>{{ product.amount }} Kr</td>
<td>{{ product.avg_price }} Kr</td> <td>{{ product.avg_price }} Kr</td>
<td>{{ product.amount }} Kr</td>
</tr> </tr>
{% endfor %} {% endfor %}
<tr class="grand-total-row"> <tr class="grand-total-row">
<td>Totalt</td> <td>Totalt</td>
<td>{{ customer.summary.total_volume }}</td> <td>{{ customer.summary.total_volume }}</td>
<td>{{ customer.summary.grand_total }} Kr</td>
<td></td> <td></td>
<td>{{ customer.summary.grand_total }} Kr</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>