66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
import ngModule from '../../module';
|
|
|
|
class Controller {
|
|
constructor($scope, $state, $http, $stateParams) {
|
|
this.$http = $http;
|
|
this.$ = $scope;
|
|
this.$state = $state;
|
|
this.$stateParams = $stateParams;
|
|
|
|
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;
|
|
|
|
if (this.$stateParams.bankFk)
|
|
this.receipt.bankFk = this.$stateParams.bankFk;
|
|
|
|
if (this.$stateParams.amountPaid)
|
|
this.receipt.amountPaid = this.$stateParams.amountPaid;
|
|
|
|
if (this.$stateParams.companyFk)
|
|
this.receipt.companyFk = this.$stateParams.companyFk;
|
|
}
|
|
|
|
$onInit() {
|
|
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();
|
|
}
|
|
|
|
goToIndex() {
|
|
this.$state.go('client.card.risk.index');
|
|
}
|
|
|
|
onSubmit() {
|
|
this.$.watcher.submit().then(
|
|
() => {
|
|
this.goToIndex();
|
|
}
|
|
);
|
|
}
|
|
}
|
|
Controller.$inject = ['$scope', '$state', '$http', '$stateParams'];
|
|
|
|
ngModule.component('vnClientRiskCreate', {
|
|
template: require('./index.html'),
|
|
controller: Controller
|
|
});
|