223 lines
6.6 KiB
JavaScript
223 lines
6.6 KiB
JavaScript
import ngModule from '../module';
|
|
|
|
class Controller {
|
|
constructor($state, $scope, $http, vnApp, $translate, aclService) {
|
|
this.$scope = $scope;
|
|
this.$state = $state;
|
|
this.$http = $http;
|
|
this.vnApp = vnApp;
|
|
this.$translate = $translate;
|
|
this.aclService = aclService;
|
|
this.moreOptions = [
|
|
{callback: this.showAddTurnDialog, name: 'Add turn'},
|
|
{callback: this.showAddStowaway, name: 'Add stowaway', show: () => this.isTicketModule()},
|
|
{callback: this.showRemoveStowaway, name: 'Remove stowaway', show: () => this.shouldShowRemoveStowaway()},
|
|
{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'}
|
|
];
|
|
}
|
|
|
|
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'));
|
|
this.cardReload();
|
|
});
|
|
}
|
|
}
|
|
|
|
isTicketModule() {
|
|
let path = this.$state.getCurrentPath();
|
|
if (path[1].state.name === 'ticket')
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
shouldShowRemoveStowaway() {
|
|
if (!this._ticket || !this.isTicketModule())
|
|
return false;
|
|
|
|
return (this._ticket.stowaway || (this._ticket.ship && this._ticket.ship.length > 0));
|
|
}
|
|
|
|
onMoreChange(callback) {
|
|
callback.call(this);
|
|
}
|
|
|
|
goToTicket(ticketID) {
|
|
this.$state.go('ticket.card.sale', {id: ticketID}, {absolute: true});
|
|
}
|
|
|
|
onMoreOpen() {
|
|
let options = this.moreOptions.filter(option => {
|
|
const hasShowProperty = Object.hasOwnProperty.call(option, 'show');
|
|
const hasAclProperty = Object.hasOwnProperty.call(option, 'acl');
|
|
const hasAcl = !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl]));
|
|
|
|
return (!hasShowProperty || option.show === true ||
|
|
typeof option.show === 'function' && option.show()) && hasAcl;
|
|
});
|
|
this.$scope.moreButton.data = options;
|
|
}
|
|
|
|
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'));
|
|
});
|
|
}
|
|
}
|
|
|
|
openRptRoute() {
|
|
let url = `/api/report/rpt-route?routeFk=${this.ticket.routeFk}`;
|
|
window.open(url);
|
|
}
|
|
|
|
showAddStowaway() {
|
|
this.$scope.addStowaway.show();
|
|
}
|
|
|
|
showRemoveStowaway() {
|
|
this.$scope.removeStowaway.show();
|
|
}
|
|
|
|
get ticket() {
|
|
return this._ticket;
|
|
}
|
|
|
|
set ticket(value) {
|
|
this._ticket = value;
|
|
|
|
if (!value) return;
|
|
|
|
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'
|
|
};
|
|
}
|
|
|
|
if (value.ship && value.ship.length == 1) {
|
|
links.btnThree = {
|
|
icon: 'icon-stowaway',
|
|
state: `ticket.card.summary({id: ${value.ship[0].id}})`,
|
|
tooltip: 'Stowaway'
|
|
};
|
|
} else if (value.ship && value.ship.length > 1)
|
|
this.shipStowaways = value.ship;
|
|
|
|
this._quicklinks = links;
|
|
}
|
|
|
|
set quicklinks(value = {}) {
|
|
this._quicklinks = Object.assign(value, this._quicklinks);
|
|
}
|
|
|
|
get quicklinks() {
|
|
return this._quicklinks;
|
|
}
|
|
|
|
showDeliveryNote() {
|
|
let url = `/api/report/rpt-delivery-note?ticketFk=${this.ticket.id}`;
|
|
window.open(url);
|
|
}
|
|
|
|
showSMSDialog() {
|
|
const address = this.ticket.address;
|
|
this.newSMS = {
|
|
destinationFk: this.ticket.clientFk,
|
|
destination: address.mobile || null,
|
|
message: this.$translate.instant('SMSPayment')
|
|
};
|
|
this.$scope.sms.open();
|
|
}
|
|
|
|
/**
|
|
* Shows an invoice confirmation
|
|
*/
|
|
showInvoiceOutMakeDialog() {
|
|
this.$scope.invoiceMakeConfirmation.show();
|
|
}
|
|
|
|
/**
|
|
* Makes an invoice
|
|
* from current ticket
|
|
*
|
|
* @param {String} response - Response result
|
|
*/
|
|
makeInvoiceOut(response) {
|
|
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();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate', 'aclService'];
|
|
|
|
ngModule.component('vnTicketDescriptor', {
|
|
template: require('./index.html'),
|
|
bindings: {
|
|
ticket: '<',
|
|
cardReload: '&'
|
|
},
|
|
controller: Controller
|
|
});
|