コード例 #1
0
 /**
  * @param BudgetRepositoryInterface $repository
  *
  * @param ARI                       $accountRepository
  *
  * @return \Illuminate\View\View
  */
 public function index(BudgetRepositoryInterface $repository, ARI $accountRepository)
 {
     $budgets = $repository->getActiveBudgets();
     $inactive = $repository->getInactiveBudgets();
     $spent = '0';
     $budgeted = '0';
     $range = Preferences::get('viewRange', '1M')->data;
     $start = Navigation::startOfPeriod(Session::get('start', new Carbon()), $range);
     $end = Navigation::endOfPeriod($start, $range);
     $key = 'budgetIncomeTotal' . $start->format('Ymd') . $end->format('Ymd');
     $budgetIncomeTotal = Preferences::get($key, 1000)->data;
     $period = Navigation::periodShow($start, $range);
     $accounts = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']);
     bcscale(2);
     /**
      * Do some cleanup:
      */
     $repository->cleanupBudgets();
     // loop the budgets:
     /** @var Budget $budget */
     foreach ($budgets as $budget) {
         $budget->spent = $repository->balanceInPeriod($budget, $start, $end, $accounts);
         $budget->currentRep = $repository->getCurrentRepetition($budget, $start, $end);
         if ($budget->currentRep) {
             $budgeted = bcadd($budgeted, $budget->currentRep->amount);
         }
         $spent = bcadd($spent, $budget->spent);
     }
     $budgetMaximum = Preferences::get('budgetMaximum', 1000)->data;
     $defaultCurrency = Amount::getDefaultCurrency();
     return view('budgets.index', compact('budgetMaximum', 'period', 'range', 'budgetIncomeTotal', 'defaultCurrency', 'inactive', 'budgets', 'spent', 'budgeted'));
 }
コード例 #2
0
 /**
  * Shows a budget list with spent/left/overspent.
  *
  * @param BudgetRepositoryInterface $repository
  *
  * @param ARI                       $accountRepository
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function frontpage(BudgetRepositoryInterface $repository, ARI $accountRepository)
 {
     $start = Session::get('start', Carbon::now()->startOfMonth());
     $end = Session::get('end', Carbon::now()->endOfMonth());
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('budget');
     $cache->addProperty('all');
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $budgets = $repository->getBudgetsAndLimitsInRange($start, $end);
     $allEntries = new Collection();
     $accounts = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']);
     bcscale(2);
     /** @var Budget $budget */
     foreach ($budgets as $budget) {
         // we already have amount, startdate and enddate.
         // if this "is" a limit repetition (as opposed to a budget without one entirely)
         // depends on whether startdate and enddate are null.
         $name = $budget->name;
         if (is_null($budget->startdate) && is_null($budget->enddate)) {
             $currentStart = clone $start;
             $currentEnd = clone $end;
             $expenses = $repository->balanceInPeriod($budget, $currentStart, $currentEnd, $accounts);
             $amount = 0;
             $left = 0;
             $spent = $expenses;
             $overspent = 0;
         } else {
             $currentStart = clone $budget->startdate;
             $currentEnd = clone $budget->enddate;
             $expenses = $repository->balanceInPeriod($budget, $currentStart, $currentEnd, $accounts);
             $amount = $budget->amount;
             // smaller than 1 means spent MORE than budget allows.
             $left = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? 0 : bcadd($budget->amount, $expenses);
             $spent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? $amount * -1 : $expenses;
             $overspent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? bcadd($budget->amount, $expenses) : 0;
         }
         $allEntries->push([$name, $left, $spent, $overspent, $amount, $expenses]);
     }
     $noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end);
     $allEntries->push([trans('firefly.noBudget'), 0, 0, $noBudgetExpenses, 0, 0]);
     $data = $this->generator->frontpage($allEntries);
     $cache->store($data);
     return Response::json($data);
 }
コード例 #3
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;
     $allBudgets = $repository->getBudgets();
     $budgets = new Collection();
     // 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
     }
     // filter empty budgets:
     foreach ($allBudgets as $budget) {
         $spent = $repository->balanceInPeriod($budget, $start, $end, $shared);
         if ($spent != 0) {
             $budgets->push($budget);
         }
     }
     $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->balanceInPeriod($budget, $start, $month, $shared);
             $row[] = $spent * -1;
         }
         $entries->push($row);
         $start->endOfMonth()->addDay();
     }
     $data = $this->generator->year($allBudgets, $entries);
     $cache->store($data);
     return Response::json($data);
 }
コード例 #4
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->balanceInPeriod($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'));
 }