2022-10-25 12:09:21 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`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 (
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT
|
2022-10-13 07:30:31 +00:00
|
|
|
t.id AS ticketFk
|
|
|
|
FROM ticket t
|
2024-01-15 11:31:03 +00:00
|
|
|
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
|
2024-01-15 11:31:03 +00:00
|
|
|
JOIN alertLevel al ON al.id = ts.alertLevel
|
2024-03-01 14:05:12 +00:00
|
|
|
WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code != 'delivered'))
|
2024-01-15 11:31:03 +00:00
|
|
|
AND t.id = vTicketFk
|
2022-10-13 07:30:31 +00:00
|
|
|
AND t.refFk IS NULL
|
2024-03-14 07:36:19 +00:00
|
|
|
GROUP BY t.id
|
|
|
|
);
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2022-10-13 07:30:31 +00:00
|
|
|
CALL ticket_close();
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
DROP TEMPORARY TABLE tmp.ticket_close;
|
2022-10-25 12:09:21 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|