Sort chart and code cleanup [skip ci]

This commit is contained in:
James Cole
2015-08-02 07:41:47 +02:00
parent 80c0efe821
commit 5a77bef494
2 changed files with 29 additions and 18 deletions

View File

@@ -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);
$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) { foreach ($accounts as $account) {
$id = $account->id; if ($account->difference > 0) {
$startBalance = isset($startBalances[$id]) ? $startBalances[$id] : 0;
$endBalance = isset($endBalances[$id]) ? $endBalances[$id] : 0;
$diff = $endBalance - $startBalance;
if ($diff > 0) {
$data['labels'][] = $account->name; $data['labels'][] = $account->name;
$data['datasets'][0]['data'][] = $diff; $data['datasets'][0]['data'][] = $account->difference;
} }
} }
return $data; return $data;
} }

View File

@@ -79,18 +79,16 @@ class HomeController extends Controller
return redirect(route('new-user.index')); return redirect(route('new-user.index'));
} }
$title = 'Firefly'; $title = 'Firefly';
$subTitle = trans('firefly.welcomeBack'); $subTitle = trans('firefly.welcomeBack');
$mainTitleIcon = 'fa-fire'; $mainTitleIcon = 'fa-fire';
$transactions = []; $transactions = [];
$frontPage = Preferences::get('frontPageAccounts', []); $frontPage = Preferences::get('frontPageAccounts', []);
$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();