diff --git a/db/changes/10491-august/ticket_closeByTicket.sql b/db/changes/10491-august/ticket_closeByTicket.sql new file mode 100644 index 000000000..25b04f629 --- /dev/null +++ b/db/changes/10491-august/ticket_closeByTicket.sql @@ -0,0 +1,31 @@ +drop procedure `vn`.`ticket_closeByTicket`; + +create + definer = root@localhost procedure `vn`.`ticket_closeByTicket`(IN vTicketFk int) +BEGIN + +/** + * Inserta el ticket en la tabla temporal + * para ser cerrado. + * + * @param vTicketFk Id del ticket + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close; + CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY ( + SELECT + t.id AS ticketFk + FROM ticket t + JOIN agencyMode am ON am.id = t.agencyModeFk + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + JOIN alertLevel al ON al.id = ts.alertLevel + WHERE al.code = 'PACKED' OR (am.code = 'refund' AND al.code != 'delivered') + AND t.id = vTicketFk + AND t.refFk IS NULL + GROUP BY t.id); + + CALL ticket_close(); + + DROP TEMPORARY TABLE tmp.ticket_close; +END; + diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 5e81e3827..327278c2b 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -52,7 +52,7 @@ module.exports = Self => { 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 - WHERE al.code = 'PACKED' + WHERE al.code = 'PACKED' OR (am.code = 'refund' AND al.code != 'delivered') AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) AND util.dayEnd(?) AND t.refFk IS NULL