Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix #11346
James Cole8f81cb8cc45c
diff --git a/app/Console/Commands/Correction/ClearsEmptyForeignAmounts.php b/app/Console/Commands/Correction/ClearsEmptyForeignAmounts.phpnew file mode 100644index 0000000000..da980aaafa--- /dev/null+++ b/app/Console/Commands/Correction/ClearsEmptyForeignAmounts.php@@ -0,0 +1,64 @@+<?php+/*+ * ClearsEmptyForeignAmounts.php+ * Copyright (c) 2025 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++namespace FireflyIII\Console\Commands\Correction;++use FireflyIII\Console\Commands\ShowsFriendlyMessages;+use FireflyIII\Models\Transaction;+use Illuminate\Console\Command;++class ClearsEmptyForeignAmounts extends Command+{+ use ShowsFriendlyMessages;+ /**+ * The name and signature of the console command.+ *+ * @var string+ */+ protected $signature = 'correction:clears-empty-foreign-amounts';++ /**+ * The console command description.+ *+ * @var string+ */+ protected $description = 'Removes references to foreign amounts if there is no amount.';++ /**+ * Execute the console command.+ */+ public function handle():int+ {+ // transaction: has no amount, but reference to currency.+ $count = Transaction::whereNull('foreign_amount')->whereNotNull('foreign_currency_id')->count();+ if($count > 0) {+ Transaction::whereNull('foreign_amount')->whereNotNull('foreign_currency_id')->update(['foreign_currency_id' => null]);+ $this->friendlyInfo(sprintf('Corrected %d invalid foreign amount reference(s)', $count));+ }+ // transaction: has amount, but no currency.+ $count = Transaction::whereNull('foreign_currency_id')->whereNotNull('foreign_amount')->count();+ if($count > 0) {+ Transaction::whereNull('foreign_currency_id')->whereNotNull('foreign_amount')->update(['foreign_amount' => null]);+ $this->friendlyInfo(sprintf('Corrected %d invalid foreign amount reference(s)', $count));+ }+ return self::SUCCESS;+ }+}diff --git a/app/Console/Commands/Correction/CorrectsDatabase.php b/app/Console/Commands/Correction/CorrectsDatabase.phpindex 8a0c416d41..89d2818f07 100644--- a/app/Console/Commands/Correction/CorrectsDatabase.php+++ b/app/Console/Commands/Correction/CorrectsDatabase.php@@ -78,6 +78,7 @@ class CorrectsDatabase extends Command// 'correction:transaction-types', // resource heavy, disabled.'correction:recalculate-pc-amounts','correction:remove-links-to-deleted-objects',+ 'correction:clears-empty-foreign-amounts','firefly-iii:report-integrity',];foreach ($commands as $command) {diff --git a/resources/views/list/groups.twig b/resources/views/list/groups.twigindex fe4ab310d5..0761699621 100644--- a/resources/views/list/groups.twig+++ b/resources/views/list/groups.twig@@ -277,9 +277,17 @@{% endif %}{% elseif transaction.transaction_type_type == 'Withdrawal' %}+{% if 'Loan' == transaction.destination_account_type or 'Mortgage' == transaction.destination_account_type or 'Debt' == transaction.destination_account_type %}+{% if currency.id == transaction.currency_id %}- {{ formatAmountBySymbol(transaction.destination_balance_after, transaction.currency_symbol, transaction.currency_decimal_places) }}+ {% if account.id == transaction.source_account_id %}+ {{ formatAmountBySymbol(transaction.source_balance_after, transaction.currency_symbol, transaction.currency_decimal_places) }}+ {% endif %}+ {% if account.id == transaction.destination_account_id %}+ {{ formatAmountBySymbol(transaction.destination_balance_after, transaction.currency_symbol, transaction.currency_decimal_places) }}+ {% endif %}+{% endif %}{% if currency.id == transaction.foreign_currency_id and null != transaction.destination_balance_after and null != transaction.destination_balance_after %}{{ formatAmountBySymbol(transaction.destination_balance_after, transaction.foreign_currency_symbol ?? transaction.currency_symbol, transaction.foreign_currency_decimal_places ?? transaction.currency_decimal_places) }}