2018-11-30 06:57:41 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
|
|
|
|
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() {
|
|
|
|
let config = {params: {
|
|
|
|
filter: {
|
|
|
|
where: {
|
|
|
|
code: 'G'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
|
|
|
|
let query = '/api/TaxClasses/findOne';
|
|
|
|
this.$http.get(query, config).then(res => {
|
|
|
|
if (res.data)
|
|
|
|
this.defaultTaxClass = res.data;
|
|
|
|
});
|
2018-11-30 06:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
add() {
|
|
|
|
this.$scope.model.insert({
|
2019-05-16 12:07:16 +00:00
|
|
|
taxClassFk: this.defaultTaxClass.id,
|
2018-11-30 06:57:41 +00:00
|
|
|
quantity: 1,
|
|
|
|
ticketFk: this.$stateParams.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-16 12:07:16 +00:00
|
|
|
onNewServiceTypeOpen() {
|
|
|
|
this.newServiceType.name = '';
|
|
|
|
|
|
|
|
this.nameInput = this.$element[0].querySelector('.edit input');
|
|
|
|
this.nameInput.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
newServiceTypeDialog(elementIndex) {
|
|
|
|
this.$scope.createServiceTypeDialog.show();
|
|
|
|
this.currentServiceIndex = elementIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
onNewServiceTypeResponse(response) {
|
|
|
|
if (response == 'ACCEPT') {
|
|
|
|
try {
|
|
|
|
if (!this.newServiceType.name)
|
|
|
|
throw new Error(`Name can't be empty`);
|
|
|
|
|
|
|
|
this.$http.post(`/api/TicketServiceTypes`, this.newServiceType).then(response => {
|
|
|
|
this.services[this.currentServiceIndex].description = response.data.name;
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
this.vnApp.showError(this.$translate.instant(err.message));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 06:57:41 +00:00
|
|
|
onSubmit() {
|
|
|
|
this.$scope.watcher.check();
|
|
|
|
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
|
|
|
|
});
|