Withdrawal directly from Piggy Bank - Fixes #6631

This commit is contained in:
Christian Desktop 2023-05-21 22:01:58 -06:00 committed by ChrisWin22
parent 6d0906c37b
commit 74992e95f2
5 changed files with 3 additions and 30 deletions

View File

@ -25,11 +25,10 @@ namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Models\PiggyBankEvent; use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command; 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 * Class FixPiggies
*/ */
@ -57,7 +56,7 @@ class FixPiggies extends Command
{ {
$count = 0; $count = 0;
$start = microtime(true); $start = microtime(true);
$set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal', 'TransactionJournal.TransactionType'])->get(); $set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal'])->get();
/** @var PiggyBankEvent $event */ /** @var PiggyBankEvent $event */
foreach ($set as $event) { foreach ($set as $event) {
@ -73,15 +72,6 @@ class FixPiggies extends Command
$count++; $count++;
continue; 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) { if (0 === $count) {
$this->line('All piggy bank events are correct.'); $this->line('All piggy bank events are correct.');

View File

@ -49,12 +49,6 @@ class PiggyBankEventFactory
return; 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 */ /** @var PiggyBankRepositoryInterface $piggyRepos */
$piggyRepos = app(PiggyBankRepositoryInterface::class); $piggyRepos = app(PiggyBankRepositoryInterface::class);
$piggyRepos->setUser($journal->user); $piggyRepos->setUser($journal->user);

View File

@ -569,11 +569,6 @@ class TransactionJournalFactory
private function storePiggyEvent(TransactionJournal $journal, NullArrayObject $data): void private function storePiggyEvent(TransactionJournal $journal, NullArrayObject $data): void
{ {
Log::debug('Will now store piggy event.'); 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']); $piggyBank = $this->piggyRepository->findPiggyBank((int)$data['piggy_bank_id'], $data['piggy_bank_name']);

View File

@ -65,12 +65,6 @@ class UpdatePiggybank implements ActionInterface
$type = TransactionType::find((int)$journalObj->transaction_type_id); $type = TransactionType::find((int)$journalObj->transaction_type_id);
$journal['transaction_type_type'] = $type->type; $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); $piggyBank = $this->findPiggyBank($user);
if (null === $piggyBank) { if (null === $piggyBank) {
Log::info( Log::info(

View File

@ -18,7 +18,7 @@
- along with this program. If not, see <https://www.gnu.org/licenses/>. - along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<template> <template>
<div v-if="typeof this.transactionType !== 'undefined' && this.transactionType === 'Transfer'" <div v-if="typeof this.transactionType !== 'undefined'"
class="form-group" class="form-group"
v-bind:class="{ 'has-error': hasError()}"> v-bind:class="{ 'has-error': hasError()}">
<div class="col-sm-12 text-sm"> <div class="col-sm-12 text-sm">