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

80 lines
2.2 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();
this.isDataSaved = false;
this.checkeds = [];
}
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());
}
createRefund() {
if (!this.checkeds.length) return;
const params = {servicesIds: this.checkeds, withWarehouse: false};
const query = 'Sales/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.sale', {id: refundTicket.id});
});
}
addChecked(id) {
if (this.checkeds.includes(id))
return this.checkeds = this.checkeds.filter(check => check != id);
this.checkeds.push(id);
}
}
ngModule.vnComponent('vnTicketService', {
template: require('./index.html'),
controller: Controller
});