*!* 30.06.2017
*!* marius.mutu
*!* adaugat parametru tcValuta

*!*	MESSAGEBOX(suma_in_vorbe(1))
*!*	MESSAGEBOX(suma_in_vorbe(10))
*!*	MESSAGEBOX(suma_in_vorbe(100))
*!*	MESSAGEBOX(suma_in_vorbe(1000))
*!*	MESSAGEBOX(suma_in_vorbe(10000))
*!*	MESSAGEBOX(suma_in_vorbe(100000))
*!*	MESSAGEBOX(suma_in_vorbe(1000000))
*!*	MESSAGEBOX(suma_in_vorbe(10000000))
*!*	MESSAGEBOX(suma_in_vorbe(100000000))
*!*	MESSAGEBOX(suma_in_vorbe(1000000000))
*!*	MESSAGEBOX(suma_in_vorbe(10000000000))
*!*	MESSAGEBOX(suma_in_vorbe(11000000000))
*!*	MESSAGEBOX(suma_in_vorbe(11100000000))
*!*	MESSAGEBOX(suma_in_vorbe(11110000000))
*!*	MESSAGEBOX(suma_in_vorbe(11111000000))
*!*	MESSAGEBOX(suma_in_vorbe(11111100000))
*!*	MESSAGEBOX(suma_in_vorbe(11111110000))
*!*	MESSAGEBOX(suma_in_vorbe(11111111000))
*!*	MESSAGEBOX(suma_in_vorbe(11111111100))
*!*	MESSAGEBOX(suma_in_vorbe(11111111110))
*!*	MESSAGEBOX(suma_in_vorbe(11111111111))

*!*	Function SUMA_IN_VORBE
Parameter tnSuma, tcValuta

LOCAL lcValuta, lcLei, lcLeu, lcBani, lcBan
 
lcValuta = IIF(EMPTY(m.tcValuta), 'RON', ALLTRIM(UPPER(tcValuta)))
lcLei = IIF(INLIST(m.lcValuta,'LEI','RON'), 'lei', IIF('EUR'$m.lcValuta, 'euro', IIF(m.lcValuta = 'USD', 'dolari', IIF(m.lcValuta = 'GBP', 'lire', 'lei'))))
lcLeu = IIF(INLIST(m.lcValuta,'LEI','RON'), 'un leu', IIF('EUR'$m.lcValuta, 'un euro', IIF(m.lcValuta = 'USD', 'un dolar', IIF(m.lcValuta = 'GBP', 'o lira', 'un leu'))))
lcBani = IIF(INLIST(m.lcValuta,'LEI','RON'), 'bani', IIF('EUR'$m.lcValuta, 'centi', IIF(m.lcValuta = 'USD', 'centi', IIF(m.lcValuta = 'GBP', 'pence', 'bani'))))
lcBan = IIF(INLIST(m.lcValuta,'LEI','RON'), 'un ban', IIF('EUR'$m.lcValuta, 'un cent', IIF(m.lcValuta = 'USD', 'un cent', IIF(m.lcValuta = 'GBP', 'un peny', 'un ban'))))

Local i,j, putere, lit,numar1,numar2
Local lnSuma, lnSuma2
Local A[1], B[1]

Store 0 To i,j,lnSuma,lnSuma2
Store 1 To putere
Store '' To lit,numar1,numar2

lnSuma=Round(tnSuma,2)
lnSuma2=(lnSuma-Int(lnSuma))*100
lnSuma=Int(lnSuma)

*!*	lnSuma=ROUND(lnSuma,gnPa)
*!*	FOR j=1 TO gnPa
*!*		putere=10*putere
*!*	ENDFOR
*!*	lnSuma2=(lnSuma-Int(lnSuma))*putere

numar1=Space(12)
*!*	numar2=Space(gnPa)
numar2=Space(2)

numar1=Str(lnSuma,12)
*!*	numar2=Str(lnSuma2,gnPa)
numar2=Str(lnSuma2,2)

Dimension A(12)
A(1)=Subs(numar1,12,1)
A(2)=Subs(numar1,11,1)
A(3)=Subs(numar1,10,1)
A(4)=Subs(numar1,9,1)
A(5)=Subs(numar1,8,1)
A(6)=Subs(numar1,7,1)
A(7)=Subs(numar1,6,1)
A(8)=Subs(numar1,5,1)
A(9)=Subs(numar1,4,1)
A(10)=Subs(numar1,3,1)
A(11)=Subs(numar1,2,1)
A(12)=Subs(numar1,1,1)
Sele mila1
*********************
Loca For NR=Val(A(12))
lit=lit+Alltri(cr1)

If Val(A(11))=1
	If Val(A(10))=0
		Loca For NR=Val(A(11))
		lit=lit+Alltri(cr5)
	Else
		Loca For NR=Val(A(10))
		*!*	modificare	ROAAUTO v 2.0.5
		*!*			lit=lit+Alltri(cr4)
		lit=lit+Alltri(Strtran(cr4,[doi],[doua]))
		*!*	modificare	ROAAUTO v 2.0.5	^
	Endif
Else
	If Val(A(10))=0
		Loca For NR=Val(A(11))
		lit=lit+Alltrim(cr5)
	Else
		Loca For NR=Val(A(11))
		lit=lit+Alltrim(cr2)
		Loca For NR=Val(A(10))
		*!*	modificare	ROAAUTO v 2.0.5
		*!*			lit=lit+Alltri(cr3)
		*!* modificare	ROAAUTO v 2.1.12		
		lit=lit+Alltri(Strtran(Strtran(cr3,[unu],[un]),[doi],[doua]))
		*!*	modificare	ROAAUTO v 2.0.5	^
	Endif
Endif
Do Case
	CASE Val(A(10)) = 1 AND VAL(a(11)) = 0 AND VAL(a(12)) = 0	&&	modificare	ROAAUTO v 2.1.12
		lit=lit+' miliard'
	Case Val(A(12)) # 0
		lit=lit+' miliarde'
	Case Val(A(11)) # 0
		lit=lit+' miliarde'
	Case Val(A(10)) # 0
		lit=lit+' miliarde'
Endcase
***********************
Loca For NR=Val(A(9))
lit=lit+Alltri(cr1)

If Val(A(8))=1
	If Val(A(7))=0
		Loca For NR=Val(A(8))
		lit=lit+Alltri(cr5)
	Else
		Loca For NR=Val(A(7))
		*!*	modificare	ROAAUTO v 2.0.5
		*!*			lit=lit+Alltri(cr4)
		lit=lit+Alltri(Strtran(cr4,[doi],[doua]))
		*!*	modificare	ROAAUTO v 2.0.5	^
	Endif
Else
	If Val(A(7))=0
		Loca For NR=Val(A(8))
		lit=lit+Alltrim(cr5)
	Else
		Loca For NR=Val(A(8))
		lit=lit+Alltrim(cr2)
		Loca For NR=Val(A(7))
		*!*	modificare	ROAAUTO v 2.0.5
		*!*			lit=lit+Alltri(cr3)
		*!* modificare	ROAAUTO v 2.1.12		
		lit=lit+Alltri(Strtran(Strtran(cr3,[unu],[un]),[doi],[doua]))
		*!*	modificare	ROAAUTO v 2.0.5	^
	Endif
Endif
Do Case
	CASE Val(A(7)) = 1 AND VAL(a(8)) = 0 AND VAL(a(9)) = 0	&&	modificare	ROAAUTO v 2.1.12
		lit=lit+' milion'
	Case Val(A(9)) # 0
		lit=lit+' milioane'
	Case Val(A(8)) # 0
		lit=lit+' milioane'
	Case Val(A(7)) # 0
		lit=lit+' milioane'
Endcase
***********************
Loca For NR=Val(A(6))
lit=lit+Alltri(cr1)

If Val(A(5))=1
	If Val(A(4))=0
		Loca For NR=Val(A(5))
		lit=lit+Alltri(cr5)
	Else
		Loca For NR=Val(A(4))
		*!*	modificare	ROAAUTO v 2.0.5
		*!*			lit=lit+Alltri(cr4)
		lit=lit+Alltri(Strtran(cr4,[doi],[doua]))
		*!*	modificare	ROAAUTO v 2.0.5	^
	Endif
Else
	If Val(A(4))=0
		Loca For NR=Val(A(5))
		lit=lit+Alltrim(cr5)
	Else
		Loca For NR=Val(A(5))
		lit=lit+Alltrim(cr2)
		Loca For NR=Val(A(4))
		*!*	modificare	ROAAUTO v 2.0.5
		*!*			lit=lit+Alltri(cr3)
		*!* modificare	ROAAUTO v 2.1.12
		lit=lit+Alltri(STRTRAN(Strtran(cr3,[unu],[una]),[doi],[doua]))
		*!*	modificare	ROAAUTO v 2.0.5	^
	Endif
Endif
Do Case
	CASE Val(A(4)) = 1 AND VAL(a(5)) = 0 AND VAL(a(6)) = 0	&&	modificare	ROAAUTO v 2.1.12
		lit=lit+' mie'
	Case Val(A(6)) # 0
		lit=lit+' mii'
	Case Val(A(5)) # 0
		lit=lit+' mii'
	Case Val(A(4)) # 0
		lit=lit+' mii'
Endcase

*********************
Loca For NR=Val(A(3))
lit=lit+Alltri(cr1)

If Val(A(2))=1
	If Val(A(1))=0
		Loca For NR=Val(A(2))
		lit=lit+Alltri(cr5)
	Else
		Loca For NR=Val(A(1))
		lit=lit+Alltri(cr4)
	Endif
Else
	If Val(A(1))=0
		Loca For NR=Val(A(2))
		lit=lit+Alltrim(cr5)
	Else
		Loca For NR=Val(A(2))
		lit=lit+Alltrim(cr2)
		Loca For NR=Val(A(1))
		lit=lit+Alltrim(cr3)
	Endif
Endif
*!*	modificare	ROAAUTO v 2.1.12
*!*	lit=lit+' lei'
IF lnSuma # 0
	IF lnSuma = 1
		lit = m.lcLeu && 'un leu'
	Else
		lit=lit+' ' + m.lcLei && 'lei'
	Endif
Endif
*!*	modificare	ROAAUTO v 2.1.12	^
*********************
Do Case
	Case lnSuma2>1
		lit=lit+' si'
		Dimension B(2)
		B(1)=Subs(numar2,2,1)
		B(2)=Subs(numar2,1,1)

		Do Case
			Case Val(B(2))=1 And Val(B(1))!=0
				Loca For NR=Val(B(1))
				lit=lit+Alltri(cr4)
			Case Val(B(2))=0
				Loca For NR=Val(B(1))
				lit=lit+Alltrim(cr3)
			Case Val(B(1))=0
				Loca For NR=Val(B(2))
				lit=lit+Alltrim(cr5)
			Otherwise
				Loca For NR=Val(B(2))
				lit=lit+Alltrim(cr2)
				Loca For NR=Val(B(1))
				lit=lit+Alltrim(cr3)
		Endcase
		lit=lit+' ' + m.lcBani &&& 'bani'
	Case lnSuma2=1
		lit=lit+'si ' + m.lcBan && 'un ban'
Endcase

Sele mila1
*!*	use

lit=Strtran(lit,' ','')

Return lit
 