salix/print/templates/reports/buy-label-barcode/buy-label-barcode.js

50 lines
1.4 KiB
JavaScript
Executable File

const UserError = require('vn-loopback/util/user-error');
const {DOMImplementation, XMLSerializer} = require('xmldom');
const moment = require('moment');
const jsbarcode = require('jsbarcode');
module.exports = {
name: 'buy-label-barcode',
async serverPrefetch() {
this.date = Date.vnNew();
this.buys = await this.rawSqlFromDef('buy', [this.copies || 1, this.id]);
if (!this.buys.length) throw new UserError(`Empty data source`);
this.date = moment(this.date).format('WW/E');
},
methods: {
getBarcode(data) {
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, data, {
xmlDocument: document,
format: 'code128',
displayValue: false,
width: 3.8,
height: 85,
margin: 0
});
return new XMLSerializer().serializeToString(svgNode);
}
},
props: {
id: {
type: Number,
required: true,
description: 'The item id'
},
warehouseId: {
type: Number
},
packing: {
type: Number
},
copies: {
type: Number
},
typeId: {
type: String
}
}
};