diff --git a/package.json b/package.json index 39f5c5573..7247476f9 100755 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "autoprefixer": "^10.0.4", "chart.js": "^3.3.0", "css-loader": "^3.6.0", + "currency.js": "^2.0.4", "dayjs": "^1.8.36", "jspdf": "^2.1.1", "mini-css-extract-plugin": "^1.0.0", diff --git a/resources/ts/filters/currency.ts b/resources/ts/filters/currency.ts index 1487dfc21..f8357281d 100755 --- a/resources/ts/filters/currency.ts +++ b/resources/ts/filters/currency.ts @@ -1,5 +1,6 @@ import Vue from 'vue'; import NumeralJS from "numeral"; +import currency from 'currency.js'; declare const ns; declare const window; @@ -9,17 +10,6 @@ const precision = ( new Array( parseInt( ns.currency.ns_currency_precision const nsCurrency = Vue.filter( 'currency', ( value, format = 'full', locale = 'en' ) => { let numeralFormat, currencySymbol; - switch( format ) { - case 'abbreviate': - numeralFormat = `0.00a`; - break; - default: - numeralFormat = `0${ns.currency.ns_currency_thousand_separator}0${ns.currency.ns_currency_decimal_separator}${precision}`; - break; - } - - NumeralJS.locale( locale ); - switch( ns.currency.ns_currency_prefered ) { case 'iso' : currencySymbol = ns.currency.ns_currency_iso; @@ -29,7 +19,16 @@ const nsCurrency = Vue.filter( 'currency', ( value, format = 'full', lo break; } - return `${ns.currency.ns_currency_position === 'before' ? currencySymbol : '' }${NumeralJS( value ).format( numeralFormat )}${ns.currency.ns_currency_position === 'after' ? currencySymbol : '' }`; + const config = { + decimal: ns.currency.ns_currency_decimal_separator, + separator: ns.currency.ns_currency_thousand_separator, + precision : parseInt( ns.currency.ns_currency_precision ), + symbol: '' + }; + + const currencyValue = currency( value, config ); + + return `${ns.currency.ns_currency_position === 'before' ? currencySymbol : '' }${ currencyValue.format() }${ns.currency.ns_currency_position === 'after' ? currencySymbol : '' }`; }); const nsRawCurrency = ( value ) => {