2019-04-04 11:06:41 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
2019-10-23 07:25:28 +00:00
|
|
|
constructor($stateParams, $scope, $translate, $http, vnApp, $filter) {
|
2019-04-04 11:06:41 +00:00
|
|
|
this.$translate = $translate;
|
|
|
|
this.$stateParams = $stateParams;
|
2019-10-23 07:25:28 +00:00
|
|
|
this.$ = $scope;
|
2019-04-04 11:06:41 +00:00
|
|
|
this.$http = $http;
|
|
|
|
this.vnApp = vnApp;
|
2019-10-23 07:25:28 +00:00
|
|
|
this.$filter = $filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
set route(value) {
|
|
|
|
this._route = value;
|
|
|
|
if (value)
|
|
|
|
this.buildPossibleTicketsFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
get route() {
|
|
|
|
return this._route;
|
2019-04-04 11:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get isChecked() {
|
|
|
|
if (this.tickets) {
|
|
|
|
for (let instance of this.tickets)
|
|
|
|
if (instance.checked) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-23 07:25:28 +00:00
|
|
|
buildPossibleTicketsFilter() {
|
|
|
|
let minDate = new Date(this.route.finished);
|
|
|
|
minDate.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
let maxDate = new Date(this.route.finished);
|
|
|
|
maxDate.setHours(23, 59, 59, 59);
|
|
|
|
|
|
|
|
this.possibleTicketsFilter = {
|
|
|
|
where: {
|
|
|
|
zoneFk: this.route.zoneFk,
|
|
|
|
routeFk: null,
|
|
|
|
landed: {between: [minDate, maxDate]},
|
|
|
|
},
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'warehouse',
|
|
|
|
scope: {
|
|
|
|
fields: ['name']
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
relation: 'address'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-04 11:06:41 +00:00
|
|
|
getHighestPriority() {
|
2019-10-23 07:25:28 +00:00
|
|
|
let highestPriority = Math.max(...this.$.model.data.map(tag => {
|
|
|
|
return tag.priority;
|
|
|
|
}));
|
|
|
|
return highestPriority + 1;
|
2019-04-04 11:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setPriority(id, priority) {
|
|
|
|
let params = {priority: priority};
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `Tickets/${id}/`;
|
2019-04-04 11:06:41 +00:00
|
|
|
this.$http.patch(query, params).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
this.$.model.refresh();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-23 07:25:28 +00:00
|
|
|
getSelectedItems(items) {
|
|
|
|
const selectedItems = [];
|
|
|
|
|
|
|
|
if (items) {
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
if (items[i].checked)
|
|
|
|
selectedItems.push(items[i]);
|
2019-04-04 11:06:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-23 07:25:28 +00:00
|
|
|
return selectedItems;
|
2019-04-04 11:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
goToBuscaman() {
|
2019-12-10 11:42:14 +00:00
|
|
|
let query = `Routes/${this.route.vehicleFk}/getDeliveryPoint`;
|
|
|
|
let deliveryPointAddress;
|
|
|
|
let addresses;
|
|
|
|
|
|
|
|
this.$http.get(query).then(response => {
|
|
|
|
deliveryPointAddress = response.data;
|
|
|
|
}).then(() => {
|
|
|
|
addresses = deliveryPointAddress;
|
|
|
|
let lines = this.getSelectedItems(this.tickets);
|
|
|
|
|
|
|
|
let url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=';
|
|
|
|
lines.forEach(line => {
|
|
|
|
addresses = addresses + '+to:' + line.address.postalCode + ' ' + line.address.city + ' ' + line.address.street;
|
|
|
|
});
|
|
|
|
|
|
|
|
window.open(url + addresses, '_blank');
|
2019-04-04 11:06:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-10 11:42:14 +00:00
|
|
|
|
2019-10-23 07:25:28 +00:00
|
|
|
showDeleteConfirm(id) {
|
|
|
|
this.selectedTicket = id;
|
2019-04-04 11:06:41 +00:00
|
|
|
this.$.confirm.show();
|
|
|
|
}
|
|
|
|
|
2019-06-06 11:50:12 +00:00
|
|
|
removeTicketFromRoute(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response === 'accept') {
|
2019-04-04 11:06:41 +00:00
|
|
|
let params = {routeFk: null};
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `Tickets/${this.selectedTicket}/`;
|
2019-04-04 11:06:41 +00:00
|
|
|
this.$http.patch(query, params).then(() => {
|
2019-06-06 11:50:12 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Ticket removed from route'));
|
|
|
|
this.updateVolume();
|
2019-04-04 11:06:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 11:50:12 +00:00
|
|
|
updateVolume() {
|
2019-10-24 22:53:53 +00:00
|
|
|
let url = `Routes/${this.$stateParams.id}/updateVolume`;
|
2019-06-06 11:50:12 +00:00
|
|
|
this.$http.post(url).then(() => {
|
|
|
|
this.card.reload();
|
|
|
|
this.$.model.refresh();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-04 11:06:41 +00:00
|
|
|
guessPriority() {
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = `Routes/${this.$stateParams.id}/guessPriority/`;
|
2019-04-04 11:06:41 +00:00
|
|
|
this.$http.get(query).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Order changed'));
|
|
|
|
this.$.model.refresh();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showTicketDescriptor(event, ticketFk) {
|
|
|
|
this.$.ticketDescriptor.ticketFk = ticketFk;
|
|
|
|
this.$.ticketDescriptor.parent = event.target;
|
|
|
|
this.$.ticketDescriptor.show();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
showClientDescriptor(event, clientFk) {
|
|
|
|
this.$.clientDescriptor.clientFk = clientFk;
|
|
|
|
this.$.clientDescriptor.parent = event.target;
|
|
|
|
this.$.clientDescriptor.show();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2019-10-23 07:25:28 +00:00
|
|
|
|
|
|
|
openPossibleTicketsDialog() {
|
|
|
|
this.$.possibleTicketsModel.refresh();
|
|
|
|
this.$.possibleTicketsDialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
setTicketsRoute(response) {
|
2019-10-30 15:57:14 +00:00
|
|
|
if (response === 'accept') {
|
2019-10-23 07:25:28 +00:00
|
|
|
let tickets = this.getSelectedItems(this.possibleTickets);
|
|
|
|
|
|
|
|
for (let i = 0; i < tickets.length; i++) {
|
|
|
|
delete tickets[i].checked;
|
|
|
|
tickets[i].routeFk = this.route.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.$.possibleTicketsModel.save().then(() => {
|
|
|
|
this.$.model.data = this.$.model.data.concat(tickets);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
2019-04-04 11:06:41 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 07:25:28 +00:00
|
|
|
Controller.$inject = ['$stateParams', '$scope', '$translate', '$http', 'vnApp', '$filter'];
|
2019-04-04 11:06:41 +00:00
|
|
|
|
|
|
|
ngModule.component('vnRouteTickets', {
|
|
|
|
template: require('./index.html'),
|
2019-10-23 07:25:28 +00:00
|
|
|
controller: Controller,
|
2019-06-06 11:50:12 +00:00
|
|
|
require: {
|
|
|
|
card: '^vnRouteCard'
|
|
|
|
},
|
2019-10-23 07:25:28 +00:00
|
|
|
bindings: {
|
|
|
|
route: '<'
|
|
|
|
}
|
2019-04-04 11:06:41 +00:00
|
|
|
});
|