diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 116e2c00aa..28d26f07ff 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -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. * diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 1210e5d45d..070ee7d75a 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -258,7 +258,7 @@ class ReportController extends Controller 'accounts', 'incomes', 'incomeTopLength', 'expenses', 'expenseTopLength', - 'budgets', 'balance', + 'budgets', 'balance','url', 'categories', 'bills' ) diff --git a/app/Http/routes.php b/app/Http/routes.php index 4920086e13..30cd984781 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -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']); diff --git a/public/js/reports.js b/public/js/reports.js index 0ff3f6ffba..2264414386 100644 --- a/public/js/reports.js +++ b/public/js/reports.js @@ -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'); + } } diff --git a/resources/twig/reports/default.twig b/resources/twig/reports/default.twig index 0b9111669b..58934f9031 100644 --- a/resources/twig/reports/default.twig +++ b/resources/twig/reports/default.twig @@ -84,6 +84,7 @@