Replace calls to Amount facade.

This commit is contained in:
James Cole
2025-12-20 08:21:05 +01:00
parent c63f4a941b
commit 340540bd5a
39 changed files with 77 additions and 77 deletions

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).
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($userGroup); $primaryCurrency = \FireflyIII\Support\Facades\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 = [$primaryCurrency->id]; $found = [$primaryCurrency->id];

View File

@@ -133,6 +133,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')->getPrimaryCurrencyByUserGroup($account->userGroup); return $repos->getAccountCurrency($account) ?? \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->userGroup);
} }
} }

View File

@@ -105,7 +105,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:
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($user->userGroup); $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($user->userGroup);
/** @var Account $account */ /** @var Account $account */
foreach ($accounts as $account) { foreach ($accounts as $account) {

View File

@@ -67,7 +67,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')->getPrimaryCurrencyByUserGroup($user->userGroup); $currency = \FireflyIII\Support\Facades\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

@@ -95,7 +95,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')->getPrimaryCurrencyByUserGroup($piggyBank->account->user->userGroup); $currency = $this->accountRepository->getAccountCurrency($piggyBank->account) ?? \FireflyIII\Support\Facades\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

@@ -51,7 +51,7 @@ class BillFactory
Log::debug(sprintf('Now in %s', __METHOD__), $data); 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')->getPrimaryCurrencyByUserGroup($this->user->userGroup); ?? \FireflyIII\Support\Facades\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

@@ -126,7 +126,7 @@ class PiggyBankFactory
private function getCurrency(array $data): TransactionCurrency private function getCurrency(array $data): TransactionCurrency
{ {
// currency: // currency:
$primaryCurrency = app('amount')->getPrimaryCurrency(); $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency();
$currency = null; $currency = null;
if (array_key_exists('transaction_currency_code', $data)) { if (array_key_exists('transaction_currency_code', $data)) {
$currency = $this->currencyRepository->findByCode((string)($data['transaction_currency_code'] ?? '')); $currency = $this->currencyRepository->findByCode((string)($data['transaction_currency_code'] ?? ''));

View File

@@ -502,7 +502,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')->getPrimaryCurrencyByUserGroup($this->user->userGroup); return \FireflyIII\Support\Facades\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

@@ -144,7 +144,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
$dayBeforeBalance = Steam::accountsBalancesOptimized(new Collection()->push($account), $date)[$account->id]; $dayBeforeBalance = Steam::accountsBalancesOptimized(new Collection()->push($account), $date)[$account->id];
$startBalance = $dayBeforeBalance['balance']; $startBalance = $dayBeforeBalance['balance'];
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup); $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
$currency = $accountRepository->getAccountCurrency($account) ?? $primaryCurrency; $currency = $accountRepository->getAccountCurrency($account) ?? $primaryCurrency;
foreach ($journals as $index => $journal) { foreach ($journals as $index => $journal) {

View File

@@ -52,7 +52,7 @@ class AccountObserver
if (!Amount::convertToPrimary($account->user)) { if (!Amount::convertToPrimary($account->user)) {
return; return;
} }
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup); $userCurrency = \FireflyIII\Support\Facades\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::convertToPrimary($autoBudget->budget->user)) { if (!Amount::convertToPrimary($autoBudget->budget->user)) {
return; return;
} }
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($autoBudget->budget->user->userGroup); $userCurrency = \FireflyIII\Support\Facades\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')->getPrimaryCurrencyByUserGroup($availableBudget->user->userGroup); $userCurrency = \FireflyIII\Support\Facades\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::convertToPrimary($bill->user)) { if (!Amount::convertToPrimary($bill->user)) {
return; return;
} }
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($bill->user->userGroup); $userCurrency = \FireflyIII\Support\Facades\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

@@ -72,7 +72,7 @@ class BudgetLimitObserver
return; return;
} }
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($budgetLimit->budget->user->userGroup); $userCurrency = \FireflyIII\Support\Facades\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::convertToPrimary($user)) { if (!Amount::convertToPrimary($user)) {
return; return;
} }
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($event->piggyBank->accounts()->first()->user->userGroup); $userCurrency = \FireflyIII\Support\Facades\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')->getPrimaryCurrencyByUserGroup($group); $userCurrency = \FireflyIII\Support\Facades\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

@@ -52,7 +52,7 @@ class TransactionObserver
if (!Amount::convertToPrimary($transaction->transactionJournal->user)) { if (!Amount::convertToPrimary($transaction->transactionJournal->user)) {
return; return;
} }
$userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($transaction->transactionJournal->user->userGroup); $userCurrency = \FireflyIII\Support\Facades\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

@@ -205,14 +205,14 @@ class BudgetLimitController extends Controller
// add some extra metadata: // add some extra metadata:
$spentArr = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, null, new Collection()->push($budget), $currency); $spentArr = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, null, new Collection()->push($budget), $currency);
$array['spent'] = $spentArr[$currency->id]['sum'] ?? '0'; $array['spent'] = $spentArr[$currency->id]['sum'] ?? '0';
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], (string) $array['amount'])); $array['left_formatted'] = \FireflyIII\Support\Facades\Amount::formatAnything($limit->transactionCurrency, bcadd($array['spent'], (string) $array['amount']));
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']); $array['amount_formatted'] = \FireflyIII\Support\Facades\Amount::formatAnything($limit->transactionCurrency, $limit['amount']);
$array['days_left'] = (string) $this->activeDaysLeft($start, $end); $array['days_left'] = (string) $this->activeDaysLeft($start, $end);
// left per day: // left per day:
$array['left_per_day'] = 0 === bccomp('0', $array['days_left']) ? bcadd((string) $array['spent'], (string) $array['amount']) : bcdiv(bcadd((string) $array['spent'], (string) $array['amount']), $array['days_left']); $array['left_per_day'] = 0 === bccomp('0', $array['days_left']) ? bcadd((string) $array['spent'], (string) $array['amount']) : bcdiv(bcadd((string) $array['spent'], (string) $array['amount']), $array['days_left']);
// left per day formatted. // left per day formatted.
$array['left_per_day_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $array['left_per_day']); $array['left_per_day_formatted'] = \FireflyIII\Support\Facades\Amount::formatAnything($limit->transactionCurrency, $array['left_per_day']);
// notes: // notes:
$array['notes'] = $this->blRepository->getNoteText($limit); $array['notes'] = $this->blRepository->getNoteText($limit);
@@ -239,8 +239,8 @@ class BudgetLimitController extends Controller
$this->blRepository->destroyBudgetLimit($budgetLimit); $this->blRepository->destroyBudgetLimit($budgetLimit);
$array = [ $array = [
'budget_id' => $budgetId, 'budget_id' => $budgetId,
'left_formatted' => app('amount')->formatAnything($currency, '0'), 'left_formatted' => \FireflyIII\Support\Facades\Amount::formatAnything($currency, '0'),
'left_per_day_formatted' => app('amount')->formatAnything($currency, '0'), 'left_per_day_formatted' => \FireflyIII\Support\Facades\Amount::formatAnything($currency, '0'),
'transaction_currency_id' => $currency->id, 'transaction_currency_id' => $currency->id,
]; ];
@@ -269,14 +269,14 @@ class BudgetLimitController extends Controller
); );
$daysLeft = $this->activeDaysLeft($limit->start_date, $limit->end_date); $daysLeft = $this->activeDaysLeft($limit->start_date, $limit->end_date);
$array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0'; $array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0';
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], (string) $array['amount'])); $array['left_formatted'] = \FireflyIII\Support\Facades\Amount::formatAnything($limit->transactionCurrency, bcadd($array['spent'], (string) $array['amount']));
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']); $array['amount_formatted'] = \FireflyIII\Support\Facades\Amount::formatAnything($limit->transactionCurrency, $limit['amount']);
$array['days_left'] = (string) $daysLeft; $array['days_left'] = (string) $daysLeft;
$array['left_per_day'] = 0 === $daysLeft ? bcadd((string) $array['spent'], (string) $array['amount']) : bcdiv(bcadd((string) $array['spent'], (string) $array['amount']), $array['days_left']); $array['left_per_day'] = 0 === $daysLeft ? bcadd((string) $array['spent'], (string) $array['amount']) : bcdiv(bcadd((string) $array['spent'], (string) $array['amount']), $array['days_left']);
// left per day formatted. // left per day formatted.
$array['amount'] = Steam::bcround($limit['amount'], $limit->transactionCurrency->decimal_places); $array['amount'] = Steam::bcround($limit['amount'], $limit->transactionCurrency->decimal_places);
$array['left_per_day_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $array['left_per_day']); $array['left_per_day_formatted'] = \FireflyIII\Support\Facades\Amount::formatAnything($limit->transactionCurrency, $array['left_per_day']);
if ('true' === $request->get('redirect')) { if ('true' === $request->get('redirect')) {
return redirect(route('budgets.index')); return redirect(route('budgets.index'));
} }

View File

@@ -106,7 +106,7 @@ class JavascriptController extends Controller
$currency = $repository->getAccountCurrency($account) ?? $this->primaryCurrency; $currency = $repository->getAccountCurrency($account) ?? $this->primaryCurrency;
} }
$locale = Steam::getLocale(); $locale = Steam::getLocale();
$accounting = app('amount')->getJsConfig(); $accounting = \FireflyIII\Support\Facades\Amount::getJsConfig();
$accounting['frac_digits'] = $currency->decimal_places; $accounting['frac_digits'] = $currency->decimal_places;
$pref = Preferences::get('language', config('firefly.default_language', 'en_US')); $pref = Preferences::get('language', config('firefly.default_language', 'en_US'));
$lang = $pref->data; $lang = $pref->data;

View File

@@ -121,15 +121,15 @@ class BoxController extends Controller
$keys = array_keys($sums); $keys = array_keys($sums);
foreach ($keys as $currencyId) { foreach ($keys as $currencyId) {
$currency = $repository->find($currencyId); $currency = $repository->find($currencyId);
$sums[$currencyId] = app('amount')->formatAnything($currency, $sums[$currencyId], false); $sums[$currencyId] = \FireflyIII\Support\Facades\Amount::formatAnything($currency, $sums[$currencyId], false);
$incomes[$currencyId] = app('amount')->formatAnything($currency, $incomes[$currencyId] ?? '0', false); $incomes[$currencyId] = \FireflyIII\Support\Facades\Amount::formatAnything($currency, $incomes[$currencyId] ?? '0', false);
$expenses[$currencyId] = app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false); $expenses[$currencyId] = \FireflyIII\Support\Facades\Amount::formatAnything($currency, $expenses[$currencyId] ?? '0', false);
} }
if (0 === count($sums)) { if (0 === count($sums)) {
$currency = $this->primaryCurrency; $currency = $this->primaryCurrency;
$sums[$this->primaryCurrency->id] = app('amount')->formatAnything($this->primaryCurrency, '0', false); $sums[$this->primaryCurrency->id] = \FireflyIII\Support\Facades\Amount::formatAnything($this->primaryCurrency, '0', false);
$incomes[$this->primaryCurrency->id] = app('amount')->formatAnything($this->primaryCurrency, '0', false); $incomes[$this->primaryCurrency->id] = \FireflyIII\Support\Facades\Amount::formatAnything($this->primaryCurrency, '0', false);
$expenses[$this->primaryCurrency->id] = app('amount')->formatAnything($this->primaryCurrency, '0', false); $expenses[$this->primaryCurrency->id] = \FireflyIII\Support\Facades\Amount::formatAnything($this->primaryCurrency, '0', false);
} }
$response = [ $response = [
@@ -187,7 +187,7 @@ class BoxController extends Controller
if ('primary' === $key) { if ('primary' === $key) {
continue; continue;
} }
$return[$data['currency_id']] = app('amount')->formatFlat($data['currency_symbol'], $data['currency_decimal_places'], $data['balance'], false); $return[$data['currency_id']] = \FireflyIII\Support\Facades\Amount::formatFlat($data['currency_symbol'], $data['currency_decimal_places'], $data['balance'], false);
} }
$return = [ $return = [
'net_worths' => array_values($return), 'net_worths' => array_values($return),

View File

@@ -84,9 +84,9 @@ class BudgetController extends Controller
return response()->json( return response()->json(
[ [
'budgeted' => $budgeted, 'budgeted' => $budgeted,
'budgeted_formatted' => app('amount')->formatAnything($currency, $budgeted, true), 'budgeted_formatted' => \FireflyIII\Support\Facades\Amount::formatAnything($currency, $budgeted, true),
'available' => $available, 'available' => $available,
'available_formatted' => app('amount')->formatAnything($currency, $available, true), 'available_formatted' => \FireflyIII\Support\Facades\Amount::formatAnything($currency, $available, true),
'percentage' => $percentage, 'percentage' => $percentage,
'currency_id' => $currency->id, 'currency_id' => $currency->id,
'currency_code' => $currency->code, 'currency_code' => $currency->code,

View File

@@ -167,7 +167,7 @@ class AmountController extends Controller
$piggyBank->refresh(); $piggyBank->refresh();
} }
if (0 !== bccomp($total, '0')) { if (0 !== bccomp($total, '0')) {
session()->flash('success', (string) trans('firefly.added_amount_to_piggy', ['amount' => app('amount')->formatAnything($piggyBank->transactionCurrency, $total, false), 'name' => $piggyBank->name])); session()->flash('success', (string) trans('firefly.added_amount_to_piggy', ['amount' => \FireflyIII\Support\Facades\Amount::formatAnything($piggyBank->transactionCurrency, $total, false), 'name' => $piggyBank->name]));
Preferences::mark(); Preferences::mark();
return redirect(route('piggy-banks.index')); return redirect(route('piggy-banks.index'));
@@ -177,7 +177,7 @@ class AmountController extends Controller
'error', 'error',
(string) trans( (string) trans(
'firefly.cannot_add_amount_piggy', 'firefly.cannot_add_amount_piggy',
['amount' => app('amount')->formatAnything($piggyBank->transactionCurrency, $total, false), 'name' => e($piggyBank->name)] ['amount' => \FireflyIII\Support\Facades\Amount::formatAnything($piggyBank->transactionCurrency, $total, false), 'name' => e($piggyBank->name)]
) )
); );
@@ -214,7 +214,7 @@ class AmountController extends Controller
'success', 'success',
(string) trans( (string) trans(
'firefly.removed_amount_from_piggy', 'firefly.removed_amount_from_piggy',
['amount' => app('amount')->formatAnything($piggyBank->transactionCurrency, $total, false), 'name' => $piggyBank->name] ['amount' => \FireflyIII\Support\Facades\Amount::formatAnything($piggyBank->transactionCurrency, $total, false), 'name' => $piggyBank->name]
) )
); );
Preferences::mark(); Preferences::mark();
@@ -226,7 +226,7 @@ class AmountController extends Controller
'error', 'error',
(string) trans( (string) trans(
'firefly.cannot_remove_from_piggy', 'firefly.cannot_remove_from_piggy',
['amount' => app('amount')->formatAnything($piggyBank->transactionCurrency, $total, false), 'name' => e($piggyBank->name)] ['amount' => \FireflyIII\Support\Facades\Amount::formatAnything($piggyBank->transactionCurrency, $total, false), 'name' => e($piggyBank->name)]
) )
); );

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')->getPrimaryCurrencyByUserGroup($user->userGroup); $native = \FireflyIII\Support\Facades\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

@@ -353,7 +353,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
if (AccountTypeEnum::ASSET->value !== $account->accountType->type) { if (AccountTypeEnum::ASSET->value !== $account->accountType->type) {
throw new FireflyException(sprintf('%s is not an asset account.', $account->name)); throw new FireflyException(sprintf('%s is not an asset account.', $account->name));
} }
$currency = $this->getAccountCurrency($account) ?? app('amount')->getPrimaryCurrency(); $currency = $this->getAccountCurrency($account) ?? \FireflyIII\Support\Facades\Amount::getPrimaryCurrency();
$name = trans('firefly.reconciliation_account_name', ['name' => $account->name, 'currency' => $currency->code]); $name = trans('firefly.reconciliation_account_name', ['name' => $account->name, 'currency' => $currency->code]);
/** @var AccountType $type */ /** @var AccountType $type */

View File

@@ -59,7 +59,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup);
$return = [ $return = [
'accounts' => [], 'accounts' => [],
@@ -146,7 +146,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
private function groupExpenseByDestination(array $array): array private function groupExpenseByDestination(array $array): array
{ {
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup);
/** @var CurrencyRepositoryInterface $currencyRepos */ /** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class); $currencyRepos = app(CurrencyRepositoryInterface::class);
@@ -231,7 +231,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
private function groupIncomeBySource(array $array): array private function groupIncomeBySource(array $array): array
{ {
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup);
/** @var CurrencyRepositoryInterface $currencyRepos */ /** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class); $currencyRepos = app(CurrencyRepositoryInterface::class);

View File

@@ -536,7 +536,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
$bills = $this->getActiveBills(); $bills = $this->getActiveBills();
$return = []; $return = [];
$convertToPrimary = Amount::convertToPrimary($this->user); $convertToPrimary = Amount::convertToPrimary($this->user);
$primary = app('amount')->getPrimaryCurrency(); $primary = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency();
/** @var Bill $bill */ /** @var Bill $bill */
foreach ($bills as $bill) { foreach ($bills as $bill) {
@@ -602,7 +602,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
$bills = $this->getActiveBills(); $bills = $this->getActiveBills();
$return = []; $return = [];
$convertToPrimary = Amount::convertToPrimary($this->user); $convertToPrimary = Amount::convertToPrimary($this->user);
$primary = app('amount')->getPrimaryCurrency(); $primary = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency();
/** @var Bill $bill */ /** @var Bill $bill */
foreach ($bills as $bill) { foreach ($bills as $bill) {

View File

@@ -94,7 +94,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
$limitRepository = app(BudgetLimitRepository::class); $limitRepository = app(BudgetLimitRepository::class);
$limitRepository->setUser($this->user); $limitRepository->setUser($this->user);
$budgets = $this->getActiveBudgets(); $budgets = $this->getActiveBudgets();
$primaryCurrency = app('amount')->getPrimaryCurrency(); $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency();
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();
/** @var Budget $budget */ /** @var Budget $budget */
@@ -393,7 +393,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
$autoBudget = $this->getAutoBudget($budget); $autoBudget = $this->getAutoBudget($budget);
// grab default currency: // grab default currency:
$currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); $currency = \FireflyIII\Support\Facades\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.
@@ -778,7 +778,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')->getPrimaryCurrencyByUserGroup($this->user->userGroup); $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup);
} }
$autoBudget = new AutoBudget(); $autoBudget = new AutoBudget();

View File

@@ -240,7 +240,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')->getPrimaryCurrencyByUserGroup($this->user->userGroup); $result = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup);
} }
Log::debug(sprintf('Final result: %s', $result->code)); Log::debug(sprintf('Final result: %s', $result->code));
@@ -440,7 +440,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
public function makePrimary(TransactionCurrency $currency): void public function makePrimary(TransactionCurrency $currency): void
{ {
$current = app('amount')->getPrimaryCurrencyByUserGroup($this->userGroup); $current = \FireflyIII\Support\Facades\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

@@ -72,7 +72,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')->getPrimaryCurrencyByUserGroup($this->user->userGroup); $userCurrency = \FireflyIII\Support\Facades\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);
@@ -95,7 +95,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')->getPrimaryCurrencyByUserGroup($this->user->userGroup); $userCurrency = \FireflyIII\Support\Facades\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);
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup);
Log::debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBank->transactionCurrency->code)); Log::debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBank->transactionCurrency->code));
@@ -302,7 +302,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
/** @var PiggyBank $piggy */ /** @var PiggyBank $piggy */
foreach ($set as $piggy) { foreach ($set as $piggy) {
$currentAmount = $this->getCurrentAmount($piggy); $currentAmount = $this->getCurrentAmount($piggy);
$piggy->name = sprintf('%s (%s)', $piggy->name, app('amount')->formatAnything($piggy->transactionCurrency, $currentAmount, false)); $piggy->name = sprintf('%s (%s)', $piggy->name, \FireflyIII\Support\Facades\Amount::formatAnything($piggy->transactionCurrency, $currentAmount, false));
} }
return $set; return $set;

View File

@@ -231,7 +231,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')->getPrimaryCurrencyByUserGroup($account->user->userGroup); $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
} }
// submit to factory: // submit to factory:
@@ -348,7 +348,7 @@ trait AccountServiceTrait
if (null === $currency) { if (null === $currency) {
// use default currency: // use default currency:
$currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup);
} }
$currency->enabled = true; $currency->enabled = true;
$currency->save(); $currency->save();
@@ -388,7 +388,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')->getPrimaryCurrencyByUserGroup($account->user->userGroup); $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
} }
// simply grab the first journal and change it: // simply grab the first journal and change it:
@@ -454,7 +454,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')->getPrimaryCurrencyByUserGroup($account->user->userGroup); $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
} }
// submit to factory: // submit to factory:
$submission = [ $submission = [
@@ -571,7 +571,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')->getPrimaryCurrencyByUserGroup($account->user->userGroup); $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
} }
// simply grab the first journal and change it: // simply grab the first journal and change it:
@@ -652,7 +652,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')->getPrimaryCurrencyByUserGroup($account->user->userGroup); $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
} }
// submit to factory: // submit to factory:

View File

@@ -107,7 +107,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')->getPrimaryCurrencyByUserGroup($recurrence->user->userGroup); $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($recurrence->user->userGroup);
} }
Log::debug( Log::debug(

View File

@@ -53,7 +53,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')->getPrimaryCurrencyByUserGroup($bill->user->userGroup); ?? \FireflyIII\Support\Facades\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

@@ -123,10 +123,10 @@ class CurrencyForm
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value); $value = $this->fillFieldValue($name, $value);
$options['step'] = 'any'; $options['step'] = 'any';
$primaryCurrency = $options['currency'] ?? app('amount')->getPrimaryCurrency(); $primaryCurrency = $options['currency'] ?? \FireflyIII\Support\Facades\Amount::getPrimaryCurrency();
/** @var Collection $currencies */ /** @var Collection $currencies */
$currencies = app('amount')->getAllCurrencies(); $currencies = \FireflyIII\Support\Facades\Amount::getAllCurrencies();
unset($options['currency'], $options['placeholder']); unset($options['currency'], $options['placeholder']);
// perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount) // perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount)
@@ -176,10 +176,10 @@ class CurrencyForm
$classes = $this->getHolderClasses($name); $classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value); $value = $this->fillFieldValue($name, $value);
$options['step'] = 'any'; $options['step'] = 'any';
$primaryCurrency = $options['currency'] ?? app('amount')->getPrimaryCurrency(); $primaryCurrency = $options['currency'] ?? \FireflyIII\Support\Facades\Amount::getPrimaryCurrency();
/** @var Collection $currencies */ /** @var Collection $currencies */
$currencies = app('amount')->getCurrencies(); $currencies = \FireflyIII\Support\Facades\Amount::getCurrencies();
unset($options['currency'], $options['placeholder']); unset($options['currency'], $options['placeholder']);
// perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount) // perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount)
$preFilled = session('preFilled'); $preFilled = session('preFilled');

View File

@@ -67,7 +67,7 @@ trait ChartGeneration
/** @var AccountRepositoryInterface $accountRepos */ /** @var AccountRepositoryInterface $accountRepos */
$accountRepos = app(AccountRepositoryInterface::class); $accountRepos = app(AccountRepositoryInterface::class);
$primary = app('amount')->getPrimaryCurrency(); $primary = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency();
$chartData = []; $chartData = [];
Log::debug(sprintf('Start of accountBalanceChart(list, %s, %s)', $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s'))); Log::debug(sprintf('Start of accountBalanceChart(list, %s, %s)', $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s')));

View File

@@ -136,7 +136,7 @@ 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')->getPrimaryCurrencyByUserGroup($user->userGroup); $this->currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($user->userGroup);
} }
/** /**

View File

@@ -180,7 +180,7 @@ class General extends AbstractExtension
if ('balance' === $key) { if ('balance' === $key) {
// balance in account currency. // balance in account currency.
if (!$usePrimary) { if (!$usePrimary) {
$strings[] = app('amount')->formatAnything($currency, $balance, false); $strings[] = \FireflyIII\Support\Facades\Amount::formatAnything($currency, $balance, false);
} }
continue; continue;
@@ -188,14 +188,14 @@ class General extends AbstractExtension
if ('pc_balance' === $key) { if ('pc_balance' === $key) {
// balance in primary currency. // balance in primary currency.
if ($usePrimary) { if ($usePrimary) {
$strings[] = app('amount')->formatAnything($primary, $balance, false); $strings[] = \FireflyIII\Support\Facades\Amount::formatAnything($primary, $balance, false);
} }
continue; continue;
} }
// for multi currency accounts. // for multi currency accounts.
if ($usePrimary && $key !== $primary->code) { if ($usePrimary && $key !== $primary->code) {
$strings[] = app('amount')->formatAnything(Amount::getTransactionCurrencyByCode($key), $balance, false); $strings[] = \FireflyIII\Support\Facades\Amount::formatAnything(Amount::getTransactionCurrencyByCode($key), $balance, false);
} }
} }

View File

@@ -172,7 +172,7 @@ class TransactionGroupTwig extends AbstractExtension
if (TransactionTypeEnum::TRANSFER->value === $type) { if (TransactionTypeEnum::TRANSFER->value === $type) {
$colored = false; $colored = false;
} }
$result = app('amount')->formatFlat($array['foreign_currency_symbol'], (int)$array['foreign_currency_decimal_places'], $amount, $colored); $result = \FireflyIII\Support\Facades\Amount::formatFlat($array['foreign_currency_symbol'], (int)$array['foreign_currency_decimal_places'], $amount, $colored);
if (TransactionTypeEnum::TRANSFER->value === $type) { if (TransactionTypeEnum::TRANSFER->value === $type) {
return sprintf('<span class="text-info money-transfer">%s</span>', $result); return sprintf('<span class="text-info money-transfer">%s</span>', $result);
} }
@@ -199,7 +199,7 @@ class TransactionGroupTwig extends AbstractExtension
if (TransactionTypeEnum::TRANSFER->value === $type) { if (TransactionTypeEnum::TRANSFER->value === $type) {
$colored = false; $colored = false;
} }
$result = app('amount')->formatFlat($currency->symbol, $currency->decimal_places, $amount, $colored); $result = \FireflyIII\Support\Facades\Amount::formatFlat($currency->symbol, $currency->decimal_places, $amount, $colored);
if (TransactionTypeEnum::TRANSFER->value === $type) { if (TransactionTypeEnum::TRANSFER->value === $type) {
return sprintf('<span class="text-info money-transfer">%s</span>', $result); return sprintf('<span class="text-info money-transfer">%s</span>', $result);
} }
@@ -230,7 +230,7 @@ class TransactionGroupTwig extends AbstractExtension
$colored = false; $colored = false;
} }
$result = app('amount')->formatFlat($array['currency_symbol'], (int)$array['currency_decimal_places'], $amount, $colored); $result = \FireflyIII\Support\Facades\Amount::formatFlat($array['currency_symbol'], (int)$array['currency_decimal_places'], $amount, $colored);
if (TransactionTypeEnum::TRANSFER->value === $type) { if (TransactionTypeEnum::TRANSFER->value === $type) {
return sprintf('<span class="text-info money-transfer">%s</span>', $result); return sprintf('<span class="text-info money-transfer">%s</span>', $result);
} }
@@ -257,7 +257,7 @@ class TransactionGroupTwig extends AbstractExtension
if (TransactionTypeEnum::TRANSFER->value === $type) { if (TransactionTypeEnum::TRANSFER->value === $type) {
$colored = false; $colored = false;
} }
$result = app('amount')->formatFlat($currency->symbol, $currency->decimal_places, $amount, $colored); $result = \FireflyIII\Support\Facades\Amount::formatFlat($currency->symbol, $currency->decimal_places, $amount, $colored);
if (TransactionTypeEnum::TRANSFER->value === $type) { if (TransactionTypeEnum::TRANSFER->value === $type) {
return sprintf('<span class="text-info money-transfer">%s</span>', $result); return sprintf('<span class="text-info money-transfer">%s</span>', $result);
} }

View File

@@ -224,7 +224,7 @@ trait TransactionValidation
/** @var AccountRepository $accountRepository */ /** @var AccountRepository $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class); $accountRepository = app(AccountRepositoryInterface::class);
$primaryCurrency = app('amount')->getPrimaryCurrency(); $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency();
$sourceCurrency = $accountRepository->getAccountCurrency($source) ?? $primaryCurrency; $sourceCurrency = $accountRepository->getAccountCurrency($source) ?? $primaryCurrency;
$destinationCurrency = $accountRepository->getAccountCurrency($destination) ?? $primaryCurrency; $destinationCurrency = $accountRepository->getAccountCurrency($destination) ?? $primaryCurrency;
// if both accounts have the same currency, continue. // if both accounts have the same currency, continue.