DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`ticket_getCurrencyRate`(
	vSelf INT,
	vCurrencyFk SMALLINT
)
	RETURNS DECIMAL(10,2)
	NOT DETERMINISTIC
	READS SQL DATA
BEGIN
/**
 * Returns the rate exchange based on the specified currency for a ticket
 *
 * @param vSelf The ticket id
 * @param vCurrencyFk The currency id, if is null, get the currency of the ticket
 * @return The rate of currency exchange
 */
	SELECT IFNULL(vCurrencyFk, currencyFk) INTO vCurrencyFk
		FROM ticket
		WHERE id = vSelf;

	RETURN currency_getRate(vCurrencyFk, ticket_getCurrencyDate(vSelf));
END$$
DELIMITER ;
