salix/services/mailer/application/template/letter-debtor-st/letter-debtor-st.js

40 lines
1.6 KiB
JavaScript
Raw Normal View History

var path = require('path');
var database = require(path.join(__dirname, '../../database.js'));
var format = require(path.join(__dirname, '../../util/format.js'));
module.exports = class LetterDebtorSt {
getData(params, cb) {
let query = `SELECT
sa.iban,
be.name AS bankName,
LOWER(ct.code) countryCode,
c.email recipient
FROM client c
JOIN company AS cny
JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk
JOIN bankEntity be ON be.id = sa.bankEntityFk
JOIN country ct ON ct.id = c.countryFk
WHERE c.id = ? AND cny.id = ?`;
this.clientId = params.clientId;
this.companyId = params.companyId;
this.token = params.token;
database.pool.query(query, [params.clientId, params.companyId], (error, result) => {
if (error || result.length == 0)
return cb(new Error('No template data found'));
Object.assign(this, result[0]);
cb();
});
}
get previewAttachments() {
if (this.isPreview)
return `<a href="/print/manuscript/letter-debtor/${this.companyId}/${this.clientId}/preview?token=${this.token}" target="_blank" title="Ver extracto.pdf">` +
'<div class="attachment"><div class="attachment-icon"><img src="cid:attachment.png" alt="Descargar adjunto"/></div>' +
'<span>extracto.pdf</span></div></a>';
}
};