2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_Clone`(vOriginalTicket INT, OUT vNewTicket INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
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;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
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 ;
|