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

39 lines
1016 B
JavaScript
Executable File

const vnReport = require('../../../core/mixins/vn-report.js');
module.exports = {
name: 'driver-route',
mixins: [vnReport],
async serverPrefetch() {
let ids = this.id;
console.log(typeof ids);
const hasMultipleRoutes = String(this.id).includes(',');
if (hasMultipleRoutes)
ids = this.id.split(',');
const routes = await this.rawSqlFromDef('routes', +[ids]);
const tickets = await this.rawSqlFromDef('tickets', [ids, 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;
this.checkMainEntity(this.routes);
},
props: {
id: {
type: Number,
required: true,
description: 'The route id'
}
}
};