mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Small functional changes to all Account related methods and views.
This commit is contained in:
parent
bc0e8434ec
commit
9ecc8ab547
@ -14,7 +14,7 @@ class AccountController extends \BaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ARI $repository
|
* @param ARI $repository
|
||||||
* @param AI $accounts
|
* @param AI $accounts
|
||||||
*/
|
*/
|
||||||
public function __construct(ARI $repository, AI $accounts)
|
public function __construct(ARI $repository, AI $accounts)
|
||||||
{
|
{
|
||||||
@ -37,6 +37,12 @@ class AccountController extends \BaseController
|
|||||||
*/
|
*/
|
||||||
public function delete(Account $account)
|
public function delete(Account $account)
|
||||||
{
|
{
|
||||||
|
$accountType = $account->accountType()->first();
|
||||||
|
|
||||||
|
if ($accountType->description == 'Initial balance account' || $accountType->description == 'Cash account') {
|
||||||
|
return \View::make('error')->with('message', 'Cannot edit this account type (' . $accountType->description . ').');
|
||||||
|
}
|
||||||
|
|
||||||
return View::make('accounts.delete')->with('account', $account);
|
return View::make('accounts.delete')->with('account', $account);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +53,11 @@ class AccountController extends \BaseController
|
|||||||
*/
|
*/
|
||||||
public function destroy(Account $account)
|
public function destroy(Account $account)
|
||||||
{
|
{
|
||||||
|
$accountType = $account->accountType()->first();
|
||||||
|
|
||||||
|
if ($accountType->description == 'Initial balance account' || $accountType->description == 'Cash account') {
|
||||||
|
return View::make('error')->with('message', 'Cannot edit this account type (' . $accountType->description . ').');
|
||||||
|
}
|
||||||
$result = $this->_repository->destroy($account);
|
$result = $this->_repository->destroy($account);
|
||||||
if ($result === true) {
|
if ($result === true) {
|
||||||
Session::flash('success', 'The account was deleted.');
|
Session::flash('success', 'The account was deleted.');
|
||||||
@ -65,6 +76,11 @@ class AccountController extends \BaseController
|
|||||||
*/
|
*/
|
||||||
public function edit(Account $account)
|
public function edit(Account $account)
|
||||||
{
|
{
|
||||||
|
$accountType = $account->accountType()->first();
|
||||||
|
|
||||||
|
if ($accountType->description == 'Initial balance account' || $accountType->description == 'Cash account') {
|
||||||
|
return View::make('error')->with('message', 'Cannot edit this account type (' . $accountType->description . ').');
|
||||||
|
}
|
||||||
$openingBalance = $this->_accounts->openingBalanceTransaction($account);
|
$openingBalance = $this->_accounts->openingBalanceTransaction($account);
|
||||||
|
|
||||||
return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance);
|
return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance);
|
||||||
@ -88,6 +104,11 @@ class AccountController extends \BaseController
|
|||||||
*/
|
*/
|
||||||
public function show(Account $account)
|
public function show(Account $account)
|
||||||
{
|
{
|
||||||
|
$accountType = $account->accountType()->first();
|
||||||
|
if ($accountType->description == 'Initial balance account' || $accountType->description == 'Cash account') {
|
||||||
|
return View::make('error')->with('message', 'Cannot show this account type (' . $accountType->description . ').');
|
||||||
|
}
|
||||||
|
|
||||||
$show = $this->_accounts->show($account, 40);
|
$show = $this->_accounts->show($account, 40);
|
||||||
|
|
||||||
return View::make('accounts.show')->with('account', $account)->with('show', $show);
|
return View::make('accounts.show')->with('account', $account)->with('show', $show);
|
||||||
@ -125,6 +146,10 @@ class AccountController extends \BaseController
|
|||||||
*/
|
*/
|
||||||
public function update(Account $account)
|
public function update(Account $account)
|
||||||
{
|
{
|
||||||
|
$accountType = $account->accountType()->first();
|
||||||
|
if ($accountType->description == 'Initial balance account' || $accountType->description == 'Cash account') {
|
||||||
|
return View::make('error')->with('message', 'Cannot show this account type (' . $accountType->description . ').');
|
||||||
|
}
|
||||||
$account = $this->_repository->update($account, Input::all());
|
$account = $this->_repository->update($account, Input::all());
|
||||||
if ($account->validate()) {
|
if ($account->validate()) {
|
||||||
Session::flash('success', 'Account "' . $account->name . '" updated.');
|
Session::flash('success', 'Account "' . $account->name . '" updated.');
|
||||||
|
@ -40,7 +40,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
|||||||
$account = $this->findByName($name, $type);
|
$account = $this->findByName($name, $type);
|
||||||
if (!$account) {
|
if (!$account) {
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'account_type' => $type
|
'account_type' => $type
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -74,6 +74,38 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function destroy(\Account $account)
|
public function destroy(\Account $account)
|
||||||
{
|
{
|
||||||
|
// find the oldest transaction which also is a "Opening balance"
|
||||||
|
$first = \Transaction::
|
||||||
|
leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
|
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||||
|
->where('transaction_journals.user_id', \Auth::user()->id)
|
||||||
|
->where('transaction_types.type', 'Opening balance')
|
||||||
|
->where('account_id', '!=', $account->id)
|
||||||
|
->orderBy('transactions.id', 'DESC')->first(['transactions.*']);
|
||||||
|
|
||||||
|
$initialbalanceAccount = null;
|
||||||
|
if (!is_null($first)) {
|
||||||
|
$initialbalanceAccount = $first->account()->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// loop the account, find all transaction journals, and delete them:
|
||||||
|
$transactions = $account->transactions()->with('transactionjournal')->get();
|
||||||
|
$journals = [];
|
||||||
|
/** @var \Transaction $transaction */
|
||||||
|
foreach ($transactions as $transaction) {
|
||||||
|
$journals[$transaction->transaction_journal_id] = $transaction->transactionJournal;
|
||||||
|
}
|
||||||
|
/** @var \TransactionJournal $journal */
|
||||||
|
foreach ($journals as $journal) {
|
||||||
|
$journal->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!is_null($initialbalanceAccount)) {
|
||||||
|
$initialbalanceAccount->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$account->delete();
|
$account->delete();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -274,8 +306,8 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Account $account
|
* @param \Account $account
|
||||||
* @param int $amount
|
* @param int $amount
|
||||||
* @param Carbon $date
|
* @param Carbon $date
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
|
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Mockery as m;
|
|
||||||
use League\FactoryMuffin\Facade as f;
|
use League\FactoryMuffin\Facade as f;
|
||||||
|
use Mockery as m;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountControllerTest
|
* Class AccountControllerTest
|
||||||
@ -21,9 +21,6 @@ class AccountControllerTest extends TestCase
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Artisan::call('migrate');
|
Artisan::call('migrate');
|
||||||
Artisan::call('db:seed');
|
Artisan::call('db:seed');
|
||||||
$this->_repository = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
$this->_repository = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||||
@ -55,21 +52,50 @@ class AccountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Default account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
// for successful binding:
|
// for successful binding:
|
||||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||||
Auth::shouldReceive('check')->andReturn(true);
|
Auth::shouldReceive('check')->andReturn(true);
|
||||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||||
|
|
||||||
// view
|
$this->action('GET', 'AccountController@delete', $account->id);
|
||||||
View::shouldReceive('make')->once()->with('accounts.delete')->andReturn(m::self())->shouldReceive('with')->with(
|
$this->assertViewHas('account');
|
||||||
'account', m::any()
|
$this->assertResponseOk();
|
||||||
);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::delete
|
||||||
|
*/
|
||||||
|
public function testDeleteWrongType()
|
||||||
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Initial balance account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
|
// for successful binding:
|
||||||
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||||
|
Auth::shouldReceive('check')->andReturn(true);
|
||||||
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||||
|
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||||
|
|
||||||
$this->action('GET', 'AccountController@delete', $account->id);
|
$this->action('GET', 'AccountController@delete', $account->id);
|
||||||
|
$this->assertViewHas('message');
|
||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,8 +104,17 @@ class AccountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDestroy()
|
public function testDestroy()
|
||||||
{
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Default account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
|
|
||||||
// for successful binding:
|
// for successful binding:
|
||||||
Auth::shouldReceive('user')->once()->andReturn($this->_user);
|
Auth::shouldReceive('user')->once()->andReturn($this->_user);
|
||||||
Auth::shouldReceive('check')->once()->andReturn(true);
|
Auth::shouldReceive('check')->once()->andReturn(true);
|
||||||
@ -91,13 +126,47 @@ class AccountControllerTest extends TestCase
|
|||||||
$this->assertSessionHas('success');
|
$this->assertSessionHas('success');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::destroy
|
||||||
|
*/
|
||||||
|
public function testDestroyWrongType()
|
||||||
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Initial balance account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
|
|
||||||
|
// for successful binding:
|
||||||
|
Auth::shouldReceive('user')->once()->andReturn($this->_user);
|
||||||
|
Auth::shouldReceive('check')->once()->andReturn(true);
|
||||||
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||||
|
|
||||||
|
$this->action('POST', 'AccountController@destroy', $account->id);
|
||||||
|
$this->assertViewHas('message');
|
||||||
|
$this->assertResponseOk();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::destroy
|
* @covers ::destroy
|
||||||
*/
|
*/
|
||||||
public function testDestroyFails()
|
public function testDestroyFails()
|
||||||
{
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Default account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
// for successful binding:
|
// for successful binding:
|
||||||
Auth::shouldReceive('user')->once()->andReturn($this->_user);
|
Auth::shouldReceive('user')->once()->andReturn($this->_user);
|
||||||
Auth::shouldReceive('check')->once()->andReturn(true);
|
Auth::shouldReceive('check')->once()->andReturn(true);
|
||||||
@ -111,8 +180,16 @@ class AccountControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testEdit()
|
public function testEdit()
|
||||||
{
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Default account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
// for successful binding.
|
// for successful binding.
|
||||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||||
Auth::shouldReceive('check')->andReturn(true);
|
Auth::shouldReceive('check')->andReturn(true);
|
||||||
@ -130,23 +207,50 @@ class AccountControllerTest extends TestCase
|
|||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testEditWrongType()
|
||||||
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Initial balance account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
|
// for successful binding.
|
||||||
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||||
|
Auth::shouldReceive('check')->andReturn(true);
|
||||||
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||||
|
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||||
|
|
||||||
|
$this->action('GET', 'AccountController@edit', $account->id);
|
||||||
|
$this->assertViewHas('message');
|
||||||
|
$this->assertResponseOk();
|
||||||
|
}
|
||||||
|
|
||||||
public function testIndex()
|
public function testIndex()
|
||||||
{
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Default account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
$collection = new Collection();
|
$collection = new Collection();
|
||||||
$collection->add($account);
|
$collection->add($account);
|
||||||
|
|
||||||
// create some fake accounts:
|
|
||||||
$personal = f::create('Account');
|
|
||||||
$bene = f::create('Account');
|
|
||||||
$init = f::create('Account');
|
|
||||||
$cash = f::create('Account');
|
|
||||||
|
|
||||||
$list = [
|
$list = [
|
||||||
'personal' => [$personal],
|
'personal' => [],
|
||||||
'beneficiaries' => [$bene],
|
'beneficiaries' => [],
|
||||||
'initial' => [$init],
|
'initial' => [],
|
||||||
'cash' => [$cash]
|
'cash' => []
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->_repository->shouldReceive('get')->once()->andReturn($collection);
|
$this->_repository->shouldReceive('get')->once()->andReturn($collection);
|
||||||
@ -157,8 +261,16 @@ class AccountControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testShow()
|
public function testShow()
|
||||||
{
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Default account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
// for successful binding.
|
// for successful binding.
|
||||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||||
Auth::shouldReceive('check')->andReturn(true);
|
Auth::shouldReceive('check')->andReturn(true);
|
||||||
@ -171,19 +283,19 @@ class AccountControllerTest extends TestCase
|
|||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'statistics' => [
|
'statistics' => [
|
||||||
'period' => [
|
'period' => [
|
||||||
'in' => 0,
|
'in' => 0,
|
||||||
'out' => 0,
|
'out' => 0,
|
||||||
'diff' => 0,
|
'diff' => 0,
|
||||||
't_in' => 0,
|
't_in' => 0,
|
||||||
't_out' => 0,
|
't_out' => 0,
|
||||||
't_diff' => 0
|
't_diff' => 0
|
||||||
],
|
],
|
||||||
'categories' => [],
|
'categories' => [],
|
||||||
'budgets' => [],
|
'budgets' => [],
|
||||||
'accounts' => []
|
'accounts' => []
|
||||||
],
|
],
|
||||||
'journals' => $paginator,
|
'journals' => $paginator,
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->_accounts->shouldReceive('show')->once()->andReturn($data);
|
$this->_accounts->shouldReceive('show')->once()->andReturn($data);
|
||||||
@ -191,9 +303,42 @@ class AccountControllerTest extends TestCase
|
|||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testShowWrongType()
|
||||||
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Initial balance account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
|
// for successful binding.
|
||||||
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||||
|
Auth::shouldReceive('check')->andReturn(true);
|
||||||
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||||
|
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn($account->email);
|
||||||
|
|
||||||
|
|
||||||
|
$this->action('GET', 'AccountController@show', $account->id);
|
||||||
|
$this->assertViewHas('message');
|
||||||
|
$this->assertResponseOk();
|
||||||
|
}
|
||||||
|
|
||||||
public function testStore()
|
public function testStore()
|
||||||
{
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Default account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
$this->_repository->shouldReceive('store')->andReturn($account);
|
$this->_repository->shouldReceive('store')->andReturn($account);
|
||||||
$this->action('POST', 'AccountController@store');
|
$this->action('POST', 'AccountController@store');
|
||||||
$this->assertRedirectedToRoute('accounts.index');
|
$this->assertRedirectedToRoute('accounts.index');
|
||||||
@ -201,7 +346,16 @@ class AccountControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testStoreFails()
|
public function testStoreFails()
|
||||||
{
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Default account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
unset($account->name);
|
unset($account->name);
|
||||||
$this->_repository->shouldReceive('store')->andReturn($account);
|
$this->_repository->shouldReceive('store')->andReturn($account);
|
||||||
$this->action('POST', 'AccountController@store');
|
$this->action('POST', 'AccountController@store');
|
||||||
@ -210,7 +364,16 @@ class AccountControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testStoreRecreate()
|
public function testStoreRecreate()
|
||||||
{
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Default account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
$this->_repository->shouldReceive('store')->andReturn($account);
|
$this->_repository->shouldReceive('store')->andReturn($account);
|
||||||
$this->action('POST', 'AccountController@store', ['create' => '1']);
|
$this->action('POST', 'AccountController@store', ['create' => '1']);
|
||||||
$this->assertRedirectedToRoute('accounts.create');
|
$this->assertRedirectedToRoute('accounts.create');
|
||||||
@ -218,7 +381,16 @@ class AccountControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Default account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
// for successful binding.
|
// for successful binding.
|
||||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||||
Auth::shouldReceive('check')->andReturn(true);
|
Auth::shouldReceive('check')->andReturn(true);
|
||||||
@ -230,9 +402,42 @@ class AccountControllerTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUpdateWrongType()
|
||||||
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Initial balance account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
|
// for successful binding.
|
||||||
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||||
|
Auth::shouldReceive('check')->andReturn(true);
|
||||||
|
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($account->user_id);
|
||||||
|
$this->_repository->shouldReceive('update')->andReturn($account);
|
||||||
|
|
||||||
|
$this->action('POST', 'AccountController@update', $account->id);
|
||||||
|
$this->assertViewHas('message');
|
||||||
|
$this->assertResponseOk();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testUpdateFails()
|
public function testUpdateFails()
|
||||||
{
|
{
|
||||||
|
/** @var \Account $account */
|
||||||
$account = f::create('Account');
|
$account = f::create('Account');
|
||||||
|
|
||||||
|
/** @var \AccountType $accountType */
|
||||||
|
$accountType = f::create('AccountType');
|
||||||
|
$accountType->description = 'Default account';
|
||||||
|
$accountType->save();
|
||||||
|
$account->accountType()->associate($accountType);
|
||||||
|
$account->save();
|
||||||
|
|
||||||
unset($account->name);
|
unset($account->name);
|
||||||
// for successful binding.
|
// for successful binding.
|
||||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||||
|
@ -20,33 +20,23 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||||
|
@if(count($accounts['personal']) > 0)
|
||||||
<h3>Your accounts</h3>
|
<h3>Your accounts</h3>
|
||||||
<p style="width:50%;" class="text-info">
|
<p style="width:50%;" class="text-info">
|
||||||
These are your personal accounts.
|
These are your personal accounts.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@include('accounts.list',['accounts' => $accounts['personal']])
|
@include('accounts.list',['accounts' => $accounts['personal']])
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if(count($accounts['beneficiaries']) > 0)
|
||||||
<h3>Beneficiaries</h3>
|
<h3>Beneficiaries</h3>
|
||||||
<p style="width:50%;" class="text-info">
|
<p style="width:50%;" class="text-info">
|
||||||
These are beneficiaries; places where you spend money or people who pay you.
|
These are beneficiaries; places where you spend money or people who pay you.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@include('accounts.list',['accounts' => $accounts['beneficiaries']])
|
@include('accounts.list',['accounts' => $accounts['beneficiaries']])
|
||||||
|
@endif
|
||||||
|
|
||||||
<h3>Initial balances</h3>
|
|
||||||
<p style="width:50%;" class="text-info">
|
|
||||||
These are system accounts; created to add balance to the books when you add a personal account
|
|
||||||
which already has money in it. That money has to come from somewhere.
|
|
||||||
</p>
|
|
||||||
@include('accounts.list',['accounts' => $accounts['initial']])
|
|
||||||
|
|
||||||
<h3>Cash</h3>
|
|
||||||
<p style="width:50%;" class="text-info">
|
|
||||||
This is a system account. When you don't specify a beneficiary or draw many from an ATM (or put cash in your
|
|
||||||
personal accounts) it gets added or drawn from this account.
|
|
||||||
</p>
|
|
||||||
@include('accounts.list',['accounts' => $accounts['cash']])
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||||
<table class="table table-striped table-condensed">
|
<table class="table table-striped table-condensed">
|
||||||
|
@if(count($show['statistics']['accounts']) > 0)
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:30%;">Related accounts</td>
|
<td style="width:30%;">Related accounts</td>
|
||||||
<td>
|
<td>
|
||||||
@ -70,22 +71,27 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@endif
|
||||||
|
@if(count($show['statistics']['categories']) > 0)
|
||||||
<tr>
|
<tr>
|
||||||
<td>Related categories</td>
|
<td>Related categories</td>
|
||||||
<td>
|
<td>
|
||||||
@foreach($show['statistics']['categories'] as $cat)
|
@foreach($show['statistics']['categories'] as $cat)
|
||||||
<a href="#category-overview" class="btn btn-default btn-xs">{{{$cat->name}}}</a>
|
<a href="{{route('categories.show',$cat->id)}}" class="btn btn-default btn-xs">{{{$cat->name}}}</a>
|
||||||
@endforeach
|
@endforeach
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@endif
|
||||||
|
@if(count($show['statistics']['budgets']) > 0)
|
||||||
<tr>
|
<tr>
|
||||||
<td>Related budgets</td>
|
<td>Related budgets</td>
|
||||||
<td>
|
<td>
|
||||||
@foreach($show['statistics']['budgets'] as $bud)
|
@foreach($show['statistics']['budgets'] as $bud)
|
||||||
<a href="#budget-overview" class="btn btn-default btn-xs">{{{$bud->name}}}</a>
|
<a href="{{route('budgets.show',$bud->id)}}" class="btn btn-default btn-xs">{{{$bud->name}}}</a>
|
||||||
@endforeach
|
@endforeach
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@endif
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -63,6 +63,7 @@
|
|||||||
<a href="{{route('accounts.show',$journal->transactions[1]->account_id)}}">{{{$journal->transactions[1]->account->name}}}</a>
|
<a href="{{route('accounts.show',$journal->transactions[1]->account_id)}}">{{{$journal->transactions[1]->account->name}}}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@if($journal->transactiontype->type != 'Opening balance')
|
||||||
<div class="btn-group btn-group-xs">
|
<div class="btn-group btn-group-xs">
|
||||||
<a href="{{route('transactions.edit',$journal->id)}}" class="btn btn-default">
|
<a href="{{route('transactions.edit',$journal->id)}}" class="btn btn-default">
|
||||||
<span class="glyphicon glyphicon-pencil"></span>
|
<span class="glyphicon glyphicon-pencil"></span>
|
||||||
@ -70,6 +71,7 @@
|
|||||||
<span class="glyphicon glyphicon-trash"></span>
|
<span class="glyphicon glyphicon-trash"></span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@endif
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
Loading…
Reference in New Issue
Block a user