salix/print/report/payment-update/index.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-01-22 08:55:35 +00:00
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: 'payment-update',
async asyncData(ctx, params) {
const data = {
isPreview: ctx.method === 'GET',
};
if (!params.clientFk)
throw new UserException('No client id specified');
2019-02-04 09:10:57 +00:00
return this.methods.fetchClient(params.clientFk)
2019-01-22 08:55:35 +00:00
.then(([result]) => {
2019-01-25 14:08:11 +00:00
if (!result)
throw new UserException('No client data found');
2019-01-22 08:55:35 +00:00
return Object.assign(data, result[0]);
});
},
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: {
2019-02-04 09:10:57 +00:00
fetchClient(clientFk) {
2019-01-22 08:55:35 +00:00
return database.pool.query(`
SELECT
u.lang locale,
c.email recipient,
c.dueDay,
c.iban,
pm.id payMethodFk,
pm.name payMethodName
FROM client c
JOIN payMethod pm ON pm.id = c.payMethodFk
JOIN account.user u ON u.id = c.id
WHERE c.id = ?`, [clientFk]);
},
},
computed: {
accountAddress: function() {
return this.iban.slice(-4);
},
},
components: {
'email-header': emailHeader,
'email-footer': emailFooter,
},
};