Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Extend JS to include currency code #37
James Colefe1fb23e5bbb
diff --git a/app/views/accounts/index.blade.php b/app/views/accounts/index.blade.phpindex c98c6e38b1..5c2416ab00 100644--- a/app/views/accounts/index.blade.php+++ b/app/views/accounts/index.blade.php@@ -30,6 +30,7 @@@section('scripts')<script type="text/javascript">var what = '{{{$what}}}';+ var currencyCode = '{{getCurrencyCode()}}';</script><!-- load the libraries and scripts necessary for Google Charts: -->diff --git a/app/views/accounts/show.blade.php b/app/views/accounts/show.blade.phpindex d54e245446..b7da493119 100644--- a/app/views/accounts/show.blade.php+++ b/app/views/accounts/show.blade.php@@ -52,6 +52,7 @@<script type="text/javascript">var accountID = {{{$account->id}}};var view = '{{{$range}}}';+ var currencyCode = '{{getCurrencyCode()}}';</script><!-- load the libraries and scripts necessary for Google Charts: --><script type="text/javascript" src="https://www.google.com/jsapi"></script>diff --git a/app/views/categories/index.blade.php b/app/views/categories/index.blade.phpindex e20f21b4e5..8a0a4034b1 100644--- a/app/views/categories/index.blade.php+++ b/app/views/categories/index.blade.php@@ -28,6 +28,9 @@</div>@stop@section('scripts')+<script type="text/javascript">+ var currencyCode = '{{getCurrencyCode()}}';+</script><!-- load the libraries and scripts necessary for Google Charts: --><script type="text/javascript" src="https://www.google.com/jsapi"></script>{{HTML::script('assets/javascript/firefly/gcharts.options.js')}}diff --git a/app/views/categories/show.blade.php b/app/views/categories/show.blade.phpindex 34e1d4a265..a80f0a9bb5 100644--- a/app/views/categories/show.blade.php+++ b/app/views/categories/show.blade.php@@ -32,9 +32,8 @@<script type="text/javascript">var componentID = {{$category->id}};var year = {{Session::get('start',\Carbon\Carbon::now()->startOfMonth())->format('Y')}};-+ var currencyCode = '{{getCurrencyCode()}}';</script>-<!-- load the libraries and scripts necessary for Google Charts: --><script type="text/javascript" src="https://www.google.com/jsapi"></script>{{HTML::script('assets/javascript/firefly/gcharts.options.js')}}diff --git a/app/views/index.blade.php b/app/views/index.blade.phpindex 587f3a6f34..5a90e8ce31 100644--- a/app/views/index.blade.php+++ b/app/views/index.blade.php@@ -113,6 +113,9 @@@stop@section('scripts')+<script type="text/javascript">+ var currencyCode = '{{getCurrencyCode()}}';+</script><!-- load the libraries and scripts necessary for Google Charts: --><script type="text/javascript" src="https://www.google.com/jsapi"></script>{{HTML::script('assets/javascript/firefly/gcharts.options.js')}}diff --git a/app/views/recurring/show.blade.php b/app/views/recurring/show.blade.phpindex 27d059ef2f..b877599d47 100644--- a/app/views/recurring/show.blade.php+++ b/app/views/recurring/show.blade.php@@ -105,9 +105,9 @@@section('scripts')<script type="text/javascript">-var recurringID = {{{$recurring->id}}};+ var recurringID = {{{$recurring->id}}};+ var currencyCode = '{{getCurrencyCode()}}';</script>-<!-- load the libraries and scripts necessary for Google Charts: --><script type="text/javascript" src="https://www.google.com/jsapi"></script>{{HTML::script('assets/javascript/firefly/gcharts.options.js')}}diff --git a/app/views/reports/unbalanced.blade.php b/app/views/reports/unbalanced.blade.phpindex 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')+<script type="text/javascript">+ var currencyCode = '{{getCurrencyCode()}}';+</script>{{HTML::script('assets/javascript/firefly/reports.js')}}{{HTML::script('assets/javascript/firefly/related-manager.js')}}@stop\ No newline at end of filediff --git a/app/views/reports/year.blade.php b/app/views/reports/year.blade.phpindex e3a358494f..827f988a37 100644--- a/app/views/reports/year.blade.php+++ b/app/views/reports/year.blade.php@@ -117,7 +117,7 @@<script type="text/javascript">var year = '{{$year}}';-+var currencyCode = '{{getCurrencyCode()}}';</script>{{HTML::script('assets/javascript/firefly/reports.js')}}diff --git a/bootstrap/start.php b/bootstrap/start.phpindex 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 '<span style="color:#999">'.$currencySymbol.' ' . $string . '</span>';+ return '<span style="color:#999">' . $currencySymbol . ' ' . $string . '</span>';}if ($amount > 0) {- return '<span class="text-success">'.$currencySymbol.' ' . $string . '</span>';+ return '<span class="text-success">' . $currencySymbol . ' ' . $string . '</span>';}- return '<span class="text-danger">'.$currencySymbol.' ' . $string . '</span>';+ return '<span class="text-danger">' . $currencySymbol . ' ' . $string . '</span>';}+// €- 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 $booleandiff --git a/public/assets/javascript/firefly/gcharts.js b/public/assets/javascript/firefly/gcharts.jsindex 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);