From dee70198241fdad2d46e9d992404cb14584d1985 Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 8 Feb 2024 10:50:56 +0100 Subject: [PATCH] refs #6443 migrate vn2008.cc_to_iban to util.accountNumberToIban --- .../util/functions/accountNumberToIban.sql | 58 +++++++++++++++++++ db/routines/vn2008/functions/cc_to_iban.sql | 49 ---------------- .../10873-greenPaniculata/00-firstScript.sql | 1 + 3 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 db/routines/util/functions/accountNumberToIban.sql delete mode 100644 db/routines/vn2008/functions/cc_to_iban.sql create mode 100644 db/versions/10873-greenPaniculata/00-firstScript.sql diff --git a/db/routines/util/functions/accountNumberToIban.sql b/db/routines/util/functions/accountNumberToIban.sql new file mode 100644 index 000000000..2b38efe72 --- /dev/null +++ b/db/routines/util/functions/accountNumberToIban.sql @@ -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 ; \ No newline at end of file diff --git a/db/routines/vn2008/functions/cc_to_iban.sql b/db/routines/vn2008/functions/cc_to_iban.sql deleted file mode 100644 index c4515a9cc..000000000 --- a/db/routines/vn2008/functions/cc_to_iban.sql +++ /dev/null @@ -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 ; diff --git a/db/versions/10873-greenPaniculata/00-firstScript.sql b/db/versions/10873-greenPaniculata/00-firstScript.sql new file mode 100644 index 000000000..59ab23944 --- /dev/null +++ b/db/versions/10873-greenPaniculata/00-firstScript.sql @@ -0,0 +1 @@ +REVOKE EXECUTE ON FUNCTION vn2008.cc_to_iban FROM hr, financial;