2017-06-07 13:28:42 +00:00
|
|
|
var path = require('path');
|
|
|
|
var database = require(path.join(__dirname, '../../database.js'));
|
2017-06-07 17:29:16 +00:00
|
|
|
var format = require(path.join(__dirname, '../../util/format.js'));
|
2017-06-07 13:28:42 +00:00
|
|
|
|
|
|
|
module.exports = class PaymentUpdate {
|
|
|
|
getData(params, cb) {
|
2017-08-30 12:50:46 +00:00
|
|
|
let query = `SELECT
|
|
|
|
pm.id payMethodFk,
|
|
|
|
pm.name payMethodName,
|
|
|
|
c.dueDay,
|
|
|
|
c.iban,
|
|
|
|
LOWER(ct.code) countryCode,
|
2017-08-31 14:11:37 +00:00
|
|
|
c.email recipient
|
|
|
|
FROM client c
|
2017-08-30 12:50:46 +00:00
|
|
|
JOIN payMethod pm ON pm.id = c.paymentMethodFk
|
|
|
|
JOIN country ct ON ct.id = c.countryFk
|
2017-08-31 14:11:37 +00:00
|
|
|
WHERE c.id = ?`;
|
|
|
|
database.pool.query(query, [params.recipient], (error, result) => {
|
|
|
|
if (error || result.length == 0)
|
2017-10-17 06:22:59 +00:00
|
|
|
return cb(new Error('No template data found'));
|
2017-08-31 14:11:37 +00:00
|
|
|
|
2017-06-07 17:29:16 +00:00
|
|
|
Object.assign(this, result[0]);
|
2017-10-17 06:22:59 +00:00
|
|
|
cb();
|
2017-06-07 13:28:42 +00:00
|
|
|
});
|
|
|
|
}
|
2017-06-08 14:53:10 +00:00
|
|
|
|
|
|
|
get paymentDay() {
|
2017-10-20 12:03:25 +00:00
|
|
|
if (this.payMethodFk != 5)
|
2017-08-30 12:50:46 +00:00
|
|
|
return `<div>${this._.paymentDay}: <strong style="font-size: 16px">${this.dueDay} ${this._.everyMonth}</strong></div>`;
|
2017-06-08 14:53:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 17:29:16 +00:00
|
|
|
get paymentAdvice() {
|
2017-08-30 12:50:46 +00:00
|
|
|
switch (this.payMethodFk) {
|
2017-10-20 12:03:25 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|