/** * Show this month's category overview. * * @param CategoryRepositoryInterface $repository * * @return \Symfony\Component\HttpFoundation\Response */ public function frontpage(CategoryRepositoryInterface $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 } $array = $repository->getCategoriesAndExpensesCorrected($start, $end); // sort by callback: uasort($array, function ($left, $right) { if ($left['sum'] == $right['sum']) { return 0; } return $left['sum'] < $right['sum'] ? 1 : -1; }); $set = new Collection($array); $data = $this->generator->frontpage($set); 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); }