2018-10-24 12:10:48 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
|
|
|
|
class Controller {
|
2019-02-05 15:42:28 +00:00
|
|
|
constructor($scope, $state, $http, $stateParams) {
|
2018-10-24 12:10:48 +00:00
|
|
|
this.$http = $http;
|
|
|
|
this.$ = $scope;
|
|
|
|
this.$state = $state;
|
2019-02-05 15:42:28 +00:00
|
|
|
this.$stateParams = $stateParams;
|
2018-10-24 12:10:48 +00:00
|
|
|
|
|
|
|
this.receipt = {
|
|
|
|
payed: new Date(),
|
|
|
|
clientFk: this.$state.params.id,
|
|
|
|
companyFk: window.localStorage.defaultCompanyFk,
|
|
|
|
bankFk: window.localStorage.defaultBankFk
|
|
|
|
};
|
|
|
|
|
2019-02-05 15:42:28 +00:00
|
|
|
if (this.$stateParams.payed)
|
|
|
|
this.receipt.payed = this.$stateParams.payed;
|
2018-10-24 12:10:48 +00:00
|
|
|
|
2019-02-05 15:42:28 +00:00
|
|
|
if (this.$stateParams.bankFk)
|
|
|
|
this.receipt.bankFk = this.$stateParams.bankFk;
|
2018-10-24 12:10:48 +00:00
|
|
|
|
2019-02-05 15:42:28 +00:00
|
|
|
if (this.$stateParams.amountPaid)
|
|
|
|
this.receipt.amountPaid = this.$stateParams.amountPaid;
|
2018-10-24 12:10:48 +00:00
|
|
|
|
2019-02-05 15:42:28 +00:00
|
|
|
if (this.$stateParams.companyFk)
|
|
|
|
this.receipt.companyFk = this.$stateParams.companyFk;
|
2018-10-24 12:10:48 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 15:42:28 +00:00
|
|
|
$onInit() {
|
2018-10-24 12:10:48 +00:00
|
|
|
let filter = {
|
|
|
|
where: {
|
|
|
|
clientFk: this.$state.params.id,
|
|
|
|
companyFk: this.receipt.companyFk
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let query = `/client/api/ClientRisks?filter=${JSON.stringify(filter)}`;
|
|
|
|
this.$http.get(query).then(res => {
|
|
|
|
this.receipt.amountPaid = (res.data.length && res.data[0].amount) || null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-05 15:42:28 +00:00
|
|
|
cancel() {
|
|
|
|
this.goToIndex();
|
2018-10-24 12:10:48 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 15:42:28 +00:00
|
|
|
goToIndex() {
|
|
|
|
this.$state.go('client.card.risk.index');
|
2018-10-24 12:10:48 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 15:42:28 +00:00
|
|
|
onSubmit() {
|
|
|
|
this.$.watcher.submit().then(
|
|
|
|
() => {
|
|
|
|
this.goToIndex();
|
|
|
|
}
|
|
|
|
);
|
2018-10-24 12:10:48 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-05 15:42:28 +00:00
|
|
|
Controller.$inject = ['$scope', '$state', '$http', '$stateParams'];
|
2018-10-24 12:10:48 +00:00
|
|
|
|
|
|
|
ngModule.component('vnClientRiskCreate', {
|
|
|
|
template: require('./index.html'),
|
2019-02-05 15:42:28 +00:00
|
|
|
controller: Controller
|
2018-10-24 12:10:48 +00:00
|
|
|
});
|