From cfdeb387a1dc3d165e3fe44dc6c8fb0b440e2d53 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 4 Apr 2019 13:06:41 +0200 Subject: [PATCH] #1241 routes.tickets --- db/changes/10002-lent/00-ticket.sql | 11 ++ front/core/components/table/style.scss | 1 - .../route/back/methods/route/getTickets.js | 4 +- .../route/back/methods/route/guessPriority.js | 28 +++++ modules/route/back/models/route.js | 1 + modules/route/front/index.js | 1 + modules/route/front/routes.json | 42 ++++--- modules/route/front/tickets/index.html | 114 ++++++++++++++++++ modules/route/front/tickets/index.js | 111 +++++++++++++++++ modules/route/front/tickets/locale/es.yml | 5 + modules/route/front/tickets/style.scss | 6 + 11 files changed, 302 insertions(+), 22 deletions(-) create mode 100644 db/changes/10002-lent/00-ticket.sql create mode 100644 modules/route/back/methods/route/guessPriority.js create mode 100644 modules/route/front/tickets/index.html create mode 100644 modules/route/front/tickets/index.js create mode 100644 modules/route/front/tickets/locale/es.yml create mode 100644 modules/route/front/tickets/style.scss diff --git a/db/changes/10002-lent/00-ticket.sql b/db/changes/10002-lent/00-ticket.sql new file mode 100644 index 000000000..b98550328 --- /dev/null +++ b/db/changes/10002-lent/00-ticket.sql @@ -0,0 +1,11 @@ +DROP TRIGGER IF EXISTS `vn2008`.`TicketsAfterUpdate`; + +DELIMITER $$ +USE `vn2008`$$ +CREATE DEFINER=`root`@`%` TRIGGER `vn2008`.`TicketsAfterUpdate` + AFTER UPDATE ON `Tickets` FOR EACH ROW +BEGIN + + CALL stock.queueAdd ('ticket', NEW.Id_Ticket, OLD.Id_Ticket); +END$$ +DELIMITER ; diff --git a/front/core/components/table/style.scss b/front/core/components/table/style.scss index 33e2ee06a..0322c6f43 100644 --- a/front/core/components/table/style.scss +++ b/front/core/components/table/style.scss @@ -170,7 +170,6 @@ vn-table { } } vn-textfield { - max-width: 100px; float: right; margin: 0!important; } diff --git a/modules/route/back/methods/route/getTickets.js b/modules/route/back/methods/route/getTickets.js index 2394c3441..cbe7db9f8 100644 --- a/modules/route/back/methods/route/getTickets.js +++ b/modules/route/back/methods/route/getTickets.js @@ -25,7 +25,7 @@ module.exports = Self => { include: [ {relation: 'ticket', scope: { - fields: ['id', 'packages', 'warehouseFk', 'nickname', 'clientFk', 'priority'], + fields: ['id', 'packages', 'warehouseFk', 'nickname', 'clientFk', 'priority', 'addressFk'], order: 'priority', include: [ { @@ -56,7 +56,7 @@ module.exports = Self => { { relation: 'address', scope: { - fields: ['id', 'street', 'postcode', 'city'], + fields: ['id', 'street', 'postalCode', 'city'], } }, diff --git a/modules/route/back/methods/route/guessPriority.js b/modules/route/back/methods/route/guessPriority.js new file mode 100644 index 000000000..324cf9182 --- /dev/null +++ b/modules/route/back/methods/route/guessPriority.js @@ -0,0 +1,28 @@ +module.exports = Self => { + Self.remoteMethod('guessPriority', { + description: 'Changes automatically the priority of the tickets in a route', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'Guess priority', + http: {source: 'path'} + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/:id/guessPriority`, + verb: 'GET' + } + }); + + Self.guessPriority = async id => { + let query = `CALL vn.routeGuessPriority(?)`; + + let options = [id]; + return await Self.rawSql(query, options); + }; +}; diff --git a/modules/route/back/models/route.js b/modules/route/back/models/route.js index d5febe23e..e3ebabb68 100644 --- a/modules/route/back/models/route.js +++ b/modules/route/back/models/route.js @@ -1,4 +1,5 @@ module.exports = Self => { require('../methods/route/summary')(Self); require('../methods/route/getTickets')(Self); + require('../methods/route/guessPriority')(Self); }; diff --git a/modules/route/front/index.js b/modules/route/front/index.js index af8a0b69b..a6530c6b8 100644 --- a/modules/route/front/index.js +++ b/modules/route/front/index.js @@ -8,3 +8,4 @@ import './card'; import './create'; import './basic-data'; import './log'; +import './tickets'; diff --git a/modules/route/front/routes.json b/modules/route/front/routes.json index 9aae910e3..635324267 100644 --- a/modules/route/front/routes.json +++ b/modules/route/front/routes.json @@ -6,8 +6,8 @@ "dependencies": ["client", "worker", "ticket"], "menu": [ {"state": "route.card.basicData", "icon": "settings"}, - {"state": "route.card.log", "icon": "history"} - ], + {"state": "route.card.log", "icon": "history"}, + {"state": "route.card.tickets", "icon": "icon-ticket"}], "routes": [ { "url": "/route", @@ -16,26 +16,22 @@ "component": "ui-view", "description": "Routes", "acl": ["employee"] - }, - { + }, { "url": "/index?q", "state": "route.index", "component": "vn-route-index", "description": "Routes" - }, - { + }, { "url": "/create", "state": "route.create", "component": "vn-route-create", "description": "New route" - }, - { + }, { "url": "/:id", "state": "route.card", "abstract": true, "component": "vn-route-card" - }, - { + }, { "url": "/summary", "state": "route.card.summary", "component": "vn-route-summary", @@ -43,8 +39,7 @@ "params": { "route": "$ctrl.route" } - }, - { + }, { "url": "/basic-data", "state": "route.card.basicData", "component": "vn-route-basic-data", @@ -53,12 +48,21 @@ "route": "$ctrl.route" }, "acl": ["delivery"] - }, { - "url" : "/log", - "state": "route.card.log", - "component": "vn-route-log", - "description": "Log", - "acl": ["delivery"] - } + }, { + "url" : "/log", + "state": "route.card.log", + "component": "vn-route-log", + "description": "Log", + "acl": ["delivery"] + }, { + "url": "/tickets", + "state": "route.card.tickets", + "component": "vn-route-tickets", + "description": "Tickets", + "params": { + "route": "$ctrl.route" + }, + "acl": ["delivery"] + } ] } \ No newline at end of file diff --git a/modules/route/front/tickets/index.html b/modules/route/front/tickets/index.html new file mode 100644 index 000000000..df04086e4 --- /dev/null +++ b/modules/route/front/tickets/index.html @@ -0,0 +1,114 @@ + + +
+ + + + + + + + + + + + + + + + + Order + Ticket id + Alias + Packages + + Warehouse + PC + Street + + + + + + + + + + + + + + + + + {{ticket.id | zeroFill:6}} + + + + + {{ticket.nickname}} + + + {{ticket.packages}} + {{ticket.volume}} + {{ticket.warehouse.name}} + {{ticket.client.postcode}} + {{ticket.client.street}} + + + + + + + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/modules/route/front/tickets/index.js b/modules/route/front/tickets/index.js new file mode 100644 index 000000000..2b3aa26f1 --- /dev/null +++ b/modules/route/front/tickets/index.js @@ -0,0 +1,111 @@ +import ngModule from '../module'; +import './style.scss'; + +class Controller { + constructor($stateParams, $, $translate, $http, vnApp) { + this.$translate = $translate; + this.$stateParams = $stateParams; + this.$ = $; + this.$http = $http; + this.vnApp = vnApp; + } + + get isChecked() { + if (this.tickets) { + for (let instance of this.tickets) + if (instance.checked) return true; + } + + return false; + } + + getHighestPriority() { + let max = 0; + this.$.model.data.forEach(tag => { + if (tag.priority > max) + max = tag.priority; + }); + return max + 1; + } + + setPriority(id, priority) { + let params = {priority: priority}; + let query = `/api/Tickets/${id}/`; + this.$http.patch(query, params).then(() => { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.$.model.refresh(); + }); + } + + getCheckedLines() { + let lines = []; + let data = this.tickets; + if (data) { + for (let i = 0; i < data.length; i++) { + if (data[i].checked) + lines.push(data[i]); + } + } + return lines; + } + + goToBuscaman() { + // firstAddress is a temporal variable, will be replaced with #1298 + let firstAddress = `46460 Av Espioca 100-46460 Silla`; + let addresses = firstAddress; + + let lines = this.getCheckedLines(); + + let url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr='; + lines.forEach(line => { + addresses = addresses + '+to:' + line.address.postalCode + ' ' + line.address.street + '-' + line.address.postalCode + ' ' + line.address.city; + }); + + window.open(url + addresses, '_blank'); + } + + showDeleteConfirm(ticket) { + this.selectedTicket = ticket; + this.$.confirm.show(); + } + + deleteFromRoute(response) { + if (response === 'ACCEPT') { + let params = {routeFk: null}; + let query = `/api/Tickets/${this.selectedTicket}/`; + this.$http.patch(query, params).then(() => { + this.vnApp.showSuccess(this.$translate.instant('Ticket deleted from route')); + this.$.model.refresh(); + }); + } + } + + guessPriority() { + let query = `/api/Routes/${this.$stateParams.id}/guessPriority/`; + 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(); + } +} + +Controller.$inject = ['$stateParams', '$scope', '$translate', '$http', 'vnApp']; + +ngModule.component('vnRouteTickets', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/route/front/tickets/locale/es.yml b/modules/route/front/tickets/locale/es.yml new file mode 100644 index 000000000..2081a738e --- /dev/null +++ b/modules/route/front/tickets/locale/es.yml @@ -0,0 +1,5 @@ +Remove ticket: Borrar ticket +Open buscaman: Abrir buscaman +Ticket deleted from route: Ticket borrado de la ruta +Order changed: Orden cambiado +Delete ticket from route?: ¿Borrar ticket de la ruta? diff --git a/modules/route/front/tickets/style.scss b/modules/route/front/tickets/style.scss new file mode 100644 index 000000000..55a57fd24 --- /dev/null +++ b/modules/route/front/tickets/style.scss @@ -0,0 +1,6 @@ +@import "variables"; + +vn-route-tickets form{ + margin: 0 auto; + max-width: $width-large; +} \ No newline at end of file