Some small bug fixes in the account views.

This commit is contained in:
James Cole 2015-03-02 11:42:27 +01:00
parent b261b0b447
commit d98d366eea
3 changed files with 59 additions and 18 deletions

View File

@ -116,7 +116,14 @@ class AccountController extends Controller
$subTitle = Config::get('firefly.subTitlesByIdentifier.' . $what);
$subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
$types = Config::get('firefly.accountTypesByIdentifier.' . $what);
$accounts = Auth::user()->accounts()->accountTypeIn($types)->get(['accounts.*']);
// move to repository:
$accounts = Auth::user()->accounts()->with(
['accountmeta' => function ($query) {
$query->where('name', 'accountRole');
}]
)->accountTypeIn($types)->get(['accounts.*']);
return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts'));
}

View File

@ -46,7 +46,7 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function getJournals(Account $account, $page, $range = 'session')
{
$offset = ($page-1) * 50;
$offset = ($page - 1) * 50;
$query = Auth::user()
->transactionJournals()
->withRelevantData()
@ -69,6 +69,23 @@ class AccountRepository implements AccountRepositoryInterface
}
/**
* @param Account $account
*
* @return float
*/
public function leftOnAccount(Account $account)
{
$balance = \Steam::balance($account);
/** @var PiggyBank $p */
foreach ($account->piggybanks()->get() as $p) {
$balance -= $p->currentRelevantRep()->currentamount;
}
return $balance;
}
/**
* @param Account $account
*
@ -123,13 +140,7 @@ class AccountRepository implements AccountRepositoryInterface
$account->save();
// update meta data:
/** @var AccountMeta $meta */
foreach ($account->accountMeta()->get() as $meta) {
if ($meta->name == 'accountRole') {
$meta->data = $data['accountRole'];
$meta->save();
}
}
$this->_updateMetadata($account, $data);
$openingBalance = $this->openingBalanceTransaction($account);
@ -313,18 +324,35 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @param Account $account
*
* @return float
* @param array $data
*/
public function leftOnAccount(Account $account)
protected function _updateMetadata(Account $account, array $data)
{
$balance = \Steam::balance($account);
/** @var PiggyBank $p */
foreach ($account->piggybanks()->get() as $p) {
$balance -= $p->currentRelevantRep()->currentamount;
$metaEntries = $account->accountMeta()->get();
$updated = false;
/** @var AccountMeta $entry */
foreach ($metaEntries as $entry) {
if ($entry->name == 'accountRole') {
$entry->data = $data['accountRole'];
$updated = true;
$entry->save();
}
}
return $balance;
if ($updated === false) {
$metaData = new AccountMeta(
[
'account_id' => $account->id,
'name' => 'accountRole',
'data' => $data['accountRole']
]
);
if (!$metaData->isValid()) {
App::abort(500);
}
$metaData->save();
}
}
}

View File

@ -19,7 +19,13 @@
</td>
<td><a href="{{route('accounts.show',$account->id)}}">{{{$account->name}}}</a></td>
@if(isset($what) && $what == 'asset')
<td>{{{$account->accountRole}}}</td>
<td>
@foreach($account->accountmeta as $entry)
@if($entry->name == 'accountRole')
{{Config::get('firefly.accountRoles.'.$entry->data)}}
@endif
@endforeach
</td>
@endif
<td>{!! Amount::format(Steam::balance($account)) !!}</td>
<td>