Extended budgets and limits [skip-ci]

This commit is contained in:
James Cole 2014-07-20 20:46:10 +02:00
parent 08cbd91dd9
commit 988046189d
9 changed files with 199 additions and 95 deletions

View File

@ -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()

View File

@ -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();

View File

@ -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;

View File

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

View File

@ -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'])

View File

@ -0,0 +1,84 @@
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<table class="table table-bordered table-striped">
<tr>
<th>Budget</th>
<th>Current envelope(s)</th>
<th>&nbsp;</th>
</tr>
@foreach($budgets as $budget)
<tr>
<td>
<a href="{{route('budgets.show',$budget->id)}}">{{{$budget->name}}}</a>
</td>
<td>
<div class="row">
<div class="col-sm-2">
<small>Envelope</small>
</div>
<div class="col-sm-2">
<small>Left</small>
</div>
</div>
@foreach($budget->limits as $limit)
@foreach($limit->limitrepetitions as $index => $rep)
<div class="row">
<div class="col-sm-2">
<span class="label label-primary">
<span class="glyphicon glyphicon-envelope"></span>
{{mf($rep->amount,false)}}</span>
</div>
<div class="col-sm-2">
@if($rep->left() < 0)
<span class="label label-danger">
<span class="glyphicon glyphicon-envelope"></span>
{{mf($rep->left(),false)}}</span>
@else
<span class="label label-success">
<span class="glyphicon glyphicon-envelope"></span>
{{mf($rep->left(),false)}}</span>
@endif
</div>
<div class="col-sm-3">
<small>
@if($limit->repeat_freq == 'monthly')
{{$rep->startdate->format('F Y')}}
@else
NO FORMAT
@endif
</small>
</div>
@if($limit->repeats == 1)
<div class="col-sm-2">
<span class="label label-warning">auto repeats</span>
</div>
@endif
<div class="col-sm-2 @if($limit->repeats == 0) col-sm-offset-2 @endif">
<a href="#" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
@if($limit->repeats == 0 || ($limit->repeats == 1 && $index == 0))
<a href="#" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
@endif
</div>
</div>
@endforeach
@endforeach
<p style="margin-top:5px;">
<a href="{{route('budgets.limits.create',$budget->id)}}" class="btn btn-default btn-xs"><span
class="glyphicon-plus-sign glyphicon"></span> Add another limit</a>
</p>
</td>
<td>
<div class="btn-group btn-group-sm">
<a href="#" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
<a href="#" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
</div>
</td>
</tr>
@endforeach
</table>
</div>
</div>

View File

@ -0,0 +1,43 @@
@foreach($reps as $date => $data)
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<h3>{{$data['date']}}</h3>
<table class="table table-bordered table-striped">
<tr>
<th style="width:45%;">Budget</th>
<th style="width:15%;">Envelope</th>
<th style="width:15%;">Left</th>
<th>&nbsp;</th>
</tr>
@foreach($data['limitrepetitions'] as $index => $rep)
<tr>
<td>
<a href="{{route('budgets.show',$rep->limit->budget->id)}}">{{{$rep->limit->budget->name}}}</a>
</td>
<td>
<span class="label label-primary">
<span class="glyphicon glyphicon-envelope"></span> {{mf($rep->amount,false)}}</span>
</td>
<td>
@if($rep->left() < 0)
<span class="label label-danger">
<span class="glyphicon glyphicon-envelope"></span>
{{mf($rep->left(),false)}}</span>
@else
<span class="label label-success">
<span class="glyphicon glyphicon-envelope"></span>
{{mf($rep->left(),false)}}</span>
@endif
</td>
<td>
<a href="{{route('budgets.limits.delete',$rep->limit->id)}}" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
@if($rep->limit->repeats == 1)
<span class="label label-warning">auto repeats</span>
@endif
</td>
</tr>
@endforeach
</table>
</div>
</div>
@endforeach

View File

@ -11,92 +11,19 @@
budgets,
which means that for each period of time (for example a month) a virtual "envelope" can be created
containing a certain amount of money. Money spent within a budget is removed from the envelope.
</p>
<p>
@if($group == 'budget')
<a class="btn btn-default" href ="{{route('budgets.index','date')}}"><span class="glyphicon glyphicon-th-list"></span> Group by date</a>
@else
<a class="btn btn-default" href ="{{route('budgets.index','budget')}}"><span class="glyphicon glyphicon-th-list"></span> Group by budget</a>
@endif
</p>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<table class="table table-bordered table-striped">
<tr>
<th>Budget</th>
<th>Current envelope(s)</th>
<th>&nbsp;</th>
</tr>
@foreach($budgets as $budget)
<tr>
<td>
<a href="{{route('budgets.show',$budget->id)}}">{{{$budget->name}}}</a>
</td>
<td>
<div class="row">
<div class="col-sm-2">
<small>Envelope</small>
</div>
<div class="col-sm-2">
<small>Left</small>
</div>
</div>
@foreach($budget->limits as $limit)
@foreach($limit->limitrepetitions as $index => $rep)
<div class="row">
<div class="col-sm-2">
<span class="label label-primary">
<span class="glyphicon glyphicon-envelope"></span>
{{mf($rep->amount,false)}}</span>
</div>
<div class="col-sm-2">
@if($rep->left() < 0)
<span class="label label-danger">
<span class="glyphicon glyphicon-envelope"></span>
{{mf($rep->left(),false)}}</span>
@else
<span class="label label-success">
<span class="glyphicon glyphicon-envelope"></span>
{{mf($rep->left(),false)}}</span>
@endif
</div>
<div class="col-sm-3">
<small>
@if($limit->repeat_freq == 'monthly')
{{$rep->startdate->format('F Y')}}
@else
NO FORMAT
@endif
</small>
</div>
@if($limit->repeats == 1)
<div class="col-sm-2">
<span class="label label-warning">auto repeats</span>
</div>
@endif
<div class="col-sm-2 @if($limit->repeats == 0) col-sm-offset-2 @endif">
<a href="#" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
@if($limit->repeats == 0 || ($limit->repeats == 1 && $index == 0))
<a href="#" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
@endif
</div>
</div>
@endforeach
@endforeach
<p style="margin-top:5px;">
<a href="{{route('budgets.limits.create',$budget->id)}}" class="btn btn-default btn-xs"><span
class="glyphicon-plus-sign glyphicon"></span> Add another limit</a>
</p>
</td>
<td>
<div class="btn-group btn-group-sm">
<a href="#" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
<a href="#" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
</div>
</td>
</tr>
@endforeach
</table>
</div>
</div>
@if($group == 'budget')
@include('budgets.index-budget')
@else
@include('budgets.index-date')
@endif
@stop

View File

@ -19,7 +19,7 @@
</div>
</div>
{{Form::open(['class' => 'form-horizontal','url' => route('limits.store')])}}
{{Form::open(['class' => 'form-horizontal','url' => route('budgets.limits.store')])}}
<div class="row">
<div class="col-lg-6 col-md-12 col-sm-6">