mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code for #384
This commit is contained in:
@@ -74,6 +74,39 @@ class ReportController extends Controller
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function accountReport(Collection $accounts, Collection $expense, Carbon $start, Carbon $end)
|
||||
{
|
||||
if ($end < $start) {
|
||||
return view('error')->with('message', trans('firefly.end_after_start_date'));
|
||||
}
|
||||
|
||||
if ($start < session('first')) {
|
||||
$start = session('first');
|
||||
}
|
||||
|
||||
View::share(
|
||||
'subTitle', trans(
|
||||
'firefly.report_default', ['start' => $start->formatLocalized($this->monthFormat), 'end' => $end->formatLocalized($this->monthFormat),]
|
||||
)
|
||||
);
|
||||
|
||||
$generator = ReportGeneratorFactory::reportGenerator('Account', $start, $end);
|
||||
$generator->setAccounts($accounts);
|
||||
$generator->setExpense($expense);
|
||||
$result = $generator->generate();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function auditReport(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
@@ -109,6 +142,7 @@ class ReportController extends Controller
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function budgetReport(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
|
||||
{
|
||||
@@ -145,6 +179,7 @@ class ReportController extends Controller
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function categoryReport(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
|
||||
{
|
||||
@@ -180,6 +215,7 @@ class ReportController extends Controller
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function defaultReport(Collection $accounts, Carbon $start, Carbon $end)
|
||||
{
|
||||
@@ -230,6 +266,7 @@ class ReportController extends Controller
|
||||
* @param string $reportType
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function options(string $reportType)
|
||||
{
|
||||
@@ -246,6 +283,9 @@ class ReportController extends Controller
|
||||
case 'tag':
|
||||
$result = $this->tagReportOptions();
|
||||
break;
|
||||
case 'account':
|
||||
$result = $this->accountReportOptions();
|
||||
break;
|
||||
}
|
||||
|
||||
return Response::json(['html' => $result]);
|
||||
@@ -255,6 +295,7 @@ class ReportController extends Controller
|
||||
* @param ReportFormRequest $request
|
||||
*
|
||||
* @return RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function postIndex(ReportFormRequest $request)
|
||||
@@ -267,6 +308,7 @@ class ReportController extends Controller
|
||||
$categories = join(',', $request->getCategoryList()->pluck('id')->toArray());
|
||||
$budgets = join(',', $request->getBudgetList()->pluck('id')->toArray());
|
||||
$tags = join(',', $request->getTagList()->pluck('tag')->toArray());
|
||||
$expense = join(',', $request->getExpenseList()->pluck('id')->toArray());
|
||||
$uri = route('reports.index');
|
||||
|
||||
if (0 === $request->getAccountList()->count()) {
|
||||
@@ -314,6 +356,9 @@ class ReportController extends Controller
|
||||
case 'tag':
|
||||
$uri = route('reports.report.tag', [$accounts, $tags, $start, $end]);
|
||||
break;
|
||||
case 'account':
|
||||
$uri = route('reports.report.account', [$accounts, $expense, $start, $end]);
|
||||
break;
|
||||
}
|
||||
|
||||
return redirect($uri);
|
||||
@@ -326,6 +371,7 @@ class ReportController extends Controller
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
|
||||
{
|
||||
@@ -357,6 +403,30 @@ class ReportController extends Controller
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Throwable
|
||||
*/
|
||||
private function accountReportOptions(): string
|
||||
{
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$expense = $repository->getActiveAccountsByType([AccountType::EXPENSE]);
|
||||
$revenue = $repository->getActiveAccountsByType([AccountType::REVENUE]);
|
||||
$set = new Collection;
|
||||
$names = $revenue->pluck('name')->toArray();
|
||||
foreach ($expense as $exp) {
|
||||
if (in_array($exp->name, $names)) {
|
||||
$set->push($exp);
|
||||
}
|
||||
}
|
||||
|
||||
$result = view('reports.options.account', compact('set'))->render();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Throwable
|
||||
*/
|
||||
private function budgetReportOptions(): string
|
||||
{
|
||||
@@ -370,6 +440,7 @@ class ReportController extends Controller
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Throwable
|
||||
*/
|
||||
private function categoryReportOptions(): string
|
||||
{
|
||||
@@ -383,6 +454,7 @@ class ReportController extends Controller
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Throwable
|
||||
*/
|
||||
private function noReportOptions(): string
|
||||
{
|
||||
@@ -391,6 +463,7 @@ class ReportController extends Controller
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Throwable
|
||||
*/
|
||||
private function tagReportOptions(): string
|
||||
{
|
||||
|
@@ -45,6 +45,28 @@ class ReportFormRequest extends Request
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getExpenseList(): Collection
|
||||
{
|
||||
// fixed
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$set = $this->get('exp_rev');
|
||||
$collection = new Collection;
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $accountId) {
|
||||
$account = $repository->find(intval($accountId));
|
||||
if (null !== $account->id) {
|
||||
$collection->push($account);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -178,7 +200,7 @@ class ReportFormRequest extends Request
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'report_type' => 'in:audit,default,category,budget,tag',
|
||||
'report_type' => 'in:audit,default,category,budget,tag,account',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -676,6 +676,20 @@ Breadcrumbs::register(
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'reports.report.account',
|
||||
function (BreadCrumbGenerator $breadcrumbs, string $accountIds, string $expenseIds, Carbon $start, Carbon $end) {
|
||||
$breadcrumbs->parent('reports.index');
|
||||
|
||||
$monthFormat = (string)trans('config.month_and_day');
|
||||
$startString = $start->formatLocalized($monthFormat);
|
||||
$endString = $end->formatLocalized($monthFormat);
|
||||
$title = (string)trans('firefly.report_account', ['start' => $startString, 'end' => $endString]);
|
||||
|
||||
$breadcrumbs->push($title, route('reports.report.account', [$accountIds, $expenseIds, $start->format('Ymd'), $end->format('Ymd')]));
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'reports.report.default',
|
||||
function (BreadCrumbGenerator $breadcrumbs, string $accountIds, Carbon $start, Carbon $end) {
|
||||
|
Reference in New Issue
Block a user