/**
  * Show an overview for a category for all time, per month/week/year.
  *
  * @param CRI                  $repository
  * @param AccountCrudInterface $crud
  * @param Category             $category
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function all(CRI $repository, AccountCrudInterface $crud, Category $category)
 {
     $start = $repository->firstUseDate($category);
     $range = Preferences::get('viewRange', '1M')->data;
     $start = Navigation::startOfPeriod($start, $range);
     $categoryCollection = new Collection([$category]);
     $end = new Carbon();
     $entries = new Collection();
     $cache = new CacheProperties();
     $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('all');
     $cache->addProperty('categories');
     if ($cache->has()) {
         return Response::json($cache->get());
     }
     while ($start <= $end) {
         $currentEnd = Navigation::endOfPeriod($start, $range);
         $spent = $repository->spentInPeriod($categoryCollection, $accounts, $start, $currentEnd);
         $earned = $repository->earnedInPeriod($categoryCollection, $accounts, $start, $currentEnd);
         $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);
 }
 /**
  * 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);
 }