salix/db/routines/vn/functions/currency_getCommission.sql

24 lines
556 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`currency_getCommission`(vSelf INT)
RETURNS int(11)
DETERMINISTIC
BEGIN
/**
* Devuelve el tipo de cambio en el dia de hoy dada el tipo de moneda
*
* @param vSelf id del tipo de moneda
* @return devuelve la comision
*/
DECLARE vCommission INT;
SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission
FROM referenceCurrent r
WHERE r.currencyFk = vSelf
AND r.`dated` <= util.VN_CURDATE()
ORDER BY r.`dated` DESC
LIMIT 1;
RETURN vCommission;
END$$
DELIMITER ;