From d5137e393d99536ac5149a2112ef6e00459fa45a Mon Sep 17 00:00:00 2001 From: lupus Date: Sat, 30 Aug 2025 12:30:49 +0200 Subject: [PATCH] Fix: Use amounts in base currency for customer charts (#403) Previously, the customer chart used the total/amount fields to calculate net profits/expenses/etc. If the currency the expense (for example) was created in differed from the base currency of the company, the chart would display wrong amounts. This change addresses the issue by always using the base currency field. --- .../V1/Admin/Customer/CustomerStatsController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/V1/Admin/Customer/CustomerStatsController.php b/app/Http/Controllers/V1/Admin/Customer/CustomerStatsController.php index f82aa001..1476a407 100644 --- a/app/Http/Controllers/V1/Admin/Customer/CustomerStatsController.php +++ b/app/Http/Controllers/V1/Admin/Customer/CustomerStatsController.php @@ -61,7 +61,7 @@ class CustomerStatsController extends Controller ) ->whereCompany() ->whereCustomer($customer->id) - ->sum('total') ?? 0 + ->sum('base_total') ?? 0 ); array_push( $expenseTotals, @@ -71,7 +71,7 @@ class CustomerStatsController extends Controller ) ->whereCompany() ->whereUser($customer->id) - ->sum('amount') ?? 0 + ->sum('base_amount') ?? 0 ); array_push( $receiptTotals, @@ -81,7 +81,7 @@ class CustomerStatsController extends Controller ) ->whereCompany() ->whereCustomer($customer->id) - ->sum('amount') ?? 0 + ->sum('base_amount') ?? 0 ); array_push( $netProfits, @@ -103,21 +103,21 @@ class CustomerStatsController extends Controller ) ->whereCompany() ->whereCustomer($customer->id) - ->sum('total'); + ->sum('base_total'); $totalReceipts = Payment::whereBetween( 'payment_date', [$startDate->format('Y-m-d'), $start->format('Y-m-d')] ) ->whereCompany() ->whereCustomer($customer->id) - ->sum('amount'); + ->sum('base_amount'); $totalExpenses = Expense::whereBetween( 'expense_date', [$startDate->format('Y-m-d'), $start->format('Y-m-d')] ) ->whereCompany() ->whereUser($customer->id) - ->sum('amount'); + ->sum('base_amount'); $netProfit = (int) $totalReceipts - (int) $totalExpenses; $chartData = [