salix/print/templates/reports/buy-label-qr/buy-label-qr.js

52 lines
1.3 KiB
JavaScript
Executable File

const UserError = require('vn-loopback/util/user-error');
const moment = require('moment');
const qrcode = require('qrcode');
module.exports = {
name: 'buy-label-qr',
async serverPrefetch() {
this.date = Date.vnNew();
this.buys = await this.rawSqlFromDef('buy', [this.copies || 1, this.id]);
if (!this.buys.length) throw new UserError(`Empty data source`);
this.qr = await this.getQr(this.buys[0].buyFk);
this.date = moment(this.date).format('WW/E');
},
methods: {
getQr(data) {
data = {
company: this.buys.company,
user: this.userId,
created: this.date,
table: 'buy',
id: data
};
return qrcode.toDataURL(JSON.stringify(data), {
margin: 0,
errorCorrectionLevel: 'L'
});
}
},
props: {
id: {
type: Number,
required: true,
description: 'The item id'
},
warehouseId: {
type: Number
},
packing: {
type: Number
},
copies: {
type: Number
},
userId: {
type: Number
},
typeId: {
type: String
}
}
};