Lots of stuff for budgets, accounts and others!

This commit is contained in:
Sander Dorigo 2014-11-05 19:57:56 +01:00
parent aaab7f8e0e
commit 21f362c7b9
11 changed files with 151 additions and 66 deletions

View File

@ -356,6 +356,9 @@ class AccountController extends BaseController
case 'Beneficiary account':
$data['what'] = 'expense';
break;
case 'Revenue account':
$data['what'] = 'revenue';
break;
}
switch (Input::get('post_submit_action')) {
@ -363,14 +366,14 @@ class AccountController extends BaseController
throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
break;
case 'create_another':
case 'store':
case 'update':
$messages = $acct->validate($data);
/** @var MessageBag $messages ['errors'] */
if ($messages['errors']->count() > 0) {
Session::flash('warnings', $messages['warnings']);
Session::flash('successes', $messages['successes']);
Session::flash('error', 'Could not save account: ' . $messages['errors']->first());
return Redirect::route('accounts.create', $data['what'])->withInput()->withErrors($messages['errors']);
return Redirect::route('accounts.edit', $account->id)->withInput()->withErrors($messages['errors']);
}
// store!
$acct->update($account, $data);

View File

@ -5,6 +5,7 @@ use Firefly\Exception\FireflyException;
use Firefly\Helper\Controllers\BudgetInterface as BI;
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
use FireflyIII\Exception\NotImplementedException;
use Illuminate\Support\MessageBag;
class BudgetController extends BaseController
@ -36,7 +37,7 @@ class BudgetController extends BaseController
public function amount(Budget $budget)
{
$amount = intval(Input::get('amount'));
$date = Session::get('start');
$date = Session::get('start');
/** @var \Limit $limit */
$limit = $budget->limits()->where('startdate', $date->format('Y-m-d'))->first();
if (!$limit) {
@ -57,10 +58,10 @@ class BudgetController extends BaseController
}
// try to find the limit repetition for this limit:
$repetition = $limit->limitrepetitions()->first();
if($repetition) {
return Response::json(['name' => $budget->name,'repetition' => $repetition->id]);
if ($repetition) {
return Response::json(['name' => $budget->name, 'repetition' => $repetition->id]);
} else {
return Response::json(['name' => $budget->name,'repetition' => null]);
return Response::json(['name' => $budget->name, 'repetition' => null]);
}
}
@ -82,7 +83,7 @@ class BudgetController extends BaseController
foreach ($budgets as $budget) {
$budget->spent = $repos->spentInMonth($budget, $date);
$budget->pct = 0;
$budget->pct = 0;
$budget->limit = 0;
/** @var \Limit $limit */
@ -91,8 +92,8 @@ class BudgetController extends BaseController
foreach ($limit->limitrepetitions as $repetition) {
if ($repetition->startdate == $date) {
$budget->currentRep = $repetition;
$budget->limit = floatval($repetition->amount);
if($budget->limit > $budget->spent) {
$budget->limit = floatval($repetition->amount);
if ($budget->limit > $budget->spent) {
// not overspent:
$budget->pct = 30;
} else {
@ -109,6 +110,9 @@ class BudgetController extends BaseController
return View::make('budgets.index', compact('budgets'))->with('budgetAmount', $budgetAmount);
}
/**
* @return $this
*/
public function updateIncome()
{
$date = Session::get('start');
@ -118,6 +122,21 @@ class BudgetController extends BaseController
return View::make('budgets.income')->with('amount', $budgetAmount)->with('date', $date);
}
/**
* @param Budget $budget
* @param LimitRepetition $repetition
*
* @return \Illuminate\View\View
*/
public function show(Budget $budget, LimitRepetition $repetition = null)
{
if (!is_null($repetition) && $repetition->limit->budget->id != $budget->id) {
App::abort(500);
}
return View::make('budgets.show');
}
@ -152,13 +171,17 @@ class BudgetController extends BaseController
//// return Redirect::route('budgets.index.budget');
//
// }
// public function edit(Budget $budget)
// {
// throw new NotImplementedException;
//// return View::make('budgets.edit')->with('budget', $budget)
//// ->with('subTitle', 'Edit budget "' . $budget->name . '"');
//
// }
/**
* @param Budget $budget
*
* @return $this
*/
public function edit(Budget $budget)
{
Session::flash('prefilled', ['name' => $budget->name]);
return View::make('budgets.edit')->with('budget', $budget)->with('subTitle', 'Edit budget "' . $budget->name . '"');
}
// /**
// * @return $this|\Illuminate\View\View
@ -267,13 +290,50 @@ class BudgetController extends BaseController
//
// }
//
// /**
// * @param Budget $budget
// *
// * @return $this|\Illuminate\Http\RedirectResponse
// */
// public function update(Budget $budget)
// {
/**
* @param Budget $budget
*
* @throws FireflyException
*/
public function update(Budget $budget)
{
/** @var \FireflyIII\Database\Budget $repos */
$repos = App::make('FireflyIII\Database\Budget');
$data = Input::except('_token');
switch (Input::get('post_submit_action')) {
default:
throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
break;
case 'create_another':
case 'update':
$messages = $repos->validate($data);
/** @var MessageBag $messages ['errors'] */
if ($messages['errors']->count() > 0) {
Session::flash('warnings', $messages['warnings']);
Session::flash('successes', $messages['successes']);
Session::flash('error', 'Could not save account: ' . $messages['errors']->first());
return Redirect::route('budgets.edit', $budget->id)->withInput()->withErrors($messages['errors']);
}
// store!
$repos->update($budget, $data);
Session::flash('success', 'Account updated!');
if ($data['post_submit_action'] == 'create_another') {
return Redirect::route('budgets.edit', $budget->id);
} else {
return Redirect::route('budgets.edit', $budget->id);
}
case 'validate_only':
$messageBags = $repos->validate($data);
Session::flash('warnings', $messageBags['warnings']);
Session::flash('successes', $messageBags['successes']);
Session::flash('errors', $messageBags['errors']);
return Redirect::route('budgets.edit', $budget->id)->withInput();
break;
}
// $budget = $this->_repository->update($budget, Input::all());
// if ($budget->validate()) {
// Event::fire('budgets.update', [$budget]);
@ -290,7 +350,7 @@ class BudgetController extends BaseController
// return Redirect::route('budgets.edit', $budget->id)->withInput()->withErrors($budget->errors());
// }
//
// }
}
// public function nobudget($view = 'session') {
// switch($view) {

View File

@ -126,9 +126,6 @@ class EloquentLimitTrigger
// remove and recreate limit repetitions.
// if limit is not repeating, simply update the repetition to match the limit,
// even though deleting everything is easier.
foreach ($limit->limitrepetitions()->get() as $l) {
$l->delete();
}
$limit->createRepetition($limit->startdate);
return true;

View File

@ -2,6 +2,7 @@
namespace FireflyIII\Database;
use Carbon\Carbon;
use FireflyIII\Exception\NotImplementedException;
use Illuminate\Support\MessageBag;
use LaravelBook\Ardent\Ardent;
use Illuminate\Support\Collection;
@ -74,7 +75,7 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
*/
public function validate(array $model)
{
// TODO: Implement validate() method.
throw new NotImplementedException;
}
/**

View File

@ -115,6 +115,12 @@ class Limit extends Ardent
if (isset($repetition->id)) {
\Event::fire('limits.repetition', [$repetition]);
}
} else if($count == 1) {
// update this one:
$repetition = $this->limitrepetitions()->where('startdate', $start->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->first();
$repetition->amount = $this->amount;
$repetition->save();
}
}

View File

@ -144,11 +144,11 @@ Route::group(
#Route::get('/budgets/date', ['uses' => 'BudgetController@indexByDate', 'as' => 'budgets.index.date']);
#Route::get('/budgets/budget', ['uses' => 'BudgetController@indexByBudget', 'as' => 'budgets.index.budget']);
#Route::get('/budgets/create', ['uses' => 'BudgetController@create', 'as' => 'budgets.create']);
Route::get('/budgets/create', ['uses' => 'BudgetController@create', 'as' => 'budgets.create']);
#Route::get('/budgets/nobudget/{period}', ['uses' => 'BudgetController@nobudget', 'as' => 'budgets.nobudget']);
#Route::get('/budgets/edit/{budget}', ['uses' => 'BudgetController@edit', 'as' => 'budgets.edit']);
#Route::get('/budgets/delete/{budget}', ['uses' => 'BudgetController@delete', 'as' => 'budgets.delete']);
Route::get('/budgets/edit/{budget}', ['uses' => 'BudgetController@edit', 'as' => 'budgets.edit']);
Route::get('/budgets/delete/{budget}', ['uses' => 'BudgetController@delete', 'as' => 'budgets.delete']);
// category controller:
Route::get('/categories', ['uses' => 'CategoryController@index', 'as' => 'categories.index']);
@ -276,8 +276,9 @@ Route::group(
// budget controller:
Route::post('/budgets/income', ['uses' => 'BudgetController@postUpdateIncome', 'as' => 'budgets.postIncome']);
Route::post('/budgets/update/{budget}', ['uses' => 'BudgetController@update', 'as' => 'budgets.update']);
#Route::post('/budgets/store', ['uses' => 'BudgetController@store', 'as' => 'budgets.store']);
#Route::post('/budgets/update/{budget}', ['uses' => 'BudgetController@update', 'as' => 'budgets.update']);
#Route::post('/budgets/destroy/{budget}', ['uses' => 'BudgetController@destroy', 'as' => 'budgets.destroy']);
// category controller

View File

@ -45,7 +45,7 @@
<i class="fa fa-bolt"></i> Options
</div>
<div class="panel-body">
{{Form::ffOptionsList('create','account')}}
{{Form::ffOptionsList('update','account')}}
</div>
</div>

View File

@ -7,40 +7,34 @@
</div>
{{Form::open(['class' => 'form-horizontal','url' => route('budgets.update',$budget->id)])}}
{{Form::hidden('from',e(Input::get('from')))}}
<div class="row">
<div class="col-lg-6 col-md-12 col-sm-6">
<h4>Mandatory fields</h4>
<div class="form-group">
<label for="name" class="col-sm-4 control-label">Name</label>
<div class="col-sm-8">
<input type="text" name="name" class="form-control" id="name" value="{{Input::old('name') ?: $budget->name}}" placeholder="Name">
@if($errors->has('name'))
<p class="text-danger">{{$errors->first('name')}}</p>
@else
<span class="help-block">For example: groceries, bills</span>
@endif
<div class="panel panel-primary">
<div class="panel-heading">
<i class="fa fa-fw fa-exclamation"></i> Mandatory fields
</div>
<div class="panel-body">
{{Form::ffText('name')}}
</div>
</div>
<p>
<button type="submit" class="btn btn-lg btn-success">
<i class="fa fa-pencil"></i> Update budget
</button>
</p>
</div>
</div><!-- TODO cleanup to match new theme & form -->
<div class="row">
<div class="col-lg-6 col-md-12 col-sm-6">
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<button type="submit" class="btn btn-default btn-success">Update the budget</button>
<!-- panel for options -->
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-bolt"></i> Options
</div>
<div class="panel-body">
{{Form::ffOptionsList('update','budget')}}
</div>
</div>
</div>
</div>
{{Form::close()}}

View File

@ -29,7 +29,6 @@
</div>
</div>
<h3></h3>
</div>
<div class="col-lg-3 col-sm-4 col-md-4">
<!-- time based navigation -->
@ -39,7 +38,7 @@
<div class="row">
@foreach($budgets as $budget)
<div class="col-lg-3 col-sm-4 col-md-6">
<div class="col-lg-3 col-sm-4 col-md-6" style="height:180px;">
<div class="panel panel-default">
<div class="panel-heading">
@if($budget->currentRep)
@ -47,6 +46,22 @@
@else
<a href="{{route('budgets.show',$budget->id)}}" id="budget-link-{{$budget->id}}">{{{$budget->name}}}</a>
@endif
<!-- ACTIONS MENU -->
<div class="pull-right">
<div class="btn-group">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
Actions
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-right" role="menu">
<li><a href="{{route('budgets.edit',$budget->id)}}"><i class="fa fa-pencil fa-fw"></i> Edit</a></li>
<li><a href="{{route('budgets.delete',$budget->id)}}"><i class="fa fa-trash fa-fw"></i> Delete</a></li>
</ul>
</div>
</div>
</div>
<div class="panel-body">
<!-- the range in which the budget can be set -->
@ -75,7 +90,7 @@
@else
<span id="budget-description-{{$budget->id}}"><em>No budget</em></span>
<span id="budget-info-{{$budget->id}}">
<span class="text-success" style="display:none;">&euro;</span> <input style="display:none;" data-id="{{$budget->id}}" type="number" min="0" max="900" step="1" value="0" style="width:50px;color:#3c763d;" />
<span class="text-success" style="display:none;">&euro;</span> <input data-id="{{$budget->id}}" type="number" min="0" max="900" step="1" value="0" style="width:50px;color:#3c763d;display:none;" />
</span>
@endif
</span>
@ -86,8 +101,16 @@
</div>
</div>
</div>
@endforeach
<div class="col-lg-3 col-sm-4 col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
Create budget
</div>
<div class="panel-body">
<a href="{{route('budgets.create')}}" class="btn btn-success">Create new budget</a>
</div>
</div>
</div>

View File

@ -17,7 +17,7 @@
</div>
<p>
<button type="submit" class="btn btn-lg btn-success">
<i class="fa fa-plus-circle"></i> Store new piggy bank
<i class="fa fa-pencil"></i> Update piggy bank
</button>
</p>
</div>

View File

@ -9,16 +9,16 @@ if (!function_exists('mf')) {
$string = number_format($n, 2, ',', '.');
if ($coloured === true && $n === 0.0) {
return '<span style="color:#999">&#128; ' . $string . '</span>';
return '<span style="color:#999">&#8364; ' . $string . '</span>';
}
if ($coloured === true && $n > 0) {
return '<span class="text-success">&#128; ' . $string . '</span>';
return '<span class="text-success">&#8364; ' . $string . '</span>';
}
if ($coloured === true && $n < 0) {
return '<span class="text-danger">&#128; ' . $string . '</span>';
return '<span class="text-danger">&#8364; ' . $string . '</span>';
}
return '&#128; ' . $string;
return '&#8364; ' . $string;
}
}