From feeb9eece7f68dbf4b209ec3f39f5abcee8994e3 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 29 Feb 2024 08:12:17 +0100 Subject: [PATCH 1/2] feat: refs #6401 Added QR and CIF in the CMR report --- .../reports/cmr/assets/css/style.css | 17 +++- print/templates/reports/cmr/cmr.html | 22 +++++- print/templates/reports/cmr/cmr.js | 77 +++++++++++-------- print/templates/reports/cmr/sql/data.sql | 1 + 4 files changed, 78 insertions(+), 39 deletions(-) diff --git a/print/templates/reports/cmr/assets/css/style.css b/print/templates/reports/cmr/assets/css/style.css index 201afc3b6..8b007b3b0 100644 --- a/print/templates/reports/cmr/assets/css/style.css +++ b/print/templates/reports/cmr/assets/css/style.css @@ -3,7 +3,7 @@ html { margin: 10px; font-size: 22px; } -.mainTable, .specialTable, .categoryTable { +.mainTable, .specialTable, .categoryTable, .observationTable { width: 100%; border-collapse: collapse; font-size: inherit; @@ -98,4 +98,19 @@ img { #merchandiseLabels td { padding-bottom: 11px; max-width: 300px; +} + +.observationTable tr td { + border: none; + padding: 5px; +} + +#qrSection { + text-align: center; + width: 30%; +} + +#truckPlateQr { + width: 125px; + margin-bottom: 10px; } \ No newline at end of file diff --git a/print/templates/reports/cmr/cmr.html b/print/templates/reports/cmr/cmr.html index c6a9e79d6..a8f302086 100644 --- a/print/templates/reports/cmr/cmr.html +++ b/print/templates/reports/cmr/cmr.html @@ -30,8 +30,11 @@ 16. Transportista / Transporteur / Carrier
{{data.carrierName}}
- {{data.carrierStreet}}
- {{data.carrierPostalCode}} {{data.carrierCity}} {{(data.carrierCountry) ? `(${data.carrierCountry})` : null}} + {{data.carrierStreet}} {{data.carrierPostalCode}} + {{data.carrierCity}} {{(data.carrierCountry) + ? `(${data.carrierCountry})` + : null}}
+ CIF: {{data.carrierCif}} @@ -71,8 +74,19 @@ Carrier's reservations and observations
- {{data.truckPlate}}
- {{data.observations}} + + + + + +
+ {{data.observations}} + + +
+ {{data.truckPlate}} +
+ diff --git a/print/templates/reports/cmr/cmr.js b/print/templates/reports/cmr/cmr.js index c939e5152..2ee855ce0 100644 --- a/print/templates/reports/cmr/cmr.js +++ b/print/templates/reports/cmr/cmr.js @@ -2,44 +2,53 @@ const config = require(`vn-print/core/config`); const vnReport = require('../../../core/mixins/vn-report.js'); const md5 = require('md5'); const fs = require('fs-extra'); +const qrcode = require('qrcode'); const prefixBase64 = 'data:image/png;base64,'; module.exports = { - name: 'cmr', - mixins: [vnReport], - async serverPrefetch() { - this.data = await this.findOneFromDef('data', [this.id]); - if (this.data.ticketFk) { - this.merchandises = await this.rawSqlFromDef('merchandise', [this.data.ticketFk]); - this.signature = await this.findOneFromDef('signature', [this.data.ticketFk]); - } else - this.merchandises = null; + name: 'cmr', + mixins: [vnReport], + async serverPrefetch() { + this.data = await this.findOneFromDef('data', [this.id]); + if (this.data.ticketFk) { + this.merchandises = await this.rawSqlFromDef('merchandise', [this.data.ticketFk]); + this.signature = await this.findOneFromDef('signature', [this.data.ticketFk]); + } else + this.merchandises = null; - this.senderStamp = (this.data.senderStamp) - ? `${prefixBase64} ${this.data.senderStamp.toString('base64')}` - : null; - this.deliveryStamp = (this.data.deliveryStamp) - ? `${prefixBase64} ${this.data.deliveryStamp.toString('base64')}` - : null; - }, - props: { - id: { - type: Number, - required: true, - description: 'The cmr id' - }, - }, - computed: { - signPath() { - if (!this.signature) return; + this.senderStamp = (this.data.senderStamp) + ? `${prefixBase64} ${this.data.senderStamp.toString('base64')}` + : null; + this.deliveryStamp = (this.data.deliveryStamp) + ? `${prefixBase64} ${this.data.deliveryStamp.toString('base64')}` + : null; + this.truckPlateQr = await this.getQR(this.data.truckPlate); + }, + props: { + id: { + type: Number, + required: true, + description: 'The cmr id' + }, + }, + computed: { + signPath() { + if (!this.signature) return; - const signatureName = this.signature.signature - const hash = md5(signatureName.toString()).substring(0, 3); - const file = `${config.storage.root}/${hash}/${signatureName}.png`; - if (!fs.existsSync(file)) return null; + const signatureName = this.signature.signature; + const hash = md5(signatureName.toString()).substring(0, 3); + const file = `${config.storage.root}/${hash}/${signatureName}.png`; + if (!fs.existsSync(file)) return null; - return `${prefixBase64} ${Buffer.from(fs.readFileSync(file), 'utf8').toString('base64')}`; - }, - } -}; \ No newline at end of file + return `${prefixBase64} ${Buffer.from(fs.readFileSync(file), 'utf8').toString('base64')}`; + }, + }, + methods: { + getQR(id) { + const data = String(id); + + return qrcode.toDataURL(data, {margin: 0}); + }, + } +}; diff --git a/print/templates/reports/cmr/sql/data.sql b/print/templates/reports/cmr/sql/data.sql index 9708c4483..e9500cc4b 100644 --- a/print/templates/reports/cmr/sql/data.sql +++ b/print/templates/reports/cmr/sql/data.sql @@ -10,6 +10,7 @@ SELECT c.id cmrFk, c.merchandiseDetail, c.ead, s.name carrierName, + s.nif carrierCif, s.street carrierStreet, s.postCode carrierPostCode, s.city carrierCity, From 3736d0708bd99873b34e2d5b5a791b7c9148173c Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 29 Feb 2024 08:16:07 +0100 Subject: [PATCH 2/2] feat: refs #6401 Minor change --- print/templates/reports/cmr/cmr.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/print/templates/reports/cmr/cmr.js b/print/templates/reports/cmr/cmr.js index 2ee855ce0..ef99a08a0 100644 --- a/print/templates/reports/cmr/cmr.js +++ b/print/templates/reports/cmr/cmr.js @@ -46,9 +46,7 @@ module.exports = { }, methods: { getQR(id) { - const data = String(id); - - return qrcode.toDataURL(data, {margin: 0}); + return qrcode.toDataURL(String(id), {margin: 0}); }, } };