Cleanup account views, controllers and repositories.

This commit is contained in:
James Cole
2014-09-11 21:58:51 +02:00
parent 9bcd27b847
commit d296dbbc23
10 changed files with 350 additions and 212 deletions

View File

@@ -27,30 +27,47 @@ class AccountController extends \BaseController
/**
* @return \Illuminate\View\View
*/
public function create()
public function create($what)
{
return View::make('accounts.create')->with('title', 'Create account');
return View::make('accounts.create')->with('title', 'Accounts')->with(
'subTitle', 'Create a new ' . $what . ' account'
)->with('what', $what);
}
/**
* @return $this
*/
public function asset() {
return View::make('accounts.asset')->with('title','Accounts')->with('subTitle','Asset accounts');
public function asset()
{
$accounts = $this->_repository->getOfTypes(['Asset account', 'Default account']);
return View::make('accounts.asset')->with('title', 'Accounts')->with('subTitle', 'Asset accounts')->with(
'accounts', $accounts
);
}
/**
* @return $this
*/
public function expense() {
return View::make('accounts.expense')->with('title','Accounts')->with('subTitle','Expense accounts');
public function expense()
{
$accounts = $this->_repository->getOfTypes(['Expense account', 'Beneficiary account']);
return View::make('accounts.expense')->with('title', 'Accounts')->with('subTitle', 'Expense accounts')->with(
'accounts', $accounts
);
}
/**
* @return $this
*/
public function revenue() {
return View::make('accounts.revenue')->with('title','Accounts')->with('subTitle','Revenue accounts');
public function revenue()
{
$accounts = $this->_repository->getOfTypes(['Revenue account']);
return View::make('accounts.revenue')->with('title', 'Accounts')->with('subTitle', 'Revenue accounts')->with(
'accounts', $accounts
);
}
/**
@@ -61,7 +78,9 @@ class AccountController extends \BaseController
public function delete(Account $account)
{
return View::make('accounts.delete')->with('account', $account)
->with('title', 'Delete account "' . $account->name . '"');
->with('title', 'Accounts')->with(
'subTitle', 'Delete ' . strtolower($account->accountType->type) . ' "' . $account->name . '"'
);
}
/**
@@ -71,11 +90,23 @@ class AccountController extends \BaseController
*/
public function destroy(Account $account)
{
$type = $account->accountType->type;
$this->_repository->destroy($account);
Session::flash('success', 'The account was deleted.');
switch ($type) {
case 'Asset account':
case 'Default account':
return Redirect::route('accounts.asset');
break;
case 'Expense account':
case 'Beneficiary account':
return Redirect::route('accounts.expense');
break;
case 'Revenue account':
return Redirect::route('accounts.revenue');
break;
}
return Redirect::route('accounts.index');
}
@@ -88,7 +119,8 @@ class AccountController extends \BaseController
{
$openingBalance = $this->_accounts->openingBalanceTransaction($account);
return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)
->with('title', 'Edit account "' . $account->name . '"');
->with('title','Accounts')
->with('subTitle', 'Edit '.strtolower($account->accountType->type).' "' . $account->name . '"');
}
/**
@@ -96,23 +128,24 @@ class AccountController extends \BaseController
*/
public function index()
{
$accounts = $this->_repository->get();
$set = [
'personal' => [],
'beneficiaries' => []
];
foreach ($accounts as $account) {
switch ($account->accounttype->type) {
case 'Default account':
$set['personal'][] = $account;
break;
case 'Beneficiary account':
$set['beneficiaries'][] = $account;
break;
}
}
return View::make('accounts.index')->with('accounts', $set)->with('title', 'All your accounts');
return View::make('error')->with('message','This view has been disabled');
// $accounts = $this->_repository->get();
// $set = [
// 'personal' => [],
// 'beneficiaries' => []
// ];
// foreach ($accounts as $account) {
// switch ($account->accounttype->type) {
// case 'Default account':
// $set['personal'][] = $account;
// break;
// case 'Beneficiary account':
// $set['beneficiaries'][] = $account;
// break;
// }
// }
//
// return View::make('accounts.index')->with('accounts', $set)->with('title', 'All your accounts');
}
/**
@@ -125,9 +158,9 @@ class AccountController extends \BaseController
$data = $this->_accounts->show($account, 40);
return View::make('accounts.show')->with('account', $account)->with('show', $data)->with(
'title',
'Details for account "' . $account->name . '"'
);
'subTitle',
'Details for '.strtolower($account->accountType->type).' "' . $account->name . '"'
)->with('title','Accounts');
}
/**
@@ -136,13 +169,30 @@ class AccountController extends \BaseController
public function store()
{
$account = $this->_repository->store(Input::all());
$data = Input::all();
$data['what'] = isset($data['what']) && $data['what'] != '' ? $data['what'] : 'asset';
switch ($data['what']) {
default:
case 'asset':
$data['account_type'] = 'Asset account';
break;
case 'expense':
$data['account_type'] = 'Expense account';
break;
case 'revenue':
$data['account_type'] = 'Revenue account';
break;
}
$account = $this->_repository->store($data);
if ($account->validate()) {
// saved! return to wherever.
Session::flash('success', 'Account "' . $account->name . '" created!');
if (intval(Input::get('create')) === 1) {
return Redirect::route('accounts.create')->withInput();
return Redirect::route('accounts.create', $data['what'])->withInput();
} else {
return Redirect::route('accounts.index');
}
@@ -150,7 +200,7 @@ class AccountController extends \BaseController
// did not save, return with error:
Session::flash('error', 'Could not save the new account: ' . $account->errors()->first());
return Redirect::route('accounts.create')->withErrors($account->errors())->withInput();
return Redirect::route('accounts.create', $data['what'])->withErrors($account->errors())->withInput();
}
}