diff --git a/print/report/rpt-sepa-core/index.js b/print/report/rpt-sepa-core/index.js index 9c4ee6ac6..c98ddbcb4 100755 --- a/print/report/rpt-sepa-core/index.js +++ b/print/report/rpt-sepa-core/index.js @@ -11,7 +11,7 @@ module.exports = { if (!params.companyFk) throw new UserException('No company id specified'); - return this.methods.fetchClient(params.clientFk) + return this.methods.fetchClient(params.clientFk, params.companyFk) .then(([[client]]) => { if (!client) throw new UserException('No client data found'); @@ -24,7 +24,7 @@ module.exports = { this.$i18n.locale = this.locale; }, methods: { - fetchClient(clientFk) { + fetchClient(clientFk, companyFk) { return database.pool.query( `SELECT c.id clientId, @@ -46,12 +46,12 @@ module.exports = { FROM client c JOIN account.user u ON u.id = c.id JOIN country ct ON ct.id = c.countryFk + JOIN mandate m ON m.clientFk = c.id AND m.finished IS NULL + JOIN supplier s ON s.id = m.companyFk + JOIN country sc ON sc.id = s.countryFk + JOIN province sp ON sp.id = s.provinceFk LEFT JOIN province p ON p.id = c.provinceFk - LEFT JOIN mandate m ON m.clientFk = c.id 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 - WHERE c.id = ?`, [clientFk]); + WHERE m.companyFk = ? AND c.id = ?`, [companyFk, clientFk]); }, dated: () => { return strftime('%d-%m-%Y', new Date());