Files
firefly-iii/app/Http/Controllers/Transaction/SingleController.php

467 lines
19 KiB
PHP
Raw Normal View History

2016-10-21 19:20:03 +02:00
<?php
/**
* SingleController.php
2017-10-21 08:40:00 +02:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
2016-10-21 19:20:03 +02:00
*
2017-10-21 08:40:00 +02:00
* This file is part of Firefly III.
2016-10-21 19:20:03 +02:00
*
2017-10-21 08:40:00 +02:00
* 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
2017-12-17 14:44:05 +01:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2016-10-21 19:20:03 +02:00
*/
declare(strict_types=1);
2016-10-21 19:20:03 +02:00
namespace FireflyIII\Http\Controllers\Transaction;
2017-08-21 17:11:18 +02:00
use Carbon\Carbon;
2016-10-22 09:31:27 +02:00
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Events\UpdatedTransactionJournal;
2016-10-21 19:20:03 +02:00
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\JournalFormRequest;
2017-10-06 15:41:21 +02:00
use FireflyIII\Models\Note;
2017-07-07 17:51:14 +02:00
use FireflyIII\Models\Transaction;
2016-10-21 19:20:03 +02:00
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Http\RedirectResponse;
2017-11-24 17:33:05 +01:00
use Illuminate\Http\Request;
2016-10-21 19:20:03 +02:00
use Log;
use View;
/**
2017-11-15 12:25:49 +01:00
* Class SingleController.
2018-07-20 14:34:56 +02:00
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2016-10-21 19:20:03 +02:00
*/
class SingleController extends Controller
{
2018-07-22 08:10:16 +02:00
/** @var AttachmentHelperInterface The attachment helper. */
2016-10-21 19:20:03 +02:00
private $attachments;
2018-07-21 08:06:24 +02:00
/** @var BudgetRepositoryInterface The budget repository */
2016-10-21 19:20:03 +02:00
private $budgets;
/** @var JournalRepositoryInterface Journals and transactions overview */
2017-07-04 16:31:16 +02:00
private $repository;
2016-10-21 19:20:03 +02:00
/**
2018-07-22 08:10:16 +02:00
* SingleController constructor.
2016-10-21 19:20:03 +02:00
*/
public function __construct()
{
parent::__construct();
2017-11-25 20:54:42 +01:00
$maxFileSize = app('steam')->phpBytes(ini_get('upload_max_filesize'));
$maxPostSize = app('steam')->phpBytes(ini_get('post_max_size'));
2016-10-21 19:20:03 +02:00
$uploadSize = min($maxFileSize, $maxPostSize);
app('view')->share('uploadSize', $uploadSize);
2016-10-21 19:20:03 +02:00
// some useful repositories:
$this->middleware(
function ($request, $next) {
$this->budgets = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
2017-07-04 16:31:16 +02:00
$this->repository = app(JournalRepositoryInterface::class);
2016-10-21 19:20:03 +02:00
2018-07-15 09:38:49 +02:00
app('view')->share('title', (string)trans('firefly.transactions'));
2017-12-16 19:46:36 +01:00
app('view')->share('mainTitleIcon', 'fa-repeat');
2016-10-29 07:44:46 +02:00
2016-10-21 19:20:03 +02:00
return $next($request);
}
);
}
2017-12-17 14:30:53 +01:00
/**
2018-07-22 08:10:16 +02:00
* CLone a transaction.
*
2017-12-17 14:30:53 +01:00
* @param TransactionJournal $journal
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
2018-07-20 14:34:56 +02:00
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2017-12-17 14:30:53 +01:00
*/
public function cloneTransaction(TransactionJournal $journal)
{
$source = $this->repository->getJournalSourceAccounts($journal)->first();
$destination = $this->repository->getJournalDestinationAccounts($journal)->first();
$budgetId = $this->repository->getJournalBudgetId($journal);
$categoryName = $this->repository->getJournalCategoryName($journal);
2018-06-21 18:58:27 +02:00
$tags = implode(',', $this->repository->getTags($journal));
2017-07-07 17:51:14 +02:00
/** @var Transaction $transaction */
2017-06-12 17:21:31 +02:00
$transaction = $journal->transactions()->first();
2017-11-25 20:54:42 +01:00
$amount = app('steam')->positive($transaction->amount);
$foreignAmount = null === $transaction->foreign_amount ? null : app('steam')->positive($transaction->foreign_amount);
$preFilled = [
2017-07-07 17:51:14 +02:00
'description' => $journal->description,
2018-06-30 05:21:21 +02:00
'source_id' => $source->id,
'source_name' => $source->name,
'destination_id' => $destination->id,
'destination_name' => $destination->name,
2017-07-07 17:51:14 +02:00
'amount' => $amount,
'source_amount' => $amount,
'destination_amount' => $foreignAmount,
'foreign_amount' => $foreignAmount,
2017-07-08 06:09:17 +02:00
'native_amount' => $foreignAmount,
2017-07-07 17:51:14 +02:00
'amount_currency_id_amount' => $transaction->foreign_currency_id ?? 0,
2017-08-21 17:11:18 +02:00
'date' => (new Carbon())->format('Y-m-d'),
2017-07-07 17:51:14 +02:00
'budget_id' => $budgetId,
'category' => $categoryName,
'tags' => $tags,
2018-07-08 07:59:58 +02:00
'interest_date' => $this->repository->getMetaField($journal, 'interest_date'),
'book_date' => $this->repository->getMetaField($journal, 'book_date'),
'process_date' => $this->repository->getMetaField($journal, 'process_date'),
'due_date' => $this->repository->getMetaField($journal, 'due_date'),
'payment_date' => $this->repository->getMetaField($journal, 'payment_date'),
'invoice_date' => $this->repository->getMetaField($journal, 'invoice_date'),
'internal_reference' => $this->repository->getMetaField($journal, 'internal_reference'),
2017-10-06 15:41:21 +02:00
'notes' => '',
];
2017-10-06 15:41:21 +02:00
/** @var Note $note */
2017-12-23 17:42:07 +01:00
$note = $this->repository->getNote($journal);
2017-11-15 12:25:49 +01:00
if (null !== $note) {
2017-10-06 15:41:21 +02:00
$preFilled['notes'] = $note->text;
}
2018-04-22 17:10:11 +02:00
session()->flash('preFilled', $preFilled);
return redirect(route('transactions.create', [strtolower($journal->transactionType->type)]));
}
2016-10-21 19:20:03 +02:00
/**
2018-07-22 08:10:16 +02:00
* Create a new journal.
*
2018-07-08 12:08:53 +02:00
* @param Request $request
* @param string|null $what
2016-10-21 19:20:03 +02:00
*
2018-07-08 12:08:53 +02:00
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
2018-07-20 14:34:56 +02:00
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
2016-10-21 19:20:03 +02:00
*/
2018-07-08 12:08:53 +02:00
public function create(Request $request, string $what = null)
2016-10-21 19:20:03 +02:00
{
2018-07-08 12:08:53 +02:00
$what = strtolower($what ?? TransactionType::DEPOSIT);
2018-07-08 07:59:58 +02:00
$what = (string)($request->old('what') ?? $what);
2018-07-15 15:45:45 +02:00
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
2018-04-22 17:12:22 +02:00
$preFilled = session()->has('preFilled') ? session('preFilled') : [];
2018-07-15 09:38:49 +02:00
$subTitle = (string)trans('form.add_new_' . $what);
2016-10-21 19:20:03 +02:00
$subTitleIcon = 'fa-plus';
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
2018-04-02 15:10:40 +02:00
$source = (int)$request->get('source');
2018-02-28 07:22:11 +01:00
2018-07-02 15:37:56 +02:00
// grab old currency ID from old data:
2018-07-08 07:59:58 +02:00
$currencyID = (int)$request->old('amount_currency_id_amount');
2018-07-02 15:37:56 +02:00
$preFilled['amount_currency_id_amount'] = $currencyID;
2018-07-08 07:59:58 +02:00
if (('withdrawal' === $what || 'transfer' === $what) && $source > 0) {
2018-06-30 05:21:21 +02:00
$preFilled['source_id'] = $source;
2018-02-28 07:22:11 +01:00
}
2018-07-08 07:59:58 +02:00
if ('deposit' === $what && $source > 0) {
2018-06-30 05:21:21 +02:00
$preFilled['destination_id'] = $source;
2018-02-28 07:22:11 +01:00
}
2016-10-21 19:20:03 +02:00
2018-04-22 17:12:22 +02:00
session()->put('preFilled', $preFilled);
2016-10-21 19:20:03 +02:00
// put previous url in session if not redirect from store (not "create another").
2017-11-15 12:25:49 +01:00
if (true !== session('transactions.create.fromStore')) {
2017-02-05 08:26:54 +01:00
$this->rememberPreviousUri('transactions.create.uri');
2016-10-21 19:20:03 +02:00
}
2018-04-22 17:12:22 +02:00
session()->forget('transactions.create.fromStore');
2016-10-21 19:20:03 +02:00
return view(
'transactions.single.create',
compact('subTitleIcon', 'budgets', 'what', 'subTitle', 'optionalFields', 'preFilled')
);
2016-10-21 19:20:03 +02:00
}
/**
* Shows the form that allows a user to delete a transaction journal.
*
* @param TransactionJournal $journal
*
2017-07-23 08:16:11 +02:00
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
2016-10-21 19:20:03 +02:00
*/
public function delete(TransactionJournal $journal)
{
2017-03-03 18:19:25 +01:00
// Covered by another controller's tests
// @codeCoverageIgnoreStart
2016-11-22 19:10:17 +01:00
if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal);
}
2017-03-03 18:19:25 +01:00
// @codeCoverageIgnoreEnd
2016-11-22 19:10:17 +01:00
2016-10-21 19:20:03 +02:00
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
2018-07-15 09:38:49 +02:00
$subTitle = (string)trans('firefly.delete_' . $what, ['description' => $journal->description]);
2016-10-21 19:20:03 +02:00
// put previous url in session
2017-02-05 08:26:54 +01:00
$this->rememberPreviousUri('transactions.delete.uri');
2016-10-21 19:20:03 +02:00
return view('transactions.single.delete', compact('journal', 'subTitle', 'what'));
2016-10-21 19:20:03 +02:00
}
/**
2018-07-22 08:10:16 +02:00
* Actually destroys the journal.
*
2017-08-11 05:42:15 +02:00
* @param TransactionJournal $transactionJournal
2016-10-21 19:20:03 +02:00
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(TransactionJournal $transactionJournal): RedirectResponse
2016-10-21 19:20:03 +02:00
{
2017-03-03 18:19:25 +01:00
// @codeCoverageIgnoreStart
2016-11-22 19:10:17 +01:00
if ($this->isOpeningBalance($transactionJournal)) {
return $this->redirectToAccount($transactionJournal);
}
2017-03-03 18:19:25 +01:00
// @codeCoverageIgnoreEnd
$type = $this->repository->getTransactionType($transactionJournal);
2018-04-22 17:10:11 +02:00
session()->flash('success', (string)trans('firefly.deleted_' . strtolower($type), ['description' => $transactionJournal->description]));
2016-10-21 19:20:03 +02:00
2018-02-18 10:31:15 +01:00
$this->repository->destroy($transactionJournal);
2016-10-21 19:20:03 +02:00
2018-07-08 12:08:53 +02:00
app('preferences')->mark();
2016-10-21 19:20:03 +02:00
2017-02-05 08:26:54 +01:00
return redirect($this->getPreviousUri('transactions.delete.uri'));
2016-10-21 19:20:03 +02:00
}
/**
2018-07-22 08:10:16 +02:00
* Edit a journal.
*
2018-03-11 16:24:07 +01:00
* @param TransactionJournal $journal
*
* @param JournalRepositoryInterface $repository
2016-10-21 19:20:03 +02:00
*
* @return mixed
2018-07-20 14:34:56 +02:00
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
2016-10-21 19:20:03 +02:00
*/
public function edit(TransactionJournal $journal, JournalRepositoryInterface $repository)
2016-10-21 19:20:03 +02:00
{
$transactionType = $repository->getTransactionType($journal);
// redirect to account:
if ($transactionType === TransactionType::OPENING_BALANCE) {
2016-11-22 19:10:17 +01:00
return $this->redirectToAccount($journal);
}
// redirect to reconcile edit:
if ($transactionType === TransactionType::RECONCILIATION) {
return redirect(route('accounts.reconcile.edit', [$journal->id]));
}
// redirect to split edit:
2017-07-04 16:31:16 +02:00
if ($this->isSplitJournal($journal)) {
2016-12-06 08:59:08 +01:00
return redirect(route('transactions.split.edit', [$journal->id]));
2016-10-21 19:20:03 +02:00
}
2018-03-07 10:18:22 +01:00
$what = strtolower($transactionType);
2018-07-15 15:45:45 +02:00
$budgetList = app('expandedform')->makeSelectListWithEmpty($this->budgets->getBudgets());
2016-10-21 19:20:03 +02:00
// view related code
2018-07-15 09:38:49 +02:00
$subTitle = (string)trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
2016-11-22 19:10:17 +01:00
2016-10-21 19:20:03 +02:00
// journal related code
$sourceAccounts = $repository->getJournalSourceAccounts($journal);
$destinationAccounts = $repository->getJournalDestinationAccounts($journal);
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
$pTransaction = $repository->getFirstPosTransaction($journal);
2018-04-02 15:10:40 +02:00
$foreignCurrency = $pTransaction->foreignCurrency ?? $pTransaction->transactionCurrency;
2016-10-21 19:20:03 +02:00
$preFilled = [
2018-06-30 05:21:21 +02:00
'date' => $repository->getJournalDate($journal, null), // $journal->dateAsString()
'interest_date' => $repository->getJournalDate($journal, 'interest_date'),
'book_date' => $repository->getJournalDate($journal, 'book_date'),
'process_date' => $repository->getJournalDate($journal, 'process_date'),
'category' => $repository->getJournalCategoryName($journal),
'budget_id' => $repository->getJournalBudgetId($journal),
'tags' => implode(',', $repository->getTags($journal)),
'source_id' => $sourceAccounts->first()->id,
'source_name' => $sourceAccounts->first()->edit_name,
'destination_id' => $destinationAccounts->first()->id,
'destination_name' => $destinationAccounts->first()->edit_name,
2016-10-21 19:20:03 +02:00
// new custom fields:
2018-06-30 05:21:21 +02:00
'due_date' => $repository->getJournalDate($journal, 'due_date'),
'payment_date' => $repository->getJournalDate($journal, 'payment_date'),
'invoice_date' => $repository->getJournalDate($journal, 'invoice_date'),
'interal_reference' => $repository->getMetaField($journal, 'internal_reference'),
'notes' => $repository->getNoteText($journal),
// amount fields
2018-06-30 05:21:21 +02:00
'amount' => $pTransaction->amount,
'source_amount' => $pTransaction->amount,
'native_amount' => $pTransaction->amount,
'destination_amount' => $pTransaction->foreign_amount,
'currency' => $pTransaction->transactionCurrency,
'source_currency' => $pTransaction->transactionCurrency,
'native_currency' => $pTransaction->transactionCurrency,
'foreign_currency' => $foreignCurrency,
'destination_currency' => $foreignCurrency,
2016-10-21 19:20:03 +02:00
];
// amounts for withdrawals and deposits:
2017-06-05 11:12:50 +02:00
// amount, native_amount, source_amount, destination_amount
2018-07-08 12:08:53 +02:00
if (null !== $pTransaction->foreign_amount && ($journal->isWithdrawal() || $journal->isDeposit())) {
$preFilled['amount'] = $pTransaction->foreign_amount;
$preFilled['currency'] = $pTransaction->foreignCurrency;
}
2018-04-22 17:10:11 +02:00
session()->flash('preFilled', $preFilled);
2016-10-21 19:20:03 +02:00
// put previous url in session if not redirect from store (not "return_to_edit").
2017-11-15 12:25:49 +01:00
if (true !== session('transactions.edit.fromUpdate')) {
2017-02-05 08:26:54 +01:00
$this->rememberPreviousUri('transactions.edit.uri');
2016-10-21 19:20:03 +02:00
}
2018-04-22 17:12:22 +02:00
session()->forget('transactions.edit.fromUpdate');
2016-10-21 19:20:03 +02:00
return view(
'transactions.single.edit',
2018-03-07 10:18:22 +01:00
compact('journal', 'optionalFields', 'what', 'budgetList', 'subTitle')
2016-10-21 19:20:03 +02:00
)->with('data', $preFilled);
}
/**
2018-07-22 08:10:16 +02:00
* Stores a new journal.
*
2016-10-21 19:20:03 +02:00
* @param JournalFormRequest $request
* @param JournalRepositoryInterface $repository
*
* @return RedirectResponse
* @throws \FireflyIII\Exceptions\FireflyException
2018-07-20 14:34:56 +02:00
*
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
2016-10-21 19:20:03 +02:00
*/
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository): RedirectResponse
2016-10-21 19:20:03 +02:00
{
2018-04-02 15:10:40 +02:00
$doSplit = 1 === (int)$request->get('split_journal');
$createAnother = 1 === (int)$request->get('create_another');
$data = $request->getJournalData();
$journal = $repository->store($data);
2017-11-15 12:25:49 +01:00
if (null === $journal->id) {
2016-10-21 19:20:03 +02:00
// error!
2018-04-02 15:10:40 +02:00
Log::error('Could not store transaction journal.');
2018-04-22 17:10:11 +02:00
session()->flash('error', (string)trans('firefly.unknown_journal_error'));
2016-10-21 19:20:03 +02:00
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
}
2017-01-14 19:43:33 +01:00
/** @var array $files */
2016-12-28 13:02:56 +01:00
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$this->attachments->saveAttachmentsForModel($journal, $files);
2016-10-21 19:20:03 +02:00
// store the journal only, flash the rest.
2017-10-27 12:59:43 +02:00
Log::debug(sprintf('Count of error messages is %d', $this->attachments->getErrors()->count()));
2018-04-02 15:10:40 +02:00
if (\count($this->attachments->getErrors()->get('attachments')) > 0) {
2018-04-22 17:10:11 +02:00
session()->flash('error', $this->attachments->getErrors()->get('attachments'));
2016-10-21 19:20:03 +02:00
}
// flash messages
2018-04-02 15:10:40 +02:00
if (\count($this->attachments->getMessages()->get('attachments')) > 0) {
2018-04-22 17:10:11 +02:00
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
2016-10-21 19:20:03 +02:00
}
2016-10-22 09:31:27 +02:00
event(new StoredTransactionJournal($journal, $data['piggy_bank_id']));
2016-10-21 19:20:03 +02:00
2018-04-22 17:10:11 +02:00
session()->flash('success', (string)trans('firefly.stored_journal', ['description' => $journal->description]));
2018-07-08 12:08:53 +02:00
app('preferences')->mark();
2016-10-21 19:20:03 +02:00
2017-03-03 18:19:25 +01:00
// @codeCoverageIgnoreStart
2017-11-15 12:25:49 +01:00
if (true === $createAnother) {
2018-04-22 17:12:22 +02:00
session()->put('transactions.create.fromStore', true);
2016-10-21 19:20:03 +02:00
return redirect(route('transactions.create', [$request->input('what')]))->withInput();
}
2017-11-15 12:25:49 +01:00
if (true === $doSplit) {
2016-12-06 08:59:08 +01:00
return redirect(route('transactions.split.edit', [$journal->id]));
2016-10-21 19:20:03 +02:00
}
2017-03-03 18:19:25 +01:00
// @codeCoverageIgnoreEnd
2016-10-21 19:20:03 +02:00
2017-02-05 08:26:54 +01:00
return redirect($this->getPreviousUri('transactions.create.uri'));
2016-10-21 19:20:03 +02:00
}
/**
2018-07-22 08:10:16 +02:00
* Update a journal.
*
2017-06-07 08:18:42 +02:00
* @param JournalFormRequest $request
* @param JournalRepositoryInterface $repository
* @param TransactionJournal $journal
2016-10-21 19:20:03 +02:00
*
2016-10-22 09:39:31 +02:00
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
2018-07-20 14:34:56 +02:00
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
2016-10-21 19:20:03 +02:00
*/
2017-06-07 08:18:42 +02:00
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
2016-10-21 19:20:03 +02:00
{
2017-03-03 18:19:25 +01:00
// @codeCoverageIgnoreStart
2016-11-22 19:10:17 +01:00
if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal);
}
2017-03-03 18:19:25 +01:00
// @codeCoverageIgnoreEnd
2016-11-22 19:10:17 +01:00
2018-04-22 12:01:18 +02:00
$data = $request->getJournalData();
// keep current bill:
$data['bill_id'] = $journal->bill_id;
2017-06-07 08:18:42 +02:00
$journal = $repository->update($journal, $data);
2017-01-14 19:43:33 +01:00
/** @var array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
2016-12-28 13:02:56 +01:00
$this->attachments->saveAttachmentsForModel($journal, $files);
2016-10-21 19:20:03 +02:00
2017-03-03 18:19:25 +01:00
// @codeCoverageIgnoreStart
2018-04-28 06:23:13 +02:00
if (\count($this->attachments->getErrors()->get('attachments')) > 0) {
2018-04-22 17:10:11 +02:00
session()->flash('error', $this->attachments->getErrors()->get('attachments'));
2016-10-21 19:20:03 +02:00
}
2018-04-28 06:23:13 +02:00
if (\count($this->attachments->getMessages()->get('attachments')) > 0) {
2018-04-22 17:10:11 +02:00
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
2016-10-21 19:20:03 +02:00
}
2017-03-03 18:19:25 +01:00
// @codeCoverageIgnoreEnd
2016-10-21 19:20:03 +02:00
2016-10-22 09:31:27 +02:00
event(new UpdatedTransactionJournal($journal));
2016-10-21 19:20:03 +02:00
// update, get events by date and sort DESC
$type = strtolower($this->repository->getTransactionType($journal));
2018-04-22 17:10:11 +02:00
session()->flash('success', (string)trans('firefly.updated_' . $type, ['description' => $data['description']]));
2018-07-08 12:08:53 +02:00
app('preferences')->mark();
2016-10-21 19:20:03 +02:00
2017-03-03 18:19:25 +01:00
// @codeCoverageIgnoreStart
2018-04-02 15:10:40 +02:00
if (1 === (int)$request->get('return_to_edit')) {
2018-04-22 17:12:22 +02:00
session()->put('transactions.edit.fromUpdate', true);
2016-10-21 19:20:03 +02:00
return redirect(route('transactions.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);
}
2017-03-03 18:19:25 +01:00
// @codeCoverageIgnoreEnd
2016-10-21 19:20:03 +02:00
// redirect to previous URL.
2017-02-05 08:26:54 +01:00
return redirect($this->getPreviousUri('transactions.edit.uri'));
2016-10-21 19:20:03 +02:00
}
2017-07-04 16:31:16 +02:00
/**
2018-07-22 08:10:16 +02:00
* Checks if journal is split.
*
2017-07-04 16:31:16 +02:00
* @param TransactionJournal $journal
*
* @return bool
*/
private function isSplitJournal(TransactionJournal $journal): bool
{
$count = $this->repository->countTransactions($journal);
2018-03-26 19:19:11 +02:00
return $count > 2;
2017-07-04 16:31:16 +02:00
}
2016-10-23 12:42:44 +02:00
}