salix/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js

58 lines
1.8 KiB
JavaScript

const vnReport = require('../../../core/mixins/vn-report.js');
const jsBarcode = require('jsbarcode');
const {DOMImplementation, XMLSerializer} = require('xmldom');
const qrcode = require('qrcode');
module.exports = {
name: 'expedition-pallet-label',
mixins: [vnReport],
props: {
id: {
type: Number,
required: true,
description: 'The pallet id'
},
userFk: {
type: Number,
description: 'The user id'
}
},
async serverPrefetch() {
this.username = null;
this.labelsData = await this.rawSqlFromDef('labelData', this.id);
if (this.userFk) this.username = await this.findOneFromDef('username', this.userFk);
this.labelData = this.labelsData[0];
this.checkMainEntity(this.labelData);
let QRdata = JSON.stringify({
company: 'vnl',
user: this.userFk,
created: Date.vnNew(),
table: 'expeditionPallet',
id: this.id
});
this.QR = await this.getQR(QRdata);
},
methods: {
getQR(id) {
const data = String(id);
return qrcode.toDataURL(data, {margin: 0});
},
getBarcode(id) {
const xmlSerializer = new XMLSerializer();
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: 6,
height: 90,
});
return xmlSerializer.serializeToString(svgNode);
},
},
};