Beispiel #1
0
 /**
  * Show a yearly overview for a budget.
  *
  * @param BudgetRepositoryInterface $repository
  * @param                           $year
  * @param bool                      $shared
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function year(BudgetRepositoryInterface $repository, $year, $shared = false)
 {
     $start = new Carbon($year . '-01-01');
     $end = new Carbon($year . '-12-31');
     $shared = $shared == 'shared' ? true : false;
     $budgets = $repository->getBudgets();
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('budget');
     $cache->addProperty('year');
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $entries = new Collection();
     while ($start < $end) {
         // month is the current end of the period:
         $month = clone $start;
         $month->endOfMonth();
         $row = [clone $start];
         // each budget, fill the row:
         foreach ($budgets as $budget) {
             $spent = $repository->spentInPeriodCorrected($budget, $start, $month, $shared);
             $row[] = $spent;
         }
         $entries->push($row);
         $start->endOfMonth()->addDay();
     }
     $data = $this->generator->year($budgets, $entries);
     $cache->store($data);
     return Response::json($data);
 }
Beispiel #2
0
 /**
  * @param BudgetRepositoryInterface $repository
  *
  * @return \Illuminate\View\View
  */
 public function index(BudgetRepositoryInterface $repository)
 {
     $budgets = $repository->getActiveBudgets();
     $inactive = $repository->getInactiveBudgets();
     $spent = '0';
     $budgeted = '0';
     bcscale(2);
     /**
      * Do some cleanup:
      */
     $repository->cleanupBudgets();
     // loop the budgets:
     /** @var Budget $budget */
     foreach ($budgets as $budget) {
         $date = Session::get('start', Carbon::now()->startOfMonth());
         $end = Session::get('end', Carbon::now()->endOfMonth());
         $budget->spent = $repository->spentInPeriodCorrected($budget, $date, $end);
         $budget->currentRep = $repository->getCurrentRepetition($budget, $date);
         if ($budget->currentRep) {
             $budgeted = bcadd($budgeted, $budget->currentRep->amount);
         }
         $spent = bcadd($spent, $budget->spent);
     }
     $dateAsString = Session::get('start', Carbon::now()->startOfMonth())->format('FY');
     $budgetIncomeTotal = Preferences::get('budgetIncomeTotal' . $dateAsString, 1000)->data;
     $budgetMaximum = Preferences::get('budgetMaximum', 1000)->data;
     $defaultCurrency = Amount::getDefaultCurrency();
     return view('budgets.index', compact('budgetMaximum', 'budgetIncomeTotal', 'defaultCurrency', 'inactive', 'budgets', 'spent', 'budgeted'));
 }