/** * @param CategoryRepositoryInterface $repository * * @return \Illuminate\View\View */ public function index(CategoryRepositoryInterface $repository) { $categories = $repository->getCategories(); $categories->each(function (Category $category) use($repository) { $category->lastActivity = $repository->getLatestActivity($category); }); return view('categories.index', compact('categories')); }
/** * This chart will only show income. * * @param CategoryRepositoryInterface $repository * @param $year * @param bool $shared * * @return \Symfony\Component\HttpFoundation\Response */ public function earnedInYear(CategoryRepositoryInterface $repository, $year, $shared = false) { $start = new Carbon($year . '-01-01'); $end = new Carbon($year . '-12-31'); $cache = new CacheProperties(); // chart properties for cache: $cache->addProperty($start); $cache->addProperty($end); $cache->addProperty('category'); $cache->addProperty('earned-in-year'); if ($cache->has()) { return Response::json($cache->get()); // @codeCoverageIgnore } $shared = $shared == 'shared' ? true : false; $allCategories = $repository->getCategories(); $allEntries = new Collection(); $categories = $allCategories->filter(function (Category $category) use($repository, $start, $end, $shared) { $spent = $repository->balanceInPeriod($category, $start, $end, $shared); if ($spent > 0) { return $category; } return null; }); while ($start < $end) { $month = clone $start; // month is the current end of the period $month->endOfMonth(); $row = [clone $start]; // make a row: foreach ($categories as $category) { // each budget, fill the row $spent = $repository->balanceInPeriod($category, $start, $month, $shared); if ($spent > 0) { $row[] = $spent; } else { $row[] = 0; } } $allEntries->push($row); $start->addMonth(); } $data = $this->generator->earnedInYear($categories, $allEntries); $cache->store($data); return Response::json($data); }
/** * @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); }
/** * Returns a list of categories. * * @param CategoryRepositoryInterface $repository * * @return \Illuminate\Http\JsonResponse */ public function categories(CategoryRepositoryInterface $repository) { $list = $repository->getCategories(); $return = []; foreach ($list as $entry) { $return[] = $entry->name; } sort($return); return Response::json($return); }
/** * @param CRI $repository * * @return View */ public function index(CRI $repository) { $categories = $repository->getCategories(); $categories->each(function (Category $category) use($repository) { $category->lastActivity = $repository->lastUseDate($category, new Collection()); }); return view('categories.index', compact('categories')); }
/** * Returns a list of categories. * * @param CRI $repository * * @return \Illuminate\Http\JsonResponse */ public function categories(CRI $repository) { $list = $repository->getCategories(); $return = []; foreach ($list as $entry) { $return[] = $entry->name; } return Response::json($return); }
/** * 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); }