From 31aafc071945c2d6e84760d92b1173d7495790a3 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 10 Aug 2022 09:11:38 +0200 Subject: [PATCH] feat: add inserts in printQueue --- db/dump/fixtures.sql | 4 ++ .../methods/invoiceOut/globalInvoicing.js | 41 +++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index e7232edd3..638f191f3 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2642,3 +2642,7 @@ INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) VALUES (1, 9); + +INSERT INTO `vn`.`report` (`id`, `name`) + VALUES + (3, 'invoice'); \ No newline at end of file diff --git a/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js b/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js index 7f2cbb442..14d6913cb 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js +++ b/modules/invoiceOut/back/methods/invoiceOut/globalInvoicing.js @@ -79,6 +79,13 @@ 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); + } + // Packaging liquidation const vIsAllInvoiceable = false; const clientsWithPackaging = await getClientsWithPackaging(ctx, myOptions); @@ -138,8 +145,34 @@ module.exports = Self => { if (newInvoice.id) { await Self.rawSql('CALL invoiceOutBooking(?)', [newInvoice.id], myOptions); - query = `INSERT IGNORE INTO invoiceOut_queue(invoiceFk) VALUES(?)`; - await Self.rawSql(query, [newInvoice.id], myOptions); + // query = `INSERT IGNORE INTO invoiceOut_queue(invoiceFk) VALUES(?)`; + // await Self.rawSql(query, [newInvoice.id], myOptions); + + query = `SELECT id FROM vn.report WHERE name ='invoice'`; + const [reportFk] = await Self.rawSql(query, null, myOptions); + + query = `SELECT ref FROM vn.invoiceOut WHERE id = ?`; + const [invoiceRef] = await Self.rawSql(query, [newInvoice.id], myOptions); + + // Print invoice + const args = { + invoiceOutFk: newInvoice.id, + refFk: invoiceRef.ref, + hasToForcePdf: true, + email: '' + }; + + const userId = ctx.req.accessToken.userId; + + query = `INSERT INTO vn.printQueue (priorityFk, reportFk, workerFk, printerFk) VALUES (?, ?, ?, NULL)`; + await Self.rawSql(query, [2, reportFk.id, userId], myOptions); // La prioridad de donde se la saca? 'adPriorityBelowNormal' + + const [lastInsertedPrintQueue] = await Self.rawSql('SELECT LAST_INSERT_ID() AS id', null, myOptions); + + for (let key in args) { + query = `INSERT INTO vn.printQueueArgs (printQueueFk, name, value) VALUES (?, ?, ?)`; + await Self.rawSql(query, [lastInsertedPrintQueue.id, key, args[key]], myOptions); + } invoicesIds.push(newInvoice.id); } @@ -192,8 +225,10 @@ module.exports = Self => { const query = `SELECT DISTINCT clientFk AS id FROM ticket t 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 BETWEEN ? AND ? + AND c.isActive`; return models.InvoiceOut.rawSql(query, [ args.maxShipped, args.fromClientId,