From ea6addafe6410ec3ce167c30b77cf5173c2f83d3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 31 Jul 2025 20:55:30 +0200 Subject: [PATCH] Rename references to native amounts --- .../Commands/Correction/CorrectsAmounts.php | 6 +++--- .../Commands/Correction/CorrectsDatabase.php | 2 +- ...unts.php => CorrectsPrimaryCurrencyAmounts.php} | 14 +++++++------- app/Console/Commands/Upgrade/UpgradesDatabase.php | 2 +- ...unts.php => UpgradesPrimaryCurrencyAmounts.php} | 12 ++++++------ app/Factory/TransactionJournalFactory.php | 2 +- app/Generator/Webhook/StandardMessageGenerator.php | 2 +- app/Handlers/Events/PreferencesEventHandler.php | 13 ++++++------- app/Handlers/Observer/AccountObserver.php | 8 ++++---- app/Handlers/Observer/AutoBudgetObserver.php | 8 ++++---- app/Handlers/Observer/AvailableBudgetObserver.php | 10 +++++----- app/Handlers/Observer/BillObserver.php | 8 ++++---- app/Handlers/Observer/BudgetLimitObserver.php | 10 +++++----- app/Handlers/Observer/PiggyBankEventObserver.php | 8 ++++---- app/Handlers/Observer/PiggyBankObserver.php | 8 ++++---- app/Handlers/Observer/TransactionObserver.php | 8 ++++---- 16 files changed, 60 insertions(+), 61 deletions(-) rename app/Console/Commands/Correction/{CorrectsNativeAmounts.php => CorrectsPrimaryCurrencyAmounts.php} (94%) rename app/Console/Commands/Upgrade/{UpgradesNativeAmounts.php => UpgradesPrimaryCurrencyAmounts.php} (80%) diff --git a/app/Console/Commands/Correction/CorrectsAmounts.php b/app/Console/Commands/Correction/CorrectsAmounts.php index 1c8a22deec..9bcf3d478a 100644 --- a/app/Console/Commands/Correction/CorrectsAmounts.php +++ b/app/Console/Commands/Correction/CorrectsAmounts.php @@ -86,7 +86,7 @@ class CorrectsAmounts extends Command /** @var TransactionJournal $journal */ foreach ($journals as $journal) { $repository->setUser($journal->user); - $native = Amount::getPrimaryCurrencyByUserGroup($journal->userGroup); + $primary = Amount::getPrimaryCurrencyByUserGroup($journal->userGroup); /** @var null|Transaction $source */ $source = $journal->transactions()->where('amount', '<', 0)->first(); @@ -104,8 +104,8 @@ class CorrectsAmounts extends Command if (null === $sourceAccount || null === $destAccount) { continue; } - $sourceCurrency = $repository->getAccountCurrency($sourceAccount) ?? $native; - $destCurrency = $repository->getAccountCurrency($destAccount) ?? $native; + $sourceCurrency = $repository->getAccountCurrency($sourceAccount) ?? $primary; + $destCurrency = $repository->getAccountCurrency($destAccount) ?? $primary; if ($sourceCurrency->id === $destCurrency->id) { Log::debug('Both accounts have the same currency. Removing foreign currency info.'); diff --git a/app/Console/Commands/Correction/CorrectsDatabase.php b/app/Console/Commands/Correction/CorrectsDatabase.php index 974d4a19c0..5850619f61 100644 --- a/app/Console/Commands/Correction/CorrectsDatabase.php +++ b/app/Console/Commands/Correction/CorrectsDatabase.php @@ -75,7 +75,7 @@ class CorrectsDatabase extends Command 'correction:recalculates-liabilities', 'correction:preferences', // 'correction:transaction-types', // resource heavy, disabled. - 'correction:recalculate-native-amounts', // not necessary, disabled. + 'correction:recalculate-pc-amounts', // not necessary, disabled. 'firefly-iii:report-integrity', ]; foreach ($commands as $command) { diff --git a/app/Console/Commands/Correction/CorrectsNativeAmounts.php b/app/Console/Commands/Correction/CorrectsPrimaryCurrencyAmounts.php similarity index 94% rename from app/Console/Commands/Correction/CorrectsNativeAmounts.php rename to app/Console/Commands/Correction/CorrectsPrimaryCurrencyAmounts.php index 3532af0d79..f4544f8aa8 100644 --- a/app/Console/Commands/Correction/CorrectsNativeAmounts.php +++ b/app/Console/Commands/Correction/CorrectsPrimaryCurrencyAmounts.php @@ -2,7 +2,7 @@ /* - * CorrectsNativeAmounts.php + * CorrectsPrimaryCurrencyAmounts.php * Copyright (c) 2025 james@firefly-iii.org. * * 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\Log; -class CorrectsNativeAmounts extends Command +class CorrectsPrimaryCurrencyAmounts extends Command { 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. @@ -66,8 +66,8 @@ class CorrectsNativeAmounts extends Command return 0; } - Log::debug('Will update all native amounts. This may take some time.'); - $this->friendlyWarning('Recalculating native amounts for all objects. This may take some time!'); + Log::debug('Will update all primary currency amounts. This may take some time.'); + $this->friendlyWarning('Recalculating primary currency amounts for all objects. This may take some time!'); /** @var UserGroupRepositoryInterface $repository */ $repository = app(UserGroupRepositoryInterface::class); @@ -76,7 +76,7 @@ class CorrectsNativeAmounts extends Command foreach ($repository->getAll() as $userGroup) { $this->recalculateForGroup($userGroup); } - $this->friendlyInfo('Recalculated all native amounts.'); + $this->friendlyInfo('Recalculated all primary currency amounts.'); return 0; } diff --git a/app/Console/Commands/Upgrade/UpgradesDatabase.php b/app/Console/Commands/Upgrade/UpgradesDatabase.php index 13d7db7832..a98ff922d8 100644 --- a/app/Console/Commands/Upgrade/UpgradesDatabase.php +++ b/app/Console/Commands/Upgrade/UpgradesDatabase.php @@ -74,7 +74,7 @@ class UpgradesDatabase extends Command 'upgrade:610-currency-preferences', 'upgrade:610-currency-preferences', 'upgrade:620-piggy-banks', - 'upgrade:620-native-amounts', + 'upgrade:620-pc-amounts', 'firefly-iii:correct-database', ]; $args = []; diff --git a/app/Console/Commands/Upgrade/UpgradesNativeAmounts.php b/app/Console/Commands/Upgrade/UpgradesPrimaryCurrencyAmounts.php similarity index 80% rename from app/Console/Commands/Upgrade/UpgradesNativeAmounts.php rename to app/Console/Commands/Upgrade/UpgradesPrimaryCurrencyAmounts.php index 648237b33c..9cb26669ee 100644 --- a/app/Console/Commands/Upgrade/UpgradesNativeAmounts.php +++ b/app/Console/Commands/Upgrade/UpgradesPrimaryCurrencyAmounts.php @@ -2,7 +2,7 @@ /* - * UpgradesNativeAmounts.php + * UpgradesPrimaryCurrencyAmounts.php * Copyright (c) 2025 james@firefly-iii.org. * * 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\Support\Facades\Artisan; -class UpgradesNativeAmounts extends Command +class UpgradesPrimaryCurrencyAmounts extends Command { 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. @@ -50,7 +50,7 @@ class UpgradesNativeAmounts extends Command return 0; } - Artisan::call('correction:recalculate-native-amounts'); + Artisan::call('correction:recalculate-pc-amounts'); $this->markAsExecuted(); diff --git a/app/Factory/TransactionJournalFactory.php b/app/Factory/TransactionJournalFactory.php index be27983f07..070f71fa26 100644 --- a/app/Factory/TransactionJournalFactory.php +++ b/app/Factory/TransactionJournalFactory.php @@ -297,7 +297,7 @@ class TransactionJournalFactory $transactionFactory->setForeignCurrency($currency); $amount = (string) $row['foreign_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 { diff --git a/app/Generator/Webhook/StandardMessageGenerator.php b/app/Generator/Webhook/StandardMessageGenerator.php index 2dfefccd66..5ea7fa002b 100644 --- a/app/Generator/Webhook/StandardMessageGenerator.php +++ b/app/Generator/Webhook/StandardMessageGenerator.php @@ -177,7 +177,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface $accounts = $this->collectAccounts($model); $enrichment = new AccountEnrichment(); $enrichment->setUser($model->user); - $enrichment->setNative(Amount::getPrimaryCurrencyByUserGroup($model->userGroup)); + $enrichment->setPrimary(Amount::getPrimaryCurrencyByUserGroup($model->userGroup)); $accounts = $enrichment->enrich($accounts); foreach ($accounts as $account) { $transformer = new AccountTransformer(); diff --git a/app/Handlers/Events/PreferencesEventHandler.php b/app/Handlers/Events/PreferencesEventHandler.php index 11fd4cbda2..6296d07437 100644 --- a/app/Handlers/Events/PreferencesEventHandler.php +++ b/app/Handlers/Events/PreferencesEventHandler.php @@ -38,17 +38,16 @@ use Illuminate\Support\Facades\Log; class PreferencesEventHandler { - public function resetNativeAmounts(UserGroupChangedDefaultCurrency $event): void + public function resetPrimaryCurrencyAmounts(UserGroupChangedDefaultCurrency $event): void { - // Reset the native amounts for all objects that have it. - Log::debug('Resetting native amounts for all objects.'); + // Reset the primary currency amounts for all objects that have it. + Log::debug('Resetting primary currency amounts for all objects.'); $tables = [ // !!! this array is also in the migration 'accounts' => ['native_virtual_balance'], 'available_budgets' => ['native_amount'], 'bills' => ['native_amount_min', 'native_amount_max'], - // 'transactions' => ['native_amount', 'native_foreign_amount'] ]; foreach ($tables as $table => $columns) { foreach ($columns as $column) { @@ -61,12 +60,12 @@ class PreferencesEventHandler $this->resetTransactions($event->userGroup); // fire laravel command to recalculate them all. if (Amount::convertToPrimary()) { - Log::debug('Will now convert to native.'); - Artisan::call('correction:recalculate-native-amounts'); + Log::debug('Will now convert to primary currency.'); + Artisan::call('correction:recalculate-pc-amounts'); return; } - Log::debug('Will NOT convert to native.'); + Log::debug('Will NOT convert to primary currency.'); } private function resetPiggyBanks(UserGroup $userGroup): void diff --git a/app/Handlers/Observer/AccountObserver.php b/app/Handlers/Observer/AccountObserver.php index 8531b6eb39..b29983ada5 100644 --- a/app/Handlers/Observer/AccountObserver.php +++ b/app/Handlers/Observer/AccountObserver.php @@ -44,10 +44,10 @@ class AccountObserver public function created(Account $account): void { // 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)) { return; @@ -67,7 +67,7 @@ class AccountObserver $account->native_virtual_balance = null; } $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 { // Log::debug('Observe "updated" of an account.'); - $this->updateNativeAmount($account); + $this->updatePrimaryCurrencyAmount($account); } } diff --git a/app/Handlers/Observer/AutoBudgetObserver.php b/app/Handlers/Observer/AutoBudgetObserver.php index a4e3e5e325..ca030ba70e 100644 --- a/app/Handlers/Observer/AutoBudgetObserver.php +++ b/app/Handlers/Observer/AutoBudgetObserver.php @@ -34,10 +34,10 @@ class AutoBudgetObserver public function created(AutoBudget $autoBudget): void { 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)) { return; @@ -51,12 +51,12 @@ class AutoBudgetObserver $autoBudget->native_amount = $converter->convert($autoBudget->transactionCurrency, $userCurrency, today(), $autoBudget->amount); } $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 { Log::debug('Observe "updated" of an auto budget.'); - $this->updateNativeAmount($autoBudget); + $this->updatePrimaryCurrencyAmount($autoBudget); } } diff --git a/app/Handlers/Observer/AvailableBudgetObserver.php b/app/Handlers/Observer/AvailableBudgetObserver.php index 36e488d48f..02fc32d0b1 100644 --- a/app/Handlers/Observer/AvailableBudgetObserver.php +++ b/app/Handlers/Observer/AvailableBudgetObserver.php @@ -34,13 +34,13 @@ class AvailableBudgetObserver public function created(AvailableBudget $availableBudget): void { // 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)) { - // 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; } @@ -53,12 +53,12 @@ class AvailableBudgetObserver $availableBudget->native_amount = $converter->convert($availableBudget->transactionCurrency, $userCurrency, today(), $availableBudget->amount); } $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 { // Log::debug('Observe "updated" of an available budget.'); - $this->updateNativeAmount($availableBudget); + $this->updatePrimaryCurrencyAmount($availableBudget); } } diff --git a/app/Handlers/Observer/BillObserver.php b/app/Handlers/Observer/BillObserver.php index b6f76b4740..9d7d5f9672 100644 --- a/app/Handlers/Observer/BillObserver.php +++ b/app/Handlers/Observer/BillObserver.php @@ -38,10 +38,10 @@ class BillObserver public function created(Bill $bill): void { // 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)) { return; @@ -57,7 +57,7 @@ class BillObserver $bill->native_amount_max = $converter->convert($bill->transactionCurrency, $userCurrency, today(), $bill->amount_max); } $bill->saveQuietly(); - Log::debug('Bill native amounts are updated.'); + Log::debug('Bill primary currency amounts are updated.'); } public function deleting(Bill $bill): void @@ -76,6 +76,6 @@ class BillObserver public function updated(Bill $bill): void { // Log::debug('Observe "updated" of a bill.'); - $this->updateNativeAmount($bill); + $this->updatePrimaryCurrencyAmount($bill); } } diff --git a/app/Handlers/Observer/BudgetLimitObserver.php b/app/Handlers/Observer/BudgetLimitObserver.php index 08b5018165..fcc4b405a8 100644 --- a/app/Handlers/Observer/BudgetLimitObserver.php +++ b/app/Handlers/Observer/BudgetLimitObserver.php @@ -34,13 +34,13 @@ class BudgetLimitObserver public function created(BudgetLimit $budgetLimit): void { 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)) { - // Log::debug('Do not update native amount of the budget limit.'); + // Log::debug('Do not update primary currency amount of the budget limit.'); return; } @@ -53,12 +53,12 @@ class BudgetLimitObserver $budgetLimit->native_amount = $converter->convert($budgetLimit->transactionCurrency, $userCurrency, today(), $budgetLimit->amount); } $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 { Log::debug('Observe "updated" of a budget limit.'); - $this->updateNativeAmount($budgetLimit); + $this->updatePrimaryCurrencyAmount($budgetLimit); } } diff --git a/app/Handlers/Observer/PiggyBankEventObserver.php b/app/Handlers/Observer/PiggyBankEventObserver.php index eee9db9a80..acd8656727 100644 --- a/app/Handlers/Observer/PiggyBankEventObserver.php +++ b/app/Handlers/Observer/PiggyBankEventObserver.php @@ -34,10 +34,10 @@ class PiggyBankEventObserver public function created(PiggyBankEvent $event): void { 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; if (null === $user) { @@ -57,12 +57,12 @@ class PiggyBankEventObserver $event->native_amount = $converter->convert($event->piggyBank->transactionCurrency, $userCurrency, today(), $event->amount); } $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 { Log::debug('Observe "updated" of a piggy bank event.'); - $this->updateNativeAmount($event); + $this->updatePrimaryCurrencyAmount($event); } } diff --git a/app/Handlers/Observer/PiggyBankObserver.php b/app/Handlers/Observer/PiggyBankObserver.php index c3a4c369cb..8c8364f01f 100644 --- a/app/Handlers/Observer/PiggyBankObserver.php +++ b/app/Handlers/Observer/PiggyBankObserver.php @@ -38,10 +38,10 @@ class PiggyBankObserver public function created(PiggyBank $piggyBank): void { 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; if (null === $group) { @@ -58,7 +58,7 @@ class PiggyBankObserver $piggyBank->native_target_amount = $converter->convert($piggyBank->transactionCurrency, $userCurrency, today(), $piggyBank->target_amount); } $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 { Log::debug('Observe "updated" of a piggy bank.'); - $this->updateNativeAmount($piggyBank); + $this->updatePrimaryCurrencyAmount($piggyBank); } } diff --git a/app/Handlers/Observer/TransactionObserver.php b/app/Handlers/Observer/TransactionObserver.php index ca433badc2..a5c5fefd73 100644 --- a/app/Handlers/Observer/TransactionObserver.php +++ b/app/Handlers/Observer/TransactionObserver.php @@ -45,10 +45,10 @@ class TransactionObserver 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)) { return; @@ -72,7 +72,7 @@ class TransactionObserver } $transaction->saveQuietly(); - Log::debug('Transaction native amounts are updated.'); + Log::debug('Transaction primary currency amounts are updated.'); } public function deleting(?Transaction $transaction): void @@ -90,6 +90,6 @@ class TransactionObserver AccountBalanceCalculator::recalculateForJournal($transaction->transactionJournal); } } - $this->updateNativeAmount($transaction); + $this->updatePrimaryCurrencyAmount($transaction); } }