diff --git a/app/Console/Commands/Correction/CorrectsCurrencies.php b/app/Console/Commands/Correction/CorrectsCurrencies.php index d1ee224081..c9df75fdc7 100644 --- a/app/Console/Commands/Correction/CorrectsCurrencies.php +++ b/app/Console/Commands/Correction/CorrectsCurrencies.php @@ -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). - $primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($userGroup); + $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($userGroup); Log::debug(sprintf('Now correcting currencies for user group #%d', $userGroup->id)); $found = [$primaryCurrency->id]; diff --git a/app/Console/Commands/Correction/CorrectsOpeningBalanceCurrencies.php b/app/Console/Commands/Correction/CorrectsOpeningBalanceCurrencies.php index 9857fa2209..a52e8b04a4 100644 --- a/app/Console/Commands/Correction/CorrectsOpeningBalanceCurrencies.php +++ b/app/Console/Commands/Correction/CorrectsOpeningBalanceCurrencies.php @@ -133,6 +133,6 @@ class CorrectsOpeningBalanceCurrencies extends Command $repos = app(AccountRepositoryInterface::class); $repos->setUser($account->user); - return $repos->getAccountCurrency($account) ?? app('amount')->getPrimaryCurrencyByUserGroup($account->userGroup); + return $repos->getAccountCurrency($account) ?? \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->userGroup); } } diff --git a/app/Console/Commands/Upgrade/UpgradesAccountCurrencies.php b/app/Console/Commands/Upgrade/UpgradesAccountCurrencies.php index 833f87ab4a..46b7736562 100644 --- a/app/Console/Commands/Upgrade/UpgradesAccountCurrencies.php +++ b/app/Console/Commands/Upgrade/UpgradesAccountCurrencies.php @@ -105,7 +105,7 @@ class UpgradesAccountCurrencies extends Command $accounts = $this->accountRepos->getAccountsByType([AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value]); // get user's currency preference: - $primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($user->userGroup); + $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($user->userGroup); /** @var Account $account */ foreach ($accounts as $account) { diff --git a/app/Console/Commands/Upgrade/UpgradesBudgetLimits.php b/app/Console/Commands/Upgrade/UpgradesBudgetLimits.php index 1f0d670b42..4bb1017bbe 100644 --- a/app/Console/Commands/Upgrade/UpgradesBudgetLimits.php +++ b/app/Console/Commands/Upgrade/UpgradesBudgetLimits.php @@ -67,7 +67,7 @@ class UpgradesBudgetLimits extends Command /** @var null|User $user */ $user = $budget->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->save(); $this->friendlyInfo( diff --git a/app/Console/Commands/Upgrade/UpgradesMultiPiggyBanks.php b/app/Console/Commands/Upgrade/UpgradesMultiPiggyBanks.php index 1207bc9c76..1d746b4b9e 100644 --- a/app/Console/Commands/Upgrade/UpgradesMultiPiggyBanks.php +++ b/app/Console/Commands/Upgrade/UpgradesMultiPiggyBanks.php @@ -95,7 +95,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')->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. $piggyBank->transaction_currency_id = $currency->id; diff --git a/app/Factory/BillFactory.php b/app/Factory/BillFactory.php index e7fe5cfa59..48f3a4e6f8 100644 --- a/app/Factory/BillFactory.php +++ b/app/Factory/BillFactory.php @@ -51,7 +51,7 @@ class BillFactory 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')->getPrimaryCurrencyByUserGroup($this->user->userGroup); + ?? \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup); try { $skip = array_key_exists('skip', $data) ? $data['skip'] : 0; diff --git a/app/Factory/PiggyBankFactory.php b/app/Factory/PiggyBankFactory.php index d74cba948e..9eb807725a 100644 --- a/app/Factory/PiggyBankFactory.php +++ b/app/Factory/PiggyBankFactory.php @@ -126,7 +126,7 @@ class PiggyBankFactory private function getCurrency(array $data): TransactionCurrency { // currency: - $primaryCurrency = app('amount')->getPrimaryCurrency(); + $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency(); $currency = null; if (array_key_exists('transaction_currency_code', $data)) { $currency = $this->currencyRepository->findByCode((string)($data['transaction_currency_code'] ?? '')); diff --git a/app/Factory/TransactionJournalFactory.php b/app/Factory/TransactionJournalFactory.php index 491fe16b79..7d890b95ce 100644 --- a/app/Factory/TransactionJournalFactory.php +++ b/app/Factory/TransactionJournalFactory.php @@ -502,7 +502,7 @@ class TransactionJournalFactory $preference = $this->accountRepository->getAccountCurrency($account); if (null === $preference && !$currency instanceof TransactionCurrency) { // return user's default: - return app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); + return \FireflyIII\Support\Facades\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)); diff --git a/app/Generator/Report/Audit/MonthReportGenerator.php b/app/Generator/Report/Audit/MonthReportGenerator.php index 3c35cb8834..9bc9ec1546 100644 --- a/app/Generator/Report/Audit/MonthReportGenerator.php +++ b/app/Generator/Report/Audit/MonthReportGenerator.php @@ -144,7 +144,7 @@ class MonthReportGenerator implements ReportGeneratorInterface $dayBeforeBalance = Steam::accountsBalancesOptimized(new Collection()->push($account), $date)[$account->id]; $startBalance = $dayBeforeBalance['balance']; - $primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup); + $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup); $currency = $accountRepository->getAccountCurrency($account) ?? $primaryCurrency; foreach ($journals as $index => $journal) { diff --git a/app/Handlers/Observer/AccountObserver.php b/app/Handlers/Observer/AccountObserver.php index 6380b77755..0cc686a618 100644 --- a/app/Handlers/Observer/AccountObserver.php +++ b/app/Handlers/Observer/AccountObserver.php @@ -52,7 +52,7 @@ class AccountObserver if (!Amount::convertToPrimary($account->user)) { return; } - $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup); + $userCurrency = \FireflyIII\Support\Facades\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')) { diff --git a/app/Handlers/Observer/AutoBudgetObserver.php b/app/Handlers/Observer/AutoBudgetObserver.php index ca030ba70e..003767c1d9 100644 --- a/app/Handlers/Observer/AutoBudgetObserver.php +++ b/app/Handlers/Observer/AutoBudgetObserver.php @@ -42,7 +42,7 @@ class AutoBudgetObserver if (!Amount::convertToPrimary($autoBudget->budget->user)) { return; } - $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($autoBudget->budget->user->userGroup); + $userCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($autoBudget->budget->user->userGroup); $autoBudget->native_amount = null; if ($autoBudget->transactionCurrency->id !== $userCurrency->id) { $converter = new ExchangeRateConverter(); diff --git a/app/Handlers/Observer/AvailableBudgetObserver.php b/app/Handlers/Observer/AvailableBudgetObserver.php index 02fc32d0b1..e310962c16 100644 --- a/app/Handlers/Observer/AvailableBudgetObserver.php +++ b/app/Handlers/Observer/AvailableBudgetObserver.php @@ -44,7 +44,7 @@ class AvailableBudgetObserver return; } - $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($availableBudget->user->userGroup); + $userCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($availableBudget->user->userGroup); $availableBudget->native_amount = null; if ($availableBudget->transactionCurrency->id !== $userCurrency->id) { $converter = new ExchangeRateConverter(); diff --git a/app/Handlers/Observer/BillObserver.php b/app/Handlers/Observer/BillObserver.php index ac9e98d3e1..265957a367 100644 --- a/app/Handlers/Observer/BillObserver.php +++ b/app/Handlers/Observer/BillObserver.php @@ -46,7 +46,7 @@ class BillObserver if (!Amount::convertToPrimary($bill->user)) { 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_max = null; if ($bill->transactionCurrency->id !== $userCurrency->id) { diff --git a/app/Handlers/Observer/BudgetLimitObserver.php b/app/Handlers/Observer/BudgetLimitObserver.php index 3c6558f0e9..83783e5640 100644 --- a/app/Handlers/Observer/BudgetLimitObserver.php +++ b/app/Handlers/Observer/BudgetLimitObserver.php @@ -72,7 +72,7 @@ class BudgetLimitObserver return; } - $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($budgetLimit->budget->user->userGroup); + $userCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($budgetLimit->budget->user->userGroup); $budgetLimit->native_amount = null; if ($budgetLimit->transactionCurrency->id !== $userCurrency->id) { $converter = new ExchangeRateConverter(); diff --git a/app/Handlers/Observer/PiggyBankEventObserver.php b/app/Handlers/Observer/PiggyBankEventObserver.php index acd8656727..1c60c90414 100644 --- a/app/Handlers/Observer/PiggyBankEventObserver.php +++ b/app/Handlers/Observer/PiggyBankEventObserver.php @@ -48,7 +48,7 @@ class PiggyBankEventObserver if (!Amount::convertToPrimary($user)) { 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; if ($event->piggyBank->transactionCurrency->id !== $userCurrency->id) { $converter = new ExchangeRateConverter(); diff --git a/app/Handlers/Observer/PiggyBankObserver.php b/app/Handlers/Observer/PiggyBankObserver.php index 003f46ee88..a48686c132 100644 --- a/app/Handlers/Observer/PiggyBankObserver.php +++ b/app/Handlers/Observer/PiggyBankObserver.php @@ -49,7 +49,7 @@ class PiggyBankObserver return; } - $userCurrency = app('amount')->getPrimaryCurrencyByUserGroup($group); + $userCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($group); $piggyBank->native_target_amount = null; if ($piggyBank->transactionCurrency->id !== $userCurrency->id) { $converter = new ExchangeRateConverter(); diff --git a/app/Handlers/Observer/TransactionObserver.php b/app/Handlers/Observer/TransactionObserver.php index 63ffebfd1a..703d5b2b81 100644 --- a/app/Handlers/Observer/TransactionObserver.php +++ b/app/Handlers/Observer/TransactionObserver.php @@ -52,7 +52,7 @@ class TransactionObserver if (!Amount::convertToPrimary($transaction->transactionJournal->user)) { 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_foreign_amount = null; // first normal amount diff --git a/app/Http/Controllers/Budget/BudgetLimitController.php b/app/Http/Controllers/Budget/BudgetLimitController.php index 18858e104b..0c6c0b6491 100644 --- a/app/Http/Controllers/Budget/BudgetLimitController.php +++ b/app/Http/Controllers/Budget/BudgetLimitController.php @@ -205,14 +205,14 @@ class BudgetLimitController extends Controller // add some extra metadata: $spentArr = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, null, new Collection()->push($budget), $currency); $array['spent'] = $spentArr[$currency->id]['sum'] ?? '0'; - $array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], (string) $array['amount'])); - $array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']); + $array['left_formatted'] = \FireflyIII\Support\Facades\Amount::formatAnything($limit->transactionCurrency, bcadd($array['spent'], (string) $array['amount'])); + $array['amount_formatted'] = \FireflyIII\Support\Facades\Amount::formatAnything($limit->transactionCurrency, $limit['amount']); $array['days_left'] = (string) $this->activeDaysLeft($start, $end); // 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']); // 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: $array['notes'] = $this->blRepository->getNoteText($limit); @@ -239,8 +239,8 @@ class BudgetLimitController extends Controller $this->blRepository->destroyBudgetLimit($budgetLimit); $array = [ 'budget_id' => $budgetId, - 'left_formatted' => app('amount')->formatAnything($currency, '0'), - 'left_per_day_formatted' => app('amount')->formatAnything($currency, '0'), + 'left_formatted' => \FireflyIII\Support\Facades\Amount::formatAnything($currency, '0'), + 'left_per_day_formatted' => \FireflyIII\Support\Facades\Amount::formatAnything($currency, '0'), 'transaction_currency_id' => $currency->id, ]; @@ -269,14 +269,14 @@ class BudgetLimitController extends Controller ); $daysLeft = $this->activeDaysLeft($limit->start_date, $limit->end_date); $array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0'; - $array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], (string) $array['amount'])); - $array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']); + $array['left_formatted'] = \FireflyIII\Support\Facades\Amount::formatAnything($limit->transactionCurrency, bcadd($array['spent'], (string) $array['amount'])); + $array['amount_formatted'] = \FireflyIII\Support\Facades\Amount::formatAnything($limit->transactionCurrency, $limit['amount']); $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']); // left per day formatted. $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')) { return redirect(route('budgets.index')); } diff --git a/app/Http/Controllers/JavascriptController.php b/app/Http/Controllers/JavascriptController.php index c44c2aebee..271b27c902 100644 --- a/app/Http/Controllers/JavascriptController.php +++ b/app/Http/Controllers/JavascriptController.php @@ -106,7 +106,7 @@ class JavascriptController extends Controller $currency = $repository->getAccountCurrency($account) ?? $this->primaryCurrency; } $locale = Steam::getLocale(); - $accounting = app('amount')->getJsConfig(); + $accounting = \FireflyIII\Support\Facades\Amount::getJsConfig(); $accounting['frac_digits'] = $currency->decimal_places; $pref = Preferences::get('language', config('firefly.default_language', 'en_US')); $lang = $pref->data; diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php index a7a631a193..4db6418a8a 100644 --- a/app/Http/Controllers/Json/BoxController.php +++ b/app/Http/Controllers/Json/BoxController.php @@ -121,15 +121,15 @@ class BoxController extends Controller $keys = array_keys($sums); foreach ($keys as $currencyId) { $currency = $repository->find($currencyId); - $sums[$currencyId] = app('amount')->formatAnything($currency, $sums[$currencyId], false); - $incomes[$currencyId] = app('amount')->formatAnything($currency, $incomes[$currencyId] ?? '0', false); - $expenses[$currencyId] = app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false); + $sums[$currencyId] = \FireflyIII\Support\Facades\Amount::formatAnything($currency, $sums[$currencyId], false); + $incomes[$currencyId] = \FireflyIII\Support\Facades\Amount::formatAnything($currency, $incomes[$currencyId] ?? '0', false); + $expenses[$currencyId] = \FireflyIII\Support\Facades\Amount::formatAnything($currency, $expenses[$currencyId] ?? '0', false); } if (0 === count($sums)) { $currency = $this->primaryCurrency; - $sums[$this->primaryCurrency->id] = app('amount')->formatAnything($this->primaryCurrency, '0', false); - $incomes[$this->primaryCurrency->id] = app('amount')->formatAnything($this->primaryCurrency, '0', false); - $expenses[$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] = \FireflyIII\Support\Facades\Amount::formatAnything($this->primaryCurrency, '0', false); + $expenses[$this->primaryCurrency->id] = \FireflyIII\Support\Facades\Amount::formatAnything($this->primaryCurrency, '0', false); } $response = [ @@ -187,7 +187,7 @@ class BoxController extends Controller if ('primary' === $key) { 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 = [ 'net_worths' => array_values($return), diff --git a/app/Http/Controllers/Json/BudgetController.php b/app/Http/Controllers/Json/BudgetController.php index 6a0b494194..6eaffdacc1 100644 --- a/app/Http/Controllers/Json/BudgetController.php +++ b/app/Http/Controllers/Json/BudgetController.php @@ -84,9 +84,9 @@ class BudgetController extends Controller return response()->json( [ 'budgeted' => $budgeted, - 'budgeted_formatted' => app('amount')->formatAnything($currency, $budgeted, true), + 'budgeted_formatted' => \FireflyIII\Support\Facades\Amount::formatAnything($currency, $budgeted, true), 'available' => $available, - 'available_formatted' => app('amount')->formatAnything($currency, $available, true), + 'available_formatted' => \FireflyIII\Support\Facades\Amount::formatAnything($currency, $available, true), 'percentage' => $percentage, 'currency_id' => $currency->id, 'currency_code' => $currency->code, diff --git a/app/Http/Controllers/PiggyBank/AmountController.php b/app/Http/Controllers/PiggyBank/AmountController.php index 659da06f57..2f40a833bd 100644 --- a/app/Http/Controllers/PiggyBank/AmountController.php +++ b/app/Http/Controllers/PiggyBank/AmountController.php @@ -167,7 +167,7 @@ class AmountController extends Controller $piggyBank->refresh(); } 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(); return redirect(route('piggy-banks.index')); @@ -177,7 +177,7 @@ class AmountController extends Controller 'error', (string) trans( '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', (string) trans( '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(); @@ -226,7 +226,7 @@ class AmountController extends Controller 'error', (string) trans( '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)] ) ); diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php index 418442db77..f1d610e56c 100644 --- a/app/Models/TransactionCurrency.php +++ b/app/Models/TransactionCurrency.php @@ -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')->getPrimaryCurrencyByUserGroup($user->userGroup); + $native = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($user->userGroup); $this->userGroupNative = $native->id === $this->id; $this->userGroupEnabled = null !== $current; } diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index e2572d9450..63e0db9724 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -353,7 +353,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac if (AccountTypeEnum::ASSET->value !== $account->accountType->type) { 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]); /** @var AccountType $type */ diff --git a/app/Repositories/Account/AccountTasker.php b/app/Repositories/Account/AccountTasker.php index 4278ac4183..f984053215 100644 --- a/app/Repositories/Account/AccountTasker.php +++ b/app/Repositories/Account/AccountTasker.php @@ -59,7 +59,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); - $primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); + $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup); $return = [ 'accounts' => [], @@ -146,7 +146,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface 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 */ $currencyRepos = app(CurrencyRepositoryInterface::class); @@ -231,7 +231,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface 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 */ $currencyRepos = app(CurrencyRepositoryInterface::class); diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index 0f8fe684b8..a5a4988ec1 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -536,7 +536,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface $bills = $this->getActiveBills(); $return = []; $convertToPrimary = Amount::convertToPrimary($this->user); - $primary = app('amount')->getPrimaryCurrency(); + $primary = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency(); /** @var Bill $bill */ foreach ($bills as $bill) { @@ -602,7 +602,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface $bills = $this->getActiveBills(); $return = []; $convertToPrimary = Amount::convertToPrimary($this->user); - $primary = app('amount')->getPrimaryCurrency(); + $primary = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency(); /** @var Bill $bill */ foreach ($bills as $bill) { diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 36d7cd9f00..006a725a51 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -94,7 +94,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface $limitRepository = app(BudgetLimitRepository::class); $limitRepository->setUser($this->user); $budgets = $this->getActiveBudgets(); - $primaryCurrency = app('amount')->getPrimaryCurrency(); + $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency(); $converter = new ExchangeRateConverter(); /** @var Budget $budget */ @@ -393,7 +393,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface $autoBudget = $this->getAutoBudget($budget); // grab default currency: - $currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); + $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup); if (!$autoBudget instanceof AutoBudget) { // 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']); } if (null === $currency) { - $currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); + $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup); } $autoBudget = new AutoBudget(); diff --git a/app/Repositories/Currency/CurrencyRepository.php b/app/Repositories/Currency/CurrencyRepository.php index 9f131de94c..dc7876aed5 100644 --- a/app/Repositories/Currency/CurrencyRepository.php +++ b/app/Repositories/Currency/CurrencyRepository.php @@ -240,7 +240,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf Log::debug('Grabbing default currency for this user...'); /** @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)); @@ -440,7 +440,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf 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)); $this->userGroup->currencies()->detach($currency->id); foreach ($this->userGroup->currencies()->get() as $item) { diff --git a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php index 734cfe8b0f..1800085966 100644 --- a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php +++ b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php @@ -72,7 +72,7 @@ trait ModifiesPiggyBanks $pivot->native_current_amount = null; // 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) { $converter = new ExchangeRateConverter(); $converter->setIgnoreSettings(true); @@ -95,7 +95,7 @@ trait ModifiesPiggyBanks $pivot->native_current_amount = null; // 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) { $converter = new ExchangeRateConverter(); $converter->setIgnoreSettings(true); diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.php index fb4c4e7305..f6d314e2f5 100644 --- a/app/Repositories/PiggyBank/PiggyBankRepository.php +++ b/app/Repositories/PiggyBank/PiggyBankRepository.php @@ -171,7 +171,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte $accountRepos = app(AccountRepositoryInterface::class); $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)); @@ -302,7 +302,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte /** @var PiggyBank $piggy */ foreach ($set as $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; diff --git a/app/Services/Internal/Support/AccountServiceTrait.php b/app/Services/Internal/Support/AccountServiceTrait.php index 5019b7031a..5fbc87f1f4 100644 --- a/app/Services/Internal/Support/AccountServiceTrait.php +++ b/app/Services/Internal/Support/AccountServiceTrait.php @@ -231,7 +231,7 @@ trait AccountServiceTrait // get or grab currency: $currency = $this->accountRepository->getAccountCurrency($account); if (null === $currency) { - $currency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup); + $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup); } // submit to factory: @@ -348,7 +348,7 @@ trait AccountServiceTrait if (null === $currency) { // use default currency: - $currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup); + $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup); } $currency->enabled = true; $currency->save(); @@ -388,7 +388,7 @@ trait AccountServiceTrait // if exists, update: $currency = $this->accountRepository->getAccountCurrency($account); 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: @@ -454,7 +454,7 @@ trait AccountServiceTrait // get or grab currency: $currency = $this->accountRepository->getAccountCurrency($account); if (null === $currency) { - $currency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup); + $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup); } // submit to factory: $submission = [ @@ -571,7 +571,7 @@ trait AccountServiceTrait // if exists, update: $currency = $this->accountRepository->getAccountCurrency($account); 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: @@ -652,7 +652,7 @@ trait AccountServiceTrait // get or grab currency: $currency = $this->accountRepository->getAccountCurrency($account); if (null === $currency) { - $currency = app('amount')->getPrimaryCurrencyByUserGroup($account->user->userGroup); + $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup); } // submit to factory: diff --git a/app/Services/Internal/Support/RecurringTransactionTrait.php b/app/Services/Internal/Support/RecurringTransactionTrait.php index 25f0fb75db..da4e9ef091 100644 --- a/app/Services/Internal/Support/RecurringTransactionTrait.php +++ b/app/Services/Internal/Support/RecurringTransactionTrait.php @@ -107,7 +107,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')->getPrimaryCurrencyByUserGroup($recurrence->user->userGroup); + $currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($recurrence->user->userGroup); } Log::debug( diff --git a/app/Services/Internal/Update/BillUpdateService.php b/app/Services/Internal/Update/BillUpdateService.php index cdf2118cc8..71d9771666 100644 --- a/app/Services/Internal/Update/BillUpdateService.php +++ b/app/Services/Internal/Update/BillUpdateService.php @@ -53,7 +53,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')->getPrimaryCurrencyByUserGroup($bill->user->userGroup); + ?? \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($bill->user->userGroup); // enable the currency if it isn't. $currency->enabled = true; diff --git a/app/Support/Form/CurrencyForm.php b/app/Support/Form/CurrencyForm.php index 0abfa1ca5f..d487bc7b15 100644 --- a/app/Support/Form/CurrencyForm.php +++ b/app/Support/Form/CurrencyForm.php @@ -123,10 +123,10 @@ class CurrencyForm $classes = $this->getHolderClasses($name); $value = $this->fillFieldValue($name, $value); $options['step'] = 'any'; - $primaryCurrency = $options['currency'] ?? app('amount')->getPrimaryCurrency(); + $primaryCurrency = $options['currency'] ?? \FireflyIII\Support\Facades\Amount::getPrimaryCurrency(); /** @var Collection $currencies */ - $currencies = app('amount')->getAllCurrencies(); + $currencies = \FireflyIII\Support\Facades\Amount::getAllCurrencies(); unset($options['currency'], $options['placeholder']); // 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); $value = $this->fillFieldValue($name, $value); $options['step'] = 'any'; - $primaryCurrency = $options['currency'] ?? app('amount')->getPrimaryCurrency(); + $primaryCurrency = $options['currency'] ?? \FireflyIII\Support\Facades\Amount::getPrimaryCurrency(); /** @var Collection $currencies */ - $currencies = app('amount')->getCurrencies(); + $currencies = \FireflyIII\Support\Facades\Amount::getCurrencies(); unset($options['currency'], $options['placeholder']); // perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount) $preFilled = session('preFilled'); diff --git a/app/Support/Http/Controllers/ChartGeneration.php b/app/Support/Http/Controllers/ChartGeneration.php index 63792ed518..fd98a732fc 100644 --- a/app/Support/Http/Controllers/ChartGeneration.php +++ b/app/Support/Http/Controllers/ChartGeneration.php @@ -67,7 +67,7 @@ trait ChartGeneration /** @var AccountRepositoryInterface $accountRepos */ $accountRepos = app(AccountRepositoryInterface::class); - $primary = app('amount')->getPrimaryCurrency(); + $primary = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency(); $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'))); diff --git a/app/Support/Report/Budget/BudgetReportGenerator.php b/app/Support/Report/Budget/BudgetReportGenerator.php index 246f05dd0d..c839853eb7 100644 --- a/app/Support/Report/Budget/BudgetReportGenerator.php +++ b/app/Support/Report/Budget/BudgetReportGenerator.php @@ -136,7 +136,7 @@ class BudgetReportGenerator $this->blRepository->setUser($user); $this->opsRepository->setUser($user); $this->nbRepository->setUser($user); - $this->currency = app('amount')->getPrimaryCurrencyByUserGroup($user->userGroup); + $this->currency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrencyByUserGroup($user->userGroup); } /** diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index fb4cc08abf..d4d5c9c553 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -180,7 +180,7 @@ class General extends AbstractExtension if ('balance' === $key) { // balance in account currency. if (!$usePrimary) { - $strings[] = app('amount')->formatAnything($currency, $balance, false); + $strings[] = \FireflyIII\Support\Facades\Amount::formatAnything($currency, $balance, false); } continue; @@ -188,14 +188,14 @@ class General extends AbstractExtension if ('pc_balance' === $key) { // balance in primary currency. if ($usePrimary) { - $strings[] = app('amount')->formatAnything($primary, $balance, false); + $strings[] = \FireflyIII\Support\Facades\Amount::formatAnything($primary, $balance, false); } continue; } // for multi currency accounts. 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); } } diff --git a/app/Support/Twig/TransactionGroupTwig.php b/app/Support/Twig/TransactionGroupTwig.php index f22a0618d1..891525bf71 100644 --- a/app/Support/Twig/TransactionGroupTwig.php +++ b/app/Support/Twig/TransactionGroupTwig.php @@ -172,7 +172,7 @@ class TransactionGroupTwig extends AbstractExtension if (TransactionTypeEnum::TRANSFER->value === $type) { $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) { return sprintf('%s', $result); } @@ -199,7 +199,7 @@ class TransactionGroupTwig extends AbstractExtension if (TransactionTypeEnum::TRANSFER->value === $type) { $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) { return sprintf('%s', $result); } @@ -230,7 +230,7 @@ class TransactionGroupTwig extends AbstractExtension $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) { return sprintf('%s', $result); } @@ -257,7 +257,7 @@ class TransactionGroupTwig extends AbstractExtension if (TransactionTypeEnum::TRANSFER->value === $type) { $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) { return sprintf('%s', $result); } diff --git a/app/Validation/TransactionValidation.php b/app/Validation/TransactionValidation.php index 7689ed048e..e95a826ffb 100644 --- a/app/Validation/TransactionValidation.php +++ b/app/Validation/TransactionValidation.php @@ -224,7 +224,7 @@ trait TransactionValidation /** @var AccountRepository $accountRepository */ $accountRepository = app(AccountRepositoryInterface::class); - $primaryCurrency = app('amount')->getPrimaryCurrency(); + $primaryCurrency = \FireflyIII\Support\Facades\Amount::getPrimaryCurrency(); $sourceCurrency = $accountRepository->getAccountCurrency($source) ?? $primaryCurrency; $destinationCurrency = $accountRepository->getAccountCurrency($destination) ?? $primaryCurrency; // if both accounts have the same currency, continue.