/**
  * Show an overview for a category for all time, per month/week/year.
  *
  * @param SCRI     $repository
  * @param Category $category
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function all(SCRI $repository, Category $category)
 {
     // oldest transaction in category:
     $start = $repository->getFirstActivityDate($category);
     $range = Preferences::get('viewRange', '1M')->data;
     $start = Navigation::startOfPeriod($start, $range);
     $end = new Carbon();
     $entries = new Collection();
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('all');
     $cache->addProperty('categories');
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $spentArray = $repository->spentPerDay($category, $start, $end);
     $earnedArray = $repository->earnedPerDay($category, $start, $end);
     while ($start <= $end) {
         $currentEnd = Navigation::endOfPeriod($start, $range);
         $spent = $this->getSumOfRange($start, $currentEnd, $spentArray);
         $earned = $this->getSumOfRange($start, $currentEnd, $earnedArray);
         $date = Navigation::periodShow($start, $range);
         $entries->push([clone $start, $date, $spent, $earned]);
         $start = Navigation::addPeriod($start, $range, 0);
     }
     $entries = $entries->reverse();
     $entries = $entries->slice(0, 48);
     $entries = $entries->reverse();
     $data = $this->generator->all($entries);
     $cache->store($data);
     return Response::json($data);
 }
 /**
  * @param SCRI     $repository
  * @param Category $category
  *
  * @return \Illuminate\View\View
  */
 public function show(SCRI $repository, Category $category)
 {
     $hideCategory = true;
     // used in list.
     $page = intval(Input::get('page'));
     $set = $repository->getJournals($category, $page);
     $count = $repository->countJournals($category);
     $subTitle = $category->name;
     $journals = new LengthAwarePaginator($set, $count, 50, $page);
     $journals->setPath('categories/show/' . $category->id);
     // list of ranges for list of periods:
     // oldest transaction in category:
     $start = $repository->getFirstActivityDate($category);
     $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('category-show');
     $cache->addProperty($category->id);
     // get all spent and earned data:
     // get amount earned in period, grouped by day.
     $spentArray = $repository->spentPerDay($category, $start, $end);
     $earnedArray = $repository->earnedPerDay($category, $start, $end);
     if ($cache->has()) {
         $entries = $cache->get();
     } else {
         while ($end >= $start) {
             $end = Navigation::startOfPeriod($end, $range);
             $currentEnd = Navigation::endOfPeriod($end, $range);
             // get data from spentArray:
             $spent = $this->getSumOfRange($end, $currentEnd, $spentArray);
             $earned = $this->getSumOfRange($end, $currentEnd, $earnedArray);
             $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('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));
 }