mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Delete and update routines.
This commit is contained in:
@@ -18,6 +18,9 @@ class BudgetController extends BaseController
|
|||||||
View::share('mainTitleIcon', 'fa-tasks');
|
View::share('mainTitleIcon', 'fa-tasks');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
public function postUpdateIncome()
|
public function postUpdateIncome()
|
||||||
{
|
{
|
||||||
/** @var \Firefly\Helper\Preferences\PreferencesHelperInterface $preferences */
|
/** @var \Firefly\Helper\Preferences\PreferencesHelperInterface $preferences */
|
||||||
@@ -141,40 +144,35 @@ class BudgetController extends BaseController
|
|||||||
return View::make('budgets.show');
|
return View::make('budgets.show');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
return View::make('budgets.create')->with('subTitle', 'Create a new budget');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Budget $budget
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function delete(Budget $budget)
|
||||||
|
{
|
||||||
|
return View::make('budgets.delete')->with('budget', $budget)->with('subTitle', 'Delete budget "' . $budget->name . '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(Budget $budget)
|
||||||
|
{
|
||||||
|
/** @var \FireflyIII\Database\Budget $repos */
|
||||||
|
$repos = App::make('FireflyIII\Database\Budget');
|
||||||
|
// remove budget
|
||||||
|
$repos->destroy($budget);
|
||||||
|
Session::flash('success', 'The budget was deleted.');
|
||||||
|
return Redirect::route('budgets.index');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// public function create()
|
|
||||||
// {
|
|
||||||
// throw new NotImplementedException;
|
|
||||||
//// $periods = \Config::get('firefly.periods_to_text');
|
|
||||||
////
|
|
||||||
//// return View::make('budgets.create')->with('periods', $periods)->with('subTitle', 'Create a new budget');
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public function delete(Budget $budget)
|
|
||||||
// {
|
|
||||||
// throw new NotImplementedException;
|
|
||||||
//// return View::make('budgets.delete')->with('budget', $budget)
|
|
||||||
//// ->with('subTitle', 'Delete budget "' . $budget->name . '"');
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public function destroy(Budget $budget)
|
|
||||||
// {
|
|
||||||
// throw new NotImplementedException;
|
|
||||||
//// // remove budget
|
|
||||||
//// Event::fire('budgets.destroy', [$budget]); // just before deletion.
|
|
||||||
//// $this->_repository->destroy($budget);
|
|
||||||
//// Session::flash('success', 'The budget was deleted.');
|
|
||||||
////
|
|
||||||
//// // redirect:
|
|
||||||
//// if (Input::get('from') == 'date') {
|
|
||||||
//// return Redirect::route('budgets.index');
|
|
||||||
//// }
|
|
||||||
//// return Redirect::route('budgets.index.budget');
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
/**
|
/**
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
*
|
*
|
||||||
@@ -266,33 +264,48 @@ class BudgetController extends BaseController
|
|||||||
// ->with('subTitle', 'Overview for ' . $title);
|
// ->with('subTitle', 'Overview for ' . $title);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// /**
|
/**
|
||||||
// * @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
// */
|
*/
|
||||||
// public function store()
|
public function store()
|
||||||
// {
|
{
|
||||||
//
|
/** @var \FireflyIII\Database\Budget $repos */
|
||||||
// $budget = $this->_repository->store(Input::all());
|
$repos = App::make('FireflyIII\Database\Budget');
|
||||||
// if ($budget->validate()) {
|
$data = Input::except('_token');
|
||||||
// Event::fire('budgets.store', [$budget]);
|
|
||||||
// Session::flash('success', 'Budget created!');
|
switch ($data['post_submit_action']) {
|
||||||
//
|
default:
|
||||||
// if (Input::get('create') == '1') {
|
throw new FireflyException('Cannot handle post_submit_action "' . e($data['post_submit_action']) . '"');
|
||||||
// return Redirect::route('budgets.create', ['from' => Input::get('from')]);
|
break;
|
||||||
// }
|
case 'create_another':
|
||||||
//
|
case 'store':
|
||||||
// if (Input::get('from') == 'date') {
|
$messages = $repos->validate($data);
|
||||||
// return Redirect::route('budgets.index');
|
/** @var MessageBag $messages ['errors'] */
|
||||||
// } else {
|
if ($messages['errors']->count() > 0) {
|
||||||
// return Redirect::route('budgets.index.budget');
|
Session::flash('warnings', $messages['warnings']);
|
||||||
// }
|
Session::flash('successes', $messages['successes']);
|
||||||
// } else {
|
Session::flash('error', 'Could not save budget: ' . $messages['errors']->first());
|
||||||
// Session::flash('error', 'Could not save the new budget');
|
return Redirect::route('budgets.create')->withInput()->withErrors($messages['errors']);
|
||||||
//
|
}
|
||||||
// return Redirect::route('budgets.create')->withInput()->withErrors($budget->errors());
|
// store!
|
||||||
// }
|
$repos->store($data);
|
||||||
//
|
Session::flash('success', 'New budget stored!');
|
||||||
// }
|
|
||||||
|
if ($data['post_submit_action'] == 'create_another') {
|
||||||
|
return Redirect::route('budgets.create');
|
||||||
|
} else {
|
||||||
|
return Redirect::route('budgets.index');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
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.create')->withInput();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
//
|
//
|
||||||
/**
|
/**
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
@@ -317,7 +330,7 @@ class BudgetController extends BaseController
|
|||||||
if ($messages['errors']->count() > 0) {
|
if ($messages['errors']->count() > 0) {
|
||||||
Session::flash('warnings', $messages['warnings']);
|
Session::flash('warnings', $messages['warnings']);
|
||||||
Session::flash('successes', $messages['successes']);
|
Session::flash('successes', $messages['successes']);
|
||||||
Session::flash('error', 'Could not save account: ' . $messages['errors']->first());
|
Session::flash('error', 'Could not save budget: ' . $messages['errors']->first());
|
||||||
return Redirect::route('budgets.edit', $budget->id)->withInput()->withErrors($messages['errors']);
|
return Redirect::route('budgets.edit', $budget->id)->withInput()->withErrors($messages['errors']);
|
||||||
}
|
}
|
||||||
// store!
|
// store!
|
||||||
|
@@ -49,7 +49,8 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
|
|||||||
*/
|
*/
|
||||||
public function destroy(Ardent $model)
|
public function destroy(Ardent $model)
|
||||||
{
|
{
|
||||||
// TODO: Implement destroy() method.
|
$model->delete();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,7 +76,34 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
|
|||||||
*/
|
*/
|
||||||
public function validate(array $model)
|
public function validate(array $model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException;
|
$warnings = new MessageBag;
|
||||||
|
$successes = new MessageBag;
|
||||||
|
$errors = new MessageBag;
|
||||||
|
|
||||||
|
if(isset($model['name'])) {
|
||||||
|
if(strlen($model['name']) < 1) {
|
||||||
|
$errors->add('name', 'Name is too short');
|
||||||
|
}
|
||||||
|
if(strlen($model['name']) > 200) {
|
||||||
|
$errors->add('name', 'Name is too long');
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$errors->add('name', 'Name is mandatory');
|
||||||
|
}
|
||||||
|
$validator = \Validator::make([$model], \Budget::$rules);
|
||||||
|
if ($validator->invalid()) {
|
||||||
|
$errors->merge($errors);
|
||||||
|
}
|
||||||
|
if(!$errors->has('name')) {
|
||||||
|
$successes->add('name','OK');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'errors' => $errors,
|
||||||
|
'warnings' => $warnings,
|
||||||
|
'successes' => $successes
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,7 +113,17 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
|
|||||||
*/
|
*/
|
||||||
public function store(array $data)
|
public function store(array $data)
|
||||||
{
|
{
|
||||||
// TODO: Implement store() method.
|
$data['user_id'] = $this->getUser()->id;
|
||||||
|
|
||||||
|
$budget = new \Budget($data);
|
||||||
|
$budget->class = 'Budget';
|
||||||
|
|
||||||
|
if (!$budget->validate()) {
|
||||||
|
var_dump($budget->errors()->all());
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$budget->save();
|
||||||
|
return $budget;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,6 +217,15 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
|
|||||||
*/
|
*/
|
||||||
public function update(Ardent $model, array $data)
|
public function update(Ardent $model, array $data)
|
||||||
{
|
{
|
||||||
// TODO: Implement update() method.
|
$model->name = $data['name'];
|
||||||
|
if (!$model->validate()) {
|
||||||
|
var_dump($model->errors()->all());
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$model->save();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -277,9 +277,8 @@ Route::group(
|
|||||||
// budget controller:
|
// budget controller:
|
||||||
Route::post('/budgets/income', ['uses' => 'BudgetController@postUpdateIncome', 'as' => 'budgets.postIncome']);
|
Route::post('/budgets/income', ['uses' => 'BudgetController@postUpdateIncome', 'as' => 'budgets.postIncome']);
|
||||||
Route::post('/budgets/update/{budget}', ['uses' => 'BudgetController@update', 'as' => 'budgets.update']);
|
Route::post('/budgets/update/{budget}', ['uses' => 'BudgetController@update', 'as' => 'budgets.update']);
|
||||||
#Route::post('/budgets/store', ['uses' => 'BudgetController@store', 'as' => 'budgets.store']);
|
Route::post('/budgets/store', ['uses' => 'BudgetController@store', 'as' => 'budgets.store']);
|
||||||
|
Route::post('/budgets/destroy/{budget}', ['uses' => 'BudgetController@destroy', 'as' => 'budgets.destroy']);
|
||||||
#Route::post('/budgets/destroy/{budget}', ['uses' => 'BudgetController@destroy', 'as' => 'budgets.destroy']);
|
|
||||||
|
|
||||||
// category controller
|
// category controller
|
||||||
Route::post('/categories/store', ['uses' => 'CategoryController@store', 'as' => 'categories.store']);
|
Route::post('/categories/store', ['uses' => 'CategoryController@store', 'as' => 'categories.store']);
|
||||||
|
@@ -1,118 +1,39 @@
|
|||||||
@extends('layouts.default')
|
@extends('layouts.default')
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
|
||||||
<p class="lead">Use budgets to organize and limit your expenses.</p>
|
|
||||||
<p class="text-info">
|
|
||||||
Firefly uses the <a href="http://en.wikipedia.org/wiki/Envelope_System" class="text-success">envelope system</a>. Every budget
|
|
||||||
is an envelope in which you put money every [period]. Expenses allocated to each budget are paid from this
|
|
||||||
(virtual) envelope.
|
|
||||||
</p>
|
|
||||||
<p class="text-info">
|
|
||||||
When the envelope is empty, you must stop spending on the budget. If the envelope still has some money left at the
|
|
||||||
end of the [period], congratulations! You have saved money!
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div><!-- TODO cleanup to match new theme & form -->
|
|
||||||
|
|
||||||
{{Form::open(['class' => 'form-horizontal','url' => route('budgets.store')])}}
|
{{Form::open(['class' => 'form-horizontal','url' => route('budgets.store')])}}
|
||||||
|
|
||||||
{{Form::hidden('from',e(Input::get('from')))}}
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||||
<h4>Mandatory fields</h4>
|
<div class="panel panel-primary">
|
||||||
|
<div class="panel-heading">
|
||||||
<div class="form-group">
|
<i class="fa fa-exclamation"></i> Mandatory fields
|
||||||
<label for="name" class="col-sm-4 control-label">Name</label>
|
</div>
|
||||||
<div class="col-sm-8">
|
<div class="panel-body">
|
||||||
<input type="text" name="name" class="form-control" id="name" value="{{Input::old('name')}}" placeholder="Name">
|
{{Form::ffText('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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<p>
|
||||||
|
<button type="submit" class="btn btn-lg btn-success">
|
||||||
|
<i class="fa fa-plus-circle"></i> Store new budget
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||||
<h4>Optional fields</h4>
|
<!-- panel for options -->
|
||||||
|
<div class="panel panel-default">
|
||||||
<div class="form-group">
|
<div class="panel-heading">
|
||||||
<label for="amount" class="col-sm-4 control-label">Max. amount</label>
|
<i class="fa fa-bolt"></i> Options
|
||||||
<div class="col-sm-8">
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-addon">€</span>
|
|
||||||
<input type="number" min="0.01" step="any" name="amount" class="form-control" id="amount" value="{{Input::old('amount')}}">
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
@if($errors->has('amount'))
|
{{Form::ffOptionsList('create','budget')}}
|
||||||
<p class="text-danger">{{$errors->first('amount')}}</p>
|
|
||||||
@else
|
|
||||||
<span class="help-block">What's the most you're willing to spend in this budget? This amount is "put" in the virtual
|
|
||||||
envelope.</span>
|
|
||||||
@endif
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="period" class="col-sm-4 control-label">Spending period</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
{{Form::select('repeat_freq',$periods,Input::old('repeat_freq') ?: 'monthly',['class' => 'form-control'])}}
|
|
||||||
@if($errors->has('repeat_freq'))
|
|
||||||
<p class="text-danger">{{$errors->first('repeat_freq')}}</p>
|
|
||||||
@else
|
|
||||||
<span class="help-block">How long will the envelope last? A week, a month, or even longer?</span>
|
|
||||||
@endif
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="period" class="col-sm-4 control-label">Repeat</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<div class="checkbox">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" value="1" name="repeats">
|
|
||||||
Repeat
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
@if($errors->has('repeats'))
|
|
||||||
<p class="text-danger">{{$errors->first('repeats')}}</p>
|
|
||||||
@else
|
|
||||||
<span class="help-block">If you want, Firefly can automatically recreate the "envelope" and fill it again
|
|
||||||
when the timespan above has expired. Be careful with this option though. It makes it easier
|
|
||||||
to <a href="http://en.wikipedia.org/wiki/Personal_budget#Concepts">fall back to old habits</a>.
|
|
||||||
Instead, you should recreate the envelope yourself each [period].</span>
|
|
||||||
@endif
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
|
||||||
|
|
||||||
<!-- add another after this one? -->
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="create" class="col-sm-4 control-label"> </label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<div class="checkbox">
|
|
||||||
<label>
|
|
||||||
{{Form::checkbox('create',1,Input::old('create') == '1')}}
|
|
||||||
Create another (return to this form)
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="col-sm-offset-4 col-sm-8">
|
|
||||||
<button type="submit" class="btn btn-default btn-success">Create the budget</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{Form::close()}}
|
{{Form::close()}}
|
||||||
|
|
||||||
|
@@ -1,42 +1,31 @@
|
|||||||
@extends('layouts.default')
|
@extends('layouts.default')
|
||||||
@section('content')
|
@section('content')
|
||||||
|
{{Form::open(['class' => 'form-horizontal','url' => route('budgets.destroy',$budget->id)])}}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||||
<p class="lead">
|
<div class="panel panel-red">
|
||||||
Remember that deleting something is permanent.
|
<div class="panel-heading">
|
||||||
</p>
|
Delete budget "{{{$budget->name}}}"
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<p>
|
||||||
|
Are you sure?
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
||||||
|
<a href="{{URL::previous()}}" class="btn-default btn">Cancel</a >
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{Form::open(['class' => 'form-horizontal','url' => route('budgets.destroy',$budget->id)])}}
|
|
||||||
{{Form::hidden('from',e(Input::get('from')))}}
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
|
||||||
@if($budget->transactionjournals()->count() > 0)
|
|
||||||
<p class="text-info">
|
|
||||||
|
|
||||||
Account "{{{$budget->name}}}" still has {{$budget->transactionjournals()->count()}} transaction(s) associated to it.
|
|
||||||
These will NOT be deleted but will lose their connection to the budget.
|
|
||||||
</p>
|
|
||||||
@endif
|
|
||||||
|
|
||||||
<p class="text-danger">
|
|
||||||
Press "Delete permanently" If you are sure you want to delete "{{{$budget->name}}}".
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div><!-- TODO cleanup to match new theme & form -->
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
|
|
||||||
@if(Input::get('from') == 'date')
|
|
||||||
<a href="{{route('budgets.index')}}" class="btn-default btn">Cancel</a>
|
|
||||||
@else
|
|
||||||
<a href="{{route('budgets.index.budget')}}" class="btn-default btn">Cancel</a>
|
|
||||||
@endif
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user