2024-05-02 08:25:46 +00:00
|
|
|
const qrCode = require('qrcode');
|
|
|
|
const jsBarcode = require('jsbarcode');
|
2024-04-12 06:48:29 +00:00
|
|
|
|
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:25:46 +00:00
|
|
|
const {TRUE} = require('node-sass');
|
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'
|
2022-12-13 17:05:29 +00:00
|
|
|
},
|
|
|
|
labelCount: {
|
|
|
|
type: Number,
|
2022-12-14 15:15:41 +00:00
|
|
|
required: false,
|
2022-12-13 17:05:29 +00:00
|
|
|
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];
|
|
|
|
|
2024-05-02 08:25:46 +00:00
|
|
|
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: {
|
2024-05-02 08:25:46 +00:00
|
|
|
async getQr(ticketFk, workerFk = null) {
|
|
|
|
const QRdata = JSON.stringify({
|
2024-04-12 06:48:29 +00:00
|
|
|
company: 'vnl',
|
2024-05-02 08:25:46 +00:00
|
|
|
user: workerFk,
|
2024-04-12 06:48:29 +00:00
|
|
|
created: Date.vnNew(),
|
|
|
|
table: 'ticket',
|
2024-05-02 08:25:46 +00:00
|
|
|
id: ticketFk
|
2024-04-12 06:48:29 +00:00
|
|
|
});
|
2024-05-02 08:25:46 +00:00
|
|
|
return qrCode.toDataURL(QRdata, {margin: 0});
|
2024-04-12 06:48:29 +00:00
|
|
|
},
|
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
|
2024-05-02 08:25:46 +00:00
|
|
|
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;
|
|
|
|
},
|
2024-05-02 08:25:46 +00:00
|
|
|
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;
|
|
|
|
},
|
2024-05-02 08:25:46 +00:00
|
|
|
dashIfEmpty(value) {
|
|
|
|
return value || '---';
|
|
|
|
}
|
2022-11-10 13:50:08 +00:00
|
|
|
},
|
2022-11-08 13:40:38 +00:00
|
|
|
};
|