*!* 07.04.2009
*!* creez cursoarele xsets_standard doar la prima intrare
*!* creez cursoarele xsets_utilizator la fiecare intrare si le combin cu xsets_standard in xsets

*!* 13.07.2020
*!* cursorul xnote contine si sectie, nresp, nrord, dst_chlt pentru folosirea la adun_date

Local lnSucces, i, lcWhere, lcXsets, lcXrequest, lcXnote
lnSucces = 1

For i = 1 To 2
	If i = 1
		lcWhere = "id_set < 1000000" && seturi standard
		lcXsets = 'xsets_standard'
		lcXrequest = 'xrequest_standard'
		lcXnote = 'xnote_standard'
	Else
		lcWhere = "id_set >= 1000000"&& seturi utilizator
		lcXsets = 'xsets_utilizator'
		lcXrequest = 'xrequest_utilizator'
		lcXnote = 'xnote_utilizator'
	Endif



	If i = 1 And Used(lcXsets)
		Loop
	Endif

	If i = 1
*		WAIT WINDOW 'xAct...' NOWAIT 
		lnSucces = goExecutor.oExecute([select * from xact], [XAct])
		If lnSucces < 0
			Messagebox(goExecutor.cEroare,0+16,_Screen.Caption)
		Endif

		If lnSucces > 0
*			WAIT WINDOW 'xItems...' NOWAIT 
			lnSucces = goExecutor.oExecute([select * from xitems], [XItems])
			If lnSucces < 0
				Messagebox(goExecutor.cEroare,0+16,_Screen.Caption)
			Endif
		Endif


		If lnSucces > 0
*			WAIT WINDOW 'xSetsCategorii...' NOWAIT 		
			lnSucces = goExecutor.oExecute([select * from xsetscategorii], [Xsetscategorii])
			If lnSucces < 0
				Messagebox(goExecutor.cEroare,0+16,_Screen.Caption)
			Endif
		Endif

		If lnSucces > 0
*			WAIT WINDOW 'xSetsUtilizatori...' NOWAIT 				
			lnSucces = goExecutor.oExecute([select * from xsets_utilizatori], [xsets_utilizatori])
			If lnSucces < 0
				Messagebox(goExecutor.cEroare,0+16,_Screen.Caption)
			Endif
		Endif

		nvl2Default("xact")
		nvl2Default("XItems")

	Endif && i = 1

	lcSqlxSets = [select id_set, nr_set, nume_set, fix as fixTemp, lista_note, explicatia, model, ] + ;
		[formgest, nu_sterg as nu_stergTemp, param1, listare, param2, frm_date, discount as discountTemp, ] + ;
		[adaos as adaosTemp, factura as facturaTemp,id_selst,] + ;
		[id_seldr, tip_doc, tip_ctr, expl_fixa,aleg_cont as aleg_contTemp, frm_plata,valuta as valutatemp, compens, ] + ;
		[id_tip_rul, id_jnetax, id_jtax, tipjurnal, id_jtaxn, productie as productieTemp, ] + ;
		[formproduc, cursval as cursvaltemp, procedura_lans, wht as whttemp, plata as platatemp, ] + ;
		[nu_jtva as nu_jtvatemp, nu_doc_pereche as nu_doc_perechetemp ] + ;
		[from xsets where ] + lcWhere

	lcSqlXrequest = [select * from xrequest where ] + lcWhere

*!*		lcSqlXnote = [select * from xnote where ] + lcWhere
	TEXT TO lcSqlXnote TEXTMERGE NOSHOW 
select n.*, s.sectie, l.nrord, p.denumire as nresp, v.tip_venchelt as dst_chlt, c.numar as contract
from xnote n left join nom_sectii s on n.id_sectie = s.Id_Sectie 
left join nom_lucrari l on n.id_lucrare = l.id_lucrare 
left join nom_parteneri p on n.id_responsabil = p.id_part
left join nom_venit_cheltuieli v on n.id_venchelt = v.id_venchelt
left join contracte c on n.id_ctr = c.id_ctr
where <<m.lcWhere>>
	endtext 

	Use In (Select(lcXsets))
	Use In (Select(lcXrequest))
	Use In (Select(lcXnote))

	lnSucces = goExecutor.oExecute(lcSqlxSets, [XSetsTemp]) && are valuta si aleg_cont cu valori 1,0 care vor fi transf in .t., .f.
	If lnSucces < 0
		Messagebox(goExecutor.cEroare,0+16,_Screen.Caption)
	Else
		Select *,Iif(valutaTemp = 1, .T., .F.) As valuta,;
			IIF(aleg_contTemp = 1,.T.,.F.) As aleg_cont,;
			IIF(cursvalTemp = 1,.T.,.F.) As cursval,;
			IIF(productieTemp = 1,.T.,.F.) As productie,;
			IIF(discountTemp = 1,.T.,.F.) As discount,;
			IIF(fixTemp = 1,.T.,.F.) As fix,;
			IIF(nu_stergTemp = 1,.T.,.F.) As nu_sterg,;
			IIF(adaosTemp = 1,.T., .F.) As adaos,;
			IIF(facturaTemp = 1,.T.,.F.) As factura, ;
			IIF(whtTemp = 1,.T.,.F.) As wht, ;
			IIF(plataTemp = 1,.T.,.F.) As plata, ;
			(nu_jtvatemp = 1) As nu_jtva, ;
			(nu_doc_perechetemp = 1) As nu_doc_pereche ;						
			From XSetsTemp ;
			Into Cursor (lcXsets) Readwrite
			
		USE IN (SELECT('xSetsTemp'))
	Endif

	If lnSucces > 0
		lnSucces = goExecutor.oExecute(lcSqlXrequest , lcXrequest)
		If lnSucces < 0
			Messagebox(goExecutor.cEroare,0+16,_Screen.Caption)
		Endif
	Endif

	If lnSucces > 0
		lnSucces = goExecutor.oExecute(lcSqlXnote , lcXnote)
		If lnSucces < 0
			Messagebox(goExecutor.cEroare,0+16,_Screen.Caption)
		Endif
	Endif

	nvl2Default(lcXsets)
	nvl2Default(lcXrequest, "id_tipdoc")
	nvl2Default(lcXnote)

Endfor && i

Use In (Select('xsets'))
Select * From xsets_standard Into Cursor xsets READWRITE 
If Used('xsets_utilizator')
	Append From Dbf('xsets_utilizator')
	Use In (Select('xsets_utilizator'))
Endif

Use In (Select('xrequest'))
Select * From xrequest_standard Into Cursor xrequest READWRITE 
If Used('xrequest_utilizator')
	Append From Dbf('xrequest_utilizator')
	Use In (Select('xrequest_utilizator'))
Endif

Use In (Select('xnote'))
Select * From xnote_standard Into Cursor xnote READWRITE 
If Used('xnote_utilizator')
	Append From Dbf('xnote_utilizator')
	Use In (Select('xnote_utilizator'))
Endif

Select xsets
Index On nume_set Tag nume_set
Index On nr_Set Tag nr_Set
Index On id_set Tag id_set
Set Order To id_set

Return lnSucces
