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

286 lines
7.8 KiB
JavaScript
Raw Normal View History

2020-11-09 13:52:25 +00:00
import ngModule from '../module';
import Section from 'salix/components/section';
import './style.scss';
class Controller extends Section {
constructor($element, $, vnReport, vnEmail) {
super($element, $);
this.vnReport = vnReport;
this.vnEmail = vnEmail;
}
get ticketId() {
return this._ticketId;
}
set ticketId(value) {
this._ticketId = value;
this.id = value;
}
get id() {
return this._id;
}
set id(value) {
this._id = value;
2020-11-10 09:38:25 +00:00
if (!value) return;
this.loadData().then(() => {
2021-05-03 10:09:12 +00:00
if (this.$params.sendSMS) {
this.showSMSDialog({
message: this.$params.message
});
}
2020-11-10 09:38:25 +00:00
});
2020-11-09 13:52:25 +00:00
}
get isInvoiced() {
return this.ticket.refFk !== null;
}
get isTicketModule() {
return this.$state.getCurrentPath()[1].state.name === 'ticket';
}
get hasInvoicing() {
return this.aclService.hasAny(['invoicing']);
}
2020-11-09 13:52:25 +00:00
loadData() {
const filter = {
include: [{
relation: 'address',
}, {
relation: 'client',
scope: {
fields: [
'salesPersonFk',
'name',
'isActive',
'isFreezed',
'isTaxDataChecked',
'credit',
'email',
'phone',
'mobile'
],
include: {
relation: 'salesPersonUser',
scope: {
fields: ['id', 'name']
}
}
}
},
{relation: 'ship'},
2021-01-22 06:26:29 +00:00
{relation: 'stowaway'},
{relation: 'invoiceOut'}]
2020-11-09 13:52:25 +00:00
};
return this.$http.get(`Tickets/${this.ticketId}`, {filter})
.then(res => this.ticket = res.data)
.then(() => {
this.canStowaway();
this.isTicketEditable();
this.hasDocuware();
2020-11-09 13:52:25 +00:00
});
}
reload() {
2020-11-10 09:38:25 +00:00
return this.loadData().then(() => {
if (this.parentReload)
this.parentReload();
});
2020-11-09 13:52:25 +00:00
}
isTicketEditable() {
if (!this.ticket) return;
this.$http.get(`Tickets/${this.id}/isEditable`).then(res => {
this.isEditable = res.data;
});
}
addTurn(day) {
const 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!'));
});
}
2021-10-07 08:04:50 +00:00
showPdfDeliveryNote() {
2020-11-09 13:52:25 +00:00
this.vnReport.show('delivery-note', {
recipientId: this.ticket.client.id,
ticketId: this.id,
});
}
2022-02-16 13:57:47 +00:00
hasDocuware() {
const params = {
fileCabinet: 'deliveryClient',
dialog: 'findTicket'
};
this.$http.post(`Docuwares/${this.id}/checkFile`, params)
2022-02-28 12:37:44 +00:00
.then(res => this.hasDocuwareFile = res.data);
2022-02-16 13:57:47 +00:00
}
2021-10-07 08:04:50 +00:00
showCsvDeliveryNote() {
this.vnReport.showCsv('delivery-note', {
recipientId: this.ticket.client.id,
ticketId: this.id,
});
}
2021-10-07 08:04:50 +00:00
sendPdfDeliveryNote($data) {
2020-11-09 13:52:25 +00:00
return this.vnEmail.send('delivery-note', {
recipientId: this.ticket.client.id,
recipient: $data.email,
ticketId: this.id
});
}
2021-10-07 08:04:50 +00:00
sendCsvDeliveryNote($data) {
return this.vnEmail.sendCsv('delivery-note', {
recipientId: this.ticket.client.id,
recipient: $data.email,
2020-11-09 13:52:25 +00:00
ticketId: this.id
});
}
deleteTicket() {
return this.$http.post(`Tickets/${this.id}/setDeleted`)
.then(() => this.reload())
.then(() => {
const isInsideTicket = this.$state.current.name.startsWith('ticket');
if (isInsideTicket)
this.$state.go('ticket.index');
2020-11-09 13:52:25 +00:00
this.vnApp.showSuccess(this.$t('Ticket deleted. You can undo this action within the first hour'));
});
}
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);
}
restoreTicket() {
return this.$http.post(`Tickets/${this.id}/restore`)
.then(() => this.reload())
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
}
showChangeShipped() {
this.newShipped = this.ticket.shipped;
this.$.changeShippedDialog.show();
}
changeShipped() {
const data = {shipped: this.newShipped};
return this.$http.post(`Tickets/${this.id}/updateEditableTicket`, data)
.then(() => this.reload())
.then(() => this.vnApp.showSuccess(this.$t('Shipped hour updated')));
}
sendImportSms() {
const params = {
ticketId: this.id,
created: this.ticket.updated
};
this.showSMSDialog({
2021-04-08 11:39:11 +00:00
message: this.$t('Minimum is needed', params)
2020-11-09 13:52:25 +00:00
});
}
sendPaymentSms() {
this.showSMSDialog({
2021-04-08 11:39:11 +00:00
message: this.$t('Make a payment')
2020-11-09 13:52:25 +00:00
});
}
showSMSDialog(params) {
const address = this.ticket.address;
const client = this.ticket.client;
const phone = this.$params.phone
|| address.mobile
|| address.phone
|| client.mobile
|| client.phone;
this.newSMS = Object.assign({
ticketId: this.id,
destinationFk: this.ticket.clientFk,
destination: phone
}, params);
this.$.sms.open();
}
canStowaway() {
this.canShowStowaway = false;
if (!this.isTicketModule || !this.ticket) return;
this.$http.get(`Tickets/${this.id}/canHaveStowaway`)
.then(res => this.canShowStowaway = !!res.data);
}
get canDeleteStowaway() {
if (!this.ticket || !this.isTicketModule)
return false;
return this.ticket.stowaway || this.ticket.ship;
}
deleteStowaway() {
return this.$http.post(`Tickets/${this.id}/deleteStowaway`)
.then(() => this.reload())
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
}
makeInvoice() {
2021-07-01 12:03:28 +00:00
const params = {ticketsIds: [this.id]};
return this.$http.post(`Tickets/makeInvoice`, params)
2020-11-09 13:52:25 +00:00
.then(() => this.reload())
.then(() => this.vnApp.showSuccess(this.$t('Ticket invoiced')));
}
2021-10-07 11:36:23 +00:00
createPdfInvoice() {
2020-11-09 13:52:25 +00:00
const invoiceId = this.ticket.invoiceOut.id;
2021-03-15 12:43:22 +00:00
return this.$http.post(`InvoiceOuts/${invoiceId}/createPdf`)
.then(() => this.reload())
2020-11-09 13:52:25 +00:00
.then(() => {
const snackbarMessage = this.$t(
2021-03-15 12:43:22 +00:00
`The invoice PDF document has been regenerated`);
2020-11-09 13:52:25 +00:00
this.vnApp.showSuccess(snackbarMessage);
});
}
recalculateComponents() {
return this.$http.post(`Tickets/${this.id}/recalculateComponents`)
.then(() => this.reload())
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
}
}
Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail'];
ngModule.vnComponent('vnTicketDescriptorMenu', {
template: require('./index.html'),
controller: Controller,
bindings: {
ticketId: '<',
2020-11-10 09:38:25 +00:00
parentReload: '&'
2020-11-09 13:52:25 +00:00
}
});