Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
Javi Gallego 2018-03-14 12:04:09 +01:00
commit 19870a7732
34 changed files with 581 additions and 21 deletions

View File

@ -220,6 +220,57 @@
"params": { "params": {
"client": "$ctrl.client" "client": "$ctrl.client"
} }
},
{
"url": "/credit-classification",
"abstract": true,
"state": "clientCard.creditClassification",
"component": "ui-view",
"acl": ["creditInsurance"]
},
{
"url": "/list",
"state": "clientCard.creditClassification.list",
"component": "vn-client-credit-classification-list",
"params": {
"client": "$ctrl.client"
},
"menu": {
"description": "Credit contracts",
"icon": "security"
},
"acl": ["creditInsurance"]
},
{
"url": "/create",
"state": "clientCard.creditClassification.create",
"component": "vn-client-credit-classification-create",
"params": {
"client": "$ctrl.client"
}
},
{
"url": "/credit-insurance",
"abstract": true,
"state": "clientCard.creditInsurance",
"component": "ui-view",
"acl": ["creditInsurance"]
},
{
"url": "/:classificationId/list",
"state": "clientCard.creditInsurance.list",
"component": "vn-client-credit-insurance-list",
"params": {
"client": "$ctrl.client"
}
},
{
"url": "/:classificationId/create",
"state": "clientCard.creditInsurance.create",
"component": "vn-client-credit-insurance-create",
"params": {
"client": "$ctrl.client"
}
} }
] ]
} }

View File

@ -23,3 +23,7 @@ import './invoices/invoices';
import './summary/client-summary'; import './summary/client-summary';
import './recovery-list/recovery-list'; import './recovery-list/recovery-list';
import './recovery-create/recovery-create'; import './recovery-create/recovery-create';
import './credit-classification-list/credit-classification-list';
import './credit-classification-create/credit-classification-create';
import './credit-insurance-list/credit-insurance-list';
import './credit-insurance-create/credit-insurance-create';

View File

@ -0,0 +1,24 @@
<mg-ajax path="/client/api/clients/{{post.params.id}}/creditClassifications" options="vnPost"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.creditClassification"
form="form"
save="post">
</vn-watcher>
<form name="form" ng-submit="watcher.submitGo('clientCard.creditClassification.list')" pad-medium>
<vn-card pad-large>
<vn-title>New contract</vn-title>
<vn-horizontal>
<vn-date-picker
vn-one
label="Since"
model="$ctrl.creditClassification.started"
ini-options="{dateFormat: 'd-m-Y'}"
vn-focus>
</vn-date-picker>
</vn-horizontal>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -0,0 +1,20 @@
import ngModule from '../module';
class Controller {
constructor($filter, $state) {
this.creditClassification = {
started: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm')
};
this.$state = $state;
}
}
Controller.$inject = ['$filter', '$state'];
ngModule.component('vnClientCreditClassificationCreate', {
template: require('./credit-classification-create.html'),
controller: Controller,
bindings: {
client: '<'
}
});

View File

@ -0,0 +1,43 @@
<vn-vertical pad-medium>
<vn-card pad-large>
<vn-title vn-one>Contract credit insurance</vn-title>
<vn-horizontal ng-repeat="classification in $ctrl.classifications track by classification.id" class="pad-medium-top" style="align-items: center;">
<vn-one border-radius class="pad-small border-solid" ng-class="{'bg-dark-item': !classification.finished,'bg-opacity-item': classification.finished}">
<vn-horizontal style="align-items: center;">
<vn-none pad-medium-h style="color:#FFA410;">
<i class="material-icons pointer"
ng-if="!classification.finished"
vn-tooltip="Close contract"
tooltip-position="left"
ng-click="$ctrl.closeContract(classification)">lock_outline</i>
</vn-none>
<vn-one border-solid-right>
<div><vn-label translate>Since</vn-label> {{::classification.started | date:'dd/MM/yyyy'}}</div>
<div><vn-label translate>To</vn-label> {{classification.finished | date:'dd/MM/yyyy'}}</div>
</vn-one>
<vn-vertical vn-one pad-medium-h>
<vn-one ng-repeat="insurance in classification.creditInsurances track by insurance.id">
<vn-label translate>Credit</vn-label> <span>{{insurance.credit}}</span>
<vn-label translate>Grade</vn-label>
<span ng-if="!insurance.grade">-</span>
<span ng-if="insurance.grade">{{insurance.grade}}</span>
<vn-label translate>Date</vn-label> <span>{{insurance.created | date:'dd/MM/yyyy' }}</span>
</vn-one>
</vn-vertical>
<a vn-auto ui-sref="clientCard.creditInsurance.list({classificationId: {{classification.id}}})">
<vn-icon-button icon="edit" vn-tooltip="Edit contract" tooltip-position="left"></vn-icon-button>
</a>
</vn-horizontal>
</vn-one>
</vn-horizontal>
</vn-card>
<vn-float-button
ng-if="$ctrl.canCreateNew()"
vn-tooltip="New contract"
tooltip-position="left"
fixed-bottom-right
ui-sref="clientCard.creditClassification.create"
icon="add"
label="Add">
</vn-float-button>
</vn-vertical>

View File

@ -0,0 +1,68 @@
import ngModule from '../module';
class Controller {
constructor($http, $scope) {
this.$http = $http;
this.$scope = $scope;
}
$onChanges() {
if (this.client && this.client.id)
this._getClassifications(this.client.id);
}
_getClassifications(clientId) {
let filter = {
include: [
{
relation: 'creditInsurances',
scope: {
fields: ['id', 'credit', 'created', 'grade'],
order: 'created DESC',
limit: 2
}
}
],
where: {client: clientId}
};
filter = encodeURIComponent(JSON.stringify(filter));
let query = `/client/api/CreditClassifications?filter=${filter}`;
this.$http.get(query).then(res => {
if (res.data)
this.classifications = res.data;
});
}
canCreateNew() {
if (!this.classifications)
return false;
let items = this.classifications;
for (let i = 0; i < items.length; i++) {
if (!items[i].finished)
return false;
}
return true;
}
closeContract(classification) {
let params = {finished: Date.now()};
this.$http.patch(`/client/api/CreditClassifications/${classification.id}`, params).then(() => {
this._getClassifications(this.client.id);
});
}
}
Controller.$inject = ['$http', '$scope'];
ngModule.component('vnClientCreditClassificationList', {
template: require('./credit-classification-list.html'),
controller: Controller,
bindings: {
client: '<'
}
});

View File

@ -0,0 +1,80 @@
import './credit-classification-list.js';
describe('Client', () => {
describe('Component vnClientCreditClassificationList', () => {
let $componentController;
let controller;
let $httpBackend;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
controller = $componentController('vnClientCreditClassificationList');
}));
describe('_getClassifications()', () => {
it('should perform a GET query to define the classifications property in the controller', () => {
let res = ['some classifications'];
let query = '/client/api/CreditClassifications?filter=%7B%22include%22%3A%5B%7B%22relation%22%3A%22creditInsurances%22%2C%22scope%22%3A%7B%22fields%22%3A%5B%22id%22%2C%22credit%22%2C%22created%22%2C%22grade%22%5D%2C%22order%22%3A%22created%20DESC%22%2C%22limit%22%3A2%7D%7D%5D%2C%22where%22%3A%7B%7D%7D';
$httpBackend.whenGET(query).respond(res);
$httpBackend.expectGET(query);
controller._getClassifications();
$httpBackend.flush();
expect(controller.classifications).toEqual(['some classifications']);
});
});
describe('canCreateNew()', () => {
it(`should return false if doesn't have classifications`, () => {
let result = controller.canCreateNew();
expect(result).toBeFalsy();
});
it(`should return false if finds a classification without due date`, () => {
controller.classifications = [
{finished: Date.now()},
{finished: null}
];
let result = controller.canCreateNew();
expect(result).toBeFalsy();
});
it(`should return true if all classifications are defined with due date`, () => {
controller.classifications = [
{finished: Date.now()},
{finished: Date.now()}
];
let result = controller.canCreateNew();
expect(result).toBeTruthy();
});
});
describe('closeContract()', () => {
it('should perform a GET query to set a due date to a contract', () => {
let res = ['pepinillos'];
controller.client = {id: 101};
let classification = {id: 1};
let query = '/client/api/CreditClassifications/1';
spyOn(controller, '_getClassifications');
$httpBackend.whenPATCH(query).respond(res);
$httpBackend.expectPATCH(query);
controller.closeContract(classification);
$httpBackend.flush();
expect(controller._getClassifications).toHaveBeenCalledWith(101);
});
});
});
});

View File

@ -0,0 +1,4 @@
Contract credit insurance: Contratos de seguro de crédito
New contract: Nuevo contrato
Close contract: Cerrar contrato
Edit contract: Modificar contrato

View File

@ -0,0 +1,42 @@
<mg-ajax path="/client/api/CreditClassifications/{{post.params.classificationId}}/creditInsurances" options="vnPost"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.insurance"
form="form"
save="post">
</vn-watcher>
<form name="form"
ng-submit="watcher.submitGo('clientCard.creditInsurance.list', {classificationId: post.params.classificationId})"
pad-medium>
<vn-card pad-large>
<vn-title>New credit</vn-title>
<vn-horizontal>
<vn-textfield
vn-one
margin-medium-right
label="Credit"
model="$ctrl.insurance.credit",
rule="CreditInsurance.credit"
step="1"
vn-focus>
</vn-textfield>
<vn-date-picker vn-one
label="Date"
model="$ctrl.insurance.created"
ini-options="{enableTime: true, dateFormat: 'd-m-Y h:i', time_24hr: true}">
</vn-date-picker>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
vn-one
argin-medium-right
label="Grade"
model="$ctrl.insurance.grade"
rule="CreditInsurance.grade">
</vn-textfield>
</vn-horizontal>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -0,0 +1,20 @@
import ngModule from '../module';
class Controller {
constructor($state, $filter) {
this.insurance = {
created: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm')
};
this.classificationId = $state.params.classificationId;
}
}
Controller.$inject = ['$state', '$filter'];
ngModule.component('vnClientCreditInsuranceCreate', {
template: require('./credit-insurance-create.html'),
controller: Controller,
bindings: {
client: '<'
}
});

View File

@ -0,0 +1 @@
New credit: Añadir crédito

View File

@ -0,0 +1,28 @@
<mg-ajax path="/client/api/CreditClassifications/{{index.params.classificationId}}/creditInsurances" options="vnIndex"></mg-ajax>
<vn-vertical pad-medium>
<vn-card pad-large>
<vn-vertical>
<vn-title>Requested credits</vn-title>
<vn-grid-header>
<vn-column-header vn-one pad-medium-h text="Amount"></vn-column-header>
<vn-column-header vn-one pad-medium-h text="Grade"></vn-column-header>
<vn-column-header vn-two pad-medium-h text="Date"></vn-column-header>
</vn-grid-header>
<vn-one class="list list-content">
<vn-horizontal
vn-one class="list list-element text-center"
pad-small-bottom
ng-repeat="insurance in index.model track by insurance.id">
<vn-one pad-medium-h>{{insurance.credit}}</vn-one>
<vn-one pad-medium-h>{{insurance.grade}}</vn-one>
<vn-two pad-medium-h>{{insurance.created | date: 'dd/MM/yyyy'}}</vn-two>
</vn-horizontal>
</vn-one>
<vn-horizontal vn-one class="list list-footer"></vn-horizontal>
</vn-vertical>
</vn-card>
</vn-vertical>
<a ui-sref="clientCard.creditInsurance.create({classificationId: {{index.params.classificationId}}})"
fixed-bottom-right vn-tooltip="New credit" tooltip-position="left">
<vn-float-button icon="add"></vn-float-button>
</a>

View File

@ -0,0 +1,17 @@
import ngModule from '../module';
class Controller {
constructor($state) {
this.classificationId = $state.params.classificationId;
}
}
Controller.$inject = ['$state'];
ngModule.component('vnClientCreditInsuranceList', {
template: require('./credit-insurance-list.html'),
controller: Controller,
bindings: {
client: '<'
}
});

View File

@ -0,0 +1 @@
Requested credits: Créditos solicitados

View File

@ -17,7 +17,7 @@ Save: Guardar
Pay method : Forma de pago Pay method : Forma de pago
Address: Consignatario Address: Consignatario
Credit : Crédito Credit : Crédito
Secured credit: Crédito asegurado Credit contracts: Contratos de crédito
Verified data: Datos comprobados Verified data: Datos comprobados
Mandate: Mandato Mandate: Mandato
Amount: Importe Amount: Importe

View File

@ -123,8 +123,8 @@
<vn-one margin-medium> <vn-one margin-medium>
<h5 translate>Recovery</h5> <h5 translate>Recovery</h5>
<vn-vertical ng-if="$ctrl.recovery"> <vn-vertical ng-if="$ctrl.recovery">
<p><vn-label translate>Since</vn-label> {{$ctrl.recovery.started}}</p> <p><vn-label translate>Since</vn-label> {{$ctrl.recovery.started | date:'dd/MM/yyyy'}}</p>
<p><vn-label translate>To</vn-label> {{$ctrl.recovery.finished}}</p> <p><vn-label translate>To</vn-label> {{$ctrl.recovery.finished | date:'dd/MM/yyyy'}}</p>
<p><vn-label translate>Amount</vn-label> {{$ctrl.recovery.amount | currency:'€':2}}</p> <p><vn-label translate>Amount</vn-label> {{$ctrl.recovery.amount | currency:'€':2}}</p>
<p><vn-label translate>Period</vn-label> {{$ctrl.recovery.period}}</p> <p><vn-label translate>Period</vn-label> {{$ctrl.recovery.period}}</p>
</vn-vertical> </vn-vertical>
@ -145,8 +145,8 @@
</p> </p>
<p> <p>
<vn-label translate>Secured credit</vn-label> <vn-label translate>Secured credit</vn-label>
<b ng-if="!$ctrl.summary.creditInsurance">-</b> <span ng-if="!$ctrl.summary.creditInsurance">-</span>
<b ng-if="$ctrl.summary.creditInsurance">{{$ctrl.summary.creditInsurance | currency:'€':2}} <span ng-if="$ctrl.summary.creditInsurance">{{$ctrl.summary.creditInsurance | currency:'€':2}}</span>
</p> </p>
</vn-one> </vn-one>
</vn-horizontal> </vn-horizontal>

View File

@ -5,10 +5,38 @@
"validations": false, "validations": false,
"routes": [ "routes": [
{ {
"url": "/tickets", "url": "/ticket",
"state": "tickets", "state": "ticket",
"component": "vn-ticket-index", "abstract": true,
"acl": ["developer"] "component": "ui-view"
},
{
"url": "/list?q",
"state": "ticket.list",
"component": "vn-ticket-list"
},
{
"url": "/create",
"state": "ticket.create",
"component": "vn-ticket-create"
},
{
"url": "/:id",
"state": "ticket.card",
"abstract": true,
"component": "vn-ticket-card"
},
{
"url" : "/data",
"state": "ticket.card.data",
"component": "vn-ticket-data",
"params": {
"ticket": "$ctrl.ticket"
},
"menu": {
"description": "Basic data",
"icon": "settings"
}
} }
] ]
} }

View File

@ -0,0 +1,11 @@
<vn-main-block>
<vn-horizontal>
<vn-auto margin-medium-v class="left-block">
<vn-item-descriptor ticket="$ctrl.ticket"></vn-ticket-descriptor>
<vn-left-menu></vn-left-menu>
</vn-auto>
<vn-one>
<vn-vertical margin-medium ui-view></vn-vertical>
</vn-one>
</vn-horizontal>
</vn-main-block>

View File

@ -0,0 +1,35 @@
import ngModule from '../module';
class TicketCard {
constructor($http, $state, $timeout) {
this.$http = $http;
this.$state = $state;
this.$timeout = $timeout;
this.ticket = null;
}
_getTicket() {
let filter = {
};
this.$http.get(`/ticket/api/Tickets/${this.$state.params.id}?filter=${JSON.stringify(filter)}`)
.then(res => {
if (res.data && res.data.id) {
this.$timeout(() => {
this.ticket = res.data;
});
}
}
);
}
$onInit() {
this._getTicket();
}
}
TicketCard.$inject = ['$http', '$state', '$timeout'];
ngModule.component('vnTicketCard', {
template: require('./ticket-card.html'),
controller: TicketCard
});

View File

@ -0,0 +1,18 @@
<mg-ajax path="/item/api/Tickets" options="vnPost"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.ticket"
form="form"
save="post">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" margin-medium>
<div style="max-width: 70em; margin: 0 auto;">
<vn-card pad-large>
<vn-title>New ticket</vn-title>
</vn-card>
<vn-button-bar>
<vn-submit label="Create"></vn-submit>
</vn-button-bar>
</div>
</form>

View File

@ -0,0 +1,21 @@
import ngModule from '../module';
class TicketCreate {
constructor($scope, $state) {
this.$ = $scope;
this.$state = $state;
this.Ticket = {};
}
onSubmit() {
this.$.watcher.submit().then(
json => this.$state.go('ticket.card.data', {id: json.data.id})
);
}
}
TicketCreate.$inject = ['$scope', '$state'];
ngModule.component('vnTicketCreate', {
template: require('./ticket-create.html'),
controller: TicketCreate
});

View File

View File

View File

@ -1,5 +1,5 @@
<a <a
ui-sref="clientCard.basicData({ id: {{::$ctrl.ticket.id}} })" ui-sref="ticket.card.data({ id: {{::$ctrl.ticket.id}} })"
translate-attr="{title: 'View client'}" translate-attr="{title: 'View client'}"
class="vn-list-item"> class="vn-list-item">
<vn-horizontal ng-click="$ctrl.onClick($event)"> <vn-horizontal ng-click="$ctrl.onClick($event)">

View File

@ -13,7 +13,7 @@ class Controller {
ngModule.component('vnTicketItem', { ngModule.component('vnTicketItem', {
controller: Controller, controller: Controller,
template: require('./item.html'), template: require('./ticket-item.html'),
bindings: { bindings: {
ticket: '<' ticket: '<'
} }

View File

@ -1,4 +1,4 @@
<mg-ajax path="/client/api/Clients/filter" options="mgIndex"></mg-ajax> <mg-ajax path="/client/api/Clients/filter" options="vnIndexNonAuto"></mg-ajax>
<div margin-medium> <div margin-medium>
<div class="vn-list"> <div class="vn-list">
<vn-card> <vn-card>
@ -19,6 +19,6 @@
<vn-paging index="index" total="index.model.count"></vn-paging> <vn-paging index="index" total="index.model.count"></vn-paging>
</div> </div>
</div> </div>
<a ui-sref="create" fixed-bottom-right> <a ui-sref="ticket.create" fixed-bottom-right>
<vn-float-button icon="person_add"></vn-float-button> <vn-float-button icon="add"></vn-float-button>
</a> </a>

View File

@ -1,5 +1,6 @@
import ngModule from '../module'; import ngModule from '../module';
import './item'; import './ticket-item';
import './style.scss';
export default class Controller { export default class Controller {
search(index) { search(index) {
@ -8,7 +9,7 @@ export default class Controller {
} }
Controller.$inject = []; Controller.$inject = [];
ngModule.component('vnTicketIndex', { ngModule.component('vnTicketList', {
template: require('./index.html'), template: require('./ticket-list.html'),
controller: Controller controller: Controller
}); });

View File

@ -1,4 +1,6 @@
export * from './module'; export * from './module';
import './index/index'; import './list/ticket-list';
import './create/ticket-create';
import './card/ticket-card';
import './data/ticket-data';

View File

@ -0,0 +1,14 @@
module.exports = Self => {
Self.installMethod('filter', filterParams);
function filterParams(params) {
return {
where: {
creditClassification: params.creditClassification
},
skip: (params.page - 1) * params.size,
limit: params.size,
order: params.order
};
}
};

View File

@ -33,7 +33,7 @@
"model": "Client", "model": "Client",
"foreignKey": "client" "foreignKey": "client"
}, },
"creditInsurance": { "creditInsurances": {
"type": "hasMany", "type": "hasMany",
"model": "CreditInsurance", "model": "CreditInsurance",
"foreignKey": "creditClassification" "foreignKey": "creditClassification"

View File

@ -0,0 +1,22 @@
module.exports = function(Self) {
require('../methods/creditInsurance/filter.js')(Self);
Self.validateBinded('credit', Self.validateCredit, {
message: 'The credit must be an integer greater than or equal to zero',
allowNull: false, // FIXME: Ignored by loopback when it's false
allowBlank: false
});
Self.validateCredit = function(credit) {
return (credit >= 0 && credit % 1 == 0);
};
Self.validateBinded('grade', Self.validateGrade, {
message: 'The grade must be an integer greater than or equal to zero',
allowNull: true
});
Self.validateGrade = function(grade) {
return (typeof grade === 'undefined' || (grade >= 0 && grade % 1 == 0));
};
};

View File

@ -27,7 +27,7 @@
} }
}, },
"relations": { "relations": {
"creditClassification": { "classification": {
"type": "belongsTo", "type": "belongsTo",
"model": "CreditClassification", "model": "CreditClassification",
"foreignKey": "creditClassification" "foreignKey": "creditClassification"

View File

@ -156,6 +156,11 @@
"type": "hasMany", "type": "hasMany",
"model": "Greuge", "model": "Greuge",
"foreignKey": "clientFk" "foreignKey": "clientFk"
},
"creditClassifications": {
"type": "hasMany",
"model": "CreditClassification",
"foreignKey": "client"
} }
} }
} }