2018-11-30 06:57:41 +00:00
|
|
|
import ngModule from '../module';
|
2019-05-29 11:06:42 +00:00
|
|
|
import UserError from 'core/lib/user-error';
|
2018-11-30 06:57:41 +00:00
|
|
|
|
|
|
|
class Controller {
|
2019-05-16 12:07:16 +00:00
|
|
|
constructor($http, $scope, $stateParams, vnApp, $translate, $element) {
|
|
|
|
this.$http = $http;
|
2018-11-30 06:57:41 +00:00
|
|
|
this.$scope = $scope;
|
|
|
|
this.$stateParams = $stateParams;
|
2019-05-16 12:07:16 +00:00
|
|
|
this.vnApp = vnApp;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.$element = $element;
|
|
|
|
this.services = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$onInit() {
|
|
|
|
this.getDefaultTaxClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
getDefaultTaxClass() {
|
2019-11-11 15:32:03 +00:00
|
|
|
let filter = {
|
|
|
|
where: {code: 'G'}
|
|
|
|
};
|
|
|
|
this.$http.get('TaxClasses/findOne', {filter})
|
|
|
|
.then(res => this.defaultTaxClass = res.data);
|
2018-11-30 06:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
add() {
|
2019-11-12 07:51:50 +00:00
|
|
|
if (this.defaultTaxClass) {
|
|
|
|
this.$scope.model.insert({
|
|
|
|
taxClassFk: this.defaultTaxClass.id,
|
|
|
|
quantity: 1,
|
|
|
|
ticketFk: this.$stateParams.id
|
|
|
|
});
|
|
|
|
}
|
2018-11-30 06:57:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-16 12:07:16 +00:00
|
|
|
onNewServiceTypeOpen() {
|
2019-10-11 15:38:04 +00:00
|
|
|
this.newServiceType = {};
|
2019-05-16 12:07:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
newServiceTypeDialog(elementIndex, event) {
|
|
|
|
event.preventDefault();
|
2019-05-16 12:07:16 +00:00
|
|
|
this.$scope.createServiceTypeDialog.show();
|
|
|
|
this.currentServiceIndex = elementIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
onNewServiceTypeResponse(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response == 'accept') {
|
2019-05-29 11:06:42 +00:00
|
|
|
if (!this.newServiceType.name)
|
|
|
|
throw new UserError(`Name can't be empty`);
|
2019-05-16 12:07:16 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
this.$http.post(`TicketServiceTypes`, this.newServiceType).then(response => {
|
2019-12-13 10:59:25 +00:00
|
|
|
this.services[this.currentServiceIndex].ticketServiceTypeFk = response.data.id;
|
2019-05-29 11:06:42 +00:00
|
|
|
});
|
2019-05-16 12:07:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 06:57:41 +00:00
|
|
|
onSubmit() {
|
|
|
|
this.$scope.watcher.check();
|
2019-05-29 11:06:42 +00:00
|
|
|
|
2018-11-30 06:57:41 +00:00
|
|
|
this.$scope.model.save().then(() => {
|
|
|
|
this.$scope.watcher.notifySaved();
|
2019-03-06 07:54:04 +00:00
|
|
|
this.$scope.model.refresh();
|
2018-11-30 06:57:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 12:07:16 +00:00
|
|
|
Controller.$inject = ['$http', '$scope', '$stateParams', 'vnApp', '$translate', '$element'];
|
2018-11-30 06:57:41 +00:00
|
|
|
|
|
|
|
ngModule.component('vnTicketService', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|