From fe1fb23e5bbb4997cc6ce45daeeeba11c8a1f951 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 24 Dec 2014 06:10:39 +0100 Subject: [PATCH] Extend JS to include currency code #37 --- app/views/accounts/index.blade.php | 1 + app/views/accounts/show.blade.php | 1 + app/views/categories/index.blade.php | 3 ++ app/views/categories/show.blade.php | 3 +- app/views/index.blade.php | 3 ++ app/views/recurring/show.blade.php | 4 +- app/views/reports/unbalanced.blade.php | 3 ++ app/views/reports/year.blade.php | 2 +- bootstrap/start.php | 41 ++++++++++++++++-- public/assets/javascript/firefly/gcharts.js | 47 +++------------------ 10 files changed, 57 insertions(+), 51 deletions(-) diff --git a/app/views/accounts/index.blade.php b/app/views/accounts/index.blade.php index c98c6e38b1..5c2416ab00 100644 --- a/app/views/accounts/index.blade.php +++ b/app/views/accounts/index.blade.php @@ -30,6 +30,7 @@ @section('scripts') diff --git a/app/views/accounts/show.blade.php b/app/views/accounts/show.blade.php index d54e245446..b7da493119 100644 --- a/app/views/accounts/show.blade.php +++ b/app/views/accounts/show.blade.php @@ -52,6 +52,7 @@ diff --git a/app/views/categories/index.blade.php b/app/views/categories/index.blade.php index e20f21b4e5..8a0a4034b1 100644 --- a/app/views/categories/index.blade.php +++ b/app/views/categories/index.blade.php @@ -28,6 +28,9 @@ @stop @section('scripts') + {{HTML::script('assets/javascript/firefly/gcharts.options.js')}} diff --git a/app/views/categories/show.blade.php b/app/views/categories/show.blade.php index 34e1d4a265..a80f0a9bb5 100644 --- a/app/views/categories/show.blade.php +++ b/app/views/categories/show.blade.php @@ -32,9 +32,8 @@ - {{HTML::script('assets/javascript/firefly/gcharts.options.js')}} diff --git a/app/views/index.blade.php b/app/views/index.blade.php index 587f3a6f34..5a90e8ce31 100644 --- a/app/views/index.blade.php +++ b/app/views/index.blade.php @@ -113,6 +113,9 @@ @stop @section('scripts') + {{HTML::script('assets/javascript/firefly/gcharts.options.js')}} diff --git a/app/views/recurring/show.blade.php b/app/views/recurring/show.blade.php index 27d059ef2f..b877599d47 100644 --- a/app/views/recurring/show.blade.php +++ b/app/views/recurring/show.blade.php @@ -105,9 +105,9 @@ @section('scripts') - {{HTML::script('assets/javascript/firefly/gcharts.options.js')}} diff --git a/app/views/reports/unbalanced.blade.php b/app/views/reports/unbalanced.blade.php index 13ae78101b..74aa64fe41 100644 --- a/app/views/reports/unbalanced.blade.php +++ b/app/views/reports/unbalanced.blade.php @@ -48,6 +48,9 @@ @endif @stop @section('scripts') + {{HTML::script('assets/javascript/firefly/reports.js')}} {{HTML::script('assets/javascript/firefly/related-manager.js')}} @stop \ No newline at end of file diff --git a/app/views/reports/year.blade.php b/app/views/reports/year.blade.php index e3a358494f..827f988a37 100644 --- a/app/views/reports/year.blade.php +++ b/app/views/reports/year.blade.php @@ -117,7 +117,7 @@ {{HTML::script('assets/javascript/firefly/reports.js')}} diff --git a/bootstrap/start.php b/bootstrap/start.php index 259599da65..4ebe8c71ae 100644 --- a/bootstrap/start.php +++ b/bootstrap/start.php @@ -17,16 +17,17 @@ if (!function_exists('mf')) { if ($coloured === true) { if ($amount === 0.0) { - return ''.$currencySymbol.' ' . $string . ''; + return '' . $currencySymbol . ' ' . $string . ''; } if ($amount > 0) { - return ''.$currencySymbol.' ' . $string . ''; + return '' . $currencySymbol . ' ' . $string . ''; } - return ''.$currencySymbol.' ' . $string . ''; + return '' . $currencySymbol . ' ' . $string . ''; } + // € - return $currencySymbol.' ' . $string; + return $currencySymbol . ' ' . $string; } } @@ -62,6 +63,38 @@ if (!function_exists('getCurrencySymbol')) { } } +if (!function_exists('getCurrencyCode')) { + /** + * @return string + */ + function getCurrencyCode() + { + if (defined('FFCURRENCYCODE')) { + return FFCURRENCYCODE; + } + if (Cache::has('FFCURRENCYCODE')) { + define('FFCURRENCYCODE', Cache::get('FFCURRENCYCODE')); + + return FFCURRENCYCODE; + } + + /** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencies */ + $currencies = App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency'); + + /** @var \FireflyIII\Shared\Preferences\Preferences $preferences */ + $preferences = App::make('FireflyIII\Shared\Preferences\Preferences'); + + $currencyPreference = $preferences->get('currencyPreference', 'EUR'); + $currency = $currencies->findByCode($currencyPreference->data); + + Cache::forever('FFCURRENCYCODE', $currency->code); + + define('FFCURRENCYCODE', $currency->code); + + return $currency->code; + } +} + if (!function_exists('boolstr')) { /** * @param $boolean diff --git a/public/assets/javascript/firefly/gcharts.js b/public/assets/javascript/firefly/gcharts.js index 4aebc1a993..a7538fb977 100644 --- a/public/assets/javascript/firefly/gcharts.js +++ b/public/assets/javascript/firefly/gcharts.js @@ -14,7 +14,7 @@ function googleLineChart(URL, container, options) { var money = new google.visualization.NumberFormat({ decimalSymbol: ',', groupingSymbol: '.', - prefix: '\u20AC ' + prefix: currencyCode + ' ' }); for (i = 1; i < gdata.getNumberOfColumns(); i++) { money.format(gdata, i); @@ -52,7 +52,7 @@ function googleBarChart(URL, container, options) { var money = new google.visualization.NumberFormat({ decimalSymbol: ',', groupingSymbol: '.', - prefix: '\u20AC ' + prefix: currencyCode + ' ' }); for (i = 1; i < gdata.getNumberOfColumns(); i++) { money.format(gdata, i); @@ -90,7 +90,7 @@ function googleColumnChart(URL, container, options) { var money = new google.visualization.NumberFormat({ decimalSymbol: ',', groupingSymbol: '.', - prefix: '\u20AC ' + prefix: currencyCode + ' ' }); for (i = 1; i < gdata.getNumberOfColumns(); i++) { money.format(gdata, i); @@ -113,43 +113,6 @@ function googleColumnChart(URL, container, options) { } } -function googleStackedColumnChart(URL, container, options) { - if ($('#' + container).length == 1) { - $.getJSON(URL).success(function (data) { - /* - Get the data from the JSON - */ - gdata = new google.visualization.DataTable(data); - - /* - Format as money - */ - var money = new google.visualization.NumberFormat({ - decimalSymbol: ',', - groupingSymbol: '.', - prefix: '\u20AC ' - }); - for (i = 1; i < gdata.getNumberOfColumns(); i++) { - money.format(gdata, i); - } - - /* - Create a new google charts object. - */ - var chart = new google.visualization.ColumnChart(document.getElementById(container)); - /* - Draw it: - */ - chart.draw(gdata, options || defaultStackedColumnChartOptions); - - }).fail(function () { - $('#' + container).addClass('google-chart-error'); - }); - } else { - console.log('No container found called "' + container + '"'); - } -} - function googleComboChart(URL, container, options) { if ($('#' + container).length == 1) { $.getJSON(URL).success(function (data) { @@ -164,7 +127,7 @@ function googleComboChart(URL, container, options) { var money = new google.visualization.NumberFormat({ decimalSymbol: ',', groupingSymbol: '.', - prefix: '\u20AC ' + prefix: currencyCode + ' ' }); for (i = 1; i < gdata.getNumberOfColumns(); i++) { money.format(gdata, i); @@ -201,7 +164,7 @@ function googlePieChart(URL, container, options) { var money = new google.visualization.NumberFormat({ decimalSymbol: ',', groupingSymbol: '.', - prefix: '\u20AC ' + prefix: currencyCode + ' ' }); for (i = 1; i < gdata.getNumberOfColumns(); i++) { money.format(gdata, i);