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

53 lines
1.4 KiB
JavaScript
Executable File

const Component = require(`vn-print/core/component`);
const reportBody = new Component('report-body');
const reportFooter = new Component('report-footer');
module.exports = {
name: 'driver-route',
async serverPrefetch() {
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);
const map = new Map();
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);
}
this.routes = routes;
if (!this.routes)
throw new Error('Something went wrong');
},
methods: {
fetchRoutes(ids) {
return this.rawSqlFromDef('routes', [ids]);
},
fetchTickets(ids) {
return this.rawSqlFromDef('tickets', [ids, ids]);
}
},
components: {
'report-body': reportBody.build(),
'report-footer': reportFooter.build()
},
props: {
id: {
type: Number,
required: true,
description: 'The route id'
}
}
};