From 9b8c58ba7d4f95bcfc84b07f1ffd93f1753a6b9a Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 29 Jan 2024 16:00:24 +0100 Subject: [PATCH 1/3] refs #6270 makeInvoice --- .../ticket/back/methods/ticket/makeInvoice.js | 9 ++++- modules/ticket/front/descriptor-menu/index.js | 40 ++++++++++--------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/modules/ticket/back/methods/ticket/makeInvoice.js b/modules/ticket/back/methods/ticket/makeInvoice.js index 83222a4ee..1fcbd4130 100644 --- a/modules/ticket/back/methods/ticket/makeInvoice.js +++ b/modules/ticket/back/methods/ticket/makeInvoice.js @@ -110,7 +110,14 @@ module.exports = function(Self) { if (tx) await tx.commit(); - return resultInvoice.id; + const notificationInfo = { + clientName: firstTicket.clientFk.name, + clientEmail: firstTicket.clientFk.email, + ticketId: resultInvoice.id, + url: ctx.req.headers.referer + }; + + return {invoiceId: resultInvoice.id, notificationInfo}; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index cd819e623..4e33d2c43 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -248,26 +248,30 @@ class Controller extends Section { if (this.ticket.address.incotermsFk && !this.ticket.weight && !force) return this.$.withoutWeightConfirmation.show(); - const client = this.ticket.client; - if (client.hasElectronicInvoice) { - this.$http.post(`NotificationQueues`, { - notificationFk: 'invoice-electronic', - authorFk: client.id, - params: JSON.stringify( - { - 'name': client.name, - 'email': client.email, - 'ticketId': this.id, - 'url': window.location.href - }) - }).then(() => { - this.vnApp.showSuccess(this.$t('Invoice sent')); - }); - } - return this.$http.post(`Tickets/invoiceTickets`, {ticketsIds: [this.id]}) .then(() => this.reload()) - .then(() => this.vnApp.showSuccess(this.$t('Ticket invoiced'))); + .then(() => { + const client = this.ticket.client; + + if (client.hasElectronicInvoice) { + const notificationData = { + name: client.name, + email: client.email, + ticketId: this.id, + url: window.location.href + }; + + this.$http.post(`NotificationQueues`, { + notificationFk: 'invoice-electronic', + authorFk: client.id, + params: JSON.stringify(notificationData) + }).then(() => { + this.vnApp.showSuccess(this.$t('Invoice sent')); + }); + } + + this.vnApp.showSuccess(this.$t('Ticket invoiced')); + }); } createPdfInvoice() { From 509d5cea14c8912dde579cf1f663ef77687016f4 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 30 Jan 2024 15:54:03 +0100 Subject: [PATCH 2/3] refs #6270 fix back --- .../ticket/back/methods/ticket/makeInvoice.js | 26 +++++++++++++------ modules/ticket/front/descriptor-menu/index.js | 23 +--------------- .../invoice-electronic/invoice-electronic.js | 2 +- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/modules/ticket/back/methods/ticket/makeInvoice.js b/modules/ticket/back/methods/ticket/makeInvoice.js index 1fcbd4130..706da6f39 100644 --- a/modules/ticket/back/methods/ticket/makeInvoice.js +++ b/modules/ticket/back/methods/ticket/makeInvoice.js @@ -108,16 +108,26 @@ module.exports = function(Self) { await Self.rawSql('CALL invoiceOutBooking(?)', [resultInvoice.id], myOptions); + const client = await models.Client.findById(clientId, + {fields: ['hasElectronicInvoice', 'name', 'email']}, myOptions); + if (client.hasElectronicInvoice) { + const url = await models.Url.getUrl(); + await models.NotificationQueue.create({ + notificationFk: 'invoice-electronic', + authorFk: client.id, + params: JSON.stringify( + { + 'name': client.name, + 'email': client.email, + 'ticketId': ticketsIds.join(','), + 'url': url + 'ticket/index?q=' + encodeURIComponent(JSON.stringify({clientFk: clientId})) + }) + }, myOptions); + } + if (tx) await tx.commit(); - const notificationInfo = { - clientName: firstTicket.clientFk.name, - clientEmail: firstTicket.clientFk.email, - ticketId: resultInvoice.id, - url: ctx.req.headers.referer - }; - - return {invoiceId: resultInvoice.id, notificationInfo}; + return resultInvoice.id; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 4e33d2c43..c254900cc 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -250,28 +250,7 @@ class Controller extends Section { return this.$http.post(`Tickets/invoiceTickets`, {ticketsIds: [this.id]}) .then(() => this.reload()) - .then(() => { - const client = this.ticket.client; - - if (client.hasElectronicInvoice) { - const notificationData = { - name: client.name, - email: client.email, - ticketId: this.id, - url: window.location.href - }; - - this.$http.post(`NotificationQueues`, { - notificationFk: 'invoice-electronic', - authorFk: client.id, - params: JSON.stringify(notificationData) - }).then(() => { - this.vnApp.showSuccess(this.$t('Invoice sent')); - }); - } - - this.vnApp.showSuccess(this.$t('Ticket invoiced')); - }); + .then(() => this.vnApp.showSuccess(this.$t('Ticket invoiced'))); } createPdfInvoice() { diff --git a/print/templates/email/invoice-electronic/invoice-electronic.js b/print/templates/email/invoice-electronic/invoice-electronic.js index 2e1e739ac..1ec6d1374 100644 --- a/print/templates/email/invoice-electronic/invoice-electronic.js +++ b/print/templates/email/invoice-electronic/invoice-electronic.js @@ -10,7 +10,7 @@ module.exports = { required: true }, ticketId: { - type: [Number], + type: [String], required: true }, url: { From a6ea4ed0485db8d5257bfe07e5c493294379d05d Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 30 Jan 2024 16:42:11 +0100 Subject: [PATCH 3/3] Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6270-electronicInvoiceBack --- loopback/locale/en.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 568916bef..059da6356 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -203,5 +203,7 @@ "Cannot past travels with entries": "Cannot past travels with entries", "It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}", "Incorrect pin": "Incorrect pin.", - "The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified" + "The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified", + "Fecha fuera de rango": "Fecha fuera de rango", + "There is no zone for these parameters 34": "There is no zone for these parameters 34" } \ No newline at end of file