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