mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Code clean up.
This commit is contained in:
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Twig;
|
||||
|
||||
|
||||
use FireflyIII\Models\Account as AccountModel;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use Twig_Extension;
|
||||
@@ -46,7 +45,6 @@ class AmountFormat extends Twig_Extension
|
||||
$this->formatAmount(),
|
||||
$this->formatAmountPlain(),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +61,6 @@ class AmountFormat extends Twig_Extension
|
||||
$this->formatSourceBefore(),
|
||||
$this->formatAmountByCurrency(),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,12 +80,13 @@ class AmountFormat extends Twig_Extension
|
||||
protected function formatAmount(): Twig_SimpleFilter
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'formatAmount', function (string $string): string {
|
||||
'formatAmount',
|
||||
function (string $string): string {
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
|
||||
return app('amount')->formatAnything($currency, $string, true);
|
||||
}, ['is_safe' => ['html']]
|
||||
return app('amount')->formatAnything($currency, $string, true);
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -100,20 +98,20 @@ class AmountFormat extends Twig_Extension
|
||||
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'));
|
||||
'formatAmountByAccount',
|
||||
function (AccountModel $account, string $amount, bool $coloured = true): string {
|
||||
$currencyId = intval($account->getMeta('currency_id'));
|
||||
|
||||
if ($currencyId !== 0) {
|
||||
$currency = TransactionCurrency::find($currencyId);
|
||||
if ($currencyId !== 0) {
|
||||
$currency = TransactionCurrency::find($currencyId);
|
||||
|
||||
return app('amount')->formatAnything($currency, $amount, $coloured);
|
||||
}
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
|
||||
return app('amount')->formatAnything($currency, $amount, $coloured);
|
||||
}
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
|
||||
return app('amount')->formatAnything($currency, $amount, $coloured);
|
||||
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -125,12 +123,11 @@ class AmountFormat extends Twig_Extension
|
||||
protected function formatAmountByCurrency(): Twig_SimpleFunction
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'formatAmountByCurrency', function (TransactionCurrency $currency, string $amount, bool $coloured = true): string {
|
||||
|
||||
return app('amount')->formatAnything($currency, $amount, $coloured);
|
||||
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
'formatAmountByCurrency',
|
||||
function (TransactionCurrency $currency, string $amount, bool $coloured = true): string {
|
||||
return app('amount')->formatAnything($currency, $amount, $coloured);
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -142,16 +139,15 @@ class AmountFormat extends Twig_Extension
|
||||
protected function formatAmountBySymbol(): Twig_SimpleFunction
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'formatAmountBySymbol', function (string $amount, string $symbol, int $decimalPlaces = 2, bool $coloured = true): string {
|
||||
'formatAmountBySymbol',
|
||||
function (string $amount, string $symbol, int $decimalPlaces = 2, bool $coloured = true): string {
|
||||
$currency = new TransactionCurrency;
|
||||
$currency->symbol = $symbol;
|
||||
$currency->decimal_places = $decimalPlaces;
|
||||
|
||||
$currency = new TransactionCurrency;
|
||||
$currency->symbol = $symbol;
|
||||
$currency->decimal_places = $decimalPlaces;
|
||||
|
||||
return app('amount')->formatAnything($currency, $amount, $coloured);
|
||||
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
return app('amount')->formatAnything($currency, $amount, $coloured);
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -161,12 +157,13 @@ class AmountFormat extends Twig_Extension
|
||||
protected function formatAmountPlain(): Twig_SimpleFilter
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'formatAmountPlain', function (string $string): string {
|
||||
'formatAmountPlain',
|
||||
function (string $string): string {
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
|
||||
return app('amount')->formatAnything($currency, $string, false);
|
||||
}, ['is_safe' => ['html']]
|
||||
return app('amount')->formatAnything($currency, $string, false);
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -176,27 +173,28 @@ class AmountFormat extends Twig_Extension
|
||||
protected function formatDestinationAfter(): Twig_SimpleFunction
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'formatDestinationAfter', function (array $transaction): string {
|
||||
'formatDestinationAfter',
|
||||
function (array $transaction): string {
|
||||
|
||||
// build fake currency for main amount.
|
||||
$format = new TransactionCurrency;
|
||||
$format->decimal_places = $transaction['transaction_currency_dp'];
|
||||
$format->symbol = $transaction['transaction_currency_symbol'];
|
||||
$string = app('amount')->formatAnything($format, $transaction['destination_account_after'], true);
|
||||
|
||||
// also append foreign amount for clarity:
|
||||
if (!is_null($transaction['foreign_destination_amount'])) {
|
||||
// build fake currency for foreign amount
|
||||
$format = new TransactionCurrency;
|
||||
$format->decimal_places = $transaction['foreign_currency_dp'];
|
||||
$format->symbol = $transaction['foreign_currency_symbol'];
|
||||
$string .= ' (' . app('amount')->formatAnything($format, $transaction['foreign_destination_amount'], true) . ')';
|
||||
}
|
||||
$format->decimal_places = $transaction['transaction_currency_dp'];
|
||||
$format->symbol = $transaction['transaction_currency_symbol'];
|
||||
$string = app('amount')->formatAnything($format, $transaction['destination_account_after'], true);
|
||||
|
||||
// also append foreign amount for clarity:
|
||||
if (!is_null($transaction['foreign_destination_amount'])) {
|
||||
// build fake currency for foreign amount
|
||||
$format = new TransactionCurrency;
|
||||
$format->decimal_places = $transaction['foreign_currency_dp'];
|
||||
$format->symbol = $transaction['foreign_currency_symbol'];
|
||||
$string .= ' (' . app('amount')->formatAnything($format, $transaction['foreign_destination_amount'], true) . ')';
|
||||
}
|
||||
|
||||
|
||||
return $string;
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
return $string;
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -206,16 +204,17 @@ class AmountFormat extends Twig_Extension
|
||||
protected function formatDestinationBefore(): Twig_SimpleFunction
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'formatDestinationBefore', function (array $transaction): string {
|
||||
'formatDestinationBefore',
|
||||
function (array $transaction): string {
|
||||
|
||||
// build fake currency for main amount.
|
||||
$format = new TransactionCurrency;
|
||||
$format->decimal_places = $transaction['transaction_currency_dp'];
|
||||
$format->symbol = $transaction['transaction_currency_symbol'];
|
||||
$format = new TransactionCurrency;
|
||||
$format->decimal_places = $transaction['transaction_currency_dp'];
|
||||
$format->symbol = $transaction['transaction_currency_symbol'];
|
||||
|
||||
return app('amount')->formatAnything($format, $transaction['destination_account_before'], true);
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
return app('amount')->formatAnything($format, $transaction['destination_account_before'], true);
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -225,28 +224,28 @@ class AmountFormat extends Twig_Extension
|
||||
protected function formatSourceAfter(): Twig_SimpleFunction
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'formatSourceAfter', function (array $transaction): string {
|
||||
'formatSourceAfter',
|
||||
function (array $transaction): string {
|
||||
|
||||
// build fake currency for main amount.
|
||||
$format = new TransactionCurrency;
|
||||
$format->decimal_places = $transaction['transaction_currency_dp'];
|
||||
$format->symbol = $transaction['transaction_currency_symbol'];
|
||||
$string = app('amount')->formatAnything($format, $transaction['source_account_after'], true);
|
||||
|
||||
// also append foreign amount for clarity:
|
||||
if (!is_null($transaction['foreign_source_amount'])) {
|
||||
// build fake currency for foreign amount
|
||||
$format = new TransactionCurrency;
|
||||
$format->decimal_places = $transaction['foreign_currency_dp'];
|
||||
$format->symbol = $transaction['foreign_currency_symbol'];
|
||||
$string .= ' (' . app('amount')->formatAnything($format, $transaction['foreign_source_amount'], true) . ')';
|
||||
}
|
||||
$format->decimal_places = $transaction['transaction_currency_dp'];
|
||||
$format->symbol = $transaction['transaction_currency_symbol'];
|
||||
$string = app('amount')->formatAnything($format, $transaction['source_account_after'], true);
|
||||
|
||||
// also append foreign amount for clarity:
|
||||
if (!is_null($transaction['foreign_source_amount'])) {
|
||||
// build fake currency for foreign amount
|
||||
$format = new TransactionCurrency;
|
||||
$format->decimal_places = $transaction['foreign_currency_dp'];
|
||||
$format->symbol = $transaction['foreign_currency_symbol'];
|
||||
$string .= ' (' . app('amount')->formatAnything($format, $transaction['foreign_source_amount'], true) . ')';
|
||||
}
|
||||
|
||||
|
||||
return $string;
|
||||
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
return $string;
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -256,17 +255,17 @@ class AmountFormat extends Twig_Extension
|
||||
protected function formatSourceBefore(): Twig_SimpleFunction
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'formatSourceBefore', function (array $transaction): string {
|
||||
'formatSourceBefore',
|
||||
function (array $transaction): string {
|
||||
|
||||
// build fake currency for main amount.
|
||||
$format = new TransactionCurrency;
|
||||
$format->decimal_places = $transaction['transaction_currency_dp'];
|
||||
$format->symbol = $transaction['transaction_currency_symbol'];
|
||||
$format = new TransactionCurrency;
|
||||
$format->decimal_places = $transaction['transaction_currency_dp'];
|
||||
$format->symbol = $transaction['transaction_currency_symbol'];
|
||||
|
||||
return app('amount')->formatAnything($format, $transaction['source_account_before'], true);
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
return app('amount')->formatAnything($format, $transaction['source_account_before'], true);
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user