38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
const config = require(`vn-print/core/config`);
|
|
const vnReport = require('../../../core/mixins/vn-report.js');
|
|
const md5 = require('md5');
|
|
const fs = require('fs-extra');
|
|
|
|
module.exports = {
|
|
name: 'cmr',
|
|
mixins: [vnReport],
|
|
async serverPrefetch() {
|
|
this.data = await this.findOneFromDef('data', [this.id]);
|
|
if (this.data.ticketFk) {
|
|
this.merchandises = await this.rawSqlFromDef('merchandise', [this.data.ticketFk]);
|
|
this.signatures = await this.findOneFromDef('signatures', [this.data.ticketFk]);
|
|
}
|
|
},
|
|
props: {
|
|
id: {
|
|
type: Number,
|
|
required: true,
|
|
description: 'The cmr id'
|
|
},
|
|
},
|
|
methods: {
|
|
dmsPath(isClient) {
|
|
if (!this.signatures) return;
|
|
|
|
const signatureName = (isClient)
|
|
? this.signatures.clientSignature
|
|
: this.signatures.deliverySignature;
|
|
const hash = md5(signatureName.toString()).substring(0, 3);
|
|
const file = `${config.storage.root}/${hash}/${signatureName}.png`;
|
|
|
|
if (!fs.existsSync(file)) return null;
|
|
|
|
return `data:image/png;base64, ${Buffer.from(fs.readFileSync(file), 'utf8').toString('base64')}`;
|
|
}
|
|
}
|
|
}; |