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

256 lines
7.0 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
2020-04-25 09:50:04 +00:00
import Descriptor from 'salix/components/descriptor';
2020-04-25 09:50:04 +00:00
class Controller extends Descriptor {
2019-12-17 07:38:36 +00:00
get ticket() {
return this.entity;
2019-12-17 07:38:36 +00:00
}
set ticket(value) {
this.entity = value;
}
2019-12-17 07:38:36 +00:00
get entity() {
return super.entity;
}
2019-12-17 07:38:36 +00:00
set entity(value) {
super.entity = value;
2019-12-17 07:38:36 +00:00
this.canStowaway();
2020-09-01 10:10:32 +00:00
this.isTicketEditable();
2019-12-17 07:38:36 +00:00
if (value && this.$params.sendSMS)
this.showSMSDialog();
2019-12-17 07:38:36 +00:00
}
get isInvoiced() {
return this.ticket.refFk !== null;
2019-01-21 07:45:02 +00:00
}
get isTicketModule() {
return this.$state.getCurrentPath()[1].state.name === 'ticket';
}
get shouldShowDeleteStowaway() {
if (!this.ticket || !this.isTicketModule)
return false;
2018-11-08 14:20:42 +00:00
return this.ticket.stowaway || this.ticket.ship;
2019-01-18 12:36:13 +00:00
}
2020-07-03 11:28:49 +00:00
get filter() {
if (this.ticket)
return JSON.stringify({clientFk: this.ticket.clientFk});
return null;
}
2020-10-08 11:42:20 +00:00
get canRestoreTicket() {
const isDeleted = this.ticket.isDeleted;
const now = new Date();
const maxDate = new Date(this.ticket.updated);
maxDate.setHours(maxDate.getHours() + 1);
return isDeleted && (now <= maxDate);
}
2020-06-29 09:43:53 +00:00
isTicketEditable() {
2020-09-01 10:10:32 +00:00
if (!this.ticket) return;
this.$http.get(`Tickets/${this.id}/isEditable`).then(res => {
2020-06-29 09:43:53 +00:00
this.isEditable = res.data;
});
}
showChangeShipped() {
this.newShipped = this.ticket.shipped;
this.$.changeShippedDialog.show();
2019-01-18 12:36:13 +00:00
}
changeShipped() {
let data = {
shipped: this.newShipped
};
return this.$http.post(`Tickets/${this.id}/updateEditableTicket`, data)
.then(() => this.cardReload())
.then(() => this.vnApp.showSuccess(this.$t('Shipped hour updated')));
2018-11-08 14:20:42 +00:00
}
goToTicket(ticketId) {
this.$state.go('ticket.card.sale', {id: ticketId}, {absolute: true});
2018-11-08 14:20:42 +00:00
}
addTurn(day) {
let params = {
ticketFk: this.id,
weekDay: day,
agencyModeFk: this.ticket.agencyModeFk
};
return this.$http.patch(`TicketWeeklies`, params)
.then(() => {
this.$.addTurn.hide();
this.vnApp.showSuccess(this.$t('Data saved!'));
});
2018-11-08 14:20:42 +00:00
}
deleteTicket() {
return this.$http.post(`Tickets/${this.id}/setDeleted`)
.then(() => {
2018-11-08 14:20:42 +00:00
this.$state.go('ticket.index');
2020-10-08 11:42:20 +00:00
this.vnApp.showSuccess(this.$t('Ticket deleted. You can undo this action within the first hour'));
2018-11-08 14:20:42 +00:00
});
}
2020-10-07 09:00:26 +00:00
restoreTicket() {
return this.$http.post(`Tickets/${this.id}/restore`)
.then(() => {
2020-10-08 11:42:20 +00:00
this.vnApp.showSuccess(this.$t('Data saved!'));
2020-10-07 09:00:26 +00:00
this.cardReload();
});
}
2019-12-17 07:38:36 +00:00
canStowaway() {
this.canShowStowaway = false;
if (!this.isTicketModule || !this.ticket) return;
2018-09-04 09:49:00 +00:00
this.$http.get(`Tickets/${this.id}/canHaveStowaway`)
.then(res => this.canShowStowaway = !!res.data);
2018-09-04 09:49:00 +00:00
}
2019-12-17 07:38:36 +00:00
deleteStowaway() {
return this.$http.post(`Tickets/${this.id}/deleteStowaway`)
.then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
this.cardReload();
});
2018-09-04 09:49:00 +00:00
}
showDeliveryNote() {
2020-06-12 12:28:29 +00:00
this.vnReport.show('delivery-note', {
2020-05-22 13:20:55 +00:00
recipientId: this.ticket.client.id,
ticketId: this.id,
});
}
2019-11-06 08:32:54 +00:00
sendDeliveryNote() {
2020-06-12 12:28:29 +00:00
return this.vnEmail.send('delivery-note', {
2020-05-22 13:20:55 +00:00
recipientId: this.ticket.client.id,
2019-11-06 08:32:54 +00:00
recipient: this.ticket.client.email,
ticketId: this.id
});
}
2020-03-10 14:01:33 +00:00
sendImportSms() {
const params = {
ticketId: this.id,
2020-10-08 11:42:20 +00:00
created: this.ticket.updated
2020-03-10 14:01:33 +00:00
};
this.showSMSDialog({
message: this.$params.message || this.$t('Minimum is needed', params)
});
2020-03-10 14:01:33 +00:00
}
sendPaymentSms() {
this.showSMSDialog({
message: this.$params.message || this.$t('Make a payment')
});
2020-03-10 14:01:33 +00:00
}
showSMSDialog(params) {
const address = this.ticket.address;
2020-02-21 07:37:37 +00:00
const client = this.ticket.client;
const phone = this.$params.phone
|| address.mobile
|| address.phone
|| client.mobile
|| client.phone;
this.newSMS = Object.assign({
destinationFk: this.ticket.clientFk,
destination: phone
}, params);
2019-11-12 07:51:50 +00:00
this.$.sms.open();
}
2019-04-12 11:54:31 +00:00
makeInvoice() {
return this.$http.post(`Tickets/${this.id}/makeInvoice`)
.then(() => {
2020-03-30 15:30:03 +00:00
this.vnApp.showSuccess(this.$t('Ticket invoiced'));
2019-04-12 11:54:31 +00:00
this.$state.reload();
});
2019-04-26 06:52:43 +00:00
}
regenerateInvoice() {
const invoiceId = this.ticket.invoiceOut.id;
return this.$http.post(`InvoiceOuts/${invoiceId}/regenerate`)
.then(() => {
2020-03-30 15:30:03 +00:00
const snackbarMessage = this.$t(
2019-04-26 06:52:43 +00:00
`Invoice sent for a regeneration, will be available in a few minutes`);
this.vnApp.showSuccess(snackbarMessage);
});
2019-11-20 05:53:37 +00:00
}
recalculateComponents() {
return this.$http.post(`Tickets/${this.id}/recalculateComponents`)
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
}
cardReload() {
// Prevents error when not defined
}
loadData() {
const filter = {
include: [
{
relation: 'warehouse',
scope: {
fields: ['name']
}
}, {
relation: 'agencyMode',
scope: {
fields: ['name']
}
}, {
relation: 'client',
scope: {
fields: [
'salesPersonFk',
'name',
'isActive',
'isFreezed',
'isTaxDataChecked'
],
include: {
relation: 'salesPersonUser',
scope: {
fields: ['id', 'name']
}
}
}
}, {
2020-06-23 11:40:49 +00:00
relation: 'ticketState',
scope: {
fields: ['stateFk'],
include: {
relation: 'state',
fields: ['id', 'name'],
}
}
}
]
};
return this.getData(`Tickets/${this.id}`, {filter})
.then(res => this.entity = res.data);
2019-11-20 05:53:37 +00:00
}
}
2020-04-25 09:50:04 +00:00
ngModule.vnComponent('vnTicketDescriptor', {
template: require('./index.html'),
2020-04-25 09:50:04 +00:00
controller: Controller,
bindings: {
ticket: '<',
cardReload: '&'
2020-04-25 09:50:04 +00:00
}
});