diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index 7a9e9d68d6..58952a3301 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -43,6 +43,7 @@ use FireflyIII\Support\FireflyConfig; use FireflyIII\Support\Navigation; use FireflyIII\Support\Preferences; use FireflyIII\Support\Steam; +use FireflyIII\Support\Twig\Account; use FireflyIII\Support\Twig\General; use FireflyIII\Support\Twig\Journal; use FireflyIII\Support\Twig\PiggyBank; @@ -77,6 +78,7 @@ class FireflyServiceProvider extends ServiceProvider Twig::addExtension(new Translation); Twig::addExtension(new Transaction); Twig::addExtension(new Rule); + Twig::addExtension(new Account); } /** diff --git a/app/Support/Twig/Account.php b/app/Support/Twig/Account.php new file mode 100644 index 0000000000..d2a5520505 --- /dev/null +++ b/app/Support/Twig/Account.php @@ -0,0 +1,63 @@ +formatAmountByAccount(), + ]; + + } + + /** + * Will return "active" when a part of the route matches the argument. + * ie. "accounts" will match "accounts.index". + * + * @return Twig_SimpleFunction + */ + protected function formatAmountByAccount(): Twig_SimpleFunction + { + return new Twig_SimpleFunction( + 'formatAmountByAccount', function (AccountModel $account, string $amount, bool $coloured = true): string { + $currencyId = intval($account->getMeta('currency_id')); + if ($currencyId === 0) { + // Format using default currency: + return AmountFacade::format($amount, $coloured); + } + $currency = TransactionCurrency::find($currencyId); + + return AmountFacade::formatAnything($currency, $amount, $coloured); + }, ['is_safe' => ['html']] + ); + } + + +} \ No newline at end of file diff --git a/resources/views/list/accounts.twig b/resources/views/list/accounts.twig index baa896e1b7..46d4fad1d8 100644 --- a/resources/views/list/accounts.twig +++ b/resources/views/list/accounts.twig @@ -36,7 +36,7 @@