2019-04-04 11:06:41 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-06 12:06:01 +00:00
|
|
|
import Section from 'salix/components/section';
|
2019-04-04 11:06:41 +00:00
|
|
|
import './style.scss';
|
2021-05-05 11:36:54 +00:00
|
|
|
import UserError from 'core/lib/user-error';
|
2019-04-04 11:06:41 +00:00
|
|
|
|
2020-03-06 12:06:01 +00:00
|
|
|
class Controller extends Section {
|
|
|
|
get route() {
|
|
|
|
return this._route;
|
|
|
|
}
|
|
|
|
|
2019-10-23 07:25:28 +00:00
|
|
|
set route(value) {
|
|
|
|
this._route = value;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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(() => {
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2019-04-04 11:06:41 +00:00
|
|
|
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() {
|
2021-05-05 11:36:54 +00:00
|
|
|
if (!this.route.vehicleFk)
|
|
|
|
throw new UserError(`The route doesn't have a vehicle`);
|
2019-12-10 11:42:14 +00:00
|
|
|
let query = `Routes/${this.route.vehicleFk}/getDeliveryPoint`;
|
|
|
|
|
|
|
|
this.$http.get(query).then(response => {
|
2021-05-05 11:36:54 +00:00
|
|
|
if (!response.data)
|
2021-05-10 08:46:17 +00:00
|
|
|
throw new UserError(`The route's vehicle doesn't have a departing warehouse`);
|
2021-05-05 11:36:54 +00:00
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}).then(address => {
|
|
|
|
let addresses;
|
|
|
|
if (address) addresses = address;
|
2019-12-10 11:42:14 +00:00
|
|
|
let lines = this.getSelectedItems(this.tickets);
|
|
|
|
|
|
|
|
let url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=';
|
|
|
|
lines.forEach(line => {
|
2021-05-14 17:21:04 +00:00
|
|
|
addresses = addresses + '+to:' + line.postalCode + ' ' + line.city + ' ' + line.street;
|
2019-12-10 11:42:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
window.open(url + addresses, '_blank');
|
2019-04-04 11:06:41 +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();
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:21:04 +00:00
|
|
|
removeTicketFromRoute($index) {
|
2020-07-29 08:47:48 +00:00
|
|
|
let params = {routeFk: null};
|
|
|
|
let query = `Tickets/${this.selectedTicket}/`;
|
|
|
|
this.$http.patch(query, params).then(() => {
|
2021-05-14 17:21:04 +00:00
|
|
|
this.$.model.remove($index);
|
2020-07-29 08:47:48 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Ticket removed from route'));
|
|
|
|
this.updateVolume();
|
|
|
|
});
|
2019-04-04 11:06:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 11:50:12 +00:00
|
|
|
updateVolume() {
|
2020-03-06 12:06:01 +00:00
|
|
|
let url = `Routes/${this.$params.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() {
|
2020-03-06 12:06:01 +00:00
|
|
|
let query = `Routes/${this.$params.id}/guessPriority/`;
|
2019-04-04 11:06:41 +00:00
|
|
|
this.$http.get(query).then(() => {
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Order changed'));
|
2019-04-04 11:06:41 +00:00
|
|
|
this.$.model.refresh();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-23 07:25:28 +00:00
|
|
|
openPossibleTicketsDialog() {
|
|
|
|
this.$.possibleTicketsModel.refresh();
|
|
|
|
this.$.possibleTicketsDialog.show();
|
|
|
|
}
|
|
|
|
|
2020-07-29 08:47:48 +00:00
|
|
|
setTicketsRoute() {
|
|
|
|
let tickets = this.getSelectedItems(this.possibleTickets);
|
|
|
|
if (tickets.length === 0) return;
|
2021-03-22 15:13:12 +00:00
|
|
|
|
|
|
|
const updates = [];
|
|
|
|
|
|
|
|
for (let ticket of tickets) {
|
|
|
|
delete ticket.checked;
|
|
|
|
const update = {
|
|
|
|
where: {id: ticket.id},
|
|
|
|
data: {routeFk: this.route.id}
|
|
|
|
};
|
|
|
|
|
|
|
|
updates.push(update);
|
2019-10-23 07:25:28 +00:00
|
|
|
}
|
2020-07-29 08:47:48 +00:00
|
|
|
|
2021-03-22 15:13:12 +00:00
|
|
|
const data = {creates: [], updates: updates, deletes: []};
|
|
|
|
|
|
|
|
return this.$http.post(`Tickets/crud`, data)
|
|
|
|
.then(() => {
|
|
|
|
this.$.model.data = this.$.model.data.concat(tickets);
|
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2021-06-24 07:54:07 +00:00
|
|
|
this.updateVolume();
|
2021-11-22 11:52:02 +00:00
|
|
|
this.$.possibleTicketsDialog.hide();
|
2021-03-22 15:13:12 +00:00
|
|
|
});
|
2019-10-23 07:25:28 +00:00
|
|
|
}
|
2020-03-06 12:06:01 +00:00
|
|
|
|
|
|
|
onDrop($event) {
|
|
|
|
const ticketId = $event.dataTransfer.getData('Text');
|
|
|
|
|
|
|
|
if (isNaN(ticketId)) {
|
|
|
|
const regexp = new RegExp(/\/ticket\/([0-9]+)\//i);
|
|
|
|
const matches = ticketId.match(regexp);
|
|
|
|
|
|
|
|
if (matches && matches.length)
|
|
|
|
this.insert(matches[1]);
|
|
|
|
else
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showError(this.$t('Ticket not found'));
|
2020-03-06 12:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isNaN(ticketId))
|
|
|
|
this.insert(ticketId);
|
|
|
|
}
|
|
|
|
|
2020-12-21 13:48:47 +00:00
|
|
|
insert(ticketId) {
|
|
|
|
ticketId = parseInt(ticketId);
|
2020-11-20 11:12:06 +00:00
|
|
|
|
2020-12-21 13:48:47 +00:00
|
|
|
const query = `Routes/${this.route.id}/insertTicket`;
|
|
|
|
return this.$http.patch(query, {ticketId}).then(() => {
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2021-06-24 07:54:07 +00:00
|
|
|
this.updateVolume();
|
2020-03-06 12:06:01 +00:00
|
|
|
}).catch(error => {
|
|
|
|
if (error.status == 404)
|
2020-07-23 14:07:08 +00:00
|
|
|
return this.vnApp.showError(this.$t('Ticket not found'));
|
2020-03-06 12:06:01 +00:00
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
}
|
2019-04-04 11:06:41 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnRouteTickets', {
|
2019-04-04 11:06:41 +00:00
|
|
|
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
|
|
|
});
|