/** * @param ARI $repository * @param Account $account * * @return View */ public function show(ARI $repository, Account $account) { // show journals from current period only: $subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type); $subTitle = $account->name; $range = Preferences::get('viewRange', '1M')->data; /** @var Carbon $start */ $start = session('start', Navigation::startOfPeriod(new Carbon(), $range)); /** @var Carbon $end */ $end = session('end', Navigation::endOfPeriod(new Carbon(), $range)); $page = intval(Input::get('page')); $pageSize = Preferences::get('transactionPageSize', 50)->data; $offset = ($page - 1) * $pageSize; $set = $repository->journalsInPeriod(new Collection([$account]), [], $start, $end); $count = $set->count(); $subSet = $set->splice($offset, $pageSize); $journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page); $journals->setPath('accounts/show/' . $account->id); // grouped other months thing: // oldest transaction in account: $start = $repository->firstUseDate($account); if ($start->year == 1900) { $start = new Carbon(); } $range = Preferences::get('viewRange', '1M')->data; $start = Navigation::startOfPeriod($start, $range); $end = Navigation::endOfX(new Carbon(), $range); $entries = new Collection(); // chart properties for cache: $cache = new CacheProperties(); $cache->addProperty($start); $cache->addProperty($end); $cache->addProperty('account-show'); $cache->addProperty($account->id); if ($cache->has()) { $entries = $cache->get(); return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle')); } while ($end >= $start) { $end = Navigation::startOfPeriod($end, $range); $currentEnd = Navigation::endOfPeriod($end, $range); $spent = $this->spentInPeriod($account, $end, $currentEnd); $earned = $this->earnedInPeriod($account, $end, $currentEnd); $dateStr = $end->format('Y-m-d'); $dateName = Navigation::periodShow($end, $range); $entries->push([$dateStr, $dateName, $spent, $earned]); $end = Navigation::subtractPeriod($end, $range, 1); } $cache->store($entries); return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle')); }