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

62 lines
1.2 KiB
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`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;
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 ;