/**
  * @param CRI                  $repository
  * @param AccountCrudInterface $crud
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function frontpage(CRI $repository, AccountCrudInterface $crud)
 {
     $start = session('start', Carbon::now()->startOfMonth());
     $end = session('end', Carbon::now()->endOfMonth());
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('category');
     $cache->addProperty('frontpage');
     if ($cache->has()) {
         return Response::json($cache->get());
     }
     $categories = $repository->getCategories();
     $accounts = $crud->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
     $set = new Collection();
     /** @var Category $category */
     foreach ($categories as $category) {
         $spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end);
         if (bccomp($spent, '0') === -1) {
             $category->spent = $spent;
             $set->push($category);
         }
     }
     // this is a "fake" entry for the "no category" entry.
     $entry = new stdClass();
     $entry->name = trans('firefly.no_category');
     $entry->spent = $repository->spentInPeriodWithoutCategory(new Collection(), $start, $end);
     $set->push($entry);
     $set = $set->sortBy('spent');
     $data = $this->generator->frontpage($set);
     $cache->store($data);
     return Response::json($data);
 }
 /**
  * Show this month's category overview.
  *
  * @param CRI $repository
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function frontpage(CRI $repository)
 {
     $start = Session::get('start', Carbon::now()->startOfMonth());
     $end = Session::get('end', Carbon::now()->endOfMonth());
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('category');
     $cache->addProperty('frontpage');
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     // get data for categories (and "no category"):
     $set = $repository->spentForAccountsPerMonth(new Collection(), $start, $end);
     $outside = $repository->sumSpentNoCategory(new Collection(), $start, $end);
     // this is a "fake" entry for the "no category" entry.
     $entry = new stdClass();
     $entry->name = trans('firefly.no_category');
     $entry->spent = $outside;
     $set->push($entry);
     $set = $set->sortBy('spent');
     $data = $this->generator->frontpage($set);
     $cache->store($data);
     return Response::json($data);
 }