DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_mergeSales`(vCollectionFk INT)
BEGIN
	DECLARE vDone BOOL;
	DECLARE vTicketFk INT;

	DECLARE vTickets CURSOR FOR
		SELECT ticketFk
			FROM ticketCollection
		WHERE collectionFk = vCollectionFk;

	DECLARE CONTINUE HANDLER FOR NOT FOUND
		SET vDone = TRUE;

	OPEN vTickets;
	l: LOOP
		SET vDone = FALSE;

		FETCH vTickets INTO vTicketFk;

		IF vDone THEN
			LEAVE l;
		END IF;

		CALL ticket_mergeSales(vTicketFk);
	END LOOP;
	CLOSE vTickets;
END$$
DELIMITER ;
