mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-03 11:08:28 +00:00
Rename method.
This commit is contained in:
@@ -86,7 +86,7 @@ class CorrectsAmounts extends Command
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$repository->setUser($journal->user);
|
||||
$native = Amount::getNativeCurrencyByUserGroup($journal->userGroup);
|
||||
$native = Amount::getPrimaryCurrencyByUserGroup($journal->userGroup);
|
||||
|
||||
/** @var null|Transaction $source */
|
||||
$source = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
|
@@ -63,7 +63,7 @@ class CorrectsCurrencies extends Command
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
|
||||
// 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));
|
||||
$found = [$defaultCurrency->id];
|
||||
|
@@ -88,7 +88,7 @@ class CorrectsNativeAmounts extends Command
|
||||
|
||||
// do a check with the group's currency so we can skip some stuff.
|
||||
Preferences::mark();
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($userGroup);
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($userGroup);
|
||||
|
||||
$this->recalculatePiggyBanks($userGroup, $currency);
|
||||
$this->recalculateBudgets($userGroup, $currency);
|
||||
|
@@ -132,6 +132,6 @@ class CorrectsOpeningBalanceCurrencies extends Command
|
||||
$repos = app(AccountRepositoryInterface::class);
|
||||
$repos->setUser($account->user);
|
||||
|
||||
return $repos->getAccountCurrency($account) ?? app('amount')->getNativeCurrencyByUserGroup($account->userGroup);
|
||||
return $repos->getAccountCurrency($account) ?? app('amount')->getPrimaryCurrencyByUserGroup($account->userGroup);
|
||||
}
|
||||
}
|
||||
|
@@ -108,7 +108,7 @@ class UpgradesAccountCurrencies extends Command
|
||||
$accounts = $this->accountRepos->getAccountsByType([AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value]);
|
||||
|
||||
// get user's currency preference:
|
||||
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($user->userGroup);
|
||||
$defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($user->userGroup);
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
|
@@ -66,7 +66,7 @@ class UpgradesBudgetLimits extends Command
|
||||
/** @var null|User $user */
|
||||
$user = $budget->user;
|
||||
if (null !== $user) {
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($user->userGroup);
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($user->userGroup);
|
||||
$budgetLimit->transaction_currency_id = $currency->id;
|
||||
$budgetLimit->save();
|
||||
$this->friendlyInfo(
|
||||
|
@@ -96,7 +96,7 @@ class UpgradesMultiPiggyBanks extends Command
|
||||
$this->repository->setUser($piggyBank->account->user);
|
||||
$this->accountRepository->setUser($piggyBank->account->user);
|
||||
$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.
|
||||
$piggyBank->transaction_currency_id = $currency->id;
|
||||
|
@@ -50,7 +50,7 @@ class BillFactory
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__), $data);
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
$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 {
|
||||
$skip = array_key_exists('skip', $data) ? $data['skip'] : 0;
|
||||
|
@@ -488,7 +488,7 @@ class TransactionJournalFactory
|
||||
$preference = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $preference && !$currency instanceof TransactionCurrency) {
|
||||
// return user's default:
|
||||
return app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
return app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
}
|
||||
$result = $preference ?? $currency;
|
||||
Log::debug(sprintf('Currency is now #%d (%s) because of account #%d (%s)', $result->id, $result->code, $account->id, $account->name));
|
||||
|
@@ -141,7 +141,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
Log::debug(sprintf('getAuditReport: Call finalAccountBalance with date/time "%s"', $date->toIso8601String()));
|
||||
$dayBeforeBalance = Steam::finalAccountBalance($account, $date);
|
||||
$startBalance = $dayBeforeBalance['balance'];
|
||||
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup);
|
||||
$defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
|
||||
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
|
||||
|
||||
foreach ($journals as $index => $journal) {
|
||||
|
@@ -177,7 +177,7 @@ class StandardMessageGenerator implements MessageGeneratorInterface
|
||||
$accounts = $this->collectAccounts($model);
|
||||
$enrichment = new AccountEnrichment();
|
||||
$enrichment->setUser($model->user);
|
||||
$enrichment->setNative(Amount::getNativeCurrencyByUserGroup($model->userGroup));
|
||||
$enrichment->setNative(Amount::getPrimaryCurrencyByUserGroup($model->userGroup));
|
||||
$accounts = $enrichment->enrich($accounts);
|
||||
foreach ($accounts as $account) {
|
||||
$transformer = new AccountTransformer();
|
||||
|
@@ -52,7 +52,7 @@ class AccountObserver
|
||||
if (!Amount::convertToNative($account->user)) {
|
||||
return;
|
||||
}
|
||||
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup);
|
||||
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$currency = $repository->getAccountCurrency($account);
|
||||
if (null !== $currency && $currency->id !== $userCurrency->id && '' !== (string) $account->virtual_balance && 0 !== bccomp($account->virtual_balance, '0')) {
|
||||
|
@@ -42,7 +42,7 @@ class AutoBudgetObserver
|
||||
if (!Amount::convertToNative($autoBudget->budget->user)) {
|
||||
return;
|
||||
}
|
||||
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($autoBudget->budget->user->userGroup);
|
||||
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($autoBudget->budget->user->userGroup);
|
||||
$autoBudget->native_amount = null;
|
||||
if ($autoBudget->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
|
@@ -44,7 +44,7 @@ class AvailableBudgetObserver
|
||||
|
||||
return;
|
||||
}
|
||||
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($availableBudget->user->userGroup);
|
||||
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($availableBudget->user->userGroup);
|
||||
$availableBudget->native_amount = null;
|
||||
if ($availableBudget->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
|
@@ -46,7 +46,7 @@ class BillObserver
|
||||
if (!Amount::convertToNative($bill->user)) {
|
||||
return;
|
||||
}
|
||||
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($bill->user->userGroup);
|
||||
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($bill->user->userGroup);
|
||||
$bill->native_amount_min = null;
|
||||
$bill->native_amount_max = null;
|
||||
if ($bill->transactionCurrency->id !== $userCurrency->id) {
|
||||
|
@@ -44,7 +44,7 @@ class BudgetLimitObserver
|
||||
|
||||
return;
|
||||
}
|
||||
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($budgetLimit->budget->user->userGroup);
|
||||
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($budgetLimit->budget->user->userGroup);
|
||||
$budgetLimit->native_amount = null;
|
||||
if ($budgetLimit->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
|
@@ -48,7 +48,7 @@ class PiggyBankEventObserver
|
||||
if (!Amount::convertToNative($user)) {
|
||||
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;
|
||||
if ($event->piggyBank->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
|
@@ -49,7 +49,7 @@ class PiggyBankObserver
|
||||
|
||||
return;
|
||||
}
|
||||
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($group);
|
||||
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($group);
|
||||
$piggyBank->native_target_amount = null;
|
||||
if ($piggyBank->transactionCurrency->id !== $userCurrency->id) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
|
@@ -53,7 +53,7 @@ class TransactionObserver
|
||||
if (!Amount::convertToNative($transaction->transactionJournal->user)) {
|
||||
return;
|
||||
}
|
||||
$userCurrency = app('amount')->getNativeCurrencyByUserGroup($transaction->transactionJournal->user->userGroup);
|
||||
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($transaction->transactionJournal->user->userGroup);
|
||||
$transaction->native_amount = null;
|
||||
$transaction->native_foreign_amount = null;
|
||||
// first normal amount
|
||||
|
@@ -65,7 +65,7 @@ class TransactionCurrency extends Model
|
||||
public function refreshForUser(User $user): void
|
||||
{
|
||||
$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->userGroupEnabled = null !== $current;
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
$defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
|
||||
$return = [
|
||||
'accounts' => [],
|
||||
@@ -148,7 +148,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
|
||||
*/
|
||||
private function groupExpenseByDestination(array $array): array
|
||||
{
|
||||
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
$defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
|
||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
@@ -236,7 +236,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
|
||||
*/
|
||||
private function groupIncomeBySource(array $array): array
|
||||
{
|
||||
$defaultCurrency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
$defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
|
||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
|
@@ -271,7 +271,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
}
|
||||
$currency->enabled = true;
|
||||
$currency->save();
|
||||
@@ -369,7 +369,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
|
||||
}
|
||||
// catch unexpected null:
|
||||
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->save();
|
||||
|
@@ -391,7 +391,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
|
||||
$autoBudget = $this->getAutoBudget($budget);
|
||||
|
||||
// grab default currency:
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
|
||||
if (!$autoBudget instanceof AutoBudget) {
|
||||
// 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']);
|
||||
}
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
}
|
||||
|
||||
$autoBudget = new AutoBudget();
|
||||
|
@@ -143,7 +143,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
|
||||
|
||||
// if needs conversion to native.
|
||||
$convertToNative = Amount::convertToNative($this->user);
|
||||
$nativeCurrency = Amount::getNativeCurrencyByUserGroup($this->userGroup);
|
||||
$nativeCurrency = Amount::getPrimaryCurrencyByUserGroup($this->userGroup);
|
||||
$currencyId = (int) $nativeCurrency->id;
|
||||
$currencyCode = $nativeCurrency->code;
|
||||
$currencyName = $nativeCurrency->name;
|
||||
|
@@ -243,7 +243,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
|
||||
Log::debug('Grabbing default currency for this user...');
|
||||
|
||||
/** @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));
|
||||
@@ -428,7 +428,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
|
||||
|
||||
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));
|
||||
$this->userGroup->currencies()->detach($currency->id);
|
||||
foreach ($this->userGroup->currencies()->get() as $item) {
|
||||
|
@@ -71,7 +71,7 @@ trait ModifiesPiggyBanks
|
||||
$pivot->native_current_amount = null;
|
||||
|
||||
// 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) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter->setIgnoreSettings(true);
|
||||
@@ -94,7 +94,7 @@ trait ModifiesPiggyBanks
|
||||
$pivot->native_current_amount = null;
|
||||
|
||||
// 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) {
|
||||
$converter = new ExchangeRateConverter();
|
||||
$converter->setIgnoreSettings(true);
|
||||
|
@@ -171,7 +171,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
$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));
|
||||
|
||||
|
@@ -340,7 +340,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
{
|
||||
$return = [];
|
||||
$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)
|
||||
->with('piggyBank', 'piggyBank.account')
|
||||
->get(['piggy_bank_events.*'])
|
||||
|
@@ -245,7 +245,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
Log::debug('Grabbing default currency for this user...');
|
||||
|
||||
/** @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));
|
||||
@@ -376,7 +376,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
|
||||
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));
|
||||
$this->userGroup->currencies()->detach($currency->id);
|
||||
foreach ($this->userGroup->currencies()->get() as $item) {
|
||||
|
@@ -235,7 +235,7 @@ trait AccountServiceTrait
|
||||
// get or grab currency:
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup);
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
|
||||
}
|
||||
|
||||
// submit to factory:
|
||||
@@ -355,7 +355,7 @@ trait AccountServiceTrait
|
||||
|
||||
if (null === $currency) {
|
||||
// use default currency:
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
}
|
||||
$currency->enabled = true;
|
||||
$currency->save();
|
||||
@@ -395,7 +395,7 @@ trait AccountServiceTrait
|
||||
// if exists, update:
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
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:
|
||||
@@ -461,7 +461,7 @@ trait AccountServiceTrait
|
||||
// get or grab currency:
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup);
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
|
||||
}
|
||||
// submit to factory:
|
||||
$submission = [
|
||||
@@ -578,7 +578,7 @@ trait AccountServiceTrait
|
||||
// if exists, update:
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
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:
|
||||
@@ -659,7 +659,7 @@ trait AccountServiceTrait
|
||||
// get or grab currency:
|
||||
$currency = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup);
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup);
|
||||
}
|
||||
|
||||
// submit to factory:
|
||||
|
@@ -109,7 +109,7 @@ trait RecurringTransactionTrait
|
||||
$currency = $factory->find($array['currency_id'] ?? null, $array['currency_code'] ?? null);
|
||||
$foreignCurrency = $factory->find($array['foreign_currency_id'] ?? null, $array['foreign_currency_code'] ?? null);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getNativeCurrencyByUserGroup($recurrence->user->userGroup);
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($recurrence->user->userGroup);
|
||||
}
|
||||
|
||||
app('log')->debug(
|
||||
|
@@ -56,7 +56,7 @@ class BillUpdateService
|
||||
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
$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.
|
||||
$currency->enabled = true;
|
||||
|
@@ -137,25 +137,25 @@ class Amount
|
||||
return $this->getSystemCurrency();
|
||||
}
|
||||
|
||||
public function getNativeCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
|
||||
public function getPrimaryCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('getNativeCurrencyByGroup');
|
||||
$cache->addProperty('getPrimaryCurrencyByGroup');
|
||||
$cache->addProperty($userGroup->id);
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
/** @var null|TransactionCurrency $native */
|
||||
$native = $userGroup->currencies()->where('group_default', true)->first();
|
||||
if (null === $native) {
|
||||
$native = $this->getSystemCurrency();
|
||||
/** @var null|TransactionCurrency $primary */
|
||||
$primary = $userGroup->currencies()->where('group_default', true)->first();
|
||||
if (null === $primary) {
|
||||
$primary = $this->getSystemCurrency();
|
||||
// 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
|
||||
|
@@ -347,6 +347,6 @@ class BudgetReportGenerator
|
||||
$this->blRepository->setUser($user);
|
||||
$this->opsRepository->setUser($user);
|
||||
$this->nbRepository->setUser($user);
|
||||
$this->currency = app('amount')->getNativeCurrencyByUserGroup($user->userGroup);
|
||||
$this->currency = app('amount')->getPrimaryCurrencyByUserGroup($user->userGroup);
|
||||
}
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ class TransactionSummarizer
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->default = Amount::getNativeCurrencyByUserGroup($user->userGroup);
|
||||
$this->default = Amount::getPrimaryCurrencyByUserGroup($user->userGroup);
|
||||
$this->convertToNative = Amount::convertToNative($user);
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ class TransactionSummarizer
|
||||
$idKey = sprintf('%s_account_id', $direction);
|
||||
$nameKey = sprintf('%s_account_name', $direction);
|
||||
$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));
|
||||
|
@@ -224,7 +224,7 @@ class Steam
|
||||
$request->subDay()->endOfDay();
|
||||
Log::debug(sprintf('finalAccountBalanceInRange: Call finalAccountBalance with date/time "%s"', $request->toIso8601String()));
|
||||
$startBalance = $this->finalAccountBalance($account, $request);
|
||||
$nativeCurrency = Amount::getNativeCurrencyByUserGroup($account->user->userGroup);
|
||||
$nativeCurrency = Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
|
||||
$accountCurrency = $this->getAccountCurrency($account);
|
||||
$hasCurrency = $accountCurrency instanceof TransactionCurrency;
|
||||
$currency = $accountCurrency ?? $nativeCurrency;
|
||||
@@ -347,7 +347,7 @@ class Steam
|
||||
$convertToNative = Amount::convertToNative($account->user);
|
||||
}
|
||||
if (!$native instanceof TransactionCurrency) {
|
||||
$native = Amount::getNativeCurrencyByUserGroup($account->user->userGroup);
|
||||
$native = Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
|
||||
}
|
||||
// account balance thing.
|
||||
$currencyPresent = isset($account->meta) && array_key_exists('currency', $account->meta) && null !== $account->meta['currency'];
|
||||
|
@@ -61,7 +61,7 @@ class PiggyBankEventTransformer extends AbstractTransformer
|
||||
$this->piggyRepos->setUser($account->user);
|
||||
|
||||
// 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:
|
||||
$journalId = $event->transaction_journal_id;
|
||||
|
@@ -105,7 +105,7 @@ class UserGroupTransformer extends AbstractTransformer
|
||||
*/
|
||||
public function transform(UserGroup $userGroup): array
|
||||
{
|
||||
$currency = Amount::getNativeCurrencyByUserGroup($userGroup);
|
||||
$currency = Amount::getPrimaryCurrencyByUserGroup($userGroup);
|
||||
|
||||
return [
|
||||
'id' => $userGroup->id,
|
||||
|
@@ -139,7 +139,7 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
return $objects;
|
||||
|
Reference in New Issue
Block a user