/**
  * @param AccountRepositoryInterface $repository
  * @param string                     $reportType
  * @param Carbon                     $start
  * @param Carbon                     $end
  * @param Collection                 $accounts
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function yearInOutSummarized(AccountRepositoryInterface $repository, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
 {
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty('yearInOutSummarized');
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty($reportType);
     $cache->addProperty($accounts);
     if ($cache->has()) {
         return Response::json($cache->get());
     }
     // always per month.
     $currentStart = clone $start;
     $spentArray = [];
     $earnedArray = [];
     while ($currentStart <= $end) {
         $currentEnd = Navigation::endOfPeriod($currentStart, '1M');
         $date = $currentStart->format('Y-m');
         $spent = $repository->spentInPeriod($accounts, $currentStart, $currentEnd);
         $earned = $repository->earnedInPeriod($accounts, $currentStart, $currentEnd);
         $spentArray[$date] = bcmul($spent, '-1');
         $earnedArray[$date] = $earned;
         $currentStart = Navigation::addPeriod($currentStart, '1M', 0);
     }
     if ($start->diffInMonths($end) > 12) {
         // per year
         $data = $this->multiYearInOutSummarized($earnedArray, $spentArray, $start, $end);
         $cache->store($data);
         return Response::json($data);
     }
     // per month!
     $data = $this->singleYearInOutSummarized($earnedArray, $spentArray, $start, $end);
     $cache->store($data);
     return Response::json($data);
 }
 /**
  * @param ARI                  $accountRepository
  * @param AccountCrudInterface $crud
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function boxIn(ARI $accountRepository, AccountCrudInterface $crud)
 {
     $start = session('start', Carbon::now()->startOfMonth());
     $end = session('end', Carbon::now()->endOfMonth());
     // works for json too!
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('box-in');
     if ($cache->has()) {
         return Response::json($cache->get());
     }
     $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]);
     $amount = $accountRepository->earnedInPeriod($accounts, $start, $end);
     $data = ['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount];
     $cache->store($data);
     return Response::json($data);
 }