From 5b22096567aeea6f8d057d9fd59e666e1f85781e Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 9 Feb 2023 14:57:08 +0100 Subject: [PATCH] refactor: actuializada consulta par obtener los clientes a facturar. Excluido impresion pdfs de la transaccion --- .../methods/invoiceOut/clientsToInvoice.js | 46 +++++++------------ .../back/methods/invoiceOut/invoiceClient.js | 22 ++++----- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js index 3bab9b8bd..7eeb82e35 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js @@ -150,38 +150,24 @@ module.exports = Self => { const args = ctx.args; minShipped.setFullYear(minShipped.getFullYear() - 1); - const query = `SELECT - c.id, - SUM(IFNULL - ( - s.quantity * - s.price * (100-s.discount)/100, - 0) - + IFNULL(ts.quantity * ts.price,0) - ) AS sumAmount, - c.hasToInvoiceByAddress, - c.email, - c.isToBeMailed, - a.id addressFk - FROM ticket t - LEFT JOIN sale s ON s.ticketFk = t.id - 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 >= ? - AND (t.clientFk <= ? OR ? IS NULL) - AND t.shipped BETWEEN ? AND util.dayEnd(?) - AND t.companyFk = ? - AND c.hasToInvoice - AND c.isTaxDataChecked - AND c.isActive - AND NOT t.isDeleted - GROUP BY c.id, IF(c.hasToInvoiceByAddress,a.id,TRUE) HAVING sumAmount > 0`; + const query = `SELECT c.id, + c.hasToInvoiceByAddress, + a.id addressFk, + sum(t.totalWithVat) totalAmount + FROM ticket t + JOIN address a ON a.id = t.addressFk + JOIN client c ON c.id = t.clientFk + WHERE t.refFk IS NULL + AND t.shipped BETWEEN ? AND util.dayEnd(?) + AND t.companyFk = ? + AND c.hasToInvoice + AND c.isTaxDataChecked + AND c.isActive + AND NOT t.isDeleted + GROUP BY c.id, IF(c.hasToInvoiceByAddress, a.id, TRUE) + HAVING totalAmount > 0;`; return models.InvoiceOut.rawSql(query, [ - args.fromClientId, - args.toClientId, - args.toClientId, minShipped, args.maxShipped, args.companyFk diff --git a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js index b401d08b7..ce700796f 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js +++ b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js @@ -127,23 +127,23 @@ module.exports = Self => { invoiceId = newInvoice.id; } - if (invoiceId && !invoiceOut.client().isToBeMailed) { - const query = `CALL vn.report_print( - 'invoice', - ?, - account.myUser_getId(), - JSON_OBJECT('refFk', ?), - 'normal' - );`; - await models.InvoiceOut.rawSql(query, [args.printerFk, invoiceOut.ref], myOptions); - } - if (tx) await tx.commit(); } catch (e) { if (tx) await tx.rollback(); throw e; } + if (invoiceId && !invoiceOut.client().isToBeMailed) { + const query = `CALL vn.report_print( + 'invoice', + ?, + account.myUser_getId(), + JSON_OBJECT('refFk', ?), + 'normal' + );`; + await models.InvoiceOut.rawSql(query, [args.printerFk, invoiceOut.ref]); + } + if (invoiceId && invoiceOut.client().isToBeMailed) { ctx.args = { reference: invoiceOut.ref,