diff --git a/app/Import/ImportValidator.php b/app/Import/ImportValidator.php index 0c148b0c20..0b916a053b 100644 --- a/app/Import/ImportValidator.php +++ b/app/Import/ImportValidator.php @@ -21,6 +21,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\User; use Illuminate\Support\Collection; use Log; +use Preferences; /** * Class ImportValidator @@ -357,13 +358,16 @@ class ImportValidator { if (is_null($entry->fields['currency'])) { /** @var CurrencyRepositoryInterface $repository */ - $repository = app(CurrencyRepositoryInterface::class); - $entry->fields['currency'] = $repository->findByCode(env('DEFAULT_CURRENCY', 'EUR')); - Log::debug('Set currency to EUR'); + $repository = app(CurrencyRepositoryInterface::class, [$this->user]); + // is the default currency for the user or the system + $defaultCode = Preferences::getForUser($this->user, 'currencyPreference', env('DEFAULT_CURRENCY', 'EUR'))->data; + + $entry->fields['currency'] = $repository->findByCode($defaultCode); + Log::debug(sprintf('Set currency to %s', $defaultCode)); return $entry; } - Log::debug('Currency is OK'); + Log::debug(sprintf('Currency is OK: %s', $entry->fields['currency']->code)); return $entry; } diff --git a/app/Support/Amount.php b/app/Support/Amount.php index 0b3620d1e5..7aa23d6324 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -171,7 +171,7 @@ class Amount } /** - * @return TransactionCurrency + * @return \FireflyIII\Models\TransactionCurrency */ public function getDefaultCurrency(): TransactionCurrency { @@ -180,7 +180,7 @@ class Amount if ($cache->has()) { return $cache->get(); } - $currencyPreference = Prefs::get('currencyPreference', 'EUR'); + $currencyPreference = Prefs::get('currencyPreference', env('DEFAULT_CURRENCY', 'EUR')); $currency = TransactionCurrency::whereCode($currencyPreference->data)->first(); $cache->store($currency); diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index 46a93ad058..d505c4fd77 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -57,11 +57,11 @@ class Preferences } /** - * @param User $user - * @param string $name - * @param string $default + * @param \FireflyIII\User $user + * @param string $name + * @param string $default * - * @return Preference|null + * @return \FireflyIII\Models\Preference|null */ public function getForUser(User $user, $name, $default = null) {