Rename method.

This commit is contained in:
James Cole
2025-07-31 20:17:46 +02:00
parent 65a926874b
commit 210bd83bd4
39 changed files with 61 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::getNativeCurrencyByUserGroup($journal->userGroup); $native = 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();

View File

@@ -63,7 +63,7 @@ class CorrectsCurrencies extends Command
$repos = app(CurrencyRepositoryInterface::class); $repos = app(CurrencyRepositoryInterface::class);
// first check if the user has any default currency (not necessarily the case, so can be forced). // first check if the user has any default currency (not necessarily the case, so can be forced).
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($userGroup); $defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($userGroup);
Log::debug(sprintf('Now correcting currencies for user group #%d', $userGroup->id)); Log::debug(sprintf('Now correcting currencies for user group #%d', $userGroup->id));
$found = [$defaultCurrency->id]; $found = [$defaultCurrency->id];

View File

@@ -88,7 +88,7 @@ class CorrectsNativeAmounts extends Command
// do a check with the group's currency so we can skip some stuff. // do a check with the group's currency so we can skip some stuff.
Preferences::mark(); Preferences::mark();
$currency = app('amount')->getNativeCurrencyByUserGroup($userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($userGroup);
$this->recalculatePiggyBanks($userGroup, $currency); $this->recalculatePiggyBanks($userGroup, $currency);
$this->recalculateBudgets($userGroup, $currency); $this->recalculateBudgets($userGroup, $currency);

View File

@@ -132,6 +132,6 @@ class CorrectsOpeningBalanceCurrencies extends Command
$repos = app(AccountRepositoryInterface::class); $repos = app(AccountRepositoryInterface::class);
$repos->setUser($account->user); $repos->setUser($account->user);
return $repos->getAccountCurrency($account) ?? app('amount')->getNativeCurrencyByUserGroup($account->userGroup); return $repos->getAccountCurrency($account) ?? app('amount')->getPrimaryCurrencyByUserGroup($account->userGroup);
} }
} }

View File

@@ -108,7 +108,7 @@ class UpgradesAccountCurrencies extends Command
$accounts = $this->accountRepos->getAccountsByType([AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value]); $accounts = $this->accountRepos->getAccountsByType([AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value]);
// get user's currency preference: // get user's currency preference:
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($user->userGroup); $defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($user->userGroup);
/** @var Account $account */ /** @var Account $account */
foreach ($accounts as $account) { foreach ($accounts as $account) {

View File

@@ -66,7 +66,7 @@ class UpgradesBudgetLimits extends Command
/** @var null|User $user */ /** @var null|User $user */
$user = $budget->user; $user = $budget->user;
if (null !== $user) { if (null !== $user) {
$currency = app('amount')->getNativeCurrencyByUserGroup($user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($user->userGroup);
$budgetLimit->transaction_currency_id = $currency->id; $budgetLimit->transaction_currency_id = $currency->id;
$budgetLimit->save(); $budgetLimit->save();
$this->friendlyInfo( $this->friendlyInfo(

View File

@@ -96,7 +96,7 @@ class UpgradesMultiPiggyBanks extends Command
$this->repository->setUser($piggyBank->account->user); $this->repository->setUser($piggyBank->account->user);
$this->accountRepository->setUser($piggyBank->account->user); $this->accountRepository->setUser($piggyBank->account->user);
$repetition = $this->repository->getRepetition($piggyBank, true); $repetition = $this->repository->getRepetition($piggyBank, true);
$currency = $this->accountRepository->getAccountCurrency($piggyBank->account) ?? app('amount')->getNativeCurrencyByUserGroup($piggyBank->account->user->userGroup); $currency = $this->accountRepository->getAccountCurrency($piggyBank->account) ?? app('amount')->getPrimaryCurrencyByUserGroup($piggyBank->account->user->userGroup);
// update piggy bank to have a currency. // update piggy bank to have a currency.
$piggyBank->transaction_currency_id = $currency->id; $piggyBank->transaction_currency_id = $currency->id;

View File

@@ -50,7 +50,7 @@ class BillFactory
app('log')->debug(sprintf('Now in %s', __METHOD__), $data); app('log')->debug(sprintf('Now in %s', __METHOD__), $data);
$factory = app(TransactionCurrencyFactory::class); $factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find((int) ($data['currency_id'] ?? null), (string) ($data['currency_code'] ?? null)) $currency = $factory->find((int) ($data['currency_id'] ?? null), (string) ($data['currency_code'] ?? null))
?? app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); ?? app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
try { try {
$skip = array_key_exists('skip', $data) ? $data['skip'] : 0; $skip = array_key_exists('skip', $data) ? $data['skip'] : 0;

View File

@@ -488,7 +488,7 @@ class TransactionJournalFactory
$preference = $this->accountRepository->getAccountCurrency($account); $preference = $this->accountRepository->getAccountCurrency($account);
if (null === $preference && !$currency instanceof TransactionCurrency) { if (null === $preference && !$currency instanceof TransactionCurrency) {
// return user's default: // return user's default:
return app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); return app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
} }
$result = $preference ?? $currency; $result = $preference ?? $currency;
Log::debug(sprintf('Currency is now #%d (%s) because of account #%d (%s)', $result->id, $result->code, $account->id, $account->name)); Log::debug(sprintf('Currency is now #%d (%s) because of account #%d (%s)', $result->id, $result->code, $account->id, $account->name));

View File

@@ -141,7 +141,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
Log::debug(sprintf('getAuditReport: Call finalAccountBalance with date/time "%s"', $date->toIso8601String())); Log::debug(sprintf('getAuditReport: Call finalAccountBalance with date/time "%s"', $date->toIso8601String()));
$dayBeforeBalance = Steam::finalAccountBalance($account, $date); $dayBeforeBalance = Steam::finalAccountBalance($account, $date);
$startBalance = $dayBeforeBalance['balance']; $startBalance = $dayBeforeBalance['balance'];
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup); $defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency; $currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
foreach ($journals as $index => $journal) { foreach ($journals as $index => $journal) {

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::getNativeCurrencyByUserGroup($model->userGroup)); $enrichment->setNative(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

@@ -52,7 +52,7 @@ class AccountObserver
if (!Amount::convertToNative($account->user)) { if (!Amount::convertToNative($account->user)) {
return; return;
} }
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup); $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$currency = $repository->getAccountCurrency($account); $currency = $repository->getAccountCurrency($account);
if (null !== $currency && $currency->id !== $userCurrency->id && '' !== (string) $account->virtual_balance && 0 !== bccomp($account->virtual_balance, '0')) { if (null !== $currency && $currency->id !== $userCurrency->id && '' !== (string) $account->virtual_balance && 0 !== bccomp($account->virtual_balance, '0')) {

View File

@@ -42,7 +42,7 @@ class AutoBudgetObserver
if (!Amount::convertToNative($autoBudget->budget->user)) { if (!Amount::convertToNative($autoBudget->budget->user)) {
return; return;
} }
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($autoBudget->budget->user->userGroup); $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($autoBudget->budget->user->userGroup);
$autoBudget->native_amount = null; $autoBudget->native_amount = null;
if ($autoBudget->transactionCurrency->id !== $userCurrency->id) { if ($autoBudget->transactionCurrency->id !== $userCurrency->id) {
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();

View File

@@ -44,7 +44,7 @@ class AvailableBudgetObserver
return; return;
} }
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($availableBudget->user->userGroup); $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($availableBudget->user->userGroup);
$availableBudget->native_amount = null; $availableBudget->native_amount = null;
if ($availableBudget->transactionCurrency->id !== $userCurrency->id) { if ($availableBudget->transactionCurrency->id !== $userCurrency->id) {
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();

View File

@@ -46,7 +46,7 @@ class BillObserver
if (!Amount::convertToNative($bill->user)) { if (!Amount::convertToNative($bill->user)) {
return; return;
} }
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($bill->user->userGroup); $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($bill->user->userGroup);
$bill->native_amount_min = null; $bill->native_amount_min = null;
$bill->native_amount_max = null; $bill->native_amount_max = null;
if ($bill->transactionCurrency->id !== $userCurrency->id) { if ($bill->transactionCurrency->id !== $userCurrency->id) {

View File

@@ -44,7 +44,7 @@ class BudgetLimitObserver
return; return;
} }
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($budgetLimit->budget->user->userGroup); $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($budgetLimit->budget->user->userGroup);
$budgetLimit->native_amount = null; $budgetLimit->native_amount = null;
if ($budgetLimit->transactionCurrency->id !== $userCurrency->id) { if ($budgetLimit->transactionCurrency->id !== $userCurrency->id) {
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();

View File

@@ -48,7 +48,7 @@ class PiggyBankEventObserver
if (!Amount::convertToNative($user)) { if (!Amount::convertToNative($user)) {
return; return;
} }
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($event->piggyBank->accounts()->first()->user->userGroup); $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($event->piggyBank->accounts()->first()->user->userGroup);
$event->native_amount = null; $event->native_amount = null;
if ($event->piggyBank->transactionCurrency->id !== $userCurrency->id) { if ($event->piggyBank->transactionCurrency->id !== $userCurrency->id) {
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();

View File

@@ -49,7 +49,7 @@ class PiggyBankObserver
return; return;
} }
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($group); $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($group);
$piggyBank->native_target_amount = null; $piggyBank->native_target_amount = null;
if ($piggyBank->transactionCurrency->id !== $userCurrency->id) { if ($piggyBank->transactionCurrency->id !== $userCurrency->id) {
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();

View File

@@ -53,7 +53,7 @@ class TransactionObserver
if (!Amount::convertToNative($transaction->transactionJournal->user)) { if (!Amount::convertToNative($transaction->transactionJournal->user)) {
return; return;
} }
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($transaction->transactionJournal->user->userGroup); $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($transaction->transactionJournal->user->userGroup);
$transaction->native_amount = null; $transaction->native_amount = null;
$transaction->native_foreign_amount = null; $transaction->native_foreign_amount = null;
// first normal amount // first normal amount

View File

@@ -65,7 +65,7 @@ class TransactionCurrency extends Model
public function refreshForUser(User $user): void public function refreshForUser(User $user): void
{ {
$current = $user->userGroup->currencies()->where('transaction_currencies.id', $this->id)->first(); $current = $user->userGroup->currencies()->where('transaction_currencies.id', $this->id)->first();
$native = app('amount')->getNativeCurrencyByUserGroup($user->userGroup); $native = app('amount')->getPrimaryCurrencyByUserGroup($user->userGroup);
$this->userGroupNative = $native->id === $this->id; $this->userGroupNative = $native->id === $this->id;
$this->userGroupEnabled = null !== $current; $this->userGroupEnabled = null !== $current;
} }

View File

@@ -58,7 +58,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
$return = [ $return = [
'accounts' => [], 'accounts' => [],
@@ -148,7 +148,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
*/ */
private function groupExpenseByDestination(array $array): array private function groupExpenseByDestination(array $array): array
{ {
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
/** @var CurrencyRepositoryInterface $currencyRepos */ /** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class); $currencyRepos = app(CurrencyRepositoryInterface::class);
@@ -236,7 +236,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
*/ */
private function groupIncomeBySource(array $array): array private function groupIncomeBySource(array $array): array
{ {
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
/** @var CurrencyRepositoryInterface $currencyRepos */ /** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class); $currencyRepos = app(CurrencyRepositoryInterface::class);

View File

@@ -271,7 +271,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
$factory = app(TransactionCurrencyFactory::class); $factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null); $currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
if (null === $currency) { if (null === $currency) {
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
} }
$currency->enabled = true; $currency->enabled = true;
$currency->save(); $currency->save();
@@ -369,7 +369,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
} }
// catch unexpected null: // catch unexpected null:
if (null === $currency) { if (null === $currency) {
$currency = $budgetLimit->transactionCurrency ?? app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $currency = $budgetLimit->transactionCurrency ?? app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
} }
$currency->enabled = true; $currency->enabled = true;
$currency->save(); $currency->save();

View File

@@ -391,7 +391,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
$autoBudget = $this->getAutoBudget($budget); $autoBudget = $this->getAutoBudget($budget);
// grab default currency: // grab default currency:
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
if (!$autoBudget instanceof AutoBudget) { if (!$autoBudget instanceof AutoBudget) {
// at this point it's a blind assumption auto_budget_type is 1 or 2. // at this point it's a blind assumption auto_budget_type is 1 or 2.
@@ -776,7 +776,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
$currency = $repos->findByCode((string) $data['currency_code']); $currency = $repos->findByCode((string) $data['currency_code']);
} }
if (null === $currency) { if (null === $currency) {
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
} }
$autoBudget = new AutoBudget(); $autoBudget = new AutoBudget();

View File

@@ -143,7 +143,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
// if needs conversion to native. // if needs conversion to native.
$convertToNative = Amount::convertToNative($this->user); $convertToNative = Amount::convertToNative($this->user);
$nativeCurrency = Amount::getNativeCurrencyByUserGroup($this->userGroup); $nativeCurrency = Amount::getPrimaryCurrencyByUserGroup($this->userGroup);
$currencyId = (int) $nativeCurrency->id; $currencyId = (int) $nativeCurrency->id;
$currencyCode = $nativeCurrency->code; $currencyCode = $nativeCurrency->code;
$currencyName = $nativeCurrency->name; $currencyName = $nativeCurrency->name;

View File

@@ -243,7 +243,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
Log::debug('Grabbing default currency for this user...'); Log::debug('Grabbing default currency for this user...');
/** @var null|TransactionCurrency $result */ /** @var null|TransactionCurrency $result */
$result = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $result = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
} }
Log::debug(sprintf('Final result: %s', $result->code)); Log::debug(sprintf('Final result: %s', $result->code));
@@ -428,7 +428,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
public function makeDefault(TransactionCurrency $currency): void public function makeDefault(TransactionCurrency $currency): void
{ {
$current = app('amount')->getNativeCurrencyByUserGroup($this->userGroup); $current = app('amount')->getPrimaryCurrencyByUserGroup($this->userGroup);
Log::debug(sprintf('Enabled + made default currency %s for user #%d', $currency->code, $this->userGroup->id)); Log::debug(sprintf('Enabled + made default currency %s for user #%d', $currency->code, $this->userGroup->id));
$this->userGroup->currencies()->detach($currency->id); $this->userGroup->currencies()->detach($currency->id);
foreach ($this->userGroup->currencies()->get() as $item) { foreach ($this->userGroup->currencies()->get() as $item) {

View File

@@ -71,7 +71,7 @@ trait ModifiesPiggyBanks
$pivot->native_current_amount = null; $pivot->native_current_amount = null;
// also update native_current_amount. // also update native_current_amount.
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
if ($userCurrency->id !== $piggyBank->transaction_currency_id) { if ($userCurrency->id !== $piggyBank->transaction_currency_id) {
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();
$converter->setIgnoreSettings(true); $converter->setIgnoreSettings(true);
@@ -94,7 +94,7 @@ trait ModifiesPiggyBanks
$pivot->native_current_amount = null; $pivot->native_current_amount = null;
// also update native_current_amount. // also update native_current_amount.
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
if ($userCurrency->id !== $piggyBank->transaction_currency_id) { if ($userCurrency->id !== $piggyBank->transaction_currency_id) {
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();
$converter->setIgnoreSettings(true); $converter->setIgnoreSettings(true);

View File

@@ -171,7 +171,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
$accountRepos = app(AccountRepositoryInterface::class); $accountRepos = app(AccountRepositoryInterface::class);
$accountRepos->setUser($this->user); $accountRepos->setUser($this->user);
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
app('log')->debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBank->transactionCurrency->code)); app('log')->debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBank->transactionCurrency->code));

View File

@@ -340,7 +340,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
{ {
$return = []; $return = [];
$journals = $group->transactionJournals->pluck('id')->toArray(); $journals = $group->transactionJournals->pluck('id')->toArray();
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
$data = PiggyBankEvent::whereIn('transaction_journal_id', $journals) $data = PiggyBankEvent::whereIn('transaction_journal_id', $journals)
->with('piggyBank', 'piggyBank.account') ->with('piggyBank', 'piggyBank.account')
->get(['piggy_bank_events.*']) ->get(['piggy_bank_events.*'])

View File

@@ -245,7 +245,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
Log::debug('Grabbing default currency for this user...'); Log::debug('Grabbing default currency for this user...');
/** @var null|TransactionCurrency $result */ /** @var null|TransactionCurrency $result */
$result = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $result = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
} }
Log::debug(sprintf('Final result: %s', $result->code)); Log::debug(sprintf('Final result: %s', $result->code));
@@ -376,7 +376,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
public function makeDefault(TransactionCurrency $currency): void public function makeDefault(TransactionCurrency $currency): void
{ {
$current = app('amount')->getNativeCurrencyByUserGroup($this->userGroup); $current = app('amount')->getPrimaryCurrencyByUserGroup($this->userGroup);
Log::debug(sprintf('Enabled + made default currency %s for user #%d', $currency->code, $this->userGroup->id)); Log::debug(sprintf('Enabled + made default currency %s for user #%d', $currency->code, $this->userGroup->id));
$this->userGroup->currencies()->detach($currency->id); $this->userGroup->currencies()->detach($currency->id);
foreach ($this->userGroup->currencies()->get() as $item) { foreach ($this->userGroup->currencies()->get() as $item) {

View File

@@ -235,7 +235,7 @@ trait AccountServiceTrait
// get or grab currency: // get or grab currency:
$currency = $this->accountRepository->getAccountCurrency($account); $currency = $this->accountRepository->getAccountCurrency($account);
if (null === $currency) { if (null === $currency) {
$currency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
} }
// submit to factory: // submit to factory:
@@ -355,7 +355,7 @@ trait AccountServiceTrait
if (null === $currency) { if (null === $currency) {
// use default currency: // use default currency:
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
} }
$currency->enabled = true; $currency->enabled = true;
$currency->save(); $currency->save();
@@ -395,7 +395,7 @@ trait AccountServiceTrait
// if exists, update: // if exists, update:
$currency = $this->accountRepository->getAccountCurrency($account); $currency = $this->accountRepository->getAccountCurrency($account);
if (null === $currency) { if (null === $currency) {
$currency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
} }
// simply grab the first journal and change it: // simply grab the first journal and change it:
@@ -461,7 +461,7 @@ trait AccountServiceTrait
// get or grab currency: // get or grab currency:
$currency = $this->accountRepository->getAccountCurrency($account); $currency = $this->accountRepository->getAccountCurrency($account);
if (null === $currency) { if (null === $currency) {
$currency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
} }
// submit to factory: // submit to factory:
$submission = [ $submission = [
@@ -578,7 +578,7 @@ trait AccountServiceTrait
// if exists, update: // if exists, update:
$currency = $this->accountRepository->getAccountCurrency($account); $currency = $this->accountRepository->getAccountCurrency($account);
if (null === $currency) { if (null === $currency) {
$currency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
} }
// simply grab the first journal and change it: // simply grab the first journal and change it:
@@ -659,7 +659,7 @@ trait AccountServiceTrait
// get or grab currency: // get or grab currency:
$currency = $this->accountRepository->getAccountCurrency($account); $currency = $this->accountRepository->getAccountCurrency($account);
if (null === $currency) { if (null === $currency) {
$currency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
} }
// submit to factory: // submit to factory:

View File

@@ -109,7 +109,7 @@ trait RecurringTransactionTrait
$currency = $factory->find($array['currency_id'] ?? null, $array['currency_code'] ?? null); $currency = $factory->find($array['currency_id'] ?? null, $array['currency_code'] ?? null);
$foreignCurrency = $factory->find($array['foreign_currency_id'] ?? null, $array['foreign_currency_code'] ?? null); $foreignCurrency = $factory->find($array['foreign_currency_id'] ?? null, $array['foreign_currency_code'] ?? null);
if (null === $currency) { if (null === $currency) {
$currency = app('amount')->getNativeCurrencyByUserGroup($recurrence->user->userGroup); $currency = app('amount')->getPrimaryCurrencyByUserGroup($recurrence->user->userGroup);
} }
app('log')->debug( app('log')->debug(

View File

@@ -56,7 +56,7 @@ class BillUpdateService
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) { if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
$factory = app(TransactionCurrencyFactory::class); $factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find((int) ($data['currency_id'] ?? null), $data['currency_code'] ?? null) $currency = $factory->find((int) ($data['currency_id'] ?? null), $data['currency_code'] ?? null)
?? app('amount')->getNativeCurrencyByUserGroup($bill->user->userGroup); ?? app('amount')->getPrimaryCurrencyByUserGroup($bill->user->userGroup);
// enable the currency if it isn't. // enable the currency if it isn't.
$currency->enabled = true; $currency->enabled = true;

View File

@@ -137,25 +137,25 @@ class Amount
return $this->getSystemCurrency(); return $this->getSystemCurrency();
} }
public function getNativeCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency public function getPrimaryCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
{ {
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty('getNativeCurrencyByGroup'); $cache->addProperty('getPrimaryCurrencyByGroup');
$cache->addProperty($userGroup->id); $cache->addProperty($userGroup->id);
if ($cache->has()) { if ($cache->has()) {
return $cache->get(); return $cache->get();
} }
/** @var null|TransactionCurrency $native */ /** @var null|TransactionCurrency $primary */
$native = $userGroup->currencies()->where('group_default', true)->first(); $primary = $userGroup->currencies()->where('group_default', true)->first();
if (null === $native) { if (null === $primary) {
$native = $this->getSystemCurrency(); $primary = $this->getSystemCurrency();
// could be the user group has no default right now. // could be the user group has no default right now.
$userGroup->currencies()->sync([$native->id => ['group_default' => true]]); $userGroup->currencies()->sync([$primary->id => ['group_default' => true]]);
} }
$cache->store($native); $cache->store($primary);
return $native; return $primary;
} }
public function getSystemCurrency(): TransactionCurrency public function getSystemCurrency(): TransactionCurrency

View File

@@ -347,6 +347,6 @@ class BudgetReportGenerator
$this->blRepository->setUser($user); $this->blRepository->setUser($user);
$this->opsRepository->setUser($user); $this->opsRepository->setUser($user);
$this->nbRepository->setUser($user); $this->nbRepository->setUser($user);
$this->currency = app('amount')->getNativeCurrencyByUserGroup($user->userGroup); $this->currency = app('amount')->getPrimaryCurrencyByUserGroup($user->userGroup);
} }
} }

View File

@@ -45,7 +45,7 @@ class TransactionSummarizer
public function setUser(User $user): void public function setUser(User $user): void
{ {
$this->user = $user; $this->user = $user;
$this->default = Amount::getNativeCurrencyByUserGroup($user->userGroup); $this->default = Amount::getPrimaryCurrencyByUserGroup($user->userGroup);
$this->convertToNative = Amount::convertToNative($user); $this->convertToNative = Amount::convertToNative($user);
} }
@@ -160,7 +160,7 @@ class TransactionSummarizer
$idKey = sprintf('%s_account_id', $direction); $idKey = sprintf('%s_account_id', $direction);
$nameKey = sprintf('%s_account_name', $direction); $nameKey = sprintf('%s_account_name', $direction);
$convertToNative = Amount::convertToNative($this->user); $convertToNative = Amount::convertToNative($this->user);
$default = Amount::getNativeCurrencyByUserGroup($this->user->userGroup); $default = Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup);
Log::debug(sprintf('groupByDirection(array, %s, %s).', $direction, $method)); Log::debug(sprintf('groupByDirection(array, %s, %s).', $direction, $method));

View File

@@ -224,7 +224,7 @@ class Steam
$request->subDay()->endOfDay(); $request->subDay()->endOfDay();
Log::debug(sprintf('finalAccountBalanceInRange: Call finalAccountBalance with date/time "%s"', $request->toIso8601String())); Log::debug(sprintf('finalAccountBalanceInRange: Call finalAccountBalance with date/time "%s"', $request->toIso8601String()));
$startBalance = $this->finalAccountBalance($account, $request); $startBalance = $this->finalAccountBalance($account, $request);
$nativeCurrency = Amount::getNativeCurrencyByUserGroup($account->user->userGroup); $nativeCurrency = Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
$accountCurrency = $this->getAccountCurrency($account); $accountCurrency = $this->getAccountCurrency($account);
$hasCurrency = $accountCurrency instanceof TransactionCurrency; $hasCurrency = $accountCurrency instanceof TransactionCurrency;
$currency = $accountCurrency ?? $nativeCurrency; $currency = $accountCurrency ?? $nativeCurrency;
@@ -347,7 +347,7 @@ class Steam
$convertToNative = Amount::convertToNative($account->user); $convertToNative = Amount::convertToNative($account->user);
} }
if (!$native instanceof TransactionCurrency) { if (!$native instanceof TransactionCurrency) {
$native = Amount::getNativeCurrencyByUserGroup($account->user->userGroup); $native = Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
} }
// account balance thing. // account balance thing.
$currencyPresent = isset($account->meta) && array_key_exists('currency', $account->meta) && null !== $account->meta['currency']; $currencyPresent = isset($account->meta) && array_key_exists('currency', $account->meta) && null !== $account->meta['currency'];

View File

@@ -61,7 +61,7 @@ class PiggyBankEventTransformer extends AbstractTransformer
$this->piggyRepos->setUser($account->user); $this->piggyRepos->setUser($account->user);
// get associated currency or fall back to the default: // get associated currency or fall back to the default:
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup); $currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
// get associated journal and transaction, if any: // get associated journal and transaction, if any:
$journalId = $event->transaction_journal_id; $journalId = $event->transaction_journal_id;

View File

@@ -105,7 +105,7 @@ class UserGroupTransformer extends AbstractTransformer
*/ */
public function transform(UserGroup $userGroup): array public function transform(UserGroup $userGroup): array
{ {
$currency = Amount::getNativeCurrencyByUserGroup($userGroup); $currency = Amount::getPrimaryCurrencyByUserGroup($userGroup);
return [ return [
'id' => $userGroup->id, 'id' => $userGroup->id,

View File

@@ -139,7 +139,7 @@ class PiggyBankTransformer extends AbstractTransformer
} }
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__)); Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
$this->default = app('amount')->getNativeCurrencyByUserGroup(auth()->user()->userGroup); $this->default = app('amount')->getPrimaryCurrencyByUserGroup(auth()->user()->userGroup);
$this->converter = new ExchangeRateConverter(); $this->converter = new ExchangeRateConverter();
return $objects; return $objects;