salix/print/templates/reports/driver-route/driver-route.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-11-04 12:55:20 +00:00
const Component = require(`${appPath}/core/component`);
const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer');
2019-04-10 07:45:45 +00:00
module.exports = {
name: 'driver-route',
2019-11-04 12:55:20 +00:00
async serverPrefetch() {
2020-08-25 08:00:21 +00:00
const routesId = this.routeId.split(',');
const routes = await this.fetchRoutes(routesId);
const tickets = await this.fetchTickets(routesId);
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: {
2020-08-25 08:00:21 +00:00
fetchRoutes(routesId) {
2021-04-27 08:29:09 +00:00
return this.rawSqlFromDef('routes', [routesId]);
2019-04-10 07:45:45 +00:00
},
2020-08-25 08:00:21 +00:00
fetchTickets(routesId) {
return this.rawSqlFromDef('tickets', [routesId, routesId]);
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: {
routeId: {
required: true
}
}
2019-04-10 07:45:45 +00:00
};