Skip to content

Instantly share code, notes, and snippets.

@yogonza524
Created December 4, 2015 06:11
Show Gist options
  • Save yogonza524/5942ed5e46520623b496 to your computer and use it in GitHub Desktop.
Save yogonza524/5942ed5e46520623b496 to your computer and use it in GitHub Desktop.
Método para generar CUIT a partir de un enum de genero y el dni
public enum Genero {
MASCULINO,FEMENINO,SOCIEDAD
}
public static String generate(Genero g,int dni) throws Exception{
int tipo;
if (g.equals(Genero.MASCULINO)) {
tipo = 20;
}
else{
if (g.equals(Genero.FEMENINO)) {
tipo = 27;
}
else{
tipo = 30;
}
}
String aux = String.valueOf(tipo) + String.valueOf(dni);
String[] cuitArray = aux.split("");
int codigo = 0;
if (aux.length() != 10) {
throw new Exception("Sexo o DNI no valido. La longitud no corresponde");
}
Integer[] serie = {5, 4, 3, 2, 7, 6, 5, 4, 3, 2};
for (int i=0; i<10; i++){
codigo += Integer.valueOf(cuitArray[i]) * serie[i];
}
codigo = 11 - (codigo % 11);
//Si el resultado anterior es 11 el código es 0
if (codigo == 11){
codigo = 0;
//o si el resultado anterior es 10 el código es 9
} else if (codigo == 10){
codigo = 9;
}
return tipo + "-" + dni + "-" + codigo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment