DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_administrativeCopy`(
	vOriginalTicket INT, 
	OUT vNewTicket INT
)
BEGIN
	INSERT INTO ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed, currencyFk)
		SELECT t.clientFk, t.addressFk, t.shipped, w.id, t.companyFk, t.landed, t.currencyFk 
			FROM ticket t
				JOIN vn.warehouse w ON w.name = 'INVENTARIO'
			WHERE t.id = vOriginalTicket;
			
	SELECT LAST_INSERT_ID() INTO vNewTicket;

	INSERT INTO sale(ticketFk, itemFk, concept, quantity, price, discount, foreignPrice)
		SELECT vNewTicket, itemFk , concept, quantity, price, discount, foreignPrice
			FROM sale 
			WHERE ticketFk = vOriginalTicket;	
END$$
DELIMITER ;
