const Component = require(`${appPath}/core/component`); const db = require(`${appPath}/core/database`); const reportHeader = new Component('report-header'); const reportFooter = new Component('report-footer'); module.exports = { name: 'receipt', async serverPrefetch() { this.client = await this.fetchClient(this.receiptId); this.receipt = await this.fetchReceipt(this.receiptId); if (!this.receipt) throw new Error('Something went wrong'); }, methods: { fetchClient(receiptId) { return db.findOne( `SELECT c.id, c.socialName, u.lang locale FROM receipt r JOIN client c ON c.id = r.clientFk JOIN account.user u ON u.id = c.id WHERE r.id = ?`, [receiptId]); }, fetchReceipt(receiptId) { return db.findOne( `SELECT r.id, r.amountPaid, r.amountUnpaid, r.payed, r.companyFk FROM receipt r JOIN client c ON c.id = r.clientFk WHERE r.id = ?`, [receiptId]); } }, components: { 'report-header': reportHeader.build(), 'report-footer': reportFooter.build() }, props: { receiptId: { required: true } } };