diff --git a/db/changes/231801/01-viewCompany10L.sql b/db/changes/231801/01-viewCompany10L.sql new file mode 100644 index 000000000..335827b42 --- /dev/null +++ b/db/changes/231801/01-viewCompany10L.sql @@ -0,0 +1,12 @@ +-- vn.companyL10n source + +CREATE OR REPLACE +ALGORITHM = UNDEFINED VIEW `vn`.`companyL10n` AS +select + `c`.`id` AS `id`, + ifnull(`ci`.`footnotes`, `c`.`footnotes`) AS `footnotes` +from + (`vn`.`company` `c` +left join `vn`.`companyI18n` `ci` on + (`ci`.`companyFk` = `c`.`id` + and `ci`.`lang` = `util`.`LANG`())); \ No newline at end of file diff --git a/print/core/components/report-footer/report-footer.js b/print/core/components/report-footer/report-footer.js index 0eaab8ce4..077ef0bde 100755 --- a/print/core/components/report-footer/report-footer.js +++ b/print/core/components/report-footer/report-footer.js @@ -4,13 +4,14 @@ const db = require('../../database'); module.exports = { name: 'report-footer', async serverPrefetch() { - this.company = await db.findOne( - `SELECT - ci.footnotes - FROM companyI18n ci - JOIN company c ON c.id = ci.companyFk - WHERE c.code = ? AND ci.lang = (SELECT lang FROM account.user WHERE id = ?)`, - [this.companyCode, this.recipientId]); + this.company = await db.findOne(` + SELECT IFNULL(ci.footnotes, cl.footnotes) as footnotes + FROM company c + LEFT JOIN companyL10n cl ON c.id = cl.id + LEFT JOIN companyI18n ci ON ci.companyFk = cl.id + AND ci.lang = (SELECT lang FROM account.user where id = ?) + WHERE c.code = ?`, + [this.recipientId, this.companyCode]); }, props: ['leftText', 'companyCode', 'recipientId', 'centerText']