2019-05-07 05:33:21 +00:00
|
|
|
const fs = require('fs');
|
2019-01-31 10:44:03 +00:00
|
|
|
const strftime = require('strftime');
|
|
|
|
const database = require(`${appPath}/lib/database`);
|
2019-05-07 05:33:21 +00:00
|
|
|
|
|
|
|
const template = fs.readFileSync(__dirname + '/index.html').toString();
|
|
|
|
const lang = require('./locale.js');
|
|
|
|
|
2019-01-31 10:44:03 +00:00
|
|
|
const UserException = require(`${appPath}/lib/exceptions/userException`);
|
|
|
|
|
2019-05-07 05:33:21 +00:00
|
|
|
const rptSepaCore = {
|
2019-01-31 10:44:03 +00:00
|
|
|
name: 'rpt-sepa-core',
|
2019-05-07 05:33:21 +00:00
|
|
|
|
2019-05-08 10:19:08 +00:00
|
|
|
async asyncData(ctx, params) {
|
2019-01-31 10:44:03 +00:00
|
|
|
if (!params.clientFk)
|
|
|
|
throw new UserException('No client id specified');
|
|
|
|
|
|
|
|
if (!params.companyFk)
|
|
|
|
throw new UserException('No company id specified');
|
|
|
|
|
2019-03-12 06:52:12 +00:00
|
|
|
return this.methods.fetchClient(params.clientFk, params.companyFk)
|
2019-01-31 10:44:03 +00:00
|
|
|
.then(([[client]]) => {
|
|
|
|
if (!client)
|
|
|
|
throw new UserException('No client data found');
|
|
|
|
|
|
|
|
return client;
|
|
|
|
});
|
2019-05-08 10:19:08 +00:00
|
|
|
},
|
2019-01-31 10:44:03 +00:00
|
|
|
created() {
|
2019-05-07 05:33:21 +00:00
|
|
|
this.clientId = 101;
|
2019-01-31 10:44:03 +00:00
|
|
|
if (this.locale)
|
|
|
|
this.$i18n.locale = this.locale;
|
|
|
|
},
|
|
|
|
methods: {
|
2019-03-12 06:52:12 +00:00
|
|
|
fetchClient(clientFk, companyFk) {
|
2019-01-31 10:44:03 +00:00
|
|
|
return database.pool.query(
|
|
|
|
`SELECT
|
|
|
|
c.id clientId,
|
|
|
|
u.lang locale,
|
|
|
|
m.code mandateCode,
|
|
|
|
c.email AS recipient,
|
|
|
|
c.socialName AS clientName,
|
|
|
|
c.street AS clientStreet,
|
|
|
|
c.postcode AS clientPostCode,
|
|
|
|
c.city AS clientCity,
|
|
|
|
p.name AS clientProvince,
|
|
|
|
ct.country AS clientCountry,
|
2019-06-07 07:18:54 +00:00
|
|
|
ct.code AS clientCountryCode,
|
|
|
|
ct.ibanLength AS ibanLength,
|
2019-01-31 10:44:03 +00:00
|
|
|
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
|
2019-05-07 05:33:21 +00:00
|
|
|
LEFT JOIN mandate m ON m.clientFk = c.id
|
2019-04-01 05:05:37 +00:00
|
|
|
AND m.companyFk = ? AND m.finished IS NULL
|
2019-05-07 05:33:21 +00:00
|
|
|
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
|
2019-01-31 10:44:03 +00:00
|
|
|
LEFT JOIN province p ON p.id = c.provinceFk
|
2019-05-07 05:33:21 +00:00
|
|
|
WHERE (m.companyFk = ? OR m.companyFk IS NULL) AND c.id = ?
|
2019-04-01 05:05:37 +00:00
|
|
|
ORDER BY m.created DESC LIMIT 1`, [companyFk, companyFk, clientFk]);
|
2019-01-31 10:44:03 +00:00
|
|
|
},
|
|
|
|
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'),
|
|
|
|
},
|
2019-05-07 05:33:21 +00:00
|
|
|
template: template,
|
|
|
|
i18n: lang,
|
|
|
|
props: ['test']
|
2019-01-31 10:44:03 +00:00
|
|
|
};
|
2019-05-07 05:33:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = rptSepaCore;
|