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

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-11-04 12:55:20 +00:00
const Component = require(`${appPath}/core/component`);
const db = require(`${appPath}/core/database`);
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 = {
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) {
2020-09-25 12:45:00 +00:00
return db.rawSqlFromDef('routes', {routesId}, __dirname);
2019-04-10 07:45:45 +00:00
},
2020-08-25 08:00:21 +00:00
fetchTickets(routesId) {
2020-09-25 12:45:00 +00:00
return db.rawSqlFromDef('tickets', {routesId}, __dirname);
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
};