diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index d0fd412f85..035aadcbae 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -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 . '
'; + echo '' . $name . '
'; } } diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.php index 16d8b7ba1b..29511b80d7 100644 --- a/app/Support/Twig/Journal.php +++ b/app/Support/Twig/Journal.php @@ -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 = '' . Amount::format($amount) . ''; + } + $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(), diff --git a/resources/views/list/journals.twig b/resources/views/list/journals.twig index 0801bad16d..ddadd0aa60 100644 --- a/resources/views/list/journals.twig +++ b/resources/views/list/journals.twig @@ -62,7 +62,7 @@ {% endif %} {% if accountPerspective %} - {{ formatPerspective(journal, accountPerspective)|raw }} + {{ formatAccountPerspective(journal, accountPerspective)|raw }} {% endif %} {% if budgetPerspective %} diff --git a/resources/views/popup/list/journals.twig b/resources/views/popup/list/journals.twig index 705ae6eb51..17d314ef89 100644 --- a/resources/views/popup/list/journals.twig +++ b/resources/views/popup/list/journals.twig @@ -42,7 +42,7 @@ {% if not accountPerspective %} {{ journal|formatJournal }} {% else %} - {{ formatPerspective(journal, accountPerspective)|raw }} + {{ formatAccountPerspective(journal, accountPerspective)|raw }} {% endif %}