Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Sort chart and code cleanup [skip ci]
James Cole5a77bef49414
diff --git a/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php b/app/Generator/Chart/Account/ChartJsAccountChartGenerator.phpindex f890916960..92abc7bb90 100644--- a/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php+++ b/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php@@ -63,17 +63,30 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator$startBalances = Steam::balancesById($ids, $start);$endBalances = Steam::balancesById($ids, $end);+ $accounts->each(+ function (Account $account) use ($startBalances, $endBalances) {+ $id = $account->id;+ $startBalance = isset($startBalances[$id]) ? $startBalances[$id] : 0;+ $endBalance = isset($endBalances[$id]) ? $endBalances[$id] : 0;+ $diff = $endBalance - $startBalance;+ $account->difference = round($diff, 2);+ }+ );++ $accounts = $accounts->sortByDesc(+ function (Account $account) {+ return $account->difference;+ }+ );+foreach ($accounts as $account) {- $id = $account->id;- $startBalance = isset($startBalances[$id]) ? $startBalances[$id] : 0;- $endBalance = isset($endBalances[$id]) ? $endBalances[$id] : 0;- $diff = $endBalance - $startBalance;- if ($diff > 0) {+ if ($account->difference > 0) {$data['labels'][] = $account->name;- $data['datasets'][0]['data'][] = $diff;+ $data['datasets'][0]['data'][] = $account->difference;}}+return $data;}diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.phpindex 9b9c5bef5e..5613809750 100644--- a/app/Http/Controllers/HomeController.php+++ b/app/Http/Controllers/HomeController.php@@ -79,18 +79,16 @@ class HomeController extends Controllerreturn redirect(route('new-user.index'));}- $title = 'Firefly';- $subTitle = trans('firefly.welcomeBack');- $mainTitleIcon = 'fa-fire';- $transactions = [];- $frontPage = Preferences::get('frontPageAccounts', []);- $start = Session::get('start', Carbon::now()->startOfMonth());- $end = Session::get('end', Carbon::now()->endOfMonth());- $showTour = Preferences::get('tour', true)->data;-- $accounts = $repository->getFrontpageAccounts($frontPage);- $savings = $repository->getSavingsAccounts();-+ $title = 'Firefly';+ $subTitle = trans('firefly.welcomeBack');+ $mainTitleIcon = 'fa-fire';+ $transactions = [];+ $frontPage = Preferences::get('frontPageAccounts', []);+ $start = Session::get('start', Carbon::now()->startOfMonth());+ $end = Session::get('end', Carbon::now()->endOfMonth());+ $showTour = Preferences::get('tour', true)->data;+ $accounts = $repository->getFrontpageAccounts($frontPage);+ $savings = $repository->getSavingsAccounts();$piggyBankAccounts = $repository->getPiggyBankAccounts();