mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-13 00:45:55 -06:00
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace FireflyIII\Support;
|
|
|
|
use FireflyIII\Models\Transaction;
|
|
/**
|
|
* Class Amount
|
|
*
|
|
* @package FireflyIII\Support
|
|
*/
|
|
class Amount
|
|
{
|
|
/**
|
|
* @param \Transaction $transaction
|
|
* @param bool $coloured
|
|
*
|
|
* @return string
|
|
*/
|
|
public function formatTransaction(Transaction $transaction, $coloured = true)
|
|
{
|
|
$symbol = $transaction->transactionJournal->transactionCurrency->symbol;
|
|
$amount = floatval($transaction->amount);
|
|
|
|
return $this->formatWithSymbol($symbol, $amount, $coloured);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @param string $symbol
|
|
* @param float $amount
|
|
* @param bool $coloured
|
|
*
|
|
* @return string
|
|
*/
|
|
public function formatWithSymbol($symbol, $amount, $coloured = true)
|
|
{
|
|
$amount = floatval($amount);
|
|
$amount = round($amount, 2);
|
|
$string = number_format($amount, 2, ',', '.');
|
|
|
|
if ($coloured === true) {
|
|
if ($amount === 0.0) {
|
|
return '<span style="color:#999">' . $symbol . ' ' . $string . '</span>';
|
|
}
|
|
if ($amount > 0) {
|
|
return '<span class="text-success">' . $symbol . ' ' . $string . '</span>';
|
|
}
|
|
|
|
return '<span class="text-danger">' . $symbol . ' ' . $string . '</span>';
|
|
}
|
|
|
|
// €
|
|
return $symbol . ' ' . $string;
|
|
}
|
|
} |