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

66 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-01-22 08:55:35 +00:00
const database = require(`${appPath}/lib/database`);
2019-01-23 08:33:58 +00:00
const reportEngine = require(`${appPath}/lib/reportEngine.js`);
2019-01-22 08:55:35 +00:00
const emailHeader = require('../email-header');
const emailFooter = require('../email-footer');
const UserException = require(`${appPath}/lib/exceptions/userException`);
2019-01-23 08:33:58 +00:00
2019-01-22 08:55:35 +00:00
module.exports = {
name: 'letter-debtor-st',
async asyncData(ctx, params) {
2019-01-23 08:33:58 +00:00
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');
if (!params.companyFk)
throw new UserException('No company id specified');
2019-01-23 08:33:58 +00:00
promises.push(reportEngine.toPdf('delivery-note', 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: 'delivery-note.pdf', content: stream}]});
2019-01-22 08:55:35 +00:00
2019-01-23 08:33:58 +00:00
return data;
});
2019-01-22 08:55:35 +00:00
},
created() {
this.$i18n.locale = this.locale;
},
methods: {
2019-01-23 08:33:58 +00:00
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]);
2019-01-23 08:33:58 +00:00
}
2019-01-22 08:55:35 +00:00
},
computed: {
accountAddress: function() {
return this.iban.slice(-4);
},
},
components: {
'email-header': emailHeader,
'email-footer': emailFooter,
},
};