salix/modules/client/front/risk/create/index.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-10-24 12:10:48 +00:00
import ngModule from '../../module';
class Controller {
constructor($scope, $state, $http, $stateParams) {
2018-10-24 12:10:48 +00:00
this.$http = $http;
this.$ = $scope;
this.$state = $state;
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
};
if (this.$stateParams.payed)
this.receipt.payed = this.$stateParams.payed;
2018-10-24 12:10:48 +00:00
if (this.$stateParams.bankFk)
this.receipt.bankFk = this.$stateParams.bankFk;
2018-10-24 12:10:48 +00:00
if (this.$stateParams.amountPaid)
this.receipt.amountPaid = this.$stateParams.amountPaid;
2018-10-24 12:10:48 +00:00
if (this.$stateParams.companyFk)
this.receipt.companyFk = this.$stateParams.companyFk;
2018-10-24 12:10:48 +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;
});
}
cancel() {
this.goToIndex();
2018-10-24 12:10:48 +00:00
}
goToIndex() {
this.$state.go('client.card.risk.index');
2018-10-24 12:10:48 +00:00
}
onSubmit() {
this.$.watcher.submit().then(
() => {
this.goToIndex();
}
);
2018-10-24 12:10:48 +00:00
}
}
Controller.$inject = ['$scope', '$state', '$http', '$stateParams'];
2018-10-24 12:10:48 +00:00
ngModule.component('vnClientRiskCreate', {
template: require('./index.html'),
controller: Controller
2018-10-24 12:10:48 +00:00
});