Merge pull request 'hotFix_closeAll_emailDeliveryNote' (!3496) from hotFix_closeAll_emailDeliveryNote into master
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #3496 Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
commit
73d92db112
|
@ -1,5 +1,6 @@
|
||||||
const smtp = require('vn-print/core/smtp');
|
const smtp = require('vn-print/core/smtp');
|
||||||
const config = require('vn-print/core/config');
|
const config = require('vn-print/core/config');
|
||||||
|
const Email = require('vn-print/core/email');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('closeAll', {
|
Self.remoteMethodCtx('closeAll', {
|
||||||
|
@ -44,8 +45,7 @@ module.exports = Self => {
|
||||||
LIMIT 1`, [toDate, toDate], myOptions);
|
LIMIT 1`, [toDate, toDate], myOptions);
|
||||||
|
|
||||||
await Self.rawSql(`
|
await Self.rawSql(`
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close;
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_close
|
||||||
CREATE TEMPORARY TABLE tmp.ticket_close
|
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
WITH wTickets AS(
|
WITH wTickets AS(
|
||||||
SELECT t.id ticketFk
|
SELECT t.id ticketFk
|
||||||
|
@ -63,11 +63,12 @@ module.exports = Self => {
|
||||||
FROM wTicketsTracking wt
|
FROM wTicketsTracking wt
|
||||||
JOIN ticketTracking tt ON tt.id = wt.maxTracking
|
JOIN ticketTracking tt ON tt.id = wt.maxTracking
|
||||||
) SELECT tls.ticketFk,
|
) SELECT tls.ticketFk,
|
||||||
t.clientFk,
|
t.clientFk clientId,
|
||||||
c.name clientName,
|
c.name clientName,
|
||||||
c.email recipient,
|
c.email recipient,
|
||||||
|
c.isToBeMailed,
|
||||||
eu.email salesPersonEmail,
|
eu.email salesPersonEmail,
|
||||||
t.addressFk,
|
t.addressFk addressId,
|
||||||
c.hasDailyInvoice,
|
c.hasDailyInvoice,
|
||||||
c.hasToInvoiceByAddress,
|
c.hasToInvoiceByAddress,
|
||||||
t.totalWithVat,
|
t.totalWithVat,
|
||||||
|
@ -79,7 +80,7 @@ module.exports = Self => {
|
||||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||||
JOIN client c ON c.id = t.clientFk
|
JOIN client c ON c.id = t.clientFk
|
||||||
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
||||||
WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered'));
|
WHERE al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered');
|
||||||
CALL ticket_close();
|
CALL ticket_close();
|
||||||
`, [dateFrom, dateTo], myOptions);
|
`, [dateFrom, dateTo], myOptions);
|
||||||
|
|
||||||
|
@ -98,19 +99,25 @@ module.exports = Self => {
|
||||||
AND tob.id IS NULL
|
AND tob.id IS NULL
|
||||||
AND t.routeFk`, [dateFrom, dateTo], myOptions);
|
AND t.routeFk`, [dateFrom, dateTo], myOptions);
|
||||||
|
|
||||||
const [clients] = await Self.rawSql(`
|
const clients = await Self.rawSql(`
|
||||||
SELECT clientFk clientId,
|
SELECT *,
|
||||||
clientName,
|
|
||||||
recipient,
|
|
||||||
salesPersonEmail,
|
|
||||||
addressFk addressId,
|
|
||||||
companyFk,
|
|
||||||
SUM(totalWithVat) total,
|
SUM(totalWithVat) total,
|
||||||
'quick' serialType
|
'quick' serialType
|
||||||
FROM tmp.ticket_close
|
FROM tmp.ticket_close
|
||||||
WHERE hasDailyInvoice
|
WHERE hasDailyInvoice
|
||||||
GROUP BY IF (hasToInvoiceByAddress, addressFk, clientFk), companyFk
|
GROUP BY IF (hasToInvoiceByAddress, addressId, clientId), companyFk
|
||||||
HAVING total > 0;
|
HAVING total > 0
|
||||||
|
`, [], myOptions);
|
||||||
|
|
||||||
|
const [ticketsToMail] = await Self.rawSql(`
|
||||||
|
SELECT *
|
||||||
|
FROM tmp.ticket_close
|
||||||
|
WHERE NOT hasDailyInvoice
|
||||||
|
AND isToBeMailed
|
||||||
|
AND salesPersonEmail IS NOT NULL
|
||||||
|
AND salesPersonEmail <> ''
|
||||||
|
AND recipient IS NOT NULL
|
||||||
|
AND recipient <> '';
|
||||||
DROP TEMPORARY TABLE tmp.ticket_close;
|
DROP TEMPORARY TABLE tmp.ticket_close;
|
||||||
`, [], myOptions);
|
`, [], myOptions);
|
||||||
|
|
||||||
|
@ -130,21 +137,23 @@ module.exports = Self => {
|
||||||
if (id)
|
if (id)
|
||||||
await Self.app.models.InvoiceOut.makePdfAndNotify(ctx, id, null, nestedTransaction);
|
await Self.app.models.InvoiceOut.makePdfAndNotify(ctx, id, null, nestedTransaction);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await Self.rawSql(`
|
await handleInvoicingError(error, client, failedClients);
|
||||||
INSERT INTO util.debug (variable, value)
|
}
|
||||||
VALUES ('invoicingTicketError', ?)
|
|
||||||
`, [client.clientId + ' - ' + error]);
|
|
||||||
|
|
||||||
if (error.responseCode == 450) {
|
|
||||||
await invalidEmail(client);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
failedClients.push({
|
for (const ticket of ticketsToMail) {
|
||||||
id: client.clientId,
|
const args = {
|
||||||
address: client.addressId,
|
id: ticket.ticketFk,
|
||||||
error
|
recipientId: ticket.clientId,
|
||||||
});
|
recipient: ticket.recipient,
|
||||||
|
replyTo: ticket.salesPersonEmail,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const email = new Email('delivery-note-link', args);
|
||||||
|
await email.send();
|
||||||
|
} catch (error) {
|
||||||
|
await handleInvoicingError(error, ticket, failedClients);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,4 +197,22 @@ module.exports = Self => {
|
||||||
html: body,
|
html: body,
|
||||||
}).catch(err => console.error(err));
|
}).catch(err => console.error(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleInvoicingError(error, entity, failedClients) {
|
||||||
|
await Self.rawSql(`
|
||||||
|
INSERT INTO util.debug (variable, value)
|
||||||
|
VALUES ('invoicingTicketError', ?)
|
||||||
|
`, [entity.clientId + ' - ' + error]);
|
||||||
|
|
||||||
|
if (error.responseCode == 450) {
|
||||||
|
await invalidEmail(entity);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
failedClients.push({
|
||||||
|
id: entity.clientId,
|
||||||
|
address: entity.addressId,
|
||||||
|
error
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
buttons:
|
||||||
|
webAcccess: Visita la nostra Web
|
||||||
|
info: Ajuda'ns a millorar
|
||||||
|
fiscalAddress: VERDNATURA LEVANTE SL, B97367486 C/ Fenollar, 2. 46680 ALGEMESÍ
|
||||||
|
· verdnatura.es · clientes@verdnatura.es
|
||||||
|
disclaimer: '- AVÍS - Aquest missatge és privat i confidencial, i ha de ser utilitzat
|
||||||
|
exclusivament per la persona destinatària del mateix. Si has rebut aquest missatge
|
||||||
|
per error, et preguem que ho comuniquis al remitent i esborres aquest missatge
|
||||||
|
i qualsevol document adjunt que pugui contenir. Verdnatura Levante SL no renuncia
|
||||||
|
a la confidencialitat ni a cap privilegi per causa de transmissió errònia o mal
|
||||||
|
funcionament. Igualment, no es fa responsable dels canvis, alteracions, errors
|
||||||
|
o omissions que es puguin fer al missatge un cop enviat.'
|
||||||
|
privacy: En compliment del que disposa la Llei Orgànica 15/1999, de Protecció de
|
||||||
|
Dades de Caràcter Personal, et comuniquem que les dades personals que facilitis
|
||||||
|
s'inclouran en fitxers automatitzats de VERDNATURA LEVANTE S.L., podent en tot
|
||||||
|
moment exercir els drets d'accés, rectificació, cancel·lació i oposició,
|
||||||
|
comunicant-ho per escrit al domicili social de l'entitat. La finalitat del
|
||||||
|
fitxer és la gestió administrativa, comptabilitat i facturació.
|
|
@ -0,0 +1,11 @@
|
||||||
|
subject: El teu albarà
|
||||||
|
title: El teu albarà
|
||||||
|
dear: Estimat client
|
||||||
|
description: Ja està disponible l'albarà corresponent a la comanda <strong>{0}</strong>. <br/>
|
||||||
|
Pots veure'l fent clic <a href="https://shop.verdnatura.es/#!form=ecomerce/ticket&ticket={0}">en aquest enllaç</a>.
|
||||||
|
copyLink: 'Com a alternativa, pots copiar el següent enllaç al teu navegador:'
|
||||||
|
poll: Si ho desitges, pots respondre a la nostra enquesta de satisfacció per
|
||||||
|
ajudar-nos a oferir un millor servei. La teva opinió és molt important per a nosaltres!
|
||||||
|
help: Qualsevol dubte que tinguis, no dubtis a consultar-nos, <strong>estem aquí
|
||||||
|
per atendre't!</strong>
|
||||||
|
conclusion: Gràcies per la teva atenció!
|
Loading…
Reference in New Issue