2018-08-30 06:50:03 +00:00
|
|
|
import ngModule from '../module';
|
2020-04-25 09:50:04 +00:00
|
|
|
import Descriptor from 'salix/components/descriptor';
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2020-04-25 09:50:04 +00:00
|
|
|
class Controller extends Descriptor {
|
2019-12-17 07:38:36 +00:00
|
|
|
get ticket() {
|
2020-04-30 10:48:52 +00:00
|
|
|
return this.entity;
|
2019-12-17 07:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set ticket(value) {
|
2020-04-30 10:48:52 +00:00
|
|
|
this.entity = value;
|
|
|
|
}
|
2019-12-17 07:38:36 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
get entity() {
|
|
|
|
return super.entity;
|
|
|
|
}
|
2019-12-17 07:38:36 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
set entity(value) {
|
|
|
|
super.entity = value;
|
2019-12-17 07:38:36 +00:00
|
|
|
this.canStowaway();
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
if (value && this.$params.sendSMS)
|
|
|
|
this.showSMSDialog();
|
2019-12-17 07:38:36 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
get isEditable() {
|
|
|
|
try {
|
|
|
|
return !this.ticket.tracking.state.alertLevel;
|
|
|
|
} catch (e) {}
|
2020-03-30 15:30:03 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
return true;
|
2019-01-21 07:45:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
get isInvoiced() {
|
|
|
|
return this.ticket.refFk !== null;
|
2019-01-21 07:45:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
get isTicketModule() {
|
|
|
|
return this.$state.getCurrentPath()[1].state.name === 'ticket';
|
2019-02-04 11:24:47 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
get shouldShowDeleteStowaway() {
|
|
|
|
if (!this.ticket || !this.isTicketModule)
|
|
|
|
return false;
|
2018-11-08 14:20:42 +00:00
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
return this.ticket.stowaway || this.ticket.ship;
|
2019-01-18 12:36:13 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
showChangeShipped() {
|
|
|
|
this.newShipped = this.ticket.shipped;
|
|
|
|
this.$.changeShippedDialog.show();
|
2019-01-18 12:36:13 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +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
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
goToTicket(ticketId) {
|
|
|
|
this.$state.go('ticket.card.sale', {id: ticketId}, {absolute: true});
|
2018-11-08 14:20:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addTurn(day) {
|
2020-04-08 10:33:36 +00:00
|
|
|
let params = {
|
2020-04-30 10:48:52 +00:00
|
|
|
ticketFk: this.id,
|
2020-04-08 10:33:36 +00:00
|
|
|
weekDay: day,
|
2020-04-30 10:48:52 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +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-03-30 15:30:03 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Ticket deleted'));
|
2018-11-08 14:20:42 +00:00
|
|
|
});
|
|
|
|
}
|
2019-04-10 08:43:11 +00:00
|
|
|
|
2019-12-17 07:38:36 +00:00
|
|
|
canStowaway() {
|
2020-04-30 10:48:52 +00:00
|
|
|
this.canShowStowaway = false;
|
|
|
|
if (!this.isTicketModule || !this.ticket) return;
|
2018-09-04 09:49:00 +00:00
|
|
|
|
2020-04-30 10:48:52 +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() {
|
2020-04-30 10:48:52 +00:00
|
|
|
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
|
|
|
}
|
2019-02-11 09:06:26 +00:00
|
|
|
|
|
|
|
showDeliveryNote() {
|
2020-04-30 10:48:52 +00:00
|
|
|
this.showReport('delivery-note', {
|
2020-05-22 13:20:55 +00:00
|
|
|
recipientId: this.ticket.client.id,
|
2020-04-30 10:48:52 +00:00
|
|
|
ticketId: this.id,
|
|
|
|
});
|
2019-02-11 09:06:26 +00:00
|
|
|
}
|
2019-03-29 06:29:09 +00:00
|
|
|
|
2019-11-06 08:32:54 +00:00
|
|
|
sendDeliveryNote() {
|
2020-04-30 10:48:52 +00:00
|
|
|
return this.sendEmail('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,
|
2020-04-30 10:48:52 +00:00
|
|
|
ticketId: this.id
|
|
|
|
});
|
2019-11-06 07:20:45 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 14:01:33 +00:00
|
|
|
sendImportSms() {
|
|
|
|
const params = {
|
2020-04-30 10:48:52 +00:00
|
|
|
ticketId: this.id,
|
2020-03-10 14:01:33 +00:00
|
|
|
created: this.ticket.created
|
|
|
|
};
|
2020-04-30 10:48:52 +00:00
|
|
|
this.showSMSDialog({
|
|
|
|
message: this.$params.message || this.$t('Minimum is needed', params)
|
|
|
|
});
|
2020-03-10 14:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sendPaymentSms() {
|
2020-04-30 10:48:52 +00:00
|
|
|
this.showSMSDialog({
|
|
|
|
message: this.$params.message || this.$t('Make a payment')
|
|
|
|
});
|
2020-03-10 14:01:33 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +00:00
|
|
|
showSMSDialog(params) {
|
2019-03-29 06:29:09 +00:00
|
|
|
const address = this.ticket.address;
|
2020-02-21 07:37:37 +00:00
|
|
|
const client = this.ticket.client;
|
2020-04-30 10:48:52 +00:00
|
|
|
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-03-29 06:29:09 +00:00
|
|
|
}
|
2019-04-12 11:54:31 +00:00
|
|
|
|
2020-04-30 10:48:52 +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
|
|
|
}
|
|
|
|
|
2020-04-30 10:48:52 +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() {
|
2020-04-30 10:48:52 +00:00
|
|
|
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: 'salesPerson',
|
|
|
|
scope: {
|
|
|
|
fields: ['userFk'],
|
|
|
|
include: {
|
|
|
|
relation: 'user',
|
|
|
|
scope: {
|
|
|
|
fields: ['nickname']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'state',
|
|
|
|
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
|
|
|
}
|
2018-08-30 06:50:03 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 09:50:04 +00:00
|
|
|
ngModule.vnComponent('vnTicketDescriptor', {
|
2018-08-30 06:50:03 +00:00
|
|
|
template: require('./index.html'),
|
2020-04-25 09:50:04 +00:00
|
|
|
controller: Controller,
|
2018-08-30 06:50:03 +00:00
|
|
|
bindings: {
|
2019-02-04 11:24:47 +00:00
|
|
|
ticket: '<',
|
|
|
|
cardReload: '&'
|
2020-04-25 09:50:04 +00:00
|
|
|
}
|
2018-08-30 06:50:03 +00:00
|
|
|
});
|