mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-27 17:31:09 -06:00
Better number formatting.
This commit is contained in:
parent
ce78c8993f
commit
b0a5b53abb
@ -158,9 +158,12 @@ class HomeController extends Controller
|
||||
|
||||
$name = $route->getName();
|
||||
$methods = $route->getMethods();
|
||||
$search = ['{account}', '{what}', '{rule}', '{tj}'];
|
||||
$replace = [1, 'asset', 1, 1];
|
||||
$url = str_replace($search, $replace, $route->getUri());
|
||||
|
||||
if (!is_null($name) && in_array('GET', $methods) && !$this->startsWithAny($ignore, $name)) {
|
||||
echo $name . '<br>';
|
||||
echo '<a href="/' . $url . '" title="' . $name . '">' . $name . '</a><br>';
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,56 @@ use Twig_SimpleFunction;
|
||||
class Journal extends Twig_Extension
|
||||
{
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
public function formatAccountPerspective(): Twig_SimpleFunction
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'formatAccountPerspective', function (TransactionJournal $journal, Account $account) {
|
||||
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('formatAccountPerspective');
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty($account->id);
|
||||
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
// get the account amount:
|
||||
$transactions = $journal->transactions()->where('transactions.account_id', $account->id)->get(['transactions.*']);
|
||||
$amount = '0';
|
||||
foreach ($transactions as $transaction) {
|
||||
$amount = bcadd($amount, strval($transaction->amount));
|
||||
}
|
||||
if ($journal->isTransfer()) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
|
||||
// check if this sum is the same as the journal:
|
||||
$journalSum = TransactionJournal::amount($journal);
|
||||
$full = Amount::formatJournal($journal);
|
||||
if (bccomp($journalSum, $amount) === 0) {
|
||||
$cache->store($full);
|
||||
|
||||
return $full;
|
||||
}
|
||||
|
||||
$formatted = Amount::format($amount, true);
|
||||
|
||||
if ($journal->isTransfer()) {
|
||||
$formatted = '<span class="text-info">' . Amount::format($amount) . '</span>';
|
||||
}
|
||||
$str = $formatted . ' (' . $full . ')';
|
||||
$cache->store($str);
|
||||
|
||||
return $str;
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
@ -46,33 +96,6 @@ class Journal extends Twig_Extension
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
public function formatPerspective(): Twig_SimpleFunction
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'formatPerspective', function (TransactionJournal $journal, Account $account) {
|
||||
|
||||
// get the account amount:
|
||||
$transactions = $journal->transactions()->where('transactions.account_id', $account->id)->get(['transactions.*']);
|
||||
$amount = '0';
|
||||
foreach ($transactions as $transaction) {
|
||||
$amount = bcadd($amount, strval($transaction->amount));
|
||||
}
|
||||
|
||||
if ($journal->isWithdrawal()) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
|
||||
$formatted = Amount::format($amount, true);
|
||||
|
||||
return $formatted . ' (' . Amount::formatJournal($journal) . ')';
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
@ -126,7 +149,7 @@ class Journal extends Twig_Extension
|
||||
$functions = [
|
||||
$this->getSourceAccount(),
|
||||
$this->getDestinationAccount(),
|
||||
$this->formatPerspective(),
|
||||
$this->formatAccountPerspective(),
|
||||
$this->formatBudgetPerspective(),
|
||||
$this->journalBudgets(),
|
||||
$this->journalCategories(),
|
||||
|
@ -62,7 +62,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if accountPerspective %}
|
||||
{{ formatPerspective(journal, accountPerspective)|raw }}
|
||||
{{ formatAccountPerspective(journal, accountPerspective)|raw }}
|
||||
{% endif %}
|
||||
|
||||
{% if budgetPerspective %}
|
||||
|
@ -42,7 +42,7 @@
|
||||
{% if not accountPerspective %}
|
||||
{{ journal|formatJournal }}
|
||||
{% else %}
|
||||
{{ formatPerspective(journal, accountPerspective)|raw }}
|
||||
{{ formatAccountPerspective(journal, accountPerspective)|raw }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="hidden-sm hidden-xs">
|
||||
|
Loading…
Reference in New Issue
Block a user