/**
  * checked
  *
  * @param BudgetRepositoryInterface $repository
  * @param Budget                    $budget
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function budget(BudgetRepositoryInterface $repository, Budget $budget)
 {
     $first = $repository->firstUseDate($budget);
     $range = Preferences::get('viewRange', '1M')->data;
     $last = session('end', new Carbon());
     $cache = new CacheProperties();
     $cache->addProperty($first);
     $cache->addProperty($last);
     $cache->addProperty('budget');
     if ($cache->has()) {
         return Response::json($cache->get());
     }
     $final = clone $last;
     $final->addYears(2);
     $budgetCollection = new Collection([$budget]);
     $last = Navigation::endOfX($last, $range, $final);
     // not to overshoot.
     $entries = new Collection();
     while ($first < $last) {
         // periodspecific dates:
         $currentStart = Navigation::startOfPeriod($first, $range);
         $currentEnd = Navigation::endOfPeriod($first, $range);
         // sub another day because reasons.
         $currentEnd->subDay();
         $spent = $repository->spentInPeriod($budgetCollection, new Collection(), $currentStart, $currentEnd);
         $entry = [$first, $spent * -1];
         $entries->push($entry);
         $first = Navigation::addPeriod($first, $range, 0);
     }
     $data = $this->generator->budgetLimit($entries, 'month');
     $cache->store($data);
     return Response::json($data);
 }