firefly-iii/app/Http/Controllers/Category/NoCategoryController.php

144 lines
5.2 KiB
PHP
Raw Normal View History

2018-07-14 15:48:22 -05:00
<?php
/**
* NoCategoryController.php
2020-01-31 00:32:04 -06:00
* Copyright (c) 2019 james@firefly-iii.org
2018-07-14 15:48:22 -05:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-07-14 15:48:22 -05:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-07-14 15:48:22 -05:00
*
* This program is distributed in the hope that it will be useful,
2018-07-14 15:48:22 -05:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-07-14 15:48:22 -05:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-07-14 15:48:22 -05:00
*/
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
2018-07-14 15:48:22 -05:00
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
2018-12-31 00:58:13 -06:00
use FireflyIII\Support\Http\Controllers\PeriodOverview;
use Illuminate\Contracts\View\Factory;
2018-07-14 15:48:22 -05:00
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\View\View;
2018-07-14 15:48:22 -05:00
use Log;
/**
*
* Class NoCategoryController
*/
class NoCategoryController extends Controller
{
2018-12-31 00:58:13 -06:00
use PeriodOverview;
/** @var JournalRepositoryInterface Journals and transactions overview */
2018-07-14 15:48:22 -05:00
private $journalRepos;
/**
* CategoryController constructor.
*
* @codeCoverageIgnore
2018-07-14 15:48:22 -05:00
*/
public function __construct()
{
parent::__construct();
2019-09-04 00:51:31 -05:00
app('view')->share('showBudget', true);
2018-07-14 15:48:22 -05:00
$this->middleware(
function ($request, $next) {
app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark');
2018-07-14 15:48:22 -05:00
$this->journalRepos = app(JournalRepositoryInterface::class);
return $next($request);
}
);
}
/**
2018-07-21 01:06:24 -05:00
* Show transactions without a category.
*
* @param Request $request
2018-07-22 01:10:16 -05:00
* @param Carbon|null $start
* @param Carbon|null $end
2018-07-14 15:48:22 -05:00
*
* @return Factory|View
2018-07-14 15:48:22 -05:00
*/
public function show(Request $request, Carbon $start = null, Carbon $end = null)
{
Log::debug('Start of noCategory()');
/** @var Carbon $start */
$start = $start ?? session('start');
/** @var Carbon $end */
$end = $end ?? session('end');
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
2018-07-14 15:48:22 -05:00
$subTitle = trans(
'firefly.without_category_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
);
$periods = $this->getNoCategoryPeriodOverview($start);
Log::debug(sprintf('Start for noCategory() is %s', $start->format('Y-m-d')));
Log::debug(sprintf('End for noCategory() is %s', $end->format('Y-m-d')));
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)
->setLimit($pageSize)->setPage($page)->withoutCategory()
->withAccountInformation()->withBudgetInformation()
2018-07-14 15:48:22 -05:00
->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]);
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('categories.no-category'));
2018-07-14 15:48:22 -05:00
return view('categories.no-category', compact('groups', 'subTitle', 'periods', 'start', 'end'));
2018-07-14 15:48:22 -05:00
}
/**
2018-07-22 01:10:16 -05:00
* Show all transactions without a category.
*
* @param Request $request
2018-07-14 15:48:22 -05:00
*
* @return Factory|View
2018-07-14 15:48:22 -05:00
*/
public function showAll(Request $request)
2018-07-14 15:48:22 -05:00
{
// default values:
$start = null;
$end = null;
$periods = new Collection;
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
2018-07-14 15:48:22 -05:00
Log::debug('Start of noCategory()');
$subTitle = (string) trans('firefly.all_journals_without_category');
2018-07-14 15:48:22 -05:00
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon : $first->date;
$end = new Carbon;
Log::debug(sprintf('Start for noCategory() is %s', $start->format('Y-m-d')));
Log::debug(sprintf('End for noCategory() is %s', $end->format('Y-m-d')));
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()
->withAccountInformation()->withBudgetInformation()
2018-07-14 15:48:22 -05:00
->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]);
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('categories.no-category.all'));
2018-07-14 15:48:22 -05:00
return view('categories.no-category', compact('groups', 'subTitle', 'periods', 'start', 'end'));
2018-07-14 15:48:22 -05:00
}
}