diff --git a/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js b/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js index 4a20b81a2..71a10b1b8 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js +++ b/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js @@ -21,7 +21,8 @@ module.exports = Self => { { arg: 'toClientId', type: 'number', - description: 'The maximum client id' + description: 'The maximum client id', + required: false }, { arg: 'companyFk', @@ -77,13 +78,10 @@ module.exports = Self => { const minShipped = new Date(); minShipped.setFullYear(minShipped.getFullYear() - 1); - - if (args.fromClientId == args.toClientId) { - minShipped.setFullYear(2021); - minShipped.setMonth(1); - minShipped.setDate(1); - minShipped.setHours(0, 0, 0, 0); - } + minShipped.setMonth(1); + minShipped.setDate(1); + minShipped.setHours(0, 0, 0, 0); + // Packaging liquidation const vIsAllInvoiceable = false; @@ -200,11 +198,13 @@ module.exports = Self => { JOIN ticketPackaging tp ON t.id = tp.ticketFk JOIN client c ON c.id = t.clientFk WHERE t.shipped BETWEEN '2017-11-21' AND ? - AND t.clientFk BETWEEN ? AND ? + AND t.clientFk >= ? + AND (t.clientFk <= ? OR ? IS NULL) AND c.isActive`; return models.InvoiceOut.rawSql(query, [ args.maxShipped, args.fromClientId, + args.toClientId, args.toClientId ], options); } @@ -233,15 +233,17 @@ module.exports = Self => { LEFT JOIN ticketService ts ON ts.ticketFk = t.id JOIN address a ON a.id = t.addressFk JOIN client c ON c.id = t.clientFk - WHERE ISNULL(t.refFk) AND c.id BETWEEN ? AND ? + WHERE ISNULL(t.refFk) AND c.id >= ? + AND (t.clientFk <= ? OR ? IS NULL) AND t.shipped BETWEEN ? AND util.dayEnd(?) AND t.companyFk = ? AND c.hasToInvoice - AND c.isTaxDataChecked + AND c.isTaxDataChecked AND c.isActive GROUP BY c.id, IF(c.hasToInvoiceByAddress,a.id,TRUE) HAVING sumAmount > 0`; return models.InvoiceOut.rawSql(query, [ args.fromClientId, args.toClientId, + args.toClientId, minShipped, args.maxShipped, args.companyFk diff --git a/modules/invoiceOut/front/index/global-invoicing/index.js b/modules/invoiceOut/front/index/global-invoicing/index.js index 5e522f23d..1b1ae5ec9 100644 --- a/modules/invoiceOut/front/index/global-invoicing/index.js +++ b/modules/invoiceOut/front/index/global-invoicing/index.js @@ -54,7 +54,7 @@ class Controller extends Dialog { if (!this.invoice.invoiceDate || !this.invoice.maxShipped) throw new Error('Invoice date and the max date should be filled'); - if (!this.invoice.fromClientId || !this.invoice.toClientId) + if (!this.invoice.fromClientId) throw new Error('Choose a valid clients range'); this.isInvoicing = true;