2022-11-10 13:50:08 +00:00
|
|
|
const Component = require(`vn-print/core/component`);
|
|
|
|
const reportBody = new Component('report-body');
|
2022-11-08 13:40:38 +00:00
|
|
|
const jsBarcode = require('jsbarcode');
|
|
|
|
const {DOMImplementation, XMLSerializer} = require('xmldom');
|
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
2022-10-04 08:55:13 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'collection-label',
|
2022-11-08 13:40:38 +00:00
|
|
|
props: {
|
|
|
|
id: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
description: 'The ticket or collection id'
|
|
|
|
}
|
|
|
|
},
|
2022-10-04 08:55:13 +00:00
|
|
|
async serverPrefetch() {
|
2022-11-08 13:40:38 +00:00
|
|
|
let ticketIds;
|
|
|
|
const res = await this.rawSqlFromDef('tickets', [this.id]);
|
2022-10-04 08:55:13 +00:00
|
|
|
|
2022-11-08 13:40:38 +00:00
|
|
|
if (res.length) {
|
|
|
|
ticketIds = [];
|
|
|
|
for (const row of res)
|
|
|
|
ticketIds.push(row.ticketFk);
|
|
|
|
} else
|
|
|
|
ticketIds = [this.id];
|
|
|
|
|
|
|
|
this.labelsData = await this.rawSqlFromDef('labelsData', [ticketIds]);
|
|
|
|
|
|
|
|
if (!this.labelsData.length)
|
|
|
|
throw new UserError('Empty data source');
|
2022-10-04 08:55:13 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2022-11-08 13:40:38 +00:00
|
|
|
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');
|
2022-10-04 08:55:13 +00:00
|
|
|
|
2022-11-08 13:40:38 +00:00
|
|
|
jsBarcode(svgNode, id, {
|
|
|
|
xmlDocument: document,
|
|
|
|
format: 'code128',
|
|
|
|
displayValue: false,
|
|
|
|
width: 3.8,
|
|
|
|
height: 110,
|
2022-10-04 08:55:13 +00:00
|
|
|
});
|
2022-11-08 13:40:38 +00:00
|
|
|
return xmlSerializer.serializeToString(svgNode);
|
2022-10-04 08:55:13 +00:00
|
|
|
},
|
2022-11-10 13:50:08 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
'report-body': reportBody.build()
|
|
|
|
},
|
2022-11-08 13:40:38 +00:00
|
|
|
};
|