Fix the report chart.

This commit is contained in:
James Cole
2015-12-12 10:41:51 +01:00
parent 9284eb3fe9
commit 6426d1df06
5 changed files with 66 additions and 6 deletions

View File

@@ -79,6 +79,62 @@ class AccountController extends Controller
return Response::json($data); return Response::json($data);
} }
/**
* Shows the balances for a given set of dates and accounts.
*
* TODO fix parameters.
*
* @param AccountRepositoryInterface $repository
*
* @param $url
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function report(AccountRepositoryInterface $repository, $url)
{
$parts = explode(';', $url);
// try to make a date out of parts 1 and 2:
try {
$start = new Carbon($parts[1]);
$end = new Carbon($parts[2]);
} catch (Exception $e) {
Log::error('Could not parse date "' . $parts[1] . '" or "' . $parts[2] . '" for user #' . Auth::user()->id);
abort(404);
}
if ($end < $start) {
abort(404);
}
// accounts:
$c = count($parts);
$list = new Collection();
for ($i = 3; $i < $c; $i++) {
$account = $repository->find($parts[$i]);
if ($account) {
$list->push($account);
}
}
// chart properties for cache:
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('all');
$cache->addProperty('accounts');
$cache->addProperty('default');
$cache->addProperty($list);
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
// make chart:
$data = $this->generator->all($list, $start, $end);
$cache->store($data);
return Response::json($data);
}
/** /**
* Shows the balances for all the user's expense accounts. * Shows the balances for all the user's expense accounts.
* *

View File

@@ -258,7 +258,7 @@ class ReportController extends Controller
'accounts', 'accounts',
'incomes', 'incomeTopLength', 'incomes', 'incomeTopLength',
'expenses', 'expenseTopLength', 'expenses', 'expenseTopLength',
'budgets', 'balance', 'budgets', 'balance','url',
'categories', 'categories',
'bills' 'bills'
) )

View File

@@ -284,9 +284,8 @@ Route::group(
// accounts: // accounts:
Route::get('/chart/account/frontpage', ['uses' => 'Chart\AccountController@frontpage']); Route::get('/chart/account/frontpage', ['uses' => 'Chart\AccountController@frontpage']);
Route::get('/chart/account/expense', ['uses' => 'Chart\AccountController@expenseAccounts']); Route::get('/chart/account/expense', ['uses' => 'Chart\AccountController@expenseAccounts']);
Route::get('/chart/account/month/{year}/{month}/{shared?}', ['uses' => 'Chart\AccountController@all'])->where( Route::get('/chart/account/month/{year}/{month}/{shared?}', ['uses' => 'Chart\AccountController@all'])->where(['year' => '[0-9]{4}', 'month' => '[0-9]{1,2}', 'shared' => 'shared']);
['year' => '[0-9]{4}', 'month' => '[0-9]{1,2}', 'shared' => 'shared'] Route::get('/chart/account/report/{url}', ['uses' => 'Chart\AccountController@report']);
);
Route::get('/chart/account/{account}', ['uses' => 'Chart\AccountController@single']); Route::get('/chart/account/{account}', ['uses' => 'Chart\AccountController@single']);

View File

@@ -1,4 +1,4 @@
/* globals google, picker:true, minDate, expenseRestShow:true, incomeRestShow:true, year, shared, month, hideTheRest, showTheRest, showTheRestExpense, hideTheRestExpense, columnChart, lineChart, stackedColumnChart */ /* globals google,reportURL, picker:true, minDate, expenseRestShow:true, incomeRestShow:true, year, shared, month, hideTheRest, showTheRest, showTheRestExpense, hideTheRestExpense, columnChart, lineChart, stackedColumnChart */
$(function () { $(function () {
@@ -114,9 +114,13 @@ function drawChart() {
stackedColumnChart('chart/category/spent-in-year/' + year + shared, 'categories-spent-in-year'); stackedColumnChart('chart/category/spent-in-year/' + year + shared, 'categories-spent-in-year');
stackedColumnChart('chart/category/earned-in-year/' + year + shared, 'categories-earned-in-year'); stackedColumnChart('chart/category/earned-in-year/' + year + shared, 'categories-earned-in-year');
} }
if (typeof lineChart !== 'undefined' && typeof month !== 'undefined') { if (typeof lineChart !== 'undefined' && typeof month !== 'undefined' && typeof reportURL === 'undefined') {
lineChart('/chart/account/month/' + year + '/' + month + shared, 'account-balances-chart'); lineChart('/chart/account/month/' + year + '/' + month + shared, 'account-balances-chart');
} }
if (typeof lineChart !== 'undefined' && typeof reportURL !== 'undefined') {
//http://firefly.app/chart/account/report/default;20151101;20151130;2
lineChart('/chart/account/report/' + reportURL, 'account-balances-chart');
}
} }

View File

@@ -84,6 +84,7 @@
<script type="text/javascript"> <script type="text/javascript">
var year = {{ start.year }}; var year = {{ start.year }};
var reportURL = "{{ url }}";
var month = {{ start.month }}; var month = {{ start.month }};
var shared = {% if shared %}'/shared' var shared = {% if shared %}'/shared'
{% else %}''{% endif %}; {% else %}''{% endif %};