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