2019-03-05 13:59:18 +00:00
|
|
|
const strftime = require('strftime');
|
2019-10-24 05:41:54 +00:00
|
|
|
const db = require(`${appPath}/lib/database`);
|
2019-10-29 06:46:44 +00:00
|
|
|
const Component = require(`${appPath}/lib/component`);
|
|
|
|
const reportHeader = new Component('report-header');
|
|
|
|
const reportFooter = new Component('report-footer');
|
2019-03-05 13:59:18 +00:00
|
|
|
|
|
|
|
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-03-05 13:59:18 +00:00
|
|
|
},
|
|
|
|
created() {
|
2019-10-16 06:39:45 +00:00
|
|
|
/* if (this.client.locale)
|
|
|
|
this.$i18n.locale = this.client.locale; */
|
2019-03-05 13:59:18 +00:00
|
|
|
|
|
|
|
const embeded = [];
|
|
|
|
this.files.map(file => {
|
|
|
|
embeded[file] = `file://${__dirname + file}`;
|
|
|
|
});
|
|
|
|
this.embeded = embeded;
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
files: ['/assets/images/signature.png']
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
2019-10-24 05:41:54 +00:00
|
|
|
fetchClient(receiptId) {
|
|
|
|
return db.findOne(
|
2019-03-05 13:59:18 +00:00
|
|
|
`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-03-05 13:59:18 +00:00
|
|
|
},
|
2019-10-24 05:41:54 +00:00
|
|
|
fetchReceipt(receiptId) {
|
|
|
|
return db.findOne(
|
2019-03-05 13:59:18 +00:00
|
|
|
`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-29 06:46:44 +00:00
|
|
|
},
|
|
|
|
dated: () => {
|
2019-03-05 13:59:18 +00:00
|
|
|
return strftime('%d-%m-%Y', new Date());
|
2019-10-29 06:46:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
'report-header': reportHeader.build(),
|
|
|
|
'report-footer': reportFooter.build()
|
2019-03-05 13:59:18 +00:00
|
|
|
},
|
2019-10-24 05:41:54 +00:00
|
|
|
props: ['userId', 'receiptId']
|
2019-03-05 13:59:18 +00:00
|
|
|
};
|