salix/services/mailer/application/template/payment-update/payment-update.js

44 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-06-07 13:28:42 +00:00
var path = require('path');
var database = require(path.join(__dirname, '../../database.js'));
var format = require(path.join(__dirname, '../../util/format.js'));
2017-06-07 13:28:42 +00:00
module.exports = class PaymentUpdate {
getData(params, cb) {
let query = `SELECT
pm.id payMethodFk,
pm.name payMethodName,
c.dueDay,
c.iban,
LOWER(ct.code) countryCode,
c.email recipient
FROM client c
JOIN payMethod pm ON pm.id = c.payMethodFk
JOIN country ct ON ct.id = c.countryFk
WHERE c.id = ?`;
this.clientId = params.clientId;
2017-11-27 14:08:18 +00:00
database.pool.query(query, [params.clientId], (error, result) => {
if (error || result.length == 0)
return cb(new Error('No template data found'));
Object.assign(this, result[0]);
cb();
2017-06-07 13:28:42 +00:00
});
}
get paymentDay() {
2018-07-16 07:28:32 +00:00
if (this.payMethodFk != 5)
2017-11-27 14:08:18 +00:00
return `<div>${this._.paymentDay} <strong>${this.dueDay} ${this._.everyMonth}</strong></div>`;
}
get paymentAdvice() {
switch (this.payMethodFk) {
2018-07-16 07:28:32 +00:00
case 4:
return `${this._.accountPaymentAdviceBefore} ${format.partialAccountAddress(this.iban)} ${this._.accountPaymentAdviceAfter}`;
case 5:
return this._.cardPaymentAdvice;
2017-06-07 13:28:42 +00:00
}
}
};