/***************
聽 聽Prog 聽 聽 聽 聽: NumLetra.prg
聽 聽Autor 聽 聽 聽 : Hernan Diego Checarelli
聽 聽M贸dulo 聽 聽 聽:
聽 聽Inicio 聽 聽 聽: 14/01/2010 - Bajado del Foro FiveTech
聽 聽 聽 聽 聽 聽 聽 聽***************************************
*/
#include "fivewin.ch"
FUNCTION NumLetras( nImporte, nDec )
聽 聽local cTexto:= '' /// Equivale a '999999999999.99'
聽 聽local cPicture:= 聽Replicate('9',12)
聽 聽local lSonSoloCentavos:= .F., nCpn
聽 聽local cNumero,aU,aD,aV,aC,aE,aM
聽 聽local nImporteDec:= 0
聽 聽DEFAULT nDec:= 2
聽 聽if nImporte < 0
聽 聽 聽 cTexto:= 'Menos'
聽 聽 聽 nImporte *=-1 聽 /// Lo paso a positivo
聽 聽endif
聽 聽if nDec == 0
聽 聽 聽 nImporte:= Int( nImporte )
聽 聽endif
聽 聽if nDec > 0
聽 聽 聽 cPicture+= '.' + Replicate('9', nDec)
聽 聽endif
聽 聽if nImporte < 1 .and. nImporte > 0 聽// Solo Decimales
聽 聽 聽 nImporteDec:= Val( SubStr( Transform( nImporte, "9.9999999999999999" ), 3, nDec ) )
聽 聽 聽 nImporte 聽 := Val( AllTrim(Str(Int(nImporte))) + "." + AllTrim(Str(Int(nImporteDec))) )
聽 聽endif
聽 聽//// Evaluo la cadena numerica ,dividiendola en cuadro partes:
聽 聽//// 999 - 999 - 999 - 999 y los decimales correspondientes.
聽 聽cNumero := Transform( nImporte , cPicture )
聽 聽nImporte:= Val( cNumero )
聽 聽do case
聽 聽 聽 case nImporte 聽== 0 .and. nImporteDec == 0
聽 聽 聽 聽 聽cTexto 聽:= 'Cero'
聽 聽 聽 case nDec > 0 .and. nImporteDec > 0
聽 聽 聽 聽 聽nImporte:= nImporteDec
聽 聽 聽 聽 聽cNumero := Transform( nImporte , cPicture )
聽 聽 聽 聽 聽lSonSoloCentavos:= .T.
聽 聽endcase
聽 聽aU:= {'Uno','Dos','Tres','Cuatro','Cinco','Seis','Siete','Ocho','Nueve'}
聽 聽aD:= {'Once','Doce','Trece','Catorce','Quince','Dieciseis','Diecisiete',;
聽 聽 聽 聽 聽'Dieciocho','Diecinueve'}
聽 聽aV:= {'Diez','Veinte','Treinta','Cuarenta','Cincuenta','Sesenta','Setenta',;
聽 聽 聽 聽 聽'Ochenta','Noventa'}
聽 聽aC:= {'Ciento','Doscientos','Trescientos','Cuatrocientos','Quinientos',;
聽 聽 聽 聽 聽'Seiscientos','Setecientos','Ochocientos','Novecientos'}
聽 聽aE:= {'Veintiuno','Veintidos','Veintitres','Veinticuatro','Veinticinco',;
聽 聽 聽 聽 聽'Veintiseis','Veintisiete','Veintiocho','Veintinueve'}
聽 聽aM:= {'Billones','Millones','Mil','/100'}
聽 聽for nCpn = 1 to 4 聽/// Los 4 '999'
聽 聽 聽 //// Analizo 1er. 9 ///
聽 聽 聽 if Val(SubStr(cNumero,1,1)) <> 0 聽// Si existe Centena !!!
聽 聽 聽 聽 聽do case
聽 聽 聽 聽 聽 聽 case SubStr(cNumero,1,3) == '100'
聽 聽 聽 聽 聽 聽 聽 聽cTexto:= AllTrim(cTexto) + Space(1) + SubStr(aC[1],1,4)
聽 聽 聽 聽 聽 聽 otherwise
聽 聽 聽 聽 聽 聽 聽 聽cTexto:= AllTrim(cTexto) + Space(1) + aC[Val(SubStr(cNumero,1,1))]
聽 聽 聽 聽 聽endcase
聽 聽 聽 endif
聽 聽 聽 //// Analizo 2do. 9 ///
聽 聽 聽 if Val(SubStr(cNumero,2,1)) <> 0 聽// Si existe Decena !!!
聽 聽 聽 聽 聽do case
聽 聽 聽 聽 聽 聽 case SubStr(cNumero,2,1) == '1' .and. SubStr(cNumero,3,1) <> '0'
聽 聽 聽 聽 聽 聽 聽 聽cTexto:= AllTrim(cTexto) + Space(1) + aD[ Val(SubStr(cNumero,3,1)) ]
聽 聽 聽 聽 聽 聽 case SubStr(cNumero,2,1) == '2' .and. SubStr(cNumero,3,1) <> '0'
聽 聽 聽 聽 聽 聽 聽 聽cTexto:= AllTrim(cTexto) + Space(1) + aE[ Val(SubStr(cNumero,3,1)) ]
聽 聽 聽 聽 聽 聽 otherwise
聽 聽 聽 聽 聽 聽 聽 聽cTexto:= AllTrim(cTexto) + Space(1) + aV[ Val(SubStr(cNumero,2,1)) ]
聽 聽 聽 聽 聽endcase
聽 聽 聽 endif
聽 聽 聽 //// Analizo 3er. 9 ///
聽 聽 聽 if Val(SubStr(cNumero,3,1)) <> 0 // Si existe la Unidad !!!
聽 聽 聽 聽 聽do case
聽 聽 聽 聽 聽 聽 case SubStr(cNumero,2,1) == '1' .or. SubStr(cNumero,2,1) == '2'
聽 聽 聽 聽 聽 聽 // Del 1 al 29 ya se habrian definido antes.-
聽 聽 聽 聽 聽 聽 otherwise
聽 聽 聽 聽 聽 聽 聽 聽if Val(SubStr(cNumero,1,2)) <> 0 .and. Val(SubStr(cNumero,2,1)) <> 0
聽 聽 聽 聽 聽 聽 聽 聽 聽 cTexto:= AllTrim(cTexto)+' y'
聽 聽 聽 聽 聽 聽 聽 聽endif
聽 聽 聽 聽 聽 聽 聽 聽cTexto:= AllTrim(cTexto) + Space(1) + aU[ Val(SubStr(cNumero,3,1)) ]
聽 聽 聽 聽 聽endcase
聽 聽 聽 聽 聽if nCpn <> 4 .and. SubStr(cNumero,3,1) == '1' .and. ;
聽 聽 聽 聽 聽 聽 SubStr(cNumero,2,1) <> '1'
聽 聽 聽 聽 聽 聽 cTexto:= SubStr( AllTrim(cTexto), 1, Len(AllTrim(cTexto))-1 )
聽 聽 聽 聽 聽 聽 /// Sino quedaria Uno millon o Uno mil => Le saco el ultimo caracter.
聽 聽 聽 聽 聽endif
聽 聽 聽 endif
聽 聽 聽 if nCpn < 4
聽 聽 聽 聽 聽 if ! Val(SubStr(cNumero,1,3)) == 0
聽 聽 聽 聽 聽 聽 聽cTexto:= AllTrim(cTexto) + Space(1) + aM[nCpn]
聽 聽 聽 聽 聽 endif
聽 聽 聽 聽 聽 if (nCpn == 1 .or. nCpn == 2) .and. Val(SubStr(cNumero,1,3)) == 1 聽/// ' 聽1'
聽 聽 聽 聽 聽 聽 聽cTexto:= SubStr( AllTrim(cTexto) , 1, Len(AllTrim(cTexto))-4) + '贸n'
聽 聽 聽 聽 聽 聽 聽/// Le saco el 'ones' y le pongo '贸n'
聽 聽 聽 聽 聽 endif
聽 聽 聽 endif
聽 聽 聽 cNumero:= SubStr( cNumero , 4 )
聽 聽next
聽 聽cNumero:= SubStr(cNumero,2,2) 聽/// Decimales del Nro.
聽 聽if Val(cNumero) <> 0 聽// Si tiene decimales
聽 聽 聽 cTexto:= AllTrim(cTexto)+' Con '+ cNumero +"/1"+Replicate("0",nDec)
聽 聽endif
聽 聽if lSonSoloCentavos
聽 聽 聽 cTexto:= StrTran(cTexto,'Uno','Un ')
聽 聽 聽 cTexto:= AllTrim(cTexto) + ' Centavo'
聽 聽 聽 if nImporte > 1
聽 聽 聽 聽 聽cTexto+= 's'
聽 聽 聽 endif
聽 聽 聽 if nDec <> 2 // No le Cabe la palabra "centavo<s>" cuando nDec no es 2.
聽 聽 聽 聽 聽cTexto:= "Cero Con " + AllTrim(Str(nImporteDec))+"/1"+Replicate("0",nDec)
聽 聽 聽 endif
聽 聽endif
RETURN( AllTrim( cTexto ) )