diff --git a/services/mailer/application/mail.js b/services/mailer/application/mail.js index 674b05b2fa..6ba40ff903 100644 --- a/services/mailer/application/mail.js +++ b/services/mailer/application/mail.js @@ -36,7 +36,7 @@ module.exports = { html: body, attachments }; - console.log(recipient); + this.transporter.sendMail(mailOptions, (error, info) => { if (error) { return cb(null, 'Email not sent: ' + error); diff --git a/services/mailer/application/route/notification.js b/services/mailer/application/route/notification.js index 5ec515dd1a..a7f9904a2d 100644 --- a/services/mailer/application/route/notification.js +++ b/services/mailer/application/route/notification.js @@ -1,6 +1,6 @@ var express = require('express'); var router = new express.Router(); - +var format = require('../util/format.js'); router.get('/test', function(request, response) { response.send("test"); }); diff --git a/services/mailer/application/router.js b/services/mailer/application/router.js index a624eba0f7..2015486322 100644 --- a/services/mailer/application/router.js +++ b/services/mailer/application/router.js @@ -12,22 +12,5 @@ router.use('/manuscript', require('./route/manuscript.js')); // Notifications router.use('/notification', require('./route/notification.js')); -/*// Load template route -router.post('/:userId/:template', function(request, response, next) { - database.pool.query('SELECT `e-mail` AS email, LOWER(p.Codigo) AS countryCode FROM Clientes AS c JOIN Paises AS p ON p.id = c.Id_Pais WHERE Id_Cliente = ?', [request.params.userId], function(error, qryRs) { - if (qryRs.length == 0) - return response.json({data: {message: 'Client not found'}}); - template.getTemplate(request.params.template, qryRs[0].countryCode, {userId: request.params.userId}, function(tplRs, error) { - if (error) - return response.json({data: {message: error}}); - - mail.send(qryRs[0].email, tplRs.subject, tplRs.body, tplRs.attachments, (mailrs, error) => { - if (error) - return response.json({data: {message: error}}); - }); - }); - }); -}); -*/ module.exports = router; diff --git a/services/mailer/application/template.js b/services/mailer/application/template.js index b03fd47359..d484393c97 100644 --- a/services/mailer/application/template.js +++ b/services/mailer/application/template.js @@ -22,18 +22,19 @@ module.exports = { let TemplateClass = require(classPath); let instance = new TemplateClass(); - instance.getData(params, data => { - locale.load(template, countryCode, (rs, error) => { - data = Object.assign({}, rs, data); + let getDataCb = () => { + this.render(templatePath, instance, body => { + var titleSubject = body.match(new RegExp('(.*?)', 'i'))[1]; - this.render(templatePath, data, body => { - var titleSubject = body.match(new RegExp('(.*?)', 'i'))[1]; - - this.getAttachments(template, body, attachments => { - cb({body: body, subject: titleSubject, attachments: attachments}); - }); + this.getAttachments(template, body, attachments => { + cb({body: body, subject: titleSubject, attachments: attachments}); }); }); + }; + + locale.load(template, countryCode, (translations, error) => { + instance._ = translations; + instance.getData(params, () => getDataCb()); }); }); }, diff --git a/services/mailer/application/template/payment-update/locale/es.json b/services/mailer/application/template/payment-update/locale/es.json index ecf908f924..144cdc3464 100644 --- a/services/mailer/application/template/payment-update/locale/es.json +++ b/services/mailer/application/template/payment-update/locale/es.json @@ -3,6 +3,15 @@ "title": "Cambio en las condiciones", "dear": "Estimado cliente", "bodyDescription": "Le informamos que han cambiado las condiciones de pago de su cuenta. A continuación le indicamos las nuevas condiciones:", + "paymentMethod": "Método de pago", + "paymentDay": "Día de pago", + "everyMonth": "de cada mes", + "cardPaymentAdvice": "Su modo de pago actual implica que deberá abonar el importe de los pedidos realizados en el mismo día para que se puedan enviar.", + "accountPaymentAdviceBefore": "Su modo de pago actual implica que se le pasará un cargo a la cuenta", + "accountPaymentAdviceAfter": "por el importe pendiente, al vencimiento establecido en las condiciones.", + "notifyError": "En el caso de detectar algún error en los datos indicados o para cualquier aclaración, debe dirigirse a su comercial.", + "actionButton": "Visita nuestra Web", + "infoButton": "Ayúdanos a mejorar", "fiscalAddress": "VERDNATURA LEVANTE SL, B97367486 Avda. Espioca, 100, 46460 Silla _ www.verdnatura.es _ clientes@verdnatura.es", "privacy": "- AVISO - Este mensaje es privado y confidencial, y debe ser utilizado exclusivamente por la persona destinataria del mismo. Si usted ha recibido este mensaje por error, le rogamos lo comunique al remitente y borre dicho mensaje y cualquier documento adjunto que pudiera contener. Verdnatura Levante SL no renuncia a la confidencialidad ni a ningún privilegio por causa de transmisión errónea o mal funcionamiento. Igualmente no se hace responsable de los cambios, alteraciones, errores u omisiones que pudieran hacerse al mensaje una vez enviado.", "privacyLaw": "En cumplimiento de lo dispuesto en la Ley Orgánica 15/1999, de Protección de Datos de Carácter Personal, le comunicamos que los datos personales que facilite se incluirán en ficheros automatizados de VERDNATURA LEVANTE S.L., pudiendo en todo momento ejercitar los derechos de acceso, rectificación, cancelación y oposición, comunicándolo por escrito al domicilio social de la entidad. La finalidad del fichero es la gestión administrativa, contabilidad, y facturación." diff --git a/services/mailer/application/template/payment-update/payment-update.html b/services/mailer/application/template/payment-update/payment-update.html index 81086327a7..a943ca94cd 100644 --- a/services/mailer/application/template/payment-update/payment-update.html +++ b/services/mailer/application/template/payment-update/payment-update.html @@ -1,7 +1,7 @@ - {{subject}} + {{_.subject}} @@ -14,32 +14,32 @@
-

{{title}}

+

{{_.title}}

-

{{dear}},

-

{{bodyDescription}}

+

{{_.dear}},

+

{{_.bodyDescription}}

-

Forma de pago: {{paymentMethod}}
-
Día de pago: {{paymentDay}} de cada mes
+
{{_.paymentMethod}}: {{payMethod}}
+
{{_.paymentDay}}: {{paymentDay}} {{_.everyMonth}}

{{paymentAdvice}}

-

En el caso de detectar algún error en los datos indicados o para cualquier aclaración, debe dirigirse a su comercial.

+

{{_.notifyError}}

-
Visita nuestra Web
+
{{_.actionButton}}
-
Ayúdanos a mejorar
+
{{_.infoButton}}
@@ -70,9 +70,9 @@
-

{{fiscalAddress}}

-

{{privacy}}

-

{{privacyLaw}}

+

{{_.fiscalAddress}}

+

{{_.privacy}}

+

{{_.privacyLaw}}

diff --git a/services/mailer/application/template/payment-update/payment-update.js b/services/mailer/application/template/payment-update/payment-update.js index 8ac60c155b..9034a2dd96 100644 --- a/services/mailer/application/template/payment-update/payment-update.js +++ b/services/mailer/application/template/payment-update/payment-update.js @@ -1,24 +1,22 @@ var path = require('path'); var database = require(path.join(__dirname, '../../database.js')); +var format = require(path.join(__dirname, '../../util/format.js')); module.exports = class PaymentUpdate { getData(params, cb) { - database.pool.query('SELECT pm.name AS paymentMethod, pm.id AS paymentMethodId, vencimiento AS paymentDay FROM Clientes AS c JOIN pay_met AS pm ON pm.id = c.pay_met_id WHERE Id_Cliente = ?', [params.userId], (error, result) => { - cb({ - paymentMethod: result[0].paymentMethod, - paymentDay: result[0].paymentDay, - paymentAdvice: this.getPaymentAdvice(result[0].paymentMethodId) - }); + let query = `SELECT pm.name AS payMethod, pm.id AS payMethodId, c.vencimiento AS paymentDay, c.CC AS accountAddress + FROM Clientes AS c JOIN pay_met AS pm ON pm.id = c.pay_met_id WHERE Id_Cliente = ?`; + database.pool.query(query, [params.userId], (error, result) => { + Object.assign(this, result[0]); + cb(); }); } - _(string) { - return string; - } - getPaymentAdvice(paymentMethod) { - if (paymentMethod == 4) { - return 'Su modo de pago actual implica que se le pasará un cargo a la cuenta ESXXXX **** **** **** **** por el importe pendiente, al vencimiento establecido en las condiciones.'; - } else if (paymentMethod == 5) { - return 'Su modo de pago actual implica que deberá abonar el importe de los pedidos realizados en el mismo día para que se puedan enviar.'; + get paymentAdvice() { + switch (this.payMethodId) { + case 4: + return `${this._.accountPaymentAdviceBefore} ${format.partialAccountAddress(this.accountAddress)} ${this._.accountPaymentAdviceAfter}`; + case 5: + return this._.cardPaymentAdvice; } } }; diff --git a/services/mailer/application/util/format.js b/services/mailer/application/util/format.js new file mode 100644 index 0000000000..e166062c7b --- /dev/null +++ b/services/mailer/application/util/format.js @@ -0,0 +1,35 @@ +let database = require('../database.js'); + +module.exports = { + + /** + * Devuelve el iban + * @param {String} addressNumber - Dirección de cuenta bancaria + * @param {Object} cb - Callback + */ + accountAddressIban: function(addressNumber, cb) { + database.pool.query('SELECT vn2008.cc_to_iban(?) AS iban', [addressNumber], function(error, result) { + cb(result[0].iban); + }); + }, + + /** + * Obtiene el numero de cuenta completo incluyendo iban + * @param {String} addressNumber - Dirección de cuenta bancaria + * @return {String} Cuenta bancaria formateada + */ + accountAddress: function(addressNumber) { + var formattedAccountAddress = addressNumber.replace(/(.{4})/g, '$1-'); + return formattedAccountAddress.substring(0, formattedAccountAddress.length - 1); + }, + + /** + * Devuelve el numero de cuenta mostrando únicamente los últimos 4 dígitos. + * @param {String} addressNumber - Dirección de cuenta bancaria + * @return {String} Cuenta bancaria formateada + */ + partialAccountAddress: function(addressNumber) { + let address = this.accountAddress(addressNumber); + return address.substring(0, 19).replace(/[0-9]/g, 'X') + address.substring(19, 24); + } +};