Fix null pointer in account format.

This commit is contained in:
James Cole 2018-03-30 22:44:37 +02:00
parent 8f3e84df4d
commit 9f8c75efc6
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -24,6 +24,8 @@ namespace FireflyIII\Support\Twig;
use FireflyIII\Models\Account as AccountModel; use FireflyIII\Models\Account as AccountModel;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Twig_Extension; use Twig_Extension;
use Twig_SimpleFilter; use Twig_SimpleFilter;
use Twig_SimpleFunction; use Twig_SimpleFunction;
@ -82,14 +84,19 @@ class AmountFormat extends Twig_Extension
return new Twig_SimpleFunction( return new Twig_SimpleFunction(
'formatAmountByAccount', 'formatAmountByAccount',
function (AccountModel $account, string $amount, bool $coloured = true): string { function (AccountModel $account, string $amount, bool $coloured = true): string {
$currencyId = intval($account->getMeta('currency_id')); /** @var AccountRepositoryInterface $accountRepos */
$accountRepos = app(AccountRepositoryInterface::class);
/** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class);
$currency = app('amount')->getDefaultCurrency();
$currencyId = (int)$accountRepos->getMetaValue($account, 'currency_id');
$accountCurrency = null
if (0 !== $currencyId) { if (0 !== $currencyId) {
$currency = TransactionCurrency::find($currencyId); $accountCurrency = $currencyRepos->findNull($currencyId);
}
return app('amount')->formatAnything($currency, $amount, $coloured); if (null !== $accountCurrency) {
$currency = $accountCurrency;
} }
$currency = app('amount')->getDefaultCurrency();
return app('amount')->formatAnything($currency, $amount, $coloured); return app('amount')->formatAnything($currency, $amount, $coloured);
}, },