From db88d00560ebffb05538b65aeb91d208a6b3acd0 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Fri, 9 Mar 2018 16:44:18 +0100 Subject: [PATCH] #156 client descriptor icons missing correct icons --- client/client/src/descriptor/descriptor.html | 26 +++++++++++ client/client/src/descriptor/descriptor.js | 29 +++++++++++- .../client/src/descriptor/descriptor.spec.js | 45 +++++++++++++++++++ client/salix/src/styles/misc.scss | 15 ++++++- .../loopback/common/methods/client/getDebt.js | 27 +++++++++++ .../methods/client/specs/getDebt.spec.js | 16 +++++++ services/loopback/common/models/client.js | 1 + services/loopback/common/models/client.json | 4 ++ 8 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 client/client/src/descriptor/descriptor.spec.js create mode 100644 services/loopback/common/methods/client/getDebt.js create mode 100644 services/loopback/common/methods/client/specs/getDebt.spec.js diff --git a/client/client/src/descriptor/descriptor.html b/client/client/src/descriptor/descriptor.html index a47c491e0..950baf89c 100644 --- a/client/client/src/descriptor/descriptor.html +++ b/client/client/src/descriptor/descriptor.html @@ -25,4 +25,30 @@ - +
\ No newline at end of file diff --git a/client/client/src/descriptor/descriptor.js b/client/client/src/descriptor/descriptor.js index d3467e82d..729b85fb3 100644 --- a/client/client/src/descriptor/descriptor.js +++ b/client/client/src/descriptor/descriptor.js @@ -1,8 +1,35 @@ import ngModule from '../module'; +class ClientDescriptor { + constructor($http) { + this.$http = $http; + } + _getClientDebt(clientFk) { + this.$http.get(`/client/api/Clients/${clientFk}/getDebt`) + .then(response => { + this.clientDebt = response.data.debt; + }); + } + + _getClient(clientFk) { + this.$http.get(`/client/api/Clients/${clientFk}/card`) + .then(response => { + Object.assign(this.client, response.data); + }); + } + + $onChanges(changes) { + if (changes.client && this.client) { + this._getClient(this.client.id); + this._getClientDebt(this.client.id); + } + } +} + ngModule.component('vnClientDescriptor', { template: require('./descriptor.html'), bindings: { client: '<' - } + }, + controller: ClientDescriptor }); diff --git a/client/client/src/descriptor/descriptor.spec.js b/client/client/src/descriptor/descriptor.spec.js new file mode 100644 index 000000000..a5139298f --- /dev/null +++ b/client/client/src/descriptor/descriptor.spec.js @@ -0,0 +1,45 @@ +import './descriptor.js'; + +describe('Descriptor', () => { + describe('Component vnClientDescriptor', () => { + let $componentController; + let $httpBackend; + let controller; + + beforeEach(() => { + angular.mock.module('client'); + }); + + beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => { + $componentController = _$componentController_; + $httpBackend = _$httpBackend_; + controller = $componentController('vnClientDescriptor'); + })); + + describe('_getClientDebt()', () => { + it(`should call _getClientDebt() and define the client.debt value on the controller`, () => { + controller.client = {}; + let response = {debt: 100}; + $httpBackend.whenGET(`/client/api/Clients/101/getDebt`).respond(response); + $httpBackend.expectGET(`/client/api/Clients/101/getDebt`); + controller._getClientDebt(101); + $httpBackend.flush(); + + expect(controller.client.debt).toEqual(100); + }); + }); + + describe('_getClient()', () => { + it(`should call _getClient() and define the client value on the controller`, () => { + controller.client = {}; + let response = {id: 101, name: 'Batman'}; + $httpBackend.whenGET(`/client/api/Clients/101/card`).respond(response); + $httpBackend.expectGET(`/client/api/Clients/101/card`); + controller._getClient(101); + $httpBackend.flush(); + + expect(controller.client.name).toEqual('Batman'); + }); + }); + }); +}); diff --git a/client/salix/src/styles/misc.scss b/client/salix/src/styles/misc.scss index ecebb90e9..34fc2063c 100644 --- a/client/salix/src/styles/misc.scss +++ b/client/salix/src/styles/misc.scss @@ -138,7 +138,7 @@ vn-main-block { } .vn-descriptor { - & .header { + .header { background: #ffa410; color: white; justify-content: space-between; @@ -163,6 +163,19 @@ vn-main-block { } } } + .footer { + text-align: center; + & > vn-icon { + color: #666; + opacity: .4; + padding: 0 5% 0 5%; + font-size: 1.5em; + } + & > vn-icon.bright { + color: #ffa410; + opacity: 1; + } + } } .vn-list { diff --git a/services/loopback/common/methods/client/getDebt.js b/services/loopback/common/methods/client/getDebt.js new file mode 100644 index 000000000..c04c208b8 --- /dev/null +++ b/services/loopback/common/methods/client/getDebt.js @@ -0,0 +1,27 @@ +module.exports = Self => { + Self.remoteMethod('getDebt', { + description: 'Returns the boolean debt of a client', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'client id', + http: {source: 'path'} + }], + returns: { + type: 'number', + root: true + }, + http: { + path: `/:id/getDebt`, + verb: 'GET' + } + }); + + Self.getDebt = async clientFk => { + let query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`; + let response = await Self.rawSql(query, [clientFk]); + return response[0]; + }; +}; diff --git a/services/loopback/common/methods/client/specs/getDebt.spec.js b/services/loopback/common/methods/client/specs/getDebt.spec.js new file mode 100644 index 000000000..c79cb9058 --- /dev/null +++ b/services/loopback/common/methods/client/specs/getDebt.spec.js @@ -0,0 +1,16 @@ +const getDebt = require('../getDebt'); + +describe('client getDebt()', () => { + it('should call the getDebt method', done => { + let clientFk = 109; + let self = jasmine.createSpyObj('self', ['remoteMethod', 'rawSql']); + self.rawSql.and.returnValue(Promise.resolve([{debt: 100}])); + getDebt(self); + self.getDebt(clientFk) + .then(result => { + expect(result.debt).toEqual(100); + done(); + }); + }); +}); + diff --git a/services/loopback/common/models/client.js b/services/loopback/common/models/client.js index e5202c5bf..b09c38688 100644 --- a/services/loopback/common/models/client.js +++ b/services/loopback/common/models/client.js @@ -15,6 +15,7 @@ module.exports = function(Self) { require('../methods/client/isValidClient')(Self); require('../methods/client/activeSalesPerson')(Self); require('../methods/client/addressesPropagateRe')(Self); + require('../methods/client/getDebt')(Self); // Validations diff --git a/services/loopback/common/models/client.json b/services/loopback/common/models/client.json index 89d836d01..c7120e67a 100644 --- a/services/loopback/common/models/client.json +++ b/services/loopback/common/models/client.json @@ -64,6 +64,10 @@ "type": "boolean", "description": "The client has equalization tax" }, + "isFreezed": { + "type": "boolean", + "description": "The client frozen" + }, "hasToInvoiceByAddress": { "type": "boolean", "description": "The client has to be invoiced by address"