mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-16 11:28:50 +00:00
Fix #11346
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*
|
||||
* ClearsEmptyForeignAmounts.php
|
||||
* Copyright (c) 2025 james@firefly-iii.org
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) }}
|
||||
|
||||
Reference in New Issue
Block a user