salix/print/templates/reports/collection-label/collection-label.js

97 lines
3.1 KiB
JavaScript
Raw Normal View History

2022-11-08 13:40:38 +00:00
const {DOMImplementation, XMLSerializer} = require('xmldom');
2023-01-23 12:15:30 +00:00
const vnReport = require('../../../core/mixins/vn-report.js');
2024-05-02 08:32:20 +00:00
const {toDataURL} = require('qrcode');
const jsBarcode = require('jsbarcode');
2022-10-04 08:55:13 +00:00
module.exports = {
name: 'collection-label',
2023-01-23 12:15:30 +00:00
mixins: [vnReport],
2022-11-08 13:40:38 +00:00
props: {
id: {
type: Number,
required: true,
description: 'The ticket or collection id'
},
labelCount: {
type: Number,
required: false,
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]);
if (res.length) {
ticketIds = [];
for (const row of res)
ticketIds.push(row.ticketFk);
} else
ticketIds = [this.id];
const labels = await this.rawSqlFromDef('labelsData', [ticketIds]);
const [{scannableCodeType}] = await this.rawSqlFromDef('barcodeType');
if (scannableCodeType === 'qr') {
for (const labelData of labels)
labelData.qrData = await this.getQr(labelData?.ticketFk, labelData?.workerFk);
}
this.labelsData = labels;
2023-01-23 12:15:30 +00:00
this.checkMainEntity(this.labelsData);
2022-10-04 08:55:13 +00:00
},
methods: {
async getQr(ticketFk, workerFk = null) {
const QRdata = JSON.stringify({
company: 'vnl',
user: workerFk,
created: Date.vnNew(),
table: 'ticket',
id: ticketFk
});
2024-05-02 08:32:20 +00:00
return toDataURL(QRdata, {margin: 0});
},
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)}`;
2022-11-30 09:52:52 +00:00
} else
value = '-'.repeat(19);
2022-11-30 07:18:37 +00:00
return value;
},
getAgencyDescription(labelData) {
2023-01-13 07:44:58 +00:00
let value;
if (labelData.agencyDescription)
value = labelData.agencyDescription.toUpperCase().substring(0, 11);
2023-03-01 13:03:47 +00:00
if (labelData.routeFk) {
let routeFk = labelData.routeFk.toString();
2023-03-01 11:59:46 +00:00
value = `${value} [${routeFk.substring(routeFk.length - 3)}]`;
2023-03-01 13:03:47 +00:00
}
2023-01-13 07:44:58 +00:00
return value;
},
dashIfEmpty(value) {
return value || '---';
}
2022-11-10 13:50:08 +00:00
},
2022-11-08 13:40:38 +00:00
};