Extend JS to include currency code #37

This commit is contained in:
James Cole 2014-12-24 06:10:39 +01:00
parent c2dd61e96b
commit fe1fb23e5b
10 changed files with 57 additions and 51 deletions

View File

@ -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: -->

View File

@ -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>

View File

@ -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')}}

View File

@ -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')}}

View File

@ -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')}}

View File

@ -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')}}

View File

@ -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

View File

@ -117,7 +117,7 @@
<script type="text/javascript">
var year = '{{$year}}';
var currencyCode = '{{getCurrencyCode()}}';
</script>
{{HTML::script('assets/javascript/firefly/reports.js')}}

View File

@ -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>';
}
// &#8364;
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

View File

@ -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);