From fb6c67fa046452ee0e4cb80e0bbbe6f10f6c5d0e Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 14 Dec 2024 08:10:58 +0100 Subject: [PATCH] Fix https://github.com/firefly-iii/firefly-iii/issues/9532 --- app/Console/Commands/Integrity/ReportSum.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/Integrity/ReportSum.php b/app/Console/Commands/Integrity/ReportSum.php index 62ab39afbb..d348468aba 100644 --- a/app/Console/Commands/Integrity/ReportSum.php +++ b/app/Console/Commands/Integrity/ReportSum.php @@ -59,18 +59,22 @@ class ReportSum extends Command /** @var User $user */ foreach ($userRepository->all() as $user) { - $sum = (string)$user->transactions()->selectRaw('SUM(amount) + SUM(foreign_amount) as total')->value('total'); - if (!is_numeric($sum)) { - $message = sprintf('Error: Transactions for user #%d (%s) have an invalid sum ("%s").', $user->id, $user->email, $sum); + $sum = (string) $user->transactions()->selectRaw('SUM(amount) as total')->value('total'); + $foreign = (string) $user->transactions()->selectRaw('SUM(foreign_amount) as total')->value('total'); + $sum = '' === $sum ? '0' : $sum; + $foreign = '' === $foreign ? '0' : $foreign; + $total = bcadd($sum, $foreign); + if (!is_numeric($total)) { + $message = sprintf('Error: Transactions for user #%d (%s) have an invalid sum ("%s").', $user->id, $user->email, $total); $this->friendlyError($message); continue; } - if (0 !== bccomp($sum, '0')) { - $message = sprintf('Error: Transactions for user #%d (%s) are off by %s!', $user->id, $user->email, $sum); + if (0 !== bccomp($total, '0')) { + $message = sprintf('Error: Transactions for user #%d (%s) are off by %s!', $user->id, $user->email, $total); $this->friendlyError($message); } - if (0 === bccomp($sum, '0')) { + if (0 === bccomp($total, '0')) { $this->friendlyPositive(sprintf('Amount integrity OK for user #%d', $user->id)); } }