mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-07 06:31:22 +00:00
Improvements for #616 and others.
This commit is contained in:
@@ -300,6 +300,7 @@ class Amount
|
||||
public function transactionAmount(TransactionModel $transaction, bool $coloured = true): string
|
||||
{
|
||||
$amount = bcmul(app('steam')->positive(strval($transaction->transaction_amount)), '-1');
|
||||
|
||||
$format = '%s';
|
||||
|
||||
if ($transaction->transaction_type_type === TransactionType::DEPOSIT) {
|
||||
@@ -322,7 +323,11 @@ class Amount
|
||||
|
||||
|
||||
if (!is_null($transaction->transaction_foreign_amount)) {
|
||||
$amount = strval($transaction->transaction_foreign_amount);
|
||||
$amount = bcmul(app('steam')->positive(strval($transaction->transaction_foreign_amount)), '-1');
|
||||
if ($transaction->transaction_type_type === TransactionType::DEPOSIT) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
|
||||
|
||||
if ($transaction->transaction_type_type === TransactionType::TRANSFER) {
|
||||
$amount = app('steam')->positive($amount);
|
||||
|
||||
@@ -46,6 +46,7 @@ class AmountFormat extends Twig_Extension
|
||||
{
|
||||
return [
|
||||
$this->formatAmountByAccount(),
|
||||
$this->formatAmountBySymbol(),
|
||||
$this->transactionAmount(),
|
||||
$this->journalAmount(),
|
||||
$this->formatDestinationAfter(),
|
||||
@@ -108,6 +109,26 @@ class AmountFormat extends Twig_Extension
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will format the amount by the currency related to the given account.
|
||||
*
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function formatAmountBySymbol(): Twig_SimpleFunction
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'formatAmountBySymbol', function (string $amount, string $symbol, int $decimalPlaces = 2, bool $coloured = true): string {
|
||||
|
||||
$currency = new TransactionCurrency;
|
||||
$currency->symbol = $symbol;
|
||||
$currency->decimal_places = $decimalPlaces;
|
||||
return app('amount')->formatAnything($currency, $amount, $coloured);
|
||||
|
||||
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will format the amount by the currency related to the given account.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user