salix/print/report/letter-debtor-nd/index.js

59 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-01-22 08:55:35 +00:00
const database = require(`${appPath}/lib/database`);
const reportEngine = require(`${appPath}/lib/reportEngine.js`);
2019-01-22 08:55:35 +00:00
const UserException = require(`${appPath}/lib/exceptions/userException`);
module.exports = {
name: 'letter-debtor-nd',
async asyncData(ctx, params) {
const promises = [];
2019-01-22 08:55:35 +00:00
const data = {
isPreview: ctx.method === 'GET',
};
if (!params.clientFk)
throw new UserException('No client id specified');
2019-01-23 08:33:58 +00:00
if (!params.companyFk)
throw new UserException('No company id specified');
promises.push(reportEngine.toPdf('rpt-letter-debtor', ctx));
promises.push(this.methods.fetchClient(params.clientFk, params.companyFk));
return Promise.all(promises).then(result => {
const stream = result[0];
const [[client]] = result[1];
Object.assign(data, client);
Object.assign(data, {attachments: [{filename: 'rpt-letter-debtor.pdf', content: stream}]});
return data;
});
2019-01-22 08:55:35 +00:00
},
created() {
2019-02-05 06:58:05 +00:00
if (this.locale)
this.$i18n.locale = this.locale;
2019-01-22 08:55:35 +00:00
},
methods: {
fetchClient(clientFk, companyFk) {
2019-01-22 08:55:35 +00:00
return database.pool.query(`
SELECT
u.lang locale,
c.email recipient,
c.dueDay,
c.iban,
sa.iban,
be.name AS bankName
FROM client c
JOIN company AS cny
JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk
JOIN bankEntity be ON be.id = sa.bankEntityFk
JOIN account.user u ON u.id = c.id
WHERE c.id = ? AND cny.id = ?`, [clientFk, companyFk]);
},
},
components: {
'email-header': require('../email-header'),
'email-footer': require('../email-footer'),
2019-01-22 08:55:35 +00:00
},
};