From d5e1da594820ed4cbc4d91a45f1e07e2ead0ed6c Mon Sep 17 00:00:00 2001 From: Sander Dorigo Date: Wed, 29 Oct 2014 12:39:15 +0100 Subject: [PATCH] Some more stats on the piggy banks. --- app/controllers/PiggybankController.php | 36 +++++++++++++++---------- app/views/piggybanks/index.blade.php | 8 +++++- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php index 6f08e87c1f..71f4e572b3 100644 --- a/app/controllers/PiggybankController.php +++ b/app/controllers/PiggybankController.php @@ -62,7 +62,7 @@ class PiggybankController extends BaseController View::share('mainTitleIcon', 'fa-sort-amount-asc'); return View::make('piggybanks.create-piggybank')->with('accounts', $accounts) - ->with('periods', $periods); + ->with('periods', $periods); } /** @@ -148,14 +148,14 @@ class PiggybankController extends BaseController View::share('mainTitleIcon', 'fa-rotate-left'); return View::make('piggybanks.edit-repeated')->with('piggybank', $piggyBank)->with('accounts', $accounts) - ->with('periods', $periods); + ->with('periods', $periods); } else { // piggy bank. View::share('title', 'Piggy banks'); View::share('mainTitleIcon', 'fa-sort-amount-asc'); return View::make('piggybanks.edit-piggybank')->with('piggybank', $piggyBank)->with('accounts', $accounts) - ->with('periods', $periods); + ->with('periods', $periods); } @@ -196,11 +196,11 @@ class PiggybankController extends BaseController } break; } - if($piggyBank->repeats == 1) { - $route = 'piggybanks.index.repeated'; + if ($piggyBank->repeats == 1) { + $route = 'piggybanks.index.repeated'; } else { - $route = 'piggybanks.index.piggybanks'; + $route = 'piggybanks.index.piggybanks'; } return Redirect::route($route); } @@ -225,7 +225,15 @@ class PiggybankController extends BaseController $id = $account->id; if (!isset($accounts[$id])) { $account->leftOnAccount = $this->_repository->leftOnAccount($account); - $accounts[$id] = ['account' => $account, 'left' => $this->_repository->leftOnAccount($account)]; + $accounts[$id] = [ + 'account' => $account, + 'left' => $this->_repository->leftOnAccount($account), + 'tosave' => $piggybank->targetamount, + 'saved' => $piggybank->currentRelevantRep()->currentamount + ]; + } else { + $accounts[$id]['tosave'] += $piggybank->targetamount; + $accounts[$id]['saved'] += $piggybank->currentRelevantRep()->currentamount; } } @@ -234,9 +242,9 @@ class PiggybankController extends BaseController View::share('mainTitleIcon', 'fa-sort-amount-asc'); return View::make('piggybanks.index')->with('piggybanks', $piggybanks) - ->with('countRepeating', $countRepeating) - ->with('countNonRepeating', $countNonRepeating) - ->with('accounts', $accounts); + ->with('countRepeating', $countRepeating) + ->with('countNonRepeating', $countNonRepeating) + ->with('accounts', $accounts); } /** @@ -285,9 +293,9 @@ class PiggybankController extends BaseController return View::make('piggybanks.index')->with('piggybanks', $piggybanks) - ->with('countRepeating', $countRepeating) - ->with('countNonRepeating', $countNonRepeating) - ->with('accounts', $accounts); + ->with('countRepeating', $countRepeating) + ->with('countNonRepeating', $countNonRepeating) + ->with('accounts', $accounts); } /** @@ -311,7 +319,7 @@ class PiggybankController extends BaseController } return View::make('piggybanks.show')->with('piggyBank', $piggyBank)->with('leftOnAccount', $leftOnAccount) - ->with('balance', $balance); + ->with('balance', $balance); } /** diff --git a/app/views/piggybanks/index.blade.php b/app/views/piggybanks/index.blade.php index 5d905b2967..981d7bc1a2 100644 --- a/app/views/piggybanks/index.blade.php +++ b/app/views/piggybanks/index.blade.php @@ -186,17 +186,23 @@ --}}
-
+

Account information

+ + + @foreach($accounts as $account) + + + @endforeach
Account Left for piggy banksTotal planned savingsSaved so farLeft to save
{{{$account['account']->name}}} {{mf($account['left'])}}{{mf($account['tosave'])}}{{mf($account['saved'])}}{{mf($account['tosave']-$account['saved'])}}