/**************************************/
/* letras.p */
def shared var monto as de format "zzz,zzz,zz9.99" decimals 2.
def shared var letras as c format "x(200)".
def var ente as i.
def var cent as i.
def var can as i.
def var aux as i.
def var mil as lo.
def var lar as i.
def var car as c format "x(20)".
def var let as c format "x".
def var num as i.
def var centena as c format "x(13)" extent 10 initial
["CIENTO",
"DOSCIENTOS",
"TRESCIENTOS",
"CUATROCIENTOS",
"QUINIENTOS",
"SEISCIENTOS",
"SETECIENTOS",
"OCHOCIENTOS",
"NOVECIENTOS"].
def var decena as c format "x(9)" extent 10 initial
["DIEZ",
"VEINTE",
"TREINTA",
"CUARENTA",
"CINCUENTA",
"SESENTA",
"SETENTA",
"OCHENTA",
"NOVENTA"].
def var decena2 as c format "x(9)" extent 10 initial
["DIEZ",
"VEINTI",
"TREINTA Y ",
"CUARENTA Y ",
"CINCUENTA Y ",
"SESENTA Y ",
"SETENTA Y ",
"OCHENTA Y ",
"NOVENTA Y "].
def var unidad as c format "x(8)" extent 10 initial
["UNO",
"DOS",
"TRES",
"CUATRO",
"CINCO",
"SEIS",
"SIETE",
"OCHO",
"NUEVE"].
def var raro as c format "x(10)" extent 10 initial
["DIEZ",
"ONCE",
"DOCE",
"TRECE",
"CATORCE",
"QUINCE",
"DIECISEIS",
"DIECISIETE",
"DIECIOCHO",
"DIECINUEVE"].
letras="".
if monto=0 then return.
ente=truncate(monto,0).
cent=(monto - ente) * 100.
car=string(ente). can=length(car). lar=can. mil=yes.
repeat while can>0:
can=length(car). let=substring(car,1,1).
car=substring(car,2,(can - 1)).
num=int(let).
if can=9 then do:
if num<>0 then do:
if num=1 and substring(car,1,1)="0" and substring(car,2,1)="0" then
letras=letras + "CIEN ".
else
letras=letras + centena[num] + " ".
end.
end.
else if can=8 then do:
if num<>0 then do:
if num=1 then do:
let=string(car,"x"). aux=int(let).
letras=letras + raro[aux + 1] + " MILLONES ".
car=substring(car,2,(can - 1)).
end.
else do:
if substring(car,1,1)="0" then
letras=letras + decena[num] + " ".
else letras=letras + decena2[num].
end.
end.
end.
else if can=7 then do:
if substring(car,1,1)="0" and substring(car,2,1)="0" and
substring(car,3,1)="0" then mil=no.
if num<>0 then do:
if num=1 and substring(car,1,1)="0" then do:
letras=letras + "UN ".
if lar=7 then do: letras=letras + "MILLON ". next. end.
end.
else
if num=1 then letras=letras + "UN ".
else letras=letras + unidad[num] + " ".
end.
/*if num=1 then letras=letras + "MILLON ".
else*/ letras=letras + "MILLONES ".
end.
if can=6 then do:
if num<>0 then do:
if num=1 and substring(car,1,1)="0" and substring(car,2,1)="0" then
letras=letras + "CIEN ".
else
letras=letras + centena[num] + " ".
end.
end.
else if can=5 then do:
if num<>0 then do:
if num=1 then do:
let=string(car,"x"). aux=int(let).
letras=letras + raro[aux + 1] + " MIL ".
car=substring(car,2,(can - 1)).
end.
else do:
if substring(car,1,1)="0" then
letras=letras + decena[num] + " ".
else letras=letras + decena2[num].
end.
end.
end.
else if can=4 then do:
if num<>0 then do:
if num=1 then do:
letras=letras + "UN ".
end.
else
letras=letras + unidad[num] + " ".
end.
if mil then letras=letras + "MIL ".
end.
if can=3 then do:
if num<>0 then do:
if num=1 and substring(car,1,1)="0" and substring(car,2,1)="0" then
letras=letras + "CIEN ".
else
letras=letras + centena[num] + " ".
end.
end.
else if can=2 then do:
if num<>0 then do:
if num=1 then do:
let=string(car,"x"). aux=int(let).
letras=letras + raro[aux + 1] + " ".
car=substring(car,2,(can - 1)).
end.
else do:
if substring(car,1,1)="0" then
letras=letras + decena[num] + " ".
else letras=letras + decena2[num].
end.
end.
end.
else if can=1 then do:
if num<>0 then do:
if num=1 and lar=1 then do:
letras=letras + "UNO ".
if lar=7 then do: letras=letras. next. end.
end.
else
letras=letras + unidad[num].
end.
end.
end.
/*if ente=1 then letras=letras + "PESO".
else if ente<>0 then letras=letras + "PESOS".*/
if ente<>0 and substring(letras,length(letras),1)=" " then
letras=substring(letras,1,length(letras) - 1).
if cent=0 then do: letras=letras + ".". return. end.
if ente<>0 then letras=letras + " CON ".
car=string(cent). can=length(car). lar=can.
repeat while can>0:
can=length(car). let=substring(car,1,1).
car=substring(car,2,(can - 1)).
num=int(let).
if can=2 then do:
if num<>0 then do:
if num=1 then do:
let=string(car,"x"). aux=int(let).
letras=letras + raro[aux + 1] + " ".
car=substring(car,2,(can - 1)).
end.
else do:
if substring(car,1,1)="0" then
letras=letras + decena[num] + " ".
else letras=letras + decena2[num].
end.
end.
end.
else if can=1 then do:
if num<>0 then do:
if num=1 and lar=1 then do:
letras=letras + "UN ".
if lar=7 then do: letras=letras. next. end.
end.
else
letras=letras + unidad[num] + " ".
end.
end.
end.
if cent=1 then letras=letras + "CENTAVO.". else letras=letras + "CENTAVOS.".