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

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-11-21 12:31:55 +00:00
const Component = require(`vn-print/core/component`);
const reportBody = new Component('report-body');
const qrcode = require('qrcode');
2022-12-22 07:00:18 +00:00
const UserError = require('vn-loopback/util/user-error');
2022-11-21 12:31:55 +00:00
module.exports = {
name: 'previa-label',
async serverPrefetch() {
this.previa = await this.fetchPrevia(this.id);
this.sector = await this.fetchSector(this.id);
this.barcode = await this.getBarcodeBase64(this.id);
2022-12-22 07:00:18 +00:00
if (this.previa)
this.previa = this.previa[0];
2022-11-21 12:31:55 +00:00
if (!this.sector)
2022-12-22 07:00:18 +00:00
throw new UserError('Something went wrong - no sector found');
2022-11-21 12:31:55 +00:00
},
methods: {
fetchPrevia(id) {
return this.findOneFromDef('previa', [id]);
},
getBarcodeBase64(id) {
const data = String(id);
return qrcode.toDataURL(data, {margin: 0});
},
fetchSector(id) {
return this.findOneFromDef('sector', [id]);
}
},
components: {
'report-body': reportBody.build()
},
props: {
id: {
type: Number,
required: true,
description: 'The saleGroupFk id'
},
}
};