Rename references to native amounts

This commit is contained in:
James Cole
2025-07-31 20:55:30 +02:00
parent da36d84b79
commit ea6addafe6
16 changed files with 60 additions and 61 deletions

View File

@@ -86,7 +86,7 @@ class CorrectsAmounts extends Command
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach ($journals as $journal) { foreach ($journals as $journal) {
$repository->setUser($journal->user); $repository->setUser($journal->user);
$native = Amount::getPrimaryCurrencyByUserGroup($journal->userGroup); $primary = Amount::getPrimaryCurrencyByUserGroup($journal->userGroup);
/** @var null|Transaction $source */ /** @var null|Transaction $source */
$source = $journal->transactions()->where('amount', '<', 0)->first(); $source = $journal->transactions()->where('amount', '<', 0)->first();
@@ -104,8 +104,8 @@ class CorrectsAmounts extends Command
if (null === $sourceAccount || null === $destAccount) { if (null === $sourceAccount || null === $destAccount) {
continue; continue;
} }
$sourceCurrency = $repository->getAccountCurrency($sourceAccount) ?? $native; $sourceCurrency = $repository->getAccountCurrency($sourceAccount) ?? $primary;
$destCurrency = $repository->getAccountCurrency($destAccount) ?? $native; $destCurrency = $repository->getAccountCurrency($destAccount) ?? $primary;
if ($sourceCurrency->id === $destCurrency->id) { if ($sourceCurrency->id === $destCurrency->id) {
Log::debug('Both accounts have the same currency. Removing foreign currency info.'); Log::debug('Both accounts have the same currency. Removing foreign currency info.');

View File

@@ -75,7 +75,7 @@ class CorrectsDatabase extends Command
'correction:recalculates-liabilities', 'correction:recalculates-liabilities',
'correction:preferences', 'correction:preferences',
// 'correction:transaction-types', // resource heavy, disabled. // 'correction:transaction-types', // resource heavy, disabled.
'correction:recalculate-native-amounts', // not necessary, disabled. 'correction:recalculate-pc-amounts', // not necessary, disabled.
'firefly-iii:report-integrity', 'firefly-iii:report-integrity',
]; ];
foreach ($commands as $command) { foreach ($commands as $command) {

View File

@@ -2,7 +2,7 @@
/* /*
* CorrectsNativeAmounts.php * CorrectsPrimaryCurrencyAmounts.php
* Copyright (c) 2025 james@firefly-iii.org. * Copyright (c) 2025 james@firefly-iii.org.
* *
* This file is part of Firefly III (https://github.com/firefly-iii). * This file is part of Firefly III (https://github.com/firefly-iii).
@@ -48,13 +48,13 @@ use Illuminate\Database\Query\Builder as DatabaseBuilder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
class CorrectsNativeAmounts extends Command class CorrectsPrimaryCurrencyAmounts extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
protected $description = 'Recalculate native amounts for all objects.'; protected $description = 'Recalculate primary currency amounts for all objects.';
protected $signature = 'correction:recalculate-native-amounts'; protected $signature = 'correction:recalculate-pc-amounts';
/** /**
* Execute the console command. * Execute the console command.
@@ -66,8 +66,8 @@ class CorrectsNativeAmounts extends Command
return 0; return 0;
} }
Log::debug('Will update all native amounts. This may take some time.'); Log::debug('Will update all primary currency amounts. This may take some time.');
$this->friendlyWarning('Recalculating native amounts for all objects. This may take some time!'); $this->friendlyWarning('Recalculating primary currency amounts for all objects. This may take some time!');
/** @var UserGroupRepositoryInterface $repository */ /** @var UserGroupRepositoryInterface $repository */
$repository = app(UserGroupRepositoryInterface::class); $repository = app(UserGroupRepositoryInterface::class);
@@ -76,7 +76,7 @@ class CorrectsNativeAmounts extends Command
foreach ($repository->getAll() as $userGroup) { foreach ($repository->getAll() as $userGroup) {
$this->recalculateForGroup($userGroup); $this->recalculateForGroup($userGroup);
} }
$this->friendlyInfo('Recalculated all native amounts.'); $this->friendlyInfo('Recalculated all primary currency amounts.');
return 0; return 0;
} }

View File

@@ -74,7 +74,7 @@ class UpgradesDatabase extends Command
'upgrade:610-currency-preferences', 'upgrade:610-currency-preferences',
'upgrade:610-currency-preferences', 'upgrade:610-currency-preferences',
'upgrade:620-piggy-banks', 'upgrade:620-piggy-banks',
'upgrade:620-native-amounts', 'upgrade:620-pc-amounts',
'firefly-iii:correct-database', 'firefly-iii:correct-database',
]; ];
$args = []; $args = [];

View File

@@ -2,7 +2,7 @@
/* /*
* UpgradesNativeAmounts.php * UpgradesPrimaryCurrencyAmounts.php
* Copyright (c) 2025 james@firefly-iii.org. * Copyright (c) 2025 james@firefly-iii.org.
* *
* This file is part of Firefly III (https://github.com/firefly-iii). * This file is part of Firefly III (https://github.com/firefly-iii).
@@ -29,15 +29,15 @@ use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
class UpgradesNativeAmounts extends Command class UpgradesPrimaryCurrencyAmounts extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
public const string CONFIG_NAME = '620_native_amounts'; public const string CONFIG_NAME = '620_pc_amounts';
protected $description = 'Runs the native amounts calculations.'; protected $description = 'Runs the primary currency amounts calculations.';
protected $signature = 'upgrade:620-native-amounts {--F|force : Force the execution of this command.}'; protected $signature = 'upgrade:620-pc-amounts {--F|force : Force the execution of this command.}';
/** /**
* Execute the console command. * Execute the console command.
@@ -50,7 +50,7 @@ class UpgradesNativeAmounts extends Command
return 0; return 0;
} }
Artisan::call('correction:recalculate-native-amounts'); Artisan::call('correction:recalculate-pc-amounts');
$this->markAsExecuted(); $this->markAsExecuted();

View File

@@ -297,7 +297,7 @@ class TransactionJournalFactory
$transactionFactory->setForeignCurrency($currency); $transactionFactory->setForeignCurrency($currency);
$amount = (string) $row['foreign_amount']; $amount = (string) $row['foreign_amount'];
$foreignAmount = (string) $row['amount']; $foreignAmount = (string) $row['amount'];
Log::debug('Swap native/foreign amounts in transfer for new save method.'); Log::debug('Swap primary/foreign amounts in transfer for new save method.');
} }
try { try {

View File

@@ -177,7 +177,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
$accounts = $this->collectAccounts($model); $accounts = $this->collectAccounts($model);
$enrichment = new AccountEnrichment(); $enrichment = new AccountEnrichment();
$enrichment->setUser($model->user); $enrichment->setUser($model->user);
$enrichment->setNative(Amount::getPrimaryCurrencyByUserGroup($model->userGroup)); $enrichment->setPrimary(Amount::getPrimaryCurrencyByUserGroup($model->userGroup));
$accounts = $enrichment->enrich($accounts); $accounts = $enrichment->enrich($accounts);
foreach ($accounts as $account) { foreach ($accounts as $account) {
$transformer = new AccountTransformer(); $transformer = new AccountTransformer();

View File

@@ -38,17 +38,16 @@ use Illuminate\Support\Facades\Log;
class PreferencesEventHandler class PreferencesEventHandler
{ {
public function resetNativeAmounts(UserGroupChangedDefaultCurrency $event): void public function resetPrimaryCurrencyAmounts(UserGroupChangedDefaultCurrency $event): void
{ {
// Reset the native amounts for all objects that have it. // Reset the primary currency amounts for all objects that have it.
Log::debug('Resetting native amounts for all objects.'); Log::debug('Resetting primary currency amounts for all objects.');
$tables = [ $tables = [
// !!! this array is also in the migration // !!! this array is also in the migration
'accounts' => ['native_virtual_balance'], 'accounts' => ['native_virtual_balance'],
'available_budgets' => ['native_amount'], 'available_budgets' => ['native_amount'],
'bills' => ['native_amount_min', 'native_amount_max'], 'bills' => ['native_amount_min', 'native_amount_max'],
// 'transactions' => ['native_amount', 'native_foreign_amount']
]; ];
foreach ($tables as $table => $columns) { foreach ($tables as $table => $columns) {
foreach ($columns as $column) { foreach ($columns as $column) {
@@ -61,12 +60,12 @@ class PreferencesEventHandler
$this->resetTransactions($event->userGroup); $this->resetTransactions($event->userGroup);
// fire laravel command to recalculate them all. // fire laravel command to recalculate them all.
if (Amount::convertToPrimary()) { if (Amount::convertToPrimary()) {
Log::debug('Will now convert to native.'); Log::debug('Will now convert to primary currency.');
Artisan::call('correction:recalculate-native-amounts'); Artisan::call('correction:recalculate-pc-amounts');
return; return;
} }
Log::debug('Will NOT convert to native.'); Log::debug('Will NOT convert to primary currency.');
} }
private function resetPiggyBanks(UserGroup $userGroup): void private function resetPiggyBanks(UserGroup $userGroup): void

View File

@@ -44,10 +44,10 @@ class AccountObserver
public function created(Account $account): void public function created(Account $account): void
{ {
// Log::debug('Observe "created" of an account.'); // Log::debug('Observe "created" of an account.');
$this->updateNativeAmount($account); $this->updatePrimaryCurrencyAmount($account);
} }
private function updateNativeAmount(Account $account): void private function updatePrimaryCurrencyAmount(Account $account): void
{ {
if (!Amount::convertToPrimary($account->user)) { if (!Amount::convertToPrimary($account->user)) {
return; return;
@@ -67,7 +67,7 @@ class AccountObserver
$account->native_virtual_balance = null; $account->native_virtual_balance = null;
} }
$account->saveQuietly(); $account->saveQuietly();
// Log::debug('Account native virtual balance is updated.'); // Log::debug('Account primary currency virtual balance is updated.');
} }
/** /**
@@ -108,6 +108,6 @@ class AccountObserver
public function updated(Account $account): void public function updated(Account $account): void
{ {
// Log::debug('Observe "updated" of an account.'); // Log::debug('Observe "updated" of an account.');
$this->updateNativeAmount($account); $this->updatePrimaryCurrencyAmount($account);
} }
} }

View File

@@ -34,10 +34,10 @@ class AutoBudgetObserver
public function created(AutoBudget $autoBudget): void public function created(AutoBudget $autoBudget): void
{ {
Log::debug('Observe "created" of an auto budget.'); Log::debug('Observe "created" of an auto budget.');
$this->updateNativeAmount($autoBudget); $this->updatePrimaryCurrencyAmount($autoBudget);
} }
private function updateNativeAmount(AutoBudget $autoBudget): void private function updatePrimaryCurrencyAmount(AutoBudget $autoBudget): void
{ {
if (!Amount::convertToPrimary($autoBudget->budget->user)) { if (!Amount::convertToPrimary($autoBudget->budget->user)) {
return; return;
@@ -51,12 +51,12 @@ class AutoBudgetObserver
$autoBudget->native_amount = $converter->convert($autoBudget->transactionCurrency, $userCurrency, today(), $autoBudget->amount); $autoBudget->native_amount = $converter->convert($autoBudget->transactionCurrency, $userCurrency, today(), $autoBudget->amount);
} }
$autoBudget->saveQuietly(); $autoBudget->saveQuietly();
Log::debug('Auto budget native amount is updated.'); Log::debug('Auto budget primary currency amount is updated.');
} }
public function updated(AutoBudget $autoBudget): void public function updated(AutoBudget $autoBudget): void
{ {
Log::debug('Observe "updated" of an auto budget.'); Log::debug('Observe "updated" of an auto budget.');
$this->updateNativeAmount($autoBudget); $this->updatePrimaryCurrencyAmount($autoBudget);
} }
} }

View File

@@ -34,13 +34,13 @@ class AvailableBudgetObserver
public function created(AvailableBudget $availableBudget): void public function created(AvailableBudget $availableBudget): void
{ {
// Log::debug('Observe "created" of an available budget.'); // Log::debug('Observe "created" of an available budget.');
$this->updateNativeAmount($availableBudget); $this->updatePrimaryCurrencyAmount($availableBudget);
} }
private function updateNativeAmount(AvailableBudget $availableBudget): void private function updatePrimaryCurrencyAmount(AvailableBudget $availableBudget): void
{ {
if (!Amount::convertToPrimary($availableBudget->user)) { if (!Amount::convertToPrimary($availableBudget->user)) {
// Log::debug('Do not update native available amount of the available budget.'); // Log::debug('Do not update primary currency available amount of the available budget.');
return; return;
} }
@@ -53,12 +53,12 @@ class AvailableBudgetObserver
$availableBudget->native_amount = $converter->convert($availableBudget->transactionCurrency, $userCurrency, today(), $availableBudget->amount); $availableBudget->native_amount = $converter->convert($availableBudget->transactionCurrency, $userCurrency, today(), $availableBudget->amount);
} }
$availableBudget->saveQuietly(); $availableBudget->saveQuietly();
Log::debug('Available budget native amount is updated.'); Log::debug('Available budget primary currency amount is updated.');
} }
public function updated(AvailableBudget $availableBudget): void public function updated(AvailableBudget $availableBudget): void
{ {
// Log::debug('Observe "updated" of an available budget.'); // Log::debug('Observe "updated" of an available budget.');
$this->updateNativeAmount($availableBudget); $this->updatePrimaryCurrencyAmount($availableBudget);
} }
} }

View File

@@ -38,10 +38,10 @@ class BillObserver
public function created(Bill $bill): void public function created(Bill $bill): void
{ {
// Log::debug('Observe "created" of a bill.'); // Log::debug('Observe "created" of a bill.');
$this->updateNativeAmount($bill); $this->updatePrimaryCurrencyAmount($bill);
} }
private function updateNativeAmount(Bill $bill): void private function updatePrimaryCurrencyAmount(Bill $bill): void
{ {
if (!Amount::convertToPrimary($bill->user)) { if (!Amount::convertToPrimary($bill->user)) {
return; return;
@@ -57,7 +57,7 @@ class BillObserver
$bill->native_amount_max = $converter->convert($bill->transactionCurrency, $userCurrency, today(), $bill->amount_max); $bill->native_amount_max = $converter->convert($bill->transactionCurrency, $userCurrency, today(), $bill->amount_max);
} }
$bill->saveQuietly(); $bill->saveQuietly();
Log::debug('Bill native amounts are updated.'); Log::debug('Bill primary currency amounts are updated.');
} }
public function deleting(Bill $bill): void public function deleting(Bill $bill): void
@@ -76,6 +76,6 @@ class BillObserver
public function updated(Bill $bill): void public function updated(Bill $bill): void
{ {
// Log::debug('Observe "updated" of a bill.'); // Log::debug('Observe "updated" of a bill.');
$this->updateNativeAmount($bill); $this->updatePrimaryCurrencyAmount($bill);
} }
} }

View File

@@ -34,13 +34,13 @@ class BudgetLimitObserver
public function created(BudgetLimit $budgetLimit): void public function created(BudgetLimit $budgetLimit): void
{ {
Log::debug('Observe "created" of a budget limit.'); Log::debug('Observe "created" of a budget limit.');
$this->updateNativeAmount($budgetLimit); $this->updatePrimaryCurrencyAmount($budgetLimit);
} }
private function updateNativeAmount(BudgetLimit $budgetLimit): void private function updatePrimaryCurrencyAmount(BudgetLimit $budgetLimit): void
{ {
if (!Amount::convertToPrimary($budgetLimit->budget->user)) { if (!Amount::convertToPrimary($budgetLimit->budget->user)) {
// Log::debug('Do not update native amount of the budget limit.'); // Log::debug('Do not update primary currency amount of the budget limit.');
return; return;
} }
@@ -53,12 +53,12 @@ class BudgetLimitObserver
$budgetLimit->native_amount = $converter->convert($budgetLimit->transactionCurrency, $userCurrency, today(), $budgetLimit->amount); $budgetLimit->native_amount = $converter->convert($budgetLimit->transactionCurrency, $userCurrency, today(), $budgetLimit->amount);
} }
$budgetLimit->saveQuietly(); $budgetLimit->saveQuietly();
Log::debug('Budget limit native amounts are updated.'); Log::debug('Budget limit primary currency amounts are updated.');
} }
public function updated(BudgetLimit $budgetLimit): void public function updated(BudgetLimit $budgetLimit): void
{ {
Log::debug('Observe "updated" of a budget limit.'); Log::debug('Observe "updated" of a budget limit.');
$this->updateNativeAmount($budgetLimit); $this->updatePrimaryCurrencyAmount($budgetLimit);
} }
} }

View File

@@ -34,10 +34,10 @@ class PiggyBankEventObserver
public function created(PiggyBankEvent $event): void public function created(PiggyBankEvent $event): void
{ {
Log::debug('Observe "created" of a piggy bank event.'); Log::debug('Observe "created" of a piggy bank event.');
$this->updateNativeAmount($event); $this->updatePrimaryCurrencyAmount($event);
} }
private function updateNativeAmount(PiggyBankEvent $event): void private function updatePrimaryCurrencyAmount(PiggyBankEvent $event): void
{ {
$user = $event->piggyBank->accounts()->first()?->user; $user = $event->piggyBank->accounts()->first()?->user;
if (null === $user) { if (null === $user) {
@@ -57,12 +57,12 @@ class PiggyBankEventObserver
$event->native_amount = $converter->convert($event->piggyBank->transactionCurrency, $userCurrency, today(), $event->amount); $event->native_amount = $converter->convert($event->piggyBank->transactionCurrency, $userCurrency, today(), $event->amount);
} }
$event->saveQuietly(); $event->saveQuietly();
Log::debug('Piggy bank event native amount is updated.'); Log::debug('Piggy bank event primary currency amount is updated.');
} }
public function updated(PiggyBankEvent $event): void public function updated(PiggyBankEvent $event): void
{ {
Log::debug('Observe "updated" of a piggy bank event.'); Log::debug('Observe "updated" of a piggy bank event.');
$this->updateNativeAmount($event); $this->updatePrimaryCurrencyAmount($event);
} }
} }

View File

@@ -38,10 +38,10 @@ class PiggyBankObserver
public function created(PiggyBank $piggyBank): void public function created(PiggyBank $piggyBank): void
{ {
Log::debug('Observe "created" of a piggy bank.'); Log::debug('Observe "created" of a piggy bank.');
$this->updateNativeAmount($piggyBank); $this->updatePrimaryCurrencyAmount($piggyBank);
} }
private function updateNativeAmount(PiggyBank $piggyBank): void private function updatePrimaryCurrencyAmount(PiggyBank $piggyBank): void
{ {
$group = $piggyBank->accounts()->first()?->user->userGroup; $group = $piggyBank->accounts()->first()?->user->userGroup;
if (null === $group) { if (null === $group) {
@@ -58,7 +58,7 @@ class PiggyBankObserver
$piggyBank->native_target_amount = $converter->convert($piggyBank->transactionCurrency, $userCurrency, today(), $piggyBank->target_amount); $piggyBank->native_target_amount = $converter->convert($piggyBank->transactionCurrency, $userCurrency, today(), $piggyBank->target_amount);
} }
$piggyBank->saveQuietly(); $piggyBank->saveQuietly();
Log::debug('Piggy bank native target amount is updated.'); Log::debug('Piggy bank primary currency target amount is updated.');
} }
/** /**
@@ -85,6 +85,6 @@ class PiggyBankObserver
public function updated(PiggyBank $piggyBank): void public function updated(PiggyBank $piggyBank): void
{ {
Log::debug('Observe "updated" of a piggy bank.'); Log::debug('Observe "updated" of a piggy bank.');
$this->updateNativeAmount($piggyBank); $this->updatePrimaryCurrencyAmount($piggyBank);
} }
} }

View File

@@ -45,10 +45,10 @@ class TransactionObserver
AccountBalanceCalculator::recalculateForJournal($transaction->transactionJournal); AccountBalanceCalculator::recalculateForJournal($transaction->transactionJournal);
} }
} }
$this->updateNativeAmount($transaction); $this->updatePrimaryCurrencyAmount($transaction);
} }
private function updateNativeAmount(Transaction $transaction): void private function updatePrimaryCurrencyAmount(Transaction $transaction): void
{ {
if (!Amount::convertToPrimary($transaction->transactionJournal->user)) { if (!Amount::convertToPrimary($transaction->transactionJournal->user)) {
return; return;
@@ -72,7 +72,7 @@ class TransactionObserver
} }
$transaction->saveQuietly(); $transaction->saveQuietly();
Log::debug('Transaction native amounts are updated.'); Log::debug('Transaction primary currency amounts are updated.');
} }
public function deleting(?Transaction $transaction): void public function deleting(?Transaction $transaction): void
@@ -90,6 +90,6 @@ class TransactionObserver
AccountBalanceCalculator::recalculateForJournal($transaction->transactionJournal); AccountBalanceCalculator::recalculateForJournal($transaction->transactionJournal);
} }
} }
$this->updateNativeAmount($transaction); $this->updatePrimaryCurrencyAmount($transaction);
} }
} }