mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 01:42:19 +00:00
Some code cleanup for #1272
This commit is contained in:
@@ -28,7 +28,6 @@ use ExpandedForm;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\BulkEditJournalRequest;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Services\Internal\Update\JournalUpdateService;
|
||||
@@ -66,70 +65,25 @@ class BulkController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Collection $journals
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function edit(Request $request, Collection $journals)
|
||||
public function edit(Collection $journals)
|
||||
{
|
||||
|
||||
$subTitle = trans('firefly.mass_bulk_journals');
|
||||
|
||||
// skip transactions that have multiple destinations, multiple sources or are an opening balance.
|
||||
$filtered = new Collection;
|
||||
$messages = [];
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$sources = $this->repository->getJournalSourceAccounts($journal);
|
||||
$destinations = $this->repository->getJournalDestinationAccounts($journal);
|
||||
if ($sources->count() > 1) {
|
||||
$messages[] = trans('firefly.cannot_edit_multiple_source', ['description' => $journal->description, 'id' => $journal->id]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($destinations->count() > 1) {
|
||||
$messages[] = trans('firefly.cannot_edit_multiple_dest', ['description' => $journal->description, 'id' => $journal->id]);
|
||||
continue;
|
||||
}
|
||||
if (TransactionType::OPENING_BALANCE === $this->repository->getTransactionType($journal)) {
|
||||
$messages[] = trans('firefly.cannot_edit_opening_balance');
|
||||
continue;
|
||||
}
|
||||
|
||||
// cannot edit reconciled transactions / journals:
|
||||
if ($this->repository->isJournalReconciled($journal)) {
|
||||
$messages[] = trans('firefly.cannot_edit_reconciled', ['description' => $journal->description, 'id' => $journal->id]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$filtered->push($journal);
|
||||
}
|
||||
|
||||
if (count($messages) > 0) {
|
||||
$request->session()->flash('info', $messages);
|
||||
}
|
||||
|
||||
// put previous url in session
|
||||
$this->rememberPreviousUri('transactions.bulk-edit.uri');
|
||||
|
||||
// get list of budgets:
|
||||
/** @var BudgetRepositoryInterface $repository */
|
||||
$repository = app(BudgetRepositoryInterface::class);
|
||||
$budgetList = ExpandedForm::makeSelectListWithEmpty($repository->getActiveBudgets());
|
||||
// collect some useful meta data for the mass edit:
|
||||
$filtered->each(
|
||||
$journals->each(
|
||||
function (TransactionJournal $journal) {
|
||||
$journal->transaction_count = $journal->transactions()->count();
|
||||
}
|
||||
);
|
||||
|
||||
if (0 === $filtered->count()) {
|
||||
$request->session()->flash('error', trans('firefly.no_edit_multiple_left'));
|
||||
}
|
||||
|
||||
$journals = $filtered;
|
||||
|
||||
return view('transactions.bulk.edit', compact('journals', 'subTitle', 'budgetList'));
|
||||
}
|
||||
|
||||
@@ -142,36 +96,32 @@ class BulkController extends Controller
|
||||
*/
|
||||
public function update(BulkEditJournalRequest $request, JournalRepositoryInterface $repository)
|
||||
{
|
||||
/** @var JournalUpdateService $service */
|
||||
$service = app(JournalUpdateService::class);
|
||||
$journalIds = $request->get('journals');
|
||||
$ignoreCategory = (int)$request->get('ignore_category') === 1;
|
||||
$ignoreBudget = (int)$request->get('ignore_budget') === 1;
|
||||
$ignoreTags = (int)$request->get('ignore_tags') === 1;
|
||||
$count = 0;
|
||||
|
||||
if (is_array($journalIds)) {
|
||||
if (\is_array($journalIds)) {
|
||||
foreach ($journalIds as $journalId) {
|
||||
$journal = $repository->find((int)$journalId);
|
||||
if (null !== $journal) {
|
||||
$count++;
|
||||
Log::debug(sprintf('Found journal #%d', $journal->id));
|
||||
// update category if not told to ignore
|
||||
if ($ignoreCategory === false) {
|
||||
Log::debug(sprintf('Set category to %s', $request->string('category')));
|
||||
$count++;
|
||||
Log::debug(sprintf('Found journal #%d', $journal->id));
|
||||
|
||||
$repository->updateCategory($journal, $request->string('category'));
|
||||
}
|
||||
// update budget if not told to ignore (and is withdrawal)
|
||||
if ($ignoreBudget === false) {
|
||||
Log::debug(sprintf('Set budget to %d', $request->integer('budget_id')));
|
||||
$repository->updateBudget($journal, $request->integer('budget_id'));
|
||||
}
|
||||
if ($ignoreTags === false) {
|
||||
Log::debug(sprintf('Set tags to %s', $request->string('budget_id')));
|
||||
$repository->updateTags($journal, ['tags' => explode(',', $request->string('tags'))]);
|
||||
}
|
||||
// update tags if not told to ignore (and is withdrawal)
|
||||
// update category if not told to ignore
|
||||
if ($ignoreCategory === false) {
|
||||
Log::debug(sprintf('Set category to %s', $request->string('category')));
|
||||
|
||||
$repository->updateCategory($journal, $request->string('category'));
|
||||
}
|
||||
// update budget if not told to ignore (and is withdrawal)
|
||||
if ($ignoreBudget === false) {
|
||||
Log::debug(sprintf('Set budget to %d', $request->integer('budget_id')));
|
||||
$repository->updateBudget($journal, $request->integer('budget_id'));
|
||||
}
|
||||
if ($ignoreTags === false) {
|
||||
Log::debug(sprintf('Set tags to %s', $request->string('budget_id')));
|
||||
$repository->updateTags($journal, ['tags' => explode(',', $request->string('tags'))]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -81,14 +81,14 @@ class ConvertController extends Controller
|
||||
|
||||
// cannot convert to its own type.
|
||||
if ($sourceType->type === $destinationType->type) {
|
||||
Session::flash('info', trans('firefly.convert_is_already_type_' . $destinationType->type));
|
||||
session()->flash('info', trans('firefly.convert_is_already_type_' . $destinationType->type));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->id]));
|
||||
}
|
||||
|
||||
// cannot convert split.
|
||||
if ($journal->transactions()->count() > 2) {
|
||||
Session::flash('error', trans('firefly.cannot_convert_split_journal'));
|
||||
session()->flash('error', trans('firefly.cannot_convert_split_journal'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->id]));
|
||||
}
|
||||
@@ -138,13 +138,13 @@ class ConvertController extends Controller
|
||||
$data = $request->all();
|
||||
|
||||
if ($journal->transactionType->type === $destinationType->type) {
|
||||
Session::flash('error', trans('firefly.convert_is_already_type_' . $destinationType->type));
|
||||
session()->flash('error', trans('firefly.convert_is_already_type_' . $destinationType->type));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->id]));
|
||||
}
|
||||
|
||||
if ($journal->transactions()->count() > 2) {
|
||||
Session::flash('error', trans('firefly.cannot_convert_split_journal'));
|
||||
session()->flash('error', trans('firefly.cannot_convert_split_journal'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->id]));
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class ConvertController extends Controller
|
||||
return redirect(route('transactions.convert.index', [strtolower($destinationType->type), $journal->id]))->withErrors($errors)->withInput();
|
||||
}
|
||||
|
||||
Session::flash('success', trans('firefly.converted_to_' . $destinationType->type));
|
||||
session()->flash('success', trans('firefly.converted_to_' . $destinationType->type));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->id]));
|
||||
}
|
||||
|
@@ -86,7 +86,7 @@ class LinkController extends Controller
|
||||
{
|
||||
$this->repository->destroyLink($link);
|
||||
|
||||
Session::flash('success', (string)trans('firefly.deleted_link'));
|
||||
session()->flash('success', (string)trans('firefly.deleted_link'));
|
||||
Preferences::mark();
|
||||
|
||||
return redirect((string)session('journal_links.delete.uri'));
|
||||
@@ -104,7 +104,7 @@ class LinkController extends Controller
|
||||
Log::debug('We are here (store)');
|
||||
$linkInfo = $request->getLinkInfo();
|
||||
if (0 === $linkInfo['transaction_journal_id']) {
|
||||
Session::flash('error', trans('firefly.invalid_link_selection'));
|
||||
session()->flash('error', trans('firefly.invalid_link_selection'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->id]));
|
||||
}
|
||||
@@ -112,19 +112,19 @@ class LinkController extends Controller
|
||||
$alreadyLinked = $this->repository->findLink($journal, $other);
|
||||
|
||||
if ($other->id === $journal->id) {
|
||||
Session::flash('error', trans('firefly.journals_link_to_self'));
|
||||
session()->flash('error', trans('firefly.journals_link_to_self'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->id]));
|
||||
}
|
||||
|
||||
if ($alreadyLinked) {
|
||||
Session::flash('error', trans('firefly.journals_error_linked'));
|
||||
session()->flash('error', trans('firefly.journals_error_linked'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->id]));
|
||||
}
|
||||
Log::debug(sprintf('Journal is %d, opposing is %d', $journal->id, $other->id));
|
||||
$this->repository->storeLink($linkInfo, $other, $journal);
|
||||
Session::flash('success', trans('firefly.journals_linked'));
|
||||
session()->flash('success', trans('firefly.journals_linked'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->id]));
|
||||
}
|
||||
|
@@ -108,7 +108,7 @@ class MassController extends Controller
|
||||
}
|
||||
|
||||
Preferences::mark();
|
||||
Session::flash('success', trans('firefly.mass_deleted_transactions_success', ['amount' => $count]));
|
||||
session()->flash('success', trans('firefly.mass_deleted_transactions_success', ['amount' => $count]));
|
||||
|
||||
// redirect to previous URL:
|
||||
return redirect($this->getPreviousUri('transactions.mass-delete.uri'));
|
||||
@@ -163,7 +163,7 @@ class MassController extends Controller
|
||||
}
|
||||
|
||||
if (count($messages) > 0) {
|
||||
Session::flash('info', $messages);
|
||||
session()->flash('info', $messages);
|
||||
}
|
||||
|
||||
// put previous url in session
|
||||
@@ -196,7 +196,7 @@ class MassController extends Controller
|
||||
);
|
||||
|
||||
if (0 === $filtered->count()) {
|
||||
Session::flash('error', trans('firefly.no_edit_multiple_left'));
|
||||
session()->flash('error', trans('firefly.no_edit_multiple_left'));
|
||||
}
|
||||
|
||||
$journals = $filtered;
|
||||
@@ -281,7 +281,7 @@ class MassController extends Controller
|
||||
}
|
||||
}
|
||||
Preferences::mark();
|
||||
Session::flash('success', trans('firefly.mass_edited_transactions_success', ['amount' => $count]));
|
||||
session()->flash('success', trans('firefly.mass_edited_transactions_success', ['amount' => $count]));
|
||||
|
||||
// redirect to previous URL:
|
||||
return redirect($this->getPreviousUri('transactions.mass-edit.uri'));
|
||||
|
@@ -140,7 +140,7 @@ class SingleController extends Controller
|
||||
$preFilled['notes'] = $note->text;
|
||||
}
|
||||
|
||||
Session::flash('preFilled', $preFilled);
|
||||
session()->flash('preFilled', $preFilled);
|
||||
|
||||
return redirect(route('transactions.create', [strtolower($journal->transactionType->type)]));
|
||||
}
|
||||
@@ -227,7 +227,7 @@ class SingleController extends Controller
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
$type = $transactionJournal->transactionTypeStr();
|
||||
Session::flash('success', (string)trans('firefly.deleted_' . strtolower($type), ['description' => $transactionJournal->description]));
|
||||
session()->flash('success', (string)trans('firefly.deleted_' . strtolower($type), ['description' => $transactionJournal->description]));
|
||||
|
||||
$this->repository->destroy($transactionJournal);
|
||||
|
||||
@@ -312,7 +312,7 @@ class SingleController extends Controller
|
||||
$preFilled['currency'] = $pTransaction->foreignCurrency;
|
||||
}
|
||||
|
||||
Session::flash('preFilled', $preFilled);
|
||||
session()->flash('preFilled', $preFilled);
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (true !== session('transactions.edit.fromUpdate')) {
|
||||
@@ -343,7 +343,7 @@ class SingleController extends Controller
|
||||
if (null === $journal->id) {
|
||||
// error!
|
||||
Log::error('Could not store transaction journal.');
|
||||
Session::flash('error', (string)trans('firefly.unknown_journal_error'));
|
||||
session()->flash('error', (string)trans('firefly.unknown_journal_error'));
|
||||
|
||||
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
|
||||
}
|
||||
@@ -355,16 +355,16 @@ class SingleController extends Controller
|
||||
// store the journal only, flash the rest.
|
||||
Log::debug(sprintf('Count of error messages is %d', $this->attachments->getErrors()->count()));
|
||||
if (\count($this->attachments->getErrors()->get('attachments')) > 0) {
|
||||
Session::flash('error', $this->attachments->getErrors()->get('attachments'));
|
||||
session()->flash('error', $this->attachments->getErrors()->get('attachments'));
|
||||
}
|
||||
// flash messages
|
||||
if (\count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
Session::flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
}
|
||||
|
||||
event(new StoredTransactionJournal($journal, $data['piggy_bank_id']));
|
||||
|
||||
Session::flash('success', (string)trans('firefly.stored_journal', ['description' => $journal->description]));
|
||||
session()->flash('success', (string)trans('firefly.stored_journal', ['description' => $journal->description]));
|
||||
Preferences::mark();
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
@@ -410,10 +410,10 @@ class SingleController extends Controller
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (count($this->attachments->getErrors()->get('attachments')) > 0) {
|
||||
Session::flash('error', $this->attachments->getErrors()->get('attachments'));
|
||||
session()->flash('error', $this->attachments->getErrors()->get('attachments'));
|
||||
}
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
Session::flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
@@ -421,7 +421,7 @@ class SingleController extends Controller
|
||||
// update, get events by date and sort DESC
|
||||
|
||||
$type = strtolower($this->repository->getTransactionType($journal));
|
||||
Session::flash('success', (string)trans('firefly.updated_' . $type, ['description' => $data['description']]));
|
||||
session()->flash('success', (string)trans('firefly.updated_' . $type, ['description' => $data['description']]));
|
||||
Preferences::mark();
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
|
@@ -159,12 +159,12 @@ class SplitController extends Controller
|
||||
// flash messages
|
||||
// @codeCoverageIgnoreStart
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
Session::flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
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]));
|
||||
session()->flash('success', (string)trans('firefly.updated_' . $type, ['description' => $journal->description]));
|
||||
Preferences::mark();
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
|
Reference in New Issue
Block a user