/** * @param SCRI $repository * @param Category $category * * @param $date * * @return \Symfony\Component\HttpFoundation\Response */ public function specificPeriod(SCRI $repository, Category $category, $date) { $carbon = new Carbon($date); $range = Preferences::get('viewRange', '1M')->data; $start = Navigation::startOfPeriod($carbon, $range); $end = Navigation::endOfPeriod($carbon, $range); // chart properties for cache: $cache = new CacheProperties(); $cache->addProperty($start); $cache->addProperty($end); $cache->addProperty($category->id); $cache->addProperty('category'); $cache->addProperty('specificPeriod'); $cache->addProperty($date); if ($cache->has()) { return Response::json($cache->get()); // @codeCoverageIgnore } $entries = new Collection(); // get amount earned in period, grouped by day. $spentArray = $repository->spentPerDay($category, $start, $end); $earnedArray = $repository->earnedPerDay($category, $start, $end); // get amount spent in period, grouped by day. while ($start <= $end) { $str = $start->format('Y-m-d'); $spent = isset($spentArray[$str]) ? $spentArray[$str] : 0; $earned = isset($earnedArray[$str]) ? $earnedArray[$str] : 0; $date = Navigation::periodShow($start, '1D'); $entries->push([clone $start, $date, $spent, $earned]); $start->addDay(); } $data = $this->generator->period($entries); $cache->store($data); return Response::json($data); }
/** * @param CategoryFormRequest $request * @param SCRI $repository * @param Category $category * * @return \Illuminate\Http\RedirectResponse */ public function update(CategoryFormRequest $request, SCRI $repository, Category $category) { $categoryData = ['name' => $request->input('name')]; $repository->update($category, $categoryData); Session::flash('success', 'Category "' . $category->name . '" updated.'); Preferences::mark(); if (intval(Input::get('return_to_edit')) === 1) { Session::put('categories.edit.fromUpdate', true); return redirect(route('categories.edit', [$category->id])); } // redirect to previous URL. return redirect(Session::get('categories.edit.url')); }
/** * @param SCRI $repository * @param Category $category * @param Carbon $start * @param Carbon $end * * @return array */ private function makePeriodChart(SCRI $repository, Category $category, Carbon $start, Carbon $end) { // chart properties for cache: $cache = new CacheProperties(); $cache->addProperty($start); $cache->addProperty($end); $cache->addProperty($category->id); $cache->addProperty('specific-period'); if ($cache->has()) { return $cache->get(); // @codeCoverageIgnore } $entries = new Collection(); // get amount earned in period, grouped by day. // get amount spent in period, grouped by day. $spentArray = $repository->spentPerDay($category, $start, $end); $earnedArray = $repository->earnedPerDay($category, $start, $end); while ($start <= $end) { $str = $start->format('Y-m-d'); $spent = isset($spentArray[$str]) ? $spentArray[$str] : 0; $earned = isset($earnedArray[$str]) ? $earnedArray[$str] : 0; $date = Navigation::periodShow($start, '1D'); $entries->push([clone $start, $date, $spent, $earned]); $start->addDay(); } $data = $this->generator->period($entries); $cache->store($data); return $data; }