2024-06-28 10:57:27 +00:00
|
|
|
const vnReport = require('../../../core/mixins/vn-report.js');
|
|
|
|
const {DOMImplementation, XMLSerializer} = require('xmldom');
|
2024-08-05 09:44:20 +00:00
|
|
|
const {models} = require('vn-loopback/server/server');
|
2024-06-28 10:57:27 +00:00
|
|
|
const jsBarcode = require('jsbarcode');
|
2024-07-01 06:00:27 +00:00
|
|
|
const moment = require('moment');
|
2024-06-28 10:57:27 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2024-10-28 13:51:19 +00:00
|
|
|
name: 'buy-label-supplier',
|
2024-06-28 10:57:27 +00:00
|
|
|
mixins: [vnReport],
|
|
|
|
async serverPrefetch() {
|
2024-08-05 09:29:35 +00:00
|
|
|
const buy = await models.Buy.findById(this.id, null);
|
2024-12-05 05:56:18 +00:00
|
|
|
this.buys = await this.rawSqlFromDef('buy', [buy.entryFk, buy.entryFk, buy.entryFk, this.id, this.id]);
|
2024-07-01 06:00:27 +00:00
|
|
|
const date = new Date();
|
|
|
|
this.weekNum = moment(date).isoWeek();
|
|
|
|
this.dayNum = moment(date).day();
|
2024-06-28 10:57:27 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getBarcode(id) {
|
|
|
|
const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null);
|
|
|
|
const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
|
|
|
|
|
|
jsBarcode(svgNode, id, {
|
|
|
|
xmlDocument: document,
|
|
|
|
format: 'code128',
|
|
|
|
displayValue: false,
|
|
|
|
width: 3.8,
|
|
|
|
height: 115,
|
|
|
|
});
|
2024-07-31 06:59:33 +00:00
|
|
|
return new XMLSerializer().serializeToString(svgNode);
|
2024-12-05 05:56:18 +00:00
|
|
|
},
|
|
|
|
getTotal(buy) {
|
|
|
|
return (this.showEntryLines) ?
|
|
|
|
`${buy.entryLabelNum} / ${buy.entryLabels}` :
|
|
|
|
`${buy.buyLabelNum} / ${buy.buyLabels}`;
|
2024-06-28 10:57:27 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
id: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
description: 'The entry id'
|
2024-12-05 05:56:18 +00:00
|
|
|
},
|
|
|
|
showEntryLines: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false
|
2024-06-28 10:57:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|