Some code cleanup and fixes.

This commit is contained in:
James Cole
2014-08-10 11:30:14 +02:00
parent c50a9b4b04
commit fbd056104a
27 changed files with 145 additions and 91 deletions

View File

@@ -102,12 +102,7 @@ class AccountController extends \BaseController
$account = $this->_repository->store(Input::all());
if (!$account->id) {
// did not save, return with error:
Session::flash('error', 'Could not save the new account. Please check the form.');
return Redirect::route('accounts.create')->withErrors($account->errors())->withInput();
} else {
if ($account->validate()) {
// saved! return to wherever.
Session::flash('success', 'Account "' . $account->name . '" created!');
if (Input::get('create') == '1') {
@@ -115,6 +110,12 @@ class AccountController extends \BaseController
} else {
return Redirect::route('accounts.index');
}
} else {
// did not save, return with error:
Session::flash('error', 'Could not save the new account. Please check the form.');
return Redirect::route('accounts.create')->withErrors($account->errors())->withInput();
}
}

View File

@@ -117,7 +117,7 @@ class BudgetController extends BaseController
return View::make('budgets.show')->with('budget', $budget)->with('repetitions', $repetitions)->with(
'filters', $filters
)->with('highlight',Input::get('highlight'));
)->with('highlight', Input::get('highlight'));
}
/**
@@ -127,7 +127,7 @@ class BudgetController extends BaseController
{
$budget = $this->_repository->store(Input::all());
if ($budget->id) {
if ($budget->validate()) {
Event::fire('budgets.change');
Session::flash('success', 'Budget created!');

View File

@@ -68,8 +68,8 @@ class CategoryController extends BaseController
public function store()
{
$category = $this->_repository->store(Input::all());
if ($category->id) {
Session::flash('success', 'Category created!');
if ($category->validate()) {
Session::flash('success', 'Category "' . $category->name . '" created!');
if (Input::get('create') == '1') {
return Redirect::route('categories.create');

View File

@@ -68,7 +68,8 @@ class ChartController extends BaseController
// loop and get array data.
$url = count($accounts) == 1 && is_array($accounts)
? '<a href="' . route('accounts.show', [$account->id]) . '">View more</a>' :
? '<a href="' . route('accounts.show', [$account->id]) . '">View more</a>'
:
'<a href="' . route('accounts.index') . '">View more</a>';
$data = [
'chart_title' => count($accounts) == 1 ? $accounts[0]->name : 'All accounts',

View File

@@ -15,10 +15,10 @@ class HomeController extends BaseController
protected $_budgets;
/**
* @param ARI $accounts
* @param PHI $preferences
* @param TJRI $journal
* @param BRI $budgets
* @param ARI $accounts
* @param PHI $preferences
* @param TJRI $journal
* @param BRI $budgets
*/
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, BRI $budgets)
{

View File

@@ -86,16 +86,19 @@ class LimitController extends BaseController
// find a limit with these properties, as we might already have one:
$limit = $this->_limits->store(Input::all());
if ($limit->id) {
if ($limit->validate()) {
Session::flash('success', 'Envelope created!');
if (Input::get('from') == 'date') {
return Redirect::route('budgets.index');
} else {
return Redirect::route('budgets.index.budget');
}
} else {
Session::flash('success', 'Could not save new envelope.');
$budgetId = $budget ? $budget->id : null;
return Redirect::route('budgets.limits.create', [$budgetId, 'from' => Input::get('from')])->withInput();
$parameters = [$budgetId, 'from' => Input::get('from')];
return Redirect::route('budgets.limits.create', $parameters)->withInput()
->withErrors($limit->errors());
}
}
@@ -106,16 +109,13 @@ class LimitController extends BaseController
*/
public function update(\Limit $limit)
{
// TODO move logic to repository.
/** @var \Limit $limit */
$limit->startdate = new \Carbon\Carbon(Input::get('date'));
$limit->repeat_freq = Input::get('period');
$limit->repeats = !is_null(Input::get('repeats')) && Input::get('repeats') == '1' ? 1 : 0;
$limit->amount = floatval(Input::get('amount'));
if (!$limit->save()) {
Session::flash('error', 'Could not save new limit: ' . $limit->errors()->first());
return Redirect::route('budgets.limits.edit', [$limit->id, 'from' => Input::get('from')])->withInput();
} else {
if ($limit->save()) {
Session::flash('success', 'Limit saved!');
foreach ($limit->limitrepetitions()->get() as $rep) {
$rep->delete();
@@ -125,6 +125,13 @@ class LimitController extends BaseController
} else {
return Redirect::route('budgets.index.budget');
}
} else {
Session::flash('error', 'Could not save new limit: ' . $limit->errors()->first());
return Redirect::route('budgets.limits.edit', [$limit->id, 'from' => Input::get('from')])->withInput()
->withErrors($limit->errors());
}
}

View File

@@ -82,19 +82,20 @@ class PiggybankController extends BaseController
public function store()
{
$piggyBank = $this->_repository->store(Input::all());
if (!$piggyBank->id) {
Session::flash('error', 'Could not save piggy bank: ' . $piggyBank->errors()->first());
return Redirect::route('piggybanks.create')->withInput();
} else {
if ($piggyBank->validate()) {
Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!');
if (Input::get('create') == '1') {
return Redirect::route('piggybanks.create')->withInput();
}
return Redirect::route('piggybanks.index');
} else {
Session::flash('error', 'Could not save piggy bank: ' . $piggyBank->errors()->first());
return Redirect::route('piggybanks.create')->withInput();
}
}
@@ -103,9 +104,17 @@ class PiggybankController extends BaseController
{
$piggyBank = $this->_repository->update(Input::all());
Session::flash('success', 'Piggy bank "' . $piggyBank->name . '" updated.');
if ($piggyBank->validate()) {
Session::flash('success', 'Piggy bank "' . $piggyBank->name . '" updated.');
return Redirect::route('piggybanks.index');
} else {
Session::flash('error', 'Could not update piggy bank: ' . $piggyBank->errors()->first());
return Redirect::route('piggybanks.edit', $piggyBank->id)->withErrors($piggyBank->errors())->withInput();
}
return Redirect::route('piggybanks.index');
}
public function updateAmount(Piggybank $piggybank)

View File

@@ -60,7 +60,7 @@ class RecurringController extends BaseController
public function store()
{
$recurringTransaction = $this->_repository->store(Input::all());
if ($recurringTransaction->id) {
if ($recurringTransaction->validate()) {
Session::flash('success', 'Recurring transaction "' . $recurringTransaction->name . '" saved!');
if (Input::get('create') == '1') {
return Redirect::route('recurring.create')->withInput();

View File

@@ -145,19 +145,19 @@ class TransactionController extends BaseController
*/
public function store($what)
{
$transactionJournal = $this->_repository->store($what, Input::all());
if ($transactionJournal->id) {
Session::flash('success', 'Transaction "' . $transactionJournal->description . '" saved!');
$journal = $this->_repository->store($what, Input::all());
if ($journal->validate()) {
Session::flash('success', 'Transaction "' . $journal->description . '" saved!');
if (Input::get('create') == '1') {
return Redirect::route('transactions.create', [$what])->withInput();
} else {
return Redirect::route('transactions.index');
}
} else {
Session::flash('error', 'Could not save transaction: ' . $transactionJournal->errors()->first());
Session::flash('error', 'Could not save transaction: ' . $journal->errors()->first());
return Redirect::route('transactions.create', [$what])->withInput()->withErrors(
$transactionJournal->errors()
$journal->errors()
);
}