mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-11-03 20:55:05 +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
 | 
			
		||||
     * @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'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user