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

67 lines
1.3 KiB
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`ticket_Clone`(vOriginalTicket INT, OUT vNewTicket INT)
BEGIN
/**
* Clona el contenido de un ticket en otro
*
* @param vOriginalTicket ticket Original
* @param vNewTicket ticket creado
*/
DECLARE vStateFk INT;
2024-07-04 05:34:41 +00:00
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
RESIGNAL;
END;
INSERT INTO ticket (
clientFk,
shipped,
addressFk,
agencyModeFk,
nickname,
warehouseFk,
companyFk,
landed,
zoneFk,
zonePrice,
zoneBonus,
routeFk,
priority,
hasPriority,
clonedFrom
)
SELECT
clientFk,
shipped,
addressFk,
agencyModeFk,
nickname,
warehouseFk,
companyFk,
landed,
zoneFk,
zonePrice,
zoneBonus,
routeFk,
priority,
hasPriority,
vOriginalTicket
FROM ticket
WHERE id = vOriginalTicket;
SET vNewTicket = LAST_INSERT_ID();
INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
SELECT vNewTicket, observationTypeFk, description
FROM ticketObservation
WHERE ticketFk = vOriginalTicket;
INSERT INTO ticketTracking(ticketFk, stateFk, userFk, created)
SELECT vNewTicket, stateFk, userFk, created
FROM ticketTracking
WHERE ticketFk = vOriginalTicket
ORDER BY created;
END$$
DELIMITER ;