diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 28d26f07ff..a7df17912f 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -90,32 +90,8 @@ class AccountController extends Controller * * @return \Symfony\Component\HttpFoundation\Response */ - public function report(AccountRepositoryInterface $repository, $url) + public function report($report_type, Carbon $start, Carbon $end, Collection $accounts) { - $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); @@ -123,13 +99,13 @@ class AccountController extends Controller $cache->addProperty('all'); $cache->addProperty('accounts'); $cache->addProperty('default'); - $cache->addProperty($list); + $cache->addProperty($accounts); if ($cache->has()) { return Response::json($cache->get()); // @codeCoverageIgnore } // make chart: - $data = $this->generator->all($list, $start, $end); + $data = $this->generator->all($accounts, $start, $end); $cache->store($data); return Response::json($data); diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 070ee7d75a..a1b577e982 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -1,14 +1,11 @@ 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); - } - } - - // some fields: + // some fields for translation: $subTitle = trans('firefly.reportForMonth', ['month' => $start->formatLocalized($this->monthFormat)]); $subTitleIcon = 'fa-calendar'; $incomeTopLength = 8; $expenseTopLength = 8; // get report stuff! - $accounts = $this->helper->getAccountReportForList($start, $end, $list); - $incomes = $this->helper->getIncomeReportForList($start, $end, $list); - $expenses = $this->helper->getExpenseReportForList($start, $end, $list); - $budgets = $this->helper->getBudgetReportForList($start, $end, $list); - $categories = $this->helper->getCategoryReportForList($start, $end, $list); - $balance = $this->helper->getBalanceReportForList($start, $end, $list); - $bills = $this->helper->getBillReportForList($start, $end, $list); + $accountReport = $this->helper->getAccountReportForList($start, $end, $accounts); + $incomes = $this->helper->getIncomeReportForList($start, $end, $accounts); + $expenses = $this->helper->getExpenseReportForList($start, $end, $accounts); + $budgets = $this->helper->getBudgetReportForList($start, $end, $accounts); + $categories = $this->helper->getCategoryReportForList($start, $end, $accounts); + $balance = $this->helper->getBalanceReportForList($start, $end, $accounts); + $bills = $this->helper->getBillReportForList($start, $end, $accounts); + + // and some id's, joined: + $accountIds = []; + /** @var Account $account */ + foreach ($accounts as $account) { + $accountIds[] = $account->id; + } + $accountIds = join(';', $accountIds); // continue! return view( 'reports.default', compact( - 'start', + 'start', 'end', 'report_type', 'subTitle', 'subTitleIcon', - 'accounts', + 'accountReport', 'incomes', 'incomeTopLength', 'expenses', 'expenseTopLength', - 'budgets', 'balance','url', + 'budgets', 'balance', 'categories', - 'bills' + 'bills', + 'accountIds', 'report_type' ) ); diff --git a/app/Http/Requests/ReportFormRequest.php b/app/Http/Requests/ReportFormRequest.php new file mode 100644 index 0000000000..146256d309 --- /dev/null +++ b/app/Http/Requests/ReportFormRequest.php @@ -0,0 +1,94 @@ +URL = $this->route()->parameter('url'); + + /** @var \FireflyIII\Repositories\Account\AccountRepositoryInterface $repository */ + $repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface'); + + // split: + $parts = explode(';', $this->URL); + + // try to make a date out of parts 1 and 2: + try { + $this->startDate = new Carbon($parts[1]); + $this->endDate = 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 ($this->endDate < $this->startDate) { + abort(404); + } + + // get the accounts: + $count = count($parts); + $list = new Collection(); + for ($i = 3; $i < $count; $i++) { + $account = $repository->find($parts[$i]); + if ($account) { + $list->push($account); + } + } + $this->accounts = $list; + + return []; + } + + /** + * @return string + */ + public function getSomething() + { + return 'Hoi'; + } + + +} diff --git a/app/Http/routes.php b/app/Http/routes.php index 30cd984781..82ae0a8b01 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -1,4 +1,5 @@ where('account_types.editable', 1) + ->whereIn('accounts.id', $ids) + ->where('user_id', Auth::user()->id) + ->get(['accounts.*']); + if ($object->count() > 0) { + return $object; + } + } + throw new NotFoundHttpException; + } +); + +// Date +Route::bind( + 'start_date', + function ($value) { + if (Auth::check()) { + + try { + $date = new Carbon($value); + } catch (Exception $e) { + Log::error('Could not parse date "' . $value . '" for user #' . Auth::user()->id); + throw new NotFoundHttpException; + } + + return $date; + } + throw new NotFoundHttpException; + } +); + +// Date +Route::bind( + 'end_date', + function ($value) { + if (Auth::check()) { + + try { + $date = new Carbon($value); + } catch (Exception $e) { + Log::error('Could not parse date "' . $value . '" for user #' . Auth::user()->id); + throw new NotFoundHttpException; + } + + return $date; + } + throw new NotFoundHttpException; + } +); Route::bind( 'tj', function ($value) { @@ -162,7 +220,7 @@ Route::get('/cron/sendgrid', ['uses' => 'CronController@sendgrid']); Route::controllers( [ - 'auth' => 'Auth\AuthController', + 'auth' => 'Auth\AuthController', 'password' => 'Auth\PasswordController', ] ); @@ -284,8 +342,10 @@ 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/report/{url}', ['uses' => 'Chart\AccountController@report']); + 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/{report_type}/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\AccountController@report']); Route::get('/chart/account/{account}', ['uses' => 'Chart\AccountController@single']); @@ -302,7 +362,7 @@ Route::group( // categories: Route::get('/chart/category/frontpage', ['uses' => 'Chart\CategoryController@frontpage']); Route::get('/chart/category/spent-in-year/{year}/{shared?}', ['uses' => 'Chart\CategoryController@spentInYear'])->where( -['year' => '[0-9]{4}', 'shared' => 'shared'] + ['year' => '[0-9]{4}', 'shared' => 'shared'] ); Route::get('/chart/category/earned-in-year/{year}/{shared?}', ['uses' => 'Chart\CategoryController@earnedInYear'])->where( ['year' => '[0-9]{4}', 'shared' => 'shared'] @@ -385,7 +445,7 @@ Route::group( */ Route::get('/reports', ['uses' => 'ReportController@index', 'as' => 'reports.index']); Route::post('/reports/select', ['uses' => 'ReportController@select', 'as' => 'reports.select']); - Route::get('/reports/report/{url}', ['uses' => 'ReportController@report', 'as' => 'reports.report']); + Route::get('/reports/report/{report_type}/{start_date}/{end_date}/{accountList}', ['uses' => 'ReportController@report', 'as' => 'reports.report']); Route::get('/reports/{year}/{shared?}', ['uses' => 'ReportController@year', 'as' => 'reports.year'])->where(['year' => '[0-9]{4}', 'shared' => 'shared']); Route::get('/reports/{year}/{month}/{shared?}', ['uses' => 'ReportController@month', 'as' => 'reports.month'])->where( ['year' => '[0-9]{4}', 'month' => '[0-9]{1,2}', 'shared' => 'shared'] diff --git a/public/js/reports.js b/public/js/reports.js index 2264414386..4552f56dcd 100644 --- a/public/js/reports.js +++ b/public/js/reports.js @@ -1,4 +1,4 @@ -/* globals google,reportURL, picker:true, minDate, expenseRestShow:true, incomeRestShow:true, year, shared, month, hideTheRest, showTheRest, showTheRestExpense, hideTheRestExpense, columnChart, lineChart, stackedColumnChart */ +/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, expenseRestShow:true, incomeRestShow:true, year, month, hideTheRest, showTheRest, showTheRestExpense, hideTheRestExpense, columnChart, lineChart, stackedColumnChart */ $(function () { @@ -50,7 +50,6 @@ $(function () { $('#report-form').on('submit', catchSubmit); - // click open the top X income list: $('#showIncomes').click(showIncomes); // click open the top X expense list: @@ -61,12 +60,12 @@ function catchSubmit() { "use strict"; // default;20141201;20141231;4;5 // report name: - var url = '' + $('select[name="report_type"]').val() + ';'; + var url = '' + $('select[name="report_type"]').val() + '/'; // date, processed: var picker = $('#inputDateRange').data('daterangepicker'); - url += moment(picker.startDate).format("YYYYMMDD") + ';'; - url += moment(picker.endDate).format("YYYYMMDD"); + url += moment(picker.startDate).format("YYYYMMDD") + '/'; + url += moment(picker.endDate).format("YYYYMMDD") + '/'; // all account ids: var count = 0; @@ -74,7 +73,7 @@ function catchSubmit() { $.each($('.account-checkbox'), function (i, v) { var c = $(v); if (c.prop('checked')) { - url += ';' + c.val(); + url += c.val() + ';'; accounts.push(c.val()); count++; } @@ -105,21 +104,23 @@ function preSelectDate(e) { function drawChart() { "use strict"; - if (typeof columnChart !== 'undefined' && typeof year !== 'undefined' && typeof month === 'undefined') { - columnChart('chart/report/in-out/' + year + shared, 'income-expenses-chart'); - columnChart('chart/report/in-out-sum/' + year + shared, 'income-expenses-sum-chart'); - } - if (typeof stackedColumnChart !== 'undefined' && typeof year !== 'undefined' && typeof month === 'undefined') { - stackedColumnChart('chart/budget/year/' + year + shared, 'budgets'); - 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' && typeof reportURL === 'undefined') { - lineChart('/chart/account/month/' + year + '/' + month + shared, 'account-balances-chart'); - } - if (typeof lineChart !== 'undefined' && typeof reportURL !== 'undefined') { + //if (typeof columnChart !== 'undefined' && typeof year !== 'undefined' && typeof month === 'undefined') { + // columnChart('chart/report/in-out/' + year + shared, 'income-expenses-chart'); + // columnChart('chart/report/in-out-sum/' + year + shared, 'income-expenses-sum-chart'); + //} + //if (typeof stackedColumnChart !== 'undefined' && typeof year !== 'undefined' && typeof month === 'undefined') { + // stackedColumnChart('chart/budget/year/' + year + shared, 'budgets'); + // 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' && typeof reportURL === 'undefined') { + // lineChart('/chart/account/month/' + year + '/' + month + shared, 'account-balances-chart'); + //} + + if (typeof lineChart !== 'undefined' && typeof accountIds !== 'undefined') { //http://firefly.app/chart/account/report/default;20151101;20151130;2 - lineChart('/chart/account/report/' + reportURL, 'account-balances-chart'); + lineChart('/chart/account/report/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'account-balances-chart'); } } diff --git a/resources/twig/partials/reports/accounts.twig b/resources/twig/partials/reports/accounts.twig index 89c051d859..b0d4782a24 100644 --- a/resources/twig/partials/reports/accounts.twig +++ b/resources/twig/partials/reports/accounts.twig @@ -13,7 +13,7 @@ - {% for account in accounts.getAccounts %} + {% for account in accountReport.getAccounts %} {{ account.name }} @@ -27,9 +27,9 @@ {{ 'sumOfSums'|_ }} - {{ accounts.getStart|formatAmount }} - {{ accounts.getEnd|formatAmount }} - {{ accounts.getDifference|formatAmount }} + {{ accountReport.getStart|formatAmount }} + {{ accountReport.getEnd|formatAmount }} + {{ accountReport.getDifference|formatAmount }} diff --git a/resources/twig/reports/default.twig b/resources/twig/reports/default.twig index 58934f9031..d2347b4391 100644 --- a/resources/twig/reports/default.twig +++ b/resources/twig/reports/default.twig @@ -84,10 +84,14 @@