/**
  * @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 NewUserFormRequest   $request
  * @param AccountCrudInterface $crud
  *
  * @return bool
  */
 private function storeCreditCard(NewUserFormRequest $request, AccountCrudInterface $crud) : bool
 {
     $creditAccount = ['name' => 'Credit card', 'iban' => null, 'accountType' => 'asset', 'virtualBalance' => round($request->get('credit_card_limit'), 2), 'active' => true, 'user' => auth()->user()->id, 'accountRole' => 'ccAsset', 'openingBalance' => null, 'openingBalanceDate' => null, 'openingBalanceCurrency' => intval($request->input('amount_currency_id_credit_card_limit'))];
     $creditCard = $crud->store($creditAccount);
     // store meta for CC:
     $crud->storeMeta($creditCard, 'ccType', 'monthlyFull');
     $crud->storeMeta($creditCard, 'ccMonthlyPaymentDate', Carbon::now()->year . '-01-01');
     return true;
 }
 /**
  * @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);
 }
Exemplo n.º 8
0
 /**
  * @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 AccountFormRequest   $request
  * @param AccountCrudInterface $crud
  * @param Account              $account
  *
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function update(AccountFormRequest $request, AccountCrudInterface $crud, Account $account)
 {
     $accountData = ['name' => $request->input('name'), 'active' => $request->input('active'), 'user' => auth()->user()->id, 'iban' => $request->input('iban'), 'accountNumber' => $request->input('accountNumber'), 'accountRole' => $request->input('accountRole'), 'virtualBalance' => round($request->input('virtualBalance'), 2), 'openingBalance' => round($request->input('openingBalance'), 2), 'openingBalanceDate' => new Carbon((string) $request->input('openingBalanceDate')), 'openingBalanceCurrency' => intval($request->input('amount_currency_id_openingBalance')), 'ccType' => $request->input('ccType'), 'ccMonthlyPaymentDate' => $request->input('ccMonthlyPaymentDate')];
     $crud->update($account, $accountData);
     Session::flash('success', strval(trans('firefly.updated_account', ['name' => $account->name])));
     Preferences::mark();
     if (intval(Input::get('return_to_edit')) === 1) {
         // set value so edit routine will not overwrite URL:
         Session::put('accounts.edit.fromUpdate', true);
         return redirect(route('accounts.edit', [$account->id]))->withInput(['return_to_edit' => 1]);
     }
     // redirect to previous URL.
     return redirect(session('accounts.edit.url'));
 }
 /**
  * @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'));
 }
Exemplo n.º 12
0
 /**
  * @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);
 }