81 lines
2.8 KiB
JavaScript
Executable File
81 lines
2.8 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-lcr',
|
|
async asyncData(ctx, params) {
|
|
if (!params.clientFk)
|
|
throw new UserException('No client id specified');
|
|
|
|
if (!params.companyFk)
|
|
throw new UserException('No company id specified');
|
|
|
|
return this.methods.fetchClient(params.clientFk, params.companyFk)
|
|
.then(([[client]]) => {
|
|
if (!client)
|
|
throw new UserException('No client data found');
|
|
|
|
return client;
|
|
});
|
|
},
|
|
created() {
|
|
if (this.locale)
|
|
this.$i18n.locale = this.locale;
|
|
|
|
const embeded = [];
|
|
this.files.map(file => {
|
|
embeded[file] = `file://${__dirname + file}`;
|
|
});
|
|
this.embeded = embeded;
|
|
},
|
|
data() {
|
|
return {
|
|
files: ['/assets/images/signature.png']
|
|
};
|
|
},
|
|
methods: {
|
|
fetchClient(clientFk, companyFk) {
|
|
return database.pool.query(
|
|
`SELECT
|
|
c.id clientId,
|
|
u.lang locale,
|
|
m.code mandateCode,
|
|
c.socialName AS clientName,
|
|
c.street AS clientStreet,
|
|
c.postcode AS clientPostCode,
|
|
c.city AS clientCity,
|
|
c.fi,
|
|
p.name AS clientProvince,
|
|
ct.country AS clientCountry,
|
|
s.name AS supplierName,
|
|
s.street AS supplierStreet,
|
|
sc.country AS supplierCountry,
|
|
s.postCode AS supplierPostCode,
|
|
s.city AS supplierCity,
|
|
sp.name AS supplierProvince
|
|
FROM client c
|
|
JOIN account.user u ON u.id = c.id
|
|
JOIN country ct ON ct.id = c.countryFk
|
|
LEFT JOIN mandate m ON m.clientFk = c.id
|
|
AND m.companyFk = ? AND m.finished IS NULL
|
|
LEFT JOIN supplier s ON s.id = m.companyFk
|
|
LEFT JOIN country sc ON sc.id = s.countryFk
|
|
LEFT JOIN province sp ON sp.id = s.provinceFk
|
|
LEFT JOIN province p ON p.id = c.provinceFk
|
|
WHERE (m.companyFk = ? OR m.companyFk IS NULL) AND c.id = ?
|
|
ORDER BY m.created DESC LIMIT 1`, [companyFk, companyFk, clientFk]);
|
|
},
|
|
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'),
|
|
},
|
|
};
|