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

62 lines
1.8 KiB
JavaScript
Executable File

const strftime = require('strftime');
const db = require(`${appPath}/lib/database`);
const Component = require(`${appPath}/lib/component`);
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);
},
created() {
/* if (this.client.locale)
this.$i18n.locale = this.client.locale; */
const embeded = [];
this.files.map(file => {
embeded[file] = `file://${__dirname + file}`;
});
this.embeded = embeded;
},
data() {
return {
files: ['/assets/images/signature.png']
};
},
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]);
},
dated: () => {
return strftime('%d-%m-%Y', new Date());
},
},
components: {
'report-header': reportHeader.build(),
'report-footer': reportFooter.build()
},
props: ['userId', 'receiptId']
};