From de12bda66b71a267a605f0401acd64f109b70e46 Mon Sep 17 00:00:00 2001 From: Gerard Date: Wed, 14 Nov 2018 10:55:15 +0100 Subject: [PATCH] #739 client.riisk --- client/client/src/risk/index/index.html | 43 +++++++++------ client/client/src/risk/index/index.js | 52 +++++++++++++++---- client/client/src/risk/index/index.spec.js | 35 +++++++++++++ client/client/src/risk/index/style.scss | 6 +++ .../client/common/methods/receipt/filter.js | 8 +-- .../methods/receipt/specs/filter.spec.js | 5 +- 6 files changed, 119 insertions(+), 30 deletions(-) create mode 100644 client/client/src/risk/index/index.spec.js create mode 100644 client/client/src/risk/index/style.scss diff --git a/client/client/src/risk/index/index.html b/client/client/src/risk/index/index.html index cc0135599..072ecae37 100644 --- a/client/client/src/risk/index/index.html +++ b/client/client/src/risk/index/index.html @@ -1,13 +1,9 @@ + data="$ctrl.risks"> - Risk -
-
Total por empresa
- - - - -
+ + Risk + + + + + + +
+
Total por empresa
+ + + + +
+
@@ -43,7 +53,7 @@ - + {{::risk.payed | dateTime:'dd/MM/yyyy'}} {{::risk.created | dateTime:'dd/MM/yyyy HH:mm'}} {{::risk.firstName}} {{::risk.name}} @@ -51,6 +61,7 @@ {{::risk.bankFk}} {{::risk.debit | currency: ' €': 2}} {{::risk.credit | currency: ' €': 2}} + {{risk.balance}} = 0; i--) { + let row = this.$.model.data[i]; + let tot; + if (i != this.$.model.data.length - 1) + row.balance = (row.credit - row.debit) + (this.$.model.data[i + 1].balance); + else + row.balance = row.credit - row.debit; + + tot = tot + row.balance; + } + this._risks = this.$.model.data; + } + } + + get risks() { + return this._risks; } } -Controller.$inject = ['$stateParams']; +Controller.$inject = ['$stateParams', '$translate', '$scope']; ngModule.component('vnClientRiskIndex', { template: require('./index.html'), - controller: Controller + controller: Controller, }); diff --git a/client/client/src/risk/index/index.spec.js b/client/client/src/risk/index/index.spec.js new file mode 100644 index 000000000..86e3ab1d2 --- /dev/null +++ b/client/client/src/risk/index/index.spec.js @@ -0,0 +1,35 @@ +import './index'; + +describe('Client', () => { + describe('Component vnClientRiskIndex', () => { + let $componentController; + let $scope; + let controller; + + beforeEach(() => { + angular.mock.module('client'); + }); + + beforeEach(angular.mock.inject((_$componentController_, $rootScope) => { + $componentController = _$componentController_; + $scope = $rootScope.$new(); + controller = $componentController('vnClientRiskIndex', {$scope: $scope}); + })); + + describe('risks() setter', () => { + it('should calculate the balance for each line from the oldest date to the newest', () => { + let risks = [ + {credit: 100, debit: 0}, + {credit: 100, debit: 0}, + {credit: 0, debit: 300} + ]; + controller.$.model = {data: risks}; + controller.risks = risks; + + expect(controller.risks[0].balance).toEqual(-100); + expect(controller.risks[1].balance).toEqual(-200); + expect(controller.risks[2].balance).toEqual(-300); + }); + }); + }); +}); diff --git a/client/client/src/risk/index/style.scss b/client/client/src/risk/index/style.scss new file mode 100644 index 000000000..a6758e2e6 --- /dev/null +++ b/client/client/src/risk/index/style.scss @@ -0,0 +1,6 @@ +vn-client-risk-index { + .totalBox { + display: table; + float: right; + } +} \ No newline at end of file diff --git a/services/client/common/methods/receipt/filter.js b/services/client/common/methods/receipt/filter.js index f63bac66d..d6b03001b 100644 --- a/services/client/common/methods/receipt/filter.js +++ b/services/client/common/methods/receipt/filter.js @@ -46,7 +46,7 @@ module.exports = Self => { FROM vn.receipt r LEFT JOIN vn.worker w ON w.id = r.workerFk JOIN vn.company c ON c.id = r.companyFk - WHERE clientFk = ? + WHERE r.clientFk = ? AND r.companyFk = ? UNION ALL SELECT i.id, @@ -63,11 +63,13 @@ module.exports = Self => { i.clientFk FROM vn.invoiceOut i JOIN vn.company c ON c.id = i.companyFk - WHERE clientFk = ? + WHERE i.clientFk = ? AND i.companyFk = ? ) t ORDER BY payed DESC, created DESC`, [ params.clientFk, - params.clientFk + params.companyFk, + params.clientFk, + params.companyFk, ] ); diff --git a/services/client/common/methods/receipt/specs/filter.spec.js b/services/client/common/methods/receipt/specs/filter.spec.js index aa48f473d..5691ed089 100644 --- a/services/client/common/methods/receipt/specs/filter.spec.js +++ b/services/client/common/methods/receipt/specs/filter.spec.js @@ -1,10 +1,11 @@ const app = require(`${servicesDir}/client/server/server`); -xdescribe('receipt filter()', () => { +describe('receipt filter()', () => { it('should call the filter method', async () => { let filter = {limit: 20}; let params = { - clientFk: 101 + clientFk: 101, + companyFk: 442 }; let result = await app.models.Receipt.filter(filter, params);