diff --git a/e2e/paths/02-client/21_defaulter.spec.js b/e2e/paths/02-client/21_defaulter.spec.js index c7640d028..0eb16441f 100644 --- a/e2e/paths/02-client/21_defaulter.spec.js +++ b/e2e/paths/02-client/21_defaulter.spec.js @@ -28,12 +28,12 @@ describe('Client defaulter path', () => { const salesPersonName = await page.waitToGetProperty(selectors.clientDefaulter.firstSalesPersonName, 'innerText'); - expect(clientName).toEqual('Ororo Munroe'); - expect(salesPersonName).toEqual('salesPersonNick'); + expect(clientName).toEqual('Bruce Banner'); + expect(salesPersonName).toEqual('developer'); }); it('should first observation not changed', async() => { - const expectedObservation = 'Madness, as you know, is like gravity, all it takes is a little push'; + const expectedObservation = 'Meeting with Black Widow 21st 9am'; const result = await page.waitToGetProperty(selectors.clientDefaulter.firstObservation, 'value'); expect(result).toContain(expectedObservation); diff --git a/front/core/filters/currency.js b/front/core/filters/currency.js index d44457813..a25ff6b27 100644 --- a/front/core/filters/currency.js +++ b/front/core/filters/currency.js @@ -15,8 +15,9 @@ export default function currency($translate) { maximumFractionDigits: fractionSize }; + const lang = $translate.use() == 'es' ? 'de' : $translate.use(); if (typeof input == 'number') { - return new Intl.NumberFormat($translate.use(), options) + return new Intl.NumberFormat(lang, options) .format(input); } diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index ec38c0821..81c8e1d2d 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -58,12 +58,12 @@ module.exports = Self => { DISTINCT c.id clientFk, c.name clientName, c.salesPersonFk, - u.nickname salesPersonName, + u.name salesPersonName, d.amount, co.created, co.text observation, uw.id workerFk, - uw.nickname workerName, + uw.name workerName, c.creditInsurance, d.defaulterSinced FROM vn.defaulter d diff --git a/modules/client/front/defaulter/index.html b/modules/client/front/defaulter/index.html index 92664079c..22b78594a 100644 --- a/modules/client/front/defaulter/index.html +++ b/modules/client/front/defaulter/index.html @@ -3,6 +3,7 @@ url="Defaulters/filter" filter="::$ctrl.filter" limit="20" + order="amount DESC" data="defaulters" auto-load="true"> @@ -70,13 +71,13 @@ - Last observation D. + field="created"> + L. O. Date + field="creditInsurance" + shrink> Credit I. @@ -124,13 +125,13 @@ ng-model="defaulter.observation"> - + {{::defaulter.created | date: 'dd/MM/yyyy'}} - {{::defaulter.creditInsurance | currency: 'EUR': 2}} - {{::defaulter.defaulterSinced | date: 'dd/MM/yyyy'}} + {{::defaulter.creditInsurance | currency: 'EUR': 2}} + {{::defaulter.defaulterSinced | date: 'dd/MM/yyyy'}} diff --git a/modules/client/front/defaulter/index.js b/modules/client/front/defaulter/index.js index 80f510bf2..4beadfda6 100644 --- a/modules/client/front/defaulter/index.js +++ b/modules/client/front/defaulter/index.js @@ -26,7 +26,7 @@ export default class Controller extends Section { url: 'Workers/activeWithInheritedRole', where: `{role: 'salesPerson'}`, searchFunction: '{firstName: $search}', - showField: 'nickname', + showField: 'name', valueField: 'id', } }, @@ -35,7 +35,7 @@ export default class Controller extends Section { autocomplete: { url: 'Workers/activeWithInheritedRole', searchFunction: '{firstName: $search}', - showField: 'nickname', + showField: 'name', valueField: 'id', } }, @@ -53,16 +53,8 @@ export default class Controller extends Section { } ] }; - } - get balanceDueTotal() { - let balanceDueTotal = 0; - const defaulters = this.$.model.data || []; - - for (let defaulter of defaulters) - balanceDueTotal += defaulter.amount; - - return balanceDueTotal; + 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 5801fa1f8..0732c68a1 100644 --- a/modules/client/front/defaulter/index.spec.js +++ b/modules/client/front/defaulter/index.spec.js @@ -36,17 +36,6 @@ describe('client defaulter', () => { }); }); - describe('balanceDueTotal() getter', () => { - it('should return balance due total', () => { - const data = controller.$.model.data; - const expectedAmount = data[0].amount + data[1].amount + data[2].amount; - - const result = controller.balanceDueTotal; - - expect(result).toEqual(expectedAmount); - }); - }); - describe('chipColor()', () => { it('should return undefined when the date is the present', () => { let today = new Date(); @@ -93,6 +82,7 @@ describe('client defaulter', () => { const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}]; jest.spyOn(controller.vnApp, 'showMessage'); + $httpBackend.expect('GET', `Defaulters/filter`).respond(200); $httpBackend.expect('POST', `ClientObservations`, params).respond(200, params); controller.onResponse(); @@ -115,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); + }); + }); }); }); diff --git a/modules/client/front/defaulter/locale/es.yml b/modules/client/front/defaulter/locale/es.yml index 3f046e8d6..c3e1d4e19 100644 --- a/modules/client/front/defaulter/locale/es.yml +++ b/modules/client/front/defaulter/locale/es.yml @@ -3,7 +3,7 @@ Add observation to all selected clients: Añadir observación a {{total}} client Balance D.: Saldo V. Credit I.: Crédito A. Last observation: Última observación -Last observation D.: Fecha última O. +L. O. Date: Fecha Ú. O. Last observation date: Fecha última observación Search client: Buscar clientes Worker who made the last observation: Trabajador que ha realizado la última observación \ No newline at end of file