2014-07-29 13:30:50 -05:00
|
|
|
<?php
|
|
|
|
|
2014-08-06 10:02:02 -05:00
|
|
|
use Firefly\Storage\RecurringTransaction\RecurringTransactionRepositoryInterface as RTR;
|
|
|
|
|
2014-08-02 00:34:38 -05:00
|
|
|
class RecurringController extends BaseController
|
|
|
|
{
|
2014-08-06 10:02:02 -05:00
|
|
|
protected $_repository;
|
2014-08-07 00:44:37 -05:00
|
|
|
|
2014-08-06 10:02:02 -05:00
|
|
|
public function __construct(RTR $repository)
|
|
|
|
{
|
|
|
|
$this->_repository = $repository;
|
|
|
|
View::share('menu', 'home');
|
|
|
|
}
|
2014-08-07 00:44:37 -05:00
|
|
|
|
2014-07-29 13:30:50 -05:00
|
|
|
public function create()
|
|
|
|
{
|
2014-08-07 00:44:37 -05:00
|
|
|
$periods = \Config::get('firefly.periods_to_text');
|
|
|
|
|
|
|
|
return View::make('recurring.create')->with('periods', $periods);
|
2014-07-29 13:30:50 -05:00
|
|
|
}
|
|
|
|
|
2014-08-07 00:44:37 -05:00
|
|
|
public function delete(RecurringTransaction $recurringTransaction)
|
2014-07-29 13:30:50 -05:00
|
|
|
{
|
2014-08-07 00:44:37 -05:00
|
|
|
return View::make('recurring.delete')->with('recurringTransaction', $recurringTransaction);
|
2014-07-29 13:30:50 -05:00
|
|
|
}
|
|
|
|
|
2014-08-07 00:44:37 -05:00
|
|
|
public function destroy(RecurringTransaction $recurringTransaction)
|
2014-07-29 13:30:50 -05:00
|
|
|
{
|
2014-08-07 00:44:37 -05:00
|
|
|
$result = $this->_repository->destroy($recurringTransaction);
|
|
|
|
if ($result === true) {
|
|
|
|
Session::flash('success', 'The recurring transaction was deleted.');
|
|
|
|
} else {
|
|
|
|
Session::flash('error', 'Could not delete the recurring transaction. Check the logs to be sure.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return Redirect::route('recurring.index');
|
|
|
|
|
2014-07-29 13:30:50 -05:00
|
|
|
}
|
|
|
|
|
2014-08-08 23:12:49 -05:00
|
|
|
public function edit(RecurringTransaction $recurringTransaction)
|
2014-07-29 13:30:50 -05:00
|
|
|
{
|
2014-08-08 23:12:49 -05:00
|
|
|
$periods = \Config::get('firefly.periods_to_text');
|
|
|
|
|
|
|
|
return View::make('recurring.edit')->with('periods', $periods)->with(
|
|
|
|
'recurringTransaction', $recurringTransaction
|
|
|
|
);
|
2014-07-29 13:30:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
2014-08-06 10:02:02 -05:00
|
|
|
$list = $this->_repository->get();
|
2014-08-07 00:44:37 -05:00
|
|
|
|
|
|
|
return View::make('recurring.index')->with('list', $list);
|
2014-07-29 13:30:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function show()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function store()
|
|
|
|
{
|
2014-08-07 00:44:37 -05:00
|
|
|
$recurringTransaction = $this->_repository->store(Input::all());
|
2014-08-10 04:30:14 -05:00
|
|
|
if ($recurringTransaction->validate()) {
|
2014-08-07 00:44:37 -05:00
|
|
|
Session::flash('success', 'Recurring transaction "' . $recurringTransaction->name . '" saved!');
|
|
|
|
if (Input::get('create') == '1') {
|
|
|
|
return Redirect::route('recurring.create')->withInput();
|
|
|
|
} else {
|
|
|
|
return Redirect::route('recurring.index');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Session::flash(
|
|
|
|
'error', 'Could not save the recurring transaction: ' . $recurringTransaction->errors()->first()
|
|
|
|
);
|
|
|
|
|
|
|
|
return Redirect::route('recurring.create')->withInput()->withErrors($recurringTransaction->errors());
|
|
|
|
}
|
2014-07-29 13:30:50 -05:00
|
|
|
}
|
|
|
|
|
2014-08-08 23:12:49 -05:00
|
|
|
public function update(RecurringTransaction $recurringTransaction)
|
2014-07-29 13:30:50 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|