Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Removed money_format.
James Colea55e29190871
diff --git a/app/Support/Amount.php b/app/Support/Amount.phpindex bd0624f002..6298bc61f6 100644--- a/app/Support/Amount.php+++ b/app/Support/Amount.php@@ -6,6 +6,7 @@ use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionCurrency;use FireflyIII\Models\TransactionJournal;use Illuminate\Support\Collection;+use NumberFormatter;use Preferences as Prefs;/**@@ -15,19 +16,47 @@ use Preferences as Prefs;*/class Amount{+/**- * @param $amount- * @param bool $coloured+ * This method will properly format the given number, in color or "black and white",+ * as a currency, given two things: the currency required and the current locale.+ *+ * @param TransactionCurrency $format+ * @param $amount+ * @param bool $coloured** @return string*/- public function format($amount, $coloured = true)+ public function formatAnything(TransactionCurrency $format, $amount, $coloured = true){- $currencySymbol = $this->getCurrencySymbol();+ $locale = setlocale(LC_MONETARY, 0);+ $a = new NumberFormatter($locale, NumberFormatter::CURRENCY);+ $result = $a->formatCurrency($amount, $format->code);- return $this->formatWithSymbol($currencySymbol, $amount, $coloured);+ if ($coloured === true) {+ if ($amount == 0) {+ return '<span style="color:#999">' . $result . '</span>';+ }+ if ($amount > 0) {+ return '<span class="text-success">' . $result . '</span>';+ }+ return '<span class="text-danger">' . $result . '</span>';+ }++ return $result;+ }++ /**+ * @param $amount+ * @param bool $coloured+ *+ * @return string+ */+ public function format($amount, $coloured = true)+ {+ return $this->formatAnything($this->getDefaultCurrency(), $amount, $coloured);}/**@@ -58,22 +87,7 @@ class Amount*/public function formatWithSymbol($symbol, $amount, $coloured = true){- $amount = floatval($amount);- $amount = round($amount, 2);- $string = money_format('%!.2n', $amount);-- 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;+ return $this->formatAnything($this->getDefaultCurrency(), $amount, $coloured);}/**@@ -93,27 +107,20 @@ class Amountreturn $cache->get(); // @codeCoverageIgnore}-- if (is_null($journal->symbol)) {- $symbol = $journal->transactionCurrency->symbol;- } else {- $symbol = $journal->symbol;- }-if ($journal->isTransfer() && $coloured) {- $txt = '<span class="text-info">' . $this->formatWithSymbol($symbol, $journal->amount_positive, false) . '</span>';+ $txt = '<span class="text-info">' . $this->formatAnything($journal->transactionCurrency, $journal->amount_positive, false) . '</span>';;$cache->store($txt);return $txt;}if ($journal->isTransfer() && !$coloured) {- $txt = $this->formatWithSymbol($symbol, $journal->amount_positive, false);+ $txt = $this->formatAnything($journal->transactionCurrency, $journal->amount_positive, false);$cache->store($txt);return $txt;}- $txt = $this->formatWithSymbol($symbol, $journal->amount, $coloured);+ $txt = $this->formatAnything($journal->transactionCurrency, $journal->amount, $coloured);$cache->store($txt);return $txt;@@ -127,10 +134,9 @@ class Amount*/public function formatTransaction(Transaction $transaction, $coloured = true){- $symbol = $transaction->transactionJournal->transactionCurrency->symbol;- $amount = floatval($transaction->amount);+ $currency = $transaction->transactionJournal->transactionCurrency;- return $this->formatWithSymbol($symbol, $amount, $coloured);+ return $this->formatAnything($currency, $transaction->amount);}/**@@ -168,7 +174,7 @@ class Amount}/**- * @return mixed|static+ * @return TransactionCurrency*/public function getDefaultCurrency(){