salix/modules/ticket/front/services/index.js

94 lines
2.5 KiB
JavaScript

import ngModule from '../module';
import Section from 'salix/components/section';
import UserError from 'core/lib/user-error';
class Controller extends Section {
$onInit() {
this.services = [];
this.getDefaultTaxClass();
}
getDefaultTaxClass() {
let filter = {
where: {code: 'G'}
};
this.$http.get('TaxClasses/findOne', {filter})
.then(res => this.defaultTaxClass = res.data);
}
add() {
this.$.model.insert({
taxClassFk: this.defaultTaxClass.id,
quantity: 1,
ticketFk: this.$params.id
});
}
onNewServiceTypeClick(service, event) {
event.preventDefault();
this.$.newServiceType = {};
this.$.newServiceTypeDialog.show(service);
}
onNewServiceTypeAccept(service) {
if (!this.$.newServiceType.name)
throw new UserError(`Name can't be empty`);
return this.$http.post(`TicketServiceTypes`, this.$.newServiceType)
.then(res => {
this.$.typesModel.refresh();
return res;
})
.then(res => service.ticketServiceTypeFk = res.data.id);
}
onSubmit() {
this.$.watcher.check();
this.$.model.save()
.then(() => this.$.model.refresh())
.then(() => this.$.watcher.notifySaved());
}
selectedServices() {
if (!this.services) return;
return this.services.filter(service => {
return service.checked;
});
}
selectedValidServices() {
if (!this.services) return;
const selectedServices = this.selectedServices();
return selectedServices.filter(service => {
return service.id != undefined;
});
}
createRefund() {
const services = this.selectedServices();
if (!services) return;
const servicesIds = services.map(service => service.id);
const params = {servicesIds: servicesIds};
const query = 'Tickets/refund';
this.$http.post(query, params).then(res => {
const refundTicket = res.data;
this.vnApp.showSuccess(this.$t('The following refund ticket have been created', {
ticketId: refundTicket.id
}));
this.$state.go('ticket.card.service', {id: refundTicket.id});
this.resetChanges();
});
}
}
ngModule.vnComponent('vnTicketService', {
template: require('./index.html'),
controller: Controller
});