Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Code clean up and reformat.
James Cole258d6a168874
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.phpindex f05d11623a..0347ca71a5 100644--- a/app/controllers/AccountController.php+++ b/app/controllers/AccountController.php@@ -18,38 +18,6 @@ class AccountController extends BaseControllerView::share('title', 'Accounts');}- /**- * @param string $what- *- * @return View- * @throws FireflyException- */- public function index($what = 'default')- {- switch ($what) {- default:- throw new FireflyException('Cannot handle account type "' . e($what) . '".');- break;- case 'asset':- $subTitleIcon = 'fa-money';- $subTitle = 'Asset accounts';- break;- case 'expense':- $subTitleIcon = 'fa-shopping-cart';- $subTitle = 'Expense accounts';- break;- case 'revenue':- $subTitleIcon = 'fa-download';- $subTitle = 'Revenue accounts';- break;- }- return View::make('accounts.index')- ->with('what', $what)- ->with(compact('subTitleIcon'))- ->with(compact('subTitle'));- }--/*** @return \Illuminate\View\View*/@@ -67,10 +35,7 @@ class AccountController extends BaseControllerbreak;}- return View::make('accounts.create')- ->with('subTitle', 'Create a new ' . $what . ' account')- ->with('what', $what)- ->with(compact('subTitleIcon'));+ return View::make('accounts.create')->with('subTitle', 'Create a new ' . $what . ' account')->with('what', $what)->with(compact('subTitleIcon'));}/**@@ -80,10 +45,9 @@ class AccountController extends BaseController*/public function delete(Account $account){- return View::make('accounts.delete')->with('account', $account)- ->with(- 'subTitle', 'Delete ' . strtolower($account->accountType->type) . ' "' . $account->name . '"'- );+ return View::make('accounts.delete')->with('account', $account)->with(+ 'subTitle', 'Delete ' . strtolower($account->accountType->type) . ' "' . $account->name . '"'+ );}/**@@ -193,11 +157,40 @@ class AccountController extends BaseControllerSession::flash('prefilled', $prefilled);}- return View::make('accounts.edit')- ->with('account', $account)- ->with('openingBalance', $openingBalance)- ->with(compact('subTitleIcon'))- ->with('subTitle', 'Edit ' . strtolower($account->accountType->type) . ' "' . $account->name . '"');+ return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)->with(compact('subTitleIcon'))->with(+ 'subTitle', 'Edit ' . strtolower(+ $account->accountType->type+ ) . ' "' . $account->name . '"'+ );+ }++ /**+ * @param string $what+ *+ * @return View+ * @throws FireflyException+ */+ public function index($what = 'default')+ {+ switch ($what) {+ default:+ throw new FireflyException('Cannot handle account type "' . e($what) . '".');+ break;+ case 'asset':+ $subTitleIcon = 'fa-money';+ $subTitle = 'Asset accounts';+ break;+ case 'expense':+ $subTitleIcon = 'fa-shopping-cart';+ $subTitle = 'Expense accounts';+ break;+ case 'revenue':+ $subTitleIcon = 'fa-download';+ $subTitle = 'Revenue accounts';+ break;+ }++ return View::make('accounts.index')->with('what', $what)->with(compact('subTitleIcon'))->with(compact('subTitle'));}/**@@ -223,10 +216,9 @@ class AccountController extends BaseController//$data = $this->_accounts->show($account, 40);- return View::make('accounts.show')- ->with('account', $account)- ->with('subTitle', 'Details for ' . strtolower($account->accountType->type) . ' "' . $account->name . '"')- ->with(compact('subTitleIcon'));+ return View::make('accounts.show')->with('account', $account)->with(+ 'subTitle', 'Details for ' . strtolower($account->accountType->type) . ' "' . $account->name . '"'+ )->with(compact('subTitleIcon'));}/**@@ -236,7 +228,7 @@ class AccountController extends BaseControllerpublic function store(){- $data = Input::all();+ $data = Input::all();$data['what'] = isset($data['what']) && $data['what'] != '' ? $data['what'] : 'asset';/** @var \FireflyIII\Database\Account $acct */$acct = App::make('FireflyIII\Database\Account');@@ -253,6 +245,7 @@ class AccountController extends BaseControllerSession::flash('warnings', $messages['warnings']);Session::flash('successes', $messages['successes']);Session::flash('error', 'Could not save account: ' . $messages['errors']->first());+return Redirect::route('accounts.create', $data['what'])->withInput()->withErrors($messages['errors']);}// store!@@ -270,6 +263,7 @@ class AccountController extends BaseControllerSession::flash('warnings', $messageBags['warnings']);Session::flash('successes', $messageBags['successes']);Session::flash('errors', $messageBags['errors']);+return Redirect::route('accounts.create', $data['what'])->withInput();break;}@@ -315,6 +309,7 @@ class AccountController extends BaseControllerSession::flash('warnings', $messages['warnings']);Session::flash('successes', $messages['successes']);Session::flash('error', 'Could not save account: ' . $messages['errors']->first());+return Redirect::route('accounts.edit', $account->id)->withInput()->withErrors($messages['errors']);}// store!@@ -331,6 +326,7 @@ class AccountController extends BaseControllerSession::flash('warnings', $messageBags['warnings']);Session::flash('successes', $messageBags['successes']);Session::flash('errors', $messageBags['errors']);+return Redirect::route('accounts.edit', $account->id)->withInput();break;}diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.phpindex 99522d1ef2..977cfcdb0d 100644--- a/app/controllers/BudgetController.php+++ b/app/controllers/BudgetController.php@@ -17,20 +17,6 @@ class BudgetController extends BaseControllerView::share('mainTitleIcon', 'fa-tasks');}- /**- * @return \Illuminate\Http\RedirectResponse- */- public function postUpdateIncome()- {- /** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */- $preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');- $date = Session::get('start');-- $value = intval(Input::get('amount'));- $preferences->set('budgetIncomeTotal' . $date->format('FY'), $value);- return Redirect::route('budgets.index');- }-/*** Update the amount for a budget's limitrepetition and/or create it.*@@ -78,6 +64,49 @@ class BudgetController extends BaseController}+ /**+ * @return $this+ */+ public function create()+ {+ return View::make('budgets.create')->with('subTitle', 'Create a new budget');+ }++ /**+ * @param Budget $budget+ *+ * @return $this+ */+ public function delete(Budget $budget)+ {+ return View::make('budgets.delete')->with('budget', $budget)->with('subTitle', 'Delete budget "' . $budget->name . '"');+ }++ public function destroy(Budget $budget)+ {+ /** @var \FireflyIII\Database\Budget $repos */+ $repos = App::make('FireflyIII\Database\Budget');+ // remove budget+ $repos->destroy($budget);+ Session::flash('success', 'The budget was deleted.');++ return Redirect::route('budgets.index');++ }++ /**+ * @param Budget $budget+ *+ * @return $this+ */+ public function edit(Budget $budget)+ {+ Session::flash('prefilled', ['name' => $budget->name]);++ return View::make('budgets.edit')->with('budget', $budget)->with('subTitle', 'Edit budget "' . $budget->name . '"');++ }+/*** @return $this*/@@ -137,15 +166,18 @@ class BudgetController extends BaseController}/**- * @return $this+ * @return \Illuminate\Http\RedirectResponse*/- public function updateIncome()+ public function postUpdateIncome(){- $date = Session::get('start');/** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */$preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');- $budgetAmount = $preferences->get('budgetIncomeTotal' . $date->format('FY'), 1000);- return View::make('budgets.income')->with('amount', $budgetAmount)->with('date', $date);+ $date = Session::get('start');++ $value = intval(Input::get('amount'));+ $preferences->set('budgetIncomeTotal' . $date->format('FY'), $value);++ return Redirect::route('budgets.index');}/**@@ -172,47 +204,6 @@ class BudgetController extends BaseControllerreturn View::make('budgets.show', compact('limits', 'budget', 'repetition'));}- /**- * @return $this- */- public function create()- {- return View::make('budgets.create')->with('subTitle', 'Create a new budget');- }-- /**- * @param Budget $budget- *- * @return $this- */- public function delete(Budget $budget)- {- return View::make('budgets.delete')->with('budget', $budget)->with('subTitle', 'Delete budget "' . $budget->name . '"');- }-- public function destroy(Budget $budget)- {- /** @var \FireflyIII\Database\Budget $repos */- $repos = App::make('FireflyIII\Database\Budget');- // remove budget- $repos->destroy($budget);- Session::flash('success', 'The budget was deleted.');- return Redirect::route('budgets.index');-- }-- /**- * @param Budget $budget- *- * @return $this- */- public function edit(Budget $budget)- {- Session::flash('prefilled', ['name' => $budget->name]);- return View::make('budgets.edit')->with('budget', $budget)->with('subTitle', 'Edit budget "' . $budget->name . '"');-- }-/*** @return \Illuminate\Http\RedirectResponse*/@@ -234,6 +225,7 @@ class BudgetController extends BaseControllerSession::flash('warnings', $messages['warnings']);Session::flash('successes', $messages['successes']);Session::flash('error', 'Could not save budget: ' . $messages['errors']->first());+return Redirect::route('budgets.create')->withInput()->withErrors($messages['errors']);}// store!@@ -251,6 +243,7 @@ class BudgetController extends BaseControllerSession::flash('warnings', $messageBags['warnings']);Session::flash('successes', $messageBags['successes']);Session::flash('errors', $messageBags['errors']);+return Redirect::route('budgets.create')->withInput();break;}@@ -280,6 +273,7 @@ class BudgetController extends BaseControllerSession::flash('warnings', $messages['warnings']);Session::flash('successes', $messages['successes']);Session::flash('error', 'Could not save budget: ' . $messages['errors']->first());+return Redirect::route('budgets.edit', $budget->id)->withInput()->withErrors($messages['errors']);}// store!@@ -296,8 +290,22 @@ class BudgetController extends BaseControllerSession::flash('warnings', $messageBags['warnings']);Session::flash('successes', $messageBags['successes']);Session::flash('errors', $messageBags['errors']);+return Redirect::route('budgets.edit', $budget->id)->withInput();break;}}++ /**+ * @return $this+ */+ public function updateIncome()+ {+ $date = Session::get('start');+ /** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */+ $preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');+ $budgetAmount = $preferences->get('budgetIncomeTotal' . $date->format('FY'), 1000);++ return View::make('budgets.income')->with('amount', $budgetAmount)->with('date', $date);+ }}\ No newline at end of filediff --git a/app/controllers/CategoryController.php b/app/controllers/CategoryController.phpindex d655245a3e..220f476dcb 100644--- a/app/controllers/CategoryController.php+++ b/app/controllers/CategoryController.php@@ -46,6 +46,7 @@ class CategoryController extends BaseController$repos->destroy($category);Session::flash('success', 'The category was deleted.');+return Redirect::route('categories.index');}@@ -56,8 +57,7 @@ class CategoryController extends BaseController*/public function edit(Category $category){- return View::make('categories.edit')->with('category', $category)- ->with('subTitle', 'Edit category "' . $category->name . '"');+ return View::make('categories.edit')->with('category', $category)->with('subTitle', 'Edit category "' . $category->name . '"');}/**@@ -122,6 +122,7 @@ class CategoryController extends BaseControllerSession::flash('warnings', $messages['warnings']);Session::flash('successes', $messages['successes']);Session::flash('error', 'Could not save category: ' . $messages['errors']->first());+return Redirect::route('categories.edit', $category->id)->withInput()->withErrors($messages['errors']);}// store!@@ -138,6 +139,7 @@ class CategoryController extends BaseControllerSession::flash('warnings', $messageBags['warnings']);Session::flash('successes', $messageBags['successes']);Session::flash('errors', $messageBags['errors']);+return Redirect::route('categories.edit', $category->id)->withInput();break;}diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.phpindex 281bc124db..61c520089b 100644--- a/app/controllers/GoogleChartController.php+++ b/app/controllers/GoogleChartController.php@@ -7,6 +7,162 @@ use Carbon\Carbon;class GoogleChartController extends BaseController{+ /**+ * @param Account $account+ */+ public function accountBalanceChart(Account $account)+ {+ /** @var \Grumpydictator\Gchart\GChart $chart */+ $chart = App::make('gchart');+ $chart->addColumn('Day of month', 'date');+ $chart->addColumn('Balance for ' . $account->name, 'number');++ /*+ * Loop the date, then loop the accounts, then add balance.+ */+ $start = Session::get('start');+ $end = Session::get('end');+ $current = clone $start;++ while ($end >= $current) {+ $row = [clone $current];+ if ($current > Carbon::now()) {+ $row[] = null;+ } else {+ $row[] = $account->balance($current);+ }++ $chart->addRowArray($row);+ $current->addDay();+ }+++ $chart->generate();++ return Response::json($chart->getData());+ }++ /**+ * @param Account $account+ *+ * @return \Illuminate\Http\JsonResponse+ */+ public function accountSankeyInChart(Account $account)+ {+ // collect all relevant entries.+ $set = [];++ /** @var \Grumpydictator\Gchart\GChart $chart */+ $chart = App::make('gchart');+ $chart->addColumn('From', 'string');+ $chart->addColumn('To', 'string', 'domain');+ $chart->addColumn('Weight', 'number');++ $transactions = $account->transactions()->with(+ ['transactionjournal', 'transactionjournal.transactions' => function ($q) {+ $q->where('amount', '<', 0);+ }, 'transactionjournal.budgets', 'transactionjournal.transactiontype', 'transactionjournal.categories']+ )->before(Session::get('end'))->after(+ Session::get('start')+ )->get();++ /** @var Transaction $transaction */+ foreach ($transactions as $transaction) {+ $amount = floatval($transaction->amount);+ $type = $transaction->transactionJournal->transactionType->type;++ if ($amount > 0 && $type != 'Transfer') {++ $otherAccount = $transaction->transactionJournal->transactions[0]->account->name;+ $categoryName = isset($transaction->transactionJournal->categories[0]) ? $transaction->transactionJournal->categories[0]->name : '(no cat)';+ $set[] = [$otherAccount, $categoryName, $amount];+ $set[] = [$categoryName, $account->name, $amount];+ }+ }+ // loop the set, group everything together:+ $grouped = [];+ foreach ($set as $entry) {+ $key = $entry[0] . $entry[1];+ if (isset($grouped[$key])) {+ $grouped[$key][2] += $entry[2];+ } else {+ $grouped[$key] = $entry;+ }+ }++ // add rows to the chart:+ foreach ($grouped as $entry) {+ $chart->addRow($entry[0], $entry[1], $entry[2]);+ }++ $chart->generate();++ return Response::json($chart->getData());++ }++ /**+ * @param Account $account+ *+ * @return \Illuminate\Http\JsonResponse+ */+ public function accountSankeyOutChart(Account $account)+ {+ // collect all relevant entries.+ $set = [];++ /** @var \Grumpydictator\Gchart\GChart $chart */+ $chart = App::make('gchart');+ $chart->addColumn('From', 'string');+ $chart->addColumn('To', 'string', 'domain');+ $chart->addColumn('Weight', 'number');++ $transactions = $account->transactions()->with(+ ['transactionjournal', 'transactionjournal.transactions', 'transactionjournal.budgets', 'transactionjournal.transactiontype',+ 'transactionjournal.categories']+ )->before(Session::get('end'))->after(+ Session::get('start')+ )->get();++ /** @var Transaction $transaction */+ foreach ($transactions as $transaction) {+ $amount = floatval($transaction->amount);+ $type = $transaction->transactionJournal->transactionType->type;++ if ($amount < 0 && $type != 'Transfer') {++ // from account to a budget (if present).+ $budgetName = isset($transaction->transactionJournal->budgets[0]) ? $transaction->transactionJournal->budgets[0]->name : '(no budget)';+ $set[] = [$account->name, $budgetName, $amount * -1];++ // from budget to category.+ $categoryName = isset($transaction->transactionJournal->categories[0]) ? ' ' . $transaction->transactionJournal->categories[0]->name+ : '(no cat)';+ $set[] = [$budgetName, $categoryName, $amount * -1];+ }+ }+ // loop the set, group everything together:+ $grouped = [];+ foreach ($set as $entry) {+ $key = $entry[0] . $entry[1];+ if (isset($grouped[$key])) {+ $grouped[$key][2] += $entry[2];+ } else {+ $grouped[$key] = $entry;+ }+ }++ // add rows to the chart:+ foreach ($grouped as $entry) {+ $chart->addRow($entry[0], $entry[1], $entry[2]);+ }++ $chart->generate();++ return Response::json($chart->getData());++ }+/*** This method renders the b*/@@ -60,95 +216,126 @@ class GoogleChartController extends BaseController}$chart->generate();+return Response::json($chart->getData());}/**- * @param $year- ** @return \Illuminate\Http\JsonResponse*/- public function yearInExp($year)+ public function allBudgetsHomeChart(){- try {- $start = new Carbon('01-01-' . $year);- } catch (Exception $e) {- App::abort(500);- }/** @var \Grumpydictator\Gchart\GChart $chart */$chart = App::make('gchart');- $chart->addColumn('Month', 'date');- $chart->addColumn('Income', 'number');- $chart->addColumn('Expenses', 'number');+ $chart->addColumn('Budget', 'string');+ $chart->addColumn('Budgeted', 'number');+ $chart->addColumn('Spent', 'number');- /** @var \FireflyIII\Database\TransactionJournal $tj */- $tj = App::make('FireflyIII\Database\TransactionJournal');+ /** @var \FireflyIII\Database\Budget $bdt */+ $bdt = App::make('FireflyIII\Database\Budget');+ $budgets = $bdt->get();- $end = clone $start;- $end->endOfYear();- while ($start < $end) {+ /*+ * Loop budgets:+ */+ /** @var Budget $budget */+ foreach ($budgets as $budget) {- // total income:- $income = $tj->getSumOfIncomesByMonth($start);- $expense = $tj->getSumOfExpensesByMonth($start);+ /*+ * Is there a repetition starting on this particular date? We can use that.+ */+ /** @var \LimitRepetition $repetition */+ $repetition = $bdt->repetitionOnStartingOnDate($budget, Session::get('start'));- $chart->addRow(clone $start, $income, $expense);- $start->addMonth();+ /*+ * If there is, use it. Otherwise, forget it.+ */+ if (is_null($repetition)) {+ // use the session start and end for our search query+ $searchStart = Session::get('start');+ $searchEnd = Session::get('end');+ // the limit is zero:+ $limit = 0;++ } else {+ // use the limit's start and end for our search query+ $searchStart = $repetition->startdate;+ $searchEnd = $repetition->enddate;+ // the limit is the repetitions limit:+ $limit = floatval($repetition->amount);+ }++ /*+ * No matter the result of the search for the repetition, get all the transactions associated+ * with the budget, and sum up the expenses made.+ */+ $expenses = floatval($budget->transactionjournals()->before($searchEnd)->after($searchStart)->lessThan(0)->sum('amount')) * -1;+ if ($expenses > 0) {+ $chart->addRow($budget->name, $limit, $expenses);+ }}+ /*+ * Finally, get all transactions WITHOUT a budget and add those as well.+ * (yes this method is oddly specific).+ */+ $noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange(Session::get('start'), Session::get('end'));+ $sum = $noBudgetSet->sum('amount') * -1;+ $chart->addRow('No budget', 0, $sum);+$chart->generate();- return Response::json($chart->getData());+ return Response::json($chart->getData());}/**- * @param $year- ** @return \Illuminate\Http\JsonResponse*/- public function yearInExpSum($year)+ public function allCategoriesHomeChart(){- try {- $start = new Carbon('01-01-' . $year);- } catch (Exception $e) {- App::abort(500);- }+ $data = [];+/** @var \Grumpydictator\Gchart\GChart $chart */$chart = App::make('gchart');- $chart->addColumn('Summary', 'string');- $chart->addColumn('Income', 'number');- $chart->addColumn('Expenses', 'number');+ $chart->addColumn('Category', 'string');+ $chart->addColumn('Spent', 'number');/** @var \FireflyIII\Database\TransactionJournal $tj */$tj = App::make('FireflyIII\Database\TransactionJournal');- $end = clone $start;- $end->endOfYear();- $income = 0;- $expense = 0;- $count = 0;- while ($start < $end) {-- // total income:- $income += $tj->getSumOfIncomesByMonth($start);- $expense += $tj->getSumOfExpensesByMonth($start);- $count++;+ /*+ * Get the journals:+ */+ $journals = $tj->getInDateRange(Session::get('start'), Session::get('end'));- $start->addMonth();+ /** @var \TransactionJournal $journal */+ foreach ($journals as $journal) {+ if ($journal->transactionType->type == 'Withdrawal') {+ $amount = $journal->getAmount();+ $category = $journal->categories()->first();+ if (!is_null($category)) {+ if (isset($data[$category->name])) {+ $data[$category->name] += $amount;+ } else {+ $data[$category->name] = $amount;+ }+ }+ }+ }+ arsort($data);+ foreach ($data as $key => $entry) {+ $chart->addRow($key, $entry);}- $chart->addRow('Sum', $income, $expense);- $count = $count > 0 ? $count : 1;- $chart->addRow('Average', ($income / $count), ($expense / $count));$chart->generate();+return Response::json($chart->getData());}-/*** @return \Illuminate\Http\JsonResponse*/@@ -181,192 +368,81 @@ class GoogleChartController extends BaseController$end = clone $start;$end->endOfYear();while ($start <= $end) {- $row = [clone $start];-- foreach ($budgets as $budget) {- $row[] = $bdt->spentInMonth($budget, $start);- }-- /*- * Without a budget:- */- $endOfMonth = clone $start;- $endOfMonth->endOfMonth();- $set = $bdt->transactionsWithoutBudgetInDateRange($start, $endOfMonth);- $row[] = floatval($set->sum('amount')) * -1;-- $chart->addRowArray($row);- $start->addMonth();- }--- $chart->generate();- return Response::json($chart->getData());- }-- /**- * @param Component $component- * @param $year- *- * @return \Illuminate\Http\JsonResponse- */- public function componentsAndSpending(Component $component, $year)- {- try {- $start = new Carbon('01-01-' . $year);- } catch (Exception $e) {- App::abort(500);- }-- if ($component->class == 'Budget') {- /** @var \FireflyIII\Database\Budget $repos */- $repos = App::make('FireflyIII\Database\Budget');- } else {- /** @var \FireflyIII\Database\Category $repos */- $repos = App::make('FireflyIII\Database\Category');- }-- /** @var \Grumpydictator\Gchart\GChart $chart */- $chart = App::make('gchart');- $chart->addColumn('Month', 'date');- $chart->addColumn('Budgeted', 'number');- $chart->addColumn('Spent', 'number');-- $end = clone $start;- $end->endOfYear();- while ($start <= $end) {-- $spent = $repos->spentInMonth($component, $start);- $repetition = $repos->repetitionOnStartingOnDate($component, $start);- if ($repetition) {- $budgeted = floatval($repetition->amount);- } else {- $budgeted = null;- }-- $chart->addRow(clone $start, $budgeted, $spent);-- $start->addMonth();- }--- $chart->generate();- return Response::json($chart->getData());--- }-- /**- * @return \Illuminate\Http\JsonResponse- */- public function allBudgetsHomeChart()- {- /** @var \Grumpydictator\Gchart\GChart $chart */- $chart = App::make('gchart');- $chart->addColumn('Budget', 'string');- $chart->addColumn('Budgeted', 'number');- $chart->addColumn('Spent', 'number');-- /** @var \FireflyIII\Database\Budget $bdt */- $bdt = App::make('FireflyIII\Database\Budget');- $budgets = $bdt->get();-- /*- * Loop budgets:- */- /** @var Budget $budget */- foreach ($budgets as $budget) {-- /*- * Is there a repetition starting on this particular date? We can use that.- */- /** @var \LimitRepetition $repetition */- $repetition = $bdt->repetitionOnStartingOnDate($budget, Session::get('start'));-- /*- * If there is, use it. Otherwise, forget it.- */- if (is_null($repetition)) {- // use the session start and end for our search query- $searchStart = Session::get('start');- $searchEnd = Session::get('end');- // the limit is zero:- $limit = 0;+ $row = [clone $start];- } else {- // use the limit's start and end for our search query- $searchStart = $repetition->startdate;- $searchEnd = $repetition->enddate;- // the limit is the repetitions limit:- $limit = floatval($repetition->amount);+ foreach ($budgets as $budget) {+ $row[] = $bdt->spentInMonth($budget, $start);}/*- * No matter the result of the search for the repetition, get all the transactions associated- * with the budget, and sum up the expenses made.+ * Without a budget:*/- $expenses = floatval($budget->transactionjournals()->before($searchEnd)->after($searchStart)->lessThan(0)->sum('amount')) * -1;- if ($expenses > 0) {- $chart->addRow($budget->name, $limit, $expenses);- }- }+ $endOfMonth = clone $start;+ $endOfMonth->endOfMonth();+ $set = $bdt->transactionsWithoutBudgetInDateRange($start, $endOfMonth);+ $row[] = floatval($set->sum('amount')) * -1;- /*- * Finally, get all transactions WITHOUT a budget and add those as well.- * (yes this method is oddly specific).- */- $noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange(Session::get('start'), Session::get('end'));- $sum = $noBudgetSet->sum('amount') * -1;- $chart->addRow('No budget', 0, $sum);+ $chart->addRowArray($row);+ $start->addMonth();+ }$chart->generate();+return Response::json($chart->getData());}/**+ * @param Component $component+ * @param $year+ ** @return \Illuminate\Http\JsonResponse*/- public function allCategoriesHomeChart()+ public function componentsAndSpending(Component $component, $year){- $data = [];+ try {+ $start = new Carbon('01-01-' . $year);+ } catch (Exception $e) {+ App::abort(500);+ }++ if ($component->class == 'Budget') {+ /** @var \FireflyIII\Database\Budget $repos */+ $repos = App::make('FireflyIII\Database\Budget');+ } else {+ /** @var \FireflyIII\Database\Category $repos */+ $repos = App::make('FireflyIII\Database\Category');+ }/** @var \Grumpydictator\Gchart\GChart $chart */$chart = App::make('gchart');- $chart->addColumn('Category', 'string');+ $chart->addColumn('Month', 'date');+ $chart->addColumn('Budgeted', 'number');$chart->addColumn('Spent', 'number');- /** @var \FireflyIII\Database\TransactionJournal $tj */- $tj = App::make('FireflyIII\Database\TransactionJournal');-- /*- * Get the journals:- */- $journals = $tj->getInDateRange(Session::get('start'), Session::get('end'));+ $end = clone $start;+ $end->endOfYear();+ while ($start <= $end) {- /** @var \TransactionJournal $journal */- foreach ($journals as $journal) {- if ($journal->transactionType->type == 'Withdrawal') {- $amount = $journal->getAmount();- $category = $journal->categories()->first();- if (!is_null($category)) {- if (isset($data[$category->name])) {- $data[$category->name] += $amount;- } else {- $data[$category->name] = $amount;- }- }+ $spent = $repos->spentInMonth($component, $start);+ $repetition = $repos->repetitionOnStartingOnDate($component, $start);+ if ($repetition) {+ $budgeted = floatval($repetition->amount);+ } else {+ $budgeted = null;}- }- arsort($data);- foreach ($data as $key => $entry) {- $chart->addRow($key, $entry);++ $chart->addRow(clone $start, $budgeted, $spent);++ $start->addMonth();}$chart->generate();+return Response::json($chart->getData());+}/**@@ -380,14 +456,8 @@ class GoogleChartController extends BaseController* Set of paid transaction journals.* Set of unpaid recurring transactions.*/- $paid = [- 'items' => [],- 'amount' => 0- ];- $unpaid = [- 'items' => [],- 'amount' => 0- ];+ $paid = ['items' => [], 'amount' => 0];+ $unpaid = ['items' => [], 'amount' => 0];/** @var \Grumpydictator\Gchart\GChart $chart */$chart = App::make('gchart');@@ -455,160 +525,93 @@ class GoogleChartController extends BaseController$chart->addRow('Paid: ' . join(', ', $paid['items']), $paid['amount']);$chart->generate();- return Response::json($chart->getData());-- }-- /**- * @param Account $account- */- public function accountBalanceChart(Account $account)- {- /** @var \Grumpydictator\Gchart\GChart $chart */- $chart = App::make('gchart');- $chart->addColumn('Day of month', 'date');- $chart->addColumn('Balance for ' . $account->name, 'number');-- /*- * Loop the date, then loop the accounts, then add balance.- */- $start = Session::get('start');- $end = Session::get('end');- $current = clone $start;- while ($end >= $current) {- $row = [clone $current];- if ($current > Carbon::now()) {- $row[] = null;- } else {- $row[] = $account->balance($current);- }-- $chart->addRowArray($row);- $current->addDay();- }--- $chart->generate();return Response::json($chart->getData());+}/**- * @param Account $account+ * @param $year** @return \Illuminate\Http\JsonResponse*/- public function accountSankeyOutChart(Account $account)+ public function yearInExp($year){- // collect all relevant entries.- $set = [];-+ try {+ $start = new Carbon('01-01-' . $year);+ } catch (Exception $e) {+ App::abort(500);+ }/** @var \Grumpydictator\Gchart\GChart $chart */$chart = App::make('gchart');- $chart->addColumn('From', 'string');- $chart->addColumn('To', 'string', 'domain');- $chart->addColumn('Weight', 'number');-- $transactions = $account->transactions()->with(- ['transactionjournal', 'transactionjournal.transactions', 'transactionjournal.budgets', 'transactionjournal.transactiontype',- 'transactionjournal.categories']- )->before(Session::get('end'))->after(- Session::get('start')- )->get();+ $chart->addColumn('Month', 'date');+ $chart->addColumn('Income', 'number');+ $chart->addColumn('Expenses', 'number');- /** @var Transaction $transaction */- foreach ($transactions as $transaction) {- $amount = floatval($transaction->amount);- $type = $transaction->transactionJournal->transactionType->type;+ /** @var \FireflyIII\Database\TransactionJournal $tj */+ $tj = App::make('FireflyIII\Database\TransactionJournal');- if ($amount < 0 && $type != 'Transfer') {+ $end = clone $start;+ $end->endOfYear();+ while ($start < $end) {- // from account to a budget (if present).- $budgetName = isset($transaction->transactionJournal->budgets[0]) ? $transaction->transactionJournal->budgets[0]->name : '(no budget)';- $set[] = [$account->name, $budgetName, $amount * -1];+ // total income:+ $income = $tj->getSumOfIncomesByMonth($start);+ $expense = $tj->getSumOfExpensesByMonth($start);- // from budget to category.- $categoryName = isset($transaction->transactionJournal->categories[0]) ? ' ' . $transaction->transactionJournal->categories[0]->name- : '(no cat)';- $set[] = [$budgetName, $categoryName, $amount * -1];- }- }- // loop the set, group everything together:- $grouped = [];- foreach ($set as $entry) {- $key = $entry[0] . $entry[1];- if (isset($grouped[$key])) {- $grouped[$key][2] += $entry[2];- } else {- $grouped[$key] = $entry;- }+ $chart->addRow(clone $start, $income, $expense);+ $start->addMonth();}- // add rows to the chart:- foreach ($grouped as $entry) {- $chart->addRow($entry[0], $entry[1], $entry[2]);- }$chart->generate();+return Response::json($chart->getData());}/**- * @param Account $account+ * @param $year** @return \Illuminate\Http\JsonResponse*/- public function accountSankeyInChart(Account $account)+ public function yearInExpSum($year){- // collect all relevant entries.- $set = [];-+ try {+ $start = new Carbon('01-01-' . $year);+ } catch (Exception $e) {+ App::abort(500);+ }/** @var \Grumpydictator\Gchart\GChart $chart */$chart = App::make('gchart');- $chart->addColumn('From', 'string');- $chart->addColumn('To', 'string', 'domain');- $chart->addColumn('Weight', 'number');+ $chart->addColumn('Summary', 'string');+ $chart->addColumn('Income', 'number');+ $chart->addColumn('Expenses', 'number');- $transactions = $account->transactions()->with(- ['transactionjournal', 'transactionjournal.transactions' => function ($q) {- $q->where('amount', '<', 0);- }, 'transactionjournal.budgets', 'transactionjournal.transactiontype', 'transactionjournal.categories']- )->before(Session::get('end'))->after(- Session::get('start')- )->get();+ /** @var \FireflyIII\Database\TransactionJournal $tj */+ $tj = App::make('FireflyIII\Database\TransactionJournal');- /** @var Transaction $transaction */- foreach ($transactions as $transaction) {- $amount = floatval($transaction->amount);- $type = $transaction->transactionJournal->transactionType->type;+ $end = clone $start;+ $end->endOfYear();+ $income = 0;+ $expense = 0;+ $count = 0;+ while ($start < $end) {- if ($amount > 0 && $type != 'Transfer') {+ // total income:+ $income += $tj->getSumOfIncomesByMonth($start);+ $expense += $tj->getSumOfExpensesByMonth($start);+ $count++;- $otherAccount = $transaction->transactionJournal->transactions[0]->account->name;- $categoryName = isset($transaction->transactionJournal->categories[0]) ? $transaction->transactionJournal->categories[0]->name- : '(no cat)';- $set[] = [$otherAccount, $categoryName, $amount];- $set[] = [$categoryName, $account->name, $amount];- }- }- // loop the set, group everything together:- $grouped = [];- foreach ($set as $entry) {- $key = $entry[0] . $entry[1];- if (isset($grouped[$key])) {- $grouped[$key][2] += $entry[2];- } else {- $grouped[$key] = $entry;- }+ $start->addMonth();}+ $chart->addRow('Sum', $income, $expense);+ $count = $count > 0 ? $count : 1;+ $chart->addRow('Average', ($income / $count), ($expense / $count));- // add rows to the chart:- foreach ($grouped as $entry) {- $chart->addRow($entry[0], $entry[1], $entry[2]);- }$chart->generate();+return Response::json($chart->getData());}diff --git a/app/controllers/GoogleTableController.php b/app/controllers/GoogleTableController.phpindex 18c45283d5..9b5cfeccba 100644--- a/app/controllers/GoogleTableController.php+++ b/app/controllers/GoogleTableController.php@@ -7,6 +7,56 @@ use FireflyIII\Exception\FireflyException;class GoogleTableController extends BaseController{+ /**+ * @param $what+ *+ * @throws FireflyException+ */+ public function accountList($what)+ {++ /** @var \FireflyIII\Database\Account $acct */+ $acct = App::make('FireflyIII\Database\Account');++ switch ($what) {+ default:+ throw new FireflyException('Cannot handle "' . e($what) . '" in accountList.');+ break;+ case 'asset':+ $list = $acct->getAssetAccounts();+ break;+ case 'expense':+ $list = $acct->getExpenseAccounts();+ break;+ case 'revenue':+ $list = $acct->getRevenueAccounts();+ break;+ }+++ $chart = App::make('gchart');+ $chart->addColumn('ID', 'number');+ $chart->addColumn('ID_Edit', 'string');+ $chart->addColumn('ID_Delete', 'string');+ $chart->addColumn('Name_URL', 'string');+ $chart->addColumn('Name', 'string');+ $chart->addColumn('Balance', 'number');++ /** @var \Account $entry */+ foreach ($list as $entry) {+ $edit = route('accounts.edit', $entry->id);+ $delete = route('accounts.delete', $entry->id);+ $show = route('accounts.show', $entry->id);+ $chart->addRow($entry->id, $edit, $delete, $show, $entry->name, $entry->balance());+ }++ $chart->generate();++ return Response::json($chart->getData());+++ }+/*** @return \Illuminate\Http\JsonResponse*/@@ -35,61 +85,156 @@ class GoogleTableController extends BaseController$chart->generate();+return Response::json($chart->getData());}- /**- * @param $what- *- * @throws FireflyException- */- public function accountList($what)+ public function recurringList(){+ /** @var \Grumpydictator\Gchart\GChart $chart */+ $chart = App::make('gchart');+ $chart->addColumn('ID', 'number');+ $chart->addColumn('ID_Edit', 'string');+ $chart->addColumn('ID_Delete', 'string');+ $chart->addColumn('Name_URL', 'string');+ $chart->addColumn('Name', 'string');- /** @var \FireflyIII\Database\Account $acct */- $acct = App::make('FireflyIII\Database\Account');+ /** @var \FireflyIII\Database\RecurringTransaction $repository */+ $repository = App::make('FireflyIII\Database\RecurringTransaction');++ $set = $repository->get();++ /** @var \RecurringTransaction $entry */+ foreach ($set as $entry) {+ $row = [$entry->id, route('recurring.edit', $entry->id), route('recurring.delete', $entry->id), route('recurring.show', $entry->id), $entry->name];+ $chart->addRowArray($row);- switch ($what) {- default:- throw new FireflyException('Cannot handle "' . e($what) . '" in accountList.');- break;- case 'asset':- $list = $acct->getAssetAccounts();- break;- case 'expense':- $list = $acct->getExpenseAccounts();- break;- case 'revenue':- $list = $acct->getRevenueAccounts();- break;}+ /*+ * <th>name</th>+ <th>match</th>+ <th>amount_min</th>+ <th>amount_max</th>+ <th>date</th>+ <th>active</th>+ <th>automatch</th>+ <th>repeat_freq</th>+ <th>id</th>++ */+ $chart->generate();++ return Response::json($chart->getData());+ }++ /**+ * @param Account $account+ */+ public function transactionsByAccount(Account $account)+ {+ /** @var \Grumpydictator\Gchart\GChart $chart */$chart = App::make('gchart');$chart->addColumn('ID', 'number');$chart->addColumn('ID_Edit', 'string');$chart->addColumn('ID_Delete', 'string');- $chart->addColumn('Name_URL', 'string');- $chart->addColumn('Name', 'string');- $chart->addColumn('Balance', 'number');+ $chart->addColumn('Date', 'date');+ $chart->addColumn('Description_URL', 'string');+ $chart->addColumn('Description', 'string');+ $chart->addColumn('Amount', 'number');+ $chart->addColumn('From_URL', 'string');+ $chart->addColumn('From', 'string');+ $chart->addColumn('To_URL', 'string');+ $chart->addColumn('To', 'string');+ $chart->addColumn('Budget_URL', 'string');+ $chart->addColumn('Budget', 'string');+ $chart->addColumn('Category_URL', 'string');+ $chart->addColumn('Category', 'string');- /** @var \Account $entry */- foreach ($list as $entry) {- $edit = route('accounts.edit', $entry->id);- $delete = route('accounts.delete', $entry->id);- $show = route('accounts.show', $entry->id);- $chart->addRow($entry->id, $edit, $delete, $show, $entry->name, $entry->balance());++ /*+ * Find transactions:+ */+ $accountID = $account->id;+ $transactions = $account->transactions()->with(+ ['transactionjournal', 'transactionjournal.transactions' => function ($q) use ($accountID) {+ $q->where('account_id', '!=', $accountID);+ }, 'transactionjournal.budgets', 'transactionjournal.transactiontype', 'transactionjournal.categories']+ )->before(Session::get('end'))->after(+ Session::get('start')+ )->orderBy('date', 'DESC')->get();++ /** @var Transaction $transaction */+ foreach ($transactions as $transaction) {+ $date = $transaction->transactionJournal->date;+ $descriptionURL = route('transactions.show', $transaction->transaction_journal_id);+ $description = $transaction->transactionJournal->description;+ $amount = floatval($transaction->amount);++ if ($transaction->transactionJournal->transactions[0]->account->id == $account->id) {+ $opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[1]->account->id);+ $opposingAccountName = $transaction->transactionJournal->transactions[1]->account->name;+ } else {+ $opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[0]->account->id);+ $opposingAccountName = $transaction->transactionJournal->transactions[0]->account->name;+ }+ if (isset($transaction->transactionJournal->budgets[0])) {+ $budgetURL = route('budgets.show', $transaction->transactionJournal->budgets[0]->id);+ $budget = $transaction->transactionJournal->budgets[0]->name;+ } else {+ $budgetURL = '';+ $budget = '';+ }++ if (isset($transaction->transactionJournal->categories[0])) {+ $categoryURL = route('categories.show', $transaction->transactionJournal->categories[0]->id);+ $category = $transaction->transactionJournal->categories[0]->name;+ } else {+ $categoryURL = '';+ $category = '';+ }+++ if ($amount < 0) {+ $from = $account->name;+ $fromURL = route('accounts.show', $account->id);++ $to = $opposingAccountName;+ $toURL = $opposingAccountURI;+ } else {+ $to = $account->name;+ $toURL = route('accounts.show', $account->id);++ $from = $opposingAccountName;+ $fromURL = $opposingAccountURI;+ }++ $id = $transaction->transactionJournal->id;+ $edit = route('transactions.edit', $transaction->transactionJournal->id);+ $delete = route('transactions.delete', $transaction->transactionJournal->id);+ $chart->addRow(+ $id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $budget, $categoryURL, $category+ );}- $chart->generate();- return Response::json($chart->getData());+ // <th>Date</th>+ // <th>Description</th>+ // <th>Amount (€)</th>+ // <th>From</th>+ // <th>To</th>+ // <th>Budget / category</th>+ // <th>ID</th>+ $chart->generate();++ return Response::json($chart->getData());}/**- * @param Component $component+ * @param Component $component* @param LimitRepetition $repetition*/public function transactionsByComponent(Component $component, LimitRepetition $repetition = null)@@ -114,26 +259,25 @@ class GoogleTableController extends BaseControllerif (is_null($repetition)) {$journals = $component->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->orderBy('date', 'DESC')- ->get();+ ->get();} else {$journals = $component->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->after($repetition->startdate- )- ->before($repetition->enddate)->orderBy('date', 'DESC')->get();+ )->before($repetition->enddate)->orderBy('date', 'DESC')->get();}/** @var TransactionJournal $transaction */foreach ($journals as $journal) {- $date = $journal->date;+ $date = $journal->date;$descriptionURL = route('transactions.show', $journal->id);- $description = $journal->description;+ $description = $journal->description;/** @var Transaction $transaction */foreach ($journal->transactions as $transaction) {if (floatval($transaction->amount) > 0) {$amount = floatval($transaction->amount);- $to = $transaction->account->name;- $toURL = route('accounts.show', $transaction->account->id);+ $to = $transaction->account->name;+ $toURL = route('accounts.show', $transaction->account->id);} else {- $from = $transaction->account->name;+ $from = $transaction->account->name;$fromURL = route('accounts.show', $transaction->account->id);}@@ -148,15 +292,15 @@ class GoogleTableController extends BaseControllerif (isset($journal->categories[0])) {$categoryURL = route('categories.show', $journal->categories[0]->id);- $category = $journal->categories[0]->name;+ $category = $journal->categories[0]->name;} else {$categoryURL = '';- $category = '';+ $category = '';}- $id = $journal->id;- $edit = route('transactions.edit', $journal->id);+ $id = $journal->id;+ $edit = route('transactions.edit', $journal->id);$delete = route('transactions.delete', $journal->id);$chart->addRow($id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $component, $categoryURL,@@ -166,53 +310,9 @@ class GoogleTableController extends BaseController$chart->generate();- return Response::json($chart->getData());-- }-- public function recurringList()- {- /** @var \Grumpydictator\Gchart\GChart $chart */- $chart = App::make('gchart');- $chart->addColumn('ID', 'number');- $chart->addColumn('ID_Edit', 'string');- $chart->addColumn('ID_Delete', 'string');- $chart->addColumn('Name_URL', 'string');- $chart->addColumn('Name', 'string');-- /** @var \FireflyIII\Database\RecurringTransaction $repository */- $repository = App::make('FireflyIII\Database\RecurringTransaction');-- $set = $repository->get();-- /** @var \RecurringTransaction $entry */- foreach ($set as $entry) {- $row = [- $entry->id,- route('recurring.edit', $entry->id),- route('recurring.delete', $entry->id),- route('recurring.show', $entry->id),- $entry->name- ];- $chart->addRowArray($row);-- }-- /*- * <th>name</th>- <th>match</th>- <th>amount_min</th>- <th>amount_max</th>- <th>date</th>- <th>active</th>- <th>automatch</th>- <th>repeat_freq</th>- <th>id</th>-- */- $chart->generate();return Response::json($chart->getData());+}/**@@ -261,158 +361,55 @@ class GoogleTableController extends BaseController/** @var TransactionJournal $journal */foreach ($list as $journal) {- $date = $journal->date;+ $date = $journal->date;$descriptionURL = route('transactions.show', $journal->id);- $description = $journal->description;- $id = $journal->id;+ $description = $journal->description;+ $id = $journal->id;if ($journal->transactions[0]->amount < 0) {- $fromURL = route('accounts.show', $journal->transactions[0]->account->id);+ $fromURL = route('accounts.show', $journal->transactions[0]->account->id);$fromName = $journal->transactions[0]->account->name;- $amount = floatval($journal->transactions[0]->amount);+ $amount = floatval($journal->transactions[0]->amount);- $toURL = route('accounts.show', $journal->transactions[1]->account->id);+ $toURL = route('accounts.show', $journal->transactions[1]->account->id);$toName = $journal->transactions[1]->account->name;} else {- $fromURL = route('accounts.show', $journal->transactions[1]->account->id);+ $fromURL = route('accounts.show', $journal->transactions[1]->account->id);$fromName = $journal->transactions[1]->account->name;- $amount = floatval($journal->transactions[1]->amount);+ $amount = floatval($journal->transactions[1]->amount);- $toURL = route('accounts.show', $journal->transactions[0]->account->id);+ $toURL = route('accounts.show', $journal->transactions[0]->account->id);$toName = $journal->transactions[0]->account->name;}if (isset($journal->budgets[0])) {$budgetURL = route('budgets.show', $journal->budgets[0]->id);- $budget = $journal->budgets[0]->name;+ $budget = $journal->budgets[0]->name;} else {$budgetURL = '';- $budget = '';+ $budget = '';}if (isset($journal->categories[0])) {$categoryURL = route('categories.show', $journal->categories[0]->id);- $category = $journal->categories[0]->name;+ $category = $journal->categories[0]->name;} else {$categoryURL = '';- $category = '';+ $category = '';}- $edit = route('transactions.edit', $journal->id);+ $edit = route('transactions.edit', $journal->id);$delete = route('transactions.delete', $journal->id);$chart->addRow(- $id, $edit, $delete, $date, $descriptionURL, $description, $amount,- $fromURL, $fromName, $toURL, $toName,- $budgetURL, $budget, $categoryURL, $category+ $id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $fromName, $toURL, $toName, $budgetURL, $budget, $categoryURL,+ $category);}$chart->generate();- return Response::json($chart->getData());- }-- /**- * @param Account $account- */- public function transactionsByAccount(Account $account)- {- /** @var \Grumpydictator\Gchart\GChart $chart */- $chart = App::make('gchart');- $chart->addColumn('ID', 'number');- $chart->addColumn('ID_Edit', 'string');- $chart->addColumn('ID_Delete', 'string');- $chart->addColumn('Date', 'date');- $chart->addColumn('Description_URL', 'string');- $chart->addColumn('Description', 'string');- $chart->addColumn('Amount', 'number');- $chart->addColumn('From_URL', 'string');- $chart->addColumn('From', 'string');- $chart->addColumn('To_URL', 'string');- $chart->addColumn('To', 'string');- $chart->addColumn('Budget_URL', 'string');- $chart->addColumn('Budget', 'string');- $chart->addColumn('Category_URL', 'string');- $chart->addColumn('Category', 'string');--- /*- * Find transactions:- */- $accountID = $account->id;- $transactions = $account->transactions()->with(- ['transactionjournal', 'transactionjournal.transactions' => function ($q) use ($accountID) {- $q->where('account_id', '!=', $accountID);- }, 'transactionjournal.budgets', 'transactionjournal.transactiontype',- 'transactionjournal.categories']- )->before(Session::get('end'))->after(- Session::get('start')- )->orderBy('date', 'DESC')->get();-- /** @var Transaction $transaction */- foreach ($transactions as $transaction) {- $date = $transaction->transactionJournal->date;- $descriptionURL = route('transactions.show', $transaction->transaction_journal_id);- $description = $transaction->transactionJournal->description;- $amount = floatval($transaction->amount);- if ($transaction->transactionJournal->transactions[0]->account->id == $account->id) {- $opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[1]->account->id);- $opposingAccountName = $transaction->transactionJournal->transactions[1]->account->name;- } else {- $opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[0]->account->id);- $opposingAccountName = $transaction->transactionJournal->transactions[0]->account->name;- }- if (isset($transaction->transactionJournal->budgets[0])) {- $budgetURL = route('budgets.show', $transaction->transactionJournal->budgets[0]->id);- $budget = $transaction->transactionJournal->budgets[0]->name;- } else {- $budgetURL = '';- $budget = '';- }-- if (isset($transaction->transactionJournal->categories[0])) {- $categoryURL = route('categories.show', $transaction->transactionJournal->categories[0]->id);- $category = $transaction->transactionJournal->categories[0]->name;- } else {- $categoryURL = '';- $category = '';- }--- if ($amount < 0) {- $from = $account->name;- $fromURL = route('accounts.show', $account->id);-- $to = $opposingAccountName;- $toURL = $opposingAccountURI;- } else {- $to = $account->name;- $toURL = route('accounts.show', $account->id);-- $from = $opposingAccountName;- $fromURL = $opposingAccountURI;- }-- $id = $transaction->transactionJournal->id;- $edit = route('transactions.edit', $transaction->transactionJournal->id);- $delete = route('transactions.delete', $transaction->transactionJournal->id);- $chart->addRow(- $id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $budget, $categoryURL, $category- );- }--// <th>Date</th>-// <th>Description</th>-// <th>Amount (€)</th>-// <th>From</th>-// <th>To</th>-// <th>Budget / category</th>-// <th>ID</th>--- $chart->generate();return Response::json($chart->getData());}}\ No newline at end of filediff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.phpindex 833ea0a044..035400b976 100644--- a/app/controllers/HomeController.php+++ b/app/controllers/HomeController.php@@ -1,5 +1,4 @@<?php-use FireflyIII\Shared\Preferences\PreferencesInterface as Prefs;/*** Class HomeController@@ -7,50 +6,6 @@ use FireflyIII\Shared\Preferences\PreferencesInterface as Prefs;*/class HomeController extends BaseController{- /**- * @return \Illuminate\Http\RedirectResponse- */- public function sessionPrev()- {- /** @var \FireflyIII\Shared\Toolkit\Navigation $navigation */- $navigation = App::make('FireflyIII\Shared\Toolkit\Navigation');- $navigation->prev();- return Redirect::back();- //return Redirect::route('index');- }-- /**- * @return \Illuminate\Http\RedirectResponse- */- public function sessionNext()- {- /** @var \FireflyIII\Shared\Toolkit\Navigation $navigation */- $navigation = App::make('FireflyIII\Shared\Toolkit\Navigation');- $navigation->next();- return Redirect::back();- //return Redirect::route('index');- }-- /**- * @param $range- *- * @return \Illuminate\Http\RedirectResponse- */- public function rangeJump($range)- {-- $valid = ['1D', '1W', '1M', '3M', '6M', '1Y',];-- /** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */- $preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');-- if (in_array($range, $valid)) {- $preferences->set('viewRange', $range);- Session::forget('range');- }- return Redirect::back();- }-/*** @return \Illuminate\Http\RedirectResponse*/@@ -66,9 +21,9 @@ class HomeController extends BaseController*/public function index(){-// Event::fire('limits.check');-// Event::fire('piggybanks.check');-// Event::fire('recurring.check');+ // Event::fire('limits.check');+ // Event::fire('piggybanks.check');+ // Event::fire('recurring.check');// count, maybe Firefly needs some introducing text to show:/** @var \FireflyIII\Database\Account $acct */@@ -103,7 +58,54 @@ class HomeController extends BaseController}// build the home screen:- return View::make('index')->with('count', $count)->with('transactions', $transactions)->with('title', 'Firefly')- ->with('subTitle', 'What\'s playing?')->with('mainTitleIcon', 'fa-fire');+ return View::make('index')->with('count', $count)->with('transactions', $transactions)->with('title', 'Firefly')->with('subTitle', 'What\'s playing?')+ ->with('mainTitleIcon', 'fa-fire');+ }++ /**+ * @param $range+ *+ * @return \Illuminate\Http\RedirectResponse+ */+ public function rangeJump($range)+ {++ $valid = ['1D', '1W', '1M', '3M', '6M', '1Y',];++ /** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */+ $preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');++ if (in_array($range, $valid)) {+ $preferences->set('viewRange', $range);+ Session::forget('range');+ }++ return Redirect::back();+ }++ /**+ * @return \Illuminate\Http\RedirectResponse+ */+ public function sessionNext()+ {+ /** @var \FireflyIII\Shared\Toolkit\Navigation $navigation */+ $navigation = App::make('FireflyIII\Shared\Toolkit\Navigation');+ $navigation->next();++ return Redirect::back();+ //return Redirect::route('index');+ }++ /**+ * @return \Illuminate\Http\RedirectResponse+ */+ public function sessionPrev()+ {+ /** @var \FireflyIII\Shared\Toolkit\Navigation $navigation */+ $navigation = App::make('FireflyIII\Shared\Toolkit\Navigation');+ $navigation->prev();++ return Redirect::back();+ //return Redirect::route('index');}}\ No newline at end of filediff --git a/app/controllers/JsonController.php b/app/controllers/JsonController.phpindex 3dbe758b39..9f0512572a 100644--- a/app/controllers/JsonController.php+++ b/app/controllers/JsonController.php@@ -16,8 +16,8 @@ class JsonController extends BaseController{/** @var \FireflyIII\Database\Category $categories */$categories = App::make('FireflyIII\Database\Category');- $list = $categories->get();- $return = [];+ $list = $categories->get();+ $return = [];foreach ($list as $entry) {$return[] = $entry->name;}@@ -36,8 +36,8 @@ class JsonController extends BaseController{/** @var \FireflyIII\Database\Account $accounts */$accounts = App::make('FireflyIII\Database\Account');- $list = $accounts->getExpenseAccounts();- $return = [];+ $list = $accounts->getExpenseAccounts();+ $return = [];foreach ($list as $entry) {$return[] = $entry->name;}@@ -53,8 +53,8 @@ class JsonController extends BaseController{/** @var \FireflyIII\Database\Account $accounts */$accounts = App::make('FireflyIII\Database\Account');- $list = $accounts->getRevenueAccounts();- $return = [];+ $list = $accounts->getRevenueAccounts();+ $return = [];foreach ($list as $entry) {$return[] = $entry->name;}diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.phpindex c1e728b063..8b94de89a7 100644--- a/app/controllers/PiggybankController.php+++ b/app/controllers/PiggybankController.php@@ -19,6 +19,25 @@ class PiggybankController extends BaseController{}+ /**+ * @param Piggybank $piggybank+ *+ * @return $this+ */+ public function add(Piggybank $piggybank)+ {+ /** @var \FireflyIII\Database\Piggybank $acct */+ $repos = App::make('FireflyIII\Database\Piggybank');++ $leftOnAccount = $repos->leftOnAccount($piggybank->account);+ $savedSoFar = $piggybank->currentRelevantRep()->currentamount;+ $leftToSave = $piggybank->targetamount - $savedSoFar;+ $amount = min($leftOnAccount, $leftToSave);+++ return View::make('piggybanks.add', compact('piggybank'))->with('maxAmount', $amount);+ }+/*** @throws NotImplementedException*/@@ -35,8 +54,10 @@ class PiggybankController extends BaseController$accounts = $toolkit->makeSelectList($acct->getAssetAccounts());- return View::make('piggybanks.create', compact('accounts', 'periods'))->with('title', 'Piggy banks')->with('mainTitleIcon', 'fa-sort-amount-asc')- ->with('subTitle', 'Create new piggy bank')->with('subTitleIcon', 'fa-plus');++ return View::make('piggybanks.create', compact('accounts', 'periods'))->with('title', 'Piggy banks')->with('mainTitleIcon', 'fa-sort-amount-asc')->with(+ 'subTitle', 'Create new piggy bank'+ )->with('subTitleIcon', 'fa-plus');}/**@@ -46,11 +67,9 @@ class PiggybankController extends BaseController*/public function delete(Piggybank $piggybank){- return View::make('piggybanks.delete')- ->with('piggybank', $piggybank)- ->with('subTitle', 'Delete "' . $piggybank->name . '"')- ->with('title', 'Piggy banks')- ->with('mainTitleIcon', 'fa-sort-amount-asc');+ return View::make('piggybanks.delete')->with('piggybank', $piggybank)->with('subTitle', 'Delete "' . $piggybank->name . '"')->with(+ 'title', 'Piggy banks'+ )->with('mainTitleIcon', 'fa-sort-amount-asc');}/**@@ -89,38 +108,46 @@ class PiggybankController extends BaseController/** Flash some data to fill the form.*/- $prefilled = [- 'name' => $piggybank->name,- 'account_id' => $piggybank->account_id,- 'targetamount' => $piggybank->targetamount,- 'targetdate' => $piggybank->targetdate,- 'remind_me' => intval($piggybank->remind_me) == 1 ? true : false- ];+ $prefilled = ['name' => $piggybank->name, 'account_id' => $piggybank->account_id, 'targetamount' => $piggybank->targetamount,+ 'targetdate' => $piggybank->targetdate, 'remind_me' => intval($piggybank->remind_me) == 1 ? true : false];Session::flash('prefilled', $prefilled);return View::make('piggybanks.edit', compact('piggybank', 'accounts', 'periods', 'prefilled'))->with('title', 'Piggybanks')->with('mainTitleIcon', 'fa-sort-amount-asc'- )- ->with('subTitle', 'Edit piggy bank "' . e($piggybank->name) . '"')->with('subTitleIcon', 'fa-pencil');+ )->with('subTitle', 'Edit piggy bank "' . e($piggybank->name) . '"')->with('subTitleIcon', 'fa-pencil');}- /**- * @param Piggybank $piggybank- *- * @return $this- */- public function add(Piggybank $piggybank)+ public function index(){- /** @var \FireflyIII\Database\Piggybank $acct */+ /** @var \FireflyIII\Database\Piggybank $repos */$repos = App::make('FireflyIII\Database\Piggybank');- $leftOnAccount = $repos->leftOnAccount($piggybank->account);- $savedSoFar = $piggybank->currentRelevantRep()->currentamount;- $leftToSave = $piggybank->targetamount - $savedSoFar;- $amount = min($leftOnAccount, $leftToSave);+ /** @var Collection $piggybanks */+ $piggybanks = $repos->get();+ $accounts = [];+ /** @var Piggybank $piggybank */+ foreach ($piggybanks as $piggybank) {+ $piggybank->savedSoFar = floatval($piggybank->currentRelevantRep()->currentamount);+ $piggybank->percentage = intval($piggybank->savedSoFar / $piggybank->targetamount * 100);+ $piggybank->leftToSave = $piggybank->targetamount - $piggybank->savedSoFar;- return View::make('piggybanks.add', compact('piggybank'))->with('maxAmount', $amount);+ /*+ * Fill account information:+ */+ $account = $piggybank->account;+ if (!isset($accounts[$account->id])) {+ $accounts[$account->id] = ['name' => $account->name, 'balance' => $account->balance(),+ 'leftForPiggybanks' => $repos->leftOnAccount($account), 'sumOfSaved' => $piggybank->savedSoFar,+ 'sumOfTargets' => floatval($piggybank->targetamount), 'leftToSave' => $piggybank->leftToSave];+ } else {+ $accounts[$account->id]['sumOfSaved'] += $piggybank->savedSoFar;+ $accounts[$account->id]['sumOfTargets'] += floatval($piggybank->targetamount);+ $accounts[$account->id]['leftToSave'] += $piggybank->leftToSave;+ }+ }++ return View::make('piggybanks.index', compact('piggybanks', 'accounts'))->with('title', 'Piggy banks')->with('mainTitleIcon', 'fa-sort-amount-asc');}/**@@ -148,17 +175,8 @@ class PiggybankController extends BaseController} else {Session::flash('error', 'Could not add ' . mf($amount, false) . ' to "' . e($piggybank->name) . '".');}- return Redirect::route('piggybanks.index');- }- /**- * @param Piggybank $piggybank- *- * @return \Illuminate\View\View- */- public function remove(Piggybank $piggybank)- {- return View::make('piggybanks.remove', compact('piggybank'));+ return Redirect::route('piggybanks.index');}/**@@ -180,47 +198,20 @@ class PiggybankController extends BaseController} else {Session::flash('error', 'Could not remove ' . mf($amount, false) . ' from "' . e($piggybank->name) . '".');}+return Redirect::route('piggybanks.index');}- public function index()+ /**+ * @param Piggybank $piggybank+ *+ * @return \Illuminate\View\View+ */+ public function remove(Piggybank $piggybank){- /** @var \FireflyIII\Database\Piggybank $repos */- $repos = App::make('FireflyIII\Database\Piggybank');-- /** @var Collection $piggybanks */- $piggybanks = $repos->get();-- $accounts = [];- /** @var Piggybank $piggybank */- foreach ($piggybanks as $piggybank) {- $piggybank->savedSoFar = floatval($piggybank->currentRelevantRep()->currentamount);- $piggybank->percentage = intval($piggybank->savedSoFar / $piggybank->targetamount * 100);- $piggybank->leftToSave = $piggybank->targetamount - $piggybank->savedSoFar;-- /*- * Fill account information:- */- $account = $piggybank->account;- if (!isset($accounts[$account->id])) {- $accounts[$account->id] = [- 'name' => $account->name,- 'balance' => $account->balance(),- 'leftForPiggybanks' => $repos->leftOnAccount($account),- 'sumOfSaved' => $piggybank->savedSoFar,- 'sumOfTargets' => floatval($piggybank->targetamount),- 'leftToSave' => $piggybank->leftToSave- ];- } else {- $accounts[$account->id]['sumOfSaved'] += $piggybank->savedSoFar;- $accounts[$account->id]['sumOfTargets'] += floatval($piggybank->targetamount);- $accounts[$account->id]['leftToSave'] += $piggybank->leftToSave;- }- }- return View::make('piggybanks.index', compact('piggybanks', 'accounts'))->with('title', 'Piggy banks')->with('mainTitleIcon', 'fa-sort-amount-asc');+ return View::make('piggybanks.remove', compact('piggybank'));}-public function show(Piggybank $piggyBank){throw new NotImplementedException;@@ -249,6 +240,7 @@ class PiggybankController extends BaseControllerSession::flash('warnings', $messages['warnings']);Session::flash('successes', $messages['successes']);Session::flash('error', 'Could not save piggy bank: ' . $messages['errors']->first());+return Redirect::route('piggybanks.create')->withInput()->withErrors($messages['errors']);}// store!@@ -296,6 +288,7 @@ class PiggybankController extends BaseControllerSession::flash('warnings', $messages['warnings']);Session::flash('successes', $messages['successes']);Session::flash('error', 'Could not save piggy bank: ' . $messages['errors']->first());+return Redirect::route('piggybanks.edit', $piggyBank->id)->withInput()->withErrors($messages['errors']);}// store!@@ -312,6 +305,7 @@ class PiggybankController extends BaseControllerSession::flash('warnings', $messageBags['warnings']);Session::flash('successes', $messageBags['successes']);Session::flash('errors', $messageBags['errors']);+return Redirect::route('piggybanks.edit', $piggyBank->id)->withInput();break;}diff --git a/app/controllers/PreferencesController.php b/app/controllers/PreferencesController.phpindex e8e6b4b3e9..6e165af1c3 100644--- a/app/controllers/PreferencesController.php+++ b/app/controllers/PreferencesController.php@@ -28,13 +28,12 @@ class PreferencesController extends BaseController/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');- $accounts = $acct->getAssetAccounts();- $viewRange = $preferences->get('viewRange', '1M');+ $accounts = $acct->getAssetAccounts();+ $viewRange = $preferences->get('viewRange', '1M');$viewRangeValue = $viewRange->data;- $frontpage = $preferences->get('frontpageAccounts', []);+ $frontpage = $preferences->get('frontpageAccounts', []);- return View::make('preferences.index')->with('accounts', $accounts)->with('frontpageAccounts', $frontpage)- ->with('viewRange', $viewRangeValue);+ return View::make('preferences.index')->with('accounts', $accounts)->with('frontpageAccounts', $frontpage)->with('viewRange', $viewRangeValue);}/**diff --git a/app/controllers/ProfileController.php b/app/controllers/ProfileController.phpindex ebfbc437cd..938d41f28a 100644--- a/app/controllers/ProfileController.php+++ b/app/controllers/ProfileController.php@@ -8,21 +8,21 @@ class ProfileController extends BaseController/*** @return \Illuminate\View\View- **/- public function index()+ public function changePassword(){- return View::make('profile.index')->with('title', 'Profile')->with('subTitle', Auth::user()->email)->with('mainTitleIcon', 'fa-user');+ return View::make('profile.change-password')->with('title', Auth::user()->email)->with('subTitle', 'Change your password')->with(+ 'mainTitleIcon', 'fa-user'+ );}/*** @return \Illuminate\View\View+ **/- public function changePassword()+ public function index(){- return View::make('profile.change-password')->with('title', Auth::user()->email)->with('subTitle', 'Change your password')->with(- 'mainTitleIcon', 'fa-user'- );+ return View::make('profile.index')->with('title', 'Profile')->with('subTitle', Auth::user()->email)->with('mainTitleIcon', 'fa-user');}/**diff --git a/app/controllers/RecurringController.php b/app/controllers/RecurringController.phpindex b780a4822b..1569a7e9ec 100644--- a/app/controllers/RecurringController.php+++ b/app/controllers/RecurringController.php@@ -1,7 +1,5 @@<?php-use FireflyIII\Exception\FireflyException;-/*** Class RecurringController*@@ -23,9 +21,7 @@ class RecurringController extends BaseController{$periods = \Config::get('firefly.periods_to_text');- return View::make('recurring.create')- ->with('periods', $periods)- ->with('subTitle', 'Create new');+ return View::make('recurring.create')->with('periods', $periods)->with('subTitle', 'Create new');}/**@@ -35,9 +31,9 @@ class RecurringController extends BaseController*/public function delete(RecurringTransaction $recurringTransaction){- return View::make('recurring.delete')- ->with('recurringTransaction', $recurringTransaction)- ->with('subTitle', 'Delete "' . $recurringTransaction->name . '"');+ return View::make('recurring.delete')->with('recurringTransaction', $recurringTransaction)->with(+ 'subTitle', 'Delete "' . $recurringTransaction->name . '"'+ );}/**@@ -72,10 +68,9 @@ class RecurringController extends BaseController{$periods = \Config::get('firefly.periods_to_text');- return View::make('recurring.edit')- ->with('periods', $periods)- ->with('recurringTransaction', $recurringTransaction)- ->with('subTitle', 'Edit "' . $recurringTransaction->name . '"');+ return View::make('recurring.edit')->with('periods', $periods)->with('recurringTransaction', $recurringTransaction)->with(+ 'subTitle', 'Edit "' . $recurringTransaction->name . '"'+ );}/**@@ -86,31 +81,32 @@ class RecurringController extends BaseControllerreturn View::make('recurring.index');}- /**- *- */- public function show(RecurringTransaction $recurringTransaction)- {- return View::make('recurring.show')- ->with('recurring', $recurringTransaction)- ->with('subTitle', $recurringTransaction->name);- }-/*** @param RecurringTransaction $recurringTransaction+ ** @return mixed*/public function rescan(RecurringTransaction $recurringTransaction){if (intval($recurringTransaction->active) == 0) {Session::flash('warning', 'Inactive recurring transactions cannot be scanned.');+return Redirect::back();}throw new NotImplementedException;Session::flash('success', 'Rescanned everything.');+return Redirect::back();}+ /**+ *+ */+ public function show(RecurringTransaction $recurringTransaction)+ {+ return View::make('recurring.show')->with('recurring', $recurringTransaction)->with('subTitle', $recurringTransaction->name);+ }+public function store(){throw new NotImplementedException;diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.phpindex baab2c53a0..8c9f1fa021 100644--- a/app/controllers/ReportController.php+++ b/app/controllers/ReportController.php@@ -49,11 +49,7 @@ class ReportController extends BaseController$end = clone $date;$end->endOfYear();while ($date < $end) {- $summary[] = [- 'month' => $date->format('F'),- 'income' => $tj->getSumOfIncomesByMonth($date),- 'expense' => $tj->getSumOfExpensesByMonth($date),- ];+ $summary[] = ['month' => $date->format('F'), 'income' => $tj->getSumOfIncomesByMonth($date), 'expense' => $tj->getSumOfExpensesByMonth($date),];$date->addMonth();}diff --git a/app/controllers/SearchController.php b/app/controllers/SearchController.phpindex 49fe5ff1af..6217bdcac2 100644--- a/app/controllers/SearchController.php+++ b/app/controllers/SearchController.php@@ -14,7 +14,7 @@ class SearchController extends BaseControllerthrow new NotImplementedException;$subTitle = null;$rawQuery = null;- $result = [];+ $result = [];if (!is_null(Input::get('q'))) {$rawQuery = trim(Input::get('q'));$words = explode(' ', $rawQuery);@@ -25,18 +25,12 @@ class SearchController extends BaseController$categories = $this->_helper->searchCategories($words);$budgets = $this->_helper->searchBudgets($words);$tags = $this->_helper->searchTags($words);- $result = [- 'transactions' => $transactions,- 'accounts' => $accounts,- 'categories' => $categories,- 'budgets' => $budgets,- 'tags' => $tags- ];+ $result = ['transactions' => $transactions, 'accounts' => $accounts, 'categories' => $categories, 'budgets' => $budgets, 'tags' => $tags];}return View::make('search.index')->with('title', 'Search')->with('subTitle', $subTitle)->with('mainTitleIcon', 'fa-search'- )->with('query', $rawQuery)->with('result',$result);+ )->with('query', $rawQuery)->with('result', $result);}}\ No newline at end of filediff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.phpindex 32af9b1acc..2cf16b311c 100644--- a/app/controllers/TransactionController.php+++ b/app/controllers/TransactionController.php@@ -23,36 +23,6 @@ class TransactionController extends BaseControllerView::share('mainTitleIcon', 'fa-repeat');}- /**- * @param $what- *- * @return $this- */- public function index($what)- {-- switch ($what) {- case 'expenses':- case 'withdrawal':- $subTitleIcon = 'fa-long-arrow-left';- $subTitle = 'Expenses';- break;- case 'revenue':- case 'deposit':- $subTitleIcon = 'fa-long-arrow-right';- $subTitle = 'Revenue, income and deposits';- break;- case 'transfer':- case 'transfers':- $subTitleIcon = 'fa-arrows-h';- $subTitle = 'Transfers';- break;- }-- return View::make('transactions.index', compact('subTitle', 'subTitleIcon'))->with('what', $what);-- }-/*** Shows the view helping the user to create a new transaction journal.*@@ -122,7 +92,6 @@ class TransactionController extends BaseController}-/*** @param TransactionJournal $transactionJournal*@@ -201,12 +170,7 @@ class TransactionController extends BaseController/** Data to properly display the edit form.*/- $prefilled = [- 'date' => $journal->date->format('Y-m-d'),- 'category' => '',- 'budget_id' => 0,- 'piggybank_id' => $piggyBankId- ];+ $prefilled = ['date' => $journal->date->format('Y-m-d'), 'category' => '', 'budget_id' => 0, 'piggybank_id' => $piggyBankId];/** Fill in the category.@@ -245,6 +209,7 @@ class TransactionController extends BaseController/** Show the view.*/+return View::make('transactions.edit')->with('journal', $journal)->with('accounts', $accounts)->with('what', $what)->with('budgets', $budgets)->with('data', $prefilled)->with('piggies', $piggies)->with(@@ -252,6 +217,36 @@ class TransactionController extends BaseController);}+ /**+ * @param $what+ *+ * @return $this+ */+ public function index($what)+ {++ switch ($what) {+ case 'expenses':+ case 'withdrawal':+ $subTitleIcon = 'fa-long-arrow-left';+ $subTitle = 'Expenses';+ break;+ case 'revenue':+ case 'deposit':+ $subTitleIcon = 'fa-long-arrow-right';+ $subTitle = 'Revenue, income and deposits';+ break;+ case 'transfer':+ case 'transfers':+ $subTitleIcon = 'fa-arrows-h';+ $subTitle = 'Transfers';+ break;+ }++ return View::make('transactions.index', compact('subTitle', 'subTitleIcon'))->with('what', $what);++ }+/*** @param TransactionJournal $journal*@@ -273,8 +268,8 @@ class TransactionController extends BaseController*/public function store($what){- $data = Input::except('_token');- $data['what'] = $what;+ $data = Input::except('_token');+ $data['what'] = $what;$data['currency'] = 'EUR';/** @var \FireflyIII\Database\TransactionJournal $repository */@@ -292,6 +287,7 @@ class TransactionController extends BaseControllerSession::flash('warnings', $messages['warnings']);Session::flash('successes', $messages['successes']);Session::flash('error', 'Could not save transaction: ' . $messages['errors']->first());+return Redirect::route('transactions.create', $what)->withInput()->withErrors($messages['errors']);}// store!@@ -301,7 +297,7 @@ class TransactionController extends BaseControllerif ($data['post_submit_action'] == 'create_another') {return Redirect::route('transactions.create', $what);} else {- return Redirect::route('transactions.index',$what);+ return Redirect::route('transactions.index', $what);}break;case 'validate_only':@@ -310,7 +306,7 @@ class TransactionController extends BaseControllerSession::flash('successes', $messageBags['successes']);Session::flash('errors', $messageBags['errors']);- return Redirect::route('transactions.create',$what)->withInput();+ return Redirect::route('transactions.create', $what)->withInput();break;}@@ -335,6 +331,7 @@ class TransactionController extends BaseController*/if ($messageBag->count() > 0) {Session::flash('error', 'Could not save transaction: ' . $messageBag->first());+return Redirect::route('transactions.create', [$what])->withInput()->withErrors($messageBag);}@@ -359,6 +356,7 @@ class TransactionController extends BaseControllerSession::flash('warnings', $messageBags['warnings']);Session::flash('successes', $messageBags['successes']);Session::flash('errors', $messageBags['errors']);+return Redirect::route('transactions.create', [$what])->withInput();break;default:@@ -408,6 +406,7 @@ class TransactionController extends BaseControllerSession::flash('warnings', $messageBags['warnings']);Session::flash('successes', $messageBags['successes']);Session::flash('errors', $messageBags['errors']);+return Redirect::route('transactions.edit', $journal->id)->withInput();break;default:diff --git a/app/controllers/UserController.php b/app/controllers/UserController.phpindex 60300f52e7..18ca03429a 100644--- a/app/controllers/UserController.php+++ b/app/controllers/UserController.php@@ -23,6 +23,18 @@ class UserController extends BaseControllerreturn View::make('user.login');}+ /**+ * Logout user.+ *+ * @return \Illuminate\Http\RedirectResponse+ */+ public function logout()+ {+ Auth::logout();+ Session::flush();++ return Redirect::route('index');+ }/*** Login.@@ -32,10 +44,7 @@ class UserController extends BaseControllerpublic function postLogin(){$rememberMe = Input::get('remember_me') == '1';- $data = [- 'email' => Input::get('email'),- 'password' => Input::get('password')- ];+ $data = ['email' => Input::get('email'), 'password' => Input::get('password')];$result = Auth::attempt($data, $rememberMe);if ($result) {return Redirect::route('index');@@ -46,20 +55,6 @@ class UserController extends BaseControllerreturn View::make('user.login');}- /**- * If allowed, show the register form.- *- * @return $this|\Illuminate\View\View- */- public function register()- {- if (Config::get('auth.allow_register') !== true) {- return View::make('error')->with('message', 'Not possible');- }-- return View::make('user.register');- }-/*** If allowed, register the user.*@@ -85,7 +80,6 @@ class UserController extends BaseController$user = $repository->register(Input::all());-//$user = $this->user->register(Input::all());if ($user) {if (Config::get('auth.verify_mail') === true) {@@ -101,29 +95,6 @@ class UserController extends BaseControllerreturn View::make('user.register');}- /**- * Logout user.- *- * @return \Illuminate\Http\RedirectResponse- */- public function logout()- {- Auth::logout();- Session::flush();-- return Redirect::route('index');- }-- /**- * Show form to help user get a new password.- *- * @return \Illuminate\View\View- */- public function remindme()- {- return View::make('user.remindme');- }-/*** If need to verify, send new reset code.* Otherwise, send new password.@@ -157,6 +128,30 @@ class UserController extends BaseController}+ /**+ * If allowed, show the register form.+ *+ * @return $this|\Illuminate\View\View+ */+ public function register()+ {+ if (Config::get('auth.allow_register') !== true) {+ return View::make('error')->with('message', 'Not possible');+ }++ return View::make('user.register');+ }++ /**+ * Show form to help user get a new password.+ *+ * @return \Illuminate\View\View+ */+ public function remindme()+ {+ return View::make('user.remindme');+ }+/*** Send a user a password based on his reset code.*