From 5d9ed494514c68e642ae0749abf820ea912ece06 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 16 Jun 2020 08:17:01 +0200 Subject: [PATCH 1/7] 2285 - Added closure paths --- .../ticket_closeByAgency.sql | 32 ++++ .../ticket_closeByAllWarehouses.sql | 42 +++++ .../ticket_closeByRoute.sql | 29 ++++ .../ticket_closeByTicket.sql | 28 +++ .../ticket_closeByWarehouse.sql | 29 ++++ print/methods/closure.js | 163 ++++++++++++++++-- 6 files changed, 304 insertions(+), 19 deletions(-) create mode 100644 db/changes/10200-DeEscalation/ticket_closeByAgency.sql create mode 100644 db/changes/10200-DeEscalation/ticket_closeByAllWarehouses.sql create mode 100644 db/changes/10200-DeEscalation/ticket_closeByRoute.sql create mode 100644 db/changes/10200-DeEscalation/ticket_closeByTicket.sql create mode 100644 db/changes/10200-DeEscalation/ticket_closeByWarehouse.sql diff --git a/db/changes/10200-DeEscalation/ticket_closeByAgency.sql b/db/changes/10200-DeEscalation/ticket_closeByAgency.sql new file mode 100644 index 000000000..155305afe --- /dev/null +++ b/db/changes/10200-DeEscalation/ticket_closeByAgency.sql @@ -0,0 +1,32 @@ +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_closeByAgencyList`(vWarehouseFk INT, vDateTo DATE) +BEGIN +/** + * Inserta los tickets de todos los almacenes en la tabla temporal + * para ser cerrados. + * + * @param vWarehouseFk Id del almacén + * @param vDate Fecha del cierre + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + + CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN tmp.ticketClosureAgencyList al ON al.agencyModeFk = t.agencyModeFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND t.warehouseFk = vWarehouseFk + AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo + AND t.refFk IS NULL + GROUP BY e.ticketFk); + + + CALL ticket_close(); + + DROP TEMPORARY TABLE tmp.ticketClosureAgencyList; + DROP TEMPORARY TABLE tmp.ticketClosure; +END \ No newline at end of file diff --git a/db/changes/10200-DeEscalation/ticket_closeByAllWarehouses.sql b/db/changes/10200-DeEscalation/ticket_closeByAllWarehouses.sql new file mode 100644 index 000000000..4a3ae76c8 --- /dev/null +++ b/db/changes/10200-DeEscalation/ticket_closeByAllWarehouses.sql @@ -0,0 +1,42 @@ +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_closeByAllWarehouses`(vDateTo DATE) +BEGIN +/** + * Inserta los tickets de todos los almacenes en la tabla temporal + * para ser cerrados. + * + * @param vDate Fecha del cierre + */ + DECLARE vDateToEndDay DATETIME DEFAULT util.dayEnd(vDateTo); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + + CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk AND hasComission + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo + AND t.refFk IS NULL + GROUP BY e.ticketFk); + + CALL ticket_close(); + + -- cau 15033 + UPDATE ticket t + JOIN ticketState ts ON t.id = ts.ticketFk + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN zone z ON z.id = t.zoneFk + SET t.routeFk = NULL + WHERE shipped BETWEEN vDateTo AND vDateToEndDay + AND al.code NOT IN('DELIVERED','PACKED') + AND t.routeFk + AND z.`name` LIKE '%MADRID%'; + + DROP TEMPORARY TABLE tmp.ticketClosure; +END \ No newline at end of file diff --git a/db/changes/10200-DeEscalation/ticket_closeByRoute.sql b/db/changes/10200-DeEscalation/ticket_closeByRoute.sql new file mode 100644 index 000000000..3c1500bd6 --- /dev/null +++ b/db/changes/10200-DeEscalation/ticket_closeByRoute.sql @@ -0,0 +1,29 @@ +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_closeByRoute`( vRouteFk INT) +BEGIN +/** + * Inserta los tickets de la ruta en la tabla temporal + * para ser cerrados. + * + * @param vWarehouseFk Almacén a cerrar + * @param vRouteFk Ruta a cerrar + * @param vDate Fecha del cierre + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + + CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND t.routeFk = vRouteFk + AND t.refFk IS NULL + GROUP BY e.ticketFk); + + CALL ticket_close(); + + DROP TEMPORARY TABLE tmp.ticketClosure; +END \ No newline at end of file diff --git a/db/changes/10200-DeEscalation/ticket_closeByTicket.sql b/db/changes/10200-DeEscalation/ticket_closeByTicket.sql new file mode 100644 index 000000000..1ffb5a265 --- /dev/null +++ b/db/changes/10200-DeEscalation/ticket_closeByTicket.sql @@ -0,0 +1,28 @@ +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_closeByTicket`(vTicketFk INT) +BEGIN + +/** + * Inserta el ticket en la tabla temporal + * para ser cerrado. + * + * @param vTicketFk Id del ticket + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + + CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND t.id = vTicketFk + AND t.refFk IS NULL + GROUP BY e.ticketFk); + + CALL ticket_close(); + + DROP TEMPORARY TABLE tmp.ticketClosure; +END \ No newline at end of file diff --git a/db/changes/10200-DeEscalation/ticket_closeByWarehouse.sql b/db/changes/10200-DeEscalation/ticket_closeByWarehouse.sql new file mode 100644 index 000000000..e7996edb0 --- /dev/null +++ b/db/changes/10200-DeEscalation/ticket_closeByWarehouse.sql @@ -0,0 +1,29 @@ +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_closeByWarehouse`(vWarehouseFk INT, vDateTo DATE) +BEGIN +/** + * Inserta los tickets del almacen en la tabla temporal + * para ser cerrados. + * + * @param vWarehouseFk Almacén a cerrar + * @param vDate Fecha del cierre + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + + CREATE TEMPORARY TABLE ticketClosure ENGINE = MEMORY( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND t.warehouseFk = vWarehouseFk + AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo + AND t.refFk IS NULL + GROUP BY e.ticketFk); + + CALL ticket_close(); + + DROP TEMPORARY TABLE tmp.ticketClosure; +END \ No newline at end of file diff --git a/print/methods/closure.js b/print/methods/closure.js index 3bcca9d4e..15023263b 100644 --- a/print/methods/closure.js +++ b/print/methods/closure.js @@ -4,34 +4,157 @@ const smtp = require('../core/smtp'); const config = require('../core/config'); module.exports = app => { - app.get('/api/closure/by-ticket', async function(req, res) { + app.get('/api/closure/all', async function(req, res, next) { + try { + res.status(200).json({ + message: 'Task executed successfully' + }); + + await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`); + await db.rawSql(` + CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND DATE(t.shipped) BETWEEN DATE_ADD(CURDATE(), INTERVAL -2 DAY) AND CURDATE() + AND t.refFk IS NULL + GROUP BY e.ticketFk)`); + + await closeAll(req.args); + } catch (error) { + next(error); + } }); - app.get('/api/closure/all', async function(req, res) { - res.status(200).json({ - message: 'Task executed successfully' - }); + app.get('/api/closure/by-ticket', async function(req, res, next) { + try { + const reqArgs = req.args; + if (!reqArgs.ticketId) + throw new Error('The argument ticketId is required'); + res.status(200).json({ + message: 'Task executed successfully' + }); + + await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`); + await db.rawSql(` + CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND t.id = :ticketId + AND t.refFk IS NULL + GROUP BY e.ticketFk)`, { + ticketId: reqArgs.ticketId + }); + + await closeAll(reqArgs); + } catch (error) { + next(error); + } + }); + + app.get('/api/closure/by-agency', async function(req, res) { + try { + const reqArgs = req.args; + if (!reqArgs.agencyModeId) + throw new Error('The argument agencyModeId is required'); + + if (!reqArgs.warehouseId) + throw new Error('The argument warehouseId is required'); + + if (!reqArgs.to) + throw new Error('The argument to is required'); + + res.status(200).json({ + message: 'Task executed successfully' + }); + + await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`); + await db.rawSql(` + CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND t.agencyModeFk = :agencyModeId + AND t.warehouseFk = :warehouseId + AND DATE(t.shipped) BETWEEN DATE_ADD(:to, INTERVAL -2 DAY) AND :to + AND t.refFk IS NULL + GROUP BY e.ticketFk)`, { + agencyModeId: reqArgs.agencyModeId, + warehouseId: reqArgs.warehouseId, + to: reqArgs.to + }); + + await closeAll(reqArgs); + } catch (error) { + next(error); + } + }); + + app.get('/api/closure/by-route', async function(req, res) { + try { + const reqArgs = req.args; + if (!reqArgs.routeId) + throw new Error('The argument routeId is required'); + + res.status(200).json({ + message: 'Task executed successfully' + }); + + await db.rawSql(`DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close`); + await db.rawSql(` + CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + WHERE al.code = 'PACKED' + AND t.routeFk = :routeId + AND t.refFk IS NULL + GROUP BY e.ticketFk)`, { + routeId: reqArgs.routeId + }); + + await closeAll(reqArgs); + } catch (error) { + next(error); + } + }); + + async function closeAll(reqArgs) { const failedtickets = []; const tickets = await db.rawSql(` SELECT t.id, t.clientFk, c.email recipient, - c.isToBeMailed, c.salesPersonFk, + c.isToBeMailed, + c.hasToInvoice, + co.hasDailyInvoice, eu.email salesPersonEmail - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk + FROM tmp.ticket_close tt + JOIN ticket t ON t.id = tt.ticketFk JOIN client c ON c.id = t.clientFk - JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.alertLevel = ts.alertLevel - LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk - WHERE al.code = 'PACKED' - AND DATE(t.shipped) BETWEEN DATE_ADD(CURDATE(), INTERVAL -2 DAY) AND CURDATE() - AND t.refFk IS NULL - GROUP BY e.ticketFk`); + JOIN province p ON p.id = c.provinceFk + JOIN country co ON co.id = p.countryFk + LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk`); for (const ticket of tickets) { try { @@ -39,7 +162,8 @@ module.exports = app => { ticketId: ticket.id }); - if (!ticket.salesPersonFk || !ticket.isToBeMailed) continue; + const hasToInvoice = ticket.hasToInvoice && ticket.hasDailyInvoice; + if (!ticket.salesPersonFk || !ticket.isToBeMailed || hasToInvoice) continue; if (!ticket.recipient) { const body = `No se ha podido enviar el albarán ${ticket.id} @@ -54,7 +178,6 @@ module.exports = app => { continue; } - const reqArgs = req.args; const args = Object.assign({ ticketId: ticket.id, recipientId: ticket.clientFk, @@ -88,5 +211,7 @@ module.exports = app => { html: body }); } - }); + + await db.rawSql(`DROP TEMPORARY TABLE tmp.ticket_close`); + } }; From f3a7fc514a9595c9cbb42cd13e0944d7df7d5db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 7 Sep 2020 10:54:39 +0200 Subject: [PATCH 2/7] Changes --- db/changes/10220-a/ticket_close.sql | 119 ++++++++++++++++++++++++++++ print/methods/closure.js | 15 +++- 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 db/changes/10220-a/ticket_close.sql diff --git a/db/changes/10220-a/ticket_close.sql b/db/changes/10220-a/ticket_close.sql new file mode 100644 index 000000000..dd9786dcd --- /dev/null +++ b/db/changes/10220-a/ticket_close.sql @@ -0,0 +1,119 @@ +USE `vn`; +DROP procedure IF EXISTS `ticket_close`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_close`(vTicketFk INT) +BEGIN +/** + * Realiza el cierre de todos los + * tickets de la tabla ticketClosure. + */ + DECLARE vDone BOOL; + DECLARE vClientFk INT; + DECLARE vCurTicketFk INT; + DECLARE vIsTaxDataChecked BOOL; + DECLARE vCompanyFk INT; + DECLARE vShipped DATE; + DECLARE vPriority INT DEFAULT 1; + DECLARE vReportDeliveryNote INT DEFAULT 1; + DECLARE vNewInvoiceId INT; + DECLARE vHasDailyInvoice BOOL; + DECLARE vWithPackage BOOL; + DECLARE vHasToInvoice BOOL; + + DECLARE cur CURSOR FOR + SELECT ticketFk FROM tmp.ticketClosure; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + RESIGNAL; + END; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + CREATE TEMPORARY TABLE tmp.ticketClosure + SELECT vTicketFk AS ticketFk; + + INSERT INTO tmp.ticketClosure + SELECT id FROM stowaway s + WHERE s.shipFk = vTicketFk; + OPEN cur; + + proc: LOOP + SET vDone = FALSE; + + FETCH cur INTO vCurTicketFk; + + IF vDone THEN + LEAVE proc; + END IF; + + -- ticketClosure start + SELECT + c.id, + c.isTaxDataChecked, + t.companyFk, + t.shipped, + co.hasDailyInvoice, + w.isManaged, + c.hasToInvoice + INTO vClientFk, + vIsTaxDataChecked, + vCompanyFk, + vShipped, + vHasDailyInvoice, + vWithPackage, + vHasToInvoice + FROM ticket t + JOIN `client` c ON c.id = t.clientFk + JOIN province p ON p.id = c.provinceFk + JOIN country co ON co.id = p.countryFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.id = vCurTicketFk; + + INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) + (SELECT vCurTicketFk, p.id, COUNT(*) + FROM expedition e + JOIN packaging p ON p.itemFk = e.itemFk + WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable + AND vWithPackage + GROUP BY p.itemFk); + + -- No retornables o no catalogados + INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, isPriceFixed) + (SELECT e.itemFk, vCurTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.itemFk, vClientFk), 1 + FROM expedition e + JOIN item i ON i.id = e.itemFk + LEFT JOIN packaging p ON p.itemFk = i.id + WHERE e.ticketFk = vCurTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0 + AND getSpecialPrice(e.itemFk, vClientFk) > 0 + GROUP BY e.itemFk); + + CALL vn.zonePromo_Make(); + + IF(vHasDailyInvoice) AND vHasToInvoice THEN + + -- Facturacion rapida + CALL ticketTrackingAdd(vCurTicketFk, 'DELIVERED', NULL); + -- Facturar si está contabilizado + IF vIsTaxDataChecked THEN + CALL invoiceOut_newFromClient( + vClientFk, + (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')), + vShipped, + vCompanyFk, + NULL, + vNewInvoiceId); + END IF; + ELSE + CALL ticketTrackingAdd(vCurTicketFk, (SELECT vn.getAlert3State(vCurTicketFk)), NULL); + END IF; + END LOOP; + + CLOSE cur; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; +END$$ + +DELIMITER ; + diff --git a/print/methods/closure.js b/print/methods/closure.js index 15023263b..a1450f446 100644 --- a/print/methods/closure.js +++ b/print/methods/closure.js @@ -26,6 +26,19 @@ module.exports = app => { GROUP BY e.ticketFk)`); await closeAll(req.args); + + await db.rawSql(` + UPDATE ticket t + JOIN ticketState ts ON t.id = ts.ticketFk + JOIN alertLevel al ON al.alertLevel = ts.alertLevel + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN zone z ON z.id = t.zoneFk + SET t.routeFk = NULL + WHERE shipped BETWEEN CURDATE() AND util.dayEnd(CURDATE()) + AND al.code NOT IN('DELIVERED','PACKED') + AND t.routeFk + AND z.name LIKE '%MADRID%'`); } catch (error) { next(error); } @@ -158,7 +171,7 @@ module.exports = app => { for (const ticket of tickets) { try { - await db.rawSql(`CALL vn.ticket_closeByTicket(:ticketId)`, { + await db.rawSql(`CALL vn.ticket_close(:ticketId)`, { ticketId: ticket.id }); From 7b42497f88ed5da1cf392895718b0e9404356cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 7 Sep 2020 11:44:44 +0200 Subject: [PATCH 3/7] Removed procedures --- .../ticket_closeByAgency.sql | 32 -------------- .../ticket_closeByAllWarehouses.sql | 42 ------------------- .../ticket_closeByRoute.sql | 29 ------------- .../ticket_closeByTicket.sql | 28 ------------- .../ticket_closeByWarehouse.sql | 29 ------------- 5 files changed, 160 deletions(-) delete mode 100644 db/changes/10200-DeEscalation/ticket_closeByAgency.sql delete mode 100644 db/changes/10200-DeEscalation/ticket_closeByAllWarehouses.sql delete mode 100644 db/changes/10200-DeEscalation/ticket_closeByRoute.sql delete mode 100644 db/changes/10200-DeEscalation/ticket_closeByTicket.sql delete mode 100644 db/changes/10200-DeEscalation/ticket_closeByWarehouse.sql diff --git a/db/changes/10200-DeEscalation/ticket_closeByAgency.sql b/db/changes/10200-DeEscalation/ticket_closeByAgency.sql deleted file mode 100644 index 155305afe..000000000 --- a/db/changes/10200-DeEscalation/ticket_closeByAgency.sql +++ /dev/null @@ -1,32 +0,0 @@ -CREATE DEFINER=`root`@`%` PROCEDURE `ticket_closeByAgencyList`(vWarehouseFk INT, vDateTo DATE) -BEGIN -/** - * Inserta los tickets de todos los almacenes en la tabla temporal - * para ser cerrados. - * - * @param vWarehouseFk Id del almacén - * @param vDate Fecha del cierre - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk - JOIN tmp.ticketClosureAgencyList al ON al.agencyModeFk = t.agencyModeFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.alertLevel = ts.alertLevel - WHERE al.code = 'PACKED' - AND t.warehouseFk = vWarehouseFk - AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - - CALL ticket_close(); - - DROP TEMPORARY TABLE tmp.ticketClosureAgencyList; - DROP TEMPORARY TABLE tmp.ticketClosure; -END \ No newline at end of file diff --git a/db/changes/10200-DeEscalation/ticket_closeByAllWarehouses.sql b/db/changes/10200-DeEscalation/ticket_closeByAllWarehouses.sql deleted file mode 100644 index 4a3ae76c8..000000000 --- a/db/changes/10200-DeEscalation/ticket_closeByAllWarehouses.sql +++ /dev/null @@ -1,42 +0,0 @@ -CREATE DEFINER=`root`@`%` PROCEDURE `ticket_closeByAllWarehouses`(vDateTo DATE) -BEGIN -/** - * Inserta los tickets de todos los almacenes en la tabla temporal - * para ser cerrados. - * - * @param vDate Fecha del cierre - */ - DECLARE vDateToEndDay DATETIME DEFAULT util.dayEnd(vDateTo); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk AND hasComission - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.alertLevel = ts.alertLevel - WHERE al.code = 'PACKED' - AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - CALL ticket_close(); - - -- cau 15033 - UPDATE ticket t - JOIN ticketState ts ON t.id = ts.ticketFk - JOIN alertLevel al ON al.alertLevel = ts.alertLevel - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - JOIN zone z ON z.id = t.zoneFk - SET t.routeFk = NULL - WHERE shipped BETWEEN vDateTo AND vDateToEndDay - AND al.code NOT IN('DELIVERED','PACKED') - AND t.routeFk - AND z.`name` LIKE '%MADRID%'; - - DROP TEMPORARY TABLE tmp.ticketClosure; -END \ No newline at end of file diff --git a/db/changes/10200-DeEscalation/ticket_closeByRoute.sql b/db/changes/10200-DeEscalation/ticket_closeByRoute.sql deleted file mode 100644 index 3c1500bd6..000000000 --- a/db/changes/10200-DeEscalation/ticket_closeByRoute.sql +++ /dev/null @@ -1,29 +0,0 @@ -CREATE DEFINER=`root`@`%` PROCEDURE `ticket_closeByRoute`( vRouteFk INT) -BEGIN -/** - * Inserta los tickets de la ruta en la tabla temporal - * para ser cerrados. - * - * @param vWarehouseFk Almacén a cerrar - * @param vRouteFk Ruta a cerrar - * @param vDate Fecha del cierre - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.alertLevel = ts.alertLevel - WHERE al.code = 'PACKED' - AND t.routeFk = vRouteFk - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - CALL ticket_close(); - - DROP TEMPORARY TABLE tmp.ticketClosure; -END \ No newline at end of file diff --git a/db/changes/10200-DeEscalation/ticket_closeByTicket.sql b/db/changes/10200-DeEscalation/ticket_closeByTicket.sql deleted file mode 100644 index 1ffb5a265..000000000 --- a/db/changes/10200-DeEscalation/ticket_closeByTicket.sql +++ /dev/null @@ -1,28 +0,0 @@ -CREATE DEFINER=`root`@`%` PROCEDURE `ticket_closeByTicket`(vTicketFk INT) -BEGIN - -/** - * Inserta el ticket en la tabla temporal - * para ser cerrado. - * - * @param vTicketFk Id del ticket - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.alertLevel = ts.alertLevel - WHERE al.code = 'PACKED' - AND t.id = vTicketFk - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - CALL ticket_close(); - - DROP TEMPORARY TABLE tmp.ticketClosure; -END \ No newline at end of file diff --git a/db/changes/10200-DeEscalation/ticket_closeByWarehouse.sql b/db/changes/10200-DeEscalation/ticket_closeByWarehouse.sql deleted file mode 100644 index e7996edb0..000000000 --- a/db/changes/10200-DeEscalation/ticket_closeByWarehouse.sql +++ /dev/null @@ -1,29 +0,0 @@ -CREATE DEFINER=`root`@`%` PROCEDURE `ticket_closeByWarehouse`(vWarehouseFk INT, vDateTo DATE) -BEGIN -/** - * Inserta los tickets del almacen en la tabla temporal - * para ser cerrados. - * - * @param vWarehouseFk Almacén a cerrar - * @param vDate Fecha del cierre - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE ticketClosure ENGINE = MEMORY( - SELECT - t.id AS ticketFk - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.alertLevel = ts.alertLevel - WHERE al.code = 'PACKED' - AND t.warehouseFk = vWarehouseFk - AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - CALL ticket_close(); - - DROP TEMPORARY TABLE tmp.ticketClosure; -END \ No newline at end of file From 13b3353e9a6feb748321f20d38fac63147dc9f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 7 Sep 2020 11:45:29 +0200 Subject: [PATCH 4/7] Changed sql folder --- db/changes/{10220-a => 10210-summer}/ticket_close.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/{10220-a => 10210-summer}/ticket_close.sql (100%) diff --git a/db/changes/10220-a/ticket_close.sql b/db/changes/10210-summer/ticket_close.sql similarity index 100% rename from db/changes/10220-a/ticket_close.sql rename to db/changes/10210-summer/ticket_close.sql From 173aac0ba6ae92a020c830700d1064f5cd825c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 7 Sep 2020 11:45:54 +0200 Subject: [PATCH 5/7] Renamed sql file --- db/changes/10210-summer/{ticket_close.sql => 00-ticket_close.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/10210-summer/{ticket_close.sql => 00-ticket_close.sql} (100%) diff --git a/db/changes/10210-summer/ticket_close.sql b/db/changes/10210-summer/00-ticket_close.sql similarity index 100% rename from db/changes/10210-summer/ticket_close.sql rename to db/changes/10210-summer/00-ticket_close.sql From c10e24b7cdb9b0cc0184d50655f40b02ee933278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 7 Sep 2020 11:50:23 +0200 Subject: [PATCH 6/7] Updated param description --- db/changes/10210-summer/00-ticket_close.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/changes/10210-summer/00-ticket_close.sql b/db/changes/10210-summer/00-ticket_close.sql index dd9786dcd..e01fa8f7e 100644 --- a/db/changes/10210-summer/00-ticket_close.sql +++ b/db/changes/10210-summer/00-ticket_close.sql @@ -8,6 +8,8 @@ BEGIN /** * Realiza el cierre de todos los * tickets de la tabla ticketClosure. + * + * @param vTicketFk Id del ticket */ DECLARE vDone BOOL; DECLARE vClientFk INT; From bb092b1de97cce03439f0c897b91c020d81890e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 7 Sep 2020 12:16:20 +0200 Subject: [PATCH 7/7] Removed unused vars --- db/changes/10210-summer/00-ticket_close.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/db/changes/10210-summer/00-ticket_close.sql b/db/changes/10210-summer/00-ticket_close.sql index e01fa8f7e..96f9c5528 100644 --- a/db/changes/10210-summer/00-ticket_close.sql +++ b/db/changes/10210-summer/00-ticket_close.sql @@ -17,8 +17,6 @@ BEGIN DECLARE vIsTaxDataChecked BOOL; DECLARE vCompanyFk INT; DECLARE vShipped DATE; - DECLARE vPriority INT DEFAULT 1; - DECLARE vReportDeliveryNote INT DEFAULT 1; DECLARE vNewInvoiceId INT; DECLARE vHasDailyInvoice BOOL; DECLARE vWithPackage BOOL;