From 4e78307a8de2d494e423f205a2b57eebcf976237 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 6 May 2024 14:51:53 +0200 Subject: [PATCH 1/5] feat: refs #6739 transferInvoice new functionality --- .../methods/invoiceOut/transferInvoice.js | 13 +++++-- .../front/descriptor-menu/index.html | 10 +++++ .../invoiceOut/front/descriptor-menu/index.js | 37 ++++++++++++++++--- .../front/descriptor-menu/locale/en.yml | 5 ++- .../front/descriptor-menu/locale/es.yml | 3 ++ 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js index 8e234d7cc..b5eb9bed5 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js @@ -36,6 +36,11 @@ module.exports = Self => { type: 'number', required: true }, + { + arg: 'checked', + type: 'boolean', + required: true + }, ], returns: { type: 'boolean', @@ -51,6 +56,7 @@ module.exports = Self => { const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; const {id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk} = ctx.args; + const checked = ctx.args.checked; let tx; if (typeof options == 'object') Object.assign(myOptions, options); @@ -96,9 +102,10 @@ module.exports = Self => { await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions); - const [invoiceId] = await models.Ticket.invoiceTicketsAndPdf(ctx, clonedTicketIds, null, myOptions); - - return invoiceId; + if (!checked) { + const [invoiceId] = await models.Ticket.invoiceTicketsAndPdf(ctx, clonedTicketIds, null, myOptions); + return invoiceId; + } } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/invoiceOut/front/descriptor-menu/index.html b/modules/invoiceOut/front/descriptor-menu/index.html index 1bf34831e..18ebdda3c 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.html +++ b/modules/invoiceOut/front/descriptor-menu/index.html @@ -215,6 +215,7 @@ show-field="description" value-field="id" ng-model="$ctrl.cplusRectificationType" + ng-init="$ctrl.cplusRectificationType = (cplusRectificationTypes.length > 0 ? cplusRectificationTypes[1].id : null)" search-function="{or: [{id: $search}, {description: {like: '%'+ $search +'%'}}]}" label="Rectificative type"> @@ -232,6 +233,7 @@ fields="['id','code','description']" required="true" ng-model="$ctrl.siiTypeInvoiceOut" + ng-init="$ctrl.siiTypeInvoiceOut = (siiTypeInvoiceOuts.length > 0 ? siiTypeInvoiceOuts[3].id : null)" label="Class"> {{::code}} - {{::description}} @@ -248,6 +250,14 @@ label="Type"> + + + + diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index 5184c137e..746e42522 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.js +++ b/modules/invoiceOut/front/descriptor-menu/index.js @@ -7,6 +7,7 @@ class Controller extends Section { super($element, $); this.vnReport = vnReport; this.vnEmail = vnEmail; + this.checked = true; } get invoiceOut() { @@ -23,6 +24,14 @@ class Controller extends Section { return this.aclService.hasAny(['invoicing']); } + get isChecked() { + return this.checked; + } + + set isChecked(value) { + this.checked = value; + } + loadData() { const filter = { include: [ @@ -34,7 +43,7 @@ class Controller extends Section { }, { relation: 'client', scope: { - fields: ['id', 'name', 'email'] + fields: ['id', 'name', 'email', 'hasToInvoiceByAddress'] } } ] @@ -136,12 +145,28 @@ class Controller extends Section { newClientFk: this.clientId, cplusRectificationTypeFk: this.cplusRectificationType, siiTypeInvoiceOutFk: this.siiTypeInvoiceOut, - invoiceCorrectionTypeFk: this.invoiceCorrectionType + invoiceCorrectionTypeFk: this.invoiceCorrectionType, + checked: this.checked }; - this.$http.post(`InvoiceOuts/transferInvoice`, params).then(res => { - const invoiceId = res.data; - this.vnApp.showSuccess(this.$t('Transferred invoice')); - this.$state.go('invoiceOut.card.summary', {id: invoiceId}); + this.$http.get(`Clients/${this.clientId}`).then(response => { + const clientData = response.data; + const hasToInvoiceByAddress = clientData.hasToInvoiceByAddress; + + if (this.checked && hasToInvoiceByAddress) { + if (window.confirm('El cliente destino tiene marcado facturar por consignatario, ¿desea continuar?')) { + this.$http.post(`InvoiceOuts/transferInvoice`, params).then(res => { + const invoiceId = res.data; + this.vnApp.showSuccess(this.$t('Transferred invoice')); + this.$state.go('invoiceOut.card.summary', {id: invoiceId}); + }); + } + } else { + this.$http.post(`InvoiceOuts/transferInvoice`, params).then(res => { + const invoiceId = res.data; + this.vnApp.showSuccess(this.$t('Transferred invoice')); + this.$state.go('invoiceOut.card.summary', {id: invoiceId}); + }); + } }); } } diff --git a/modules/invoiceOut/front/descriptor-menu/locale/en.yml b/modules/invoiceOut/front/descriptor-menu/locale/en.yml index 8fad5f25e..5470424cf 100644 --- a/modules/invoiceOut/front/descriptor-menu/locale/en.yml +++ b/modules/invoiceOut/front/descriptor-menu/locale/en.yml @@ -1,3 +1,6 @@ The following refund tickets have been created: "The following refund tickets have been created: {{ticketIds}}" Transfer invoice to...: Transfer invoice to... -Cplus Type: Cplus Type \ No newline at end of file +Cplus Type: Cplus Type +transferInvoice: Transfer Invoice +destinationClient: Bill destination client +checkinfo: New tickets from the destination customer will be generated in the consignee by default. \ No newline at end of file diff --git a/modules/invoiceOut/front/descriptor-menu/locale/es.yml b/modules/invoiceOut/front/descriptor-menu/locale/es.yml index 9285fafa7..75f1ab2c7 100644 --- a/modules/invoiceOut/front/descriptor-menu/locale/es.yml +++ b/modules/invoiceOut/front/descriptor-menu/locale/es.yml @@ -24,3 +24,6 @@ Refund...: Abono... Transfer invoice to...: Transferir factura a... Rectificative type: Tipo rectificativa Transferred invoice: Factura transferida +transferInvoice: Transferir factura +destinationClient: Facturar cliente destino +checkinfo: Los nuevos tickets del cliente destino, serán generados en el consignatario por defecto. \ No newline at end of file From d4f734455d3163040e5e662a2db2de44d66a2623 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 7 May 2024 11:35:05 +0200 Subject: [PATCH 2/5] refactor: refs #6739 transferInvoice() refactor --- .../methods/invoiceOut/makePdfAndNotify.js | 1 - .../invoiceOut/front/descriptor-menu/index.js | 27 +++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/makePdfAndNotify.js b/modules/invoiceOut/back/methods/invoiceOut/makePdfAndNotify.js index 4bba2498f..e2dc15993 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/makePdfAndNotify.js +++ b/modules/invoiceOut/back/methods/invoiceOut/makePdfAndNotify.js @@ -33,7 +33,6 @@ module.exports = Self => { try { await Self.makePdf(id, options); } catch (err) { - console.error(err); throw new UserError('Error while generating PDF', 'pdfError'); } diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index 746e42522..c29e4b788 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.js +++ b/modules/invoiceOut/front/descriptor-menu/index.js @@ -148,25 +148,24 @@ class Controller extends Section { invoiceCorrectionTypeFk: this.invoiceCorrectionType, checked: this.checked }; + + const transferInvoiceRequest = () => { + this.$http.post(`InvoiceOuts/transferInvoice`, params).then(res => { + const invoiceId = res.data; + this.vnApp.showSuccess(this.$t('Transferred invoice')); + this.$state.go('invoiceOut.card.summary', {id: invoiceId}); + }); + }; + this.$http.get(`Clients/${this.clientId}`).then(response => { const clientData = response.data; const hasToInvoiceByAddress = clientData.hasToInvoiceByAddress; if (this.checked && hasToInvoiceByAddress) { - if (window.confirm('El cliente destino tiene marcado facturar por consignatario, ¿desea continuar?')) { - this.$http.post(`InvoiceOuts/transferInvoice`, params).then(res => { - const invoiceId = res.data; - this.vnApp.showSuccess(this.$t('Transferred invoice')); - this.$state.go('invoiceOut.card.summary', {id: invoiceId}); - }); - } - } else { - this.$http.post(`InvoiceOuts/transferInvoice`, params).then(res => { - const invoiceId = res.data; - this.vnApp.showSuccess(this.$t('Transferred invoice')); - this.$state.go('invoiceOut.card.summary', {id: invoiceId}); - }); - } + if (window.confirm('El cliente destino tiene marcado facturar por consignatario, ¿desea continuar?')) + transferInvoiceRequest(); + } else + transferInvoiceRequest(); }); } } From 9d75ba0bc56bfe17aa8ab4c849200deff2785ce4 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 8 May 2024 14:12:10 +0200 Subject: [PATCH 3/5] refactor: refs #6739 default params --- .../front/descriptor-menu/index.html | 20 ++---------- .../invoiceOut/front/descriptor-menu/index.js | 31 ++++++++++++------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/modules/invoiceOut/front/descriptor-menu/index.html b/modules/invoiceOut/front/descriptor-menu/index.html index 18ebdda3c..573694807 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.html +++ b/modules/invoiceOut/front/descriptor-menu/index.html @@ -1,15 +1,3 @@ - - - - - {{::description}} + {{ ::description}} @@ -227,13 +214,12 @@ {{::code}} - {{::description}} diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index c29e4b788..8047e1c14 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.js +++ b/modules/invoiceOut/front/descriptor-menu/index.js @@ -8,6 +8,16 @@ class Controller extends Section { this.vnReport = vnReport; this.vnEmail = vnEmail; this.checked = true; + this.$http.get(`CplusRectificationTypes`, {filter: {order: 'description'}}) + .then(res => { + this.cplusRectificationTypes = res.data; + this.cplusRectificationType = res.data.filter(type => type.description == 'I – Por diferencias')[0].id; + }); + this.$http.get(`SiiTypeInvoiceOuts`, {filter: {where: {code: {like: 'R%'}}}}) + .then(res => { + this.siiTypeInvoiceOuts = res.data; + this.siiTypeInvoiceOut = res.data.filter(type => type.code == 'R4')[0].id; + }); } get invoiceOut() { @@ -149,23 +159,20 @@ class Controller extends Section { checked: this.checked }; - const transferInvoiceRequest = () => { - this.$http.post(`InvoiceOuts/transferInvoice`, params).then(res => { - const invoiceId = res.data; - this.vnApp.showSuccess(this.$t('Transferred invoice')); - this.$state.go('invoiceOut.card.summary', {id: invoiceId}); - }); - }; - this.$http.get(`Clients/${this.clientId}`).then(response => { const clientData = response.data; const hasToInvoiceByAddress = clientData.hasToInvoiceByAddress; if (this.checked && hasToInvoiceByAddress) { - if (window.confirm('El cliente destino tiene marcado facturar por consignatario, ¿desea continuar?')) - transferInvoiceRequest(); - } else - transferInvoiceRequest(); + if (!window.confirm('El cliente destino tiene marcado facturar por consignatario, ¿desea continuar?')) + return; + } + + this.$http.post(`InvoiceOuts/transferInvoice`, params).then(res => { + const invoiceId = res.data; + this.vnApp.showSuccess(this.$t('Transferred invoice')); + this.$state.go('invoiceOut.card.summary', {id: invoiceId}); + }); }); } } From 77c2f61f47cd25f79d2c13cea4f021cd66548774 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 8 May 2024 14:30:20 +0200 Subject: [PATCH 4/5] refs #6739 move petitions --- .../invoiceOut/front/descriptor-menu/index.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index 8047e1c14..927fec955 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.js +++ b/modules/invoiceOut/front/descriptor-menu/index.js @@ -8,16 +8,6 @@ class Controller extends Section { this.vnReport = vnReport; this.vnEmail = vnEmail; this.checked = true; - this.$http.get(`CplusRectificationTypes`, {filter: {order: 'description'}}) - .then(res => { - this.cplusRectificationTypes = res.data; - this.cplusRectificationType = res.data.filter(type => type.description == 'I – Por diferencias')[0].id; - }); - this.$http.get(`SiiTypeInvoiceOuts`, {filter: {where: {code: {like: 'R%'}}}}) - .then(res => { - this.siiTypeInvoiceOuts = res.data; - this.siiTypeInvoiceOut = res.data.filter(type => type.code == 'R4')[0].id; - }); } get invoiceOut() { @@ -42,6 +32,18 @@ class Controller extends Section { this.checked = value; } + $onInit() { + this.$http.get(`CplusRectificationTypes`, {filter: {order: 'description'}}) + .then(res => { + this.cplusRectificationTypes = res.data; + this.cplusRectificationType = res.data.filter(type => type.description == 'I – Por diferencias')[0].id; + }); + this.$http.get(`SiiTypeInvoiceOuts`, {filter: {where: {code: {like: 'R%'}}}}) + .then(res => { + this.siiTypeInvoiceOuts = res.data; + this.siiTypeInvoiceOut = res.data.filter(type => type.code == 'R4')[0].id; + }); + } loadData() { const filter = { include: [ From 58aedf160b3557f61cb40aec1a827cab7006ffc9 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 9 May 2024 08:05:23 +0200 Subject: [PATCH 5/5] refactor: refs #6739 changed translations' keys --- modules/invoiceOut/front/descriptor-menu/index.html | 2 +- modules/invoiceOut/front/descriptor-menu/index.js | 2 +- modules/invoiceOut/front/descriptor-menu/locale/en.yml | 3 ++- modules/invoiceOut/front/descriptor-menu/locale/es.yml | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/invoiceOut/front/descriptor-menu/index.html b/modules/invoiceOut/front/descriptor-menu/index.html index 573694807..da04c8e72 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.html +++ b/modules/invoiceOut/front/descriptor-menu/index.html @@ -240,7 +240,7 @@ diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index 927fec955..0d7fb32dd 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.js +++ b/modules/invoiceOut/front/descriptor-menu/index.js @@ -166,7 +166,7 @@ class Controller extends Section { const hasToInvoiceByAddress = clientData.hasToInvoiceByAddress; if (this.checked && hasToInvoiceByAddress) { - if (!window.confirm('El cliente destino tiene marcado facturar por consignatario, ¿desea continuar?')) + if (!window.confirm(this.$t('confirmTransferInvoice'))) return; } diff --git a/modules/invoiceOut/front/descriptor-menu/locale/en.yml b/modules/invoiceOut/front/descriptor-menu/locale/en.yml index 5470424cf..32ea03442 100644 --- a/modules/invoiceOut/front/descriptor-menu/locale/en.yml +++ b/modules/invoiceOut/front/descriptor-menu/locale/en.yml @@ -3,4 +3,5 @@ Transfer invoice to...: Transfer invoice to... Cplus Type: Cplus Type transferInvoice: Transfer Invoice destinationClient: Bill destination client -checkinfo: New tickets from the destination customer will be generated in the consignee by default. \ No newline at end of file +transferInvoiceInfo: New tickets from the destination customer will be generated in the default consignee. +confirmTransferInvoice: Destination customer has marked to bill by consignee, do you want to continue? \ No newline at end of file diff --git a/modules/invoiceOut/front/descriptor-menu/locale/es.yml b/modules/invoiceOut/front/descriptor-menu/locale/es.yml index 75f1ab2c7..92c109878 100644 --- a/modules/invoiceOut/front/descriptor-menu/locale/es.yml +++ b/modules/invoiceOut/front/descriptor-menu/locale/es.yml @@ -26,4 +26,5 @@ Rectificative type: Tipo rectificativa Transferred invoice: Factura transferida transferInvoice: Transferir factura destinationClient: Facturar cliente destino -checkinfo: Los nuevos tickets del cliente destino, serán generados en el consignatario por defecto. \ No newline at end of file +transferInvoiceInfo: Los nuevos tickets del cliente destino serán generados en el consignatario por defecto. +confirmTransferInvoice: El cliente destino tiene marcado facturar por consignatario, ¿desea continuar? \ No newline at end of file