mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 20:38:57 +00:00
Allow piggy bank edit/update.
This commit is contained in:
@@ -529,34 +529,49 @@ class PiggybankController extends BaseController
|
|||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * @param Piggybank $piggyBank
|
* @param Piggybank $piggyBank
|
||||||
// *
|
*
|
||||||
// * @return $this|\Illuminate\Http\RedirectResponse
|
* @return $this|\Illuminate\Http\RedirectResponse
|
||||||
// */
|
*/
|
||||||
public function update(Piggybank $piggyBank)
|
public function update(Piggybank $piggyBank)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException;
|
|
||||||
// $piggyBank = $this->_repository->update($piggyBank, Input::all());
|
/** @var \FireflyIII\Database\Piggybank $repos */
|
||||||
// if ($piggyBank->validate()) {
|
$repos = App::make('FireflyIII\Database\Piggybank');
|
||||||
// if ($piggyBank->repeats == 1) {
|
$data = Input::except('_token');
|
||||||
// $route = 'piggybanks.index.repeated';
|
|
||||||
// $message = 'Repeated expense';
|
switch (Input::get('post_submit_action')) {
|
||||||
// } else {
|
default:
|
||||||
// $route = 'piggybanks.index.piggybanks';
|
throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
|
||||||
// $message = 'Piggy bank';
|
break;
|
||||||
// }
|
case 'create_another':
|
||||||
//
|
case 'update':
|
||||||
//
|
$messages = $repos->validate($data);
|
||||||
// Session::flash('success', $message . ' "' . $piggyBank->name . '" updated.');
|
/** @var MessageBag $messages ['errors'] */
|
||||||
// Event::fire('piggybanks.update', [$piggyBank]);
|
if ($messages['errors']->count() > 0) {
|
||||||
//
|
Session::flash('warnings', $messages['warnings']);
|
||||||
// return Redirect::route($route);
|
Session::flash('successes', $messages['successes']);
|
||||||
// } else {
|
Session::flash('error', 'Could not save piggy bank: ' . $messages['errors']->first());
|
||||||
// Session::flash('error', 'Could not update piggy bank: ' . $piggyBank->errors()->first());
|
return Redirect::route('piggybanks.edit', $piggyBank->id)->withInput()->withErrors($messages['errors']);
|
||||||
//
|
}
|
||||||
// return Redirect::route('piggybanks.edit', $piggyBank->id)->withErrors($piggyBank->errors())->withInput();
|
// store!
|
||||||
// }
|
$repos->update($piggyBank, $data);
|
||||||
|
Session::flash('success', 'Piggy bank updated!');
|
||||||
|
|
||||||
|
if ($data['post_submit_action'] == 'create_another') {
|
||||||
|
return Redirect::route('piggybanks.edit', $piggyBank->id);
|
||||||
|
} else {
|
||||||
|
return Redirect::route('piggybanks.index');
|
||||||
|
}
|
||||||
|
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('piggybanks.edit', $piggyBank->id)->withInput();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,6 +231,20 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface
|
|||||||
*/
|
*/
|
||||||
public function update(Ardent $model, array $data)
|
public function update(Ardent $model, array $data)
|
||||||
{
|
{
|
||||||
// TODO: Implement update() method.
|
/** @var \Piggybank $model */
|
||||||
|
$model->name = $data['name'];
|
||||||
|
$model->account_id = intval($data['account_id']);
|
||||||
|
$model->targetamount = floatval($data['targetamount']);
|
||||||
|
$model->targetdate = isset($data['targetdate']) && $data['targetdate'] != '' ? $data['targetdate'] : null;
|
||||||
|
$model->rep_every = isset($data['rep_every']) ? $data['rep_every'] : 0;
|
||||||
|
$model->reminder_skip = isset($data['reminder_skip']) ? $data['reminder_skip'] : 0;
|
||||||
|
$model->order = isset($data['order']) ? $data['order'] : 0;
|
||||||
|
$model->remind_me = isset($data['remind_me']) ? intval($data['remind_me']) : 0;
|
||||||
|
if(!$model->validate()) {
|
||||||
|
var_dump($model->errors());
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
$model->save();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
<i class="fa fa-bolt"></i> Options
|
<i class="fa fa-bolt"></i> Options
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{{Form::ffOptionsList('create','piggy bank')}}
|
{{Form::ffOptionsList('update','piggy bank')}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user