77 lines
2.4 KiB
JavaScript
Executable File
77 lines
2.4 KiB
JavaScript
Executable File
const strftime = require('strftime');
|
|
const database = require(`${appPath}/lib/database`);
|
|
const UserException = require(`${appPath}/lib/exceptions/userException`);
|
|
|
|
module.exports = {
|
|
name: 'rpt-claim-pickup-order',
|
|
async asyncData(ctx, params) {
|
|
const promises = [];
|
|
const data = {};
|
|
|
|
if (!params.claimFk)
|
|
throw new UserException('No claim id specified');
|
|
|
|
promises.push(this.methods.fetchClaim(params.claimFk));
|
|
promises.push(this.methods.fetchSales(params.claimFk));
|
|
|
|
return Promise.all(promises).then(result => {
|
|
const [[claim]] = result[0];
|
|
const [sales] = result[1];
|
|
|
|
if (!claim)
|
|
throw new UserException('No claim data found');
|
|
|
|
Object.assign(data, claim, {sales});
|
|
|
|
return data;
|
|
});
|
|
},
|
|
created() {
|
|
if (this.locale)
|
|
this.$i18n.locale = this.locale;
|
|
},
|
|
methods: {
|
|
dated: () => {
|
|
return strftime('%d-%m-%Y', new Date());
|
|
},
|
|
fetchClaim(claimFk) {
|
|
return database.pool.query(
|
|
`SELECT
|
|
u.lang locale,
|
|
c.id clientId,
|
|
cl.id claimId,
|
|
c.email AS recipient,
|
|
c.socialName,
|
|
c.name AS clientName,
|
|
c.street,
|
|
c.postcode,
|
|
c.city,
|
|
c.fi,
|
|
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
|
|
LEFT JOIN province p ON p.id = c.provinceFk
|
|
WHERE cl.id = ?`, [claimFk]);
|
|
},
|
|
|
|
fetchSales(claimFk) {
|
|
return database.pool.query(
|
|
`SELECT
|
|
s.id,
|
|
s.quantity,
|
|
s.concept,
|
|
cb.quantity claimQuantity
|
|
FROM claimBeginning cb
|
|
JOIN sale s ON s.id = cb.saleFk
|
|
WHERE cb.claimFk = ?`, [claimFk]);
|
|
},
|
|
},
|
|
components: {
|
|
'report-header': require('../report-header'),
|
|
'report-footer': require('../report-footer'),
|
|
},
|
|
};
|