salix/print/templates/email/delivery-note/delivery-note.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-10-29 06:46:44 +00:00
const db = require(`${appPath}/lib/database`);
const Component = require(`${appPath}/lib/component`);
const emailHeader = new Component('email-header');
const emailFooter = new Component('email-footer');
2019-09-06 09:06:44 +00:00
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() {
2019-10-29 06:46:44 +00:00
this.locale = 'es';
2019-09-06 09:06:44 +00:00
},
methods: {
2019-10-29 06:46:44 +00:00
fetchTicket(ticketId) {
return db.findOne(`
2019-09-06 09:06:44 +00:00
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
2019-10-29 06:46:44 +00:00
WHERE t.id = ?`, [ticketId]);
2019-09-06 09:06:44 +00:00
},
},
components: {
2019-10-29 06:46:44 +00:00
'email-header': emailHeader.build(),
'email-footer': emailFooter.build()
2019-09-06 09:06:44 +00:00
},
2019-10-29 06:46:44 +00:00
props: ['ticketId', 'isPreview']
2019-09-06 09:06:44 +00:00
};