DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProblem`(
	vSelf INT
)
BEGIN
/**
 * Actualiza los problemas para los tickets con riesgo
 *
 * @param vSelf Id del ticket
 */
	DECLARE vHasRisk BOOL;
	DECLARE vHasHighRisk BOOL;

	SELECT t.risk > (c.credit + 10), ((t.risk - cc.riskTolerance) > (c.credit + 10)) 
			INTO vHasRisk, vHasHighRisk
		FROM client c
			JOIN ticket t ON t.clientFk = c.id 
			JOIN clientConfig cc
		WHERE t.id = vSelf;

	CREATE OR REPLACE TEMPORARY TABLE tmp.ticket 
		SELECT vSelf ticketFk, vRisk hasProblem;
	
	CALL ticket_setProblem('hasRisk');

	CREATE OR REPLACE TEMPORARY TABLE tmp.ticket 
		SELECT vSelf ticketFk, vHasHighRisk hasProblem;
	
	CALL ticket_setProblem('hasHighRisk');

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