Fix the view for accounts.

This commit is contained in:
James Cole
2014-11-28 07:40:04 +01:00
parent 935276af88
commit 5a920d5efd
5 changed files with 75 additions and 27 deletions

View File

@@ -219,10 +219,11 @@ class AccountController extends BaseController
/** /**
* @param Account $account * @param Account $account
* @param string $view
* *
* @return $this * @return $this
*/ */
public function show(Account $account) public function show(Account $account, $view = 'session')
{ {
switch ($account->accountType->type) { switch ($account->accountType->type) {
case 'Asset account': case 'Asset account':
@@ -241,16 +242,19 @@ class AccountController extends BaseController
// get a paginated view of all transactions for this account: // get a paginated view of all transactions for this account:
/** @var \FireflyIII\Database\Account $acct */ /** @var \FireflyIII\Database\Account $acct */
$acct = App::make('FireflyIII\Database\Account'); $acct = App::make('FireflyIII\Database\Account');
if (Input::get('showAll') == 'true') { switch ($view) {
default:
$journals = $acct->getAllTransactionJournals($account, 50); case 'session':
} else {
$journals = $acct->getTransactionJournals($account, 50); $journals = $acct->getTransactionJournals($account, 50);
break;
case 'all':
$journals = $acct->getAllTransactionJournals($account, 50);
break;
} }
//$data = $this->_accounts->show($account, 40); return View::make('accounts.show', compact('account', 'view', 'subTitleIcon', 'journals'))->with('account', $account)->with(
return View::make('accounts.show', compact('account', 'subTitleIcon', 'journals'))->with('account', $account)->with(
'subTitle', 'Details for ' . strtolower($account->accountType->type) . ' "' . $account->name . '"' 'subTitle', 'Details for ' . strtolower($account->accountType->type) . ' "' . $account->name . '"'
); );
} }

View File

@@ -10,18 +10,39 @@ class GoogleChartController extends BaseController
/** /**
* @param Account $account * @param Account $account
*/ */
public function accountBalanceChart(Account $account) public function accountBalanceChart(Account $account, $view = 'session')
{ {
/** @var \Grumpydictator\Gchart\GChart $chart */ /** @var \Grumpydictator\Gchart\GChart $chart */
$chart = App::make('gchart'); $chart = App::make('gchart');
$chart->addColumn('Day of month', 'date'); $chart->addColumn('Day of month', 'date');
$chart->addColumn('Balance for ' . $account->name, 'number'); $chart->addColumn('Balance for ' . $account->name, 'number');
/* /*
* Loop the date, then loop the accounts, then add balance. * Loop the date, then loop the accounts, then add balance.
*/ */
switch ($view) {
default:
case 'session':
$start = Session::get('start'); $start = Session::get('start');
$end = Session::get('end'); $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; $current = clone $start;
while ($end >= $current) { while ($end >= $current) {
@@ -47,7 +68,7 @@ class GoogleChartController extends BaseController
* *
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function accountSankeyInChart(Account $account) public function accountSankeyInChart(Account $account, $view = 'session')
{ {
// collect all relevant entries. // collect all relevant entries.
$set = []; $set = [];
@@ -58,13 +79,34 @@ class GoogleChartController extends BaseController
$chart->addColumn('To', 'string', 'domain'); $chart->addColumn('To', 'string', 'domain');
$chart->addColumn('Weight', 'number'); $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( $transactions = $account->transactions()->with(
['transactionjournal', 'transactionjournal.transactions' => function ($q) { ['transactionjournal', 'transactionjournal.transactions' => function ($q) {
$q->where('amount', '<', 0); $q->where('amount', '<', 0);
}, 'transactionjournal.budgets', 'transactionjournal.transactiontype', 'transactionjournal.categories'] }, 'transactionjournal.budgets', 'transactionjournal.transactiontype', 'transactionjournal.categories']
)->before(Session::get('end'))->after( )->before($end)->after($start)->get();
Session::get('start')
)->get();
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($transactions as $transaction) { foreach ($transactions as $transaction) {
@@ -106,7 +148,7 @@ class GoogleChartController extends BaseController
* *
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function accountSankeyOutChart(Account $account) public function accountSankeyOutChart(Account $account, $view = 'session')
{ {
// collect all relevant entries. // collect all relevant entries.
$set = []; $set = [];

View File

@@ -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/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/edit/{account}', ['uses' => 'AccountController@edit', 'as' => 'accounts.edit']);
Route::get('/accounts/delete/{account}', ['uses' => 'AccountController@delete', 'as' => 'accounts.delete']); 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: // budget controller:
Route::get('/budgets', ['uses' => 'BudgetController@index', 'as' => 'budgets.index']); 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/budgets', ['uses' => 'GoogleChartController@allBudgetsHomeChart']);
Route::get('/chart/home/categories', ['uses' => 'GoogleChartController@allCategoriesHomeChart']); Route::get('/chart/home/categories', ['uses' => 'GoogleChartController@allCategoriesHomeChart']);
Route::get('/chart/home/recurring', ['uses' => 'GoogleChartController@recurringTransactionsOverview']); Route::get('/chart/home/recurring', ['uses' => 'GoogleChartController@recurringTransactionsOverview']);
Route::get('/chart/account/{account}', ['uses' => 'GoogleChartController@accountBalanceChart']); Route::get('/chart/account/{account}/{view?}', ['uses' => 'GoogleChartController@accountBalanceChart']);
Route::get('/chart/sankey/{account}/out', ['uses' => 'GoogleChartController@accountSankeyOutChart']); Route::get('/chart/sankey/{account}/out/{view?}', ['uses' => 'GoogleChartController@accountSankeyOutChart']);
Route::get('/chart/sankey/{account}/in', ['uses' => 'GoogleChartController@accountSankeyInChart']); 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/{year}', ['uses' => 'GoogleChartController@yearInExp']);
Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']); Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
Route::get('/chart/recurring/{recurring}', ['uses' => 'GoogleChartController@recurringOverview']); Route::get('/chart/recurring/{recurring}', ['uses' => 'GoogleChartController@recurringOverview']);

View File

@@ -21,10 +21,10 @@
<div class="panel-body"> <div class="panel-body">
<p> <p>
<!-- TODO clean up these methods and everything associated with them. --> <!-- TODO clean up these methods and everything associated with them. -->
@if(Input::get('showAll') == 'true') @if($view == 'all')
<a href="{{route('accounts.show',$account->id)}}" class="btn btn-default">Stick to date-range</a> <a href="{{route('accounts.show',$account->id)}}/session" class="btn btn-default">Stick to date-range</a>
@else @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 @endif
</p> </p>
</div> </div>
@@ -74,6 +74,7 @@
@section('scripts') @section('scripts')
<script type="text/javascript"> <script type="text/javascript">
var accountID = {{{$account->id}}}; var accountID = {{{$account->id}}};
var view = '{{{$view}}}';
</script> </script>
<!-- load the libraries and scripts necessary for Google Charts: --> <!-- load the libraries and scripts necessary for Google Charts: -->
<script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript" src="https://www.google.com/jsapi"></script>

View File

@@ -1,12 +1,12 @@
$(function () { $(function () {
if (typeof(googleLineChart) == "function" && typeof accountID != 'undefined') { if (typeof(googleLineChart) == "function" && typeof accountID != 'undefined' && typeof view != 'undefined') {
googleLineChart('chart/account/' + accountID, 'overview-chart'); googleLineChart('chart/account/' + accountID + '/' + view, 'overview-chart');
} }
// //
if (typeof(googleSankeyChart) == 'function' && typeof accountID != 'undefined') { if (typeof(googleSankeyChart) == 'function' && typeof accountID != 'undefined' && typeof view != 'undefined') {
googleSankeyChart('chart/sankey/' + accountID + '/out', 'account-out-sankey'); googleSankeyChart('chart/sankey/' + accountID + '/out' + '/' + view, 'account-out-sankey');
googleSankeyChart('chart/sankey/' + accountID + '/in', 'account-in-sankey'); googleSankeyChart('chart/sankey/' + accountID + '/in' + '/' + view, 'account-in-sankey');
} }
}); });