73 lines
2.3 KiB
JavaScript
Executable File
73 lines
2.3 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-delivery-note',
|
|
async asyncData(ctx, params) {
|
|
const promises = [];
|
|
const data = {};
|
|
|
|
if (!params.ticketFk)
|
|
throw new UserException('No ticket id specified');
|
|
|
|
promises.push(this.methods.fetchClient(params.ticketFk));
|
|
// promises.push(this.methods.fetchSales(params.ticketFk));
|
|
|
|
return Promise.all(promises).then(result => {
|
|
const [[client]] = result[0];
|
|
// const [[sales]] = result[1];
|
|
|
|
if (!client)
|
|
throw new UserException('No client data found');
|
|
|
|
Object.assign(data, client);
|
|
|
|
return data;
|
|
});
|
|
},
|
|
created() {
|
|
if (this.locale)
|
|
this.$i18n.locale = this.locale;
|
|
},
|
|
data() {
|
|
return {totalBalance: 0.00};
|
|
},
|
|
methods: {
|
|
fetchClient(ticketFk) {
|
|
return database.pool.query(
|
|
`SELECT
|
|
c.id clientId,
|
|
u.lang locale,
|
|
c.email AS recipient,
|
|
c.socialName AS clientName,
|
|
c.street,
|
|
c.postcode,
|
|
c.city,
|
|
c.fi,
|
|
p.name AS province,
|
|
ct.country
|
|
FROM ticket t
|
|
JOIN client c ON c.id = t.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 t.id = ?`, [ticketFk]);
|
|
},
|
|
fetchSales(clientFk, companyFk) {
|
|
return database.pool.query(
|
|
`CALL vn.clientGetDebtDiary(?, ?)`, [clientFk, companyFk]);
|
|
},
|
|
dated: () => {
|
|
return strftime('%d-%m-%Y', new Date());
|
|
},
|
|
toISOString: date => {
|
|
return strftime('%d-%m-%Y', date);
|
|
},
|
|
},
|
|
components: {
|
|
'report-header': require('../report-header'),
|
|
'report-footer': require('../report-footer'),
|
|
},
|
|
};
|