Ejemplo n.º 1
0
 /**
  * Shows the amount left in a specific budget limit.
  *
  * @param BudgetRepositoryInterface $repository
  * @param Budget                    $budget
  * @param LimitRepetition           $repetition
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function budgetLimit(BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition)
 {
     $start = clone $repetition->startdate;
     $end = $repetition->enddate;
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('budget');
     $cache->addProperty('limit');
     $cache->addProperty($budget->id);
     $cache->addProperty($repetition->id);
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $entries = new Collection();
     $amount = $repetition->amount;
     while ($start <= $end) {
         /*
          * Sum of expenses on this day:
          */
         $sum = $repository->expensesOnDayCorrected($budget, $start);
         $amount += $sum;
         $entries->push([clone $start, $amount]);
         $start->addDay();
     }
     $data = $this->generator->budgetLimit($entries);
     $cache->store($data);
     return Response::json($data);
 }