diff --git a/print/config/print.json b/print/config/print.json index bb74682814..ceb7cbb285 100755 --- a/print/config/print.json +++ b/print/config/print.json @@ -22,13 +22,18 @@ "displayHeaderFooter": true, "printBackground": true }, - "mysql": { - "host": "localhost", - "port": 3306, - "database": "vn", - "user": "root", - "password": "root" - }, + "datasources": [ + { + "name": "default", + "options": { + "host": "localhost", + "port": 3306, + "database": "vn", + "user": "root", + "password": "root" + } + } + ], "smtp": { "host": "localhost", "port": 465, diff --git a/print/core/components/email-header/assets/css/style.css b/print/core/components/email-header/assets/css/style.css index e6451ca5a3..474bc8b80d 100644 --- a/print/core/components/email-header/assets/css/style.css +++ b/print/core/components/email-header/assets/css/style.css @@ -8,7 +8,7 @@ header .logo { } header .logo img { - width: 50% + width: 300px } header .topbar { diff --git a/print/core/components/report-header/report-header.js b/print/core/components/report-header/report-header.js index 9d501d3ba0..58c06bc1a0 100755 --- a/print/core/components/report-header/report-header.js +++ b/print/core/components/report-header/report-header.js @@ -33,13 +33,13 @@ module.exports = { SELECT s.name, s.street, s.postCode, s.city, s.phone FROM company c JOIN supplier s ON s.id = c.id - WHERE c.code = :code`, {code}); + WHERE c.code = ?`, [code]); }, getFiscalAddress(code) { return db.findOne(` SELECT nif, register FROM company c JOIN supplier s ON s.id = c.id - WHERE c.code = :code`, {code}); + WHERE c.code = ?`, [code]); } }, props: ['companyCode'] diff --git a/print/core/database.js b/print/core/database.js index dee7a29331..4592294be8 100644 --- a/print/core/database.js +++ b/print/core/database.js @@ -1,16 +1,38 @@ -const mysql = require('mysql2/promise'); +const mysql = require('mysql2'); const config = require('./config.js'); const fs = require('fs-extra'); -const PromisePoolConnection = mysql.PromisePoolConnection; +const PoolConnection = mysql.PoolConnection; module.exports = { init() { if (!this.pool) { - this.pool = mysql.createPool(config.mysql); - this.pool.on('connection', connection => { - connection.config.namedPlaceholders = true; - }); + const datasources = config.datasources; + const pool = mysql.createPoolCluster(); + + for (let datasource of datasources) + pool.add(datasource.name, datasource.options); + + this.pool = pool; } + + return this.pool; + }, + + /** + * Retuns a pool connection from specific cluster node + * @param {String} name - The cluster name + * + * @return {Object} - Pool connection + */ + getConnection(name) { + let pool = this.pool; + return new Promise((resolve, reject) => { + pool.getConnection(name, function(error, connection) { + if (error) return reject(error); + + resolve(connection); + }); + }); }, /** @@ -23,12 +45,27 @@ module.exports = { */ rawSql(query, params, connection) { let pool = this.pool; - if (params instanceof PromisePoolConnection) + if (params instanceof PoolConnection) connection = params; if (connection) pool = connection; - return pool.query(query, params).then(([rows]) => { - return rows; + return new Promise((resolve, reject) => { + if (!connection) { + pool.getConnection('default', function(error, conn) { + if (error) return reject(error); + + conn.query(query, params, (error, rows) => { + if (error) return reject(error); + conn.release(); + resolve(rows); + }); + }); + } else { + connection.query(query, params, (error, rows) => { + if (error) return reject(error); + resolve(rows); + }); + } }); }, diff --git a/print/core/mixins/db-helper.js b/print/core/mixins/db-helper.js index 1de27e6cd4..791766775f 100644 --- a/print/core/mixins/db-helper.js +++ b/print/core/mixins/db-helper.js @@ -4,6 +4,14 @@ const db = require('../database'); const dbHelper = { methods: { + /** + * Retuns a pool connection from specific cluster node + * @param {String} name - The cluster name + * + * @return {Object} - Pool connection + */ + getConnection: name => db.getConnection(name), + /** * Makes a query from a raw sql * @param {String} query - The raw SQL query diff --git a/print/core/smtp.js b/print/core/smtp.js index 23d19cabc3..8c292fafe7 100644 --- a/print/core/smtp.js +++ b/print/core/smtp.js @@ -26,13 +26,13 @@ module.exports = { }).finally(async() => { await db.rawSql(` INSERT INTO vn.mail (sender, replyTo, sent, subject, body, status) - VALUES (:recipient, :sender, 1, :subject, :body, :status)`, { - sender: options.replyTo, - recipient: options.to, - subject: options.subject, - body: options.text || options.html, - status: error && error.message || 'Sent' - }); + VALUES (?, ?, 1, ?, ?, ?)`, [ + options.replyTo, + options.to, + options.subject, + options.text || options.html, + error && error.message || 'Sent' + ]); }); } }; diff --git a/print/methods/closure.js b/print/methods/closure.js index e313699636..85b4861581 100644 --- a/print/methods/closure.js +++ b/print/methods/closure.js @@ -23,12 +23,10 @@ module.exports = app => { JOIN ticketState ts ON ts.ticketFk = t.id JOIN alertLevel al ON al.alertLevel = ts.alertLevel WHERE al.code = 'PACKED' - AND DATE(t.shipped) BETWEEN DATE_ADD(:to, INTERVAL -2 DAY) - AND util.dayEnd(:to) + AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) + AND util.dayEnd(?) AND t.refFk IS NULL - GROUP BY e.ticketFk`, { - to: reqArgs.to - }); + GROUP BY e.ticketFk`, [reqArgs.to, reqArgs.to]); const ticketIds = tickets.map(ticket => ticket.id); await closeAll(ticketIds, req.args); @@ -40,13 +38,11 @@ module.exports = app => { JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk JOIN zone z ON z.id = t.zoneFk SET t.routeFk = NULL - WHERE DATE(t.shipped) BETWEEN DATE_ADD(:to, INTERVAL -2 DAY) - AND util.dayEnd(:to) + WHERE DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) + AND util.dayEnd(?) AND al.code NOT IN('DELIVERED','PACKED') AND t.routeFk - AND z.name LIKE '%MADRID%'`, { - to: reqArgs.to - }); + AND z.name LIKE '%MADRID%'`, [reqArgs.to, reqArgs.to]); } catch (error) { next(error); } @@ -70,11 +66,9 @@ module.exports = app => { JOIN ticketState ts ON ts.ticketFk = t.id JOIN alertLevel al ON al.alertLevel = ts.alertLevel WHERE al.code = 'PACKED' - AND t.id = :ticketId + AND t.id = ? AND t.refFk IS NULL - GROUP BY e.ticketFk`, { - ticketId: reqArgs.ticketId - }); + GROUP BY e.ticketFk`, [reqArgs.ticketId]); const ticketIds = tickets.map(ticket => ticket.id); await closeAll(ticketIds, reqArgs); @@ -108,16 +102,17 @@ module.exports = app => { JOIN ticketState ts ON ts.ticketFk = t.id JOIN alertLevel al ON al.alertLevel = ts.alertLevel WHERE al.code = 'PACKED' - AND t.agencyModeFk IN(:agencyModeId) - AND t.warehouseFk = :warehouseId + AND t.agencyModeFk IN(?) + AND t.warehouseFk = ? AND DATE(t.shipped) BETWEEN DATE_ADD(:to, INTERVAL -2 DAY) - AND util.dayEnd(:to) + AND util.dayEnd(?) AND t.refFk IS NULL - GROUP BY e.ticketFk`, { - agencyModeId: agenciesId, - warehouseId: reqArgs.warehouseId, - to: reqArgs.to - }); + GROUP BY e.ticketFk`, [ + agenciesId, + reqArgs.warehouseId, + reqArgs.to, + reqArgs.to + ]); const ticketIds = tickets.map(ticket => ticket.id); await closeAll(ticketIds, reqArgs); @@ -144,11 +139,9 @@ module.exports = app => { JOIN ticketState ts ON ts.ticketFk = t.id JOIN alertLevel al ON al.alertLevel = ts.alertLevel WHERE al.code = 'PACKED' - AND t.routeFk = :routeId + AND t.routeFk = ? AND t.refFk IS NULL - GROUP BY e.ticketFk`, { - routeId: reqArgs.routeId - }); + GROUP BY e.ticketFk`, [reqArgs.routeId]); const ticketIds = tickets.map(ticket => ticket.id); await closeAll(ticketIds, reqArgs); @@ -179,9 +172,7 @@ module.exports = app => { for (const ticket of tickets) { try { - await db.rawSql(`CALL vn.ticket_close(:ticketId)`, { - ticketId: ticket.id - }); + await db.rawSql(`CALL vn.ticket_close(?)`, [ticket.id]); const hasToInvoice = ticket.hasToInvoice && ticket.hasDailyInvoice; if (!ticket.salesPersonFk || !ticket.isToBeMailed || hasToInvoice) continue; @@ -239,20 +230,19 @@ module.exports = app => { } async function invalidEmail(ticket) { - await db.rawSql(`UPDATE client SET email = NULL WHERE id = :clientId`, { - clientId: ticket.clientFk - }); + await db.rawSql(`UPDATE client SET email = NULL WHERE id = ?`, [ + ticket.clientFk + ]); const oldInstance = `{"email": "${ticket.recipient}"}`; const newInstance = `{"email": ""}`; await db.rawSql(` INSERT INTO clientLog (originFk, userFk, action, changedModel, oldInstance, newInstance) - VALUES (:clientId, :userId, 'UPDATE', 'Client', :oldInstance, :newInstance)`, { - clientId: ticket.clientFk, - userId: null, - oldInstance: oldInstance, - newInstance: newInstance - }); + VALUES (?, NULL, 'UPDATE', 'Client', ?, ?)`, [ + ticket.clientFk, + oldInstance, + newInstance + ]); const body = `No se ha podido enviar el albarán ${ticket.id} al cliente ${ticket.clientFk} - ${ticket.clientName} diff --git a/print/templates/email/osticket-report/assets/css/import.js b/print/templates/email/osticket-report/assets/css/import.js new file mode 100644 index 0000000000..c742fdf90a --- /dev/null +++ b/print/templates/email/osticket-report/assets/css/import.js @@ -0,0 +1,9 @@ +const Stylesheet = require(`${appPath}/core/stylesheet`); + +module.exports = new Stylesheet([ + `${appPath}/common/css/spacing.css`, + `${appPath}/common/css/misc.css`, + `${appPath}/common/css/layout.css`, + `${appPath}/common/css/email.css`, + `${__dirname}/style.css`]) + .mergeStyles(); diff --git a/print/templates/email/osticket-report/assets/css/style.css b/print/templates/email/osticket-report/assets/css/style.css new file mode 100644 index 0000000000..67595b8cfb --- /dev/null +++ b/print/templates/email/osticket-report/assets/css/style.css @@ -0,0 +1,33 @@ +.grid-block table.column-oriented { + max-width: 100%; +} + +.grid-block table.column-oriented td.message { + overflow: hidden; + max-width: 300px +} + + +.grid-block table.column-oriented th a { + color: #333 +} + +.grid-block { + max-width: 98% +} + +.table-title { + background-color: #95d831; + padding: 0 10px; + margin-bottom: 20px; +} + +.table-title h2 { + margin: 10px 0 +} + +.external-link { + border: 2px dashed #8dba25; + border-radius: 3px; + text-align: center +} \ No newline at end of file diff --git a/print/templates/email/osticket-report/locale/es.yml b/print/templates/email/osticket-report/locale/es.yml new file mode 100644 index 0000000000..c231aa1389 --- /dev/null +++ b/print/templates/email/osticket-report/locale/es.yml @@ -0,0 +1,13 @@ +subject: Informe de tickets semanal +title: Informe de tickets semanal +dear: Hola +description: A continuación se el resumen de incidencias resueltas desde {0 | date('%d-%m-%Y')} hasta {1}. +totalResolved: Un total de {0} tickets han sido resueltos durante la última semana. +author: Autor +dated: Fecha +opened: Abierto +closed: Cerrado +ticketSubject: Asunto +ticketDescription: Descripción +resolution: Resolución +grafanaLink: "Puedes ver la gráfica desde el siguiente enlace:" \ No newline at end of file diff --git a/print/templates/email/osticket-report/osticket-report.html b/print/templates/email/osticket-report/osticket-report.html new file mode 100644 index 0000000000..749c061288 --- /dev/null +++ b/print/templates/email/osticket-report/osticket-report.html @@ -0,0 +1,93 @@ + + +
+ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ $t('title') }}+{{$t('dear')}}, + + + + +
+
+
+
+
+
+
+
+ {{technician.name}} ({{technician.tickets.length}})+
+
+
+
+
+
+
+
+ |
+