コード例 #1
0
 /**
  * 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->spentInPeriod($category, $start, $currentEnd);
         $earned = $repository->earnedInPeriod($category, $start, $currentEnd);
         $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);
 }
コード例 #2
0
 /**
  * @param CategoryRepositoryInterface $repository
  * @param Category                    $category
  *
  * @return \Illuminate\View\View
  */
 public function show(CategoryRepositoryInterface $repository, Category $category)
 {
     $hideCategory = true;
     // used in list.
     $page = intval(Input::get('page'));
     $set = $repository->getJournals($category, $page);
     $count = $repository->countJournals($category);
     $subTitle = $category->name;
     $journals = new LengthAwarePaginator($set, $count, 50, $page);
     $journals->setPath('categories/show/' . $category->id);
     // list of ranges for list of periods:
     // oldest transaction in category:
     $start = $repository->getFirstActivityDate($category);
     $range = Preferences::get('viewRange', '1M')->data;
     $start = Navigation::startOfPeriod($start, $range);
     $end = Navigation::endOfX(new Carbon(), $range);
     $entries = new Collection();
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('category-show');
     $cache->addProperty($category->id);
     if ($cache->has()) {
         $entries = $cache->get();
     } else {
         while ($end >= $start) {
             $end = Navigation::startOfPeriod($end, $range);
             $currentEnd = Navigation::endOfPeriod($end, $range);
             // here do something.
             $spent = $repository->spentInPeriod($category, $end, $currentEnd);
             $earned = $repository->earnedInPeriod($category, $end, $currentEnd);
             $dateStr = $end->format('Y-m-d');
             $dateName = Navigation::periodShow($end, $range);
             $entries->push([$dateStr, $dateName, $spent, $earned]);
             $end = Navigation::subtractPeriod($end, $range, 1);
         }
         $cache->store($entries);
     }
     return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));
 }
コード例 #3
0
 /**
  * @param CRI      $repository
  * @param Category $category
  * @param Carbon   $start
  * @param Carbon   $end
  *
  * @return array
  */
 private function makePeriodChart(CRI $repository, Category $category, Carbon $start, Carbon $end)
 {
     $categoryCollection = new Collection([$category]);
     $cache = new CacheProperties();
     /** @var AccountCrudInterface $crud */
     $crud = app(AccountCrudInterface::class);
     $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty($accounts);
     $cache->addProperty($category->id);
     $cache->addProperty('specific-period');
     if ($cache->has()) {
         return $cache->get();
     }
     $entries = new Collection();
     while ($start <= $end) {
         $spent = $repository->spentInPeriod($categoryCollection, $accounts, $start, $start);
         $earned = $repository->earnedInPeriod($categoryCollection, $accounts, $start, $start);
         $date = Navigation::periodShow($start, '1D');
         $entries->push([clone $start, $date, $spent, $earned]);
         $start->addDay();
     }
     $data = $this->generator->period($entries);
     $cache->store($data);
     return $data;
 }
コード例 #4
0
 /**
  * @param CRI                  $repository
  * @param AccountCrudInterface $crud
  * @param Category             $category
  *
  * @return View
  */
 public function show(CRI $repository, AccountCrudInterface $crud, Category $category)
 {
     $range = Preferences::get('viewRange', '1M')->data;
     /** @var Carbon $start */
     $start = session('start', Navigation::startOfPeriod(new Carbon(), $range));
     /** @var Carbon $end */
     $end = session('end', Navigation::endOfPeriod(new Carbon(), $range));
     $hideCategory = true;
     // used in list.
     $page = intval(Input::get('page'));
     $pageSize = Preferences::get('transactionPageSize', 50)->data;
     $offset = ($page - 1) * $pageSize;
     $set = $repository->journalsInPeriod(new Collection([$category]), new Collection(), [], $start, $end);
     $count = $set->count();
     $subSet = $set->splice($offset, $pageSize);
     $subTitle = $category->name;
     $subTitleIcon = 'fa-bar-chart';
     $journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page);
     $journals->setPath('categories/show/' . $category->id);
     // oldest transaction in category:
     $start = $repository->firstUseDate($category);
     if ($start->year == 1900) {
         $start = new Carbon();
     }
     $range = Preferences::get('viewRange', '1M')->data;
     $start = Navigation::startOfPeriod($start, $range);
     $end = Navigation::endOfX(new Carbon(), $range);
     $entries = new Collection();
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('category-show');
     $cache->addProperty($category->id);
     if ($cache->has()) {
         $entries = $cache->get();
         return view('categories.show', compact('category', 'journals', 'entries', 'subTitleIcon', 'hideCategory', 'subTitle'));
     }
     $categoryCollection = new Collection([$category]);
     $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
     while ($end >= $start) {
         $end = Navigation::startOfPeriod($end, $range);
         $currentEnd = Navigation::endOfPeriod($end, $range);
         $spent = $repository->spentInPeriod($categoryCollection, $accounts, $end, $currentEnd);
         $earned = $repository->earnedInPeriod($categoryCollection, $accounts, $end, $currentEnd);
         $dateStr = $end->format('Y-m-d');
         $dateName = Navigation::periodShow($end, $range);
         $entries->push([$dateStr, $dateName, $spent, $earned]);
         $end = Navigation::subtractPeriod($end, $range, 1);
     }
     $cache->store($entries);
     return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));
 }