salix/print/report/rpt-route/index.js

95 lines
3.6 KiB
JavaScript
Raw Normal View History

2019-04-10 07:45:45 +00:00
const strftime = require('strftime');
const database = require(`${appPath}/lib/database`);
const UserException = require(`${appPath}/lib/exceptions/userException`);
module.exports = {
name: 'rpt-route',
async asyncData(ctx, params) {
2019-04-15 12:34:33 +00:00
Object.assign(this, this.methods);
2019-04-10 07:45:45 +00:00
2019-04-15 12:34:33 +00:00
const [[route]] = await this.fetchRoute(params.routeFk);
const [tickets] = await this.fetchTickets(params.routeFk);
2019-04-10 07:45:45 +00:00
if (!route)
2019-04-15 12:34:33 +00:00
throw new UserException('No route data found');
2019-04-10 07:45:45 +00:00
2019-04-15 12:34:33 +00:00
if (!tickets)
throw new UserException('No ticket data found');
return {route, tickets};
2019-04-10 07:45:45 +00:00
},
methods: {
fetchRoute(routeFk) {
return database.pool.query(
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,
u.lang AS locale,
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 ticket t ON t.routeFk = r.id
LEFT JOIN sale s ON s.ticketFk = t.id
LEFT JOIN cache.last_buy lb ON lb.item_id = s.itemFk
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
2019-04-10 07:45:45 +00:00
WHERE r.id = ?`, [routeFk]);
},
2019-04-15 12:34:33 +00:00
fetchTickets(routeFk) {
return database.pool.query(
`SELECT
t.nickname addressName,
t.packages,
t.priority,
t.id,
t.clientFk,
t.companyFk,
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
LEFT JOIN worker w ON w.id = vn2008.Averiguar_ComercialCliente_Id(t.clientFk, CURDATE())
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
WHERE r.id = ?
ORDER BY t.priority, t.id`, [routeFk]);
2019-04-10 07:45:45 +00:00
},
2019-04-15 12:34:33 +00:00
date(date) {
if (date)
return strftime('%d-%m-%Y', date);
},
time: time => {
if (time)
return strftime('%H:%M', time);
},
},
components: {
'report-header': require('../report-header'),
'report-footer': require('../report-footer'),
2019-04-10 07:45:45 +00:00
},
};