diff --git a/modules/invoiceOut/back/methods/invoiceOut/clientToInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/clientToInvoice.js
index 5466f22ac..cb2bfece7 100644
--- a/modules/invoiceOut/back/methods/invoiceOut/clientToInvoice.js
+++ b/modules/invoiceOut/back/methods/invoiceOut/clientToInvoice.js
@@ -30,10 +30,14 @@ module.exports = Self => {
description: 'The company id to invoice'
}
],
- returns: {
- type: 'object',
- root: true
+ returns: [{
+ arg: 'clientsAndAddresses',
+ type: ['object']
},
+ {
+ arg: 'invoice',
+ type: 'object'
+ }],
http: {
path: '/clientToInvoice',
verb: 'POST'
@@ -94,23 +98,30 @@ module.exports = Self => {
const invoiceableClients = await getInvoiceableClients(ctx, myOptions);
- if (!invoiceableClients.length) return;
+ if (!invoiceableClients) return;
- const clientAndAddress = invoiceableClients.map(
- invoiceableClient => [invoiceableClient.id, invoiceableClient.addressFk]
+ const clientsAndAddresses = invoiceableClients.map(invoiceableClient => {
+ return {
+ clientId: invoiceableClient.id,
+ addressId: invoiceableClient.addressFk
+
+ };
+ }
);
if (tx) await tx.commit();
- return {
- clientAndAddressIds: clientAndAddress,
- invoiceDate: args.invoiceDate,
- maxShipped: args.maxShipped,
- fromClientId: args.fromClientId,
- toClientId: args.toClientId,
- companyFk: args.companyFk,
- minShipped: minShipped
- };
+ return [
+ clientsAndAddresses,
+ {
+ invoiceDate: args.invoiceDate,
+ maxShipped: args.maxShipped,
+ fromClientId: args.fromClientId,
+ toClientId: args.toClientId,
+ companyFk: args.companyFk,
+ minShipped: minShipped
+ }
+ ];
} catch (e) {
if (tx) await tx.rollback();
throw e;
diff --git a/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js b/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js
index a90a986c3..8728a5278 100644
--- a/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js
+++ b/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js
@@ -1,6 +1,6 @@
module.exports = Self => {
Self.remoteMethodCtx('globalInvoicing', {
- description: 'Make a global invoice of a client',
+ description: 'Make a invoice of a client',
accessType: 'WRITE',
accepts: [{
arg: 'clientId',
@@ -17,17 +17,20 @@ module.exports = Self => {
{
arg: 'invoiceDate',
type: 'date',
- description: 'The invoice date'
+ description: 'The invoice date',
+ required: true
},
{
arg: 'maxShipped',
type: 'date',
- description: 'The maximum shipped date'
+ description: 'The maximum shipped date',
+ required: true
},
{
arg: 'fromClientId',
type: 'number',
- description: 'The minimum client id'
+ description: 'The minimum client id',
+ required: true
},
{
arg: 'toClientId',
@@ -38,12 +41,14 @@ module.exports = Self => {
{
arg: 'companyFk',
type: 'number',
- description: 'The company id to invoice'
+ description: 'The company id to invoice',
+ required: true
},
{
arg: 'minShipped',
type: 'date',
- description: 'The company id to invoice'
+ description: 'The company id to invoice',
+ required: true
}],
returns: {
type: 'object',
@@ -72,7 +77,6 @@ module.exports = Self => {
const invoicesIds = [];
const failedClients = [];
try {
- // const addresses = await models.Address.find({where: {clientFk: args.clientId}}, myOptions);
const client = await models.Client.findById(args.clientId, {
fields: ['id', 'hasToInvoiceByAddress']
}, myOptions);
diff --git a/modules/invoiceOut/front/index/global-invoicing/index.html b/modules/invoiceOut/front/index/global-invoicing/index.html
index d7b4c3604..a6c7661f5 100644
--- a/modules/invoiceOut/front/index/global-invoicing/index.html
+++ b/modules/invoiceOut/front/index/global-invoicing/index.html
@@ -16,10 +16,12 @@
+ ng-if="$ctrl.lastClientId">
-
- {{$ctrl.currentClientId}} {{$ctrl.$t('of')}} {{$ctrl.lastClientId}}
+
+ {{'Id Client' | translate}}: {{$ctrl.currentClientId}}
+ {{'of' | translate}} {{::$ctrl.lastClientId}}
+
@@ -66,5 +68,5 @@
-
+ {{$ctrl.isInvoicing}}
\ No newline at end of file
diff --git a/modules/invoiceOut/front/index/global-invoicing/index.js b/modules/invoiceOut/front/index/global-invoicing/index.js
index 30d965e9f..a74cf7610 100644
--- a/modules/invoiceOut/front/index/global-invoicing/index.js
+++ b/modules/invoiceOut/front/index/global-invoicing/index.js
@@ -6,7 +6,7 @@ class Controller extends Dialog {
constructor($element, $, $transclude) {
super($element, $, $transclude);
- this.isInvoicing = false;
+ this.lastClientId = null;
this.invoice = {
maxShipped: new Date()
};
@@ -46,7 +46,7 @@ class Controller extends Dialog {
this.invoice.companyFk = value;
}
- responseHandler(response) {
+ async responseHandler(response) {
try {
if (response !== 'accept')
return super.responseHandler(response);
@@ -57,25 +57,49 @@ class Controller extends Dialog {
if (!this.invoice.fromClientId)
throw new Error('Choose a valid clients range');
+ this.on('close', () => {
+ if (this.canceler) this.canceler.resolve();
+ this.vnApp.showSuccess(this.$t('Data saved!'));
+ });
+
return this.$http.post(`InvoiceOuts/clientToInvoice`, this.invoice)
.then(async res => {
- const clientAndAddressIds = res.data.clientAndAddressIds;
- if (!clientAndAddressIds) return super.responseHandler(response);
- this.lastClientId = clientAndAddressIds[clientAndAddressIds.length - 1][0];
- this.isInvoicing = true;
- for (let clientAndAddresId of clientAndAddressIds) {
- this.currentClientId = clientAndAddresId[0];
- res.data.clientId = clientAndAddresId[0];
- res.data.addressId = clientAndAddresId[1];
- await this.$http.post(`InvoiceOuts/globalInvoicing`, res.data);
+ const clientsAndAddresses = res.data.clientsAndAddresses;
+ const invoice = res.data.invoice;
+
+ if (!clientsAndAddresses.length) return super.responseHandler(response);
+ this.lastClientId = clientsAndAddresses[clientsAndAddresses.length - 1].clientId;
+ this.$.invoiceButton.setAttribute('disabled', true);
+ for (let clientAndAddress of clientsAndAddresses) {
+ this.currentClientId = clientAndAddress.clientId;
+ const params = {
+ clientId: clientAndAddress.clientId,
+ addressId: clientAndAddress.addressId,
+ invoiceDate: invoice.invoiceDate,
+ maxShipped: invoice.maxShipped,
+ fromClientId: invoice.fromClientId,
+ toClientId: invoice.toClientId,
+ companyFk: invoice.companyFk,
+ minShipped: invoice.minShipped,
+
+ };
+ this.canceler = this.$q.defer();
+ const options = {
+ timeout: this.canceler.promise
+ };
+ await this.$http.post(`InvoiceOuts/globalInvoicing`, params, options);
}
})
.then(() => super.responseHandler(response))
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
- .finally(() => this.isInvoicing = false);
+ .finally(() => {
+ this.lastClientId = null;
+ this.$.invoiceButton.removeAttribute('disabled');
+ });
} catch (e) {
this.vnApp.showError(this.$t(e.message));
- this.isInvoicing = false;
+ this.lastClientId = null;
+ this.$.invoiceButton.removeAttribute('disabled');
return false;
}
}
diff --git a/modules/invoiceOut/front/index/global-invoicing/locale/es.yml b/modules/invoiceOut/front/index/global-invoicing/locale/es.yml
index 208974307..6245ee208 100644
--- a/modules/invoiceOut/front/index/global-invoicing/locale/es.yml
+++ b/modules/invoiceOut/front/index/global-invoicing/locale/es.yml
@@ -7,4 +7,5 @@ From client: Desde el cliente
To client: Hasta el cliente
Invoice date and the max date should be filled: La fecha de factura y la fecha límite deben rellenarse
Choose a valid clients range: Selecciona un rango válido de clientes
-of: de
\ No newline at end of file
+of: de
+Id Client: Id Cliente
\ No newline at end of file