52 lines
1.5 KiB
JavaScript
Executable File
52 lines
1.5 KiB
JavaScript
Executable File
const db = require(`${appPath}/lib/database`);
|
|
const Component = require(`${appPath}/lib/component`);
|
|
const emailHeader = new Component('email-header');
|
|
const emailFooter = new Component('email-footer');
|
|
|
|
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() {
|
|
this.locale = 'es';
|
|
},
|
|
methods: {
|
|
fetchTicket(ticketId) {
|
|
return db.findOne(`
|
|
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 = ?`, [ticketId]);
|
|
},
|
|
},
|
|
components: {
|
|
'email-header': emailHeader.build(),
|
|
'email-footer': emailFooter.build()
|
|
},
|
|
props: ['ticketId', 'isPreview']
|
|
};
|