Skip to content

Commit

Permalink
Fixed: currency configuration not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Blair2004 committed Jul 27, 2021
1 parent 480ca11 commit 7ad9dc9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 11 additions & 12 deletions resources/ts/filters/currency.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue';
import NumeralJS from "numeral";
import currency from 'currency.js';

declare const ns;
declare const window;
Expand All @@ -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;
Expand All @@ -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 ) => {
Expand Down

0 comments on commit 7ad9dc9

Please sign in to comment.