Code cleanup [skip-ci]

This commit is contained in:
James Cole
2014-07-15 22:16:29 +02:00
parent 473e0f81c9
commit d280767407
35 changed files with 469 additions and 128 deletions

View File

@@ -6,44 +6,59 @@ use Firefly\Storage\Budget\BudgetRepositoryInterface as Bud;
use Firefly\Storage\Category\CategoryRepositoryInterface as Cat;
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
/**
* Class TransactionController
*/
class TransactionController extends BaseController
{
protected $accounts;
protected $budgets;
protected $categories;
protected $tj;
protected $_accounts;
protected $_budgets;
protected $_categories;
protected $_journal;
public function __construct(ARI $accounts, Bud $budgets, Cat $categories, TJRI $tj)
/**
* @param ARI $accounts
* @param Bud $budgets
* @param Cat $categories
* @param TJRI $journal
*/
public function __construct(ARI $accounts, Bud $budgets, Cat $categories, TJRI $journal)
{
$this->accounts = $accounts;
$this->budgets = $budgets;
$this->categories = $categories;
$this->tj = $tj;
$this->_accounts = $accounts;
$this->_budgets = $budgets;
$this->_categories = $categories;
$this->_journal = $journal;
View::share('menu', 'home');
}
/**
* @return $this|\Illuminate\View\View
*/
public function createWithdrawal()
{
// get accounts with names and id's.
$accounts = $this->accounts->getActiveDefaultAsSelectList();
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
$budgets = $this->budgets->getAsSelectList();
$budgets = $this->_budgets->getAsSelectList();
$budgets[0] = '(no budget)';
return View::make('transactions.withdrawal')->with('accounts', $accounts)->with('budgets', $budgets);
}
/**
* @return $this|\Illuminate\View\View
*/
public function createDeposit()
{
// get accounts with names and id's.
$accounts = $this->accounts->getActiveDefaultAsSelectList();
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
$budgets = $this->budgets->getAsSelectList();
$budgets = $this->_budgets->getAsSelectList();
$budgets[0] = '(no budget)';
@@ -51,12 +66,15 @@ class TransactionController extends BaseController
}
/**
* @return $this|\Illuminate\View\View
*/
public function createTransfer()
{
// get accounts with names and id's.
$accounts = $this->accounts->getActiveDefaultAsSelectList();
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
$budgets = $this->budgets->getAsSelectList();
$budgets = $this->_budgets->getAsSelectList();
$budgets[0] = '(no budget)';
@@ -64,25 +82,28 @@ class TransactionController extends BaseController
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function postCreateWithdrawal()
{
// create or find beneficiary:
$beneficiary = $this->accounts->createOrFindBeneficiary(Input::get('beneficiary'));
$beneficiary = $this->_accounts->createOrFindBeneficiary(Input::get('beneficiary'));
// fall back to cash account if empty:
if (is_null($beneficiary)) {
$beneficiary = $this->accounts->getCashAccount();
$beneficiary = $this->_accounts->getCashAccount();
}
// create or find category:
$category = $this->categories->createOrFind(Input::get('category'));
$category = $this->_categories->createOrFind(Input::get('category'));
// find budget:
$budget = $this->budgets->find(intval(Input::get('budget_id')));
$budget = $this->_budgets->find(intval(Input::get('budget_id')));
// find account:
$account = $this->accounts->find(intval(Input::get('account_id')));
$account = $this->_accounts->find(intval(Input::get('account_id')));
// find amount & description:
$description = trim(Input::get('description'));
@@ -92,7 +113,7 @@ class TransactionController extends BaseController
// create journal
/** @var \TransactionJournal $journal */
try {
$journal = $this->tj->createSimpleJournal($account, $beneficiary, $description, $amount, $date);
$journal = $this->_journal->createSimpleJournal($account, $beneficiary, $description, $amount, $date);
} catch (\Firefly\Exception\FireflyException $e) {
return Redirect::route('transactions.withdrawal')->withInput();
}
@@ -109,21 +130,24 @@ class TransactionController extends BaseController
return Redirect::route('index');
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function postCreateDeposit()
{
// create or find beneficiary:
$beneficiary = $this->accounts->createOrFindBeneficiary(Input::get('beneficiary'));
$beneficiary = $this->_accounts->createOrFindBeneficiary(Input::get('beneficiary'));
// fall back to cash account if empty:
if (is_null($beneficiary)) {
$beneficiary = $this->accounts->getCashAccount();
$beneficiary = $this->_accounts->getCashAccount();
}
// create or find category:
$category = $this->categories->createOrFind(Input::get('category'));
$category = $this->_categories->createOrFind(Input::get('category'));
// find account:
$account = $this->accounts->find(intval(Input::get('account_id')));
$account = $this->_accounts->find(intval(Input::get('account_id')));
// find amount & description:
$description = trim(Input::get('description'));
@@ -133,7 +157,7 @@ class TransactionController extends BaseController
// create journal
/** @var \TransactionJournal $journal */
try {
$journal = $this->tj->createSimpleJournal($beneficiary, $account, $description, $amount, $date);
$journal = $this->_journal->createSimpleJournal($beneficiary, $account, $description, $amount, $date);
} catch (\Firefly\Exception\FireflyException $e) {
return Redirect::route('transactions.deposit')->withInput();
}
@@ -146,16 +170,19 @@ class TransactionController extends BaseController
return Redirect::route('index');
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function postCreateTransfer()
{
// create or find category:
$category = $this->categories->createOrFind(Input::get('category'));
$category = $this->_categories->createOrFind(Input::get('category'));
// find account to:
$to = $this->accounts->find(intval(Input::get('account_to_id')));
$toAccount = $this->_accounts->find(intval(Input::get('account_to_id')));
// find account from
$from = $this->accounts->find(intval(Input::get('account_from_id')));
$from = $this->_accounts->find(intval(Input::get('account_from_id')));
// find amount & description:
$description = trim(Input::get('description'));
@@ -165,7 +192,7 @@ class TransactionController extends BaseController
// create journal
/** @var \TransactionJournal $journal */
try {
$journal = $this->tj->createSimpleJournal($from, $to, $description, $amount, $date);
$journal = $this->_journal->createSimpleJournal($from, $toAccount, $description, $amount, $date);
} catch (\Firefly\Exception\FireflyException $e) {
return Redirect::route('transactions.transfer')->withInput();
}