parent
33a375653b
commit
462879a40b
|
@ -0,0 +1,101 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('getTickets', {
|
||||
description: 'Updates the item taxes',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The item id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/getTickets`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getTickets = async id => {
|
||||
let filter = {
|
||||
where: {id: id},
|
||||
include: [
|
||||
{relation: 'ticket',
|
||||
scope: {
|
||||
fields: ['id', 'packages', 'warehouseFk', 'nickname', 'clientFk', 'priority'],
|
||||
order: 'priority',
|
||||
include: [
|
||||
{
|
||||
relation: 'client',
|
||||
scope: {
|
||||
fields: ['id', 'street', 'postcode'],
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'state',
|
||||
scope: {
|
||||
fields: ['id', 'stateFk'],
|
||||
include: [{relation: 'state'}]
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'warehouse',
|
||||
scope: {
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'notes',
|
||||
scope: {
|
||||
where: {observationTypeFk: 3}
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
}, {
|
||||
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']
|
||||
}
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
route = await Self.app.models.Route.findOne(filter);
|
||||
|
||||
for (let i = 0; i < route.ticket().length; i++) {
|
||||
let ticket = route.ticket()[i];
|
||||
let query = `
|
||||
SELECT vn.ticketTotalVolume(?) AS m3`;
|
||||
|
||||
let options = [ticket.id];
|
||||
let [volume] = await Self.rawSql(query, options);
|
||||
|
||||
ticket.volume = volume.m3;
|
||||
}
|
||||
|
||||
return route.ticket();
|
||||
};
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('route summary()', () => {
|
||||
it('should return a summary object containing data freom his tickets', async() => {
|
||||
let result = await app.models.Route.getTickets(1);
|
||||
|
||||
expect(result[2].id).toEqual(11);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('route summary()', () => {
|
||||
it('should return a summary object containing data from 1 route', async() => {
|
||||
let result = await app.models.Route.summary(2);
|
||||
|
||||
expect(result.route.id).toEqual(2);
|
||||
expect(result.route.workerFk).toEqual(56);
|
||||
});
|
||||
|
||||
it('should return a summary object containing data freom his tickets', async() => {
|
||||
let result = await app.models.Route.summary(1);
|
||||
|
||||
expect(result.tickets[2].id).toEqual(11);
|
||||
});
|
||||
});
|
|
@ -22,44 +22,10 @@ module.exports = Self => {
|
|||
Self.summary = async id => {
|
||||
let summary = {};
|
||||
|
||||
// Item basic data and taxes
|
||||
let filter = {
|
||||
where: {id: id},
|
||||
include: [
|
||||
{relation: 'ticket',
|
||||
scope: {
|
||||
fields: ['id', 'packages', 'warehouseFk', 'nickname', 'clientFk', 'priority'],
|
||||
order: 'priority',
|
||||
include: [
|
||||
{
|
||||
relation: 'client',
|
||||
scope: {
|
||||
fields: ['id', 'street', 'postcode'],
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'state',
|
||||
scope: {
|
||||
fields: ['id', 'stateFk'],
|
||||
include: [{relation: 'state'}]
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'warehouse',
|
||||
scope: {
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'notes',
|
||||
scope: {
|
||||
where: {observationTypeFk: 3}
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
}, {
|
||||
{
|
||||
relation: 'agencyMode',
|
||||
scope: {
|
||||
fields: ['id', 'name']
|
||||
|
@ -87,17 +53,7 @@ module.exports = Self => {
|
|||
};
|
||||
|
||||
summary.route = await Self.app.models.Route.findOne(filter);
|
||||
|
||||
for (let i = 0; i < summary.route.ticket().length; i++) {
|
||||
let ticket = summary.route.ticket()[i];
|
||||
let query = `
|
||||
SELECT vn.ticketTotalVolume(?) AS m3`;
|
||||
|
||||
let options = [ticket.id];
|
||||
let [volume] = await Self.rawSql(query, options);
|
||||
|
||||
ticket.volume = volume.m3;
|
||||
}
|
||||
summary.tickets = await Self.app.models.Route.getTickets(id);
|
||||
|
||||
return summary;
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/route/summary')(Self);
|
||||
require('../methods/route/getTickets')(Self);
|
||||
};
|
||||
|
|
|
@ -66,8 +66,8 @@
|
|||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="ticket in $ctrl.summary.route.ticket">
|
||||
<vn-td shrink>{{ticket.priority}}</vn-td>
|
||||
<vn-tr ng-repeat="ticket in $ctrl.summary.tickets">
|
||||
<vn-td shrink>{{ticket.priority | dashIfEmpty}}</vn-td>
|
||||
<vn-td number>
|
||||
<span
|
||||
ng-click="$ctrl.showTicketDescriptor($event, ticket.id)"
|
||||
|
|
|
@ -15,7 +15,7 @@ class Controller {
|
|||
|
||||
sumPackages() {
|
||||
this.packagesTotal = 0;
|
||||
this.summary.route.ticket.forEach(ticket => {
|
||||
this.summary.tickets.forEach(ticket => {
|
||||
this.packagesTotal += ticket.packages;
|
||||
});
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class Controller {
|
|||
getSummary() {
|
||||
this.$http.get(`/api/Routes/${this.route.id}/summary`).then(response => {
|
||||
this.summary = response.data;
|
||||
if (response.data && response.data.route && response.data.route.ticket)
|
||||
if (response.data && response.data.tickets)
|
||||
this.sumPackages();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -23,5 +23,19 @@ describe('Route', () => {
|
|||
expect(controller.summary).toEqual(24);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sumPackages()', () => {
|
||||
it('should calculate the packages total', () => {
|
||||
controller.summary = {
|
||||
tickets: [
|
||||
{packages: 3},
|
||||
{packages: 1}
|
||||
]
|
||||
};
|
||||
controller.sumPackages();
|
||||
|
||||
expect(controller.packagesTotal).toEqual(4);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue