Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Better number formatting.
James Coleb0a5b53abbe8
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.phpindex 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 . '<br>';+ echo '<a href="/' . $url . '" title="' . $name . '">' . $name . '</a><br>';}}diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.phpindex 16d8b7ba1b..29511b80d7 100644--- a/app/Support/Twig/Journal.php+++ b/app/Support/Twig/Journal.php@@ -25,45 +25,68 @@ class Journal extends Twig_Extension/*** @return Twig_SimpleFunction*/- public function formatBudgetPerspective(): Twig_SimpleFunction+ public function formatAccountPerspective(): Twig_SimpleFunction{return new Twig_SimpleFunction(- 'formatBudgetPerspective', function (TransactionJournal $journal, Budget $budget) {+ '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.amount', '<', 0)->get(['transactions.*']);+ $transactions = $journal->transactions()->where('transactions.account_id', $account->id)->get(['transactions.*']);$amount = '0';foreach ($transactions as $transaction) {- $currentBudget = $transaction->budgets->first();- if (!is_null($currentBudget) && $currentBudget->id === $budget->id) {- $amount = bcadd($amount, strval($transaction->amount));- }+ $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);- return $formatted . ' (' . Amount::formatJournal($journal) . ')';+ if ($journal->isTransfer()) {+ $formatted = '<span class="text-info">' . Amount::format($amount) . '</span>';+ }+ $str = $formatted . ' (' . $full . ')';+ $cache->store($str);++ return $str;+});}-/*** @return Twig_SimpleFunction*/- public function formatPerspective(): Twig_SimpleFunction+ public function formatBudgetPerspective(): Twig_SimpleFunction{return new Twig_SimpleFunction(- 'formatPerspective', function (TransactionJournal $journal, Account $account) {-+ 'formatBudgetPerspective', function (TransactionJournal $journal, Budget $budget) {// get the account amount:- $transactions = $journal->transactions()->where('transactions.account_id', $account->id)->get(['transactions.*']);+ $transactions = $journal->transactions()->where('transactions.amount', '<', 0)->get(['transactions.*']);$amount = '0';foreach ($transactions as $transaction) {- $amount = bcadd($amount, strval($transaction->amount));- }-- if ($journal->isWithdrawal()) {- $amount = bcmul($amount, '-1');+ $currentBudget = $transaction->budgets->first();+ if (!is_null($currentBudget) && $currentBudget->id === $budget->id) {+ $amount = bcadd($amount, strval($transaction->amount));+ }}$formatted = Amount::format($amount, true);@@ -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.twigindex 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.twigindex 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 %}</td><td class="hidden-sm hidden-xs">