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

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-10-21 12:57:55 +00:00
const UserError = require('vn-loopback/util/user-error');
const moment = require('moment');
const qrcode = require('qrcode');
module.exports = {
name: 'buy-label-qr',
2024-10-21 12:57:55 +00:00
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');
2024-10-21 12:57:55 +00:00
},
methods: {
getQr(data) {
data = {
company: this.buys.company,
2024-10-21 12:57:55 +00:00
user: this.userId,
created: this.date,
2024-10-21 12:57:55 +00:00
table: 'buy',
id: data
};
return qrcode.toDataURL(JSON.stringify(data), {
margin: 0,
errorCorrectionLevel: 'L'
2024-10-21 12:57:55 +00:00
});
}
},
props: {
id: {
type: Number,
required: true,
description: 'The item id'
},
warehouseId: {
type: Number
},
packing: {
type: Number
},
2024-10-21 12:57:55 +00:00
copies: {
type: Number
},
userId: {
type: Number
},
typeId: {
type: String
2024-10-21 12:57:55 +00:00
}
}
};