refs #6184 saveCmr #1788

Merged
guillermo merged 58 commits from 6184-saveCmr into dev 2024-02-13 06:47:06 +00:00
12 changed files with 193 additions and 1 deletions
Showing only changes of commit a676607e29 - Show all commits

View File

@ -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]
}]
});
};
};

View File

@ -17,6 +17,7 @@ module.exports = Self => {
require('../methods/route/cmr')(Self); require('../methods/route/cmr')(Self);
require('../methods/route/getExternalCmrs')(Self); require('../methods/route/getExternalCmrs')(Self);
require('../methods/route/downloadCmrsZip')(Self); require('../methods/route/downloadCmrsZip')(Self);
require('../methods/route/cmrEmail')(Self);
require('../methods/route/getExpeditionSummary')(Self); require('../methods/route/getExpeditionSummary')(Self);
require('../methods/route/getByWorker')(Self); require('../methods/route/getByWorker')(Self);

View File

@ -142,7 +142,8 @@ module.exports = Self => {
stateFk: deliveryState.id stateFk: deliveryState.id
}, myOptions); }, 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(); if (tx) await tx.commit();

View File

@ -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();

View File

@ -0,0 +1,6 @@
[
{
"filename": "cmr.pdf",
"component": "cmr"
}
]

View File

@ -0,0 +1,12 @@
<email-body v-bind="$props">
<div class="grid-row">
<div class="grid-block vn-pa-ml">
<h1>{{ $t('title') }}</h1>
<p>{{$t('dear')}},</p>
<p v-html="$t('description', [cmr.id, cmr.ticketFk])"></p>
<p v-html="$t('poll')"></p>
<p v-html="$t('help')"></p>
<p v-html="$t('conclusion')"></p>
</div>
</div>
</email-body>

View File

@ -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
}
}
};

View File

@ -0,0 +1,9 @@
subject: Your CMR
title: Your CMR
dear: Dear Customer
description: The CMR <strong>{0}</strong> corresponding to order <strong>{1}</strong> is now available. <br/>
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, <strong>we are here to serve you!</strong>
conclusion: Thank you for your attention!

View File

@ -0,0 +1,9 @@
subject: Tu CMR
title: Tu CMR
dear: Estimado cliente
description: Ya está disponible el CMR <strong>{0}</strong> correspondiente al pedido <strong>{1}</strong>. <br/>
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, <strong>¡estamos para atenderte!</strong>
conclusion: ¡Gracias por tu atención!

View File

@ -0,0 +1,9 @@
subject: Votre CMR
title: Votre CMR
dear: Cher client
description: Le CMR <strong>{0}</strong> correspondant à la commande <strong>{1}</strong> est maintenant disponible. <br/>
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, <strong>nous sommes là pour vous servir !</strong>
conclusion: Merci de votre attention !

View File

@ -0,0 +1,9 @@
subject: Seu CMR
title: Seu CMR
dear: Caro cliente
description: O CMR <strong>{0}</strong> correspondente ao pedido <strong>{1}</strong> já está disponível. <br/>
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, <strong>estamos aqui para atendê-lo!</strong>
conclusion: Obrigado pela sua atenção!

View File

@ -0,0 +1,5 @@
SELECT t.id ticketFk,
c.id
FROM ticket t
JOIN cmr c ON c.id = t.cmrFk
WHERE t.id = ?