2018-05-23 12:26:51 +00:00
|
|
|
import ngModule from '../../module';
|
2019-10-01 14:17:57 +00:00
|
|
|
import './style.scss';
|
2018-03-14 10:36:57 +00:00
|
|
|
|
|
|
|
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 = {
|
2018-03-28 13:07:48 +00:00
|
|
|
order: 'finished ASC, started DESC',
|
2018-03-14 10:36:57 +00:00
|
|
|
include: [
|
|
|
|
{
|
2018-07-09 11:01:46 +00:00
|
|
|
relation: 'insurances',
|
2018-03-14 10:36:57 +00:00
|
|
|
scope: {
|
|
|
|
fields: ['id', 'credit', 'created', 'grade'],
|
|
|
|
order: 'created DESC',
|
|
|
|
limit: 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
where: {client: clientId}
|
|
|
|
};
|
|
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `CreditClassifications?filter=${filter}`;
|
2018-03-14 10:36:57 +00:00
|
|
|
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) {
|
2018-03-28 13:07:48 +00:00
|
|
|
this.classificationId = classification.id;
|
|
|
|
this.$scope.closeContract.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
returnDialog(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response === 'accept') {
|
2018-05-21 09:59:23 +00:00
|
|
|
let params = {finished: Date.now()};
|
2019-10-24 22:53:53 +00:00
|
|
|
this.$http.patch(`CreditClassifications/${this.classificationId}`, params).then(() => {
|
2018-05-21 09:59:23 +00:00
|
|
|
this._getClassifications(this.client.id);
|
|
|
|
});
|
|
|
|
}
|
2018-03-14 10:36:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$http', '$scope'];
|
|
|
|
|
2018-05-23 12:26:51 +00:00
|
|
|
ngModule.component('vnClientCreditInsuranceIndex', {
|
|
|
|
template: require('./index.html'),
|
2018-03-14 10:36:57 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
client: '<'
|
|
|
|
}
|
|
|
|
});
|