2017-10-20 12:03:25 +00:00
|
|
|
var path = require('path');
|
|
|
|
var database = require(path.join(__dirname, '../../database.js'));
|
|
|
|
var format = require(path.join(__dirname, '../../util/format.js'));
|
|
|
|
|
|
|
|
module.exports = class ClientWelcome {
|
|
|
|
getData(params, cb) {
|
|
|
|
let query = `SELECT
|
2017-11-27 14:08:18 +00:00
|
|
|
c.id clientId,
|
2017-10-20 12:03:25 +00:00
|
|
|
CONCAT(w.name, ' ', w.firstName) name,
|
|
|
|
w.phone AS phone,
|
|
|
|
CONCAT(wu.name, '@verdnatura.es') AS email,
|
|
|
|
u.name AS userName,
|
|
|
|
LOWER(ct.code) countryCode,
|
|
|
|
c.email recipient
|
|
|
|
FROM client c
|
|
|
|
JOIN account.user u ON u.id = c.id
|
|
|
|
LEFT JOIN worker w ON w.id = c.workerFk
|
|
|
|
LEFT JOIN account.user wu ON wu.id = w.userFk
|
|
|
|
JOIN country ct ON ct.id = c.countryFk
|
|
|
|
WHERE c.id = ?`;
|
2017-11-27 14:08:18 +00:00
|
|
|
database.pool.query(query, [params.clientId], (error, result) => {
|
2017-10-20 12:03:25 +00:00
|
|
|
if (error || result.length == 0)
|
|
|
|
return cb(new Error('No template data found'));
|
|
|
|
|
|
|
|
Object.assign(this, result[0]);
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get salesPersonName() {
|
|
|
|
if (this.name)
|
2017-10-24 22:38:02 +00:00
|
|
|
return `<div>${this._.salesPersonNameText}: <strong>${this.name}</strong></div>`;
|
2017-10-20 12:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get salesPersonPhone() {
|
|
|
|
if (this.phone)
|
2017-10-24 22:38:02 +00:00
|
|
|
return `<div>${this._.salesPersonPhoneText}: <strong>${format.phone(this.phone)}</strong></div>`;
|
2017-10-20 12:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get salesPersonEmail() {
|
|
|
|
if (this.email)
|
|
|
|
return `<div>${this._.salesPersonEmailText}: ` +
|
|
|
|
`<strong><a href="mailto:${this.email}" target="_blank" style="color:#8dba25">${this.email}</strong></div>`;
|
|
|
|
}
|
|
|
|
};
|