mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-30 14:58:02 +00:00 
			
		
		
		
	Simplify edit transaction routine.
This commit is contained in:
		| @@ -54,6 +54,9 @@ class SingleController extends Controller | |||||||
|     /** @var  PiggyBankRepositoryInterface */ |     /** @var  PiggyBankRepositoryInterface */ | ||||||
|     private $piggyBanks; |     private $piggyBanks; | ||||||
|  |  | ||||||
|  |     /** @var  JournalRepositoryInterface */ | ||||||
|  |     private $repository; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * |      * | ||||||
|      */ |      */ | ||||||
| @@ -74,6 +77,7 @@ class SingleController extends Controller | |||||||
|                 $this->piggyBanks  = app(PiggyBankRepositoryInterface::class); |                 $this->piggyBanks  = app(PiggyBankRepositoryInterface::class); | ||||||
|                 $this->attachments = app(AttachmentHelperInterface::class); |                 $this->attachments = app(AttachmentHelperInterface::class); | ||||||
|                 $this->currency    = app(CurrencyRepositoryInterface::class); |                 $this->currency    = app(CurrencyRepositoryInterface::class); | ||||||
|  |                 $this->repository  = app(JournalRepositoryInterface::class); | ||||||
|  |  | ||||||
|                 View::share('title', trans('firefly.transactions')); |                 View::share('title', trans('firefly.transactions')); | ||||||
|                 View::share('mainTitleIcon', 'fa-repeat'); |                 View::share('mainTitleIcon', 'fa-repeat'); | ||||||
| @@ -196,7 +200,7 @@ class SingleController extends Controller | |||||||
|      * |      * | ||||||
|      * @return \Illuminate\Http\RedirectResponse |      * @return \Illuminate\Http\RedirectResponse | ||||||
|      */ |      */ | ||||||
|     public function destroy(JournalRepositoryInterface $repository, TransactionJournal $transactionJournal) |     public function destroy(TransactionJournal $transactionJournal) | ||||||
|     { |     { | ||||||
|         // @codeCoverageIgnoreStart |         // @codeCoverageIgnoreStart | ||||||
|         if ($this->isOpeningBalance($transactionJournal)) { |         if ($this->isOpeningBalance($transactionJournal)) { | ||||||
| @@ -206,7 +210,7 @@ class SingleController extends Controller | |||||||
|         $type = $transactionJournal->transactionTypeStr(); |         $type = $transactionJournal->transactionTypeStr(); | ||||||
|         Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => e($transactionJournal->description)]))); |         Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => e($transactionJournal->description)]))); | ||||||
|  |  | ||||||
|         $repository->delete($transactionJournal); |         $this->repository->delete($transactionJournal); | ||||||
|  |  | ||||||
|         Preferences::mark(); |         Preferences::mark(); | ||||||
|  |  | ||||||
| @@ -225,10 +229,7 @@ class SingleController extends Controller | |||||||
|             return $this->redirectToAccount($journal); |             return $this->redirectToAccount($journal); | ||||||
|         } |         } | ||||||
|         // @codeCoverageIgnoreEnd |         // @codeCoverageIgnoreEnd | ||||||
|  |         if ($this->isSplitJournal($journal)) { | ||||||
|         $count = $journal->transactions()->count(); |  | ||||||
|  |  | ||||||
|         if ($count > 2) { |  | ||||||
|             return redirect(route('transactions.split.edit', [$journal->id])); |             return redirect(route('transactions.split.edit', [$journal->id])); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -244,6 +245,7 @@ class SingleController extends Controller | |||||||
|         $destinationAccounts = $journal->destinationAccountList(); |         $destinationAccounts = $journal->destinationAccountList(); | ||||||
|         $optionalFields      = Preferences::get('transaction_journal_optional_fields', [])->data; |         $optionalFields      = Preferences::get('transaction_journal_optional_fields', [])->data; | ||||||
|         $pTransaction        = $journal->positiveTransaction(); |         $pTransaction        = $journal->positiveTransaction(); | ||||||
|  |         $foreignCurrency     = !is_null($pTransaction->foreignCurrency) ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency; | ||||||
|         $preFilled           = [ |         $preFilled           = [ | ||||||
|             'date'                     => $journal->dateAsString(), |             'date'                     => $journal->dateAsString(), | ||||||
|             'interest_date'            => $journal->dateAsString('interest_date'), |             'interest_date'            => $journal->dateAsString('interest_date'), | ||||||
| @@ -272,8 +274,8 @@ class SingleController extends Controller | |||||||
|             'currency'                 => $pTransaction->transactionCurrency, |             'currency'                 => $pTransaction->transactionCurrency, | ||||||
|             'source_currency'          => $pTransaction->transactionCurrency, |             'source_currency'          => $pTransaction->transactionCurrency, | ||||||
|             'native_currency'          => $pTransaction->transactionCurrency, |             'native_currency'          => $pTransaction->transactionCurrency, | ||||||
|             'foreign_currency'         => !is_null($pTransaction->foreignCurrency) ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency, |             'foreign_currency'         => $foreignCurrency, | ||||||
|             'destination_currency'     => !is_null($pTransaction->foreignCurrency) ? $pTransaction->foreignCurrency : $pTransaction->transactionCurrency, |             'destination_currency'     => $foreignCurrency, | ||||||
|         ]; |         ]; | ||||||
|  |  | ||||||
|         // amounts for withdrawals and deposits: |         // amounts for withdrawals and deposits: | ||||||
| @@ -283,21 +285,6 @@ class SingleController extends Controller | |||||||
|             $preFilled['currency'] = $pTransaction->foreignCurrency; |             $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('preFilled', $preFilled); | ||||||
|         Session::flash('gaEventCategory', 'transactions'); |         Session::flash('gaEventCategory', 'transactions'); | ||||||
|         Session::flash('gaEventAction', 'edit-' . $what); |         Session::flash('gaEventAction', 'edit-' . $what); | ||||||
| @@ -416,4 +403,20 @@ class SingleController extends Controller | |||||||
|         // redirect to previous URL. |         // redirect to previous URL. | ||||||
|         return redirect($this->getPreviousUri('transactions.edit.uri')); |         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; | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -76,6 +76,16 @@ class JournalRepository implements JournalRepositoryInterface | |||||||
|         return new MessageBag; |         return new MessageBag; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param TransactionJournal $journal | ||||||
|  |      * | ||||||
|  |      * @return int | ||||||
|  |      */ | ||||||
|  |     public function countTransactions(TransactionJournal $journal): int | ||||||
|  |     { | ||||||
|  |         return $journal->transactions()->count(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param TransactionJournal $journal |      * @param TransactionJournal $journal | ||||||
|      * |      * | ||||||
|   | |||||||
| @@ -38,6 +38,13 @@ interface JournalRepositoryInterface | |||||||
|      */ |      */ | ||||||
|     public function convert(TransactionJournal $journal, TransactionType $type, Account $source, Account $destination): MessageBag; |     public function convert(TransactionJournal $journal, TransactionType $type, Account $source, Account $destination): MessageBag; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param TransactionJournal $journal | ||||||
|  |      * | ||||||
|  |      * @return int | ||||||
|  |      */ | ||||||
|  |     public function countTransactions(TransactionJournal $journal): int; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Deletes a journal. |      * Deletes a journal. | ||||||
|      * |      * | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user