2022-09-26 06:07:45 +00:00
|
|
|
const Component = require(`vn-print/core/component`);
|
2019-11-04 12:55:20 +00:00
|
|
|
const reportHeader = new Component('report-header');
|
|
|
|
const reportFooter = new Component('report-footer');
|
2019-04-10 07:45:45 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2019-11-06 07:20:45 +00:00
|
|
|
name: 'driver-route',
|
2019-11-04 12:55:20 +00:00
|
|
|
async serverPrefetch() {
|
2022-09-26 06:07:45 +00:00
|
|
|
let ids = this.id;
|
|
|
|
|
|
|
|
const hasMultipleRoutes = String(this.id).includes(',');
|
|
|
|
if (hasMultipleRoutes)
|
|
|
|
ids = this.id.split(',');
|
|
|
|
|
|
|
|
const routes = await this.fetchRoutes(ids);
|
|
|
|
const tickets = await this.fetchTickets(ids);
|
2019-04-10 07:45:45 +00:00
|
|
|
|
2020-09-14 09:44:10 +00:00
|
|
|
const map = new Map();
|
2020-08-25 08:00:21 +00:00
|
|
|
|
2020-09-14 09:44:10 +00:00
|
|
|
for (let route of routes)
|
|
|
|
map.set(route.id, route);
|
|
|
|
|
|
|
|
for (let ticket of tickets) {
|
|
|
|
const route = map.get(ticket.routeFk);
|
|
|
|
if (!route.tickets) route.tickets = [];
|
|
|
|
route.tickets.push(ticket);
|
2020-08-25 08:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.routes = routes;
|
|
|
|
|
|
|
|
if (!this.routes)
|
2019-11-04 12:55:20 +00:00
|
|
|
throw new Error('Something went wrong');
|
|
|
|
},
|
2019-04-10 07:45:45 +00:00
|
|
|
methods: {
|
2022-09-26 06:07:45 +00:00
|
|
|
fetchRoutes(ids) {
|
|
|
|
return this.rawSqlFromDef('routes', [ids]);
|
2019-04-10 07:45:45 +00:00
|
|
|
},
|
2022-09-26 06:07:45 +00:00
|
|
|
fetchTickets(ids) {
|
|
|
|
return this.rawSqlFromDef('tickets', [ids, ids]);
|
2019-11-04 12:55:20 +00:00
|
|
|
}
|
2019-04-15 12:34:33 +00:00
|
|
|
},
|
|
|
|
components: {
|
2019-11-04 12:55:20 +00:00
|
|
|
'report-header': reportHeader.build(),
|
|
|
|
'report-footer': reportFooter.build()
|
2019-04-10 07:45:45 +00:00
|
|
|
},
|
2019-11-04 12:55:20 +00:00
|
|
|
props: {
|
2022-09-26 06:07:45 +00:00
|
|
|
id: {
|
2022-01-17 11:44:43 +00:00
|
|
|
type: [Number, String],
|
2022-09-26 11:33:27 +00:00
|
|
|
required: true,
|
|
|
|
description: 'The route id'
|
2019-11-04 12:55:20 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-10 07:45:45 +00:00
|
|
|
};
|