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

62 lines
1.9 KiB
JavaScript
Executable File

const database = require(`${appPath}/lib/database`);
const emailHeader = require('../email-header');
const emailFooter = require('../email-footer');
const UserException = require(`${appPath}/lib/exceptions/userException`);
module.exports = {
name: 'letter-debtor-st',
async asyncData(ctx, params) {
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');
return this.methods.fetchClientData(params.clientFk, params.companyFk)
.then(([[result]]) => {
if (!result) throw new UserException('Client data not found');
return Object.assign(data, result);
});
},
created() {
this.$i18n.locale = this.locale;
},
data() {
return {
attachments: ['http://localhost:5000/report/delivery-note'],
};
},
methods: {
fetchClientData(clientFk, companyFk) {
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]);
},
},
computed: {
accountAddress: function() {
return this.iban.slice(-4);
},
},
components: {
'email-header': emailHeader,
'email-footer': emailFooter,
},
};