77 lines
1.9 KiB
JavaScript
77 lines
1.9 KiB
JavaScript
import ngModule from '../../module';
|
|
import './style.scss';
|
|
|
|
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 = {
|
|
order: 'finished ASC, started DESC',
|
|
include: [
|
|
{
|
|
relation: 'insurances',
|
|
scope: {
|
|
fields: ['id', 'credit', 'created', 'grade'],
|
|
order: 'created DESC',
|
|
limit: 2
|
|
}
|
|
}
|
|
|
|
],
|
|
where: {client: clientId}
|
|
};
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
|
|
let query = `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) {
|
|
this.classificationId = classification.id;
|
|
this.$scope.closeContract.show();
|
|
}
|
|
|
|
returnDialog(response) {
|
|
if (response === 'accept') {
|
|
let params = {finished: Date.now()};
|
|
this.$http.patch(`CreditClassifications/${this.classificationId}`, params).then(() => {
|
|
this._getClassifications(this.client.id);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$http', '$scope'];
|
|
|
|
ngModule.component('vnClientCreditInsuranceIndex', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
client: '<'
|
|
}
|
|
});
|