/** * @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')); }
/** * @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')); }