Clean up some urls

This commit is contained in:
James Cole 2015-12-12 17:51:07 +01:00
parent 1423d5b314
commit 59bc5d22d1
7 changed files with 222 additions and 100 deletions

View File

@ -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);

View File

@ -1,14 +1,11 @@
<?php namespace FireflyIII\Http\Controllers;
use Auth;
use Carbon\Carbon;
use Exception;
use FireflyIII\Helpers\Report\ReportHelperInterface;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Input;
use Log;
use Redirect;
use Session;
use View;
@ -206,61 +203,51 @@ class ReportController extends Controller
}
/**
* @param $url
* @param $report_type
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return View
*/
public function report($url, AccountRepositoryInterface $repository)
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);
}
}
// 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'
)
);

View File

@ -0,0 +1,94 @@
<?php
namespace FireflyIII\Http\Requests;
use Auth;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\Collection;
use Log;
/**
* Class AccountFormRequest
*
* @codeCoverageIgnore
* @package FireflyIII\Http\Requests
*/
class ReportFormRequest extends Request
{
/** @var Carbon */
public $startDate;
/** @var Carbon */
public $endDate;
/** @var Collection */
public $accounts;
/** @var string */
public $reportType;
/** @var string */
public $URL;
/**
* @return bool
*/
public function authorize()
{
// Only allow logged in users
return Auth::check();
}
/**
* This probably really isn't the best way to do this but I have no idea what Laravel
* thought up to do this. Oh well, let's just see what happens.
* @return array
*/
public function rules()
{
// URL:
$this->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';
}
}

View File

@ -1,4 +1,5 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\Attachment;
use FireflyIII\Models\Bill;
@ -29,6 +30,63 @@ Route::bind(
throw new NotFoundHttpException;
}
);
// account list! Yay!
Route::bind(
'accountList',
function ($value) {
if (Auth::check()) {
$ids = explode(';', $value);
/** @var \Illuminate\Support\Collection $object */
$object = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->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) {
@ -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']);
@ -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']

View File

@ -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');
}
}

View File

@ -13,7 +13,7 @@
</tr>
</thead>
<tbody>
{% for account in accounts.getAccounts %}
{% for account in accountReport.getAccounts %}
<tr>
<td>
<a href="{{ route('accounts.show',account.id) }}" title="{{ account.name }}">{{ account.name }}</a>
@ -27,9 +27,9 @@
<tfoot>
<tr>
<td><em>{{ 'sumOfSums'|_ }}</em></td>
<td>{{ accounts.getStart|formatAmount }}</td>
<td>{{ accounts.getEnd|formatAmount }}</td>
<td>{{ accounts.getDifference|formatAmount }}</td>
<td>{{ accountReport.getStart|formatAmount }}</td>
<td>{{ accountReport.getEnd|formatAmount }}</td>
<td>{{ accountReport.getDifference|formatAmount }}</td>
</tr>
</tfoot>
</table>

View File

@ -84,10 +84,14 @@
<script type="text/javascript">
var year = {{ start.year }};
var reportURL = "{{ url }}";
var month = {{ start.month }};
var shared = {% if shared %}'/shared'
{% else %}''{% endif %};
// to report another URL:
var startDate = '{{ start.format('Ymd') }}';
var endDate = '{{ end.format('Ymd') }}';
var reportType = '{{ report_type }}';
var accountIds = '{{ accountIds }}';
var incomeTopLength = {{ incomeTopLength }};
var expenseTopLength = {{ expenseTopLength }};
var incomeRestShow = false; // starts hidden.