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.
This commit is contained in:
lupus
2025-08-30 12:30:49 +02:00
committed by GitHub
parent 20caf7ef5b
commit d5137e393d

View File

@@ -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 = [