salix/db/routines/vn/procedures/ticket_closeByTicket.sql

28 lines
754 B
MySQL
Raw Normal View History

2022-10-25 12:09:21 +00:00
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_closeByTicket`(IN vTicketFk int)
2022-10-13 07:30:31 +00:00
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
2022-10-13 07:30:31 +00:00
t.id AS ticketFk
FROM ticket t
JOIN agencyMode am ON am.id = t.agencyModeFk
2022-10-13 07:30:31 +00:00
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
2022-10-13 07:30:31 +00:00
AND t.refFk IS NULL
GROUP BY t.id);
2022-10-13 07:30:31 +00:00
CALL ticket_close();
DROP TEMPORARY TABLE tmp.ticket_close;
2022-10-25 12:09:21 +00:00
END$$
DELIMITER ;