mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Clean up some urls
This commit is contained in:
@@ -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);
|
||||
|
@@ -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'
|
||||
)
|
||||
);
|
||||
|
||||
|
94
app/Http/Requests/ReportFormRequest.php
Normal file
94
app/Http/Requests/ReportFormRequest.php
Normal 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';
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -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) {
|
||||
@@ -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']
|
||||
|
Reference in New Issue
Block a user