2019-10-29 06:46:44 +00:00
|
|
|
const Component = require(`${appPath}/core/component`);
|
2019-11-07 10:19:05 +00:00
|
|
|
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');
|
2019-01-24 14:03:01 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2019-10-31 11:43:04 +00:00
|
|
|
name: 'claim-pickup-order',
|
2019-10-29 06:46:44 +00:00
|
|
|
async serverPrefetch() {
|
2019-10-31 11:43:04 +00:00
|
|
|
this.client = await this.fetchClient(this.claimId);
|
2019-10-29 06:46:44 +00:00
|
|
|
this.sales = await this.fetchSales(this.claimId);
|
2019-10-31 11:43:04 +00:00
|
|
|
|
|
|
|
if (!this.client)
|
|
|
|
throw new Error('Something went wrong');
|
2019-01-24 14:03:01 +00:00
|
|
|
},
|
2019-10-31 11:43:04 +00:00
|
|
|
computed: {
|
|
|
|
currentDate: function() {
|
|
|
|
const filters = this.$options.filters;
|
|
|
|
|
|
|
|
return filters.date(new Date(), '%d-%m-%Y');
|
|
|
|
}
|
2019-01-24 14:03:01 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2019-10-31 11:43:04 +00:00
|
|
|
fetchClient(claimId) {
|
2019-10-29 06:46:44 +00:00
|
|
|
return db.findOne(
|
2019-01-24 14:03:01 +00:00
|
|
|
`SELECT
|
2019-10-31 11:43:04 +00:00
|
|
|
c.id,
|
2019-01-24 14:03:01 +00:00
|
|
|
c.socialName,
|
2019-10-31 11:43:04 +00:00
|
|
|
c.name,
|
2019-01-24 14:03:01 +00:00
|
|
|
c.fi,
|
2019-09-24 10:08:21 +00:00
|
|
|
a.city,
|
|
|
|
a.postalCode,
|
|
|
|
a.street,
|
|
|
|
a.nickname,
|
2019-01-24 14:03:01 +00:00
|
|
|
p.name AS province,
|
|
|
|
ct.country
|
|
|
|
FROM claim cl
|
|
|
|
JOIN client c ON c.id = cl.clientFk
|
|
|
|
JOIN account.user u ON u.id = c.id
|
|
|
|
JOIN country ct ON ct.id = c.countryFk
|
2019-09-24 10:08:21 +00:00
|
|
|
JOIN ticket t ON t.id = cl.ticketFk
|
|
|
|
JOIN address a ON a.id = t.addressFk
|
2019-01-24 14:03:01 +00:00
|
|
|
LEFT JOIN province p ON p.id = c.provinceFk
|
2019-10-29 06:46:44 +00:00
|
|
|
WHERE cl.id = ?`, [claimId]);
|
2019-01-24 14:03:01 +00:00
|
|
|
},
|
2019-10-29 06:46:44 +00:00
|
|
|
fetchSales(claimId) {
|
2019-11-18 14:04:51 +00:00
|
|
|
return db.rawSql(
|
2019-01-24 14:03:01 +00:00
|
|
|
`SELECT
|
|
|
|
s.id,
|
|
|
|
s.quantity,
|
|
|
|
s.concept,
|
|
|
|
cb.quantity claimQuantity
|
|
|
|
FROM claimBeginning cb
|
|
|
|
JOIN sale s ON s.id = cb.saleFk
|
2019-10-29 06:46:44 +00:00
|
|
|
WHERE cb.claimFk = ?`, [claimId]);
|
2019-01-24 14:03:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
components: {
|
2019-10-29 06:46:44 +00:00
|
|
|
'report-header': reportHeader.build(),
|
|
|
|
'report-footer': reportFooter.build()
|
2019-01-24 14:03:01 +00:00
|
|
|
},
|
2019-10-31 11:43:04 +00:00
|
|
|
props: {
|
|
|
|
claimId: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
2019-01-24 14:03:01 +00:00
|
|
|
};
|