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

78 lines
2.3 KiB
JavaScript

const vnReport = require('../../../core/mixins/vn-report.js');
const {toDataURL} = require('qrcode');
module.exports = {
name: 'collection-label',
mixins: [vnReport],
props: {
id: {
type: Number,
required: true,
description: 'The ticket or collection id'
},
labelCount: {
type: Number,
required: false,
description: 'The number of labels'
}
},
async serverPrefetch() {
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]);
for (const labelData of labels)
labelData.qrData = await this.getQr(labelData?.ticketFk, labelData?.workerFk);
this.labelsData = labels;
this.checkMainEntity(this.labelsData);
},
methods: {
async getQr(ticketFk, workerFk = null) {
const QRdata = JSON.stringify({
company: 'vnl',
user: workerFk,
created: Date.vnNew(),
table: 'ticket',
id: ticketFk
});
return toDataURL(QRdata, {margin: 0});
},
getVertical(labelData) {
let value;
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);
return value;
},
getAgencyDescription(labelData) {
let value;
if (labelData.agencyDescription)
value = labelData.agencyDescription.toUpperCase().substring(0, 11);
if (labelData.routeFk) {
let routeFk = labelData.routeFk.toString();
value = `${value} [${routeFk.substring(routeFk.length - 3)}]`;
}
return value;
},
dashIfEmpty(value) {
return value || '---';
}
},
};