Skip to content

Firefly III: a personal finances manager

Fixes for account routes.

James Cole4632142e06fa
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index f36cf7b94f..2ddcd82e42 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -31,7 +31,18 @@ class AccountController extends \BaseController
*/
public function create($what)
{
- View::share('subTitleIcon', 'fa-money');
+ switch ($what) {
+ case 'asset':
+ View::share('subTitleIcon', 'fa-money');
+ break;
+ case 'expense':
+ View::share('subTitleIcon', 'fa-shopping-cart');
+ break;
+ case 'revenue':
+ View::share('subTitleIcon', 'fa-download');
+ break;
+ }
+
return View::make('accounts.create')->with('subTitle', 'Create a new ' . $what . ' account')->with(
'what', $what
@@ -43,7 +54,7 @@ class AccountController extends \BaseController
*/
public function asset()
{
- View::share('subTitleIcon','fa-money');
+ View::share('subTitleIcon', 'fa-money');
$accounts = $this->_repository->getOfTypes(['Asset account', 'Default account']);
@@ -57,7 +68,7 @@ class AccountController extends \BaseController
*/
public function expense()
{
- View::share('subTitleIcon','fa-shopping-cart');
+ View::share('subTitleIcon', 'fa-shopping-cart');
$accounts = $this->_repository->getOfTypes(['Expense account', 'Beneficiary account']);
@@ -71,7 +82,7 @@ class AccountController extends \BaseController
*/
public function revenue()
{
- View::share('subTitleIcon','fa-download');
+ View::share('subTitleIcon', 'fa-download');
$accounts = $this->_repository->getOfTypes(['Revenue account']);
@@ -127,6 +138,21 @@ class AccountController extends \BaseController
*/
public function edit(Account $account)
{
+
+ switch ($account->accountType->type) {
+ case 'Asset account':
+ case 'Default account':
+ View::share('subTitleIcon', 'fa-money');
+ break;
+ case 'Expense account':
+ case 'Beneficiary account':
+ View::share('subTitleIcon', 'fa-shopping-cart');
+ break;
+ case 'Revenue account':
+ View::share('subTitleIcon', 'fa-download');
+ break;
+ }
+
$openingBalance = $this->_accounts->openingBalanceTransaction($account);
return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)
@@ -139,23 +165,6 @@ class AccountController extends \BaseController
public function index()
{
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');
}
/**
@@ -165,6 +174,21 @@ class AccountController extends \BaseController
*/
public function show(Account $account)
{
+ switch ($account->accountType->type) {
+ case 'Asset account':
+ case 'Default account':
+ View::share('subTitleIcon', 'fa-money');
+ break;
+ case 'Expense account':
+ case 'Beneficiary account':
+ View::share('subTitleIcon', 'fa-shopping-cart');
+ break;
+ case 'Revenue account':
+ View::share('subTitleIcon', 'fa-download');
+ break;
+ }
+
+
$data = $this->_accounts->show($account, 40);
return View::make('accounts.show')->with('account', $account)->with('show', $data)->with(
@@ -204,7 +228,8 @@ class AccountController extends \BaseController
if (intval(Input::get('create')) === 1) {
return Redirect::route('accounts.create', $data['what'])->withInput();
} else {
- return Redirect::route('accounts.index');
+
+ return Redirect::route('accounts.' . e($data['what']));
}
} else {
// did not save, return with error:
@@ -222,11 +247,24 @@ class AccountController extends \BaseController
*/
public function update(Account $account)
{
+ /** @var \Account $account */
$account = $this->_repository->update($account, Input::all());
if ($account->validate()) {
Session::flash('success', 'Account "' . $account->name . '" updated.');
+ switch ($account->accountType->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');
} else {
Session::flash('error', 'Could not update account: ' . $account->errors()->first());
diff --git a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php
index e9b56107ce..0c451a7555 100644
--- a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php
+++ b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php
@@ -66,7 +66,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
/*
* Find the import map for both:
*/
- $accountMap = $repository->findImportEntry($importMap, 'Account', $componentId);
+ $accountMap = $repository->findImportEntry($importMap, 'Account', $componentId);
$transactionMap = $repository->findImportEntry($importMap, 'Transaction', $transactionId);
/*
@@ -74,7 +74,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
*/
if (is_null($accountMap) || is_null($transactionMap)) {
\Log::notice('No map found in account/transaction mapper. Release.');
- if(\Config::get('queue.default') == 'sync') {
+ if (\Config::get('queue.default') == 'sync') {
$importMap->jobsdone++;
$importMap->save();
$job->delete(); // count fixed
@@ -96,7 +96,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
*/
if (is_null($account) || is_null($journal)) {
\Log::notice('Map is incorrect in account/transaction mapper. Release.');
- if(\Config::get('queue.default') == 'sync') {
+ if (\Config::get('queue.default') == 'sync') {
$importMap->jobsdone++;
$importMap->save();
$job->delete(); // count fixed
@@ -111,18 +111,18 @@ class EloquentAccountRepository implements AccountRepositoryInterface
*/
$importType = $this->findAccountType('Import account');
/** @var \Transaction $transaction */
- foreach($journal->transactions as $transaction) {
+ foreach ($journal->transactions as $transaction) {
/*
* If it's of the right type, update it!
*/
- if($transaction->account->account_type_id == $importType->id) {
+ if ($transaction->account->account_type_id == $importType->id) {
$transaction->account()->associate($account);
$transaction->save();
}
}
$journal->save();
- \Log::debug('Connected expense account "' . $account->name . '" to journal "' . $journal->description.'"');
+ \Log::debug('Connected expense account "' . $account->name . '" to journal "' . $journal->description . '"');
$importMap->jobsdone++;
$importMap->save();
@@ -131,6 +131,37 @@ class EloquentAccountRepository implements AccountRepositoryInterface
}
+ /**
+ * @param \User $user
+ *
+ * @return mixed|void
+ */
+ public function overruleUser(\User $user)
+ {
+ $this->_user = $user;
+ return true;
+ }
+
+ /**
+ * @param $accountId
+ *
+ * @return mixed
+ */
+ public function find($accountId)
+ {
+ return $this->_user->accounts()->where('id', $accountId)->first();
+ }
+
+ /**
+ * @param $type
+ *
+ * @return mixed
+ */
+ public function findAccountType($type)
+ {
+ return \AccountType::where('type', $type)->first();
+ }
+
/**
* @param Job $job
* @param array $payload
@@ -198,7 +229,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
$importMap->jobsdone++;
$importMap->save();
- $job->delete();// count fixed
+ $job->delete(); // count fixed
return;
}
\Log::debug('Imported ' . $payload['account_type'] . ': ' . $payload['data']['name']);
@@ -213,27 +244,6 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return;
}
- /**
- * @param \User $user
- *
- * @return mixed|void
- */
- public function overruleUser(\User $user)
- {
- $this->_user = $user;
- return true;
- }
-
- /**
- * @param $type
- *
- * @return mixed
- */
- public function findAccountType($type)
- {
- return \AccountType::where('type', $type)->first();
- }
-
/**
* @param $data
*
@@ -294,44 +304,6 @@ class EloquentAccountRepository implements AccountRepositoryInterface
// whatever the result, return the account.
return $account;
}
-
- /**
- * @param \Account $account
- * @param int $amount
- * @param Carbon $date
- *
- * @return bool
- * @SuppressWarnings(PHPMD.CamelCaseMethodName)
- */
- protected function _createInitialBalance(\Account $account, $amount = 0, Carbon $date)
- {
- // get account type:
- $initialBalanceAT = \AccountType::where('type', 'Initial balance account')->first();
-
- // create new account:
- $initial = new \Account;
- $initial->accountType()->associate($initialBalanceAT);
- $initial->user()->associate($this->_user);
- $initial->name = $account->name . ' initial balance';
- $initial->active = 0;
- if ($initial->validate()) {
- $initial->save();
- // create new transaction journal (and transactions):
- /** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $transactionJournal */
- $transactionJournal = \App::make(
- 'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'
- );
- $transactionJournal->overruleUser($this->_user);
-
- $transactionJournal->createSimpleJournal(
- $initial, $account, 'Initial Balance for ' . $account->name, $amount, $date
- );
-
- return true;
- }
-
- return false;
- }
//
// /**
// * @param $name
@@ -383,6 +355,44 @@ class EloquentAccountRepository implements AccountRepositoryInterface
// ->first();
// }
+ /**
+ * @param \Account $account
+ * @param int $amount
+ * @param Carbon $date
+ *
+ * @return bool
+ * @SuppressWarnings(PHPMD.CamelCaseMethodName)
+ */
+ protected function _createInitialBalance(\Account $account, $amount = 0, Carbon $date)
+ {
+ // get account type:
+ $initialBalanceAT = \AccountType::where('type', 'Initial balance account')->first();
+
+ // create new account:
+ $initial = new \Account;
+ $initial->accountType()->associate($initialBalanceAT);
+ $initial->user()->associate($this->_user);
+ $initial->name = $account->name . ' initial balance';
+ $initial->active = 0;
+ if ($initial->validate()) {
+ $initial->save();
+ // create new transaction journal (and transactions):
+ /** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $transactionJournal */
+ $transactionJournal = \App::make(
+ 'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'
+ );
+ $transactionJournal->overruleUser($this->_user);
+
+ $transactionJournal->createSimpleJournal(
+ $initial, $account, 'Initial Balance for ' . $account->name, $amount, $date
+ );
+
+ return true;
+ }
+
+ return false;
+ }
+
public function firstOrCreate(array $data)
{
return \Account::firstOrCreate($data);
@@ -422,6 +432,20 @@ class EloquentAccountRepository implements AccountRepositoryInterface
}
+// /**
+// * Used for import
+// *
+// * @param $name
+// *
+// * @return mixed
+// */
+// public function findByNameAny($name)
+// {
+// return $this->_user->accounts()
+// ->where('name', 'like', '%' . $name . '%')
+// ->first();
+// }
+
/**
* @param \Account $account
*
@@ -430,7 +454,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
public function destroy(\Account $account)
{
// find all transaction journals related to this account:
- $journals = \TransactionJournal::withRelevantData()->account($account)->get(['transaction_journals.*']);
+ $journals = \TransactionJournal::withRelevantData()->accountIs($account)->get(['transaction_journals.*']);
$accountIDs = [];
/** @var \TransactionJournal $journal */
@@ -463,30 +487,6 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return true;
}
-// /**
-// * Used for import
-// *
-// * @param $name
-// *
-// * @return mixed
-// */
-// public function findByNameAny($name)
-// {
-// return $this->_user->accounts()
-// ->where('name', 'like', '%' . $name . '%')
-// ->first();
-// }
-
- /**
- * @param $accountId
- *
- * @return mixed
- */
- public function find($accountId)
- {
- return $this->_user->accounts()->where('id', $accountId)->first();
- }
-
// /**
// * @return array|mixed
// */
@@ -598,7 +598,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
$account->save();
}
// update initial balance if necessary:
- if (floatval($data['openingbalance']) != 0) {
+ if (isset($data['openingbalance']) && floatval($data['openingbalance']) != 0) {
/** @var \Firefly\Helper\Controllers\AccountInterface $interface */
$interface = \App::make('Firefly\Helper\Controllers\AccountInterface');
diff --git a/app/routes.php b/app/routes.php
index f1f5e282c1..1660c65d09 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -136,14 +136,11 @@ Route::group(['before' => 'auth'], function () {
// account controller:
Route::get('/accounts', ['uses' => 'AccountController@index', 'as' => 'accounts.index']);
-
- // new routes for new layout:
Route::get('/accounts/asset', ['uses' => 'AccountController@asset', 'as' => 'accounts.asset']);
Route::get('/accounts/expense', ['uses' => 'AccountController@expense', 'as' => 'accounts.expense']);
Route::get('/accounts/revenue', ['uses' => 'AccountController@revenue', 'as' => 'accounts.revenue']);
- Route::get('/accounts/create/{what}', ['uses' => 'AccountController@create', 'as' => 'accounts.create'])
- ->where('what','revenue|asset|expense');
+ Route::get('/accounts/create/{what}', ['uses' => 'AccountController@create', 'as' => 'accounts.create'])->where('what','revenue|asset|expense');
Route::get('/accounts/{account}', ['uses' => 'AccountController@show', 'as' => 'accounts.show']);
Route::get('/accounts/{account}/edit', ['uses' => 'AccountController@edit', 'as' => 'accounts.edit']);
Route::get('/accounts/{account}/delete', ['uses' => 'AccountController@delete', 'as' => 'accounts.delete']);
diff --git a/app/views/accounts/create.blade.php b/app/views/accounts/create.blade.php
index 5254e1b914..4e0024a5b0 100644
--- a/app/views/accounts/create.blade.php
+++ b/app/views/accounts/create.blade.php
@@ -28,7 +28,21 @@
@if($errors->has('name'))
<p class="text-danger">{{$errors->first('name')}}</p>
@else
- <span class="help-block">Use something descriptive such as "checking account" or "My Bank Main Account".</span>
+ @if($what == 'asset')
+ <span class="help-block">
+ Use something descriptive such as "checking account" or "My Bank Main Account".
+ </span>
+ @endif
+ @if($what == 'expense')
+ <span class="help-block">
+ Use something descriptive such as "Albert Heijn" or "Amazon".
+ </span>
+ @endif
+ @if($what == 'revenue')
+ <span class="help-block">
+ Use something descriptive such as "my mom" or "my job".
+ </span>
+ @endif
@endif
</div>
@@ -91,7 +105,7 @@
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
- <button type="submit" class="btn btn-default btn-success">Create the account</button>
+ <button type="submit" class="btn btn-default btn-success">Create the {{{$what}}} account</button>
</div>
</div>
</div>
diff --git a/app/views/accounts/edit.blade.php b/app/views/accounts/edit.blade.php
index 54deee2c82..3393570a0b 100644
--- a/app/views/accounts/edit.blade.php
+++ b/app/views/accounts/edit.blade.php
@@ -29,7 +29,7 @@
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
- @if($account->accounttype->type == 'Default account')
+ @if($account->accounttype->type == 'Default account' || $account->accounttype->type == 'Asset account')
<h4>Optional fields</h4>
<div class="form-group">
@@ -58,7 +58,7 @@
@if(!is_null($openingBalance))
{{ Form::input('date','openingbalancedate', Input::old('openingbalancedate') ?: $openingBalance->date->format('Y-m-d'), ['class' => 'form-control']) }}
@else
- {{ Form::input('date','openingbalancedate', Input::old('openingbalancedate') ?: date('Y-m-d'), ['class' => 'form-control']) }}
+ {{ Form::input('date','openingbalancedate', Input::old('openingbalancedate') ?: '', ['class' => 'form-control']) }}
@endif
@if($errors->has('openingbalancedate'))
<p class="text-danger">{{$errors->first('openingbalancedate')}}</p>