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 @@
+ | Name | +Current balance | +Active | +Last activity | +
---|---|---|---|---|
+ + | +{{{$account->name}}} | +{{mf($account->balance())}} | ++ @if($account->active) + + @else + + @endif + | ++ lastActionDate(); ?> + @if($active) + {{{$active->format('j F Y @ H:i')}}} + @else + Never + @endif + | +