Lot of debug info for #619

This commit is contained in:
James Cole 2017-03-16 17:52:13 +01:00
parent 79aa0afc97
commit d618ddc8c5
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -111,6 +111,8 @@ class Amount
*/
public function format(string $amount, bool $coloured = true): string
{
Log::debug(sprintf('Now in format("%s", %s).', $amount, var_export($coloured, true)));
return $this->formatAnything($this->getDefaultCurrency(), $amount, $coloured);
}
@ -126,12 +128,19 @@ class Amount
*/
public function formatAnything(TransactionCurrency $format, string $amount, bool $coloured = true): string
{
Log::debug(sprintf('Now in formatAnything($format, "%s",%s)', $amount, var_export($coloured, true)));
Log::debug('Currency $format: ', $format->toArray());
$locale = explode(',', trans('config.locale'));
$locale = array_map('trim', $locale);
Log::debug('Locale is ', $locale);
setlocale(LC_MONETARY, $locale);
$float = round($amount, 12);
$info = localeconv();
$formatted = number_format($float, $format->decimal_places, $info['mon_decimal_point'], $info['mon_thousands_sep']);
Log::debug('Localeconv is', $info);
Log::debug(sprintf('Now calling number_format(%f, %d, "%s", "%s")', $float, $format->decimal_places, $info['mon_decimal_point'], $info['mon_thousands_sep']));
Log::debug('Decimal places raw: %s', var_export($format->decimal_places, true));
$formatted = number_format($float, intval($format->decimal_places), $info['mon_decimal_point'], $info['mon_thousands_sep']);
// some complicated switches to format the amount correctly:
$precedes = $amount < 0 ? $info['n_cs_precedes'] : $info['p_cs_precedes'];
@ -262,20 +271,29 @@ class Amount
*/
public function getDefaultCurrency(): TransactionCurrency
{
Log::debug('Now in getDefaultCurrency()');
$cache = new CacheProperties;
$cache->addProperty('getDefaultCurrency');
if ($cache->has()) {
Log::debug('Return cache value: ', $cache->get()->toArray());
return $cache->get(); // @codeCoverageIgnore
}
Log::debug('getDefaultCurrency() is not in cache.');
$currencyPreference = Prefs::get('currencyPreference', config('firefly.default_currency', 'EUR'));
$currency = TransactionCurrency::where('code', $currencyPreference->data)->first();
Log::debug('currencyPreference is', $currencyPreference->toArray());
$currency = TransactionCurrency::where('code', $currencyPreference->data)->first();
if (is_null($currency)) {
Log::debug('Currency is NULL!');
throw new FireflyException(sprintf('No currency found with code "%s"', $currencyPreference->data));
}
Log::debug('Currency is ', $currency->toArray());
$cache->store($currency);
Log::debug('Return $currency');
return $currency;
}