diff --git a/app/Console/Commands/Correction/ClearsEmptyForeignAmounts.php b/app/Console/Commands/Correction/ClearsEmptyForeignAmounts.php new file mode 100644 index 0000000000..da980aaafa --- /dev/null +++ b/app/Console/Commands/Correction/ClearsEmptyForeignAmounts.php @@ -0,0 +1,64 @@ +. + */ + +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.php index 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.twig index 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) }}