mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Fix #2694
This commit is contained in:
@@ -63,20 +63,19 @@ class IndexController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
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'));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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 AccountRepositoryInterface
|
||||
|
||||
return $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.*']);
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
*/
|
||||
|
@@ -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',
|
||||
|
@@ -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>
|
||||
|
@@ -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',
|
||||
|
@@ -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 () {
|
||||
|
||||
|
Reference in New Issue
Block a user