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

55 lines
1.4 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);
2024-11-27 09:40:47 +00:00
this.date = moment(this.date).format('WW/DD');
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
});
2024-11-27 09:40:47 +00:00
},
formatNumber(number) {
return new Intl.NumberFormat('es-ES', {maximumFractionDigits: 0}).format(number);
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
}
}
};