/** * @param AccountRepositoryInterface $repository * * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function index(AccountRepositoryInterface $repository) { $types = Config::get('firefly.accountTypesByIdentifier.asset'); $count = $repository->countAccounts($types); bcscale(2); if ($count == 0) { return redirect(route('new-user.index')); } $title = 'Firefly'; $subTitle = trans('firefly.welcomeBack'); $mainTitleIcon = 'fa-fire'; $transactions = []; $frontPage = Preferences::get('frontPageAccounts', []); $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); $showTour = Preferences::get('tour', true)->data; $accounts = $repository->getFrontpageAccounts($frontPage); $savings = $repository->getSavingsAccounts(); $piggyBankAccounts = $repository->getPiggyBankAccounts(); $savingsTotal = 0; foreach ($savings as $savingAccount) { $savingsTotal = bcadd($savingsTotal, Steam::balance($savingAccount, $end)); } $sum = $repository->sumOfEverything(); if ($sum != 0) { Session::flash('error', 'Your transactions are unbalanced. This means a' . ' withdrawal, deposit or transfer was not stored properly. ' . 'Please check your accounts and transactions for errors.'); } foreach ($accounts as $account) { $set = $repository->getFrontpageTransactions($account, $start, $end); if (count($set) > 0) { $transactions[] = [$set, $account]; } } return view('index', compact('count', 'showTour', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts')); }
/** * @param ARI $repository * @param AccountCrudInterface $crud * * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View */ public function index(ARI $repository, AccountCrudInterface $crud) { $types = config('firefly.accountTypesByIdentifier.asset'); $count = $repository->countAccounts($types); if ($count == 0) { return redirect(route('new-user.index')); } $title = 'Firefly'; $subTitle = trans('firefly.welcomeBack'); $mainTitleIcon = 'fa-fire'; $transactions = []; $frontPage = Preferences::get('frontPageAccounts', $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray()); /** @var Carbon $start */ $start = session('start', Carbon::now()->startOfMonth()); /** @var Carbon $end */ $end = session('end', Carbon::now()->endOfMonth()); $showTour = Preferences::get('tour', true)->data; $accounts = $crud->getAccountsById($frontPage->data); $savings = $repository->getSavingsAccounts($start, $end); $piggyBankAccounts = $repository->getPiggyBankAccounts($start, $end); $savingsTotal = '0'; foreach ($savings as $savingAccount) { $savingsTotal = bcadd($savingsTotal, Steam::balance($savingAccount, $end)); } foreach ($accounts as $account) { $set = $repository->journalsInPeriod(new Collection([$account]), [], $start, $end); $set = $set->splice(0, 10); if (count($set) > 0) { $transactions[] = [$set, $account]; } } return view('index', compact('count', 'showTour', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts')); }