CODIGO DESARROLLADO EN VISUAL FOX PRO PARA GENERAR RFC CON HOMOCLAVE Y DIGITO VERIFICADOR SEGUN HACIENDA EN MEXICO
FUNCTION GENERA_RFC(CL_PAT,CL_MAT,CL_NOM,DL_FECNAC)
DIMENSION arre8(10),arre6(4),arre2(10),arre9(1),anex11(1),anex12(1),anex31(1),anex32(1)
arre8[1]="DE "
arre8[2]="DEL "
arre8[3]="LA "
arre8[4]="LOS "
arre8[5]="LAS "
arre8[6]="Y "
arre8[7]="MC "
arre8[8]="MAC "
arre8[9]="VON "
arre8[10]="VAN "
arre6[1]="JOSE "
arre6[2]="MARIA "
arre6[3]="J "
arre6[4]="MA "
arre2[1]="A"
arre2[2]="E"
arre2[3]="I"
arre2[4]="O"
arre2[5]="U"
arre2[6]="a"
arre2[7]="e"
arre2[8]="i"
arre2[9]="o"
arre2[10]="u"
arre9[1]=""
sino = "S"
malas ="BUEIBUEYCACACACOCAGACAGOCAKACAKOCOGECOJAKOGEKOJOKAKAKULOMAMEMAMO"
malas = malas +"MEARMEASMEONMIONCOJECOJICOJOCULOFETOGUEYJOTOKACAKACOKAGA"
malas = malas + "KAGOMOCOMULAPEDAPEDOPENEPUTAPUTOQULORATARUIN"
for x = 1 to Len(malas) step 4
DIMENSION arre9(X)
arre9(X)=SubStr(malas, x, 4)
next
anex11[1] = ''
anex12[1] = ''
taba11 = "*0123456789&\ABCDEFGHIJKLMNOPQRSTUVWXYZ"
taba12 = "000001020304050607080910101112131415161718192122232425262728293233343536373839"
for x = 1 to Len(taba11)
DIMENSION anex11(x),anex12(x)
anex11(x)=SubStr(taba11, x, 1)
two = x * 2 - 1
anex12(x)=SubStr(taba12, two, 2)
next
malas = ""
taba11 = ""
taba12 = ""
taba21 = "00010203040506070809101112131415161718192021222324252627282930313233"
taba22 = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZ"
for x = 1 to Len(taba21) step 2
DIMENSION anex21(x),anex22(x)
anex21(x)=SubStr(taba21, x, 2)
two = ( x + 1 ) / 2
anex22(x)=SubStr(taba22, two, 1)
next
taba21 = ""
taba22 = ""
taba11 = "0123456789ABCDEFGHIJKLMN&OPQRSTUVWXYZ*"
taba12 = "0001020304050607080910111213141516171819202122232425262728293031323334353637"
anex31(1) = ''
anex32(1) = ''
FOR x = 1 to Len(taba11)
DIMENSION anex31(x),anex32(x)
anex31(x)=SubStr(taba11, x, 1)
two = (x * 2) - 1
anex32(x)=SubStr(taba12, two, 2)
NEXT
STORE SPACE(0) TO taba11,taba12,wrfc,wnumer6,wlos3
STORE Space(30) TO wpaterno,wmaterno,wnombre,paterno,materno,nombre
mask = Replicate("!", 30)
wanual = VAL(STR(YEAR(dl_fecnac),4)+PADL(ALLTRIM(STR(MONTH(dl_Fecnac),2)),2,'0')+PADL(ALLTRIM(STR(DAY(dl_fecnac),2)),2,'0'))
wpaterno = CL_PAT
wmaterno = CL_MAT
wnombre = CL_NOM
IF nacio(wanual) = .F.
=MESSAGEBOX('La Fecha de Nacimiento es Incorrecta',16+0,'Error')
RETURN SPACE(0)
ENDIF
IF los3(wpaterno, wmaterno, wnombre) = .F.
=MESSAGEBOX('El Nombre del Empleado es Incorrecto',16+0,'Error')
RETURN SPACE(0)
ENDIF
finice = .F.
octava()
sexta()
tercera()
wbase = alltrim(alltrim(paterno) + " " + alltrim(materno) +" " + alltrim(nombre))
IF ( Len(paterno) = 0 .OR. Len(materno) = 0 )
septima()
finice = .T.
ENDIF
IF ( !finice )
IF ( Len(paterno) < 3 )
cuarta()
finice = .T.
ENDIF
ENDIF
IF ( !finice )
prime_segu()
ENDIF
RETURN wrfc
ENDFUNC
PROCEDURE SHOW_IT( Arg1 )
cuatro = SubStr(Arg1, 1, 4)
van = ascan(arre9, cuatro)
if ( van > 0 )
wrfc = stuff(wrfc, 4, 1, "X")
endif
homoni()
digito()
RETURN
ENDPROC
PROCEDURE PRIME_SEGU()
letra = SubStr(paterno, 2, 1)
for x = 2 to Len(paterno)
van = ascan(arre2, SubStr(paterno, x, 1))
if ( van > 0 )
letra = arre2[ van ]
x = Len(paterno) + 8
endif
next
wrfc = SubStr(paterno, 1, 1) + letra + SubStr(materno, 1, 1) + SubStr(nombre, 1, 1)
wrfc = wrfc + wnumer6 + "000"
show_it(wrfc)
RETURN
ENDPROC
PROCEDURE TERCERA()
IF ( SubStr(nombre, 1, 2) = "CH" )
nombre = stuff(nombre, 1, 2, "C")
ELSE
IF ( SubStr(nombre, 1, 2) = "LL" )
nombre = stuff(nombre, 1, 2, "L")
ENDIF
ENDIF
IF ( SubStr(paterno, 1, 2) = "CH" )
paterno = stuff(paterno, 1, 2, "C")
ELSE
IF ( SubStr(paterno, 1, 2) = "LL" )
paterno = stuff(paterno, 1, 2, "L")
ENDIF
ENDIF
IF ( SubStr(materno, 1, 2) = "CH" )
materno = stuff(materno, 1, 2, "C")
ELSE
IF ( SubStr(materno, 1, 2) = "LL" )
materno = stuff(materno, 1, 2, "L")
ENDIF
ENDIF
RETURN
ENDPROC
********************************
PROCEDURE CUARTA()
wrfc = SubStr(paterno, 1, 1) + SubStr(materno, 1, 1) +SubStr(nombre, 1, 2) + wnumer6 + "000"
show_it(wrfc)
RETURN
ENDPROC
********************************
PROCEDURE SEXTA()
posi = At(" ", nombre)
IF ( posi > 0 )
FOR xx = 1 to ALen(arre6,1)
nombre = strtran(nombre, arre6[xx])
NEXT
ENDIF
RETURN
ENDPROC
********************************
PROCEDURE SEPTIMA()
IF ( Len(paterno) = 0 .AND. Len(materno) > 0 )
unosolo = materno
ELSE
IF ( Len(paterno) > 0 .AND. Len(materno) = 0 )
unosolo = paterno
ENDIF
ELSE
unosolo = nombre
endif
wrfc = SubStr(unosolo, 1, 2) + SubStr(nombre, 1, 2) + wnumer6 + "000"
show_it(wrfc)
RETURN
ENDPROC
********************************
PROCEDURE OCTAVA()
FOR xx = 1 to aLen(arre8,1)
paterno = strtran(paterno, arre8[ xx ])
materno = strtran(materno, arre8[ xx ])
nombre = strtran(nombre, arre8[ xx ])
NEXT
RETURN
ENDPROC
Function NACIO( Arg1 )
LOCAL ll_error
DIMENSION Local1(12)
Local1(1)=31
Local1(2)=28
Local1(3)=31
Local1(4)=30
Local1(5)=31
Local1(6)=30
Local1(7)=31
Local1(8)=31
Local1(9)=30
Local1(10)=31
Local1(11)=30
Local1(12)=31
if ( Arg1 = 0 )
bb = .F.
else
todo = Str(Arg1, 8)
bb = .T.
uno = Val(SubStr(todo, 7, 2))
dos = Val(SubStr(todo, 5, 2))
tres = Val(SubStr(todo, 1, 4))
if ( Arg1 = 0 .OR. uno = 0 .OR. dos = 0 )
bb = .F.
ELSE
IF ( dos <= 0 .OR. dos > 12 )
bb = .F.
ELSE
bisies = Local1[ dos ]
sanual = Str(tres, 4)
sanual2 = Val(sanual)
if ( dos = 2 .AND. Int(sanual2 / 4) * 4 = sanual2 )
bisies = bisies + 1
endif
ENDIF
if ( bb )
if ( uno <= 0 .OR. uno > bisies )
bb = .F.
endif
endif
endif
if ( !bb )
=MESSAGEBOX('ERROR EN FECHA DE NACIMIENTO',16+0,'Error')
else
wnumer6 = SUBSTR(Str(tres, 4),3,2)
if ( dos < 10 )
wnumer6 = wnumer6 + "0" + Str(dos, 1)
else
wnumer6 = wnumer6 + Str(dos, 2)
endif
if ( uno < 10 )
wnumer6 = wnumer6 + "0" + Str(uno, 1)
else
wnumer6 = wnumer6 + Str(uno, 2)
endif
ENDIF
Return bb
ENDFUNC
Function LOS3( Arg1, Arg2, Arg3 )
paterno = Trim(Arg1)
materno = Trim(Arg2)
nombre = Trim(Arg3)
wlos3 = alltrim(alltrim(Arg1) + " " + alltrim(Arg2) + " " + ;
alltrim(Arg3))
wlos3 = strtran(wlos3, " ", " ")
IF ( Len(wlos3) <= 6 )
Return .F.
ENDIF
Return .T.
ENDFUNC
PROCEDURE HOMONI()
valores = "0"
wbase = alltrim(alltrim(wpaterno) + " " + alltrim(wmaterno) +" " + alltrim(wnombre))
FOR x = 1 TO Len(wbase)
unok = SubStr(wbase, x, 1)
IF ( unok = " " )
unok = "*"
ENDIF
van = ascan(anex11, unok)
IF ( van > 0 )
valores = valores + anex12[ van ]
ELSE
valores = valores + "00"
ENDIF
NEXT
sumas = 0
FOR x = 1 TO Len(valores) - 1
prod1 = Val(SubStr(valores, x, 2))
prod2 = Val(SubStr(valores, x + 1, 1))
prod3 = prod1 * prod2
sumas = sumas + prod3
NEXT
zumass = Str(sumas, 10, 0)
zumass = right(zumass, 3)
zumas = Val(zumass)
solotres = zumas
cociente = Int(solotres / 34)
residuo = solotres - cociente * 34
IF ( cociente < 10 )
wrok = "0" + Str(cociente, 1)
ELSE
wrok = Str(cociente, 2)
ENDIF
van = ascan(anex21, wrok)
IF ( van > 0 )
homo = anex22[ van ]
ELSE
homo = "1"
ENDIF
IF ( residuo < 10 )
wrok = "0" + Str(residuo, 1)
ELSE
wrok = Str(residuo, 2)
ENDIF
van = ascan(anex21, wrok)
IF ( van > 0 )
homo = homo + anex22[ van ]
ELSE
homo = homo + "1"
ENDIF
wrfc = SubStr(wrfc, 1, 10) + homo
RETURN
ENDPROC
PROCEDURE DIGITO()
valores = ""
FOR x = 1 TO Len(wrfc)
unok = SubStr(wrfc, x, 1)
IF unok = " "
unok = "*"
ENDIF
van = ascan(anex31, unok)
IF van > 0
valores = valores + anex32[ van ]
ELSE
valores = valores + "00"
ENDIF
NEXT
sumas = 0
trece = 13
FOR x = 1 TO 12
prod1 = Val(SubStr(valores, x * 2 - 1, 2))
prod3 = prod1 * trece
sumas = sumas + prod3
trece = trece - 1
NEXT
cociente = Int(sumas / 11)
residuo = Int(sumas) - cociente * 11
IF residuo = 0
dijito = "0"
ELSE
valor = 11 - residuo
IF ( valor = 10 )
dijito = "A"
ELSE
entrer = Str(valor, 10, 0)
dijito = right(entrer, 1)
ENDIF
ENDIF
wrfc = wrfc + dijito
RETURN
ENDPROC