From 7043b833d02ee33ab74a75cd4efb387554b0f468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 14 Sep 2020 11:44:10 +0200 Subject: [PATCH] Pdf optimization --- print/core/config.js | 6 ++++-- print/core/report.js | 2 +- .../reports/driver-route/driver-route.js | 15 +++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/print/core/config.js b/print/core/config.js index 5194762b4..fba30dab9 100644 --- a/print/core/config.js +++ b/print/core/config.js @@ -1,4 +1,5 @@ const fs = require('fs-extra'); +const path = require('path'); let env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development'; let configPath = `/etc/salix`; @@ -12,8 +13,9 @@ let configFiles = [ ]; for (let configFile of configFiles) { - if (fs.existsSync(configFile)) { - const conf = require(configFile); + const filePath = path.join(__dirname, configFile); + if (fs.existsSync(filePath)) { + const conf = require(filePath); for (let prop in conf) Object.assign(config[prop], conf[prop]); } diff --git a/print/core/report.js b/print/core/report.js index 46404ff96..b20b8e5df 100644 --- a/print/core/report.js +++ b/print/core/report.js @@ -27,7 +27,7 @@ class Report extends Component { if (fs.existsSync(fullPath)) options = require(optionsPath); - const page = await config.browser.newPage(); + const page = (await config.browser.pages())[0]; await page.emulateMedia('screen'); await page.setContent(template); diff --git a/print/templates/reports/driver-route/driver-route.js b/print/templates/reports/driver-route/driver-route.js index cab5342e5..0f8461046 100755 --- a/print/templates/reports/driver-route/driver-route.js +++ b/print/templates/reports/driver-route/driver-route.js @@ -10,12 +10,15 @@ module.exports = { const routes = await this.fetchRoutes(routesId); const tickets = await this.fetchTickets(routesId); - for (let route of routes) { - const routeTickets = tickets.filter(ticket => { - return ticket.routeFk == route.id; - }); + const map = new Map(); - route.tickets = routeTickets; + 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; @@ -61,7 +64,7 @@ module.exports = { a.postalCode, LPAD(a.id, 5, '0') AS addressFk, p.name province, - vn.ticketGetTotal(t.id) AS import, + 0 AS import, am.name ticketAgency, tob.description, s.shipFk,