salix/print/templates/reports/receipt/receipt.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-10-31 11:43:04 +00:00
const Component = require(`${appPath}/core/component`);
const db = require(`${appPath}/core/database`);
2019-10-29 06:46:44 +00:00
const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer');
module.exports = {
2019-10-24 05:41:54 +00:00
name: 'receipt',
async serverPrefetch() {
this.client = await this.fetchClient(this.receiptId);
this.receipt = await this.fetchReceipt(this.receiptId);
2019-10-31 11:43:04 +00:00
if (!this.receipt)
throw new Error('Something went wrong');
},
methods: {
2019-10-24 05:41:54 +00:00
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
2019-10-24 05:41:54 +00:00
WHERE r.id = ?`, [receiptId]);
},
2019-10-24 05:41:54 +00:00
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
2019-10-24 05:41:54 +00:00
WHERE r.id = ?`, [receiptId]);
2019-10-31 11:43:04 +00:00
}
2019-10-29 06:46:44 +00:00
},
components: {
'report-header': reportHeader.build(),
'report-footer': reportFooter.build()
},
2019-10-31 11:43:04 +00:00
props: {
receiptId: {
required: true
}
}
};