2018-07-14 15:48:22 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* NoCategoryController.php
|
|
|
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This file is part of Firefly III.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers\Category;
|
|
|
|
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2018-08-11 07:33:47 -05:00
|
|
|
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
2018-07-14 15:48:22 -05:00
|
|
|
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
|
|
|
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;
|
2018-07-14 15:48:22 -05:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Log;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Class NoCategoryController
|
|
|
|
*/
|
|
|
|
class NoCategoryController extends Controller
|
|
|
|
{
|
2018-12-31 00:58:13 -06:00
|
|
|
use PeriodOverview;
|
2018-07-20 13:53:48 -05:00
|
|
|
/** @var JournalRepositoryInterface Journals and transactions overview */
|
2018-07-14 15:48:22 -05:00
|
|
|
private $journalRepos;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CategoryController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->middleware(
|
|
|
|
function ($request, $next) {
|
2018-07-15 02:38:49 -05:00
|
|
|
app('view')->share('title', (string)trans('firefly.categories'));
|
2018-07-14 15:48:22 -05:00
|
|
|
app('view')->share('mainTitleIcon', 'fa-bar-chart');
|
|
|
|
$this->journalRepos = app(JournalRepositoryInterface::class);
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-21 01:06:24 -05:00
|
|
|
* Show transactions without a category.
|
|
|
|
*
|
2018-07-14 15:48:22 -05:00
|
|
|
* @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 \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
$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')));
|
|
|
|
|
2018-08-11 07:33:47 -05:00
|
|
|
/** @var TransactionCollectorInterface $collector */
|
|
|
|
$collector = app(TransactionCollectorInterface::class);
|
2018-07-14 15:48:22 -05:00
|
|
|
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()->withOpposingAccount()
|
|
|
|
->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]);
|
|
|
|
$collector->removeFilter(InternalTransferFilter::class);
|
2018-08-11 07:33:47 -05:00
|
|
|
$transactions = $collector->getPaginatedTransactions();
|
2018-07-14 15:48:22 -05:00
|
|
|
$transactions->setPath(route('categories.no-category'));
|
|
|
|
|
2018-08-08 10:53:40 -05:00
|
|
|
return view('categories.no-category', compact('transactions', '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.
|
|
|
|
*
|
2018-08-09 10:46:14 -05:00
|
|
|
* @param Request $request
|
2018-07-14 15:48:22 -05:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
2018-08-08 10:53:40 -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;
|
|
|
|
Log::debug('Start of noCategory()');
|
2018-07-15 02:38:49 -05:00
|
|
|
$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')));
|
|
|
|
|
2018-08-11 07:33:47 -05:00
|
|
|
/** @var TransactionCollectorInterface $collector */
|
|
|
|
$collector = app(TransactionCollectorInterface::class);
|
2018-07-14 15:48:22 -05:00
|
|
|
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()->withOpposingAccount()
|
|
|
|
->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]);
|
|
|
|
$collector->removeFilter(InternalTransferFilter::class);
|
2018-08-11 07:33:47 -05:00
|
|
|
$transactions = $collector->getPaginatedTransactions();
|
2018-11-20 23:21:57 -06:00
|
|
|
$transactions->setPath(route('categories.no-category.all'));
|
2018-07-14 15:48:22 -05:00
|
|
|
|
2018-08-08 10:53:40 -05:00
|
|
|
return view('categories.no-category', compact('transactions', 'subTitle', 'periods', 'start', 'end'));
|
2018-07-14 15:48:22 -05:00
|
|
|
}
|
2018-07-22 13:32:02 -05:00
|
|
|
}
|