diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 00f8491e29..8e10e9f830 100644 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -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); diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php index 21aed96411..a564f1b7fa 100644 --- a/app/controllers/BudgetController.php +++ b/app/controllers/BudgetController.php @@ -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) { diff --git a/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.php b/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.php index bbdf2360c9..67f1e4dd03 100644 --- a/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.php +++ b/app/lib/Firefly/Trigger/Limits/EloquentLimitTrigger.php @@ -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; diff --git a/app/lib/FireflyIII/Database/Budget.php b/app/lib/FireflyIII/Database/Budget.php index 867237b802..d707f33adf 100644 --- a/app/lib/FireflyIII/Database/Budget.php +++ b/app/lib/FireflyIII/Database/Budget.php @@ -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; } /** diff --git a/app/models/Limit.php b/app/models/Limit.php index 0255c0429e..49571e2d25 100644 --- a/app/models/Limit.php +++ b/app/models/Limit.php @@ -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(); + } } diff --git a/app/routes.php b/app/routes.php index dc13af8700..83f840415a 100644 --- a/app/routes.php +++ b/app/routes.php @@ -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 diff --git a/app/views/accounts/edit.blade.php b/app/views/accounts/edit.blade.php index eccbd863a0..39e14486ca 100644 --- a/app/views/accounts/edit.blade.php +++ b/app/views/accounts/edit.blade.php @@ -45,7 +45,7 @@ Options
- {{Form::ffOptionsList('create','account')}} + {{Form::ffOptionsList('update','account')}}
diff --git a/app/views/budgets/edit.blade.php b/app/views/budgets/edit.blade.php index f179965866..baeeb1cc8c 100644 --- a/app/views/budgets/edit.blade.php +++ b/app/views/budgets/edit.blade.php @@ -7,40 +7,34 @@ {{Form::open(['class' => 'form-horizontal','url' => route('budgets.update',$budget->id)])}} - -{{Form::hidden('from',e(Input::get('from')))}} -
-

Mandatory fields

- -
- -
- - @if($errors->has('name')) -

{{$errors->first('name')}}

- @else - For example: groceries, bills - @endif +
+
+ Mandatory fields +
+
+ {{Form::ffText('name')}}
- +

+ +

- -
- -
- -
-
- + +
+
+ Options +
+
+ {{Form::ffOptionsList('update','budget')}}
- {{Form::close()}} diff --git a/app/views/budgets/index.blade.php b/app/views/budgets/index.blade.php index bdc4c703e1..82a035cfcf 100644 --- a/app/views/budgets/index.blade.php +++ b/app/views/budgets/index.blade.php @@ -29,7 +29,6 @@
-

@@ -39,7 +38,7 @@
@foreach($budgets as $budget) -
+
@if($budget->currentRep) @@ -47,6 +46,22 @@ @else {{{$budget->name}}} @endif + + + +
+
+ + +
+
+
@@ -75,7 +90,7 @@ @else No budget - + @endif @@ -86,8 +101,16 @@
- @endforeach +
+
+
+ Create budget +
+ +
diff --git a/app/views/piggybanks/edit.blade.php b/app/views/piggybanks/edit.blade.php index 69169a5279..3cdead892d 100644 --- a/app/views/piggybanks/edit.blade.php +++ b/app/views/piggybanks/edit.blade.php @@ -17,7 +17,7 @@

diff --git a/bootstrap/start.php b/bootstrap/start.php index 7edb58f2c9..1e76ce97dd 100644 --- a/bootstrap/start.php +++ b/bootstrap/start.php @@ -9,16 +9,16 @@ if (!function_exists('mf')) { $string = number_format($n, 2, ',', '.'); if ($coloured === true && $n === 0.0) { - return '€ ' . $string . ''; + return '€ ' . $string . ''; } if ($coloured === true && $n > 0) { - return '€ ' . $string . ''; + return '€ ' . $string . ''; } if ($coloured === true && $n < 0) { - return '€ ' . $string . ''; + return '€ ' . $string . ''; } - return '€ ' . $string; + return '€ ' . $string; } }