2018-08-30 06:50:03 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
|
|
|
|
class Controller {
|
2019-04-12 11:54:31 +00:00
|
|
|
constructor($state, $scope, $http, vnApp, $translate, aclService) {
|
2018-08-30 06:50:03 +00:00
|
|
|
this.$scope = $scope;
|
2018-09-04 09:49:00 +00:00
|
|
|
this.$state = $state;
|
2018-11-08 14:20:42 +00:00
|
|
|
this.$http = $http;
|
|
|
|
this.vnApp = vnApp;
|
|
|
|
this.$translate = $translate;
|
2019-04-12 11:54:31 +00:00
|
|
|
this.aclService = aclService;
|
2018-11-08 14:20:42 +00:00
|
|
|
this.moreOptions = [
|
2019-04-12 11:54:31 +00:00
|
|
|
{callback: this.showAddTurnDialog, name: 'Add turn'},
|
2019-02-04 11:24:47 +00:00
|
|
|
{callback: this.showAddStowaway, name: 'Add stowaway', show: () => this.isTicketModule()},
|
2019-01-21 07:45:02 +00:00
|
|
|
{callback: this.showRemoveStowaway, name: 'Remove stowaway', show: () => this.shouldShowRemoveStowaway()},
|
2019-04-12 11:54:31 +00:00
|
|
|
{callback: this.showInvoiceOutMakeDialog, name: 'Make invoice', acl: 'invoicing'},
|
|
|
|
{callback: this.showDeliveryNote, name: 'Show Delivery Note'},
|
|
|
|
{callback: this.showDeleteTicketDialog, name: 'Delete ticket'},
|
|
|
|
{callback: this.showChangeShipped, name: 'Change shipped hour'},
|
|
|
|
{callback: this.showSMSDialog, name: 'Send SMS'},
|
|
|
|
{callback: this.openRptRoute, name: 'Show pallet report'}
|
2018-11-08 14:20:42 +00:00
|
|
|
];
|
2018-08-30 06:50:03 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 07:45:02 +00:00
|
|
|
showChangeShipped() {
|
|
|
|
if (!this.isEditable) {
|
|
|
|
this.vnApp.showError(this.$translate.instant('This ticket can\'t be modified'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.newShipped = new Date(this.ticket.shipped);
|
|
|
|
this.$scope.changeShippedDialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
changeShipped(response) {
|
|
|
|
if (response === 'ACCEPT') {
|
|
|
|
let params = {shipped: this.newShipped};
|
|
|
|
this.$http.patch(`/ticket/api/Tickets/${this.ticket.id}/`, params).then(() => {
|
|
|
|
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();
|
|
|
|
if (path[1].state.name === 'ticket')
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:36:13 +00:00
|
|
|
shouldShowRemoveStowaway() {
|
2019-02-04 11:24:47 +00:00
|
|
|
if (!this._ticket || !this.isTicketModule())
|
2019-01-18 12:36:13 +00:00
|
|
|
return false;
|
2019-02-01 11:11:56 +00:00
|
|
|
|
|
|
|
return (this._ticket.stowaway || (this._ticket.ship && this._ticket.ship.length > 0));
|
2019-01-18 12:36:13 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
});
|
|
|
|
this.$scope.moreButton.data = options;
|
|
|
|
}
|
|
|
|
|
2018-11-08 14:20:42 +00:00
|
|
|
get isEditable() {
|
|
|
|
try {
|
|
|
|
return !this.ticket.tracking.state.alertLevel;
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
showAddTurnDialog() {
|
|
|
|
this.$scope.addTurn.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
addTurn(day) {
|
|
|
|
let params = {ticketFk: this.ticket.id, weekDay: day};
|
|
|
|
this.$http.patch(`/ticket/api/TicketWeeklies`, params).then(() => {
|
|
|
|
this.$scope.addTurn.hide();
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showDeleteTicketDialog() {
|
|
|
|
if (!this.isEditable) {
|
|
|
|
this.vnApp.showError(this.$translate.instant('This ticket cant be deleted'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$scope.deleteConfirmation.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteTicket(response) {
|
|
|
|
if (response === 'ACCEPT') {
|
|
|
|
let params = {id: this.ticket.id};
|
|
|
|
this.$http.post(`/ticket/api/Tickets/deleted`, params).then(() => {
|
|
|
|
this.$state.go('ticket.index');
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Ticket deleted'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-10 08:43:11 +00:00
|
|
|
openRptRoute() {
|
|
|
|
let url = `/api/report/rpt-route?routeFk=${this.ticket.routeFk}`;
|
|
|
|
window.open(url);
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:36:13 +00:00
|
|
|
showAddStowaway() {
|
|
|
|
this.$scope.addStowaway.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
showRemoveStowaway() {
|
|
|
|
this.$scope.removeStowaway.show();
|
|
|
|
}
|
|
|
|
|
2018-09-04 09:49:00 +00:00
|
|
|
get ticket() {
|
|
|
|
return this._ticket;
|
2018-08-30 06:50:03 +00:00
|
|
|
}
|
|
|
|
|
2018-09-04 09:49:00 +00:00
|
|
|
set ticket(value) {
|
|
|
|
this._ticket = value;
|
|
|
|
|
|
|
|
if (!value) return;
|
|
|
|
|
2019-01-18 12:36:13 +00:00
|
|
|
let links = {
|
2018-09-04 09:49:00 +00:00
|
|
|
btnOne: {
|
|
|
|
icon: 'person',
|
|
|
|
state: `client.card.summary({id: ${value.clientFk}})`,
|
|
|
|
tooltip: 'Client card'
|
2019-01-18 12:36:13 +00:00
|
|
|
}};
|
2019-04-01 07:48:22 +00:00
|
|
|
|
2019-01-18 12:36:13 +00:00
|
|
|
if (value.stowaway) {
|
|
|
|
links.btnTwo = {
|
2019-02-01 10:42:31 +00:00
|
|
|
icon: 'icon-stowaway',
|
2019-01-18 12:36:13 +00:00
|
|
|
state: `ticket.card.summary({id: ${value.stowaway.shipFk}})`,
|
|
|
|
tooltip: 'Ship'
|
|
|
|
};
|
|
|
|
}
|
2019-01-21 07:45:02 +00:00
|
|
|
|
|
|
|
if (value.ship && value.ship.length == 1) {
|
2019-01-18 12:36:13 +00:00
|
|
|
links.btnThree = {
|
2019-02-01 10:42:31 +00:00
|
|
|
icon: 'icon-stowaway',
|
2019-01-18 12:36:13 +00:00
|
|
|
state: `ticket.card.summary({id: ${value.ship[0].id}})`,
|
|
|
|
tooltip: 'Stowaway'
|
|
|
|
};
|
2019-01-21 07:45:02 +00:00
|
|
|
} else if (value.ship && value.ship.length > 1)
|
2019-01-18 12:36:13 +00:00
|
|
|
this.shipStowaways = value.ship;
|
2019-01-21 07:45:02 +00:00
|
|
|
|
2019-01-18 12:36:13 +00:00
|
|
|
this._quicklinks = links;
|
2018-09-04 09:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set quicklinks(value = {}) {
|
|
|
|
this._quicklinks = Object.assign(value, this._quicklinks);
|
|
|
|
}
|
|
|
|
|
|
|
|
get quicklinks() {
|
|
|
|
return this._quicklinks;
|
|
|
|
}
|
2019-02-11 09:06:26 +00:00
|
|
|
|
|
|
|
showDeliveryNote() {
|
|
|
|
let url = `/api/report/rpt-delivery-note?ticketFk=${this.ticket.id}`;
|
|
|
|
window.open(url);
|
|
|
|
}
|
2019-03-29 06:29:09 +00:00
|
|
|
|
|
|
|
showSMSDialog() {
|
|
|
|
const address = this.ticket.address;
|
|
|
|
this.newSMS = {
|
2019-04-16 05:59:12 +00:00
|
|
|
destinationFk: this.ticket.clientFk,
|
|
|
|
destination: address.mobile || null,
|
2019-03-29 06:29:09 +00:00
|
|
|
message: this.$translate.instant('SMSPayment')
|
|
|
|
};
|
|
|
|
this.$scope.sms.open();
|
|
|
|
}
|
2019-04-12 11:54:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows an invoice confirmation
|
|
|
|
*/
|
|
|
|
showInvoiceOutMakeDialog() {
|
|
|
|
this.$scope.invoiceMakeConfirmation.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes an invoice
|
|
|
|
* from current ticket
|
|
|
|
*
|
|
|
|
* @param {String} response - Response result
|
|
|
|
*/
|
2019-04-23 06:58:49 +00:00
|
|
|
makeInvoiceOut(response) {
|
2019-04-12 11:54:31 +00:00
|
|
|
if (response === 'ACCEPT') {
|
|
|
|
const query = `/ticket/api/Tickets/${this.ticket.id}/makeInvoice`;
|
|
|
|
this.$http.post(query).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Ticket invoiced'));
|
|
|
|
this.$state.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-08-30 06:50:03 +00:00
|
|
|
}
|
|
|
|
|
2019-04-12 11:54:31 +00:00
|
|
|
Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate', 'aclService'];
|
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
|
|
|
|
});
|