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-12-26 09:02:47 +00:00
|
|
|
let query = `SELECT
|
2017-08-30 12:50:46 +00:00
|
|
|
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-12-26 09:11:43 +00:00
|
|
|
JOIN payMethod pm ON pm.id = c.payMethodFk
|
2017-08-30 12:50:46 +00:00
|
|
|
JOIN country ct ON ct.id = c.countryFk
|
2017-08-31 14:11:37 +00:00
|
|
|
WHERE c.id = ?`;
|
2017-12-26 09:02:47 +00:00
|
|
|
|
|
|
|
this.clientId = params.clientId;
|
|
|
|
|
2017-11-27 14:08:18 +00:00
|
|
|
database.pool.query(query, [params.clientId], (error, result) => {
|
2017-08-31 14:11:37 +00:00
|
|
|
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() {
|
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>`;
|
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) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|