mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix null pointer in account format.
This commit is contained in:
parent
8f3e84df4d
commit
9f8c75efc6
@ -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);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user