mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-06 12:45:30 +00:00
Simplify edit transaction routine.
This commit is contained in:
@@ -54,6 +54,9 @@ class SingleController extends Controller
|
||||
/** @var PiggyBankRepositoryInterface */
|
||||
private $piggyBanks;
|
||||
|
||||
/** @var JournalRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -74,6 +77,7 @@ class SingleController extends Controller
|
||||
$this->piggyBanks = app(PiggyBankRepositoryInterface::class);
|
||||
$this->attachments = app(AttachmentHelperInterface::class);
|
||||
$this->currency = app(CurrencyRepositoryInterface::class);
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
|
||||
View::share('title', trans('firefly.transactions'));
|
||||
View::share('mainTitleIcon', 'fa-repeat');
|
||||
@@ -196,7 +200,7 @@ class SingleController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(JournalRepositoryInterface $repository, TransactionJournal $transactionJournal)
|
||||
public function destroy(TransactionJournal $transactionJournal)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($this->isOpeningBalance($transactionJournal)) {
|
||||
@@ -206,7 +210,7 @@ class SingleController extends Controller
|
||||
$type = $transactionJournal->transactionTypeStr();
|
||||
Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => e($transactionJournal->description)])));
|
||||
|
||||
$repository->delete($transactionJournal);
|
||||
$this->repository->delete($transactionJournal);
|
||||
|
||||
Preferences::mark();
|
||||
|
||||
@@ -225,10 +229,7 @@ class SingleController extends Controller
|
||||
return $this->redirectToAccount($journal);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$count = $journal->transactions()->count();
|
||||
|
||||
if ($count > 2) {
|
||||
if ($this->isSplitJournal($journal)) {
|
||||
return redirect(route('transactions.split.edit', [$journal->id]));
|
||||
}
|
||||
|
||||
@@ -244,6 +245,7 @@ class SingleController extends Controller
|
||||
$destinationAccounts = $journal->destinationAccountList();
|
||||
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
$pTransaction = $journal->positiveTransaction();
|
||||
$foreignCurrency = !is_null($pTransaction->foreignCurrency) ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency;
|
||||
$preFilled = [
|
||||
'date' => $journal->dateAsString(),
|
||||
'interest_date' => $journal->dateAsString('interest_date'),
|
||||
@@ -272,8 +274,8 @@ class SingleController extends Controller
|
||||
'currency' => $pTransaction->transactionCurrency,
|
||||
'source_currency' => $pTransaction->transactionCurrency,
|
||||
'native_currency' => $pTransaction->transactionCurrency,
|
||||
'foreign_currency' => !is_null($pTransaction->foreignCurrency) ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency,
|
||||
'destination_currency' => !is_null($pTransaction->foreignCurrency) ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency,
|
||||
'foreign_currency' => $foreignCurrency,
|
||||
'destination_currency' => $foreignCurrency,
|
||||
];
|
||||
|
||||
// amounts for withdrawals and deposits:
|
||||
@@ -283,21 +285,6 @@ class SingleController extends Controller
|
||||
$preFilled['currency'] = $pTransaction->foreignCurrency;
|
||||
}
|
||||
|
||||
if ($journal->isTransfer() && !is_null($pTransaction->foreign_amount)) {
|
||||
$preFilled['destination_amount'] = $pTransaction->foreign_amount;
|
||||
$preFilled['destination_currency'] = $pTransaction->foreignCurrency;
|
||||
}
|
||||
|
||||
// fixes for cash accounts:
|
||||
if ($journal->isWithdrawal() && $destinationAccounts->first()->accountType->type === AccountType::CASH) {
|
||||
$preFilled['destination_account_name'] = '';
|
||||
}
|
||||
|
||||
if ($journal->isDeposit() && $sourceAccounts->first()->accountType->type === AccountType::CASH) {
|
||||
$preFilled['source_account_name'] = '';
|
||||
}
|
||||
|
||||
|
||||
Session::flash('preFilled', $preFilled);
|
||||
Session::flash('gaEventCategory', 'transactions');
|
||||
Session::flash('gaEventAction', 'edit-' . $what);
|
||||
@@ -416,4 +403,20 @@ class SingleController extends Controller
|
||||
// redirect to previous URL.
|
||||
return redirect($this->getPreviousUri('transactions.edit.uri'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isSplitJournal(TransactionJournal $journal): bool
|
||||
{
|
||||
$count = $this->repository->countTransactions($journal);
|
||||
|
||||
if ($count > 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user