Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix the view for accounts.
James Cole5a920d5efd35
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.phpindex 88e8b75145..8c89dda1f8 100644--- a/app/controllers/AccountController.php+++ b/app/controllers/AccountController.php@@ -219,10 +219,11 @@ class AccountController extends BaseController/*** @param Account $account+ * @param string $view** @return $this*/- public function show(Account $account)+ public function show(Account $account, $view = 'session'){switch ($account->accountType->type) {case 'Asset account':@@ -241,16 +242,19 @@ class AccountController extends BaseController// get a paginated view of all transactions for this account:/** @var \FireflyIII\Database\Account $acct */$acct = App::make('FireflyIII\Database\Account');- if (Input::get('showAll') == 'true') {+ switch ($view) {+ default:+ case 'session':+ $journals = $acct->getTransactionJournals($account, 50);+ break;+ case 'all':+ $journals = $acct->getAllTransactionJournals($account, 50);- $journals = $acct->getAllTransactionJournals($account, 50);- } else {- $journals = $acct->getTransactionJournals($account, 50);+ break;}- //$data = $this->_accounts->show($account, 40);- return View::make('accounts.show', compact('account', 'subTitleIcon', 'journals'))->with('account', $account)->with(+ return View::make('accounts.show', compact('account', 'view', 'subTitleIcon', 'journals'))->with('account', $account)->with('subTitle', 'Details for ' . strtolower($account->accountType->type) . ' "' . $account->name . '"');}diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.phpindex 700b29f575..bb71c4f7cd 100644--- a/app/controllers/GoogleChartController.php+++ b/app/controllers/GoogleChartController.php@@ -10,18 +10,39 @@ class GoogleChartController extends BaseController/*** @param Account $account*/- public function accountBalanceChart(Account $account)+ public function accountBalanceChart(Account $account, $view = 'session'){/** @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');+ switch ($view) {+ default:+ case 'session':+ $start = Session::get('start');+ $end = Session::get('end');+ break;+ case 'all':+ $first = $account->transactionjournals()->orderBy('date', 'DESC')->first();+ $last = $account->transactionjournals()->orderBy('date', 'ASC')->first();+ if (is_null($first)) {+ $start = Session::get('start');+ } else {+ $start = clone $first->date;+ }+ if (is_null($last)) {+ $end = Session::get('end');+ } else {+ $end = clone $last->date;+ }+ break;+ }+$current = clone $start;while ($end >= $current) {@@ -47,7 +68,7 @@ class GoogleChartController extends BaseController** @return \Illuminate\Http\JsonResponse*/- public function accountSankeyInChart(Account $account)+ public function accountSankeyInChart(Account $account, $view = 'session'){// collect all relevant entries.$set = [];@@ -58,13 +79,34 @@ class GoogleChartController extends BaseController$chart->addColumn('To', 'string', 'domain');$chart->addColumn('Weight', 'number');+ switch ($view) {+ default:+ case 'session':+ $start = Session::get('start');+ $end = Session::get('end');+ break;+ case 'all':+ $first = $account->transactionjournals()->orderBy('date', 'DESC')->first();+ $last = $account->transactionjournals()->orderBy('date', 'ASC')->first();+ if (is_null($first)) {+ $start = Session::get('start');+ } else {+ $start = clone $first->date;+ }+ if (is_null($last)) {+ $end = Session::get('end');+ } else {+ $end = clone $last->date;+ }+ break;+ }++$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();+ )->before($end)->after($start)->get();/** @var Transaction $transaction */foreach ($transactions as $transaction) {@@ -106,7 +148,7 @@ class GoogleChartController extends BaseController** @return \Illuminate\Http\JsonResponse*/- public function accountSankeyOutChart(Account $account)+ public function accountSankeyOutChart(Account $account, $view = 'session'){// collect all relevant entries.$set = [];diff --git a/app/routes.php b/app/routes.phpindex 4f0d2a3154..3c10a8f1a5 100644--- a/app/routes.php+++ b/app/routes.php@@ -141,7 +141,8 @@ Route::group(Route::get('/accounts/create/{what}', ['uses' => 'AccountController@create', 'as' => 'accounts.create'])->where('what', 'revenue|asset|expense');Route::get('/accounts/edit/{account}', ['uses' => 'AccountController@edit', 'as' => 'accounts.edit']);Route::get('/accounts/delete/{account}', ['uses' => 'AccountController@delete', 'as' => 'accounts.delete']);- Route::get('/accounts/show/{account}', ['uses' => 'AccountController@show', 'as' => 'accounts.show']);+ Route::get('/accounts/show/{account}/{view?}', ['uses' => 'AccountController@show', 'as' => 'accounts.show']);+// budget controller:Route::get('/budgets', ['uses' => 'BudgetController@index', 'as' => 'budgets.index']);@@ -163,9 +164,9 @@ Route::group(Route::get('/chart/home/budgets', ['uses' => 'GoogleChartController@allBudgetsHomeChart']);Route::get('/chart/home/categories', ['uses' => 'GoogleChartController@allCategoriesHomeChart']);Route::get('/chart/home/recurring', ['uses' => 'GoogleChartController@recurringTransactionsOverview']);- Route::get('/chart/account/{account}', ['uses' => 'GoogleChartController@accountBalanceChart']);- Route::get('/chart/sankey/{account}/out', ['uses' => 'GoogleChartController@accountSankeyOutChart']);- Route::get('/chart/sankey/{account}/in', ['uses' => 'GoogleChartController@accountSankeyInChart']);+ Route::get('/chart/account/{account}/{view?}', ['uses' => 'GoogleChartController@accountBalanceChart']);+ Route::get('/chart/sankey/{account}/out/{view?}', ['uses' => 'GoogleChartController@accountSankeyOutChart']);+ Route::get('/chart/sankey/{account}/in/{view?}', ['uses' => 'GoogleChartController@accountSankeyInChart']);Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']);Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);Route::get('/chart/recurring/{recurring}', ['uses' => 'GoogleChartController@recurringOverview']);diff --git a/app/views/accounts/show.blade.php b/app/views/accounts/show.blade.phpindex dad1b61fcc..8fb7e70507 100644--- a/app/views/accounts/show.blade.php+++ b/app/views/accounts/show.blade.php@@ -21,10 +21,10 @@<div class="panel-body"><p><!-- TODO clean up these methods and everything associated with them. -->- @if(Input::get('showAll') == 'true')- <a href="{{route('accounts.show',$account->id)}}" class="btn btn-default">Stick to date-range</a>+ @if($view == 'all')+ <a href="{{route('accounts.show',$account->id)}}/session" class="btn btn-default">Stick to date-range</a>@else- <a href="{{route('accounts.show',$account->id)}}?showAll=true" class="btn btn-default">Show all transactions</a>+ <a href="{{route('accounts.show',$account->id)}}/all" class="btn btn-default">Show all transactions</a>@endif</p></div>@@ -74,6 +74,7 @@@section('scripts')<script type="text/javascript">var accountID = {{{$account->id}}};+ var view = '{{{$view}}}';</script><!-- load the libraries and scripts necessary for Google Charts: --><script type="text/javascript" src="https://www.google.com/jsapi"></script>diff --git a/public/assets/javascript/firefly/accounts.js b/public/assets/javascript/firefly/accounts.jsindex 31882b5442..0a3ec71d4a 100644--- a/public/assets/javascript/firefly/accounts.js+++ b/public/assets/javascript/firefly/accounts.js@@ -1,12 +1,12 @@$(function () {- if (typeof(googleLineChart) == "function" && typeof accountID != 'undefined') {- googleLineChart('chart/account/' + accountID, 'overview-chart');+ if (typeof(googleLineChart) == "function" && typeof accountID != 'undefined' && typeof view != 'undefined') {+ googleLineChart('chart/account/' + accountID + '/' + view, 'overview-chart');}//- if (typeof(googleSankeyChart) == 'function' && typeof accountID != 'undefined') {- googleSankeyChart('chart/sankey/' + accountID + '/out', 'account-out-sankey');- googleSankeyChart('chart/sankey/' + accountID + '/in', 'account-in-sankey');+ if (typeof(googleSankeyChart) == 'function' && typeof accountID != 'undefined' && typeof view != 'undefined') {+ googleSankeyChart('chart/sankey/' + accountID + '/out' + '/' + view, 'account-out-sankey');+ googleSankeyChart('chart/sankey/' + accountID + '/in' + '/' + view, 'account-in-sankey');}});\ No newline at end of file