Account list is capable of showing the selected currency

This commit is contained in:
James Cole 2017-04-13 21:36:23 +02:00
parent bac7a73555
commit 89ee9c058a
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 67 additions and 2 deletions

View File

@ -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);
}
/**

View File

@ -0,0 +1,63 @@
<?php
/**
* Account.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Twig;
use FireflyIII\Models\Account as AccountModel;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Facades\Amount as AmountFacade;
use Twig_Extension;
use Twig_SimpleFunction;
/**
* Class Account
*
* @package FireflyIII\Support\Twig
*/
class Account extends Twig_Extension
{
/**
* {@inheritDoc}
*/
public function getFunctions(): array
{
return [
$this->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']]
);
}
}

View File

@ -36,7 +36,7 @@
<td class="hidden-sm hidden-xs">{{ account.iban }}</td>
<td data-value="{{ account.endBalance }}" style="text-align: right;">
<span style="margin-right:5px;">
{{ account.endBalance|formatAmount }}
{{ formatAmountByAccount(account, account.endBalance) }}
</span>
</td>
<td class="hidden-sm hidden-xs" data-value="{{ account.active }}">
@ -57,7 +57,7 @@
{% endif %}
<td class="hidden-sm hidden-xs" data-value="{{ account.difference }}" style="text-align: right;">
<span style="margin-right:5px;">
{{ (account.difference)|formatAmount }}
{{ formatAmountByAccount(account, account.difference) }}
</span>
</td>