reoute tickets order columns + endpoint refactor
This commit is contained in:
parent
d4eedc69e1
commit
457d23dc16
|
@ -410,11 +410,12 @@ INSERT INTO `vn`.`clientObservation`(`id`, `clientFk`, `workerFk`, `text`, `crea
|
|||
|
||||
INSERT INTO `vn`.`observationType`(`id`,`description`, `code`)
|
||||
VALUES
|
||||
(1, 'observation one', 'observation one'),
|
||||
(2, 'observation two', 'observation two'),
|
||||
(3, 'observation three', 'observation three'),
|
||||
(4, 'comercial', 'salesPerson'),
|
||||
(5, 'delivery', 'delivery');
|
||||
(1, 'Sacador', 'itemPicker'),
|
||||
(2, 'Encajador', 'packager'),
|
||||
(3, 'Repartidor', 'delivery'),
|
||||
(4, 'Comercial', 'salesPerson'),
|
||||
(5, 'Administración', 'administrative'),
|
||||
(6, 'Peso Aduana', 'weight');
|
||||
|
||||
INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`)
|
||||
VALUES
|
||||
|
@ -607,16 +608,16 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des
|
|||
VALUES
|
||||
(1, 11, 1, 'ready'),
|
||||
(2, 2, 2, 'do it fast please'),
|
||||
(3, 3, 3, 'Faster faster fasteeeeeer!!!'),
|
||||
(4, 4, 3, 'Deliver before 8am'),
|
||||
(5, 13, 3, 'You can run from the disappointments you are trying to forget. But its only when you embrace your past that you truly move forward. Maybe I never get to go home again, but I found my way there. And I am glad I did.'),
|
||||
(6, 14, 3, 'Careful, armed warhead'),
|
||||
(3, 3, 5, 'Faster faster fasteeeeeer!!!'),
|
||||
(4, 4, 5, 'Deliver before 8am'),
|
||||
(5, 13, 5, 'You can run from the disappointments you are trying to forget. But its only when you embrace your past that you truly move forward. Maybe I never get to go home again, but I found my way there. And I am glad I did.'),
|
||||
(6, 14, 5, 'Careful, armed warhead'),
|
||||
(7, 23, 1, 'under the floor'),
|
||||
(8, 23, 2, 'wears leather and goes out at night'),
|
||||
(9, 23, 3, 'care with the dog'),
|
||||
(9, 23, 5, 'care with the dog'),
|
||||
(10, 23, 4, 'Reclama ticket: 8'),
|
||||
(11, 24, 4, 'Reclama ticket: 7'),
|
||||
(12, 11, 5, 'Delivery after 10am');
|
||||
(12, 11, 3, 'Delivery after 10am');
|
||||
|
||||
-- FIX for state hours on local, inter_afterInsert
|
||||
UPDATE vncontrol.inter SET odbc_date = DATE_ADD(CURDATE(), INTERVAL -10 SECOND);
|
||||
|
|
|
@ -1,101 +1,73 @@
|
|||
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('getTickets', {
|
||||
description: 'Return the tickets information displayed on the route module',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The route id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
accepts: [
|
||||
{
|
||||
arg: 'filter',
|
||||
type: 'object',
|
||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||
http: {source: 'query'}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/getTickets`,
|
||||
path: `/getTickets`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getTickets = async id => {
|
||||
let filter = {
|
||||
where: {id: id},
|
||||
include: [
|
||||
{relation: 'ticket',
|
||||
scope: {
|
||||
fields: ['id', 'packages', 'warehouseFk', 'nickname', 'clientFk', 'priority', 'addressFk'],
|
||||
order: 'priority',
|
||||
include: [
|
||||
{
|
||||
relation: 'ticketState',
|
||||
scope: {
|
||||
fields: ['id', 'stateFk'],
|
||||
include: [{relation: 'state'}]
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'warehouse',
|
||||
scope: {
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'notes',
|
||||
scope: {
|
||||
where: {observationTypeFk: 3}
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'address',
|
||||
scope: {
|
||||
fields: ['id', 'street', 'postalCode', 'city'],
|
||||
}
|
||||
},
|
||||
Self.getTickets = async(filter, options) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
|
||||
]
|
||||
}
|
||||
}, {
|
||||
relation: 'agencyMode',
|
||||
scope: {
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
}, {
|
||||
relation: 'worker',
|
||||
scope: {
|
||||
fields: ['id', 'userFk'],
|
||||
include: [
|
||||
{
|
||||
relation: 'user',
|
||||
scope: {
|
||||
fields: ['id', 'nickname']
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}, {
|
||||
relation: 'vehicle',
|
||||
scope: {
|
||||
fields: ['id', 'm3', 'numberPlate']
|
||||
}
|
||||
}
|
||||
],
|
||||
};
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT
|
||||
t.id,
|
||||
t.packages,
|
||||
t.warehouseFk,
|
||||
t.nickname,
|
||||
t.clientFk,
|
||||
t.priority,
|
||||
t.addressFk,
|
||||
st.code AS ticketStateCode,
|
||||
st.name AS ticketStateName,
|
||||
wh.name AS warehouseName,
|
||||
tob.description AS ticketObservation,
|
||||
a.street,
|
||||
a.postalCode,
|
||||
a.city,
|
||||
am.name AS agencyModeName,
|
||||
u.nickname AS userNickname,
|
||||
vn.ticketTotalVolume(t.id) AS volume
|
||||
FROM route r
|
||||
LEFT JOIN ticket t ON t.routeFk = r.id
|
||||
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
LEFT JOIN state st ON st.id = ts.stateFk
|
||||
LEFT JOIN warehouse wh ON wh.id = t.warehouseFk
|
||||
LEFT JOIN ticketObservation tob ON tob.ticketFk = t.id
|
||||
LEFT JOIN observationType ot ON tob.observationTypeFk = ot.id
|
||||
AND ot.code = 'delivery'
|
||||
LEFT JOIN address a ON a.id = t.addressFk
|
||||
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||
LEFT JOIN account.user u ON u.id = r.workerFk
|
||||
LEFT JOIN vehicle v ON v.id = r.vehicleFk`
|
||||
);
|
||||
|
||||
route = await Self.app.models.Route.findOne(filter);
|
||||
if (!filter.where) filter.where = {};
|
||||
|
||||
for (let i = 0; i < route.ticket().length; i++) {
|
||||
let ticket = route.ticket()[i];
|
||||
let query = `
|
||||
SELECT vn.ticketTotalVolume(?) AS m3`;
|
||||
const where = filter.where;
|
||||
where['r.id'] = filter.id;
|
||||
|
||||
let options = [ticket.id];
|
||||
let [volume] = await Self.rawSql(query, options);
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
|
||||
ticket.volume = volume.m3;
|
||||
}
|
||||
const tickets = await conn.executeStmt(stmt, options);
|
||||
|
||||
return route.ticket();
|
||||
return tickets;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -2,7 +2,8 @@ const app = require('vn-loopback/server/server');
|
|||
|
||||
describe('route getTickets()', () => {
|
||||
it('should return the tickets for a given route', async() => {
|
||||
let result = await app.models.Route.getTickets(2);
|
||||
const filter = {id: 2};
|
||||
let result = await app.models.Route.getTickets(filter);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
});
|
||||
|
|
|
@ -53,7 +53,7 @@ module.exports = Self => {
|
|||
};
|
||||
|
||||
summary.route = await Self.app.models.Route.findOne(filter);
|
||||
summary.tickets = await Self.app.models.Route.getTickets(id);
|
||||
summary.tickets = await Self.app.models.Route.getTickets({id: id});
|
||||
|
||||
return summary;
|
||||
};
|
||||
|
|
|
@ -106,9 +106,9 @@
|
|||
</vn-td>
|
||||
<vn-td number shrink>{{ticket.packages}}</vn-td>
|
||||
<vn-td shrink>{{ticket.volume}}</vn-td>
|
||||
<vn-td>{{ticket.warehouse.name}}</vn-td>
|
||||
<vn-td shrink>{{ticket.address.postalCode}}</vn-td>
|
||||
<vn-td expand title="{{ticket.address.street}}">{{ticket.address.street}}</vn-td>
|
||||
<vn-td>{{ticket.warehouseName}}</vn-td>
|
||||
<vn-td shrink>{{ticket.postalCode}}</vn-td>
|
||||
<vn-td expand title="{{ticket.address.street}}">{{ticket.street}}</vn-td>
|
||||
<vn-td shrink>
|
||||
<vn-icon
|
||||
ng-if="ticket.notes.length"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="Routes/{{$ctrl.$params.id}}/getTickets"
|
||||
url="Routes/getTickets"
|
||||
filter="{id: $ctrl.$params.id}"
|
||||
order="priority ASC"
|
||||
data="$ctrl.tickets"
|
||||
auto-load="true">
|
||||
|
@ -34,14 +35,14 @@
|
|||
model="model">
|
||||
</vn-multi-check>
|
||||
</vn-th>
|
||||
<vn-th>Order</vn-th>
|
||||
<vn-th expand>Street</vn-th>
|
||||
<vn-th>City</vn-th>
|
||||
<vn-th translate-attr="{title: 'Postcode'}" shrink>PC</vn-th>
|
||||
<vn-th expand>Client</vn-th>
|
||||
<vn-th shrink>Packages</vn-th>
|
||||
<vn-th shrink>m³</vn-th>
|
||||
<vn-th number>Ticket</vn-th>
|
||||
<vn-th field="priority">Order</vn-th>
|
||||
<vn-th field="street" expand>Street</vn-th>
|
||||
<vn-th field="city">City</vn-th>
|
||||
<vn-th field="postalCode" translate-attr="{title: 'Postcode'}" shrink>PC</vn-th>
|
||||
<vn-th field="clientFk" expand>Client</vn-th>
|
||||
<vn-th field="packages" shrink>Packages</vn-th>
|
||||
<vn-th field="volume" shrink>m³</vn-th>
|
||||
<vn-th field="id" number>Ticket</vn-th>
|
||||
<vn-th shrink></vn-th>
|
||||
<vn-th shrink></vn-th>
|
||||
</vn-tr>
|
||||
|
@ -62,9 +63,9 @@
|
|||
display-controls=true>
|
||||
</vn-input-number>
|
||||
</vn-td>
|
||||
<vn-td expand title="{{ticket.address.street}}">{{ticket.address.street}}</vn-td>
|
||||
<vn-td expand>{{ticket.address.city}}</vn-td>
|
||||
<vn-td shrink>{{ticket.address.postalCode}}</vn-td>
|
||||
<vn-td expand title="{{ticket.street}}">{{::ticket.street}}</vn-td>
|
||||
<vn-td expand>{{::ticket.city}}</vn-td>
|
||||
<vn-td shrink>{{::ticket.postalCode}}</vn-td>
|
||||
<vn-td expand>
|
||||
<span
|
||||
ng-click="clientDescriptor.show($event, ticket.clientFk)"
|
||||
|
@ -72,13 +73,13 @@
|
|||
{{ticket.nickname}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td shrink>{{ticket.packages}}</vn-td>
|
||||
<vn-td shrink>{{::ticket.packages}}</vn-td>
|
||||
<vn-td shrink>{{::ticket.volume | number:1}}</vn-td>
|
||||
<vn-td number>
|
||||
<span
|
||||
ng-click="ticketDescriptor.show($event, ticket.id)"
|
||||
class="link">
|
||||
{{ticket.id}}
|
||||
{{::ticket.id}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td shrink>
|
||||
|
|
Loading…
Reference in New Issue