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);
$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;
}

View File

@ -79,18 +79,16 @@ class HomeController extends Controller
return 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();