salix/print/reports/claim-pickup/index.js

73 lines
2.3 KiB
JavaScript
Raw Normal View History

const strftime = require('strftime');
const database = require(`${appPath}/lib/database`);
const UserException = require(`${appPath}/lib/exceptions/userException`);
module.exports = {
name: 'claim-pickup',
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];
Object.assign(data, claim, {sales});
return data;
});
},
created() {
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'),
},
};