51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
|
const database = require(`${appPath}/lib/database`);
|
||
|
const reportEngine = require(`${appPath}/lib/reportEngine.js`);
|
||
|
const UserException = require(`${appPath}/lib/exceptions/userException`);
|
||
|
|
||
|
module.exports = {
|
||
|
name: 'delivery-note',
|
||
|
async asyncData(ctx, params) {
|
||
|
const promises = [];
|
||
|
const data = {
|
||
|
isPreview: ctx.method === 'GET',
|
||
|
};
|
||
|
|
||
|
if (!params.ticketFk)
|
||
|
throw new UserException('No ticket id specified');
|
||
|
|
||
|
promises.push(reportEngine.toPdf('rpt-delivery-note', ctx));
|
||
|
promises.push(this.methods.fetchTicket(params.ticketFk));
|
||
|
|
||
|
return Promise.all(promises).then(result => {
|
||
|
const stream = result[0];
|
||
|
const [[ticket]] = result[1];
|
||
|
|
||
|
Object.assign(data, ticket);
|
||
|
Object.assign(data, {attachments: [{filename: 'rpt-delivery-note.pdf', content: stream}]});
|
||
|
|
||
|
return data;
|
||
|
});
|
||
|
},
|
||
|
created() {
|
||
|
if (this.locale)
|
||
|
this.$i18n.locale = this.locale;
|
||
|
},
|
||
|
methods: {
|
||
|
fetchTicket(ticketFk) {
|
||
|
return database.pool.query(`
|
||
|
SELECT
|
||
|
t.id,
|
||
|
u.lang locale,
|
||
|
c.email recipient
|
||
|
FROM ticket t
|
||
|
JOIN client c ON c.id = t.clientFk
|
||
|
JOIN account.user u ON u.id = c.id
|
||
|
WHERE t.id = ?`, [ticketFk]);
|
||
|
},
|
||
|
},
|
||
|
components: {
|
||
|
'email-header': require('../email-header'),
|
||
|
'email-footer': require('../email-footer'),
|
||
|
},
|
||
|
};
|