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

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-10-22 11:43:54 +00:00
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',
2024-10-22 11:43:54 +00:00
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`);
2024-11-27 09:40:47 +00:00
this.date = moment(this.date).format('WW/DD');
2024-10-22 11:43:54 +00:00
},
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,
2024-10-23 07:46:06 +00:00
width: 3.8,
2024-11-27 11:58:32 +00:00
height: 80,
2024-10-22 11:43:54 +00:00
margin: 0
});
return new XMLSerializer().serializeToString(svgNode);
2024-11-27 09:40:47 +00:00
},
formatNumber(number) {
return new Intl.NumberFormat('es-ES', {maximumFractionDigits: 0}).format(number);
2024-10-22 11:43:54 +00:00
}
},
props: {
id: {
type: Number,
required: true,
description: 'The item id'
},
warehouseId: {
type: Number
},
packing: {
type: Number
},
copies: {
type: Number
},
typeId: {
type: String
2024-10-22 11:43:54 +00:00
}
}
};