From 1a2ed9ce68cef8d172148c76adb0d2cfd78efcd7 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 31 Jul 2024 11:33:12 +0200 Subject: [PATCH] refactor: refs #7644 Optimized barcode --- .../templates/reports/buy-label/buy-label.js | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/print/templates/reports/buy-label/buy-label.js b/print/templates/reports/buy-label/buy-label.js index 48ffe336c..18f71c772 100755 --- a/print/templates/reports/buy-label/buy-label.js +++ b/print/templates/reports/buy-label/buy-label.js @@ -12,20 +12,28 @@ module.exports = { const date = new Date(); this.weekNum = moment(date).isoWeek(); this.dayNum = moment(date).day(); + this.barcodes = []; + await this.generateAllBarcodes(this.buys); }, methods: { - getBarcode(id) { - const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null); - const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); + generateAllBarcodes(buys) { + const uniqueBuyIds = new Set(buys.map(buy => buy.id)); + for (let buy of uniqueBuyIds) { + const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null); + const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); - jsBarcode(svgNode, id, { - xmlDocument: document, - format: 'code128', - displayValue: false, - width: 3.8, - height: 115, - }); - return new XMLSerializer().serializeToString(svgNode); + jsBarcode(svgNode, buy, { + xmlDocument: document, + format: 'code128', + displayValue: false, + width: 3.8, + height: 115, + }); + this.barcodes.push({id: buy, barcode: new XMLSerializer().serializeToString(svgNode)}); + } + }, + getBarcode(id) { + return this.barcodes.find(item => item.id === id).barcode; } }, props: {