mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-09 03:08:09 +00:00
Add checks to fix #3119
This commit is contained in:
@@ -90,11 +90,40 @@ class FixUnevenAmount extends Command
|
|||||||
}
|
}
|
||||||
/** @var Transaction $source */
|
/** @var Transaction $source */
|
||||||
$source = $journal->transactions()->where('amount', '<', 0)->first();
|
$source = $journal->transactions()->where('amount', '<', 0)->first();
|
||||||
|
|
||||||
|
if (null === $source) {
|
||||||
|
$this->error(
|
||||||
|
sprintf(
|
||||||
|
'Journal #%d ("%s") has no source transaction. It will be deleted to maintain database consistency.', $journal->id ?? 0,
|
||||||
|
$journal->description ?? ''
|
||||||
|
)
|
||||||
|
);
|
||||||
|
Transaction::where('transaction_journal_id', $journal->id ?? 0)->forceDelete();
|
||||||
|
TransactionJournal::where('id', $journal-> ?? 0)->forceDelete();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$amount = bcmul('-1', (string)$source->amount);
|
$amount = bcmul('-1', (string)$source->amount);
|
||||||
|
|
||||||
// fix amount of destination:
|
// fix amount of destination:
|
||||||
/** @var Transaction $destination */
|
/** @var Transaction $destination */
|
||||||
$destination = $journal->transactions()->where('amount', '>', 0)->first();
|
$destination = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
|
|
||||||
|
if (null === $destination) {
|
||||||
|
$this->error(
|
||||||
|
sprintf(
|
||||||
|
'Journal #%d ("%s") has no destination transaction. It will be deleted to maintain database consistency.', $journal->id ?? 0,
|
||||||
|
$journal->description ?? ''
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Transaction::where('transaction_journal_id', $journal->id ?? 0)->forceDelete();
|
||||||
|
TransactionJournal::where('id', $journal-> ?? 0)->forceDelete();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$destination->amount = $amount;
|
$destination->amount = $amount;
|
||||||
$destination->save();
|
$destination->save();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user