diff --git a/modules/route/back/methods/route/cmrEmail.js b/modules/route/back/methods/route/cmrEmail.js
new file mode 100644
index 000000000..e24d8a58f
--- /dev/null
+++ b/modules/route/back/methods/route/cmrEmail.js
@@ -0,0 +1,98 @@
+const {Email} = require('vn-print');
+
+module.exports = Self => {
+ Self.remoteMethodCtx('cmrEmail', {
+ description: 'Sends the email with an cmr attached PDF',
+ accessType: 'WRITE',
+ accepts: [
+ {
+ arg: 'ticketId',
+ type: 'number',
+ required: true,
+ description: 'The ticket id',
+ },
+ {
+ arg: 'recipientId',
+ type: 'number',
+ description: 'The client id',
+ required: true
+ },
+ {
+ arg: 'recipient',
+ type: 'string',
+ description: 'The recipient email',
+ required: false,
+ }
+ ],
+ returns: [
+ {
+ arg: 'body',
+ type: 'file',
+ root: true
+ }, {
+ arg: 'Content-Type',
+ type: 'string',
+ http: {target: 'header'}
+ }, {
+ arg: 'Content-Disposition',
+ type: 'string',
+ http: {target: 'header'}
+ }
+ ],
+ http: {
+ path: '/cmrEmail',
+ verb: 'POST'
+ }
+ });
+
+ Self.cmrEmail = async function(ctx, ticketId, recipientId, recipient, options) {
+ const models = Self.app.models;
+ const myOptions = {};
+ const args = Object.assign({}, ctx.args);
+ const params = {
+ recipient: args.recipient,
+ lang: ctx.req.getLocale()
+ };
+
+ delete args.ctx;
+ for (const param in args)
+ params[param] = args[param];
+
+ if (typeof options == 'object')
+ Object.assign(myOptions, options);
+
+ if (!recipient)
+ params.recipient = (await models.Client.findById(recipientId, {fields: ['email']}, myOptions)).email;
+
+ const cmr = (await models.Ticket.findById(ticketId, {fields: ['cmrFk']}, myOptions)).cmrFk;
+
+ const dms = await models.TicketDms.findOne({
+ where: {
+ ticketFk: ticketId
+ },
+ include: [
+ {
+ relation: 'dms',
+ fields: ['id'],
+ scope: {
+ relation: 'dmsType',
+ where: {
+ code: 'cmr'
+ }
+ }
+ }
+ ]
+ }, myOptions);
+
+ const response = await models.Dms.downloadFile(ctx, dms.id);
+ const email = new Email('cmr', params);
+
+ return email.send({
+ overrideAttachments: true,
+ attachments: [{
+ filename: `${cmr}.pdf`,
+ content: response[0]
+ }]
+ });
+ };
+};
diff --git a/modules/route/back/models/route.js b/modules/route/back/models/route.js
index 9b5f3564f..a25e8769b 100644
--- a/modules/route/back/models/route.js
+++ b/modules/route/back/models/route.js
@@ -17,6 +17,7 @@ module.exports = Self => {
require('../methods/route/cmr')(Self);
require('../methods/route/getExternalCmrs')(Self);
require('../methods/route/downloadCmrsZip')(Self);
+ require('../methods/route/cmrEmail')(Self);
require('../methods/route/getExpeditionSummary')(Self);
require('../methods/route/getByWorker')(Self);
diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js
index 9df1cdecc..26ca2e1c5 100644
--- a/modules/ticket/back/methods/ticket/saveSign.js
+++ b/modules/ticket/back/methods/ticket/saveSign.js
@@ -142,7 +142,8 @@ module.exports = Self => {
stateFk: deliveryState.id
}, myOptions);
- await models.Ticket.saveCmr([ticketId], myOptions);
+ await models.Ticket.saveCmr(ctx, [ticketId], myOptions);
+ await models.Route.cmrEmail(ctx, [ticketId], myOptions);
}
if (tx) await tx.commit();
diff --git a/print/templates/email/cmr/assets/css/import.js b/print/templates/email/cmr/assets/css/import.js
new file mode 100644
index 000000000..4b4bb7086
--- /dev/null
+++ b/print/templates/email/cmr/assets/css/import.js
@@ -0,0 +1,11 @@
+const Stylesheet = require(`vn-print/core/stylesheet`);
+
+const path = require('path');
+const vnPrintPath = path.resolve('print');
+
+module.exports = new Stylesheet([
+ `${vnPrintPath}/common/css/spacing.css`,
+ `${vnPrintPath}/common/css/misc.css`,
+ `${vnPrintPath}/common/css/layout.css`,
+ `${vnPrintPath}/common/css/email.css`])
+ .mergeStyles();
diff --git a/print/templates/email/cmr/attachments.json b/print/templates/email/cmr/attachments.json
new file mode 100644
index 000000000..40845566d
--- /dev/null
+++ b/print/templates/email/cmr/attachments.json
@@ -0,0 +1,6 @@
+[
+ {
+ "filename": "cmr.pdf",
+ "component": "cmr"
+ }
+]
\ No newline at end of file
diff --git a/print/templates/email/cmr/cmr.html b/print/templates/email/cmr/cmr.html
new file mode 100644
index 000000000..2f6d9e346
--- /dev/null
+++ b/print/templates/email/cmr/cmr.html
@@ -0,0 +1,12 @@
+
+
+
+
{{ $t('title') }}
+
{{$t('dear')}},
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/print/templates/email/cmr/cmr.js b/print/templates/email/cmr/cmr.js
new file mode 100755
index 000000000..104e4d2fe
--- /dev/null
+++ b/print/templates/email/cmr/cmr.js
@@ -0,0 +1,22 @@
+const Component = require(`vn-print/core/component`);
+const emailBody = new Component('email-body');
+module.exports = {
+ name: 'cmr',
+ async serverPrefetch() {
+ this.cmr = await this.fetchCmr(this.ticketId);
+ },
+ methods: {
+ fetchCmr(ticketId) {
+ return this.findOneFromDef('cmr', [ticketId]);
+ },
+ },
+ components: {
+ 'email-body': emailBody.build(),
+ },
+ props: {
+ ticketId: {
+ type: Number,
+ required: true
+ }
+ }
+};
diff --git a/print/templates/email/cmr/locale/en.yml b/print/templates/email/cmr/locale/en.yml
new file mode 100644
index 000000000..fbfca9aaa
--- /dev/null
+++ b/print/templates/email/cmr/locale/en.yml
@@ -0,0 +1,9 @@
+subject: Your CMR
+title: Your CMR
+dear: Dear Customer
+description: The CMR {0} corresponding to order {1} is now available.
+ You can download it by clicking on the attachment in this email.
+poll: If you wish, you can respond to our satisfaction survey to
+ help us provide better service. Your opinion is very important to us!
+help: If you have any doubts, do not hesitate to ask, we are here to serve you!
+conclusion: Thank you for your attention!
\ No newline at end of file
diff --git a/print/templates/email/cmr/locale/es.yml b/print/templates/email/cmr/locale/es.yml
new file mode 100644
index 000000000..4c384edf5
--- /dev/null
+++ b/print/templates/email/cmr/locale/es.yml
@@ -0,0 +1,9 @@
+subject: Tu CMR
+title: Tu CMR
+dear: Estimado cliente
+description: Ya está disponible el CMR {0} correspondiente al pedido {1}.
+ Puedes descargarla haciendo clic en el adjunto de este correo.
+poll: Si lo deseas, puedes responder a nuestra encuesta de satisfacción para
+ ayudarnos a prestar un mejor servicio. ¡Tu opinión es muy importante para nosotros!
+help: Cualquier duda que te surja, no dudes en consultarla, ¡estamos para atenderte!
+conclusion: ¡Gracias por tu atención!
\ No newline at end of file
diff --git a/print/templates/email/cmr/locale/fr.yml b/print/templates/email/cmr/locale/fr.yml
new file mode 100644
index 000000000..c715f4433
--- /dev/null
+++ b/print/templates/email/cmr/locale/fr.yml
@@ -0,0 +1,9 @@
+subject: Votre CMR
+title: Votre CMR
+dear: Cher client
+description: Le CMR {0} correspondant à la commande {1} est maintenant disponible.
+ Vous pouvez le télécharger en cliquant sur la pièce jointe de cet e-mail.
+poll: Si vous le souhaitez, vous pouvez répondre à notre enquête de satisfaction pour
+ nous aider à améliorer notre service. Votre avis est très important pour nous !
+help: Si vous avez des doutes, n'hésitez pas à nous consulter, nous sommes là pour vous servir !
+conclusion: Merci de votre attention !
\ No newline at end of file
diff --git a/print/templates/email/cmr/locale/pt.yml b/print/templates/email/cmr/locale/pt.yml
new file mode 100644
index 000000000..74b2b2e7a
--- /dev/null
+++ b/print/templates/email/cmr/locale/pt.yml
@@ -0,0 +1,9 @@
+subject: Seu CMR
+title: Seu CMR
+dear: Caro cliente
+description: O CMR {0} correspondente ao pedido {1} já está disponível.
+ Você pode baixá-lo clicando no anexo deste e-mail.
+poll: Se desejar, pode responder à nossa pesquisa de satisfação para
+ nos ajudar a oferecer um serviço melhor. Sua opinião é muito importante para nós!
+help: Se tiver alguma dúvida, não hesite em nos consultar, estamos aqui para atendê-lo!
+conclusion: Obrigado pela sua atenção!
\ No newline at end of file
diff --git a/print/templates/email/cmr/sql/cmr.sql b/print/templates/email/cmr/sql/cmr.sql
new file mode 100644
index 000000000..f1c0904d8
--- /dev/null
+++ b/print/templates/email/cmr/sql/cmr.sql
@@ -0,0 +1,5 @@
+SELECT t.id ticketFk,
+ c.id
+ FROM ticket t
+ JOIN cmr c ON c.id = t.cmrFk
+ WHERE t.id = ?