47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
|
const Component = require(`vn-print/core/component`);
|
||
|
const reportBody = new Component('report-body');
|
||
|
const UserError = require('vn-loopback/util/user-error');
|
||
|
const qrcode = require('qrcode');
|
||
|
|
||
|
module.exports = {
|
||
|
name: 'expedition-pallet-label',
|
||
|
props: {
|
||
|
id: {
|
||
|
type: Number,
|
||
|
required: true,
|
||
|
description: 'The pallet id'
|
||
|
},
|
||
|
userFk: {
|
||
|
type: Number,
|
||
|
required: true,
|
||
|
description: 'The user id'
|
||
|
}
|
||
|
},
|
||
|
async serverPrefetch() {
|
||
|
this.labelsData = await this.rawSqlFromDef('labelData', this.id);
|
||
|
this.username = await this.findOneFromDef('username', this.userFk);
|
||
|
this.labelData = this.labelsData[0];
|
||
|
|
||
|
let QRdata = JSON.stringify({
|
||
|
company: 'vnl',
|
||
|
user: null,
|
||
|
created: new Date(),
|
||
|
table: 'expeditionPallet',
|
||
|
id: this.id
|
||
|
});
|
||
|
|
||
|
this.QR = await this.getQR(QRdata);
|
||
|
if (!this.labelsData.length)
|
||
|
throw new UserError('Empty data source');
|
||
|
},
|
||
|
methods: {
|
||
|
getQR(id) {
|
||
|
const data = String(id);
|
||
|
return qrcode.toDataURL(data, {margin: 0});
|
||
|
},
|
||
|
},
|
||
|
components: {
|
||
|
'report-body': reportBody.build()
|
||
|
},
|
||
|
};
|