DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_getProblemsByTicket`(
    IN vTicketFk INT, 
    IN vIsTodayRelative TINYINT(1)
)
BEGIN
/**
 * Calcula los problemas de cada venta para un tickets.
 *
 * @return Problems result
 */
	CREATE OR REPLACE TEMPORARY TABLE tmp.sale
		(INDEX (saleFk))
		ENGINE = MEMORY
		SELECT id saleFk FROM sale WHERE ticketFk = vTicketFk;

	CALL sale_getProblems(vIsTodayRelative);

	SELECT * FROM tmp.saleProblems;

	DROP TEMPORARY TABLE tmp.saleProblems;
END$$
DELIMITER ;
