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
|
|
|
}
|
|
|
|
|
2021-10-04 08:19:53 +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',
|
2022-07-01 07:15:07 +00:00
|
|
|
},
|
|
|
|
{
|
2020-11-09 13:52:25 +00:00
|
|
|
relation: 'client',
|
|
|
|
scope: {
|
|
|
|
fields: [
|
|
|
|
'salesPersonFk',
|
|
|
|
'name',
|
|
|
|
'isActive',
|
|
|
|
'isFreezed',
|
|
|
|
'isTaxDataChecked',
|
|
|
|
'credit',
|
|
|
|
'email',
|
|
|
|
'phone',
|
2022-11-15 10:01:00 +00:00
|
|
|
'mobile',
|
2022-11-23 07:55:44 +00:00
|
|
|
'hasElectronicInvoice',
|
2020-11-09 13:52:25 +00:00
|
|
|
],
|
|
|
|
include: {
|
|
|
|
relation: 'salesPersonUser',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'name']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-07-01 07:15:07 +00:00
|
|
|
{
|
|
|
|
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.isTicketEditable();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-10-27 06:46:22 +00:00
|
|
|
transferClient() {
|
2023-07-20 08:19:03 +00:00
|
|
|
const ticket = this.ticket;
|
2023-07-21 06:28:19 +00:00
|
|
|
const clientFk = ticket.client.id;
|
2022-10-27 06:46:22 +00:00
|
|
|
|
2023-07-21 06:28:19 +00:00
|
|
|
this.$http.patch(`Tickets/${ticket.id}/transferClient`, {clientFk})
|
2023-07-20 13:15:33 +00:00
|
|
|
.then(() => {
|
2022-10-27 06:46:22 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
this.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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!'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-19 10:59:32 +00:00
|
|
|
showPdfDeliveryNote(type) {
|
|
|
|
this.vnReport.show(`tickets/${this.id}/delivery-note-pdf`, {
|
2021-10-01 10:41:31 +00:00
|
|
|
recipientId: this.ticket.client.id,
|
2022-09-19 10:59:32 +00:00
|
|
|
type: type
|
2021-10-01 10:41:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-07 08:04:50 +00:00
|
|
|
sendPdfDeliveryNote($data) {
|
2023-01-12 14:16:38 +00:00
|
|
|
let query = `tickets/${this.id}/delivery-note-email`;
|
2023-05-18 12:12:46 +00:00
|
|
|
if (this.hasDocuwareFile) query = `docuwares/delivery-note-email`;
|
2023-01-12 14:16:38 +00:00
|
|
|
|
|
|
|
return this.vnEmail.send(query, {
|
2023-05-18 12:12:46 +00:00
|
|
|
id: this.id,
|
2020-11-09 13:52:25 +00:00
|
|
|
recipientId: this.ticket.client.id,
|
2022-09-19 10:59:32 +00:00
|
|
|
recipient: $data.email
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showCsvDeliveryNote() {
|
2022-10-03 06:28:47 +00:00
|
|
|
this.vnReport.show(`tickets/${this.id}/delivery-note-csv`, {
|
|
|
|
recipientId: this.ticket.client.id
|
2021-10-01 10:41:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-07 08:04:50 +00:00
|
|
|
sendCsvDeliveryNote($data) {
|
2022-10-03 06:28:47 +00:00
|
|
|
return this.vnEmail.send(`tickets/${this.id}/delivery-note-csv-email`, {
|
2021-10-01 10:41:31 +00:00
|
|
|
recipientId: this.ticket.client.id,
|
2022-10-03 06:28:47 +00:00
|
|
|
recipient: $data.email
|
2020-11-09 13:52:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteTicket() {
|
|
|
|
return this.$http.post(`Tickets/${this.id}/setDeleted`)
|
|
|
|
.then(() => this.reload())
|
|
|
|
.then(() => {
|
2022-01-20 10:06:15 +00:00
|
|
|
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;
|
2023-01-16 14:18:24 +00:00
|
|
|
const now = Date.vnNew();
|
2020-11-09 13:52:25 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-23 14:15:40 +00:00
|
|
|
sendChangesSms() {
|
2022-11-24 14:04:15 +00:00
|
|
|
return this.$http.get(`TicketLogs/${this.id}/getChanges`)
|
|
|
|
.then(res => {
|
|
|
|
const params = {
|
|
|
|
ticketId: this.id,
|
|
|
|
created: this.ticket.updated,
|
|
|
|
changes: res.data
|
|
|
|
};
|
|
|
|
this.showSMSDialog({message: this.$t('Send changes', params)});
|
|
|
|
});
|
2022-11-23 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2022-11-22 06:59:18 +00:00
|
|
|
|
2020-11-09 13:52:25 +00:00
|
|
|
this.$.sms.open();
|
|
|
|
}
|
|
|
|
|
2023-07-05 13:20:51 +00:00
|
|
|
makeInvoice(force) {
|
|
|
|
if (this.ticket.address.incotermsFk && !this.ticket.weight && !force)
|
|
|
|
return this.$.withoutWeightConfirmation.show();
|
2022-11-15 09:37:12 +00:00
|
|
|
|
|
|
|
const client = this.ticket.client;
|
2022-11-23 07:55:44 +00:00
|
|
|
if (client.hasElectronicInvoice) {
|
2022-11-15 09:37:12 +00:00
|
|
|
this.$http.post(`NotificationQueues`, {
|
2022-12-20 13:21:01 +00:00
|
|
|
notificationFk: 'invoice-electronic',
|
2022-11-15 09:37:12 +00:00
|
|
|
authorFk: client.id,
|
2022-12-20 13:21:01 +00:00
|
|
|
params: JSON.stringify(
|
|
|
|
{
|
|
|
|
'name': client.name,
|
|
|
|
'email': client.email,
|
|
|
|
'ticketId': this.id,
|
|
|
|
'url': window.location.href
|
|
|
|
})
|
2022-12-16 09:36:18 +00:00
|
|
|
}).then(() => {
|
2022-11-15 10:01:00 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Invoice sent'));
|
2022-11-15 09:37:12 +00:00
|
|
|
});
|
2022-11-08 11:26:01 +00:00
|
|
|
}
|
|
|
|
|
2023-07-13 08:19:12 +00:00
|
|
|
return this.$http.post(`Tickets/invoiceTickets`, {ticketsIds: [this.id]})
|
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`)
|
2021-10-01 12:31:42 +00:00
|
|
|
.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!')));
|
|
|
|
}
|
2022-04-04 11:26:53 +00:00
|
|
|
|
2023-05-23 13:06:38 +00:00
|
|
|
refund(withWarehouse) {
|
|
|
|
const params = {ticketsIds: [this.id], withWarehouse: withWarehouse};
|
2022-07-14 11:40:50 +00:00
|
|
|
const query = 'Tickets/refund';
|
2023-05-23 13:06:38 +00:00
|
|
|
return 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});
|
|
|
|
});
|
2022-04-04 11:26:53 +00:00
|
|
|
}
|
2022-11-25 08:59:02 +00:00
|
|
|
|
|
|
|
onSmsSend(sms) {
|
|
|
|
return this.$http.post(`Tickets/${this.id}/sendSms`, sms)
|
|
|
|
.then(() => this.vnApp.showSuccess(this.$t('SMS sent')));
|
|
|
|
}
|
2023-01-09 14:11:53 +00:00
|
|
|
|
|
|
|
hasDocuware() {
|
2023-01-13 12:33:59 +00:00
|
|
|
this.$http.post(`Docuwares/${this.id}/checkFile`, {fileCabinet: 'deliveryNote', signed: true})
|
2023-01-09 14:11:53 +00:00
|
|
|
.then(res => {
|
|
|
|
this.hasDocuwareFile = res.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-13 12:33:59 +00:00
|
|
|
uploadDocuware(force) {
|
|
|
|
if (!force)
|
|
|
|
return this.$.pdfToTablet.show();
|
|
|
|
|
2023-06-12 13:20:46 +00:00
|
|
|
return this.$http.post(`Docuwares/upload`, {fileCabinet: 'deliveryNote', ticketIds: [this.id]})
|
2023-01-11 14:19:09 +00:00
|
|
|
.then(() => {
|
2023-02-09 09:26:55 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('PDF sent!'));
|
2023-01-11 14:19:09 +00:00
|
|
|
});
|
2023-01-09 14:11:53 +00:00
|
|
|
}
|
2023-05-30 13:34:11 +00:00
|
|
|
|
|
|
|
docuwareDownload() {
|
|
|
|
this.vnFile.download(`api/Ticket/${this.ticket.id}/docuwareDownload`);
|
|
|
|
}
|
2023-07-21 10:40:59 +00:00
|
|
|
|
2023-04-26 11:49:08 +00:00
|
|
|
setTicketWeight(weight) {
|
|
|
|
return this.$http.patch(`Tickets/${this.ticket.id}`, {weight})
|
|
|
|
.then(() => {
|
|
|
|
this.$.setTicketWeight.hide();
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
this.reload();
|
|
|
|
});
|
|
|
|
}
|
2020-11-09 13:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|