31 lines
861 B
SQL
31 lines
861 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`addressTaxArea`(vAddresId INT, vCompanyId INT)
|
|
RETURNS varchar(25) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
|
|
DETERMINISTIC
|
|
BEGIN
|
|
/**
|
|
* Devuelve el area de un Consignatario,
|
|
* intracomunitario, extracomunitario, nacional o recargo de equivalencia.
|
|
* Asumimos que no tenemos ninguna empresa
|
|
*
|
|
* @param vAddresId Id del Consignatario
|
|
* @param vCompanyId Compañia desde la que se factura
|
|
* @return Código de area
|
|
*/
|
|
DECLARE vTaxArea VARCHAR(25);
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany;
|
|
CREATE TEMPORARY TABLE tmp.addressCompany
|
|
SELECT vAddresId addressFk, vCompanyId companyFk;
|
|
|
|
CALL vn.addressTaxArea();
|
|
SELECT areaFk INTO vTaxArea FROM tmp.addressTaxArea;
|
|
|
|
DROP TEMPORARY TABLE
|
|
tmp.addressCompany,
|
|
tmp.addressTaxArea;
|
|
|
|
RETURN vTaxArea;
|
|
END$$
|
|
DELIMITER ;
|