From 74992e95f27943c015c7b5741d16042b890b26e6 Mon Sep 17 00:00:00 2001 From: Christian Desktop Date: Sun, 21 May 2023 22:01:58 -0600 Subject: [PATCH] Withdrawal directly from Piggy Bank - Fixes #6631 --- app/Console/Commands/Correction/FixPiggies.php | 14 ++------------ app/Factory/PiggyBankEventFactory.php | 6 ------ app/Factory/TransactionJournalFactory.php | 5 ----- app/TransactionRules/Actions/UpdatePiggybank.php | 6 ------ .../js/components/transactions/PiggyBank.vue | 2 +- 5 files changed, 3 insertions(+), 30 deletions(-) diff --git a/app/Console/Commands/Correction/FixPiggies.php b/app/Console/Commands/Correction/FixPiggies.php index 8d2bca27c0..a7f98d9fb9 100644 --- a/app/Console/Commands/Correction/FixPiggies.php +++ b/app/Console/Commands/Correction/FixPiggies.php @@ -25,11 +25,10 @@ namespace FireflyIII\Console\Commands\Correction; use FireflyIII\Models\PiggyBankEvent; use FireflyIII\Models\TransactionJournal; -use FireflyIII\Models\TransactionType; use Illuminate\Console\Command; /** - * Report (and fix) piggy banks. Make sure there are only transfers linked to piggy bank events. + * Report (and fix) piggy banks. * * Class FixPiggies */ @@ -57,7 +56,7 @@ class FixPiggies extends Command { $count = 0; $start = microtime(true); - $set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal', 'TransactionJournal.TransactionType'])->get(); + $set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal'])->get(); /** @var PiggyBankEvent $event */ foreach ($set as $event) { @@ -73,15 +72,6 @@ class FixPiggies extends Command $count++; continue; } - - - $type = $journal->transactionType->type; - if (TransactionType::TRANSFER !== $type) { - $event->transaction_journal_id = null; - $event->save(); - $this->line(sprintf('Piggy bank #%d was referenced by an invalid event. This has been fixed.', $event->piggy_bank_id)); - $count++; - } } if (0 === $count) { $this->line('All piggy bank events are correct.'); diff --git a/app/Factory/PiggyBankEventFactory.php b/app/Factory/PiggyBankEventFactory.php index 3cfe576a91..09b4be3b31 100644 --- a/app/Factory/PiggyBankEventFactory.php +++ b/app/Factory/PiggyBankEventFactory.php @@ -49,12 +49,6 @@ class PiggyBankEventFactory return; } - if (TransactionType::TRANSFER !== $journal->transactionType->type) { - Log::info(sprintf('Will not connect %s #%d to a piggy bank.', $journal->transactionType->type, $journal->id)); - - return; - } - /** @var PiggyBankRepositoryInterface $piggyRepos */ $piggyRepos = app(PiggyBankRepositoryInterface::class); $piggyRepos->setUser($journal->user); diff --git a/app/Factory/TransactionJournalFactory.php b/app/Factory/TransactionJournalFactory.php index d5eb723a6e..3df1293a52 100644 --- a/app/Factory/TransactionJournalFactory.php +++ b/app/Factory/TransactionJournalFactory.php @@ -569,11 +569,6 @@ class TransactionJournalFactory private function storePiggyEvent(TransactionJournal $journal, NullArrayObject $data): void { Log::debug('Will now store piggy event.'); - if (!$journal->isTransfer()) { - Log::debug('Journal is not a transfer, do nothing.'); - - return; - } $piggyBank = $this->piggyRepository->findPiggyBank((int)$data['piggy_bank_id'], $data['piggy_bank_name']); diff --git a/app/TransactionRules/Actions/UpdatePiggybank.php b/app/TransactionRules/Actions/UpdatePiggybank.php index 2f13ca31b0..96a14032ce 100644 --- a/app/TransactionRules/Actions/UpdatePiggybank.php +++ b/app/TransactionRules/Actions/UpdatePiggybank.php @@ -65,12 +65,6 @@ class UpdatePiggybank implements ActionInterface $type = TransactionType::find((int)$journalObj->transaction_type_id); $journal['transaction_type_type'] = $type->type; - if (TransactionType::TRANSFER !== $journal['transaction_type_type']) { - Log::info(sprintf('Journal #%d is a "%s" so skip this action.', $journal['transaction_journal_id'], $journal['transaction_type_type'])); - - return false; - } - $piggyBank = $this->findPiggyBank($user); if (null === $piggyBank) { Log::info( diff --git a/resources/assets/js/components/transactions/PiggyBank.vue b/resources/assets/js/components/transactions/PiggyBank.vue index 14585aee65..fd0472892f 100644 --- a/resources/assets/js/components/transactions/PiggyBank.vue +++ b/resources/assets/js/components/transactions/PiggyBank.vue @@ -18,7 +18,7 @@ - along with this program. If not, see . -->