refs #6443 migrate vn2008.cc_to_iban to util.accountNumberToIban #2006

Merged
ivanm merged 2 commits from 6443-MigrateVn2008.cc_to_ibanToUtil into dev 2024-02-08 10:48:43 +00:00
3 changed files with 59 additions and 49 deletions

View File

@ -0,0 +1,58 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`accountNumberToIban`(
vAccount VARCHAR(20)
)
RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
DETERMINISTIC
BEGIN
/**
* Calcula y genera el código IBAN correspondiente
* a un número de cuenta bancaria español.
*
* @param vAccount Número de cuenta bancaria
* @return vIban Código IBAN de 4 caracteres.
*/
DECLARE vIban VARCHAR(4);
SELECT
CONCAT('ES',
RIGHT(
CONCAT(0,
98-MOD(
CONCAT(
MOD(
CONCAT(
MOD(
CONCAT(
MOD(
SUBSTRING(vAccount, 1, 8),
97
),
SUBSTRING(vAccount,9,8)
),
97
),
SUBSTRING(
CONCAT(vAccount, 142800),
17,
8
)
),
97
),
SUBSTRING(
CONCAT(vAccount, 142800),
25,
2
)
),
97
)
),
2
)
) INTO vIban;
RETURN vIban;
END$$
DELIMITER ;

View File

@ -1,49 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn2008`.`cc_to_iban`(cc VARCHAR(20))
RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
DETERMINISTIC
BEGIN
DECLARE iban VARCHAR(4);
select
CONCAT('ES',
RIGHT(
concat(0,
98-
mod(
concat(
mod(
concat(
mod(
concat(
mod(
substring(cc,1,8),
97),
substring(cc,9,8)
),
97),
substring(
concat(
cc,
142800
),
17,
8
)
),
97),
substring(
concat(
cc,
142800
),
25,
2
)
),
97)
)
,2)
)into iban;
RETURN iban;
END$$
DELIMITER ;

View File

@ -0,0 +1 @@
REVOKE EXECUTE ON FUNCTION vn2008.cc_to_iban FROM hr, financial;