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

41 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-10-04 08:55:13 +00:00
const Component = require(`${appPath}/core/component`);
const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer');
const qrcode = require('qrcode');
module.exports = {
name: 'collection-label',
async serverPrefetch() {
2022-10-04 11:06:59 +00:00
this.isCollection = await this.isCollection(this.param);
this.tags = await this.fetchCollectionTicket(this.isCollection, this.param, this.param);
this.barcode = await this.getBarcodeBase64(this.param);
2022-10-04 08:55:13 +00:00
2022-10-04 11:06:59 +00:00
if (!this.tags)
2022-10-04 08:55:13 +00:00
throw new Error('Something went wrong');
},
methods: {
2022-10-04 11:06:59 +00:00
isCollection(param) {
return this.findOneFromDef('isCollection', [param]);
2022-10-04 08:55:13 +00:00
},
2022-10-04 11:06:59 +00:00
fetchCollectionTicket(isCollection, param, param) {
return this.rawSqlFromDef('collectionTicket', [isCollection, param, param]).then(rows => {
2022-10-04 08:55:13 +00:00
const tags = {};
rows.forEach(row => tags[row.code] = row.value);
return tags;
});
},
2022-10-04 11:06:59 +00:00
getBarcodeBase64(param) {
return qrcode.toDataURL(param, {margin: 0});
2022-10-04 08:55:13 +00:00
}
},
components: {
'report-header': reportHeader.build(),
'report-footer': reportFooter.build()
},
props: {
2022-10-04 11:06:59 +00:00
param: {
2022-10-04 08:55:13 +00:00
required: true
}
}
2022-10-04 11:06:59 +00:00
};