diff --git a/front/core/filters/currency.js b/front/core/filters/currency.js index e4c428e5d..a25ff6b27 100644 --- a/front/core/filters/currency.js +++ b/front/core/filters/currency.js @@ -15,10 +15,7 @@ export default function currency($translate) { maximumFractionDigits: fractionSize }; - let lang = $translate.use(); - if (lang == 'es') - lang = 'de'; - + const lang = $translate.use() == 'es' ? 'de' : $translate.use(); if (typeof input == 'number') { return new Intl.NumberFormat(lang, options) .format(input); diff --git a/modules/client/front/defaulter/index.html b/modules/client/front/defaulter/index.html index 143784ea1..22b78594a 100644 --- a/modules/client/front/defaulter/index.html +++ b/modules/client/front/defaulter/index.html @@ -27,7 +27,7 @@
Total
+ value="{{$ctrl.balanceDueTotal | currency: 'EUR': 2}}"> diff --git a/modules/client/front/defaulter/index.js b/modules/client/front/defaulter/index.js index 5da055c9a..4beadfda6 100644 --- a/modules/client/front/defaulter/index.js +++ b/modules/client/front/defaulter/index.js @@ -54,15 +54,7 @@ export default class Controller extends Section { ] }; - this.$http.get('Defaulters/filter') - .then(res => { - if (!res.data) return 0; - - this.balanceDueTotal = res.data.reduce( - (accumulator, currentValue) => { - return accumulator + (currentValue['amount'] || 0); - }, 0); - }); + this.getBalanceDueTotal(); } get checked() { @@ -76,6 +68,18 @@ export default class Controller extends Section { return checkedLines; } + getBalanceDueTotal() { + this.$http.get('Defaulters/filter') + .then(res => { + if (!res.data) return 0; + + this.balanceDueTotal = res.data.reduce( + (accumulator, currentValue) => { + return accumulator + (currentValue['amount'] || 0); + }, 0); + }); + } + chipColor(date) { const day = 24 * 60 * 60 * 1000; const today = new Date(); diff --git a/modules/client/front/defaulter/index.spec.js b/modules/client/front/defaulter/index.spec.js index 370cd9a82..0732c68a1 100644 --- a/modules/client/front/defaulter/index.spec.js +++ b/modules/client/front/defaulter/index.spec.js @@ -105,5 +105,17 @@ describe('client defaulter', () => { expect(expr).toEqual({'d.clientFk': '5'}); }); }); + + describe('getBalanceDueTotal()', () => { + it('should return balance due total', () => { + const defaulters = controller.$.model.data; + $httpBackend.when('GET', `Defaulters/filter`).respond(defaulters); + + controller.getBalanceDueTotal(); + $httpBackend.flush(); + + expect(controller.balanceDueTotal).toEqual(875); + }); + }); }); });