mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix the report chart.
This commit is contained in:
parent
9284eb3fe9
commit
6426d1df06
@ -79,6 +79,62 @@ class AccountController extends Controller
|
||||
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.
|
||||
*
|
||||
|
@ -258,7 +258,7 @@ class ReportController extends Controller
|
||||
'accounts',
|
||||
'incomes', 'incomeTopLength',
|
||||
'expenses', 'expenseTopLength',
|
||||
'budgets', 'balance',
|
||||
'budgets', 'balance','url',
|
||||
'categories',
|
||||
'bills'
|
||||
)
|
||||
|
@ -284,9 +284,8 @@ Route::group(
|
||||
// accounts:
|
||||
Route::get('/chart/account/frontpage', ['uses' => 'Chart\AccountController@frontpage']);
|
||||
Route::get('/chart/account/expense', ['uses' => 'Chart\AccountController@expenseAccounts']);
|
||||
Route::get('/chart/account/month/{year}/{month}/{shared?}', ['uses' => 'Chart\AccountController@all'])->where(
|
||||
['year' => '[0-9]{4}', 'month' => '[0-9]{1,2}', 'shared' => 'shared']
|
||||
);
|
||||
Route::get('/chart/account/month/{year}/{month}/{shared?}', ['uses' => 'Chart\AccountController@all'])->where(['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']);
|
||||
|
||||
|
||||
|
@ -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 () {
|
||||
@ -114,9 +114,13 @@ function drawChart() {
|
||||
stackedColumnChart('chart/category/spent-in-year/' + year + shared, 'categories-spent-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');
|
||||
}
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -84,6 +84,7 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
var year = {{ start.year }};
|
||||
var reportURL = "{{ url }}";
|
||||
var month = {{ start.month }};
|
||||
var shared = {% if shared %}'/shared'
|
||||
{% else %}''{% endif %};
|
||||
|
Loading…
Reference in New Issue
Block a user