2287 - Notify to sales person
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
b7ceeae65a
commit
539afcd19b
|
@ -17,13 +17,17 @@ module.exports = app => {
|
|||
SELECT
|
||||
t.id,
|
||||
t.clientFk,
|
||||
c.email recipient
|
||||
c.email recipient,
|
||||
c.isToBeMailed,
|
||||
eu.email salesPersonEmail
|
||||
FROM expedition e
|
||||
JOIN ticket t ON t.id = e.ticketFk
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN warehouse w ON w.id = t.warehouseFk AND hasComission
|
||||
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
WHERE ts.code = 'PACKED'
|
||||
JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission
|
||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
JOIN alertLevel al ON al.alertLevel = ts.alertLevel
|
||||
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
||||
WHERE al.code = 'PACKED'
|
||||
AND DATE(t.shipped) BETWEEN DATE_ADD(CURDATE(), INTERVAL -2 DAY) AND CURDATE()
|
||||
AND t.refFk IS NULL
|
||||
GROUP BY e.ticketFk`);
|
||||
|
@ -34,6 +38,21 @@ module.exports = app => {
|
|||
ticketId: ticket.id
|
||||
});
|
||||
|
||||
if (!ticket.salesPersonFk || !ticket.isToBeMailed) continue;
|
||||
|
||||
if (!ticket.recipient) {
|
||||
const body = `No se ha podido enviar el albarán <strong>${ticket.id}</strong>
|
||||
al cliente <strong>${ticket.clientFk}</strong> porque no tiene un email especificado.<br/><br/>
|
||||
Para dejar de recibir esta notificación, asígnale un email o desactiva la notificación por email para este cliente.`;
|
||||
smtp.send({
|
||||
to: ticket.salesPersonEmail,
|
||||
subject: 'No se ha podido enviar el albarán',
|
||||
html: body
|
||||
});
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const args = {
|
||||
ticketId: ticket.id,
|
||||
recipientId: ticket.clientFk,
|
||||
|
@ -52,7 +71,7 @@ module.exports = app => {
|
|||
|
||||
// Send email with failed tickets
|
||||
if (failedtickets.length > 0) {
|
||||
let body = 'This following tickets has failed:<br/><br/>';
|
||||
let body = 'This following tickets have failed:<br/><br/>';
|
||||
|
||||
for (ticket of failedtickets) {
|
||||
body += `Ticket: <strong>${ticket.id}</strong>
|
||||
|
@ -61,7 +80,7 @@ module.exports = app => {
|
|||
|
||||
smtp.send({
|
||||
to: config.app.reportEmail,
|
||||
subject: '[API] Nightly ticket closure has failed',
|
||||
subject: '[API] Nightly ticket closure report',
|
||||
html: body
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue