formatCurrency($amount, $format->code); if ($coloured === true) { if ($amount == 0) { return '' . $result . ''; } if ($amount > 0) { return '' . $result . ''; } return '' . $result . ''; } return $result; } /** * @param $amount * @param bool $coloured * * @return string */ public function format($amount, $coloured = true) { return $this->formatAnything($this->getDefaultCurrency(), $amount, $coloured); } /** * @return string */ public function getCurrencySymbol() { $cache = new CacheProperties; $cache->addProperty('getCurrencySymbol'); if ($cache->has()) { return $cache->get(); } else { $currencyPreference = Prefs::get('currencyPreference', env('DEFAULT_CURRENCY', 'EUR')); $currency = TransactionCurrency::whereCode($currencyPreference->data)->first(); $cache->store($currency->symbol); return $currency->symbol; } } /** * @param string $symbol * @param float $amount * @param bool $coloured * * @return string */ public function formatWithSymbol($symbol, $amount, $coloured = true) { return $this->formatAnything($this->getDefaultCurrency(), $amount, $coloured); } /** * * @param TransactionJournal $journal * @param bool $coloured * * @return string */ public function formatJournal(TransactionJournal $journal, $coloured = true) { $cache = new CacheProperties; $cache->addProperty($journal->id); $cache->addProperty('formatJournal'); if ($cache->has()) { return $cache->get(); // @codeCoverageIgnore } if ($journal->isTransfer() && $coloured) { $txt = '' . $this->formatAnything($journal->transactionCurrency, $journal->amount_positive, false) . '';; $cache->store($txt); return $txt; } if ($journal->isTransfer() && !$coloured) { $txt = $this->formatAnything($journal->transactionCurrency, $journal->amount_positive, false); $cache->store($txt); return $txt; } $txt = $this->formatAnything($journal->transactionCurrency, $journal->amount, $coloured); $cache->store($txt); return $txt; } /** * @param Transaction $transaction * @param bool $coloured * * @return string */ public function formatTransaction(Transaction $transaction, $coloured = true) { $currency = $transaction->transactionJournal->transactionCurrency; return $this->formatAnything($currency, $transaction->amount); } /** * @return Collection */ public function getAllCurrencies() { return TransactionCurrency::orderBy('code', 'ASC')->get(); } /** * @return string */ public function getCurrencyCode() { $cache = new CacheProperties; $cache->addProperty('getCurrencyCode'); if ($cache->has()) { return $cache->get(); } else { $currencyPreference = Prefs::get('currencyPreference', env('DEFAULT_CURRENCY', 'EUR')); $currency = TransactionCurrency::whereCode($currencyPreference->data)->first(); if ($currency) { $cache->store($currency->code); return $currency->code; } $cache->store(env('DEFAULT_CURRENCY', 'EUR')); return env('DEFAULT_CURRENCY', 'EUR'); // @codeCoverageIgnore } } /** * @return TransactionCurrency */ public function getDefaultCurrency() { $cache = new CacheProperties; $cache->addProperty('getDefaultCurrency'); if ($cache->has()) { return $cache->get(); } $currencyPreference = Prefs::get('currencyPreference', 'EUR'); $currency = TransactionCurrency::whereCode($currencyPreference->data)->first(); $cache->store($currency); return $currency; } }