mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-21 19:49:54 +00:00
Sort chart and code cleanup [skip ci]
This commit is contained in:
@@ -63,17 +63,30 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
|
|||||||
$startBalances = Steam::balancesById($ids, $start);
|
$startBalances = Steam::balancesById($ids, $start);
|
||||||
$endBalances = Steam::balancesById($ids, $end);
|
$endBalances = Steam::balancesById($ids, $end);
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
$accounts->each(
|
||||||
|
function (Account $account) use ($startBalances, $endBalances) {
|
||||||
$id = $account->id;
|
$id = $account->id;
|
||||||
$startBalance = isset($startBalances[$id]) ? $startBalances[$id] : 0;
|
$startBalance = isset($startBalances[$id]) ? $startBalances[$id] : 0;
|
||||||
$endBalance = isset($endBalances[$id]) ? $endBalances[$id] : 0;
|
$endBalance = isset($endBalances[$id]) ? $endBalances[$id] : 0;
|
||||||
$diff = $endBalance - $startBalance;
|
$diff = $endBalance - $startBalance;
|
||||||
if ($diff > 0) {
|
$account->difference = round($diff, 2);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$accounts = $accounts->sortByDesc(
|
||||||
|
function (Account $account) {
|
||||||
|
return $account->difference;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
if ($account->difference > 0) {
|
||||||
$data['labels'][] = $account->name;
|
$data['labels'][] = $account->name;
|
||||||
$data['datasets'][0]['data'][] = $diff;
|
$data['datasets'][0]['data'][] = $account->difference;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -87,10 +87,8 @@ class HomeController extends Controller
|
|||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
$showTour = Preferences::get('tour', true)->data;
|
$showTour = Preferences::get('tour', true)->data;
|
||||||
|
|
||||||
$accounts = $repository->getFrontpageAccounts($frontPage);
|
$accounts = $repository->getFrontpageAccounts($frontPage);
|
||||||
$savings = $repository->getSavingsAccounts();
|
$savings = $repository->getSavingsAccounts();
|
||||||
|
|
||||||
$piggyBankAccounts = $repository->getPiggyBankAccounts();
|
$piggyBankAccounts = $repository->getPiggyBankAccounts();
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user