Last active
May 23, 2018 12:11
Revisions
-
rkleine renamed this gist
Aug 12, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rkleine revised this gist
Aug 12, 2017 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ function generateCUIL(dni, type) { if (dni.toString().length < 7) return false; let xy = 30; @@ -9,7 +9,14 @@ function generateCUIL(dni, type) { xy = 20; } const parts = `${dni}`.split(''); const diff = 8 - parts.length; for (let i = 0; i < diff; i++) { parts.unshift('0'); } parts.unshift(...`${xy}`.split('')) const numbers = '5432765432'.split(''); let sum = 0; -
rkleine revised this gist
Aug 12, 2017 . 2 changed files with 64 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ function generateCUIL(dni, type) { if (dni.length < 7) return false; let xy = 30; if (type === 'f') { xy = 27; } else if(type === 'm') { xy = 20; } const parts = `${xy}${dni}`.split(''); const numbers = '5432765432'.split(''); let sum = 0; for (let i = 0; i <= 9; i++) { sum += +parts[i] * +numbers[i]; } const remainder = sum % 11; let z = 11 - remainder; if (remainder === 0) { z = 0; } else if (remainder === 1 && type === 'm') { z = 9; xy = 23; } else if (remainder === 1 && type === 'f') { z = 4; xy = 23; } return `${xy}-${dni}-${z}`; } function validateCUIT(number, type) { const parts = `${number}`.split(''); if (parts.length !== 11) return false; const numbers = '5432765432'.split(''); let sum = 0; for (let i = 0; i <= 9; i++) { sum += +parts[i] * +numbers[i]; } const remainder = sum % 11; let z = 11 - remainder; if (remainder === 0) { z = 0; } else if (remainder === 1 && type === 'm') { z = 9; xy = 23; } else if (remainder === 1 && type === 'f') { z = 4; xy = 23; } else if (remainder === 1) { z = 9; } return z === +parts[10]; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +0,0 @@ -
rkleine revised this gist
May 29, 2017 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
rkleine revised this gist
Mar 26, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ def valid_cuit? numbers = %w(5 4 3 2 7 6 5 4 3 2) result = 0 10.times.each { |i| result += number[i].to_i * numbers[i].to_i } result = result % 11 result = 11 - result -
rkleine revised this gist
Mar 26, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ class Object def valid_cuit? number = self.to_s.gsub(/\D/, '').split('') return if number.size != 11 -
rkleine revised this gist
Mar 26, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ function validCUIT(number) { number = String(number || '').split(''); if (number.length !== 11) { return false; } -
rkleine revised this gist
Mar 26, 2015 . 2 changed files with 27 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ function isValidCUIT(number) { number = String(number || '').split(''); if (number.length !== 11) { return false; } var numbers = '5432765432'.split(''), result = 0; for (var i = 0; i <= 9; i++) { result += Number(number[i]) * Number(numbers[i]); } result = result % 11; result = 11 - result; if (result === 11) { result = 0; } if (result === 10) { result = 9; } return result === Number(number[10]); } validCUIT(20311251407) // => true validCUIT("20-31125140-7") // => true validCUIT(20311251405) // => false This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ class Object def valid_cuit? number = "20-31125140-7".to_s.gsub(/\D/, '').split('') return if number.size != 11 numbers = %w(5 4 3 2 7 6 5 4 3 2) result = 0 9.times.each { |i| result += number[i].to_i * numbers[i].to_i } @@ -20,4 +20,5 @@ def valid_cuit? end 20311251407.valid_cuit? # => true "20-31125140-7".valid_cuit? # => true 20311251405.valid_cuit? # => false -
rkleine revised this gist
Mar 26, 2015 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ class Object def valid_cuit? number = self.to_s.gsub(/\D/, '').split('') return if number.size != 11 @@ -18,3 +18,6 @@ def valid_cuit? result == number[10].to_i end end 20311251407.valid_cuit? # => true 20311251405.valid_cuit? # => false -
rkleine revised this gist
Mar 26, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ class Object def valid_cuit? number = self.to_s.split('') return if number.size != 11 -
rkleine renamed this gist
Mar 26, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rkleine created this gist
Mar 26, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ class Object def valid_cuit? number = (self.to_s || '').split('') return if number.size != 11 numbers = %w(5 4 3 2 7 6 5 4 3 2) result = 0; 9.times.each { |i| result += number[i].to_i * numbers[i].to_i } result = result % 11 result = 11 - result result = 0 if result == 11 result = 9 if result == 10 result == number[10].to_i end end