From 704c25ce458b2541b6b32bad6f5f2ef5645bf4e8 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Tue, 19 Sep 2017 16:50:01 +0200 Subject: [PATCH] Aggiunta libreria NumeralJS --- lib/functions.js | 49 ++++++++++++++---------------- modules/fatture/crea_documento.php | 6 ++-- modules/primanota/add.php | 6 ++-- modules/primanota/edit.php | 6 ++-- modules/scadenzario/edit.php | 4 +-- package.json | 1 + 6 files changed, 35 insertions(+), 37 deletions(-) diff --git a/lib/functions.js b/lib/functions.js index a717e090e..a7c7af627 100644 --- a/lib/functions.js +++ b/lib/functions.js @@ -36,6 +36,25 @@ $(document).ready(function () { moment.locale(globals.locale); globals.timestampFormat = moment.localeData().longDateFormat('L') + ' ' + moment.localeData().longDateFormat('LT'); + // Imposta lo standard per la conversione dei numeri + numeral.register('locale', 'it', { + delimiters: { + thousands: globals.thousands, + decimal: globals.decimals, + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + currency: { + symbol: '€' + } + }); + numeral.locale('it'); + numeral.defaultFormat('0,0.' + ('0').repeat(globals.cifre_decimali)); + // Orologio clock(); @@ -74,7 +93,7 @@ $(document).ready(function () { }, function (start, end) { // Esegue il submit del periodo selezionato e ricarica la pagina - $.get(globals.rootdir + '/core.php?period_start=' + start.format('YYYY-MM-DD') + '&period_end=' + end.format('YYYY-MM-DD'), function (data ) { + $.get(globals.rootdir + '/core.php?period_start=' + start.format('YYYY-MM-DD') + '&period_end=' + end.format('YYYY-MM-DD'), function (data) { location.reload(); }); } @@ -1105,34 +1124,12 @@ Number.prototype.formatMoney = function (c, d, t) { return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); } -Number.prototype.toFixedLocale = function (decimals) { - decimals = decimals || globals.cifre_decimali - return this.toFixed(decimals).toLocale(); -}; - String.prototype.toEnglish = function () { - var x = this.split(globals.decimals); - - if (globals.thousands) { - x[0] = x[0].replace(globals.thousands, ''); - } - - return parseFloat(x[0] + '.' + x[1]); + return numeral(this.toString()).value(); }; -String.prototype.toLocale = function () { - var x = this.split('.'); - - if (globals.thousands) { - x[0] = x[0].split("").reverse().join(""); - x[0] = x[0].replace(/(.{3})/g, "$1" + globals.thousands); - x[0] = x[0].split("").reverse().join(""); - if (x[0][0] == globals.thousands) { - x[0] = x[0].substr(1); - } - } - - return x[0] + globals.decimals + x[1]; +Number.prototype.toLocale = function () { + return numeral(this).format(); }; function setContrast(backgroundcolor) { diff --git a/modules/fatture/crea_documento.php b/modules/fatture/crea_documento.php index 5739ebe0a..5d21b9aae 100644 --- a/modules/fatture/crea_documento.php +++ b/modules/fatture/crea_documento.php @@ -250,10 +250,10 @@ echo ' $("#serial_"+r).data('maximum', qta); start_superselect(); - subtotale = (subtot * qta + iva * qta).toFixedLocale(2); + subtotale = (subtot * qta + iva * qta).toLocale(); $("#subtotale_"+r).html(subtotale+" €"); - $("#subtotaledettagli_"+r).html((subtot * qta).toFixedLocale(2) + " + " + (iva * qta).toFixedLocale(2)); + $("#subtotaledettagli_"+r).html((subtot * qta).toLocale() + " + " + (iva * qta).toLocale()); ricalcola_totale(); } @@ -283,7 +283,7 @@ echo ' r++; }); - $('#totale').html( (totale.toFixedLocale()) + " €" ); + $('#totale').html( (totale.toLocale()) + " €" ); if( totale==0 ) $('#submit_btn').hide(); diff --git a/modules/primanota/add.php b/modules/primanota/add.php index 38df5f942..baee59f47 100644 --- a/modules/primanota/add.php +++ b/modules/primanota/add.php @@ -287,8 +287,8 @@ include_once __DIR__.'/../../core.php'; totale_avere += valore; }); - $('#totale_dare').text(totale_dare.toFixedLocale()); - $('#totale_avere').text(totale_avere.toFixedLocale()); + $('#totale_dare').text(totale_dare.toLocale()); + $('#totale_avere').text(totale_avere.toLocale()); bilancio = totale_dare - totale_avere; @@ -297,7 +297,7 @@ include_once __DIR__.'/../../core.php'; $("button[type=submit]").removeClass('hide'); } else{ - $("#testo_aggiuntivo").addClass('text-danger').html("sbilancio di " + bilancio.toFixedLocale() + " €" ); + $("#testo_aggiuntivo").addClass('text-danger').html("sbilancio di " + bilancio.toLocale() + " €" ); $("button[type=submit]").addClass('hide'); } } diff --git a/modules/primanota/edit.php b/modules/primanota/edit.php index fad114a95..02577b3af 100644 --- a/modules/primanota/edit.php +++ b/modules/primanota/edit.php @@ -211,8 +211,8 @@ include_once __DIR__.'/../../core.php'; totale_avere += valore; }); - $('#totale_dare').text(totale_dare.toFixedLocale()); - $('#totale_avere').text(totale_avere.toFixedLocale()); + $('#totale_dare').text(totale_dare.toLocale()); + $('#totale_avere').text(totale_avere.toLocale()); bilancio = totale_dare-totale_avere; @@ -221,7 +221,7 @@ include_once __DIR__.'/../../core.php'; $("button[type=submit]").removeClass('hide'); } else{ - $("#testo_aggiuntivo").addClass('text-danger').html("sbilancio di " + bilancio.toFixedLocale() + " €" ); + $("#testo_aggiuntivo").addClass('text-danger').html("sbilancio di " + bilancio.toLocale() + " €" ); $("button[type=submit]").addClass('hide'); } diff --git a/modules/scadenzario/edit.php b/modules/scadenzario/edit.php index 190a32253..4a2bff2bf 100644 --- a/modules/scadenzario/edit.php +++ b/modules/scadenzario/edit.php @@ -175,7 +175,7 @@ echo ' $('#totale').removeClass('hide'); } - $('#diff').html(diff.toFixedLocale()); - $('#totale_utente').html(totale_utente.toFixedLocale()); + $('#diff').html(diff.toLocale()); + $('#totale_utente').html(totale_utente.toLocale()); } diff --git a/package.json b/package.json index a1c5a5722..d61af024f 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "jquery-form": "^4.2.1", "jquery-ui-touch-punch": "^0.2.3", "moment": "^2.18.1", + "numeral": "^2.0.6", "parsleyjs": "^2.7.2", "select2": "^4.0.3", "select2-bootstrap-theme": "^0.1.0-beta.10",