diff --git a/loopback/locale/en.json b/loopback/locale/en.json index a7e21960b..9bd9f01f6 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -240,6 +240,7 @@ "There is already a tray with the same height": "There is already a tray with the same height", "The height must be greater than 50cm": "The height must be greater than 50cm", "The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm", - "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", - "There are tickets for this area, delete them first": "There are tickets for this area, delete them first" -} + "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", + "There are tickets for this area, delete them first": "There are tickets for this area, delete them first", + "ticketLostExpeditions": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expeditions :{{ expeditionsId }}" +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index a97da3194..dc91bbe2c 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -384,5 +384,6 @@ "No valid travel thermograph found": "No se encontró un termógrafo válido", "The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea", "type cannot be blank": "Se debe rellenar el tipo", - "There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero" -} + "There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero", + "ticketLostExpeditions": "El ticket [{{ticketId}}]({{{ticketUrl}}}) tiene las siguientes expediciones perdidas :{{ expeditionsId }}" +} \ No newline at end of file diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 23bd5cc04..45f4d3fad 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -123,8 +123,8 @@ "Added sale to ticket": "J'ai ajouté la ligne suivante au ticket [{{ticketId}}]({{{ticketUrl}}}): {{{addition}}}", "Changed sale discount": "J'ai changé le rabais des lignes suivantes du ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Created claim": "J'ai créé la réclamation [{{claimId}}]({{{claimUrl}}}) des lignes suivantes du ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", - "Changed sale price": " le prix de [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* du ticket [{{ticketId}}]({{{ticketUrl}}})",, - "Changed sale quantity": "J'ai changé {{changes}} du ticket [{{ticketId}}]({{{ticketUrl}}})", + "Changed sale price": " le prix de [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* du ticket [{{ticketId}}]({{{ticketUrl}}})", + "Changed sale quantity": "J'ai changé {{changes}} du ticket [{{ticketId}}]({{{ticketUrl}}})", "Changes in sales": "la quantité de {{itemId}} {{concept}} de {{oldQuantity}} ➔ {{newQuantity}}", "State": "État", "regular": "normal", @@ -362,6 +362,7 @@ "The invoices have been created but the PDFs could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré", "It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré", "Cannot send mail": "Impossible d'envoyer le mail", - "Original invoice not found": "Facture originale introuvable", - "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne" -} + "Original invoice not found": "Facture originale introuvable", + "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne", + "ticketLostExpeditions": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a les expéditions perdues suivantes :{{ expeditionsId }}" +} \ No newline at end of file diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index f85afd607..5d63d02bc 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -124,7 +124,7 @@ "Changed sale discount": "Desconto da venda alterado no ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Created claim": "Reclamação criada [{{claimId}}]({{{claimUrl}}}) no ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Changed sale price": "Preço da venda alterado para [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* no ticket [{{ticketId}}]({{{ticketUrl}}})", - "Changed sale quantity": "Quantidade da venda alterada para {{changes}} no ticket [{{ticketId}}]({{{ticketUrl}}})", + "Changed sale quantity": "Quantidade da venda alterada para {{changes}} no ticket [{{ticketId}}]({{{ticketUrl}}})", "Changes in sales": " [{{itemId}} {{concept}}]({{{itemUrl}}}) de {{oldQuantity}} ➔ *{{newQuantity}}* ", "State": "Estado", "regular": "normal", @@ -361,7 +361,8 @@ "It was not able to create the invoice": "Não foi possível criar a fatura", "The invoices have been created but the PDFs could not be generated": "Foi faturado, mas o PDF não pôde ser gerado", "It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso", - "Original invoice not found": "Fatura original não encontrada", + "Original invoice not found": "Fatura original não encontrada", "Cannot send mail": "Não é possível enviar o email", - "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha" -} + "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha", + "ticketLostExpeditions": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem as seguintes expedições perdidas:{{ expeditionsId }}" +} \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index bc0da686c..38bb5a194 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -37,6 +37,7 @@ module.exports = Self => { let dms; let isSignUploaded; let externalTickets = []; + const $t = ctx.req.__; if (typeof options == 'object') Object.assign(myOptions, options); @@ -111,6 +112,12 @@ module.exports = Self => { scope: { fields: ['id'] } + }, + { + relation: 'client', + scope: { + fields: ['salesPersonFk'] + } }] }, myOptions); @@ -140,17 +147,41 @@ module.exports = Self => { await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions); await ticket.updateAttribute('isSigned', true, myOptions); - const [{stateCode}] = await Self.rawSql(` - SELECT - IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), - 'DELIVERED','PARTIAL_DELIVERED') stateCode + const ticketStateExpeditions = await Self.rawSql(` + WITH expeditionsLost AS ( + SELECT e.id FROM vn.expedition e - JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk - WHERE e.ticketFk = ?; - `, [ticketId], myOptions); + JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk + WHERE e.ticketFk = ? AND est.code = 'LOST' + ),ticketStateCode AS ( + SELECT + IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), + 'DELIVERED', 'PARTIAL_DELIVERED') stateCode + FROM vn.expedition e + JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk + WHERE e.ticketFk = ? + ) + SELECT el.id, ts.stateCode + FROM ticketStateCode ts + LEFT JOIN expeditionsLost el ON TRUE; + `, [ticketId, ticketId], myOptions); + const stateCode = ticketStateExpeditions[0]?.stateCode; await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateCode], myOptions); + const expeditionsIds = ticketStateExpeditions.map(result => result.id).filter(id => id !== null); + + const url = await Self.app.models.Url.getUrl(); + + expeditionsIds.length + && ticket.client()?.salesPersonFk + && await models.Chat.sendCheckingPresence(ctx, ticket.client().salesPersonFk, + $t('ticketLostExpeditions', { + ticketId: ticket.id, + ticketUrl: `${url}ticket/${ticket.id}/expedition`, + expeditionsId: expeditionsIds + }) + ); if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.cmrFk) { await models.Ticket.saveCmr(ctx, [ticketId], myOptions); externalTickets.push(ticketId); diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index e93408973..b62629ed7 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -1,12 +1,15 @@ const models = require('vn-loopback/server/server').models; describe('Ticket saveSign()', () => { - let ctx = {req: { - getLocale: () => { - return 'en'; - }, - accessToken: {userId: 9} - }}; + let ctx = { + req: { + getLocale: () => { + return 'en'; + }, + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'}, + __: value => value + }}; it(`should throw error if the ticket's alert level is lower than 2`, async() => { const tx = await models.TicketDms.beginTransaction({});