2016-05-20 01:57:45 -05:00
|
|
|
<?php
|
2016-05-20 05:27:31 -05:00
|
|
|
/**
|
|
|
|
* ReportController.php
|
2017-10-21 01:40:00 -05:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-05-20 05:27:31 -05:00
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* This file is part of Firefly III.
|
2016-10-04 23:52:15 -05:00
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-12-17 07:41:58 -06:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-20 05:27:31 -05:00
|
|
|
*/
|
2018-07-08 05:08:53 -05:00
|
|
|
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
|
2017-03-24 09:15:12 -05:00
|
|
|
declare(strict_types=1);
|
2016-05-20 01:57:45 -05:00
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers;
|
2015-02-23 13:25:48 -06:00
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2016-11-09 14:36:54 -06:00
|
|
|
use FireflyIII\Generator\Report\ReportGeneratorFactory;
|
2015-02-23 13:25:48 -06:00
|
|
|
use FireflyIII\Helpers\Report\ReportHelperInterface;
|
2016-11-09 14:36:54 -06:00
|
|
|
use FireflyIII\Http\Requests\ReportFormRequest;
|
2016-05-20 04:02:07 -05:00
|
|
|
use FireflyIII\Models\AccountType;
|
2016-10-10 00:49:39 -05:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2016-12-08 14:50:20 -06:00
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
2018-08-10 11:19:51 -05:00
|
|
|
use FireflyIII\Support\Http\Controllers\RenderPartialViews;
|
2016-11-09 14:36:54 -06:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2015-12-06 06:11:43 -06:00
|
|
|
use Illuminate\Support\Collection;
|
2017-03-24 05:07:38 -05:00
|
|
|
use Log;
|
2015-03-04 13:47:00 -06:00
|
|
|
|
2015-02-23 13:25:48 -06:00
|
|
|
/**
|
2017-11-15 05:25:49 -06:00
|
|
|
* Class ReportController.
|
2018-07-22 01:10:16 -05:00
|
|
|
*
|
2015-02-23 13:25:48 -06:00
|
|
|
*/
|
|
|
|
class ReportController extends Controller
|
|
|
|
{
|
2018-08-10 11:19:51 -05:00
|
|
|
use RenderPartialViews;
|
|
|
|
|
2018-07-22 01:10:16 -05:00
|
|
|
/** @var ReportHelperInterface Helper interface. */
|
2015-03-29 05:25:46 -05:00
|
|
|
protected $helper;
|
|
|
|
|
2018-07-21 01:06:24 -05:00
|
|
|
/** @var BudgetRepositoryInterface The budget repository */
|
2018-01-23 22:17:26 -06:00
|
|
|
private $repository;
|
|
|
|
|
2015-02-23 13:25:48 -06:00
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* ReportController constructor.
|
2015-02-23 13:25:48 -06:00
|
|
|
*/
|
2016-09-16 02:36:08 -05:00
|
|
|
public function __construct()
|
2015-02-23 13:25:48 -06:00
|
|
|
{
|
2015-05-15 15:00:00 -05:00
|
|
|
parent::__construct();
|
2016-01-27 13:45:49 -06:00
|
|
|
|
2016-10-29 00:44:46 -05:00
|
|
|
$this->middleware(
|
|
|
|
function ($request, $next) {
|
2018-07-15 02:38:49 -05:00
|
|
|
app('view')->share('title', (string)trans('firefly.reports'));
|
2017-12-16 12:46:36 -06:00
|
|
|
app('view')->share('mainTitleIcon', 'fa-line-chart');
|
2018-07-14 09:08:34 -05:00
|
|
|
app('view')->share('subTitleIcon', 'fa-calendar');
|
2018-01-23 22:17:26 -06:00
|
|
|
$this->helper = app(ReportHelperInterface::class);
|
|
|
|
$this->repository = app(BudgetRepositoryInterface::class);
|
2016-10-29 00:44:46 -05:00
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
2015-02-23 13:25:48 -06:00
|
|
|
}
|
2019-08-16 14:38:35 -05:00
|
|
|
|
2016-02-04 00:28:39 -06:00
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Show account report.
|
|
|
|
*
|
2016-12-05 23:52:17 -06:00
|
|
|
* @param Collection $accounts
|
2017-12-17 07:06:14 -06:00
|
|
|
* @param Collection $expense
|
2016-11-09 14:36:54 -06:00
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
2016-02-04 00:28:39 -06:00
|
|
|
*
|
2018-07-09 12:24:08 -05:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
|
2017-12-09 14:49:19 -06:00
|
|
|
* @throws \FireflyIII\Exceptions\FireflyException
|
|
|
|
*/
|
2018-07-09 12:24:08 -05:00
|
|
|
public function accountReport(Collection $accounts, Collection $expense, Carbon $start, Carbon $end)
|
2017-12-09 14:49:19 -06:00
|
|
|
{
|
|
|
|
if ($end < $start) {
|
2018-07-15 02:38:49 -05:00
|
|
|
return view('error')->with('message', (string)trans('firefly.end_after_start_date')); // @codeCoverageIgnore
|
2017-12-09 14:49:19 -06:00
|
|
|
}
|
|
|
|
|
2018-01-23 22:17:26 -06:00
|
|
|
$this->repository->cleanupBudgets();
|
2017-12-09 14:49:19 -06:00
|
|
|
|
2018-07-14 09:08:34 -05:00
|
|
|
app('view')->share(
|
2017-12-09 14:49:19 -06:00
|
|
|
'subTitle', trans(
|
2017-12-23 15:07:39 -06:00
|
|
|
'firefly.report_account',
|
2017-12-22 11:32:43 -06:00
|
|
|
['start' => $start->formatLocalized($this->monthFormat), 'end' => $end->formatLocalized($this->monthFormat)]
|
2017-12-16 12:48:31 -06:00
|
|
|
)
|
2017-12-09 14:49:19 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
$generator = ReportGeneratorFactory::reportGenerator('Account', $start, $end);
|
|
|
|
$generator->setAccounts($accounts);
|
|
|
|
$generator->setExpense($expense);
|
|
|
|
|
2018-03-27 12:29:58 -05:00
|
|
|
return $generator->generate();
|
2017-12-09 14:49:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Show audit report.
|
|
|
|
*
|
2017-12-09 14:49:19 -06:00
|
|
|
* @param Collection $accounts
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
2018-07-09 12:24:08 -05:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
|
2017-12-22 11:32:43 -06:00
|
|
|
*
|
2017-12-09 14:49:19 -06:00
|
|
|
* @throws \FireflyIII\Exceptions\FireflyException
|
2016-02-04 00:28:39 -06:00
|
|
|
*/
|
2018-07-09 12:24:08 -05:00
|
|
|
public function auditReport(Collection $accounts, Carbon $start, Carbon $end)
|
2016-02-04 00:28:39 -06:00
|
|
|
{
|
2016-11-09 14:36:54 -06:00
|
|
|
if ($end < $start) {
|
2018-07-15 02:38:49 -05:00
|
|
|
return view('error')->with('message', (string)trans('firefly.end_after_start_date')); // @codeCoverageIgnore
|
2016-11-09 14:36:54 -06:00
|
|
|
}
|
2018-01-23 22:17:26 -06:00
|
|
|
$this->repository->cleanupBudgets();
|
2016-02-04 00:28:39 -06:00
|
|
|
|
2018-07-14 09:08:34 -05:00
|
|
|
app('view')->share(
|
2017-11-15 03:52:29 -06:00
|
|
|
'subTitle',
|
|
|
|
trans(
|
2017-11-15 04:33:07 -06:00
|
|
|
'firefly.report_audit',
|
|
|
|
[
|
2019-09-02 14:21:29 -05:00
|
|
|
'start' => $start->formatLocalized($this->monthAndDayFormat),
|
|
|
|
'end' => $end->formatLocalized($this->monthAndDayFormat),
|
2017-11-15 04:33:07 -06:00
|
|
|
]
|
|
|
|
)
|
2016-11-09 14:36:54 -06:00
|
|
|
);
|
2016-11-09 23:23:21 -06:00
|
|
|
|
2016-11-09 14:36:54 -06:00
|
|
|
$generator = ReportGeneratorFactory::reportGenerator('Audit', $start, $end);
|
|
|
|
$generator->setAccounts($accounts);
|
2016-02-04 00:28:39 -06:00
|
|
|
|
2018-03-27 12:29:58 -05:00
|
|
|
return $generator->generate();
|
2016-11-09 12:25:09 -06:00
|
|
|
}
|
|
|
|
|
2019-08-16 14:38:35 -05:00
|
|
|
|
2016-12-08 14:50:20 -06:00
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Show budget report.
|
|
|
|
*
|
2016-12-08 14:50:20 -06:00
|
|
|
* @param Collection $accounts
|
2016-12-09 00:07:53 -06:00
|
|
|
* @param Collection $budgets
|
2016-12-08 14:50:20 -06:00
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
2018-07-09 12:24:08 -05:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
|
2017-12-22 11:32:43 -06:00
|
|
|
*
|
2017-12-09 14:49:19 -06:00
|
|
|
* @throws \FireflyIII\Exceptions\FireflyException
|
2016-12-08 14:50:20 -06:00
|
|
|
*/
|
2018-07-09 12:24:08 -05:00
|
|
|
public function budgetReport(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
2016-12-08 14:50:20 -06:00
|
|
|
{
|
|
|
|
if ($end < $start) {
|
2018-07-15 02:38:49 -05:00
|
|
|
return view('error')->with('message', (string)trans('firefly.end_after_start_date')); // @codeCoverageIgnore
|
2016-12-08 14:50:20 -06:00
|
|
|
}
|
2018-01-23 22:17:26 -06:00
|
|
|
$this->repository->cleanupBudgets();
|
2016-12-08 14:50:20 -06:00
|
|
|
|
2018-07-14 09:08:34 -05:00
|
|
|
app('view')->share(
|
2017-11-15 03:52:29 -06:00
|
|
|
'subTitle',
|
|
|
|
trans(
|
2017-11-15 04:33:07 -06:00
|
|
|
'firefly.report_budget',
|
|
|
|
[
|
2019-09-02 14:21:29 -05:00
|
|
|
'start' => $start->formatLocalized($this->monthAndDayFormat),
|
|
|
|
'end' => $end->formatLocalized($this->monthAndDayFormat),
|
2017-11-15 04:33:07 -06:00
|
|
|
]
|
|
|
|
)
|
2016-12-08 14:50:20 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
$generator = ReportGeneratorFactory::reportGenerator('Budget', $start, $end);
|
|
|
|
$generator->setAccounts($accounts);
|
|
|
|
$generator->setBudgets($budgets);
|
|
|
|
|
2018-04-02 08:10:40 -05:00
|
|
|
return $generator->generate();
|
2016-12-08 14:50:20 -06:00
|
|
|
}
|
|
|
|
|
2019-08-16 14:38:35 -05:00
|
|
|
|
2016-02-04 00:28:39 -06:00
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Show category report.
|
|
|
|
*
|
2016-02-04 00:28:39 -06:00
|
|
|
* @param Collection $accounts
|
2016-11-18 13:06:08 -06:00
|
|
|
* @param Collection $categories
|
2016-12-05 23:52:17 -06:00
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
2016-11-18 13:06:08 -06:00
|
|
|
*
|
2018-07-13 08:50:42 -05:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
|
2017-12-22 11:32:43 -06:00
|
|
|
*
|
2017-12-09 14:49:19 -06:00
|
|
|
* @throws \FireflyIII\Exceptions\FireflyException
|
2016-02-04 00:28:39 -06:00
|
|
|
*/
|
2018-07-09 12:24:08 -05:00
|
|
|
public function categoryReport(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
|
2016-02-04 00:28:39 -06:00
|
|
|
{
|
|
|
|
if ($end < $start) {
|
2018-07-15 02:38:49 -05:00
|
|
|
return view('error')->with('message', (string)trans('firefly.end_after_start_date')); // @codeCoverageIgnore
|
2016-11-09 23:23:21 -06:00
|
|
|
}
|
2018-01-23 22:17:26 -06:00
|
|
|
$this->repository->cleanupBudgets();
|
2016-02-04 00:28:39 -06:00
|
|
|
|
2018-07-14 09:08:34 -05:00
|
|
|
app('view')->share(
|
2017-11-15 03:52:29 -06:00
|
|
|
'subTitle',
|
|
|
|
trans(
|
2017-11-15 04:33:07 -06:00
|
|
|
'firefly.report_category',
|
|
|
|
[
|
2019-09-02 14:21:29 -05:00
|
|
|
'start' => $start->formatLocalized($this->monthAndDayFormat),
|
|
|
|
'end' => $end->formatLocalized($this->monthAndDayFormat),
|
2017-11-15 04:33:07 -06:00
|
|
|
]
|
|
|
|
)
|
2016-11-09 23:23:21 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
$generator = ReportGeneratorFactory::reportGenerator('Category', $start, $end);
|
|
|
|
$generator->setAccounts($accounts);
|
|
|
|
$generator->setCategories($categories);
|
|
|
|
|
2018-04-02 08:10:40 -05:00
|
|
|
return $generator->generate();
|
2016-11-09 23:23:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Show default report.
|
|
|
|
*
|
2016-12-05 23:52:17 -06:00
|
|
|
* @param Collection $accounts
|
2016-11-09 23:23:21 -06:00
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
2018-07-09 12:24:08 -05:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
|
2017-12-22 11:32:43 -06:00
|
|
|
*
|
2017-12-09 14:49:19 -06:00
|
|
|
* @throws \FireflyIII\Exceptions\FireflyException
|
2016-11-09 23:23:21 -06:00
|
|
|
*/
|
2018-07-09 12:24:08 -05:00
|
|
|
public function defaultReport(Collection $accounts, Carbon $start, Carbon $end)
|
2016-11-09 23:23:21 -06:00
|
|
|
{
|
|
|
|
if ($end < $start) {
|
2018-07-15 02:38:49 -05:00
|
|
|
return view('error')->with('message', (string)trans('firefly.end_after_start_date'));
|
2016-11-09 23:23:21 -06:00
|
|
|
}
|
2016-11-25 09:55:04 -06:00
|
|
|
|
2018-01-23 22:17:26 -06:00
|
|
|
$this->repository->cleanupBudgets();
|
2016-02-04 00:28:39 -06:00
|
|
|
|
2018-07-14 09:08:34 -05:00
|
|
|
app('view')->share(
|
2017-11-15 03:52:29 -06:00
|
|
|
'subTitle',
|
|
|
|
trans(
|
2017-11-15 04:33:07 -06:00
|
|
|
'firefly.report_default',
|
|
|
|
[
|
2019-08-16 14:21:38 -05:00
|
|
|
'start' => $start->formatLocalized($this->monthAndDayFormat),
|
|
|
|
'end' => $end->formatLocalized($this->monthAndDayFormat),
|
2017-11-15 04:33:07 -06:00
|
|
|
]
|
|
|
|
)
|
2016-04-08 08:10:07 -05:00
|
|
|
);
|
|
|
|
|
2016-11-09 14:36:54 -06:00
|
|
|
$generator = ReportGeneratorFactory::reportGenerator('Standard', $start, $end);
|
|
|
|
$generator->setAccounts($accounts);
|
2016-02-23 13:23:10 -06:00
|
|
|
|
2018-04-02 08:10:40 -05:00
|
|
|
return $generator->generate();
|
2016-04-08 07:50:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Show index.
|
|
|
|
*
|
2016-11-09 14:36:54 -06:00
|
|
|
* @param AccountRepositoryInterface $repository
|
2016-04-08 07:50:18 -05:00
|
|
|
*
|
2018-07-08 05:08:53 -05:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2016-04-08 07:50:18 -05:00
|
|
|
*/
|
2016-11-09 14:36:54 -06:00
|
|
|
public function index(AccountRepositoryInterface $repository)
|
2016-04-08 07:50:18 -05:00
|
|
|
{
|
2016-11-09 14:36:54 -06:00
|
|
|
/** @var Carbon $start */
|
|
|
|
$start = clone session('first');
|
|
|
|
$months = $this->helper->listOfMonths($start);
|
2018-07-14 09:08:34 -05:00
|
|
|
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
|
2016-11-09 23:23:21 -06:00
|
|
|
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
2018-04-02 08:10:40 -05:00
|
|
|
$accountList = implode(',', $accounts->pluck('id')->toArray());
|
2018-01-23 22:17:26 -06:00
|
|
|
$this->repository->cleanupBudgets();
|
2016-02-04 00:28:39 -06:00
|
|
|
|
2016-11-09 14:36:54 -06:00
|
|
|
return view('reports.index', compact('months', 'accounts', 'start', 'accountList', 'customFiscalYear'));
|
2016-02-04 00:28:39 -06:00
|
|
|
}
|
|
|
|
|
2015-12-06 06:11:43 -06:00
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Show options for reports.
|
|
|
|
*
|
2016-11-09 14:36:54 -06:00
|
|
|
* @param string $reportType
|
2015-12-12 10:51:07 -06:00
|
|
|
*
|
2016-11-09 14:36:54 -06:00
|
|
|
* @return mixed
|
2019-08-17 03:47:10 -05:00
|
|
|
*
|
2015-12-06 06:11:43 -06:00
|
|
|
*/
|
2016-11-09 14:36:54 -06:00
|
|
|
public function options(string $reportType)
|
2015-12-06 06:11:43 -06:00
|
|
|
{
|
2016-11-09 14:36:54 -06:00
|
|
|
switch ($reportType) {
|
|
|
|
default:
|
|
|
|
$result = $this->noReportOptions();
|
|
|
|
break;
|
|
|
|
case 'category':
|
|
|
|
$result = $this->categoryReportOptions();
|
|
|
|
break;
|
2016-12-08 14:50:20 -06:00
|
|
|
case 'budget':
|
|
|
|
$result = $this->budgetReportOptions();
|
|
|
|
break;
|
2017-02-15 13:07:10 -06:00
|
|
|
case 'tag':
|
|
|
|
$result = $this->tagReportOptions();
|
|
|
|
break;
|
2017-12-09 14:49:19 -06:00
|
|
|
case 'account':
|
|
|
|
$result = $this->accountReportOptions();
|
|
|
|
break;
|
2016-11-09 14:36:54 -06:00
|
|
|
}
|
|
|
|
|
2018-03-10 13:30:09 -06:00
|
|
|
return response()->json(['html' => $result]);
|
2015-12-12 12:04:30 -06:00
|
|
|
}
|
|
|
|
|
2015-12-28 00:55:09 -06:00
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Process the submit of report.
|
|
|
|
*
|
2016-11-09 14:36:54 -06:00
|
|
|
* @param ReportFormRequest $request
|
2015-12-28 00:55:09 -06:00
|
|
|
*
|
2017-03-24 05:07:38 -05:00
|
|
|
* @return RedirectResponse|\Illuminate\Routing\Redirector
|
2017-12-22 11:32:43 -06:00
|
|
|
*
|
2017-12-09 14:49:19 -06:00
|
|
|
* @throws \FireflyIII\Exceptions\FireflyException
|
2018-07-20 07:34:56 -05:00
|
|
|
*
|
2015-12-28 00:55:09 -06:00
|
|
|
*/
|
2017-03-24 05:07:38 -05:00
|
|
|
public function postIndex(ReportFormRequest $request)
|
2015-12-13 10:31:25 -06:00
|
|
|
{
|
2016-11-09 14:36:54 -06:00
|
|
|
// report type:
|
|
|
|
$reportType = $request->get('report_type');
|
|
|
|
$start = $request->getStartDate()->format('Ymd');
|
|
|
|
$end = $request->getEndDate()->format('Ymd');
|
2018-04-02 08:10:40 -05:00
|
|
|
$accounts = implode(',', $request->getAccountList()->pluck('id')->toArray());
|
|
|
|
$categories = implode(',', $request->getCategoryList()->pluck('id')->toArray());
|
|
|
|
$budgets = implode(',', $request->getBudgetList()->pluck('id')->toArray());
|
2018-08-16 22:54:29 -05:00
|
|
|
$tags = implode(',', $request->getTagList()->pluck('id')->toArray());
|
2019-09-03 10:30:45 -05:00
|
|
|
$double = implode(',', $request->getDoubleList()->pluck('id')->toArray());
|
2017-04-09 00:44:22 -05:00
|
|
|
$uri = route('reports.index');
|
2016-11-02 14:08:11 -05:00
|
|
|
|
2017-11-15 05:25:49 -06:00
|
|
|
if (0 === $request->getAccountList()->count()) {
|
2017-03-24 05:07:38 -05:00
|
|
|
Log::debug('Account count is zero');
|
2018-11-23 01:40:08 -06:00
|
|
|
session()->flash('error', (string)trans('firefly.select_at_least_one_account'));
|
2016-11-25 09:55:04 -06:00
|
|
|
|
|
|
|
return redirect(route('reports.index'));
|
|
|
|
}
|
|
|
|
|
2018-07-08 05:08:53 -05:00
|
|
|
if ('category' === $reportType && 0 === $request->getCategoryList()->count()) {
|
2018-11-23 01:40:08 -06:00
|
|
|
session()->flash('error', (string)trans('firefly.select_at_least_one_category'));
|
2016-11-28 12:45:36 -06:00
|
|
|
|
|
|
|
return redirect(route('reports.index'));
|
|
|
|
}
|
|
|
|
|
2018-07-08 05:08:53 -05:00
|
|
|
if ('budget' === $reportType && 0 === $request->getBudgetList()->count()) {
|
2018-11-23 01:40:08 -06:00
|
|
|
session()->flash('error', (string)trans('firefly.select_at_least_one_budget'));
|
2016-12-08 14:50:20 -06:00
|
|
|
|
|
|
|
return redirect(route('reports.index'));
|
|
|
|
}
|
|
|
|
|
2018-07-08 05:08:53 -05:00
|
|
|
if ('tag' === $reportType && 0 === $request->getTagList()->count()) {
|
2018-11-23 01:40:08 -06:00
|
|
|
session()->flash('error', (string)trans('firefly.select_at_least_one_tag'));
|
|
|
|
|
|
|
|
return redirect(route('reports.index'));
|
|
|
|
}
|
|
|
|
|
2019-09-03 10:30:45 -05:00
|
|
|
if ('account' === $reportType && 0 === $request->getDoubleList()->count()) {
|
2018-11-23 01:40:08 -06:00
|
|
|
session()->flash('error', (string)trans('firefly.select_at_least_one_expense'));
|
2017-02-15 13:07:10 -06:00
|
|
|
|
|
|
|
return redirect(route('reports.index'));
|
|
|
|
}
|
|
|
|
|
2017-10-22 13:13:02 -05:00
|
|
|
if ($request->getEndDate() < $request->getStartDate()) {
|
2018-07-15 02:38:49 -05:00
|
|
|
return view('error')->with('message', (string)trans('firefly.end_after_start_date'));
|
2016-11-09 14:36:54 -06:00
|
|
|
}
|
2016-11-01 22:55:44 -05:00
|
|
|
|
2016-11-09 14:36:54 -06:00
|
|
|
switch ($reportType) {
|
|
|
|
case 'category':
|
2016-12-05 23:52:17 -06:00
|
|
|
$uri = route('reports.report.category', [$accounts, $categories, $start, $end]);
|
2016-11-09 14:36:54 -06:00
|
|
|
break;
|
|
|
|
case 'default':
|
2016-12-05 23:52:17 -06:00
|
|
|
$uri = route('reports.report.default', [$accounts, $start, $end]);
|
2016-11-09 14:36:54 -06:00
|
|
|
break;
|
|
|
|
case 'audit':
|
2016-12-05 23:52:17 -06:00
|
|
|
$uri = route('reports.report.audit', [$accounts, $start, $end]);
|
2016-11-09 14:36:54 -06:00
|
|
|
break;
|
2016-12-08 14:50:20 -06:00
|
|
|
case 'budget':
|
|
|
|
$uri = route('reports.report.budget', [$accounts, $budgets, $start, $end]);
|
|
|
|
break;
|
2017-02-15 13:07:10 -06:00
|
|
|
case 'tag':
|
|
|
|
$uri = route('reports.report.tag', [$accounts, $tags, $start, $end]);
|
|
|
|
break;
|
2017-12-09 14:49:19 -06:00
|
|
|
case 'account':
|
2019-09-03 10:30:45 -05:00
|
|
|
$uri = route('reports.report.account', [$accounts, $double, $start, $end]);
|
2017-12-09 14:49:19 -06:00
|
|
|
break;
|
2016-11-09 14:36:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return redirect($uri);
|
2015-12-13 10:31:25 -06:00
|
|
|
}
|
|
|
|
|
2019-08-16 14:38:35 -05:00
|
|
|
|
2017-02-16 23:42:36 -06:00
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Get a tag report.
|
|
|
|
*
|
2017-02-16 23:42:36 -06:00
|
|
|
* @param Collection $accounts
|
|
|
|
* @param Collection $tags
|
|
|
|
* @param Carbon $start
|
|
|
|
* @param Carbon $end
|
|
|
|
*
|
2018-07-09 12:24:08 -05:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
|
2017-12-09 14:49:19 -06:00
|
|
|
* @throws \FireflyIII\Exceptions\FireflyException
|
2017-02-16 23:42:36 -06:00
|
|
|
*/
|
2018-07-09 12:24:08 -05:00
|
|
|
public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
|
2017-02-16 23:42:36 -06:00
|
|
|
{
|
|
|
|
if ($end < $start) {
|
2018-07-15 02:38:49 -05:00
|
|
|
return view('error')->with('message', (string)trans('firefly.end_after_start_date')); // @codeCoverageIgnore
|
2017-02-16 23:42:36 -06:00
|
|
|
}
|
2018-01-23 22:17:26 -06:00
|
|
|
$this->repository->cleanupBudgets();
|
2017-02-16 23:42:36 -06:00
|
|
|
|
2018-07-14 09:08:34 -05:00
|
|
|
app('view')->share(
|
2017-11-15 03:52:29 -06:00
|
|
|
'subTitle',
|
|
|
|
trans(
|
2017-11-15 04:33:07 -06:00
|
|
|
'firefly.report_tag',
|
|
|
|
[
|
2019-09-02 14:21:29 -05:00
|
|
|
'start' => $start->formatLocalized($this->monthAndDayFormat),
|
|
|
|
'end' => $end->formatLocalized($this->monthAndDayFormat),
|
2017-11-15 04:33:07 -06:00
|
|
|
]
|
|
|
|
)
|
2017-02-16 23:42:36 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
$generator = ReportGeneratorFactory::reportGenerator('Tag', $start, $end);
|
|
|
|
$generator->setAccounts($accounts);
|
|
|
|
$generator->setTags($tags);
|
|
|
|
|
2018-04-02 08:10:40 -05:00
|
|
|
return $generator->generate();
|
2017-02-16 23:42:36 -06:00
|
|
|
}
|
|
|
|
|
2016-12-08 14:50:20 -06:00
|
|
|
|
2015-02-23 13:25:48 -06:00
|
|
|
}
|