diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 0347ca71a5..8544c5fc99 100644 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -172,6 +172,9 @@ class AccountController extends BaseController */ public function index($what = 'default') { + /** @var \FireflyIII\Database\Account $acct */ + $acct = App::make('FireflyIII\Database\Account'); + switch ($what) { default: throw new FireflyException('Cannot handle account type "' . e($what) . '".'); @@ -179,18 +182,21 @@ class AccountController extends BaseController case 'asset': $subTitleIcon = 'fa-money'; $subTitle = 'Asset accounts'; + $accounts = $acct->getAssetAccounts(); break; case 'expense': $subTitleIcon = 'fa-shopping-cart'; $subTitle = 'Expense accounts'; + $accounts = $acct->getExpenseAccounts(); break; case 'revenue': $subTitleIcon = 'fa-download'; $subTitle = 'Revenue accounts'; + $accounts = $acct->getRevenueAccounts(); break; } - return View::make('accounts.index')->with('what', $what)->with(compact('subTitleIcon'))->with(compact('subTitle')); + return View::make('accounts.index',compact('what','subTitleIcon','subTitle','accounts')); } /** diff --git a/app/models/Account.php b/app/models/Account.php index ce207b98d9..b126388ad1 100644 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -1,4 +1,5 @@ ['required', 'between:1,100', 'alphabasic'], 'user_id' => 'required|exists:users,id', + = ['name' => ['required', 'between:1,100', 'alphabasic'], 'user_id' => 'required|exists:users,id', 'account_type_id' => 'required|exists:account_types,id', 'active' => 'required|boolean' ]; @@ -64,21 +65,11 @@ class Account extends Ardent return floatval( $this->transactions()->leftJoin( - 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' - )->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount') + 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' + )->where('transaction_journals.date', '<=', $date->format('Y-m-d'))->sum('transactions.amount') ); } - /** - * Transactions. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function transactions() - { - return $this->hasMany('Transaction'); - } - /** * @param TransactionJournal $journal * @@ -88,13 +79,36 @@ class Account extends Ardent { return floatval( $this->transactions()->leftJoin( - 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' - )->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d'))->where( - 'transaction_journals.created_at', '<=', $journal->created_at->format('Y-m-d H:i:s') - )->where('transaction_journals.id', '!=', $journal->id)->sum('transactions.amount') + 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' + )->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d'))->where( + 'transaction_journals.created_at', '<=', $journal->created_at->format('Y-m-d H:i:s') + )->where('transaction_journals.id', '!=', $journal->id)->sum('transactions.amount') ); } + /** + * @return Carbon + */ + public function lastActionDate() + { + $transaction = $this->transactions()->orderBy('updated_at', 'DESC')->first(); + if(is_null($transaction)) { + return null; + } + + return $transaction->updated_at; + } + + /** + * Transactions. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function transactions() + { + return $this->hasMany('Transaction'); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/app/views/accounts/index.blade.php b/app/views/accounts/index.blade.php index 2f43b6fbe2..555105e477 100644 --- a/app/views/accounts/index.blade.php +++ b/app/views/accounts/index.blade.php @@ -22,7 +22,7 @@
-
+ @include('list.accounts')
diff --git a/app/views/index.blade.php b/app/views/index.blade.php index c5422f830b..9fc7e6766d 100644 --- a/app/views/index.blade.php +++ b/app/views/index.blade.php @@ -101,7 +101,7 @@
- @include('lists.old.journals-small-index',['transactions' => $data[0],'account' => $data[1]]) + @include('list.journals-tiny',['transactions' => $data[0],'account' => $data[1]])
@endforeach diff --git a/app/views/list/accounts.blade.php b/app/views/list/accounts.blade.php new file mode 100644 index 0000000000..54f4ac7ecd --- /dev/null +++ b/app/views/list/accounts.blade.php @@ -0,0 +1,37 @@ + + + + + + + + + @foreach($accounts as $account) + + + + + + + + + @endforeach +
 NameCurrent balanceActiveLast activity
+
+ + +
+
{{{$account->name}}}{{mf($account->balance())}} + @if($account->active) + + @else + + @endif + + lastActionDate(); ?> + @if($active) + {{{$active->format('j F Y @ H:i')}}} + @else + Never + @endif +
\ No newline at end of file diff --git a/app/views/list/journals-tiny.blade.php b/app/views/list/journals-tiny.blade.php new file mode 100644 index 0000000000..91c2b6f2d3 --- /dev/null +++ b/app/views/list/journals-tiny.blade.php @@ -0,0 +1,35 @@ +
+@foreach($transactions as $journal) + + + @if($journal->transactiontype->type == 'Withdrawal') + + @endif + @if($journal->transactiontype->type == 'Deposit') + + @endif + @if($journal->transactiontype->type == 'Transfer') + + @endif + + {{{$journal->description}}} + + +@if(isset($account)) + @foreach($journal->transactions as $index => $t) + @if($t->account_id == $account->id) + {{mf($t->amount)}} + @endif + @endforeach +@else + @foreach($journal->transactions as $index => $t) + @if($index == 0) + {{mf($t->amount)}} + @endif + @endforeach +@endif + + + +@endforeach +
\ No newline at end of file