#156 client descriptor icons missing correct icons

This commit is contained in:
Carlos Jimenez 2018-03-09 16:44:18 +01:00
parent c9ba1d00e4
commit db88d00560
8 changed files with 161 additions and 2 deletions

View File

@ -25,4 +25,30 @@
<span ng-if="!$ctrl.client.creditInsurance">-</span> <span ng-if="!$ctrl.client.creditInsurance">-</span>
</div> </div>
</div> </div>
<div class="footer">
<vn-icon
vn-tooltip="Client inactive"
tooltip-position = "right"
icon="person"
ng-class="{bright: $ctrl.client.isActive == false}">
</vn-icon>
<vn-icon
vn-tooltip="Client Frozen"
tooltip-position = "right"
icon="mail"
ng-class="{bright: $ctrl.client.isFreezed == true}">
</vn-icon>
<vn-icon
vn-tooltip="Web Account inactive"
tooltip-position = "right"
icon="phone"
ng-class="{bright: $ctrl.client.account.active == false}">
</vn-icon>
<vn-icon
vn-tooltip="Client has debt"
tooltip-position = "right"
icon="power"
ng-class="{bright: $ctrl.clientDebt < 0}">
</vn-icon>
</div>
</vn-card> </vn-card>

View File

@ -1,8 +1,35 @@
import ngModule from '../module'; 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', { ngModule.component('vnClientDescriptor', {
template: require('./descriptor.html'), template: require('./descriptor.html'),
bindings: { bindings: {
client: '<' client: '<'
} },
controller: ClientDescriptor
}); });

View File

@ -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');
});
});
});
});

View File

@ -138,7 +138,7 @@ vn-main-block {
} }
.vn-descriptor { .vn-descriptor {
& .header { .header {
background: #ffa410; background: #ffa410;
color: white; color: white;
justify-content: space-between; 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 { .vn-list {

View File

@ -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];
};
};

View File

@ -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();
});
});
});

View File

@ -15,6 +15,7 @@ module.exports = function(Self) {
require('../methods/client/isValidClient')(Self); require('../methods/client/isValidClient')(Self);
require('../methods/client/activeSalesPerson')(Self); require('../methods/client/activeSalesPerson')(Self);
require('../methods/client/addressesPropagateRe')(Self); require('../methods/client/addressesPropagateRe')(Self);
require('../methods/client/getDebt')(Self);
// Validations // Validations

View File

@ -64,6 +64,10 @@
"type": "boolean", "type": "boolean",
"description": "The client has equalization tax" "description": "The client has equalization tax"
}, },
"isFreezed": {
"type": "boolean",
"description": "The client frozen"
},
"hasToInvoiceByAddress": { "hasToInvoiceByAddress": {
"type": "boolean", "type": "boolean",
"description": "The client has to be invoiced by address" "description": "The client has to be invoiced by address"