24 lines
723 B
SQL
24 lines
723 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`duaTax_getRate`(vDuaFk INT, vTaxClassFk INT)
|
|
RETURNS decimal(5,2)
|
|
DETERMINISTIC
|
|
BEGIN
|
|
/**
|
|
* Devuelve el rate para un Dua teniendo en cuenta la fecha de opreción del DUA
|
|
*
|
|
* @param vDuaFk Identificador de la tabla dua
|
|
* @param vTaxClassFk Identificador del IVA de la tabla invoiceInTaxBookingAccount
|
|
*/
|
|
RETURN (
|
|
SELECT rate
|
|
FROM dua d
|
|
JOIN supplier s ON s.id = d.companyFk
|
|
JOIN invoiceInTaxBookingAccount iit ON iit.countryFk = s.countryFk
|
|
AND iit.taxClassFk = vTaxClassFk
|
|
AND iit.effectived <= IFNULL( d.operated, util.VN_CURDATE())
|
|
WHERE d.id = vDuaFk
|
|
ORDER BY effectived DESC
|
|
LIMIT 1);
|
|
END$$
|
|
DELIMITER ;
|