コード例 #1
0
 /**
  * @param BudgetRepositoryInterface $repository
  * @param AccountCrudInterface      $crud
  *
  * @return View
  */
 public function index(BudgetRepositoryInterface $repository, AccountCrudInterface $crud)
 {
     $repository->cleanupBudgets();
     $budgets = $repository->getActiveBudgets();
     $inactive = $repository->getInactiveBudgets();
     $spent = '0';
     $budgeted = '0';
     $range = Preferences::get('viewRange', '1M')->data;
     $repeatFreq = Config::get('firefly.range_to_repeat_freq.' . $range);
     if (session('is_custom_range') === true) {
         $repeatFreq = 'custom';
     }
     /** @var Carbon $start */
     $start = session('start', new Carbon());
     /** @var Carbon $end */
     $end = session('end', new Carbon());
     $key = 'budgetIncomeTotal' . $start->format('Ymd') . $end->format('Ymd');
     $budgetIncomeTotal = Preferences::get($key, 1000)->data;
     $period = Navigation::periodShow($start, $range);
     $periodStart = $start->formatLocalized($this->monthAndDayFormat);
     $periodEnd = $end->formatLocalized($this->monthAndDayFormat);
     $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]);
     $startAsString = $start->format('Y-m-d');
     $endAsString = $end->format('Y-m-d');
     // loop the budgets:
     /** @var Budget $budget */
     foreach ($budgets as $budget) {
         $budget->spent = $repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end);
         $allRepetitions = $repository->getAllBudgetLimitRepetitions($start, $end);
         $otherRepetitions = new Collection();
         /** @var LimitRepetition $repetition */
         foreach ($allRepetitions as $repetition) {
             if ($repetition->budget_id == $budget->id) {
                 if ($repetition->budgetLimit->repeat_freq == $repeatFreq && $repetition->startdate->format('Y-m-d') == $startAsString && $repetition->enddate->format('Y-m-d') == $endAsString) {
                     // do something
                     $budget->currentRep = $repetition;
                     continue;
                 }
                 $otherRepetitions->push($repetition);
             }
         }
         $budget->otherRepetitions = $otherRepetitions;
         if (!is_null($budget->currentRep) && !is_null($budget->currentRep->id)) {
             $budgeted = bcadd($budgeted, $budget->currentRep->amount);
         }
         $spent = bcadd($spent, $budget->spent);
     }
     $defaultCurrency = Amount::getDefaultCurrency();
     return view('budgets.index', compact('periodStart', 'periodEnd', 'period', 'range', 'budgetIncomeTotal', 'defaultCurrency', 'inactive', 'budgets', 'spent', 'budgeted'));
 }
コード例 #2
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'));
 }
コード例 #3
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'));
 }