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

77 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-11-08 13:40:38 +00:00
const jsBarcode = require('jsbarcode');
const {DOMImplementation, XMLSerializer} = require('xmldom');
2023-01-23 12:15:30 +00:00
const vnReport = require('../../../core/mixins/vn-report.js');
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]);
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]);
2023-01-23 12:15:30 +00:00
this.checkMainEntity(this.labelsData);
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;
},
2023-01-13 07:44:58 +00:00
getAgencyDescripton(labelData) {
let value;
if (labelData.agencyDescription)
value = labelData.agencyDescription.toUpperCase().substring(0, 11);
else
value = '---';
2023-03-01 11:59:46 +00:00
let routeFk = labelData.routeFk.toString();
2023-01-13 07:44:58 +00:00
if (labelData.routeFk)
2023-03-01 11:59:46 +00:00
value = `${value} [${routeFk.substring(routeFk.length - 3)}]`;
2023-01-13 07:44:58 +00:00
return value;
},
2022-11-10 13:50:08 +00:00
},
2022-11-08 13:40:38 +00:00
};