Possible fix for #619

This commit is contained in:
James Cole
2017-03-15 20:09:36 +01:00
parent e53d294c1c
commit 79aa0afc97

View File

@@ -13,6 +13,7 @@ declare(strict_types = 1);
namespace FireflyIII\Support; namespace FireflyIII\Support;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
@@ -171,7 +172,7 @@ class Amount
*/ */
public function formatByCode(string $currencyCode, string $amount, bool $coloured = true): string public function formatByCode(string $currencyCode, string $amount, bool $coloured = true): string
{ {
$currency = TransactionCurrency::whereCode($currencyCode)->first(); $currency = TransactionCurrency::where('code', $currencyCode)->first();
return $this->formatAnything($currency, $amount, $coloured); return $this->formatAnything($currency, $amount, $coloured);
} }
@@ -224,7 +225,7 @@ class Amount
} else { } else {
$currencyPreference = Prefs::get('currencyPreference', config('firefly.default_currency', 'EUR')); $currencyPreference = Prefs::get('currencyPreference', config('firefly.default_currency', 'EUR'));
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first(); $currency = TransactionCurrency::where('code', $currencyPreference->data)->first();
if ($currency) { if ($currency) {
$cache->store($currency->code); $cache->store($currency->code);
@@ -248,7 +249,7 @@ class Amount
return $cache->get(); // @codeCoverageIgnore return $cache->get(); // @codeCoverageIgnore
} else { } else {
$currencyPreference = Prefs::get('currencyPreference', config('firefly.default_currency', 'EUR')); $currencyPreference = Prefs::get('currencyPreference', config('firefly.default_currency', 'EUR'));
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first(); $currency = TransactionCurrency::where('code', $currencyPreference->data)->first();
$cache->store($currency->symbol); $cache->store($currency->symbol);
@@ -267,7 +268,12 @@ class Amount
return $cache->get(); // @codeCoverageIgnore return $cache->get(); // @codeCoverageIgnore
} }
$currencyPreference = Prefs::get('currencyPreference', config('firefly.default_currency', 'EUR')); $currencyPreference = Prefs::get('currencyPreference', config('firefly.default_currency', 'EUR'));
$currency = TransactionCurrency::whereCode($currencyPreference->data)->first(); $currency = TransactionCurrency::where('code', $currencyPreference->data)->first();
if (is_null($currency)) {
throw new FireflyException(sprintf('No currency found with code "%s"', $currencyPreference->data));
}
$cache->store($currency); $cache->store($currency);
return $currency; return $currency;