From aaef10b8d8de3ef3d32563d71c5a103a941a7ddc Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 12 Apr 2024 08:48:29 +0200 Subject: [PATCH 1/3] feat(collection-label): refs #6602 add qr to the report --- .../10991-greenAsparagus/00-firstScript.sql | 2 ++ .../reports/collection-label/collection-label.html | 6 +++++- .../reports/collection-label/collection-label.js | 14 +++++++++++++- .../reports/collection-label/sql/labelsData.sql | 3 ++- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 db/versions/10991-greenAsparagus/00-firstScript.sql diff --git a/db/versions/10991-greenAsparagus/00-firstScript.sql b/db/versions/10991-greenAsparagus/00-firstScript.sql new file mode 100644 index 000000000..9cfc9e19d --- /dev/null +++ b/db/versions/10991-greenAsparagus/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.productionConfig MODIFY COLUMN id INT(10) UNSIGNED FIRST; +ALTER TABLE vn.productionConfig ADD scannableCodeType enum('qr','barcode') DEFAULT 'barcode' NOT NULL; diff --git a/print/templates/reports/collection-label/collection-label.html b/print/templates/reports/collection-label/collection-label.html index a0bfcad0e..f313fccc4 100644 --- a/print/templates/reports/collection-label/collection-label.html +++ b/print/templates/reports/collection-label/collection-label.html @@ -10,7 +10,11 @@ {{labelData.shipped || '---'}} - + +
+ {{labelData.workerCode || '---'}} + +
{{labelData.workerCode || '---'}} diff --git a/print/templates/reports/collection-label/collection-label.js b/print/templates/reports/collection-label/collection-label.js index db2adeb34..faf6792f9 100644 --- a/print/templates/reports/collection-label/collection-label.js +++ b/print/templates/reports/collection-label/collection-label.js @@ -1,4 +1,6 @@ -const jsBarcode = require('jsbarcode'); +import qrcode from 'qrcode'; +import jsBarcode from 'jsbarcode'; + const {DOMImplementation, XMLSerializer} = require('xmldom'); const vnReport = require('../../../core/mixins/vn-report.js'); @@ -31,6 +33,16 @@ module.exports = { this.checkMainEntity(this.labelsData); }, methods: { + getQR(id) { + let QRdata = JSON.stringify({ + company: 'vnl', + user: this.userFk, + created: Date.vnNew(), + table: 'ticket', + id + }); + return qrcode.toDataURL(QRdata, {margin: 0}); + }, getBarcode(id) { const xmlSerializer = new XMLSerializer(); const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null); diff --git a/print/templates/reports/collection-label/sql/labelsData.sql b/print/templates/reports/collection-label/sql/labelsData.sql index 61990812d..a83381b1f 100644 --- a/print/templates/reports/collection-label/sql/labelsData.sql +++ b/print/templates/reports/collection-label/sql/labelsData.sql @@ -17,7 +17,8 @@ SELECT c.itemPackingTypeFk code, tt.labelCount, t.nickName, SUM(IF(sgd.id IS NULL, 1, 0)) + IF(sgd.id , 1, 0) lineCount, - rm.routeFk + rm.routeFk, + pc.scannableCodeType FROM vn.ticket t JOIN vn.ticketCollection tc ON tc.ticketFk = t.id JOIN vn.collection c ON c.id = tc.collectionFk From bd1499a6f79a4b932a44d2fb9a5956fee60461f8 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 2 May 2024 10:25:46 +0200 Subject: [PATCH 2/3] feat(collection-label): new option barcode-qr --- modules/client/front/consumption/index.html | 3 +- .../collection-label/assets/css/style.css | 5 ++- .../collection-label/collection-label.html | 16 ++++----- .../collection-label/collection-label.js | 34 ++++++++++++------- .../collection-label/sql/barcodeType.sql | 3 ++ .../collection-label/sql/labelsData.sql | 4 +-- 6 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 print/templates/reports/collection-label/sql/barcodeType.sql diff --git a/modules/client/front/consumption/index.html b/modules/client/front/consumption/index.html index 17e1e8c8b..06611da5a 100644 --- a/modules/client/front/consumption/index.html +++ b/modules/client/front/consumption/index.html @@ -77,8 +77,7 @@ tabindex="-1"> - {{::sale.quantity | dashIfEmpty}} - + {{::sale.quantity | dashIfEmpty}} diff --git a/print/templates/reports/collection-label/assets/css/style.css b/print/templates/reports/collection-label/assets/css/style.css index eb300f850..3eb68a2b2 100644 --- a/print/templates/reports/collection-label/assets/css/style.css +++ b/print/templates/reports/collection-label/assets/css/style.css @@ -32,9 +32,12 @@ html { #bold { font-weight: bold; } -#barcode{ +.barcode{ width: 370px; } +.qr{ + max-height: 137px; +} #shipped { font-weight: bold; width: 50px; diff --git a/print/templates/reports/collection-label/collection-label.html b/print/templates/reports/collection-label/collection-label.html index f313fccc4..752a31185 100644 --- a/print/templates/reports/collection-label/collection-label.html +++ b/print/templates/reports/collection-label/collection-label.html @@ -8,15 +8,15 @@ {{labelData.clientFk ? `${labelData.ticketFk} « ${labelData.clientFk}` : labelData.ticketFk}} - {{labelData.shipped || '---'}} + {{dashIfEmpty(labelData.shipped)}} - -
- {{labelData.workerCode || '---'}} + + + {{dashIfEmpty(labelData.workerCode)}} -
- {{labelData.workerCode || '---'}} +
+ {{dashIfEmpty(labelData.workerCode)}} {{labelData.labelCount || 0}} @@ -25,11 +25,11 @@ {{labelData.code == 'V' ? (labelData.size || 0) + 'cm' : (labelData.volume || 0) + 'm³'}} -
{{getAgencyDescripton(labelData)}}
+
{{dashIfEmpty(getAgencyDescription(labelData))}}
{{labelData.lineCount || 0}} - {{labelData.nickName ? labelData.nickName.toUpperCase() : '---'}} + {{dashIfEmpty(labelData?.nickName.toUpperCase()) }} {{labelData.shippedHour || labelData.zoneHour}} diff --git a/print/templates/reports/collection-label/collection-label.js b/print/templates/reports/collection-label/collection-label.js index faf6792f9..fe32a0e2b 100644 --- a/print/templates/reports/collection-label/collection-label.js +++ b/print/templates/reports/collection-label/collection-label.js @@ -1,8 +1,9 @@ -import qrcode from 'qrcode'; -import jsBarcode from 'jsbarcode'; +const qrCode = require('qrcode'); +const jsBarcode = require('jsbarcode'); const {DOMImplementation, XMLSerializer} = require('xmldom'); const vnReport = require('../../../core/mixins/vn-report.js'); +const {TRUE} = require('node-sass'); module.exports = { name: 'collection-label', @@ -29,19 +30,27 @@ module.exports = { } else ticketIds = [this.id]; - this.labelsData = await this.rawSqlFromDef('labelsData', [ticketIds]); + const labels = await this.rawSqlFromDef('labelsData', [ticketIds]); + + const [{scannableCodeType}] = await this.rawSqlFromDef('barcodeType'); + if (scannableCodeType === 'qr') { + for (const labelData of labels) + labelData.qrData = await this.getQr(labelData?.ticketFk, labelData?.workerFk); + } + + this.labelsData = labels; this.checkMainEntity(this.labelsData); }, methods: { - getQR(id) { - let QRdata = JSON.stringify({ + async getQr(ticketFk, workerFk = null) { + const QRdata = JSON.stringify({ company: 'vnl', - user: this.userFk, + user: workerFk, created: Date.vnNew(), table: 'ticket', - id + id: ticketFk }); - return qrcode.toDataURL(QRdata, {margin: 0}); + return qrCode.toDataURL(QRdata, {margin: 0}); }, getBarcode(id) { const xmlSerializer = new XMLSerializer(); @@ -64,18 +73,16 @@ module.exports = { if (labelData.code == 'V') value = value + `${labelData.wagon}-${labelData.level}`; else - value = value + `${labelData.color.substring(0, 4)}`; + value = value + `${labelData.color?.substring(0, 4)}`; } else value = '-'.repeat(19); return value; }, - getAgencyDescripton(labelData) { + getAgencyDescription(labelData) { let value; if (labelData.agencyDescription) value = labelData.agencyDescription.toUpperCase().substring(0, 11); - else - value = '---'; if (labelData.routeFk) { let routeFk = labelData.routeFk.toString(); @@ -84,5 +91,8 @@ module.exports = { return value; }, + dashIfEmpty(value) { + return value || '---'; + } }, }; diff --git a/print/templates/reports/collection-label/sql/barcodeType.sql b/print/templates/reports/collection-label/sql/barcodeType.sql new file mode 100644 index 000000000..0700c95a2 --- /dev/null +++ b/print/templates/reports/collection-label/sql/barcodeType.sql @@ -0,0 +1,3 @@ +SELECT scannableCodeType + FROM productionConfig + LIMIT 1 \ No newline at end of file diff --git a/print/templates/reports/collection-label/sql/labelsData.sql b/print/templates/reports/collection-label/sql/labelsData.sql index a83381b1f..f0a9baf1f 100644 --- a/print/templates/reports/collection-label/sql/labelsData.sql +++ b/print/templates/reports/collection-label/sql/labelsData.sql @@ -11,14 +11,14 @@ SELECT c.itemPackingTypeFk code, IF(sgd.id, IFNULL(pc.itemPreviousDefaultSize, i.`size`), i.`size`) ) `size`, w.code workerCode, + w.id workerFk, TIME_FORMAT(t.shipped, '%H:%i') shippedHour, TIME_FORMAT(zo.`hour`, '%H:%i') zoneHour, DATE_FORMAT(t.shipped, '%d/%m/%y') shipped, tt.labelCount, t.nickName, SUM(IF(sgd.id IS NULL, 1, 0)) + IF(sgd.id , 1, 0) lineCount, - rm.routeFk, - pc.scannableCodeType + rm.routeFk FROM vn.ticket t JOIN vn.ticketCollection tc ON tc.ticketFk = t.id JOIN vn.collection c ON c.id = tc.collectionFk From 6868863e542e208df5d63d1e8d2e5a68e7912cf0 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 2 May 2024 10:32:20 +0200 Subject: [PATCH 3/3] fix: refs #6602 refactor code --- .../reports/collection-label/collection-label.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/print/templates/reports/collection-label/collection-label.js b/print/templates/reports/collection-label/collection-label.js index fe32a0e2b..f2f697ae6 100644 --- a/print/templates/reports/collection-label/collection-label.js +++ b/print/templates/reports/collection-label/collection-label.js @@ -1,9 +1,7 @@ -const qrCode = require('qrcode'); -const jsBarcode = require('jsbarcode'); - const {DOMImplementation, XMLSerializer} = require('xmldom'); const vnReport = require('../../../core/mixins/vn-report.js'); -const {TRUE} = require('node-sass'); +const {toDataURL} = require('qrcode'); +const jsBarcode = require('jsbarcode'); module.exports = { name: 'collection-label', @@ -50,7 +48,7 @@ module.exports = { table: 'ticket', id: ticketFk }); - return qrCode.toDataURL(QRdata, {margin: 0}); + return toDataURL(QRdata, {margin: 0}); }, getBarcode(id) { const xmlSerializer = new XMLSerializer();