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-12-13 17:05:29 +00:00
|
|
|
},
|
|
|
|
labelCount: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
description: 'The number of labels'
|
2022-11-08 13:40:38 +00:00
|
|
|
}
|
|
|
|
},
|
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,
|
2022-11-29 07:22:32 +00:00
|
|
|
height: 115,
|
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-30 09:52:52 +00:00
|
|
|
getVertical(labelData) {
|
2022-11-30 07:18:37 +00:00
|
|
|
let value;
|
2022-11-30 09:52:52 +00:00
|
|
|
if (labelData.collectionFk) {
|
|
|
|
value = `${labelData.collectionFk} ~ `;
|
|
|
|
if (labelData.code == 'V')
|
|
|
|
value = value + `${labelData.wagon}-${labelData.level}`;
|
|
|
|
else
|
|
|
|
value = value + `${labelData.color.substring(0, 4)}`;
|
|
|
|
} else
|
|
|
|
value = '-'.repeat(19);
|
|
|
|
|
2022-11-30 07:18:37 +00:00
|
|
|
return value;
|
|
|
|
},
|
2022-11-10 13:50:08 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
'report-body': reportBody.build()
|
|
|
|
},
|
2022-11-08 13:40:38 +00:00
|
|
|
};
|