/**
  * This chart will only show income.
  *
  * @param CategoryRepositoryInterface $repository
  * @param                             $year
  * @param bool                        $shared
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function earnedInYear(CategoryRepositoryInterface $repository, $year, $shared = false)
 {
     $start = new Carbon($year . '-01-01');
     $end = new Carbon($year . '-12-31');
     $cache = new CacheProperties();
     // chart properties for cache:
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('category');
     $cache->addProperty('earned-in-year');
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $shared = $shared == 'shared' ? true : false;
     $allCategories = $repository->getCategories();
     $allEntries = new Collection();
     $categories = $allCategories->filter(function (Category $category) use($repository, $start, $end, $shared) {
         $spent = $repository->balanceInPeriod($category, $start, $end, $shared);
         if ($spent > 0) {
             return $category;
         }
         return null;
     });
     while ($start < $end) {
         $month = clone $start;
         // month is the current end of the period
         $month->endOfMonth();
         $row = [clone $start];
         // make a row:
         foreach ($categories as $category) {
             // each budget, fill the row
             $spent = $repository->balanceInPeriod($category, $start, $month, $shared);
             if ($spent > 0) {
                 $row[] = $spent;
             } else {
                 $row[] = 0;
             }
         }
         $allEntries->push($row);
         $start->addMonth();
     }
     $data = $this->generator->earnedInYear($categories, $allEntries);
     $cache->store($data);
     return Response::json($data);
 }