From 25a56d9f72dbce8cd20771697d855cd1f6da366c Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 23 Dec 2024 07:13:59 +0100 Subject: [PATCH] Chart no longer as a line chart. --- .../Controllers/Chart/AccountController.php | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 828c4ffe5f..cd7295f2f1 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -92,7 +92,7 @@ class AccountController extends Controller $cache->addProperty($end); $cache->addProperty('chart.account.expense-accounts'); if ($cache->has()) { - return response()->json($cache->get()); + return response()->json($cache->get()); } $start->subDay(); @@ -102,7 +102,7 @@ class AccountController extends Controller $tempData = []; // grab all accounts and names - $accounts = $this->accountRepository->getAccountsByType([AccountType::EXPENSE]); + $accounts = $this->accountRepository->getAccountsByType([AccountTypeEnum::EXPENSE->value]); $accountNames = $this->extractNames($accounts); // grab all balances @@ -133,6 +133,14 @@ class AccountController extends Controller } } } + // recreate currencies, but on ID instead of code. + $newCurrencies = []; + foreach($currencies as $currency) { + $newCurrencies[$currency->id] = $currency; + } + $currencies = $newCurrencies; + + // sort temp array by amount. $amounts = array_column($tempData, 'diff_float'); @@ -159,7 +167,7 @@ class AccountController extends Controller foreach ($tempData as $entry) { $currencyId = $entry['currency_id']; $name = $entry['name']; - $chartData[$currencyId]['entries'][$name] = $entry['difference']; + $chartData[$currencyId]['entries'][$name] = (float) $entry['difference']; } $data = $this->generator->multiSet($chartData); @@ -494,7 +502,7 @@ class AccountController extends Controller $cache->addProperty($end); $cache->addProperty('chart.account.revenue-accounts'); if ($cache->has()) { - return response()->json($cache->get()); + return response()->json($cache->get()); } $start->subDay(); @@ -511,6 +519,8 @@ class AccountController extends Controller $startBalances = app('steam')->finalAccountsBalance($accounts, $start); $endBalances = app('steam')->finalAccountsBalance($accounts, $end); + + // loop the end balances. This is an array for each account ($expenses) foreach ($endBalances as $accountId => $expenses) { $accountId = (int) $accountId; @@ -537,6 +547,13 @@ class AccountController extends Controller } } + // recreate currencies, but on ID instead of code. + $newCurrencies = []; + foreach($currencies as $currency) { + $newCurrencies[$currency->id] = $currency; + } + $currencies = $newCurrencies; + // sort temp array by amount. $amounts = array_column($tempData, 'diff_float'); array_multisort($amounts, SORT_ASC, $tempData);