***************************************************************************************************************
****	Proceduri:
****		vizualizeaza_curs
****		citeste_cursuri_stoc
****		citeste_curs_zi
***************************************************************************************************************
****************************************** INCEPUT: vizualizeaza_curs *****************************************
Procedure vizualizeaza_curs
*!*	modificare ROAFACTURARE	v 2.0.46
Lparameters tdDataCurs
*!*	modificare ROAFACTURARE	v 2.0.46	^
Private poCurs
Local lcSelect, lcFiltru, lcSchema, lcOrder, llAfiseaza, loFrmCurs
Store .F. To llAfiseaza
Store '' To poCurs
If Used('crscurs')
	Use In crscurs
Endif

lcSchema = ['id_curs n(10),id_valuta n(10),data d,data2 d,nume_val c(100),curs n(20,gnPCurs),multiplicator N(10),id_valuta_iso N(10),iso_valuta C(3),curs_bnr n(20,4)']
lcSelect = ['select id_curs,id_valuta,data,data2,nume_val,curs,multiplicator,id_valuta_iso,iso_valuta,curs_bnr from ] + gcS + [.vcurs where 2=2']
lcOrder = [data]
*!*	modificare ROAFACTURARE	v 2.0.46
*!*	lcFiltru = [1 = 2]
lcFiltru = Iif(Empty(tdDataCurs),[1 = 2],[data <= to_date('] + Dtoc(tdDataCurs,1) + [','YYYYMMDD') ] + ;
	[and data2 >= to_date('] + Dtoc(tdDataCurs,1) + [','YYYYMMDD') ])
*!*	modificare ROAFACTURARE	v 2.0.46	^
llAfiseaza = .F.
gencursor('poCurs', 'crscurs', lcSelect, lcFiltru, lcSchema, lcOrder, llAfiseaza)
poCurs.ca_baza1.afisare()

*!*	modificare ROAFACTURARE	v 2.0.46
*!*	loFrmCurs = Createobject("frm_curs")
loFrmCurs = Createobject("frm_curs",tdDataCurs)
*!*	modificare ROAFACTURARE	v 2.0.46	^
loFrmCurs.Show(1)

Release loFrmCurs, poCurs
If Used('crscurs')
	Use In crscurs
Endif
Endproc
****************************************** SFARSIT: vizualizeaza_curs *****************************************
***************************************** INCEPUT: citeste_cursuri_stoc ****************************************
Function citeste_cursuri_stoc
Lparameters tdData,tnIdValuta
Private pdDataCurs,pnIdValuta
Local lcCursor, llContinuare,lcListaValute
pdDataCurs = tdData
pnIdValuta = tnIdValuta
lcCursor = [crscursuri]
llVerificare = .T.
llContinuare = .T.
lnIncercari = 1

Do While llVerificare
	If llContinuare
		If Used(lcCursor)
			Use In (lcCursor)
		Endif
		lcSql = [select a.id_valuta, b.curs, b.multiplicator, c.nume_val, c.moneda_nationala from ] + ;
			[(select distinct id_valuta from ] + gcS + [.stoc where an = ?gnAn and luna = ?gnLuna ] + gcCondSucursala + ;
			[and id_gestiune in (select distinct b.id_gestiune from ] + gcS + [.gest_coresp_util_grupe a ] + ;
			[left join ] + gcS + [.gest_coresp_grupe_gestiuni b on a.id_grupe = b.id_grupe ] + ;
			[left join ] + gcS + [.nom_gestiuni c on b.id_gestiune = c.id_gestiune ] + ;
			[where a.id_util = ?gnIdUtil and a.sters = 0 and b.sters = 0 and c.nr_pag ] + IIF(gnTipGest=6,[=],[<>]) + [ 6) ] + ;
			[union select ?pnIdValuta as id_valuta from dual) a ] + ;
			[left join ] + gcS + [.curs b on a.id_valuta = b.id_valuta and b.data <= ?pdDataCurs and b.data2 >= ?pdDataCurs and b.sters = 0 ] + ;
			[left join ] + gcS +[.nom_valute c on a.id_valuta = c.id_valuta ] + ;
			[where c.moneda_nationala = 0 and a.id_valuta is not null]
		lnSucces = goExecutor.oExecute(lcSql,lcCursor)
		If lnSucces < 0
			amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
			llVerificare = .F.
			llContinuare = .F.
		Else
			If Reccount(lcCursor) > 0
				lcListaValute = []
				Select (lcCursor)
				Scan For Isnull(Curs)
					lcListaValute = lcListaValute + Alltrim(Upper(nume_val)) + [,]
				Endscan
				If !Empty(lcListaValute)
					If Used(lcCursor)
						Use In (lcCursor)
					Endif
					If lnIncercari >= 2 And aMessagebox("Doriti sa continuati introducerea datelor?",4+32,"Confirmare continuare")==7
						llVerificare = .F.
						llContinuare = .F.
					Else
						lcListaValute = Substr(lcListaValute,1,Len(lcListaValute)-1) + [ !]
						amessagebox("Pentru data de "+Dtoc(pdDataCurs)+" nu exista cursul pentru " + ;
							IIF(Getwordcount(lcListaValute,[,])=1,"valuta ","valutele ")+lcListaValute,48,"Atentie")
						vizualizeaza_curs()
					Endif
				Else
					llVerificare = .F.
				Endif
			Else
				amessagebox("Cautarea cursurilor pentru ziua de "+Dtoc(pdDataCurs)+" nu a intors rezultate!",16,"Eroare")
				llVerificare = .F.
				llContinuare = .F.
			Endif
		Endif
	Endif
	lnIncercari = lnIncercari + 1
Enddo

Return llContinuare
Endfunc	&&	citeste_cursuri_stoc
***************************************** SFARSIT: citeste_cursuri_stoc ****************************************
***************************************** INCEPUT: citeste_curs_zi ****************************************
Procedure citeste_cursuri_zi
Lparameters tdDataCurs
Local lcCursor
lcCursor = [crscursuri]
lcSql = [select nume_val,curs,id_valuta,multiplicator from ] + gcS + [.vcurs where data <= to_date('] + Dtoc(tdDataCurs,1) + [','YYYYMMDD') ] + ;
	[and data2 >= to_date('] + Dtoc(tdDataCurs,1) + [','YYYYMMDD') order by nume_val]
lnSucces = goExecutor.oExecute(lcSql,lcCursor)
If lnSucces < 0
	amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
EndIf
Release lcCursor
Endproc	&& citeste_curs_zi
***************************************** SFARSIT: citeste_curs_zi ****************************************
