#1241 routes.tickets
gitea/salix/dev This commit looks good Details

This commit is contained in:
Gerard 2019-04-04 13:06:41 +02:00
parent 93bca3b3f0
commit cfdeb387a1
11 changed files with 302 additions and 22 deletions

View File

@ -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 ;

View File

@ -170,7 +170,6 @@ vn-table {
}
}
vn-textfield {
max-width: 100px;
float: right;
margin: 0!important;
}

View File

@ -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'],
}
},

View File

@ -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);
};
};

View File

@ -1,4 +1,5 @@
module.exports = Self => {
require('../methods/route/summary')(Self);
require('../methods/route/getTickets')(Self);
require('../methods/route/guessPriority')(Self);
};

View File

@ -8,3 +8,4 @@ import './card';
import './create';
import './basic-data';
import './log';
import './tickets';

View File

@ -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",
@ -59,6 +54,15 @@
"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"]
}
]
}

View File

@ -0,0 +1,114 @@
<vn-crud-model
vn-id="model"
url="/api/Routes/{{$ctrl.$stateParams.id}}/getTickets"
order="priority ASC"
data="$ctrl.tickets"
auto-load="true">
</vn-crud-model>
<form name="form">
<vn-card pad-large>
<vn-tool-bar margin-small-bottom >
<vn-button
label="Varita"
ng-click="$ctrl.guessPriority()"
vn-tooltip="Change ticket state to 'Ok'">
</vn-button>
<vn-button
disabled="!$ctrl.isChecked"
ng-click="$ctrl.goToBuscaman()"
vn-tooltip="Open buscaman"
tooltip-position="up"
icon="icon-buscaman">
</vn-button>
</vn-tool-bar>
<vn-icon-button
vn-tooltip="Load more"
ng-click="$ctrl.goToBuscaman()">
</vn-icon-button>
<vn-table model="model" auto-load="false">
<vn-thead>
<vn-tr>
<vn-th shrink>
<vn-multi-check
data="$ctrl.tickets">
</vn-multi-check>
</vn-th>
<vn-th>Order</vn-th>
<vn-th number>Ticket id</vn-th>
<vn-th>Alias</vn-th>
<vn-th number shrink>Packages</vn-th>
<vn-th shrink></vn-th>
<vn-th shrink>Warehouse</vn-th>
<vn-th shrink>PC</vn-th>
<vn-th>Street</vn-th>
<vn-th shrink></vn-th>
<vn-th shrink></vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="ticket in $ctrl.tickets">
<vn-td shrink>
<vn-check
field="ticket.checked">
</vn-check>
</vn-td>
<vn-td>
<vn-textfield
vn-tab-index="-1"
type="number"
on-change="$ctrl.setPriority(ticket.id, ticket.priority)"
model="ticket.priority"
rule="ticket.priority">
</vn-textfield>
</vn-td>
<vn-td number>
<span
ng-click="$ctrl.showTicketDescriptor($event, ticket.id)"
class="link">
{{ticket.id | zeroFill:6}}
</span>
</vn-td>
<vn-td>
<span
ng-click="$ctrl.showClientDescriptor($event, ticket.clientFk)"
class="link">
{{ticket.nickname}}
</span>
</vn-td>
<vn-td number shrink>{{ticket.packages}}</vn-td>
<vn-td shrink>{{ticket.volume}}</vn-td>
<vn-td shrink>{{ticket.warehouse.name}}</vn-td>
<vn-td shrink>{{ticket.client.postcode}}</vn-td>
<vn-td expand title="{{ticket.client.street}}">{{ticket.client.street}}</vn-td>
<vn-td shrink>
<vn-icon
ng-if="ticket.notes.length"
vn-tooltip="{{ticket.notes[0].description}}"
icon="insert_drive_file">
</vn-icon>
</vn-td>
<vn-td>
<vn-icon-button
vn-tooltip="Remove ticket"
icon="delete"
ng-click="$ctrl.showDeleteConfirm(ticket.id)"
tabindex="-1">
</vn-icon-button>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-card>
</form>
<vn-ticket-descriptor-popover
vn-id="ticketDescriptor">
</vn-ticket-descriptor-popover>
<vn-client-descriptor-popover
vn-id="clientDescriptor">
</vn-client-descriptor-popover>
<vn-confirm
vn-id="confirm"
question="Delete ticket from route?"
on-response="$ctrl.deleteFromRoute(response)">
</vn-confirm>

View File

@ -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
});

View File

@ -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?

View File

@ -0,0 +1,6 @@
@import "variables";
vn-route-tickets form{
margin: 0 auto;
max-width: $width-large;
}