From 7ae2adbb5ebefb5fb21c41fc060dab21f9742a37 Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 30 Nov 2015 15:13:46 +0200 Subject: [PATCH] 108624154-func_modification --- db/migrate/20151124200353_add_ident_autofill.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/db/migrate/20151124200353_add_ident_autofill.rb b/db/migrate/20151124200353_add_ident_autofill.rb index d4efb1449..8065bbc0a 100644 --- a/db/migrate/20151124200353_add_ident_autofill.rb +++ b/db/migrate/20151124200353_add_ident_autofill.rb @@ -45,12 +45,15 @@ class AddIdentAutofill < ActiveRecord::Migration END LOOP; mod := (total % 11); END IF; - - IF (mod < 10 AND substring(r.ident, 11, 1) = to_char(mod, 'FM999MI')) + IF (mod = 10) + THEN + mod := 0; + END IF; + IF (substring(r.ident, 11, 1) = to_char(mod, 'FM999MI')) THEN UPDATE contacts SET ident_country_code = 'EE' WHERE id = r.id; END IF; - total = 0; + total := 0; END IF; END LOOP; @@ -66,7 +69,7 @@ class AddIdentAutofill < ActiveRecord::Migration counter := (counter + 1); END LOOP; mod := total % 11; - total = 0; + total := 0; counter := 1; IF (mod >= 10) THEN @@ -78,7 +81,11 @@ class AddIdentAutofill < ActiveRecord::Migration END LOOP; mod := (total % 11); END IF; - IF (mod < 10 AND (substring(r.ident, 8, 1) = to_char(mod, 'FM999MI'))) + IF (mod = 10) + THEN + mod := 0; + END IF; + IF (substring(r.ident, 8, 1) = to_char(mod, 'FM999MI')) THEN UPDATE contacts SET ident_country_code = 'EE' WHERE id = r.id; END IF;