/** * Show an overview for a category for all time, per month/week/year. * * @param CategoryRepositoryInterface $repository * @param Category $category * * @return \Symfony\Component\HttpFoundation\Response */ public function all(CategoryRepositoryInterface $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 } while ($start <= $end) { $currentEnd = Navigation::endOfPeriod($start, $range); $spent = $repository->balanceInPeriod($category, $start, $currentEnd); $entries->push([clone $start, $spent]); $start = Navigation::addPeriod($start, $range, 0); } $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 * * @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); // get the sum from $spentArray and $earnedArray: $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); } // limit the set to the last 40: $entries = $entries->reverse(); $entries = $entries->slice(0, 48); $entries = $entries->reverse(); $data = $this->generator->all($entries); $cache->store($data); return Response::json($data); }