/** * @param AccountCrudInterface $crud * @param EJRI $jobs * * @return View */ public function index(AccountCrudInterface $crud, EJRI $jobs) { // create new export job. $job = $jobs->create(); // delete old ones. $jobs->cleanup(); // does the user have shared accounts? $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accountList = ExpandedForm::makeSelectList($accounts); $checked = array_keys($accountList); $formats = array_keys(config('firefly.export_formats')); $defaultFormat = Preferences::get('export_format', config('firefly.default_export_format'))->data; $first = session('first')->format('Y-m-d'); $today = Carbon::create()->format('Y-m-d'); return view('export.index', compact('job', 'checked', 'accountList', 'formats', 'defaultFormat', 'first', 'today')); }
/** * @param AccountCrudInterface $crud * * @return View */ public function index(AccountCrudInterface $crud) { $this->createRepositories(); /** @var Carbon $start */ $start = clone session('first'); $months = $this->helper->listOfMonths($start); $customFiscalYear = Preferences::get('customFiscalYear', 0)->data; // does the user have shared accounts? $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); // get id's for quick links: $accountIds = []; /** @var Account $account */ foreach ($accounts as $account) { $accountIds[] = $account->id; } $accountList = join(',', $accountIds); return view('reports.index', compact('months', 'accounts', 'start', 'accountList', 'customFiscalYear')); }
/** * @param AccountCrudInterface $crud * * @return View */ public function index(AccountCrudInterface $crud) { $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $viewRangePref = Preferences::get('viewRange', '1M'); $viewRange = $viewRangePref->data; $frontPageAccounts = Preferences::get('frontPageAccounts', []); $language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data; $transactionPageSize = Preferences::get('transactionPageSize', 50)->data; $customFiscalYear = Preferences::get('customFiscalYear', 0)->data; $fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data; $fiscalYearStart = date('Y') . '-' . $fiscalYearStartStr; $tjOptionalFields = Preferences::get('transaction_journal_optional_fields', [])->data; $is2faEnabled = Preferences::get('twoFactorAuthEnabled', 0)->data; // twoFactorAuthEnabled $has2faSecret = !is_null(Preferences::get('twoFactorAuthSecret')); // hasTwoFactorAuthSecret $showIncomplete = env('SHOW_INCOMPLETE_TRANSLATIONS', false) === true; return view('preferences.index', compact('language', 'accounts', 'frontPageAccounts', 'tjOptionalFields', 'viewRange', 'customFiscalYear', 'transactionPageSize', 'fiscalYearStart', 'is2faEnabled', 'has2faSecret', 'showIncomplete')); }
/** * @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')); }
/** * @param AccountCrudInterface $crud * @param RuleGroup $ruleGroup * * @return View */ public function selectTransactions(AccountCrudInterface $crud, RuleGroup $ruleGroup) { // does the user have shared accounts? $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accountList = ExpandedForm::makeSelectList($accounts); $checkedAccounts = array_keys($accountList); $first = session('first')->format('Y-m-d'); $today = Carbon::create()->format('Y-m-d'); $subTitle = (string) trans('firefly.execute_on_existing_transactions'); return view('rules.rule-group.select-transactions', compact('checkedAccounts', 'accountList', 'first', 'today', 'ruleGroup', 'subTitle')); }
/** * @param CRI $repository * @param AccountCrudInterface $crud * * @return \Illuminate\Http\JsonResponse */ public function frontpage(CRI $repository, AccountCrudInterface $crud) { $start = session('start', Carbon::now()->startOfMonth()); $end = session('end', Carbon::now()->endOfMonth()); // chart properties for cache: $cache = new CacheProperties(); $cache->addProperty($start); $cache->addProperty($end); $cache->addProperty('category'); $cache->addProperty('frontpage'); if ($cache->has()) { return Response::json($cache->get()); } $categories = $repository->getCategories(); $accounts = $crud->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]); $set = new Collection(); /** @var Category $category */ foreach ($categories as $category) { $spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end); if (bccomp($spent, '0') === -1) { $category->spent = $spent; $set->push($category); } } // this is a "fake" entry for the "no category" entry. $entry = new stdClass(); $entry->name = trans('firefly.no_category'); $entry->spent = $repository->spentInPeriodWithoutCategory(new Collection(), $start, $end); $set->push($entry); $set = $set->sortBy('spent'); $data = $this->generator->frontpage($set); $cache->store($data); return Response::json($data); }
/** * @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')); }
/** * @param AccountCrudInterface $crud * @param string $what * * @return View */ public function index(AccountCrudInterface $crud, string $what) { $what = $what ?? 'asset'; $subTitle = trans('firefly.' . $what . '_accounts'); $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); $types = config('firefly.accountTypesByIdentifier.' . $what); $accounts = $crud->getAccountsByType($types); /** @var Carbon $start */ $start = clone session('start', Carbon::now()->startOfMonth()); /** @var Carbon $end */ $end = clone session('end', Carbon::now()->endOfMonth()); $start->subDay(); $ids = $accounts->pluck('id')->toArray(); $startBalances = Steam::balancesById($ids, $start); $endBalances = Steam::balancesById($ids, $end); $activities = Steam::getLastActivities($ids); $accounts->each(function (Account $account) use($activities, $startBalances, $endBalances) { $account->lastActivityDate = $this->isInArray($activities, $account->id); $account->startBalance = $this->isInArray($startBalances, $account->id); $account->endBalance = $this->isInArray($endBalances, $account->id); }); return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts')); }
/** * @param AccountCrudInterface $crud * @param PiggyBank $piggyBank * * @return View */ public function edit(AccountCrudInterface $crud, PiggyBank $piggyBank) { $accounts = ExpandedForm::makeSelectList($crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])); $subTitle = trans('firefly.update_piggy_title', ['name' => $piggyBank->name]); $subTitleIcon = 'fa-pencil'; $targetDate = null; /* * Flash some data to fill the form. */ if (!is_null($piggyBank->targetdate)) { $targetDate = $piggyBank->targetdate->format('Y-m-d'); } $preFilled = ['name' => $piggyBank->name, 'account_id' => $piggyBank->account_id, 'targetamount' => $piggyBank->targetamount, 'targetdate' => $targetDate]; Session::flash('preFilled', $preFilled); Session::flash('gaEventCategory', 'piggy-banks'); Session::flash('gaEventAction', 'edit'); // put previous url in session if not redirect from store (not "return_to_edit"). if (session('piggy-banks.edit.fromUpdate') !== true) { Session::put('piggy-banks.edit.url', URL::previous()); } Session::forget('piggy-banks.edit.fromUpdate'); return view('piggy-banks.edit', compact('subTitle', 'subTitleIcon', 'piggyBank', 'accounts', 'preFilled')); }
/** * @param CRI $repository * @param AccountCrudInterface $crud * @param Category $category * * @return View */ public function show(CRI $repository, AccountCrudInterface $crud, Category $category) { $range = Preferences::get('viewRange', '1M')->data; /** @var Carbon $start */ $start = session('start', Navigation::startOfPeriod(new Carbon(), $range)); /** @var Carbon $end */ $end = session('end', Navigation::endOfPeriod(new Carbon(), $range)); $hideCategory = true; // used in list. $page = intval(Input::get('page')); $pageSize = Preferences::get('transactionPageSize', 50)->data; $offset = ($page - 1) * $pageSize; $set = $repository->journalsInPeriod(new Collection([$category]), new Collection(), [], $start, $end); $count = $set->count(); $subSet = $set->splice($offset, $pageSize); $subTitle = $category->name; $subTitleIcon = 'fa-bar-chart'; $journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page); $journals->setPath('categories/show/' . $category->id); // oldest transaction in category: $start = $repository->firstUseDate($category); if ($start->year == 1900) { $start = new Carbon(); } $range = Preferences::get('viewRange', '1M')->data; $start = Navigation::startOfPeriod($start, $range); $end = Navigation::endOfX(new Carbon(), $range); $entries = new Collection(); // chart properties for cache: $cache = new CacheProperties(); $cache->addProperty($start); $cache->addProperty($end); $cache->addProperty('category-show'); $cache->addProperty($category->id); if ($cache->has()) { $entries = $cache->get(); return view('categories.show', compact('category', 'journals', 'entries', 'subTitleIcon', 'hideCategory', 'subTitle')); } $categoryCollection = new Collection([$category]); $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); while ($end >= $start) { $end = Navigation::startOfPeriod($end, $range); $currentEnd = Navigation::endOfPeriod($end, $range); $spent = $repository->spentInPeriod($categoryCollection, $accounts, $end, $currentEnd); $earned = $repository->earnedInPeriod($categoryCollection, $accounts, $end, $currentEnd); $dateStr = $end->format('Y-m-d'); $dateName = Navigation::periodShow($end, $range); $entries->push([$dateStr, $dateName, $spent, $earned]); $end = Navigation::subtractPeriod($end, $range, 1); } $cache->store($entries); return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle')); }
/** * @param AccountCrudInterface $crud * * @return \Illuminate\Http\JsonResponse */ public function revenueAccounts(AccountCrudInterface $crud) { $list = $crud->getAccountsByType([AccountType::REVENUE]); $return = []; foreach ($list as $entry) { $return[] = $entry->name; } return Response::json($return); }