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/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..da04c8e72 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.html +++ b/modules/invoiceOut/front/descriptor-menu/index.html @@ -1,15 +1,3 @@ - - - - - {{::description}} + {{ ::description}} @@ -226,7 +214,7 @@ + + + + diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index 5184c137e..0d7fb32dd 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,26 @@ class Controller extends Section { return this.aclService.hasAny(['invoicing']); } + get isChecked() { + return this.checked; + } + + set isChecked(value) { + 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: [ @@ -34,7 +55,7 @@ class Controller extends Section { }, { relation: 'client', scope: { - fields: ['id', 'name', 'email'] + fields: ['id', 'name', 'email', 'hasToInvoiceByAddress'] } } ] @@ -136,12 +157,24 @@ 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(this.$t('confirmTransferInvoice'))) + 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}); + }); }); } } diff --git a/modules/invoiceOut/front/descriptor-menu/locale/en.yml b/modules/invoiceOut/front/descriptor-menu/locale/en.yml index 8fad5f25e..32ea03442 100644 --- a/modules/invoiceOut/front/descriptor-menu/locale/en.yml +++ b/modules/invoiceOut/front/descriptor-menu/locale/en.yml @@ -1,3 +1,7 @@ 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 +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 9285fafa7..92c109878 100644 --- a/modules/invoiceOut/front/descriptor-menu/locale/es.yml +++ b/modules/invoiceOut/front/descriptor-menu/locale/es.yml @@ -24,3 +24,7 @@ Refund...: Abono... Transfer invoice to...: Transferir factura a... Rectificative type: Tipo rectificativa Transferred invoice: Factura transferida +transferInvoice: Transferir factura +destinationClient: Facturar cliente destino +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