2018-08-30 06:50:03 +00:00
|
|
|
import ngModule from '../module';
|
2019-11-12 07:51:50 +00:00
|
|
|
import Component from 'core/lib/component';
|
2018-08-30 06:50:03 +00:00
|
|
|
|
2019-11-12 07:51:50 +00:00
|
|
|
class Controller extends Component {
|
2019-11-13 07:09:54 +00:00
|
|
|
constructor($element, $, aclService, $httpParamSerializer) {
|
2019-11-12 07:51:50 +00:00
|
|
|
super($element, $);
|
2019-04-12 11:54:31 +00:00
|
|
|
this.aclService = aclService;
|
2019-11-13 07:09:54 +00:00
|
|
|
this.$httpParamSerializer = $httpParamSerializer;
|
2018-11-08 14:20:42 +00:00
|
|
|
this.moreOptions = [
|
2020-02-13 07:31:29 +00:00
|
|
|
{
|
|
|
|
name: 'Add turn',
|
|
|
|
acl: 'buyer',
|
|
|
|
callback: this.showAddTurnDialog
|
|
|
|
},
|
2019-04-26 06:52:43 +00:00
|
|
|
{name: 'Show Delivery Note', callback: this.showDeliveryNote},
|
2019-09-06 09:06:44 +00:00
|
|
|
{name: 'Send Delivery Note', callback: this.confirmDeliveryNote},
|
2019-04-26 06:52:43 +00:00
|
|
|
{name: 'Delete ticket', callback: this.showDeleteTicketDialog},
|
|
|
|
{name: 'Change shipped hour', callback: this.showChangeShipped},
|
|
|
|
{name: 'Send SMS', callback: this.showSMSDialog},
|
|
|
|
{
|
|
|
|
name: 'Add stowaway',
|
|
|
|
callback: this.showAddStowaway,
|
2019-09-06 07:47:58 +00:00
|
|
|
show: () => this.canShowStowaway
|
2019-04-26 06:52:43 +00:00
|
|
|
},
|
|
|
|
{
|
2019-12-17 12:25:30 +00:00
|
|
|
name: 'Delete stowaway',
|
2019-12-17 07:38:36 +00:00
|
|
|
callback: this.showDeleteStowaway,
|
|
|
|
show: () => this.shouldShowDeleteStowaway()
|
2019-04-26 06:52:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Make invoice',
|
|
|
|
acl: 'invoicing',
|
|
|
|
callback: this.showMakeInvoiceDialog,
|
|
|
|
show: () => !this.hasInvoice()
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Regenerate invoice',
|
|
|
|
acl: 'invoicing',
|
|
|
|
callback: this.showRegenerateInvoiceDialog,
|
|
|
|
show: () => this.hasInvoice()
|
|
|
|
},
|
2019-11-20 05:53:37 +00:00
|
|
|
{
|
|
|
|
name: 'Recalculate components',
|
|
|
|
callback: this.comfirmRecalculateComponents,
|
|
|
|
show: () => this.isEditable
|
|
|
|
},
|
2018-11-08 14:20:42 +00:00
|
|
|
];
|
2018-08-30 06:50:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 07:38:36 +00:00
|
|
|
get ticket() {
|
|
|
|
return this._ticket;
|
|
|
|
}
|
|
|
|
|
|
|
|
set ticket(value) {
|
|
|
|
this._ticket = value;
|
|
|
|
|
|
|
|
if (!value) return;
|
|
|
|
|
|
|
|
if (this.$params.sendSMS)
|
|
|
|
this.showSMSDialog();
|
|
|
|
|
|
|
|
this.canStowaway();
|
|
|
|
|
|
|
|
let links = {
|
|
|
|
btnOne: {
|
|
|
|
icon: 'person',
|
|
|
|
state: `client.card.summary({id: ${value.clientFk}})`,
|
|
|
|
tooltip: 'Client card'
|
|
|
|
}};
|
|
|
|
|
|
|
|
if (value.stowaway) {
|
|
|
|
links.btnTwo = {
|
|
|
|
icon: 'icon-stowaway',
|
|
|
|
state: `ticket.card.summary({id: ${value.stowaway.shipFk}})`,
|
|
|
|
tooltip: 'Ship stowaways'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value.ship) {
|
|
|
|
links.btnThree = {
|
|
|
|
icon: 'icon-stowaway',
|
|
|
|
state: `ticket.card.summary({id: ${value.ship.id}})`,
|
|
|
|
tooltip: 'Stowaway'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this._quicklinks = links;
|
|
|
|
}
|
|
|
|
|
|
|
|
get quicklinks() {
|
|
|
|
return this._quicklinks;
|
|
|
|
}
|
|
|
|
|
|
|
|
set quicklinks(value = {}) {
|
|
|
|
this._quicklinks = Object.assign(value, this._quicklinks);
|
|
|
|
}
|
|
|
|
|
2019-01-21 07:45:02 +00:00
|
|
|
showChangeShipped() {
|
|
|
|
if (!this.isEditable) {
|
2019-11-14 13:19:39 +00:00
|
|
|
this.vnApp.showError(this.$translate.instant(`This ticket can't be modified`));
|
2019-01-21 07:45:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-04-29 05:48:59 +00:00
|
|
|
this.newShipped = this.ticket.shipped;
|
2019-11-12 07:51:50 +00:00
|
|
|
this.$.changeShippedDialog.show();
|
2019-01-21 07:45:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
changeShipped(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response === 'accept') {
|
2019-05-03 10:23:57 +00:00
|
|
|
let data = {shipped: this.newShipped};
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `Tickets/${this.ticket.id}/updateEditableTicket`;
|
2019-05-03 10:23:57 +00:00
|
|
|
this.$http.post(query, data).then(() => {
|
2019-01-21 07:45:02 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Shipped hour updated'));
|
2019-03-26 11:25:06 +00:00
|
|
|
this.cardReload();
|
2019-01-21 07:45:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 11:24:47 +00:00
|
|
|
isTicketModule() {
|
|
|
|
let path = this.$state.getCurrentPath();
|
2019-09-06 07:47:58 +00:00
|
|
|
const isTicket = path[1].state.name === 'ticket';
|
|
|
|
if (isTicket)
|
2019-02-04 11:24:47 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-08 14:20:42 +00:00
|
|
|
onMoreChange(callback) {
|
|
|
|
callback.call(this);
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:36:13 +00:00
|
|
|
goToTicket(ticketID) {
|
2019-03-20 11:23:38 +00:00
|
|
|
this.$state.go('ticket.card.sale', {id: ticketID}, {absolute: true});
|
2019-01-18 12:36:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onMoreOpen() {
|
2019-04-15 12:34:33 +00:00
|
|
|
let options = this.moreOptions.filter(option => {
|
2019-04-15 12:37:12 +00:00
|
|
|
const hasShowProperty = Object.hasOwnProperty.call(option, 'show');
|
|
|
|
const hasAclProperty = Object.hasOwnProperty.call(option, 'acl');
|
|
|
|
const hasAcl = !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl]));
|
2019-04-12 11:54:31 +00:00
|
|
|
|
2019-04-15 12:37:12 +00:00
|
|
|
return (!hasShowProperty || option.show === true ||
|
|
|
|
typeof option.show === 'function' && option.show()) && hasAcl;
|
2019-01-18 12:36:13 +00:00
|
|
|
});
|
2019-11-12 07:51:50 +00:00
|
|
|
this.$.moreButton.data = options;
|
2019-01-18 12:36:13 +00:00
|
|
|
}
|
|
|
|
|
2018-11-08 14:20:42 +00:00
|
|
|
get isEditable() {
|
|
|
|
try {
|
|
|
|
return !this.ticket.tracking.state.alertLevel;
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
showAddTurnDialog() {
|
2019-11-12 07:51:50 +00:00
|
|
|
this.$.addTurn.show();
|
2018-11-08 14:20:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addTurn(day) {
|
|
|
|
let params = {ticketFk: this.ticket.id, weekDay: day};
|
2019-10-24 22:53:53 +00:00
|
|
|
this.$http.patch(`TicketWeeklies`, params).then(() => {
|
2019-11-12 07:51:50 +00:00
|
|
|
this.$.addTurn.hide();
|
2018-11-08 14:20:42 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showDeleteTicketDialog() {
|
|
|
|
if (!this.isEditable) {
|
|
|
|
this.vnApp.showError(this.$translate.instant('This ticket cant be deleted'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-12 07:51:50 +00:00
|
|
|
this.$.deleteConfirmation.show();
|
2018-11-08 14:20:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteTicket(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response === 'accept') {
|
2019-10-24 22:53:53 +00:00
|
|
|
const query = `Tickets/${this.ticket.id}/setDeleted`;
|
2019-09-03 11:27:02 +00:00
|
|
|
this.$http.post(query).then(() => {
|
2018-11-08 14:20:42 +00:00
|
|
|
this.$state.go('ticket.index');
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Ticket deleted'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-04-10 08:43:11 +00:00
|
|
|
|
2019-12-17 07:38:36 +00:00
|
|
|
canStowaway() {
|
|
|
|
if (!this.isTicketModule()) return;
|
2019-01-18 12:36:13 +00:00
|
|
|
|
2019-12-17 07:38:36 +00:00
|
|
|
this.$http.get(`Tickets/${this.ticket.id}/canHaveStowaway`).then(response => {
|
|
|
|
if (response.data === true)
|
|
|
|
return this.canShowStowaway = true;
|
2019-01-18 12:36:13 +00:00
|
|
|
|
2019-12-17 07:38:36 +00:00
|
|
|
return this.canShowStowaway = false;
|
|
|
|
});
|
2018-08-30 06:50:03 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 07:38:36 +00:00
|
|
|
shouldShowDeleteStowaway() {
|
|
|
|
if (!this._ticket || !this.isTicketModule())
|
|
|
|
return false;
|
2019-01-21 07:45:02 +00:00
|
|
|
|
2019-12-17 07:38:36 +00:00
|
|
|
return this._ticket.stowaway || this._ticket.ship;
|
|
|
|
}
|
2019-01-21 07:45:02 +00:00
|
|
|
|
2019-12-17 07:38:36 +00:00
|
|
|
showAddStowaway() {
|
|
|
|
this.$.addStowaway.show();
|
2018-09-04 09:49:00 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 07:38:36 +00:00
|
|
|
showDeleteStowaway() {
|
|
|
|
this.$.deleteStowaway.show();
|
2018-09-04 09:49:00 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 07:38:36 +00:00
|
|
|
deleteStowaway() {
|
|
|
|
const query = `Tickets/${this.ticket.id}/deleteStowaway`;
|
|
|
|
this.$http.post(query).then(res => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
this.cardReload();
|
|
|
|
});
|
2018-09-04 09:49:00 +00:00
|
|
|
}
|
2019-02-11 09:06:26 +00:00
|
|
|
|
|
|
|
showDeliveryNote() {
|
2019-11-06 07:20:45 +00:00
|
|
|
const params = {
|
|
|
|
clientId: this.ticket.client.id,
|
|
|
|
ticketId: this.ticket.id
|
|
|
|
};
|
|
|
|
const serializedParams = this.$httpParamSerializer(params);
|
|
|
|
let url = `api/report/delivery-note?${serializedParams}`;
|
2019-02-11 09:06:26 +00:00
|
|
|
window.open(url);
|
|
|
|
}
|
2019-03-29 06:29:09 +00:00
|
|
|
|
2019-11-06 08:32:54 +00:00
|
|
|
sendDeliveryNote() {
|
|
|
|
const params = {
|
|
|
|
recipient: this.ticket.client.email,
|
|
|
|
clientId: this.ticket.client.id,
|
|
|
|
ticketId: this.ticket.id
|
|
|
|
};
|
|
|
|
const serializedParams = this.$httpParamSerializer(params);
|
|
|
|
this.$http.get(`email/delivery-note?${serializedParams}`).then(
|
|
|
|
() => this.vnApp.showMessage(this.$translate.instant('Notification sent!'))
|
|
|
|
);
|
2019-11-06 07:20:45 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 06:29:09 +00:00
|
|
|
showSMSDialog() {
|
|
|
|
const address = this.ticket.address;
|
2019-11-21 13:00:27 +00:00
|
|
|
const phone = this.$params.phone || address.mobile;
|
|
|
|
const message = this.$params.message || this.$translate.instant('SMSPayment');
|
2019-03-29 06:29:09 +00:00
|
|
|
this.newSMS = {
|
2019-04-16 05:59:12 +00:00
|
|
|
destinationFk: this.ticket.clientFk,
|
2019-11-21 13:00:27 +00:00
|
|
|
destination: phone,
|
|
|
|
message: message
|
2019-03-29 06:29:09 +00:00
|
|
|
};
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows an invoice confirmation
|
|
|
|
*/
|
2019-04-26 06:52:43 +00:00
|
|
|
showMakeInvoiceDialog() {
|
2019-11-12 07:51:50 +00:00
|
|
|
this.$.makeInvoiceConfirmation.show();
|
2019-04-12 11:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes an invoice
|
|
|
|
* from current ticket
|
|
|
|
*
|
|
|
|
* @param {String} response - Response result
|
|
|
|
*/
|
2019-04-26 06:52:43 +00:00
|
|
|
makeInvoice(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response === 'accept') {
|
2019-10-24 22:53:53 +00:00
|
|
|
const query = `Tickets/${this.ticket.id}/makeInvoice`;
|
2019-04-12 11:54:31 +00:00
|
|
|
this.$http.post(query).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Ticket invoiced'));
|
|
|
|
this.$state.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-04-26 06:52:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows an invoice confirmation
|
|
|
|
*/
|
|
|
|
showRegenerateInvoiceDialog() {
|
2019-11-12 07:51:50 +00:00
|
|
|
this.$.regenerateInvoiceConfirmation.show();
|
2019-04-26 06:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends an invoice to a regeneration queue
|
|
|
|
* for the current ticket
|
|
|
|
*
|
|
|
|
* @param {String} response - Response result
|
|
|
|
*/
|
|
|
|
regenerateInvoice(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response === 'accept') {
|
2019-04-26 06:52:43 +00:00
|
|
|
const invoiceId = this.ticket.invoiceOut.id;
|
2019-10-24 22:53:53 +00:00
|
|
|
const query = `InvoiceOuts/${invoiceId}/regenerate`;
|
2019-04-26 06:52:43 +00:00
|
|
|
this.$http.post(query).then(() => {
|
|
|
|
const snackbarMessage = this.$translate.instant(
|
|
|
|
`Invoice sent for a regeneration, will be available in a few minutes`);
|
|
|
|
this.vnApp.showSuccess(snackbarMessage);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if the current ticket
|
|
|
|
* is already invoiced
|
|
|
|
* @return {Boolean} - True if invoiced
|
|
|
|
*/
|
|
|
|
hasInvoice() {
|
|
|
|
return this.ticket.refFk !== null;
|
|
|
|
}
|
2019-09-06 09:06:44 +00:00
|
|
|
|
2019-11-20 05:53:37 +00:00
|
|
|
/**
|
|
|
|
* Shows a delivery-note send confirmation
|
|
|
|
*/
|
2019-09-06 09:06:44 +00:00
|
|
|
confirmDeliveryNote() {
|
2019-11-12 07:51:50 +00:00
|
|
|
this.$.confirmDeliveryNote.show();
|
2019-09-06 09:06:44 +00:00
|
|
|
}
|
2019-11-20 05:53:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows an invoice confirmation
|
|
|
|
*/
|
|
|
|
comfirmRecalculateComponents() {
|
|
|
|
this.$.recalculateComponentsConfirmation.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
recalculateComponents() {
|
|
|
|
const query = `Tickets/${this.ticket.id}/recalculateComponents`;
|
|
|
|
this.$http.post(query).then(res => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
2018-08-30 06:50:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-13 07:09:54 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', 'aclService', '$httpParamSerializer'];
|
2018-08-30 06:50:03 +00:00
|
|
|
|
|
|
|
ngModule.component('vnTicketDescriptor', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
bindings: {
|
2019-02-04 11:24:47 +00:00
|
|
|
ticket: '<',
|
|
|
|
cardReload: '&'
|
2018-08-30 06:50:03 +00:00
|
|
|
},
|
|
|
|
controller: Controller
|
|
|
|
});
|