Migrated all code to group collector.

This commit is contained in:
James Cole
2019-05-31 13:35:33 +02:00
parent eb6329e556
commit e15c35de64
31 changed files with 1540 additions and 1671 deletions

View File

@@ -25,7 +25,7 @@ namespace FireflyIII\Http\Controllers\Transaction;
use Carbon\Carbon;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Filter\TransactionViewFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Http\Controllers\Controller;
@@ -126,10 +126,13 @@ class MassController extends Controller
* @param Collection $journals
*
* @return IlluminateView
*
* TODO rebuild this feature.
* @throws FireflyException
*/
public function edit(Collection $journals): IlluminateView
{
throw new FireflyException('Needs refactor');
throw new FireflyException(sprintf('The mass-editor is not available in v%s of Firefly III. Sorry about that. It will be back soon.', config('firefly.version')));
/** @var User $user */
$user = auth()->user();
$subTitle = (string)trans('firefly.mass_edit_journals');
@@ -148,8 +151,8 @@ class MassController extends Controller
$transformer = app(TransactionTransformer::class);
$transformer->setParameters(new ParameterBag);
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($user);
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setJournals($journals);
@@ -175,7 +178,7 @@ class MassController extends Controller
/**
* Mass update of journals.
*
* @param MassEditJournalRequest $request
* @param MassEditJournalRequest $request
* @param JournalRepositoryInterface $repository
*
* @return mixed

View File

@@ -1,177 +0,0 @@
<?php
/**
* SplitController.php
* Copyright (c) 2017 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\Transaction;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\SplitJournalFormRequest;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Support\Http\Controllers\ModelInformation;
use FireflyIII\Support\Http\Controllers\RequestInformation;
use Illuminate\Http\Request;
use View;
/**
* Class SplitController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class SplitController extends Controller
{
use ModelInformation, RequestInformation;
/** @var AttachmentHelperInterface Attachment helper */
private $attachments;
/** @var BudgetRepositoryInterface The budget repository */
private $budgets;
/** @var CurrencyRepositoryInterface The currency repository */
private $currencies;
/** @var JournalRepositoryInterface Journals and transactions overview */
private $repository;
/**
* SplitController constructor.
*/
public function __construct()
{
throw new FireflyException('Do not use me.');
parent::__construct();
// some useful repositories:
$this->middleware(
function ($request, $next) {
$this->budgets = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
$this->currencies = app(CurrencyRepositoryInterface::class);
$this->repository = app(JournalRepositoryInterface::class);
app('view')->share('mainTitleIcon', 'fa-share-alt');
app('view')->share('title', (string)trans('firefly.split-transactions'));
return $next($request);
}
);
}
/**
* Edit a split.
*
* @param Request $request
* @param TransactionJournal $journal
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
* @throws FireflyException
*/
public function edit(Request $request, TransactionJournal $journal)
{
throw new FireflyException('Needs refactoring');
if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal); // @codeCoverageIgnore
}
// basic fields:
$uploadSize = min(app('steam')->phpBytes(ini_get('upload_max_filesize')), app('steam')->phpBytes(ini_get('post_max_size')));
$subTitle = (string)trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
$subTitleIcon = 'fa-pencil';
// lists and collections
$currencies = $this->currencies->get();
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
// other fields
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
$preFilled = $this->arrayFromJournal($request, $journal);
// put previous url in session if not redirect from store (not "return_to_edit").
if (true !== session('transactions.edit-split.fromUpdate')) {
$this->rememberPreviousUri('transactions.edit-split.uri');
}
session()->forget('transactions.edit-split.fromUpdate');
return view(
'transactions.split.edit', compact(
'subTitleIcon', 'currencies', 'optionalFields', 'preFilled', 'subTitle', 'uploadSize', 'budgets',
'journal'
)
);
}
/**
* Store new split journal.
*
* @param SplitJournalFormRequest $request
* @param TransactionJournal $journal
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function update(SplitJournalFormRequest $request, TransactionJournal $journal)
{
throw new FireflyException('Needs refactoring.');
if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal); // @codeCoverageIgnore
}
$data = $request->getAll();
// keep current bill:
$data['bill_id'] = $journal->bill_id;
$journal = $this->repository->update($journal, $data);
/** @var array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
// save attachments:
$this->attachments->saveAttachmentsForModel($journal, $files);
event(new UpdatedTransactionGroup($group));
// flash messages
// @codeCoverageIgnoreStart
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
}
// @codeCoverageIgnoreEnd
$type = strtolower($this->repository->getTransactionType($journal));
session()->flash('success', (string)trans('firefly.updated_' . $type, ['description' => $journal->description]));
app('preferences')->mark();
// @codeCoverageIgnoreStart
if (1 === (int)$request->get('return_to_edit')) {
// set value so edit routine will not overwrite URL:
session()->put('transactions.edit-split.fromUpdate', true);
return redirect(route('transactions.split.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);
}
// @codeCoverageIgnoreEnd
// redirect to previous URL.
return redirect($this->getPreviousUri('transactions.edit-split.uri'));
}
}