diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php index 1b3c466bd2..8dedc33674 100644 --- a/app/controllers/BudgetController.php +++ b/app/controllers/BudgetController.php @@ -13,13 +13,54 @@ class BudgetController extends BaseController View::share('menu', 'budgets'); } - public function index() + public function index($group = null) { - $budgets = $this->_budgets->get(); - $today = new \Carbon\Carbon; + + $opts = ['date', 'budget']; + $group = in_array($group, $opts) ? $group : 'date'; + + switch ($group) { + case 'date': + // get a list of dates by getting all repetitions: + $budgets = $this->_budgets->get(); + $reps = []; + foreach ($budgets as $budget) { + foreach ($budget->limits as $limit) { + foreach ($limit->limitrepetitions as $rep) { + + $monthOrder = $rep->startdate->format('Y-m'); + $month = $rep->startdate->format('F Y'); + $reps[$monthOrder] = isset($reps[$monthOrder]) ? $reps[$monthOrder] : ['date' => $month]; + + } + } + } + // put all the budgets under their respective date: + foreach ($budgets as $budget) { + foreach ($budget->limits as $limit) { + foreach ($limit->limitrepetitions as $rep) { + $month = $rep->startdate->format('Y-m'); + $reps[$month]['limitrepetitions'][] = $rep; + } + } + } + krsort($reps); + + return View::make('budgets.index')->with('group', $group)->with('reps',$reps); + + + break; + case 'budget': + $budgets = $this->_budgets->get(); + $today = new \Carbon\Carbon; + return View::make('budgets.index')->with('budgets', $budgets)->with('today', $today)->with( + 'group', $group + ); + + break; + } - return View::make('budgets.index')->with('budgets', $budgets)->with('today', $today); } public function create() diff --git a/app/controllers/LimitController.php b/app/controllers/LimitController.php index de01c8d4a4..07d6f739c3 100644 --- a/app/controllers/LimitController.php +++ b/app/controllers/LimitController.php @@ -39,7 +39,7 @@ class LimitController extends BaseController { // find a limit with these properties, as we might already have one: $limit = $this->_limits->store(Input::all()); - if($limit->id) { + if ($limit->id) { return Redirect::route('budgets.index'); } else { return Redirect::route('budgets.limits.create')->withInput(); diff --git a/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php b/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php index 6212c410ab..30eedc9402 100644 --- a/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php +++ b/app/lib/Firefly/Storage/Limit/EloquentLimitRepository.php @@ -11,6 +11,13 @@ namespace Firefly\Storage\Limit; class EloquentLimitRepository implements LimitRepositoryInterface { + + public function find($limitId) + { + return \Limit::with('limitrepetitions')->where('limits.id', $limitId)->leftJoin('components', 'components.id', '=', 'limits.component_id') + ->where('components.user_id', \Auth::user()->id)->first(); + } + public function store($data) { $budget = \Budget::find($data['budget_id']); @@ -74,8 +81,7 @@ class EloquentLimitRepository implements LimitRepositoryInterface { $type = \TransactionType::where('type', 'Withdrawal')->first(); - $result = $budget->transactionjournals()->after($start)-> - before($end)->get(); + $result = $budget->transactionjournals()->after($start)->before($end)->get(); return $result; diff --git a/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php b/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php index 5d2b651348..dda40f2d39 100644 --- a/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php +++ b/app/lib/Firefly/Storage/Limit/LimitRepositoryInterface.php @@ -9,4 +9,6 @@ interface LimitRepositoryInterface public function store($data); public function getTJByBudgetAndDateRange(\Budget $budget, \Carbon\Carbon $start, \Carbon\Carbon $end); + + public function find($limitId); } \ No newline at end of file diff --git a/app/routes.php b/app/routes.php index 83df9a0cc5..45e888e7e1 100644 --- a/app/routes.php +++ b/app/routes.php @@ -27,12 +27,13 @@ Route::group(['before' => 'auth'], function () { Route::get('/accounts/{account}', ['uses' => 'AccountController@show', 'as' => 'accounts.show']); // budget controller: - Route::get('/budgets',['uses' => 'BudgetController@index','as' => 'budgets.index']); + Route::get('/budgets/{group?}',['uses' => 'BudgetController@index','as' => 'budgets.index']); Route::get('/budget/create',['uses' => 'BudgetController@create', 'as' => 'budgets.create']); Route::get('/budget/show/{id}',['uses' => 'BudgetController@show', 'as' => 'budgets.show']); // limit controller: Route::get('/budgets/limits/create/{id?}',['uses' => 'LimitController@create','as' => 'budgets.limits.create']); + Route::get('/budgets/limits/delete/{id?}',['uses' => 'LimitController@delete','as' => 'budgets.limits.delete']); // JSON controller: Route::get('/json/beneficiaries', ['uses' => 'JsonController@beneficiaries', 'as' => 'json.beneficiaries']); @@ -71,7 +72,7 @@ Route::group(['before' => 'csrf|auth'], function () { Route::get('/accounts/store', ['uses' => 'AccountController@store', 'as' => 'accounts.store']); // limit controller: - Route::post('/limits/store', ['uses' => 'LimitController@store', 'as' => 'limits.store']); + Route::post('/limits/store', ['uses' => 'LimitController@store', 'as' => 'budgets.limits.store']); // transaction controller: Route::post('/transactions/store/{what}', ['uses' => 'TransactionController@store', 'as' => 'transactions.store']) diff --git a/app/views/budgets/index-budget.blade.php b/app/views/budgets/index-budget.blade.php new file mode 100644 index 0000000000..7a9116bd68 --- /dev/null +++ b/app/views/budgets/index-budget.blade.php @@ -0,0 +1,84 @@ +
Budget | +Current envelope(s) | ++ |
---|---|---|
+ {{{$budget->name}}} + + | +
+
+
+ @foreach($budget->limits as $limit)
+ @foreach($limit->limitrepetitions as $index => $rep)
+
+ Envelope
+
+
+ Left
+
+
+
+ @endforeach
+ @endforeach
+
+
+
+
+ {{mf($rep->amount,false)}}
+
+
+ @if($rep->left() < 0)
+
+
+ {{mf($rep->left(),false)}}
+ @else
+
+
+ {{mf($rep->left(),false)}}
+ @endif
+
+
+
+ @if($limit->repeat_freq == 'monthly')
+ {{$rep->startdate->format('F Y')}}
+ @else
+ NO FORMAT
+ @endif
+
+
+ @if($limit->repeats == 1)
+
+ auto repeats
+
+ @endif
+
+ |
+ + + | +
Budget | +Envelope | +Left | ++ |
---|---|---|---|
+ {{{$rep->limit->budget->name}}} + | ++ + {{mf($rep->amount,false)}} + | ++ @if($rep->left() < 0) + + + {{mf($rep->left(),false)}} + @else + + + {{mf($rep->left(),false)}} + @endif + | ++ + @if($rep->limit->repeats == 1) + auto repeats + @endif + | +
+ @if($group == 'budget') + Group by date + @else + Group by budget + @endif
-Budget | -Current envelope(s) | -- |
---|---|---|
- {{{$budget->name}}} - - | -
-
-
- @foreach($budget->limits as $limit)
- @foreach($limit->limitrepetitions as $index => $rep)
-
- Envelope
-
-
- Left
-
-
-
- @endforeach
- @endforeach
-
-
-
-
- {{mf($rep->amount,false)}}
-
-
- @if($rep->left() < 0)
-
-
- {{mf($rep->left(),false)}}
- @else
-
-
- {{mf($rep->left(),false)}}
- @endif
-
-
-
- @if($limit->repeat_freq == 'monthly')
- {{$rep->startdate->format('F Y')}}
- @else
- NO FORMAT
- @endif
-
-
- @if($limit->repeats == 1)
-
- auto repeats
-
- @endif
-
- |
- - - | -