コード例 #1
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;
 }
コード例 #2
0
 /**
  * @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;
 }