Esempio n. 1
0
 /**
  * Shows the balances for all the user's accounts.
  *
  * @param AccountRepositoryInterface $repository
  *
  * @param                            $year
  * @param                            $month
  * @param bool                       $shared
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function all(AccountRepositoryInterface $repository, $year, $month, $shared = false)
 {
     $start = new Carbon($year . '-' . $month . '-01');
     $end = clone $start;
     $end->endOfMonth();
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('all');
     $cache->addProperty('accounts');
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     /** @var Collection $accounts */
     $accounts = $repository->getAccounts(['Default account', 'Asset account']);
     if ($shared === false) {
         /** @var Account $account */
         foreach ($accounts as $index => $account) {
             if ($account->getMeta('accountRole') == 'sharedAsset') {
                 $accounts->forget($index);
             }
         }
     }
     // make chart:
     $data = $this->generator->all($accounts, $start, $end);
     $cache->store($data);
     return Response::json($data);
 }
 /**
  * @param AccountRepositoryInterface $repository
  *
  * @return $this|\Illuminate\View\View
  */
 public function index(AccountRepositoryInterface $repository)
 {
     $accounts = $repository->getAccounts(['Default account', 'Asset account']);
     $viewRangePref = Preferences::get('viewRange', '1M');
     $viewRange = $viewRangePref->data;
     $frontPageAccounts = Preferences::get('frontPageAccounts', []);
     $budgetMax = Preferences::get('budgetMaximum', 1000);
     $language = Preferences::get('language', 'en')->data;
     $budgetMaximum = $budgetMax->data;
     return view('preferences.index', compact('budgetMaximum', 'language', 'accounts', 'frontPageAccounts', 'viewRange'));
 }
 /**
  * @param ARI $repository
  *
  * @return $this|\Illuminate\View\View
  */
 public function index(ARI $repository)
 {
     $accounts = $repository->getAccounts(['Default account', 'Asset account']);
     $viewRangePref = Preferences::get('viewRange', '1M');
     $viewRange = $viewRangePref->data;
     $frontPageAccounts = Preferences::get('frontPageAccounts', []);
     $budgetMax = Preferences::get('budgetMaximum', 1000);
     $language = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'))->data;
     $budgetMaximum = $budgetMax->data;
     $showIncomplete = env('SHOW_INCOMPLETE_TRANSLATIONS', 'false') == 'true';
     return view('preferences.index', compact('budgetMaximum', 'language', 'accounts', 'frontPageAccounts', 'viewRange', 'showIncomplete'));
 }
Esempio n. 4
0
 /**
  * @param AccountRepositoryInterface $repository
  *
  * @return View
  * @internal param ReportHelperInterface $helper
  */
 public function index(AccountRepositoryInterface $repository)
 {
     $start = Session::get('first');
     $months = $this->helper->listOfMonths($start);
     // does the user have shared accounts?
     $accounts = $repository->getAccounts(['Default account', 'Asset account']);
     $hasShared = false;
     /** @var Account $account */
     foreach ($accounts as $account) {
         if ($account->getMeta('accountRole') == 'sharedAsset') {
             $hasShared = true;
         }
     }
     return view('reports.index', compact('months', 'hasShared'));
 }
Esempio n. 5
0
 /**
  * Shows the balances for all the user's expense accounts.
  *
  * @param AccountRepositoryInterface $repository
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function expenseAccounts(AccountRepositoryInterface $repository)
 {
     $start = clone Session::get('start', Carbon::now()->startOfMonth());
     $end = clone Session::get('end', Carbon::now()->endOfMonth());
     $accounts = $repository->getAccounts(['Expense account', 'Beneficiary account']);
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('expenseAccounts');
     $cache->addProperty('accounts');
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $data = $this->generator->expenseAccounts($accounts, $start, $end);
     $cache->store($data);
     return Response::json($data);
 }
 /**
  * @param ARI $repository
  *
  * @return View
  * @internal param ReportHelperInterface $helper
  */
 public function index(ARI $repository)
 {
     $start = Session::get('first');
     $months = $this->helper->listOfMonths($start);
     $startOfMonth = clone Session::get('start');
     $endOfMonth = clone Session::get('start');
     $startOfYear = clone Session::get('start');
     $endOfYear = clone Session::get('start');
     $startOfMonth->startOfMonth();
     $endOfMonth->endOfMonth();
     $startOfYear->startOfYear();
     $endOfYear->endOfYear();
     // does the user have shared accounts?
     $accounts = $repository->getAccounts(['Default account', 'Asset account']);
     // 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', 'startOfMonth', 'endOfMonth', 'startOfYear', 'endOfYear'));
 }
 /**
  * @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'));
 }
 /**
  * Shows the view to edit a transaction.
  *
  * @param ARI                $repository
  * @param TransactionJournal $journal
  *
  * @return $this
  */
 public function edit(ARI $repository, TransactionJournal $journal)
 {
     // cannot edit opening balance
     if ($journal->isOpeningBalance()) {
         return view('error')->with('message', 'Cannot edit this transaction. Edit the account instead!');
     }
     $maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
     $maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
     $uploadSize = min($maxFileSize, $maxPostSize);
     $what = strtolower($journal->getTransactionType());
     $accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
     $budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
     $budgets[0] = trans('form.noBudget');
     $piggies = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get());
     $piggies[0] = trans('form.noPiggybank');
     $subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
     $preFilled = ['date' => $journal->date->format('Y-m-d'), 'category' => '', 'budget_id' => 0, 'piggy_bank_id' => 0];
     // get tags:
     $preFilled['tags'] = join(',', $journal->tags->pluck('tag')->toArray());
     $category = $journal->categories()->first();
     if (!is_null($category)) {
         $preFilled['category'] = $category->name;
     }
     $budget = $journal->budgets()->first();
     if (!is_null($budget)) {
         $preFilled['budget_id'] = $budget->id;
     }
     if ($journal->piggyBankEvents()->count() > 0) {
         $preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id;
     }
     $preFilled['amount'] = $journal->amount_positive;
     if ($journal->isWithdrawal()) {
         $preFilled['account_id'] = $journal->source_account->id;
         $preFilled['expense_account'] = $journal->destination_account->name_for_editform;
     } else {
         $preFilled['account_id'] = $journal->destination_account->id;
         $preFilled['revenue_account'] = $journal->source_account->name_for_editform;
     }
     $preFilled['account_from_id'] = $journal->source_account->id;
     $preFilled['account_to_id'] = $journal->destination_account->id;
     Session::flash('preFilled', $preFilled);
     Session::flash('gaEventCategory', 'transactions');
     Session::flash('gaEventAction', 'edit-' . $what);
     // put previous url in session if not redirect from store (not "return_to_edit").
     if (Session::get('transactions.edit.fromUpdate') !== true) {
         Session::put('transactions.edit.url', URL::previous());
     }
     Session::forget('transactions.edit.fromUpdate');
     return view('transactions.edit', compact('journal', 'uploadSize', 'accounts', 'what', 'budgets', 'piggies', 'subTitle'))->with('data', $preFilled);
 }
Esempio n. 9
0
 /**
  * @param ARI       $repository
  * @param PiggyBank $piggyBank
  *
  * @return View
  */
 public function edit(ARI $repository, PiggyBank $piggyBank)
 {
     $periods = Config::get('firefly.piggy_bank_periods');
     $accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
     $subTitle = trans('firefly.update_piggy_title', ['name' => $piggyBank->name]);
     $subTitleIcon = 'fa-pencil';
     /*
      * Flash some data to fill the form.
      */
     if (is_null($piggyBank->targetdate) || $piggyBank->targetdate == '') {
         $targetDate = null;
     } else {
         $targetDate = new Carbon($piggyBank->targetdate);
         $targetDate = $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::get('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', 'periods', 'preFilled'));
 }
Esempio n. 10
0
 /**
  * Shows a budget list with spent/left/overspent.
  *
  * @param BudgetRepositoryInterface $repository
  *
  * @param ARI                       $accountRepository
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function frontpage(BudgetRepositoryInterface $repository, ARI $accountRepository)
 {
     $start = Session::get('start', Carbon::now()->startOfMonth());
     $end = Session::get('end', Carbon::now()->endOfMonth());
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('budget');
     $cache->addProperty('all');
     if ($cache->has()) {
         return Response::json($cache->get());
         // @codeCoverageIgnore
     }
     $budgets = $repository->getBudgetsAndLimitsInRange($start, $end);
     $allEntries = new Collection();
     $accounts = $accountRepository->getAccounts(['Default account', 'Asset account', 'Cash account']);
     bcscale(2);
     /** @var Budget $budget */
     foreach ($budgets as $budget) {
         // we already have amount, startdate and enddate.
         // if this "is" a limit repetition (as opposed to a budget without one entirely)
         // depends on whether startdate and enddate are null.
         $name = $budget->name;
         if (is_null($budget->startdate) && is_null($budget->enddate)) {
             $currentStart = clone $start;
             $currentEnd = clone $end;
             $expenses = $repository->balanceInPeriod($budget, $currentStart, $currentEnd, $accounts);
             $amount = 0;
             $left = 0;
             $spent = $expenses;
             $overspent = 0;
         } else {
             $currentStart = clone $budget->startdate;
             $currentEnd = clone $budget->enddate;
             $expenses = $repository->balanceInPeriod($budget, $currentStart, $currentEnd, $accounts);
             $amount = $budget->amount;
             // smaller than 1 means spent MORE than budget allows.
             $left = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? 0 : bcadd($budget->amount, $expenses);
             $spent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? $amount * -1 : $expenses;
             $overspent = bccomp(bcadd($budget->amount, $expenses), '0') < 1 ? bcadd($budget->amount, $expenses) : 0;
         }
         $allEntries->push([$name, $left, $spent, $overspent, $amount, $expenses]);
     }
     $noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end);
     $allEntries->push([trans('firefly.noBudget'), 0, 0, $noBudgetExpenses, 0, 0]);
     $data = $this->generator->frontpage($allEntries);
     $cache->store($data);
     return Response::json($data);
 }
Esempio n. 11
0
 /**
  * This method shows the initial upload form.
  *
  * STEP ONE
  *
  * @return \Illuminate\View\View
  */
 public function index(AccountRepositoryInterface $repository)
 {
     $subTitle = trans('firefly.csv_import');
     Session::forget('csv-date-format');
     Session::forget('csv-has-headers');
     Session::forget('csv-file');
     Session::forget('csv-import-account');
     Session::forget('csv-map');
     Session::forget('csv-roles');
     Session::forget('csv-mapped');
     Session::forget('csv-specifix');
     // get list of supported specifix
     $specifix = [];
     foreach (Config::get('csv.specifix') as $entry) {
         $specifix[$entry] = trans('firefly.csv_specifix_' . $entry);
     }
     // get a list of asset accounts:
     $accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Asset account', 'Default account']));
     // can actually upload?
     $uploadPossible = is_writable(storage_path('upload'));
     $path = storage_path('upload');
     return view('csv.index', compact('subTitle', 'uploadPossible', 'path', 'specifix', 'accounts'));
 }
Esempio n. 12
0
 /**
  * @param AccountRepositoryInterface $accountRepository
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function revenueAccounts(AccountRepositoryInterface $accountRepository)
 {
     $list = $accountRepository->getAccounts(['Revenue account']);
     $return = [];
     foreach ($list as $entry) {
         $return[] = $entry->name;
     }
     return Response::json($return);
 }
 /**
  * @param ARI                        $repository
  * @param                            $what
  *
  * @return \Illuminate\View\View
  */
 public function index(ARI $repository, $what)
 {
     $subTitle = trans('firefly.' . $what . '_accounts');
     $subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
     $types = Config::get('firefly.accountTypesByIdentifier.' . $what);
     $accounts = $repository->getAccounts($types);
     $start = clone Session::get('start', Carbon::now()->startOfMonth());
     $end = clone Session::get('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'));
 }
Esempio n. 14
0
 /**
  * @param AccountRepositoryInterface $repository
  * @param                            $what
  *
  * @return \Illuminate\View\View
  */
 public function index(AccountRepositoryInterface $repository, $what)
 {
     $subTitle = trans('firefly.' . $what . '_accounts');
     $subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
     $types = Config::get('firefly.accountTypesByIdentifier.' . $what);
     $accounts = $repository->getAccounts($types);
     // last activity:
     /**
      * HERE WE ARE
      */
     $start = clone Session::get('start', Carbon::now()->startOfMonth());
     $start->subDay();
     $accounts->each(function (Account $account) use($start, $repository) {
         $account->lastActivityDate = $repository->getLastActivity($account);
         $account->startBalance = Steam::balance($account, $start);
         $account->endBalance = Steam::balance($account, clone Session::get('end', Carbon::now()->endOfMonth()));
     });
     return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts'));
 }
Esempio n. 15
0
 /**
  * @param AccountRepositoryInterface $repository
  * @param                            $what
  *
  * @return \Illuminate\View\View
  */
 public function index(AccountRepositoryInterface $repository, $what)
 {
     $subTitle = trans('firefly.' . $what . '_accounts');
     $subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what);
     $types = Config::get('firefly.accountTypesByIdentifier.' . $what);
     $accounts = $repository->getAccounts($types);
     // last activity:
     /**
      * HERE WE ARE
      */
     $start = clone Session::get('start', Carbon::now()->startOfMonth());
     $end = clone Session::get('end', Carbon::now()->endOfMonth());
     $start->subDay();
     // start balances:
     $ids = [];
     foreach ($accounts as $account) {
         $ids[] = $account->id;
     }
     $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 = isset($activities[$account->id]) ? $activities[$account->id] : null;
         $account->startBalance = isset($startBalances[$account->id]) ? $startBalances[$account->id] : null;
         $account->endBalance = isset($endBalances[$account->id]) ? $endBalances[$account->id] : null;
     });
     return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts'));
 }
Esempio n. 16
0
 /**
  * Shows the view to edit a transaction.
  *
  * @param AccountRepositoryInterface $repository
  * @param TransactionJournal         $journal
  *
  * @return $this
  */
 public function edit(AccountRepositoryInterface $repository, TransactionJournal $journal)
 {
     $what = strtolower($journal->transactionType->type);
     $accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
     $budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
     $budgets[0] = trans('form.noBudget');
     $piggies = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get());
     $piggies[0] = trans('form.noPiggybank');
     $subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
     $preFilled = ['date' => $journal->date->format('Y-m-d'), 'category' => '', 'budget_id' => 0, 'piggy_bank_id' => 0];
     // get tags:
     $tags = [];
     foreach ($journal->tags as $tag) {
         $tags[] = $tag->tag;
     }
     $preFilled['tags'] = join(',', $tags);
     $category = $journal->categories()->first();
     if (!is_null($category)) {
         $preFilled['category'] = $category->name;
     }
     $budget = $journal->budgets()->first();
     if (!is_null($budget)) {
         $preFilled['budget_id'] = $budget->id;
     }
     if ($journal->piggyBankEvents()->count() > 0) {
         $preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id;
     }
     $preFilled['amount'] = $journal->actual_amount;
     if ($journal->transactionType->type == 'Withdrawal') {
         $preFilled['account_id'] = $journal->source_account->id;
         $preFilled['expense_account'] = $journal->destination_account->name_for_editform;
     } else {
         $preFilled['account_id'] = $journal->destination_account->id;
         $preFilled['revenue_account'] = $journal->source_account->name_for_editform;
     }
     $preFilled['account_from_id'] = $journal->source_account->id;
     $preFilled['account_to_id'] = $journal->destination_account->id;
     Session::flash('preFilled', $preFilled);
     Session::flash('gaEventCategory', 'transactions');
     Session::flash('gaEventAction', 'edit-' . $what);
     // put previous url in session if not redirect from store (not "return_to_edit").
     if (Session::get('transactions.edit.fromUpdate') !== true) {
         Session::put('transactions.edit.url', URL::previous());
     }
     Session::forget('transactions.edit.fromUpdate');
     return View::make('transactions.edit', compact('journal', 'accounts', 'what', 'budgets', 'piggies', 'subTitle'))->with('data', $preFilled);
 }