Various updates [skip ci]

This commit is contained in:
James Cole
2014-07-30 22:31:35 +02:00
parent 00a767cfc9
commit 78d575fbb1
13 changed files with 411 additions and 263 deletions

View File

@@ -82,6 +82,7 @@ class BudgetController extends BaseController
*/
public function indexByDate()
{
Event::fire('budgets.change');
// get a list of dates by getting all repetitions:
$set = $this->_repository->get();
$budgets = $this->_budgets->organizeByDate($set);

View File

@@ -29,48 +29,75 @@ class LimitController extends BaseController
*
* @return $this|\Illuminate\View\View
*/
public function create($budgetId = null)
public function create(\Budget $budget = null)
{
$periods = \Config::get('firefly.periods_to_text');
$prefilled = [
'startdate' => Input::get('startdate') ? : date('Y-m-d'),
'repeat_freq' => Input::get('repeat_freq') ? : 'monthly'
'repeat_freq' => Input::get('repeat_freq') ? : 'monthly',
'budget_id' => $budget ? $budget->id : null
];
$budgets = $this->_budgets->getAsSelectList();
return View::make('limits.create')->with('budgets', $budgets)->with('budget_id', $budgetId)->with(
return View::make('limits.create')->with('budgets', $budgets)->with(
'periods', $periods
)->with('prefilled', $prefilled);
}
public function delete(\Limit $limit)
{
return View::make('limits.delete')->with('limit', $limit);
}
public function destroy($limitId)
{
$limit = $this->_limits->find($limitId);
if ($limit) {
$limit->delete();
return Redirect::route('budgets.index');
} else {
return View::make('error')->with('message', 'No such limit!');
}
}
/**
* @param null $limitId
*
* @return $this|\Illuminate\View\View
*/
public function edit($limitId = null)
public function edit(Limit $limit)
{
$limit = $this->_limits->find($limitId);
$budgets = $this->_budgets->getAsSelectList();
$periods = \Config::get('firefly.periods_to_text');
$periods = [
'weekly' => 'A week',
'monthly' => 'A month',
'quarterly' => 'A quarter',
'half-year' => 'Six months',
'yearly' => 'A year',
];
return View::make('limits.edit')->with('limit', $limit)->with('budgets', $budgets)->with(
'periods', $periods
);
}
public function store(Budget $budget = null)
{
if ($limit) {
return View::make('limits.edit')->with('limit', $limit)->with('budgets', $budgets)->with(
'periods', $periods
);
// find a limit with these properties, as we might already have one:
$limit = $this->_limits->store(Input::all());
if ($limit->id) {
if (Input::get('from') == 'date') {
return Redirect::route('budgets.index');
} else {
return Redirect::route('budgets.index.budget');
}
} else {
$budgetId = $budget ? $budget->id : null;
return Redirect::route('budgets.limits.create', [$budgetId, 'from' => Input::get('from')])->withInput();
}
return View::make('error')->with('message', 'No such limit.');
}
/**
@@ -90,14 +117,17 @@ class LimitController extends BaseController
if (!$limit->save()) {
Session::flash('error', 'Could not save new limit: ' . $limit->errors()->first());
return Redirect::route('budgets.limits.edit', $limit->id)->withInput();
return Redirect::route('budgets.limits.edit', [$limit->id, 'from' => Input::get('from')])->withInput();
} else {
Session::flash('success', 'Limit saved!');
foreach ($limit->limitrepetitions()->get() as $rep) {
$rep->delete();
}
return Redirect::route('budgets.index');
if (Input::get('from') == 'date') {
return Redirect::route('budgets.index');
} else {
return Redirect::route('budgets.index.budget');
}
}
}
@@ -105,55 +135,5 @@ class LimitController extends BaseController
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function store()
{
// find a limit with these properties, as we might already have one:
$limit = $this->_limits->store(Input::all());
if ($limit->id) {
return Redirect::route('budgets.index');
} else {
return Redirect::route('budgets.limits.create')->withInput();
}
}
/**
* @param $limitId
*
* @return $this|\Illuminate\View\View
*/
public function delete($limitId)
{
$limit = $this->_limits->find($limitId);
if ($limit) {
return View::make('limits.delete')->with('limit', $limit);
} else {
return View::make('error')->with('message', 'No such limit!');
}
}
/**
* @param $limitId
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function destroy($limitId)
{
$limit = $this->_limits->find($limitId);
if ($limit) {
$limit->delete();
return Redirect::route('budgets.index');
} else {
return View::make('error')->with('message', 'No such limit!');
}
}
}