2019-01-25 14:08:11 +00:00
|
|
|
const UserException = require(`${appPath}/lib/exceptions/userException`);
|
|
|
|
const reportEngine = require(`${appPath}/lib/reportEngine`);
|
|
|
|
const database = require(`${appPath}/lib/database`);
|
|
|
|
const emailHeader = require('../email-header');
|
|
|
|
const emailFooter = require('../email-footer');
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'claim-pickup-order',
|
|
|
|
async asyncData(ctx, params) {
|
|
|
|
const promises = [];
|
|
|
|
const data = {
|
|
|
|
isPreview: ctx.method === 'GET',
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!params.claimFk)
|
|
|
|
throw new UserException('No claim id specified');
|
|
|
|
|
|
|
|
promises.push(reportEngine.toPdf('rpt-claim-pickup-order', ctx));
|
|
|
|
promises.push(this.methods.fetchClient(params.claimFk));
|
|
|
|
|
|
|
|
return Promise.all(promises).then(result => {
|
|
|
|
const stream = result[0];
|
|
|
|
const [[client]] = result[1];
|
|
|
|
|
|
|
|
Object.assign(data, client);
|
|
|
|
Object.assign(data, {attachments: [{filename: 'claim-pickup-order.pdf', content: stream}]});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
created() {
|
2019-02-05 06:58:05 +00:00
|
|
|
if (this.locale)
|
|
|
|
this.$i18n.locale = this.locale;
|
2019-01-25 14:08:11 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
fetchClient(claimFk) {
|
|
|
|
return database.pool.query(`
|
|
|
|
SELECT
|
|
|
|
c.id,
|
|
|
|
u.lang locale,
|
|
|
|
c.email recipient
|
|
|
|
FROM claim cl
|
|
|
|
JOIN client c ON c.id = cl.clientFk
|
|
|
|
JOIN account.user u ON u.id = c.id
|
|
|
|
WHERE cl.id = ?`, [claimFk]);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
emailHeader,
|
|
|
|
emailFooter,
|
|
|
|
},
|
|
|
|
};
|