Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix #2694
James Cole6efe5cfd4d2b
diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.phpindex 15769a7890..b0b7525ca3 100644--- a/app/Http/Controllers/Account/IndexController.php+++ b/app/Http/Controllers/Account/IndexController.php@@ -63,20 +63,19 @@ class IndexController extends Controller}/**- * Show list of accounts.- ** @param Request $request- * @param string $objectType+ * @param string $objectType** @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View*/- public function index(Request $request, string $objectType)+ public function inactive(Request $request, string $objectType){$objectType = $objectType ?? 'asset';- $subTitle = (string)trans(sprintf('firefly.%s_accounts', $objectType));+ $inactivePage = true;+ $subTitle = (string)trans(sprintf('firefly.%s_accounts_inactive', $objectType));$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));$types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType));- $collection = $this->repository->getAccountsByType($types);+ $collection = $this->repository->getInactiveAccountsByType($types);$total = $collection->count();$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;@@ -105,11 +104,65 @@ class IndexController extends Controller});+ // make paginator:+ $accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);+ $accounts->setPath(route('accounts.inactive.index', [$objectType]));++ return view('accounts.index', compact('objectType','inactivePage', 'subTitleIcon', 'subTitle', 'page', 'accounts'));++ }++ /**+ * Show list of accounts.+ *+ * @param Request $request+ * @param string $objectType+ *+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View+ */+ public function index(Request $request, string $objectType)+ {+ $objectType = $objectType ?? 'asset';+ $subTitle = (string)trans(sprintf('firefly.%s_accounts', $objectType));+ $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));+ $types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType));+ $collection = $this->repository->getActiveAccountsByType($types);+ $total = $collection->count();+ $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');+ $pageSize = (int)app('preferences')->get('listPageSize', 50)->data;+ $accounts = $collection->slice(($page - 1) * $pageSize, $pageSize);+ $inactiveCount = $this->repository->getInactiveAccountsByType($types)->count();+++ unset($collection);+ /** @var Carbon $start */+ $start = clone session('start', Carbon::now()->startOfMonth());+ /** @var Carbon $end */+ $end = clone session('end', Carbon::now()->endOfMonth());+ $start->subDay();++ $ids = $accounts->pluck('id')->toArray();+ $startBalances = app('steam')->balancesByAccounts($accounts, $start);+ $endBalances = app('steam')->balancesByAccounts($accounts, $end);+ $activities = app('steam')->getLastActivities($ids);++ $accounts->each(+ function (Account $account) use ($activities, $startBalances, $endBalances) {+ $account->lastActivityDate = $this->isInArray($activities, $account->id);+ $account->startBalance = $this->isInArray($startBalances, $account->id);+ $account->endBalance = $this->isInArray($endBalances, $account->id);+ $account->difference = bcsub($account->endBalance, $account->startBalance);+ $account->interest = round($this->repository->getMetaValue($account, 'interest'), 6);+ $account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));+ $account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type));+ }+ );+// make paginator:$accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);$accounts->setPath(route('accounts.index', [$objectType]));- return view('accounts.index', compact('objectType', 'subTitleIcon', 'subTitle', 'page', 'accounts'));+ return view('accounts.index', compact('objectType', 'inactiveCount', 'subTitleIcon', 'subTitle', 'page', 'accounts'));}diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex 73de3a9a02..048e3457a5 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -318,9 +318,8 @@ class AccountRepository implements AccountRepositoryInterface$query->where('active', 1);$query->orderBy('accounts.account_type_id', 'ASC');$query->orderBy('accounts.name', 'ASC');- $result = $query->get(['accounts.*']);- return $result;+ return $query->get(['accounts.*']);}/**@@ -606,4 +605,27 @@ class AccountRepository implements AccountRepositoryInterfacereturn $account;}++ /**+ * @param array $types+ *+ * @return Collection+ */+ public function getInactiveAccountsByType(array $types): Collection+ {+ /** @var Collection $result */+ $query = $this->user->accounts()->with(+ ['accountmeta' => function (HasMany $query) {+ $query->where('name', 'account_role');+ }]+ );+ if (count($types) > 0) {+ $query->accountTypeIn($types);+ }+ $query->where('active', 0);+ $query->orderBy('accounts.account_type_id', 'ASC');+ $query->orderBy('accounts.name', 'ASC');++ return $query->get(['accounts.*']);+ }}diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.phpindex 54793896ca..07c2727505 100644--- a/app/Repositories/Account/AccountRepositoryInterface.php+++ b/app/Repositories/Account/AccountRepositoryInterface.php@@ -142,6 +142,13 @@ interface AccountRepositoryInterface*/public function getActiveAccountsByType(array $types): Collection;+ /**+ * @param array $types+ *+ * @return Collection+ */+ public function getInactiveAccountsByType(array $types): Collection;+/*** @return Account*/diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex fe2c84dfc7..539daf219d 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -759,6 +759,9 @@ return ['list_inactive_rule' => 'inactive rule',// accounts:+ 'inactive_account_link' => 'You have :count inactive (archived) accounts, which you can view on this separate page.',+ 'all_accounts_inactive' => 'These are your inactive accounts.',+ 'active_account_link' => 'This link goes back to your active accounts.','account_missing_transaction' => 'Account #:id (":name") cannot be viewed directly, but Firefly is missing redirect information.','details_for_asset' => 'Details for asset account ":name"','details_for_expense' => 'Details for expense account ":name"',@@ -786,7 +789,9 @@ return ['make_new_revenue_account' => 'Create a new revenue account','make_new_liabilities_account' => 'Create a new liability','asset_accounts' => 'Asset accounts',+ 'asset_accounts_inactive' => 'Asset accounts (inactive)','expense_accounts' => 'Expense accounts',+ 'expense_accounts_inactive' => 'Expense accounts (inactive)','revenue_accounts' => 'Revenue accounts','cash_accounts' => 'Cash accounts','Cash account' => 'Cash account',diff --git a/resources/views/v1/accounts/index.twig b/resources/views/v1/accounts/index.twigindex 2a133a2553..ec6088e853 100644--- a/resources/views/v1/accounts/index.twig+++ b/resources/views/v1/accounts/index.twig@@ -35,7 +35,31 @@{% include 'list.accounts' %}</div><div class="box-footer">- <a href="{{ route('accounts.create', objectType) }}" class="btn btn-success"><i class="fa fa-plus fa-fw"></i> {{ ('make_new_' ~ objectType ~ '_account')|_ }}</a>+ <p>+ <a href="{{ route('accounts.create', objectType) }}" class="btn btn-success"><i+ class="fa fa-plus fa-fw"></i> {{ ('make_new_' ~ objectType ~ '_account')|_ }}</a>+ </p>+ {% if inactiveCount > 0 %}+ <p><small>+ <em>+ <a href="{{ route('accounts.inactive.index', objectType) }}" class="text-muted">+ {{ trans('firefly.inactive_account_link', {count: inactiveCount}) }}+ </a>+ </em>+ </small>+ </p>+ {% endif %}+ {% if inactivePage %}+ <p><small class="text-muted">+ <em>+ {{ 'all_accounts_inactive'|_ }}+ <a href="{{ route('accounts.index', objectType) }}">+ {{ trans('firefly.active_account_link', {count: inactiveCount}) }}+ </a>+ </em>+ </small>+ </p>+ {% endif %}</div></div></div>diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.phpindex 3150015541..fc08ecd78b 100644--- a/routes/breadcrumbs.php+++ b/routes/breadcrumbs.php@@ -88,6 +88,13 @@ try {$breadcrumbs->push(trans('firefly.' . strtolower(e($what)) . '_accounts'), route('accounts.index', [$what]));});+ Breadcrumbs::register( // inactive+ 'accounts.inactive.index',+ static function (BreadcrumbsGenerator $breadcrumbs, string $what) {+ $breadcrumbs->parent('home');+ $breadcrumbs->push(trans('firefly.' . strtolower(e($what)) . '_accounts_inactive'), route('accounts.inactive.index', [$what]));+ }+ );Breadcrumbs::register('accounts.create',diff --git a/routes/web.php b/routes/web.phpindex 280609bce9..b25a01c4e1 100644--- a/routes/web.php+++ b/routes/web.php@@ -108,9 +108,19 @@ Route::group();+//// show inactive+//+/*** Account Controller*/+Route::group(+ ['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers', 'prefix' => 'inactive-accounts', 'as' => 'accounts.'], static function () {+ Route::get('{objectType}', ['uses' => 'Account\IndexController@inactive', 'as' => 'inactive.index'])->where(+ 'objectType', 'revenue|asset|expense|liabilities'+ );+}+);Route::group(['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers', 'prefix' => 'accounts', 'as' => 'accounts.'], static function () {