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

94 lines
3.4 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-08-25 08:00:21 +00:00
for (let route of routes) {
const routeTickets = tickets.filter(ticket => {
return ticket.routeFk == route.id;
});
route.tickets = routeTickets;
}
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) {
return db.rawSql(
2019-04-15 12:34:33 +00:00
`SELECT
2019-04-10 07:45:45 +00:00
r.id,
2019-04-15 12:34:33 +00:00
r.m3,
r.created,
2019-04-10 07:45:45 +00:00
r.time,
2019-04-15 12:34:33 +00:00
u.nickName userNickName,
v.tradeMark vehicleTradeMark,
v.model vehicleModel,
v.numberPlate plateNumber,
am.name agencyName
2019-04-10 07:45:45 +00:00
FROM route r
2019-04-15 12:34:33 +00:00
LEFT JOIN vehicle v ON v.id = r.vehicleFk
LEFT JOIN worker w ON w.id = r.workerFk
LEFT JOIN account.user u ON u.id = w.userFk
LEFT JOIN agencyMode am ON am.id = r.agencyModeFk
2020-08-25 08:00:21 +00:00
WHERE r.id IN(:routesId)`, {routesId});
2019-04-10 07:45:45 +00:00
},
2020-08-25 08:00:21 +00:00
fetchTickets(routesId) {
return db.rawSql(
2019-04-15 12:34:33 +00:00
`SELECT
t.nickname addressName,
t.packages,
t.priority,
t.id,
t.clientFk,
t.companyFk,
2020-08-25 08:00:21 +00:00
t.routeFk,
2019-04-15 12:34:33 +00:00
if(a.phone, a.phone, c.phone) AS phone,
if(a.mobile, a.mobile, c.mobile) AS mobile,
wh.name warehouseName,
a.city,
a.street,
a.postalCode,
LPAD(a.id, 5, '0') AS addressFk,
p.name province,
vn.ticketGetTotal(t.id) AS import,
am.name ticketAgency,
tob.description,
s.shipFk,
u.nickName salesPersonName
FROM route r
LEFT JOIN ticket t ON t.routeFk = r.id
LEFT JOIN address a ON a.id = t.addressFk
LEFT JOIN client c ON c.id = t.clientFk
2019-11-20 11:42:10 +00:00
LEFT JOIN worker w ON w.id = client_getSalesPerson(t.clientFk, CURDATE())
2019-04-15 12:34:33 +00:00
LEFT JOIN account.user u ON u.id = w.userFk
LEFT JOIN ticketObservation tob ON tob.ticketFk = t.id AND tob.observationTypeFk = 3
LEFT JOIN province p ON a.provinceFk = p.id
LEFT JOIN warehouse wh ON wh.id = t.warehouseFk
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
LEFT JOIN stowaway s ON s.id = t.id
2020-08-25 08:00:21 +00:00
WHERE r.id IN(:routesId)
ORDER BY t.priority, t.id`, {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
};