From b3209d3b4da7a177daec17d4a7d188f7f0656e53 Mon Sep 17 00:00:00 2001 From: Sander Dorigo Date: Sun, 5 Oct 2014 08:27:18 +0200 Subject: [PATCH] Fixed validation and made some new form elements. --- app/controllers/TransactionController.php | 58 +++-- app/lib/Firefly/Form/Form.php | 202 +++++++++++++++++ .../Helper/Controllers/Transaction.php | 208 ++++++++++++++++-- .../Controllers/TransactionInterface.php | 9 + .../Account/AccountRepositoryInterface.php | 6 +- .../Account/EloquentAccountRepository.php | 120 +++++----- app/views/accounts/asset.blade.php | 15 +- app/views/accounts/create.blade.php | 15 -- app/views/transactions/create.blade.php | 175 ++------------- 9 files changed, 528 insertions(+), 280 deletions(-) create mode 100644 app/lib/Firefly/Form/Form.php diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index 6c66675ce4..e0e3abf8e5 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -4,6 +4,7 @@ use Firefly\Exception\FireflyException; use Firefly\Helper\Controllers\TransactionInterface as TI; use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI; +use Illuminate\Support\MessageBag; /** * Class TransactionController @@ -21,12 +22,12 @@ class TransactionController extends BaseController * Construct a new transaction controller with two of the most often used helpers. * * @param TJRI $repository - * @param TI $helper + * @param TI $helper */ public function __construct(TJRI $repository, TI $helper) { $this->_repository = $repository; - $this->_helper = $helper; + $this->_helper = $helper; View::share('title', 'Transactions'); View::share('mainTitleIcon', 'fa-repeat'); } @@ -59,16 +60,26 @@ class TransactionController extends BaseController $assetAccounts = $toolkit->makeSelectList($accountRepository->getActiveDefault()); // get budgets as a select list. - $budgets = $toolkit->makeSelectList($budgetRepository->get()); + $budgets = $toolkit->makeSelectList($budgetRepository->get()); $budgets[0] = '(no budget)'; // get the piggy banks. - $piggies = $toolkit->makeSelectList($piggyRepository->get()); + $piggies = $toolkit->makeSelectList($piggyRepository->get()); $piggies[0] = '(no piggy bank)'; + /* + * Catch messages from validation round: + */ + if (Session::has('messages')) { + $messages = Session::get('messages'); + Session::forget('messages'); + } else { + $messages = new MessageBag; + } + return View::make('transactions.create')->with('accounts', $assetAccounts)->with('budgets', $budgets)->with( 'what', $what - )->with('piggies', $piggies)->with('subTitle', 'Add a new ' . $what); + )->with('piggies', $piggies)->with('subTitle', 'Add a new ' . $what)->with('messages', $messages); } /** @@ -144,7 +155,7 @@ class TransactionController extends BaseController $accounts = $toolkit->makeSelectList($accountRepository->getActiveDefault()); // get budgets as a select list. - $budgets = $toolkit->makeSelectList($budgetRepository->get()); + $budgets = $toolkit->makeSelectList($budgetRepository->get()); $budgets[0] = '(no budget)'; /* @@ -152,8 +163,8 @@ class TransactionController extends BaseController * of the transactions in the journal has this field, it should all fill in nicely. */ // get the piggy banks. - $piggies = $toolkit->makeSelectList($piggyRepository->get()); - $piggies[0] = '(no piggy bank)'; + $piggies = $toolkit->makeSelectList($piggyRepository->get()); + $piggies[0] = '(no piggy bank)'; $piggyBankId = 0; foreach ($journal->transactions as $t) { if (!is_null($t->piggybank_id)) { @@ -165,9 +176,9 @@ class TransactionController extends BaseController * Data to properly display the edit form. */ $prefilled = [ - 'date' => $journal->date->format('Y-m-d'), - 'category' => '', - 'budget_id' => 0, + 'date' => $journal->date->format('Y-m-d'), + 'category' => '', + 'budget_id' => 0, 'piggybank_id' => $piggyBankId ]; @@ -185,23 +196,23 @@ class TransactionController extends BaseController */ switch ($what) { case 'withdrawal': - $prefilled['account_id'] = $journal->transactions[0]->account->id; + $prefilled['account_id'] = $journal->transactions[0]->account->id; $prefilled['expense_account'] = $journal->transactions[1]->account->name; - $prefilled['amount'] = floatval($journal->transactions[1]->amount); - $budget = $journal->budgets()->first(); + $prefilled['amount'] = floatval($journal->transactions[1]->amount); + $budget = $journal->budgets()->first(); if (!is_null($budget)) { $prefilled['budget_id'] = $budget->id; } break; case 'deposit': - $prefilled['account_id'] = $journal->transactions[1]->account->id; + $prefilled['account_id'] = $journal->transactions[1]->account->id; $prefilled['revenue_account'] = $journal->transactions[0]->account->name; - $prefilled['amount'] = floatval($journal->transactions[1]->amount); + $prefilled['amount'] = floatval($journal->transactions[1]->amount); break; case 'transfer': $prefilled['account_from_id'] = $journal->transactions[1]->account->id; - $prefilled['account_to_id'] = $journal->transactions[0]->account->id; - $prefilled['amount'] = floatval($journal->transactions[1]->amount); + $prefilled['account_to_id'] = $journal->transactions[0]->account->id; + $prefilled['amount'] = floatval($journal->transactions[1]->amount); break; } @@ -258,7 +269,7 @@ class TransactionController extends BaseController /* * Collect data to process: */ - $data = Input::except(['_token']); + $data = Input::except(['_token']); $data['what'] = $what; switch (Input::get('post_submit_action')) { @@ -292,7 +303,14 @@ class TransactionController extends BaseController } break; + case 'validate_only': + $messageBags = $this->_helper->validate($data); + Session::flash('warnings', $messageBags['warnings']); + Session::flash('successes', $messageBags['successes']); + Session::flash('errors', $messageBags['errors']); + return Redirect::route('transactions.create', [$what])->withInput(); + break; default: throw new FireflyException('Method ' . Input::get('post_submit_action') . ' not implemented yet.'); break; @@ -317,7 +335,7 @@ class TransactionController extends BaseController switch (Input::get('post_submit_action')) { case 'store': case 'return_to_edit': - $what = strtolower($journal->transactionType->type); + $what = strtolower($journal->transactionType->type); $messageBag = $this->_helper->update($journal, Input::all()); if ($messageBag->count() == 0) { // has been saved, return to index: diff --git a/app/lib/Firefly/Form/Form.php b/app/lib/Firefly/Form/Form.php new file mode 100644 index 0000000000..5aec4c3f7b --- /dev/null +++ b/app/lib/Firefly/Form/Form.php @@ -0,0 +1,202 @@ +has($name)): + $classes = 'form-group has-error has-feedback'; + break; + case (!is_null($warnings) && $warnings->has($name)): + $classes = 'form-group has-warning has-feedback'; + break; + case (!is_null($successes) && $successes->has($name)): + $classes = 'form-group has-success has-feedback'; + break; + default: + $classes = 'form-group'; + break; + } + + /* + * Add some HTML. + */ + $label = isset($options['label']) ? $options['label'] : ucfirst($name); + $html = '
'; + $html .= ''; + $html .= '
'; + + + /* + * Switch input type: + */ + switch ($type) { + case 'text': + $html .= \Form::input('text', $name, $value, $options); + break; + case 'number': + $html .= '
'; + $html .= \Form::input('number', $name, $value, $options); + $html .= '
'; + break; + case 'date': + $html .= \Form::input('date', $name, $value, $options); + break; + case 'select': + $html .= \Form::select($name, $list, $value, $options); + break; + default: + throw new FireflyException('Cannot handle type "' . $type . '" in FFFormBuilder.'); + break; + } + + /* + * If errors, respond to them: + */ + + if (!is_null($errors)) { + if ($errors->has($name)) { + $html .= ''; + $html .= '

' . e($errors->first($name)) . '

'; + } + } + unset($errors); + /* + * If warnings, respond to them: + */ + + if (!is_null($warnings)) { + if ($warnings->has($name)) { + $html .= ''; + $html .= '

' . e($warnings->first($name)) . '

'; + } + } + unset($warnings); + + /* + * If successes, respond to them: + */ + + if (!is_null($successes)) { + if ($successes->has($name)) { + $html .= ''; + $html .= '

' . e($successes->first($name)) . '

'; + } + } + unset($successes); + + $html .= '
'; + $html .= '
'; + + return $html; + + } +} \ No newline at end of file diff --git a/app/lib/Firefly/Helper/Controllers/Transaction.php b/app/lib/Firefly/Helper/Controllers/Transaction.php index c6cf4c665a..4222342da2 100644 --- a/app/lib/Firefly/Helper/Controllers/Transaction.php +++ b/app/lib/Firefly/Helper/Controllers/Transaction.php @@ -2,6 +2,9 @@ namespace Firefly\Helper\Controllers; +use Carbon\Carbon; +use Exception; +use Firefly\Exception\FireflyException; use Firefly\Storage\Account\AccountRepositoryInterface as ARI; use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI; use Firefly\Storage\Category\CategoryRepositoryInterface as CRI; @@ -36,18 +39,18 @@ class Transaction implements TransactionInterface /** * @param TJRI $journals - * @param CRI $categories - * @param BRI $budgets - * @param PRI $piggybanks - * @param ARI $accounts + * @param CRI $categories + * @param BRI $budgets + * @param PRI $piggybanks + * @param ARI $accounts */ public function __construct(TJRI $journals, CRI $categories, BRI $budgets, PRI $piggybanks, ARI $accounts) { - $this->_journals = $journals; + $this->_journals = $journals; $this->_categories = $categories; - $this->_budgets = $budgets; + $this->_budgets = $budgets; $this->_piggybanks = $piggybanks; - $this->_accounts = $accounts; + $this->_accounts = $accounts; $this->overruleUser(\Auth::user()); } @@ -69,7 +72,7 @@ class Transaction implements TransactionInterface /** * @param \TransactionJournal $journal - * @param array $data + * @param array $data * * @return MessageBag|\TransactionJournal */ @@ -120,7 +123,7 @@ class Transaction implements TransactionInterface } if (isset($data['revenue_account'])) { $from = $this->_accounts->findRevenueAccountByName($data['revenue_account']); - $to = $this->_accounts->findAssetAccountById($data['account_id']); + $to = $this->_accounts->findAssetAccountById($data['account_id']); } if (isset($data['account_from_id'])) { $from = $this->_accounts->findAssetAccountById($data['account_from_id']); @@ -168,7 +171,7 @@ class Transaction implements TransactionInterface * Connect budget and category: */ $budgetids = !isset($budget) || (isset($budget) && is_null($budget)) ? [] : [$budget->id]; - $catids = is_null($category) ? [] : [$category->id]; + $catids = is_null($category) ? [] : [$category->id]; $journal->budgets()->sync($budgetids); $journal->categories()->sync($catids); $journal->save(); @@ -179,6 +182,186 @@ class Transaction implements TransactionInterface } + /** + * Returns messages about the validation. + * + * @param array $data + * @return array + * @throws FireflyException + */ + public function validate(array $data) + { + $errors = new MessageBag; + $warnings = new MessageBag; + $successes = new MessageBag; + + /* + * Description: + */ + if (strlen($data['description']) == 0) { + $errors->add('description', 'The description should not be this short.'); + } + if (strlen($data['description']) > 250) { + $errors->add('description', 'The description should not be this long.'); + } + + /* + * Amount + */ + if (floatval($data['amount']) <= 0) { + $errors->add('amount', 'The amount cannot be zero or less than zero.'); + } + if (floatval($data['amount']) > 10000) { + $warnings->add('amount', 'OK, but that\'s a lot of money dude.'); + } + + /* + * Date + */ + try { + $date = new Carbon($data['date']); + } catch (Exception $e) { + $errors->add('date', 'The date entered was invalid'); + } + if (strlen($data['date']) == 0) { + $errors->add('date', 'The date entered was invalid'); + } + if (!$errors->has('date')) { + $successes->add('date', 'OK!'); + } + + /* + * Category + */ + $category = $this->_categories->findByName($data['category']); + if (strlen($data['category']) == 0) { + $warnings->add('category', 'No category will be created.'); + } else { + if (is_null($category)) { + $warnings->add('category', 'Will have to be created.'); + } else { + $successes->add('category', 'OK!'); + } + } + + switch ($data['what']) { + default: + throw new FireflyException('Cannot validate a ' . $data['what']); + break; + case 'deposit': + /* + * Tests for deposit + */ + // asset account + $accountId = isset($data['account_id']) ? intval($data['account_id']) : 0; + $account = $this->_accounts->find($accountId); + if (is_null($account)) { + $errors->add('account_id', 'Cannot find this asset account.'); + } else { + $successes->add('account_id', 'OK!'); + } + + // revenue account: + if (strlen($data['revenue_account']) == 0) { + $warnings->add('revenue_account', 'Revenue account will be "cash".'); + } else { + $exp = $this->_accounts->findRevenueAccountByName($data['revenue_account'], false); + if (is_null($exp)) { + $warnings->add('revenue_account', 'Expense account will be created.'); + } else { + $successes->add('revenue_account', 'OK!'); + } + } + + break; + case 'transfer': + // account from + $accountId = isset($data['account_from_id']) ? intval($data['account_from_id']) : 0; + $account = $this->_accounts->find($accountId); + if (is_null($account)) { + $errors->add('account_from_id', 'Cannot find this asset account.'); + } else { + $successes->add('account_from_id', 'OK!'); + } + unset($accountId); + // account to + $accountId = isset($data['account_to_id']) ? intval($data['account_to_id']) : 0; + $account = $this->_accounts->find($accountId); + if (is_null($account)) { + $errors->add('account_to_id', 'Cannot find this asset account.'); + } else { + $successes->add('account_to_id', 'OK!'); + } + unset($accountId); + + // piggy bank + $piggybankId = isset($data['piggybank_id']) ? intval($data['piggybank_id']) : 0; + $piggybank = $this->_piggybanks->find($piggybankId); + if (is_null($piggybank)) { + $warnings->add('piggybank_id', 'No piggy bank will be modified.'); + } else { + $successes->add('piggybank_id', 'OK!'); + } + + break; + case 'withdrawal': + /* + * Tests for withdrawal + */ + // asset account + $accountId = isset($data['account_id']) ? intval($data['account_id']) : 0; + $account = $this->_accounts->find($accountId); + if (is_null($account)) { + $errors->add('account_id', 'Cannot find this asset account.'); + } else { + $successes->add('account_id', 'OK!'); + } + + // expense account + if (strlen($data['expense_account']) == 0) { + $warnings->add('expense_account', 'Expense account will be "cash".'); + } else { + $exp = $this->_accounts->findExpenseAccountByName($data['expense_account'], false); + if (is_null($exp)) { + $warnings->add('expense_account', 'Expense account will be created.'); + } else { + $successes->add('expense_account', 'OK!'); + } + } + + // budget + if (!isset($data['budget_id']) || (isset($data['budget_id']) && intval($data['budget_id']) == 0)) { + $warnings->add('budget_id', 'No budget selected.'); + } else { + $budget = $this->_budgets->find(intval($data['budget_id'])); + if (is_null($budget)) { + $errors->add('budget_id', 'This budget does not exist'); + } else { + $successes->add('budget_id', 'OK!'); + } + } + + break; + } + + if (count($errors->get('description')) == 0) { + $successes->add('description', 'OK!'); + } + + if (count($errors->get('amount')) == 0) { + $successes->add('amount', 'OK!'); + } + + return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes]; + /* + * Tests for deposit + */ + /* + * Tests for transfer + */ + + } + /** * Store a full transaction journal and associated stuff * @@ -235,7 +418,7 @@ class Transaction implements TransactionInterface } if (isset($data['revenue_account'])) { $from = $this->_accounts->findRevenueAccountByName($data['revenue_account']); - $to = $this->_accounts->findAssetAccountById($data['account_id']); + $to = $this->_accounts->findAssetAccountById($data['account_id']); } if (isset($data['account_from_id'])) { $from = $this->_accounts->findAssetAccountById($data['account_from_id']); @@ -247,8 +430,7 @@ class Transaction implements TransactionInterface /* * Add a custom error when they are the same. */ - if ($to->id == - $from->id) { + if ($to->id == $from->id) { $bag = new MessageBag; $bag->add('account_from_id', 'The account from cannot be the same as the account to.'); return $bag; diff --git a/app/lib/Firefly/Helper/Controllers/TransactionInterface.php b/app/lib/Firefly/Helper/Controllers/TransactionInterface.php index b01e83459a..0c481b1494 100644 --- a/app/lib/Firefly/Helper/Controllers/TransactionInterface.php +++ b/app/lib/Firefly/Helper/Controllers/TransactionInterface.php @@ -19,6 +19,15 @@ interface TransactionInterface { */ public function store(array $data); + /** + * Returns messages about the validation. + * + * @param array $data + * + * @return array + */ + public function validate(array $data); + /** * @param \TransactionJournal $journal * @param array $data diff --git a/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php b/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php index 5268fe6c40..147aacaaff 100644 --- a/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php +++ b/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php @@ -83,17 +83,19 @@ interface AccountRepositoryInterface /** * @param $name + * @param $create * * @return |Account|null */ - public function findExpenseAccountByName($name); + public function findExpenseAccountByName($name, $create = true); /** * @param $name + * @param $create * * @return |Account|null */ - public function findRevenueAccountByName($name); + public function findRevenueAccountByName($name, $create = true); /** * @return mixed diff --git a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php index 2f4b4acfc7..1d234a5dd9 100644 --- a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php +++ b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php @@ -42,7 +42,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface public function destroy(\Account $account) { // find all transaction journals related to this account: - $journals = \TransactionJournal::withRelevantData()->accountIs($account)->get(['transaction_journals.*']); + $journals = \TransactionJournal::withRelevantData()->accountIs($account)->get(['transaction_journals.*']); $accountIDs = []; /** @var \TransactionJournal $journal */ @@ -58,7 +58,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface if (count($accountIDs) > 0) { // find the "initial balance" type accounts in this list. Should be just 1. $query = $this->_user->accounts()->accountTypeIn(['Initial balance account']) - ->whereIn('accounts.id', $accountIDs); + ->whereIn('accounts.id', $accountIDs); if ($query->count() == 1) { $iba = $query->first(['accounts.*']); $iba->delete(); @@ -90,22 +90,23 @@ class EloquentAccountRepository implements AccountRepositoryInterface * because when you feed it "Import account" it will always return an import account of that type. * * @param $name + * @param $create * * @return null|\Account */ - public function findExpenseAccountByName($name) + public function findExpenseAccountByName($name, $create = true) { - $cashType = $this->findAccountType('Cash account'); + $cashType = $this->findAccountType('Cash account'); $importType = $this->findAccountType('Import account'); // catch Import account: if ($name == 'Import account') { $import = $this->firstOrCreate( [ - 'name' => 'Import account', - 'user_id' => $this->_user->id, + 'name' => 'Import account', + 'user_id' => $this->_user->id, 'account_type_id' => $importType->id, - 'active' => 1 + 'active' => 1 ] ); return $import; @@ -118,15 +119,17 @@ class EloquentAccountRepository implements AccountRepositoryInterface )->first(['accounts.*']); // create if not found: - if (strlen($name) > 0 && is_null($account)) { - $type = $this->findAccountType('Expense account'); - $set = [ - 'name' => $name, - 'user_id' => $this->_user->id, - 'active' => 1, + if (strlen($name) > 0 && is_null($account) && $create === true) { + $type = $this->findAccountType('Expense account'); + $set = [ + 'name' => $name, + 'user_id' => $this->_user->id, + 'active' => 1, 'account_type_id' => $type->id ]; $account = $this->firstOrCreate($set); + } else if (strlen($name) > 0 && is_null($account) && $create === false) { + return null; } @@ -138,10 +141,10 @@ class EloquentAccountRepository implements AccountRepositoryInterface // create cash account as ultimate fall back: if (is_null($account)) { - $set = [ - 'name' => 'Cash account', - 'user_id' => $this->_user->id, - 'active' => 1, + $set = [ + 'name' => 'Cash account', + 'user_id' => $this->_user->id, + 'active' => 1, 'account_type_id' => $cashType->id ]; $account = $this->firstOrCreate($set); @@ -171,52 +174,55 @@ class EloquentAccountRepository implements AccountRepositoryInterface /** * @param $name + * @param $create * * @return |Account|null */ - public function findRevenueAccountByName($name) + public function findRevenueAccountByName($name, $create = true) { // catch Import account: if ($name == 'Import account') { $importType = $this->findAccountType('Import account'); - $import = $this->firstOrCreate( + $import = $this->firstOrCreate( [ - 'name' => 'Import account', - 'user_id' => $this->_user->id, + 'name' => 'Import account', + 'user_id' => $this->_user->id, 'account_type_id' => $importType->id, - 'active' => 1 + 'active' => 1 ] ); return $import; } // find account: - $type = $this->findAccountType('Revenue account'); + $type = $this->findAccountType('Revenue account'); $account = $this->_user->accounts()->where('name', $name)->where('account_type_id', $type->id)->first(); // create if not found: - if (strlen($name) > 0) { - $set = [ - 'name' => $name, - 'user_id' => $this->_user->id, - 'active' => 1, + if (strlen($name) > 0 && is_null($account) && $create === true) { + $set = [ + 'name' => $name, + 'user_id' => $this->_user->id, + 'active' => 1, 'account_type_id' => $type->id ]; $account = $this->firstOrCreate($set); + } else if (strlen($name) > 0 && is_null($account) && $create === false) { + return null; } // find cash account as fall back: if (is_null($account)) { $cashType = $this->findAccountType('Cash account'); - $account = $this->_user->accounts()->where('account_type_id', $cashType->id)->first(); + $account = $this->_user->accounts()->where('account_type_id', $cashType->id)->first(); } // create cash account as ultimate fall back: if (is_null($account)) { - $set = [ - 'name' => 'Cash account', - 'user_id' => $this->_user->id, - 'active' => 1, + $set = [ + 'name' => 'Cash account', + 'user_id' => $this->_user->id, + 'active' => 1, 'account_type_id' => $cashType->id ]; $account = $this->firstOrCreate($set); @@ -232,7 +238,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface public function getByAccountType(\AccountType $type) { return $this->_user->accounts()->with('accounttype')->orderBy('name', 'ASC') - ->where('account_type_id', $type->id)->get(); + ->where('account_type_id', $type->id)->get(); } /** @@ -307,7 +313,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface return $this->_user->accounts()->accountTypeIn(['Default account', 'Asset account'])->where( 'accounts.active', 1 ) - ->get(['accounts.*']); + ->get(['accounts.*']); } /** @@ -316,7 +322,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface public function getDefault() { return $this->_user->accounts()->accountTypeIn(['Default account', 'Asset account']) - ->orderBy('accounts.name', 'ASC')->get(['accounts.*']); + ->orderBy('accounts.name', 'ASC')->get(['accounts.*']); } /** @@ -334,7 +340,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface } /** - * @param Job $job + * @param Job $job * @param array $payload * * @return mixed @@ -346,7 +352,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface /** @var \Importmap $importMap */ $importMap = $repository->findImportmap($payload['mapID']); - $user = $importMap->user; + $user = $importMap->user; $this->overruleUser($user); /* @@ -369,17 +375,17 @@ class EloquentAccountRepository implements AccountRepositoryInterface * find the payload's account type: */ $payload['account_type'] = isset($payload['account_type']) ? $payload['account_type'] : 'Expense account'; - $type = $this->findAccountType($payload['account_type']); + $type = $this->findAccountType($payload['account_type']); /* * Create data array for store() procedure. */ $data = [ 'account_type' => $type, - 'name' => $payload['data']['name'], + 'name' => $payload['data']['name'], ]; if (isset($payload['data']['openingbalance'])) { - $data['openingbalance'] = floatval($payload['data']['openingbalance']); + $data['openingbalance'] = floatval($payload['data']['openingbalance']); $data['openingbalancedate'] = $payload['data']['openingbalancedate']; } if (isset($payload['data']['inactive'])) { @@ -464,7 +470,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface $account->name = $data['name']; $account->active - = isset($data['active']) && intval($data['active']) >= 0 && intval($data['active']) <= 1 ? intval( + = isset($data['active']) && intval($data['active']) >= 0 && intval($data['active']) <= 1 ? intval( $data['active'] ) : 1; @@ -474,7 +480,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface // create initial balance, if necessary: if (isset($data['openingbalance']) && isset($data['openingbalancedate'])) { $amount = floatval($data['openingbalance']); - $date = new Carbon($data['openingbalancedate']); + $date = new Carbon($data['openingbalancedate']); if ($amount != 0) { $this->_createInitialBalance($account, $amount, $date); } @@ -491,8 +497,8 @@ class EloquentAccountRepository implements AccountRepositoryInterface /** * @param \Account $account - * @param int $amount - * @param Carbon $date + * @param int $amount + * @param Carbon $date * * @return bool * @SuppressWarnings(PHPMD.CamelCaseMethodName) @@ -518,7 +524,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface $initial = new \Account; $initial->accountType()->associate($initialBalanceAT); $initial->user()->associate($this->_user); - $initial->name = $account->name . ' initial balance'; + $initial->name = $account->name . ' initial balance'; $initial->active = 0; if ($initial->validate()) { $initial->save(); @@ -528,12 +534,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface $set = [ 'account_from_id' => $initial->id, - 'account_to_id' => $account->id, - 'description' => 'Initial Balance for ' . $account->name, - 'what' => 'Opening balance', - 'amount' => $amount, - 'category' => '', - 'date' => $date->format('Y-m-d') + 'account_to_id' => $account->id, + 'description' => 'Initial Balance for ' . $account->name, + 'what' => 'Opening balance', + 'amount' => $amount, + 'category' => '', + 'date' => $date->format('Y-m-d') ]; $transactions->store($set); @@ -546,7 +552,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface /** * Takes a transaction/account component and updates the transaction journal to match. * - * @param Job $job + * @param Job $job * @param array $payload * * @return mixed @@ -558,7 +564,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface /** @var \Importmap $importMap */ $importMap = $repository->findImportmap($payload['mapID']); - $user = $importMap->user; + $user = $importMap->user; $this->overruleUser($user); if ($job->attempts() > 10) { @@ -579,12 +585,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface * Prep some vars from the payload */ $transactionId = intval($payload['data']['transaction_id']); - $componentId = intval($payload['data']['component_id']); + $componentId = intval($payload['data']['component_id']); /* * Find the import map for both: */ - $accountMap = $repository->findImportEntry($importMap, 'Account', $componentId); + $accountMap = $repository->findImportEntry($importMap, 'Account', $componentId); $transactionMap = $repository->findImportEntry($importMap, 'Transaction', $transactionId); /* @@ -713,7 +719,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface $journal = $interface->openingBalanceTransaction($account); if ($journal) { - $journal->date = new Carbon($data['openingbalancedate']); + $journal->date = new Carbon($data['openingbalancedate']); $journal->transactions[0]->amount = floatval($data['openingbalance']) * -1; $journal->transactions[1]->amount = floatval($data['openingbalance']); $journal->transactions[0]->save(); diff --git a/app/views/accounts/asset.blade.php b/app/views/accounts/asset.blade.php index 6a580f2456..5cc72b31c9 100644 --- a/app/views/accounts/asset.blade.php +++ b/app/views/accounts/asset.blade.php @@ -1,25 +1,14 @@ @extends('layouts.default') @section('content') -
-
-

- Accounts are your personal accounts that represent value. -

-

- "Asset accounts" are your personal accounts that represent value. For example: bank accounts, saving - accounts, stock, etc. -

-
-

- Create a new asset account + Create a new asset account

@if(count($accounts) > 0) @include('accounts.list')

- Create a new asset account + Create a new asset account

@endif
diff --git a/app/views/accounts/create.blade.php b/app/views/accounts/create.blade.php index 4e0024a5b0..6e3c7d2128 100644 --- a/app/views/accounts/create.blade.php +++ b/app/views/accounts/create.blade.php @@ -1,20 +1,5 @@ @extends('layouts.default') @section('content') -
-
-

- Something about accounts. -

-
-
-
-
-

- Something about accounts here! -

-
-
- {{Form::open(['class' => 'form-horizontal','route' => 'accounts.store'])}} {{Form::hidden('what',$what)}}
diff --git a/app/views/transactions/create.blade.php b/app/views/transactions/create.blade.php index fc17ed194f..7acc907bcc 100644 --- a/app/views/transactions/create.blade.php +++ b/app/views/transactions/create.blade.php @@ -12,144 +12,37 @@
-
has('description')) - class="form-group has-error has-feedback" - @else - class="form-group" - @endif - > - -
- - @if($errors->has('description')) -

{{$errors->first('description')}}

- @endif -
-
- + {{Form::ffText('description')}} @if($what == 'deposit' || $what == 'withdrawal') -
- -
- {{Form::select('account_id',$accounts,Input::old('account_id') ?: Input::get('account_id'),['class' => 'form-control'])}} - @if($errors->has('account_id')) -

{{$errors->first('account_id')}}

- @endif -
-
+ {{Form::ffSelect('account_id',$accounts)}} @endif + @if($what == 'withdrawal') -
- -
- - @if($errors->has('expense_account')) -

{{$errors->first('expense_account')}}

- @else - - This field will auto-complete your existing expense accounts (where you spent the - money), but you can type freely to create new ones. If you took the money from - an ATM, you should leave this field empty. - @endif -
-
+ {{Form::ffText('expense_account')}} @endif @if($what == 'deposit') -
- -
- - @if($errors->has('beneficiary')) -

{{$errors->first('revenue_account')}}

- @else - - This field will auto-complete your existing revenue - accounts (where you spent the receive money from), - but you can type freely to create new ones. - @endif -
-
+ {{Form::ffText('revenue_account')}} @endif + @if($what == 'transfer') -
- -
- {{Form::select('account_from_id',$accounts,Input::old('account_from_id') ?: Input::get('account_from_id'),['class' => 'form-control'])}} - @if($errors->has('account_from_id')) -

{{$errors->first('account_from_id')}}

- @endif -
-
- -
- -
- {{Form::select('account_to_id',$accounts,Input::old('account_to_id') ?: Input::get('account_to_id'),['class' => 'form-control'])}} - @if($errors->has('account_to_id')) -

{{$errors->first('account_to_id')}}

- @endif -
-
+ {{Form::ffSelect('account_from_id',$accounts)}} + {{Form::ffSelect('account_to_id',$accounts)}} @endif + -
- -
- - @if($errors->has('amount')) -

{{$errors->first('amount')}}

- @endif -
-
+ {{Form::ffAmount('amount')}} -
- -
- - @if($errors->has('date')) -

{{$errors->first('date')}}

- @endif -
-
+ {{Form::ffDate('date', date('Y-m-d'))}}
-