Define Class oexecutor As Custom
	nHandle = 0
	cSql = ''
	cCursor = ''
	nSucces = 0
	cEroare = ''
	nEroare = 0
	cTime = ''
	lReconnect = .T. && cred ca trebuie setat pe .F. inainte de o serie de proceduri executate cu tranzactie manuala
	lShowError = .F.
	lQuitOnError = .F.

	Declare aEroare[1]


* PROCEDURE INIT( tnHandle, tcSql, tcCursor  )
* Date : 06/10/2004, 12:18:21
* author : marius.mutu
* description:

****** PARAMETER BLOCK **************
* Parameters : 3
* Parameter 1:
* Parameter 2:
* Parameter 3:
*
******************************************* INCEPUT:INIT *******************************************
	Procedure Init
	Lparameters tnHandle, tcSql, tcCursor


	If Empty(tnHandle)
		This.nHandle = gnHandle
	Else
		This.nHandle = tnHandle
	Endif

	Endproc
******************************************* SFARSIT: INIT *******************************************


* PROCEDURE oExecute( tcSql, tcCursor,tlProgress, tnHandle )
* Date : 06/10/2004, 12:16:11
* author : marius.mutu
* description:

****** PARAMETER BLOCK **************
* Parameters : 3
* Parameter 1:
* Parameter 2:
* Parameter 3:
*
******************************************* INCEPUT:oExecute *******************************************
	Procedure oExecute( tcSql, tcCursor, tlProgress, tcTitluProgress, tnHandle, tlShowError, tlQuitOnError, tlReconnect )
	Local lnHandle, lcSql, lcCursor, llProgress, lnSucces, laEroare, lcEroare, llShowError, llQuitOnError, llReconnect


&& tlQuitOnError : Daca face QUIT la eroare (daca vreau QUIT dau .T.) (default .F.)
&& tlShowError : Daca arata mesajul de eroare (daca vreau sa il tratez in oexecute dau .T.) (default .F.)
&& tlReconnect : Daca incearca sa se reconecteze (default .T.)
	If .F.
		Local This As oexecutor
	Endif
	This.Oreset()

	If Type('goLog')='O'
		goLog.Log(tcSql,Program())
	Endif

	Local lnTip
	lnTip = 0

*!* 29.06.2007
*!* marius.mutu
*!* nu puneti upper(lcSql) - exista unele expresii in oracle care sunt case sensitive
	If Empty(tcSql)
		lcSql = This.cSql
	Else
		lcSql = tcSql
	Endif

	If Empty(tcCursor)
		lcCursor = This.cCursor
	Else
		lcCursor = tcCursor
	Endif

	If Empty(tnHandle)
		lnHandle = This.nHandle
	Else
		lnHandle = tnHandle
	Endif

&& DACA AM TRANZACTIE MANUALA NU FAC RECONNECT
	If SQLGetprop(lnHandle,"Transactions") = 2 && TRANZACTIE MANUALA
		This.lReconnect = .F.
	Else
		This.lReconnect = .T.
	Endif

	Do Case
	Case Pcount() < 6
		llQuitOnError = This.lQuitOnError
		llReconnect = This.lReconnect
		llShowError = This.lShowError
	Case Pcount() < 7
		llQuitOnError = This.lQuitOnError
		llReconnect = This.lReconnect
	Otherwise
		llShowError = tlShowError
		llReconnect = tlReconnect
		llQuitOnError = tlQuitOnError
	Endcase

	lnSucces = This.nSucces

	llProgress = tlProgress && IIF(tlProgress or 'SELECT'$lcSql,.T.,.F.)
	lcTitluProgress = Iif(Empty(tcTitluProgress),"",Alltrim(tcTitluProgress))

	Declare laEroare[1]
	lcEroare = ''


	lnTip = Iif('ROLLBACK'$lcSql Or 'COMMIT'$lcSql,1,0) && daca ROLLBACK SAU COMMIT TIP = 1, ALTFEL 0

	Do Case
	Case lnTip = 0
*!*					If llProgress
*!*						Local loTherm, lcTask, lnPercent, lnSeconds
*!*						If !Empty(lcTitluProgress)
*!*							lcTask =  lcTitluProgress
*!*						Else
*!*							lcTask = "Se executa ... "
*!*						Endif
*!*						loTherm = Newobject("_thermometer","_therm","",lcTask)

*!*						lnPercent = 15


*!*						loTherm.Show()
*!*					Endif

*!*					Do While .T.

*!*						If llProgress
*!*							lnPercent = lnPercent + 5
*!*							If lnPercent > 90
*!*								lnPercent = 15
*!*							Endif

*!*							loTherm.Update(lnPercent, lcTask+" "+Trans(lnPercent))
*!*						Endif


*!*						lnSucces = SQLExec(lnHandle,lcSql,lcCursor)
*!*						If lnSucces = 0
*!*	*
*!*						Else
*!*							Exit
*!*						Endif
*!*					Enddo

*!*					If llProgress
*!*						loTherm.Complete()
*!*						Release loTherm
*!*					Endif

		If llProgress
			Local loTherm, lcTask, lnPercent, lnSeconds
			If !Empty(lcTitluProgress)
				lcTask =  lcTitluProgress
			Else
				lcTask = "Se executa ... "
			Endif
			loTherm = Newobject("_thermometer","_therm","",lcTask)

			lnPercent = 15


			loTherm.Show()
		Endif

		lnSucces = -1
		Do While .T.
			Do While .T.

				If llProgress
					lnPercent = lnPercent + 5
					If lnPercent > 90
						lnPercent = 15
					Endif

					loTherm.Update(lnPercent, lcTask+" "+Trans(lnPercent))
				Endif


				lnSucces = SQLExec(lnHandle,lcSql,lcCursor)
				If lnSucces = 0
*
				Else
					Exit
				Endif
			Enddo

			If lnSucces > 0
				If Used(lcCursor)
					lcTempCursor =  Sys(2015)
					Use Dbf(lcCursor) In 0 Again Shared Alias (lcTempCursor)
					Use In (lcCursor)
					Use Dbf(lcTempCursor) In 0 Again Alias (lcCursor)
					Use In (lcTempCursor)
				Endif
				Exit
			Endif

			If lnSucces < 0
				Release laEroare
				Declare laEroare(1)
				lnEroare1 = 0
				lnEroare2 = 0
				lcTextEroare = []
				lnHandle = 0
				llEroare = .F.

				Aerror(laEroare)
				If Alen(laEroare) > 1
					lnEroare1 = laEroare[1]
					lnEroare2 = laEroare[5]
					lcTextEroare = laEroare[3]
					lnHandle = laEroare[6]
					llEroare = .T.

				Endif


				Do Case
				Case lnEroare1 <>1526 && eroare <> ODBC
					lcTextEroare = Program() + Chr(13) + Alltrim(Str(lnEroare1)) + ' ' + laEroare[2]
					If Type('goLog')='O'
						goLog.Log(lcTextEroare,Program())
					Endif
					If llShowError
						AMESSAGEBOX(lcTextEroare,0,"Eroare")
					Endif
					If llQuitOnError
						Quit
						Retry
					Else
						Exit
					Endif

				Case lnEroare1 = 1526 && eroare ODBC
					Do Case
					Case llReconnect And Inlist(lnEroare2, 12152, 3113, 3114, 12560, 4068, 28, 12) && 12512 = TNS: UNABLE TO SEND BREAK MESSAGE; 3114 = NOT CONNECTED TO ORACLE; 12560 = PROTOCOL ADAPTER ERROR
						If Type('goLog')='O'
							lcLog = laEroare(3) + Chr(13)
							goLog.Log(lcLog,Program())
						Endif

						Do While .T.
							lnRaspuns = AMESSAGEBOX('Eroare de conectare.' + Chr(13) + lcTextEroare + Chr(13) + 'Doriti reconectare?',4+32,'Eroare') && retry = 4; cancel = 2
							If lnRaspuns = 6

								lnHandle = goConn.Connect(goConn.cHost, goConn.cUser, goConn.cPassword, llReconnect)

*!*									gnHandle = SQLConnect(gcHost,gcUserName,gcPassword)

								If lnHandle < 0
									Declare laEroare2(1)
									Aerror(laEroare2)
									lcTextEroare = laEroare2(3)
									If Type('goLog')='O'
										goLog.Log(lcTextEroare,Program())
									Endif

									Release laEroare2
									Loop
								Else
*!*										goExecutor.nHandle = gnHandle
									Exit
								Endif
							Else
								Quit
								Retry
							Endif && lnRaspuns = 6
						Enddo && .T.
						Loop && daca am iesit cu un handle valid intru din nou in loop si fac cursorfill
					Otherwise
						lcTextEroare = Program() + Chr(13) + Alltrim(Str(lnEroare1)) + ' ' + Chr(13) + Transform(laEroare[2]) + Chr(13) + Transform(laEroare[3]) + Chr(13) + lcSql
						If llShowError
							lnRaspuns = AMESSAGEBOX('Eroare necunoscuta' + Chr(13) + lcTextEroare,0,'Eroare') && ok = 0
						Endif
						If Type('goLog')='O'
							goLog.Log(lcTextEroare,Program())
						Endif
						If llQuitOnError
							Quit
							Retry
						Else
							Exit
						Endif
					Endcase && INLIST(lnEroare2,12152,3114)
				Endcase
			Endif && lnSucces < 0

		Enddo && .T.

		If llProgress
			loTherm.Complete()
			Release loTherm
		Endif

	Case lnTip = 1
		If 'ROLLBACK'$lcSql
			lnSucces = Sqlrollback(lnHandle)
		Else
			lnSucces = Sqlcommit(lnHandle)
		Endif
	Endcase

	If lnSucces < 0
		Aerror(laEroare)

		If laEroare[1] <> 1526
			lcEroare = laEroare[2]
		Else
			lcEroare = Alltrim(Transform(laEroare[1])) + Chr(13) + Alltrim(Transform(laEroare[2]))  + Chr(13) + Alltrim(Transform(laEroare[3])) + Chr(13) + lcSql
		Endif

		If Type('goMyXMLHTTP') = 'O'
			lcLunaHTTP = Iif(Type('gnLuna') = 'N', Transform(gnLuna) + "/","") + Iif(Type('GNAN') = 'N', Transform(gnAn),"")
			lcErrorHTTP =  Sys(0) + ":" + Iif(Type('GCS')='C'," " + GCS,"") + ": " + lcLunaHTTP + Chr(13) +Chr(10) + lcEroare + ;
				CHR(13) + Chr(10) + Chr(13) + Chr(10) + GETCALLSTACK()

			lcUserName = gcUserNameApp
			lcProgram = Juststem(Sys(16,0))
			goMyXMLHTTP.postError(lcErrorHTTP, lcUserName, lcProgram)
		Endif

		If llShowError
			AMESSAGEBOX(lcEroare,0,"Eroare")
		Endif
		If llQuitOnError
			Quit
			Retry
		Endif

	Endif



	This.aEroare = laEroare
	This.nSucces = lnSucces
	This.cEroare = lcEroare
	This.nEroare = Iif(Alen(laEroare)>=5,laEroare[5],0)

	Return lnSucces

	Endproc
******************************************* SFARSIT: oExecute *******************************************

*!* salveaza rezultatul unei functii in variabila data ca referinta
*!* intoarce SUCCES = (1,-1)
*!* lnSucces = oFunction2Value("MyFunction(MyParam1, MyParam2)", @pnReturnValue)
	Function oFunction2Value
	Lparameters tcFunction, tuRetValue

	lcSql = "select " + tcFunction + " as retvalue from dual"
	lcCursor = Sys(2015)
	lcField = lcCursor + ".retvalue"

	lnSucces = This.oExecute(lcSql, lcCursor)

	If lnSucces > 0
		tuRetValue = Evaluate(lcField)
		If Used(lcCursor)
			Use In (lcCursor)
		Endif
	Endif

	Return lnSucces

	Endfunc && oFunction2Value
******************************************* SFARSIT: oFunction2Value *******************************************

*!* salveaza rezultatul unui select in variabila data ca referinta
*!* daca se intorc mai multe randuri - eroare
*!* intoarce SUCCES = (1,-1)
*!* lnSucces = oSelect2Value("Select sum(cantitate) from tabel where conditie", @pnReturnValue)
	Function oSelect2Value
	Lparameters tcSql, tuRetValue

	Local lcSelect, lcSql, lcCursor, lcField, lnSucces

	lcSelect = Select()
	lcSql = tcSql
	lcCursor = Sys(2015)

	lnSucces = This.oExecute(lcSql, lcCursor)

	If lnSucces > 0
		If Reccount(lcCursor) > 1
			This.nSucces = -1
			This.cEroare = 'Au rezultat mai multe valori. Se astepta o singura valoare.'
			lnSucces = -1
		Else
			lcField = lcCursor + '.' + Field(1)
			tuRetValue = Evaluate(lcField)
		Endif
		If Used(lcCursor)
			Use In (lcCursor)
		Endif
	Endif

	Select (lcSelect)

	Return lnSucces

	Endfunc &&oSelect2Value
******************************************* SFARSIT: oFunction2Value *******************************************

******************************************* INCEPUT: oPrelucrareEroare *******************************************
&&	Prelucreaza mesajul de eroare : daca este intre ORA-20000 si ORA-20999 atunci afiseaza doar textul erorii
	Function oPrelucrareEroare
	Local lcTextEroare
	lcTextEroare = This.cEroare

	If Like('*ORA-20???:*',lcTextEroare)
		lnPozi=At("ORA-20",lcTextEroare)+11
		lnPozf=At("ORA",lcTextEroare,2)
		lcTextEroare=Substr(lcTextEroare,lnPozi,lnPozf-lnPozi)
*!*					ELSE
*!*						lnPozf=At("ORA-",lcTextEroare,3)
*!*						lcTextEroare=Substr(lcTextEroare,1,lnPozf-1)+[...]
	Endif
	Return lcTextEroare
	Endfunc	&&	oPrelucrareEroare
******************************************* SFARSIT: oPrelucrareEroare *******************************************
* PROCEDURE oReset(  )
* Date : 06/10/2004, 12:21:06
* author : marius.mutu
* description:

****** PARAMETER BLOCK **************
* Parameters : 0
*
******************************************* INCEPUT:oReset *******************************************
	Procedure Oreset(  )
	With This
		.aEroare = .F.
		.nSucces = 0
		.cSql = ''
		.cCursor = ''
	Endwith
	Endproc
******************************************* SFARSIT: oReset *******************************************

Enddefine && oExecutor




*** oConn ===========================================================================================
Define Class oConn As Custom

	cHost = ''
	cUser = ''
	cPassword = ''
	nHandle = 0
	cEroare = ''
	Declare aEroare[7]
	lShowError = .F.
	lReconnect = .F. && Daca llReconnect = .T. se apeleaza InitSesiune din oInit_Optiuni.prg


*** Connect ===========================================================================================
	Procedure Connect
	Lparameters tcHost, tcUser, tcPassword, tlReconnect

*!* tlReconnect = .T. daca se apeleaza connect la reconectare (atunci se apeleaza si  InitSesiune())
	Local lnSucces, laEroare, lcString, lcHost, lcUser, lcPassword, lcSql

	If Pcount() < 3 Or Type('tcHost') # 'C' Or Type('tcUser') # 'C' Or Type('tcPassword') # 'C'
*
	Else
		This.cHost = tcHost
		This.cUser = tcUser
		This.cPassword = tcPassword
	Endif

	lcHost = This.cHost
	lcUser = This.cUser
	lcPassword = This.cPassword

	If Pcount() < 4 Or Type('tlReconnect') # 'L'
		llReconnect = This.lReconnect
	Else
		llReconnect = tlReconnect
	Endif

	SQLSetprop(0,"DispLogin",3)
	lcString="dsn="+Alltrim(lcHost)+";Uid="+Alltrim(lcUser)+";Pwd="+Alltrim(lcPassword)+";"

	This.nHandle = Sqlstringconnect(lcString)

	If Type('gnHandle') = 'N'
		gnHandle = This.nHandle
	Endif

	If Type('goExecutor') = 'O'
		goExecutor.nHandle = This.nHandle
	Endif

	If This.nHandle > 0
		lnSucces = 1

*** SETARI SESIUNE DUPA CONECTARE
		This.postConn()

		If llReconnect
			lnSucces = InitSesiune() && IN oInit_Optiuni.prg
		Endif
	Else
		lnSucces = -1
		This.ProcessError()
	Endif

	Return This.nHandle

	Endproc && Connect
*** END Connect ===========================================================================================

*** Disconnect ===========================================================================================
	Procedure Disconnect
	Lparameters tnHandle

	Local lnSucces, lnHandle

	lnHandle = Iif(Empty(tnHandle) Or Type('tnHandle') # 'N', 0 , tnHandle)

	lnSucces = SQLDisconnect(lnHandle)

	If lnSucces < 0
		This.ProcessError()
	Endif

	Return lnSucces

	Endproc &&
*** END Disconnect ===========================================================================================

*** ProcessError ===========================================================================================
	Procedure ProcessError

	Local laEroare, lnEroare1, lnEroare2, lcTextEroare, lcEroareConectare
	lcTextEroare = ''
	lcEroareConectare = ''
	Dimension laEroare[1]

	Aerror(laEroare)
	If Alen(laEroare) > 1
		lnEroare1 = laEroare[1]
		lnEroare2 = laEroare[5]
		lcTextEroare = laEroare[3]
		lnHandle = laEroare[6]
		llEroare = .T.

		lcTextEroare = 'Conectarea nu a reusit ' + Chr(13) + Chr(10) + Alltrim(Transform(laEroare[1])) + ' ' + Chr(13) + Transform(laEroare[2]) + Chr(13) + Transform(laEroare[3])
		This.cEroare = lcTextEroare
		This.aEroare = laEroare

		goLog.Log(lcTextEroare,Program())

		If laEroare[1]=1526 And Like('*ORA-20???:*',laEroare[2])
			lnPozi = At("ORA-20",laEroare[2])+11
			lnPozf = At("ORA",laEroare[2],3)
			lcEroareConectare = Substr(laEroare[2],lnPozi,lnPozf-lnPozi)
		Else
			lcEroareConectare = lcTextEroare
		Endif
		If Empty(lcEroareConectare)
			lcEroareConectare="Conectarea nu a reusit!"
		Endif

		AMESSAGEBOX(lcEroareConectare,0+48,"Atentie")
	Endif

	Return lcTextEroare

	Endproc && ProcessError
*** END ProcessError ===========================================================================================

*** postConn ===========================================================================================
	Procedure postConn
*** PUNCT ZECIMAL
	lcSql=[ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ".,"]
	lnSucces = goExecutor.oExecute(lcSql)
	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare,0+16,'Eroare')
	Endif

	Endproc && postConn
*** END postConn ===========================================================================================


Enddefine && oConn
*** END oConn ===========================================================================================



* PROCEDURE Get_Ora( tnTip )
* Date : 16/11/2004, 08:58:45
* author : marius.mutu
* description:

****** PARAMETER BLOCK **************
* Parameters : 1
* Parameter 1:
*
******************************************* INCEPUT:Get_Ora *******************************************
Procedure Get_Ora( tnTip )
* tnTip: 1 sau nimic = DATETIME ; 2 = CHARACTER

Local lcRetVal, lnSucces
Local lcCursor, lcSql, lcSelect
lcSelect = Select()

If Pcount() = 0 Or Type('tnTip') <> 'N'
	lnTip = 1
Else
	lnTip = tnTip
Endif

&&preluare ora de pe oracle server:
Store -1 To lnSucces
lcSql = [select to_char(SYSdate,'dd/mm/yyyy hh24:mi:ss') as dataora from dual]
lcCursor = [dataora_cursor]
lnSucces = goExecutor.oExecute(lcSql, lcCursor)
If lnSucces < 0
	AMESSAGEBOX(goExecutor.cEroare, 0+16, ,'Eroare')
	lcRetVal = Ttoc(Datetime())
Else
	Select dataora_cursor
	lcRetVal = dataora_cursor.dataora
	Use In dataora_cursor
Endif

If lnTip = 1
	lcRetVal = Ctot(lcRetVal)
Endif

If !Empty(lcSelect)
	Select (lcSelect)
Endif

Return lcRetVal
Endproc
******************************************* SFARSIT: Get_Ora *******************************************
*________________________________________________________

Function ULTIMAZI
Parameters tcAn, tcLuna

Local lcAn, lcLuna

If Empty(tcAn)
	lcAn  = pcAn
Else
	lcAn = Alltrim(tcAn)
Endif

If Empty(tcLuna)
	lcLuna = pcNl
Else
	lcLuna = Alltrim(tcLuna)
Endif

If Val(lcAn) = Year(Date()) And Val(lcLuna) = Month(Date())
	Return Date()
Endif

lcData = '01/'+ lcLuna + '/' + lcAn
ldData = Gomonth(Ctod(lcData),1) - 1

Return ldData

****************************************************************

Function get_nivel_upf(tnid_util,tnid_prog,tnid_firma)
Private pnid_util,pnid_prog,pnid_firma
pnid_util = tnid_util
pnid_prog= tnid_prog
pnid_firma = tnid_firma
Local lnnivel
lcSql = [select ud.id_nivel,n.nivel from contafin_oracle.util_drept ud ] + ;
	[join contafin_oracle.nivel n on ud.id_nivel = n.id_nivel ] + ;
	[where ud.id_util = ?pnid_util and ud.id_prog = ?pnid_prog and ] +;
	[ud.id_firma = ?pnid_firma]
lcCursor = [crsUtilNivel]
lnSucces = goExecutor.oExecute(lcSql,lcCursor)
If lnSucces < 0
	lcTitlu = [Eroare]
	lctip = [Avertizare]
	lcImagine = [exclam.ico]
	lcMesaj = goExecutor.cEroare
	ofrm_eroare = Createobject('frm_mesaj',lcTitlu,lcImagine,lctip,lcMesaj)
	ofrm_eroare.Show(1)
	Release ofrm_eroare
	Return
Endif
lnnivel = &lcCursor..nivel
Return lnnivel
Endfunc &&get_nivel_upf

*******************************************************************************************************

Function enumefis
Parameters tc_numefis
Private pn_len,pl_return,pc_numefis,pc_char
pn_len=0
pc_char=''
pl_return=.T.
pc_numefis=Alltrim(tc_numefis)
pn_len=Len(pc_numefis)
If pn_len=0
	pl_return=.F.
Endif
Do While pn_len>0
	pc_char=Substr(pc_numefis,pn_len,1)
	If !Between(Asc(pc_char),48,57) And !Between(Asc(pc_char),97,122) And !Between(Asc(pc_char),65,90) And Asc(pc_char)<> 95 And Asc(pc_char)<>46
		pl_return=.F.
		Exit
	Endif
	pn_len=pn_len-1
Enddo
Return pl_return
Endfunc && enumefis
***********************************************************************************************


*******************************************
* PROCEDURE ImportTable
* Date : 08/07/2005, 09:20:54
* author : marius.mutu
* description: intoarce numele unui cursor cu datele importate dintr-un dbf
*******************************************
Procedure ImportTable
Local lcCursor
lcCursor = ""
loimport = Newobject("frm_import","importdata")
loimport.Show(1)
If gnButon = 1
	lcCursor = "crsReturn"
Endif

Return lcCursor

Endproc
*----------------------------------sfarsit procedura ImportTable----------------------------------


Function Lista_Campuri
Lparameters tcAlias

Local lcSelect, i, lcAlias, lcLista
lcLista = []
lcSelect = Select()
lcAlias = tcAlias

Select (lcAlias)
lnFields = Fcount()
For i = 1 To lnFields
	lcField = Field(i)
	lcLista = lcLista + [,] + lcField
Endfor
If !Empty(lcLista)
	lcLista = Substr(lcLista,2)
Endif

Select (lcSelect)
Return lcLista

Endfunc && Lista_Campuri


***---------------------------------------------------------------------
Procedure OPEN_DEFAULT_APP
Parameters tcfilename

Declare Integer ShellExecute In shell32.Dll ;
	INTEGER hndWin, ;
	STRING cAction, ;
	STRING cFileName, ;
	STRING cParams, ;
	STRING cDir, ;
	INTEGER nShowWin
cFileName = tcfilename
cAction = "open"
ShellExecute(0,cAction,cFileName,"","",1)

Endproc && OPEN_DEFAULT_APP


***---------------------------------------------------------------------
Procedure GET_SCHEMA_GRID
Lparameters toGrid, tcColumnList, tcHeaderList, tcSchema, tlSelect, tnType, tcFrom, tcWhere, tcOrder, tcOutputName

Local lcSelect, llSelect, lcAlias, lcWhere, lcOrder, lcColumn, lcHeader
Local lnType, lcInto
&& tnType : 0 CURSOR, 1 TABLE, 2 ARRAY

If Type('tnType') # 'N'
	lnType = 0
Else
	If !Between(tnType,0,2)
		lnType = 0
	Else
		lnType = tnType
	Endif
Endif
Do Case
Case lnType = 0
	lcInto = ' INTO CURSOR '
Case lnType = 1
	lcInto = ' INTO TABLE '
Other lnType = 1
	lcInto = ' INTO ARRAY '
Endcase


tcColumnList = ''
tcHeaderList = ''
tcSchema = ''

lnNrCol = toGrid.ColumnCount
Dimension myArray[lnNrCol,3]

With toGrid
	For lnCol = 1 To .ColumnCount
		lnColumn = .Columns(lnCol).ColumnOrder
		lcColumn = .Columns(lnCol).ControlSource
		llVisible = .Columns(lnCol).Visible
		lnWidth = .Columns(lnCol).Width
		If !llVisible Or lnWidth = 0 Or Empty(Alltrim(lcColumn))
			Adel(myArray,lnCol)
			Loop
		Endif
		lnPos = At('.',lcColumn)
		If lnPos > 0
			lcColumn = Substr(lcColumn, lnPos + 1)
		Endif
*tcColumnList = tcColumnList + lcColumn + ','
		myArray[lnCol,1] = lnColumn

		For lnobjcol = 1 To .Columns(lnCol).Objects.Count
			If Upper(.Columns(lnCol).Objects(lnobjcol).BaseClass)='HEADER'
				lcHeader = .Columns(lnCol).Objects(lnobjcol).Caption
				lcHeader = Strtran(Strtran(Strtran(Strtran(Strtran(Strtran(Strtran(Strtran(Strtran(lcHeader,Chr(32),'_'),'.','_'),'/','_'),'\','_'),"&","_"),"%",""),"(","_"),")","_"),"-","_")
*tcHeaderList = tcHeaderList + lcHeader + ','
*tcSchema = tcSchema + lcColumn + [ as ] + lcHeader + [,]
				myArray[lnCol,2] = lcColumn
				myArray[lnCol,3] = lcHeader
				Exit
			Endif
		Endfor
	Endfor
*!*		tcColumnList = Substr(tcColumnList, 1, Len(tcColumnList)-1)
*!*		tcHeaderList = Substr(tcHeaderList , 1, Len(tcHeaderList)-1)
*!*		tcSchema = Substr(tcSchema , 1, Len(tcSchema)-1)
Endwith
For i = 1 To Alen(myArray,1)
	l1 = myArray[i,1]
	If Type('l1') # 'N'
		myArray[i,1] = -1
	Endif
Endfor

Asort(myArray)
For i = 1 To Alen(myArray,1)
	If myArray[i,1] <> -1
		tcColumnList = tcColumnList + Alltrim(myArray[i,2]) + [,]
		tcHeaderList = tcHeaderList + Alltrim(myArray[i,3]) + [,]
		tcSchema = tcSchema + Alltrim(myArray[i,2]) + [ as ] + Alltrim(myArray[i,3]) + [,]
	Endif
Endfor

tcColumnList = Substr(tcColumnList, 1, Len(tcColumnList)-1)
tcHeaderList = Substr(tcHeaderList , 1, Len(tcHeaderList)-1)
tcSchema = Substr(tcSchema , 1, Len(tcSchema)-1)


If tlSelect
	tcSchema = 'SELECT ' + tcSchema
Endif
If !Empty(tcFrom)
	tcSchema = tcSchema + ' FROM ' + Alltrim(tcFrom)
Endif
If !Empty(tcWhere)
	tcSchema = tcSchema + ' WHERE ' + Alltrim(tcWhere)
Endif

If !Empty(tcOrder)
	tcSchema = tcSchema + ' ORDER BY ' + Alltrim(tcOrder)
Endif

If !Empty(tcOutputName)
	tcSchema = tcSchema + lcInto + tcOutputName
Endif

Endproc && GET_SCHEMA_GRID

***---------------------------------
Procedure amessage
Lparameters tcMessage, tnDialogBoxType, tcTitleBarText, tnTimeOut
Local lnResponse
lnResponse = 0
lcMessage = Iif(Empty(tcMessage),[],tcMessage)
lnDialogBoxType = Iif(Empty(tnDialogBoxType),0,tnDialogBoxType)
lcTitleBarText = Iif(Empty(tcTitleBarText),[],tcTitleBarText)
lnTimeOut = Iif(Empty(tnTimeOut),0,tnTimeOut)
If lnTimeOut # 0
	lnResponse = AMESSAGEBOX(lcMessage,lnDialogBoxType,lcTitleBarText,lnTimeOut)
Else
	lnResponse = AMESSAGEBOX(lcMessage,lnDialogBoxType,lcTitleBarText)
Endif

Return lnResponse

Endproc && amessage
***---------------------------------

***---------------------------------
Function AMESSAGEBOX
Lparameters tcMessage, tnDialogBoxType, tcTitle, tcFont, tnTimeOut ,tnTimeoutValue

Local loMessage, lnReturn, lcMessageboxForm

*!*		*!* LOGHEZ ERORILE
*!*		IF TYPE('goLog') = 'O' AND 'ERROR'$UPPER(tcMessage) OR 'EROARE'$UPPER(tcMessage) OR 'ORA-'$UPPER(tcMessage)
*!*			goLog.LOG(tcMessage,PROGRAM())
*!*		ENDIF
If Type('gcNumeProgram') = 'C' And gcNumeProgram = 'ROASTART'
	lcMessageboxForm = "messagebox_form_desktop" && desktop .T.
Else
	lcMessageboxForm = "messagebox_form"
Endif
If !'MESSAGEBOX'$Upper(Set("Classlib"))
	If Type('lnTimeOut') = 'N' And lnTimeOut # 0
		lnReturn = Messagebox(tcMessage, tnDialogBoxType, tcTitle, tnTimeOut)
	Else
		lnReturn = Messagebox(tcMessage, tnDialogBoxType, tcTitle)
	Endif
Else
	loMessage = Newobject(lcMessageboxForm, "MessageBox.vcx", "", tcMessage, tnDialogBoxType, tcTitle, tcFont, tnTimeOut ,tnTimeoutValue)
	loMessage.AlwaysOnTop = .T.
	loMessage.Show(1)
	lnReturn = loMessage.IDOpcion
Endif


Return lnReturn

Endfunc && amessagebox
***---------------------------------

Procedure export_xls
Lparameters tcAlias,tcNumeFisier

If Empty(tcNumeFisier)
	tcNumeFisier = 'Foaie_Excel'
Endif

Local lcSelect
lcSelect = Select()

If Used(tcAlias)
	lcDir = Addbs(gcTempPath)

	lcFile = Putfile('Nume fisier:', tcNumeFisier , 'XLS')
	If Empty(lcFile)  && Esc pressed
		Return
	Endif


	Select (tcAlias)
	Export To (lcFile) Type Xl5
	Select (lcSelect)

	OPEN_DEFAULT_APP(lcFile)

Endif
Endproc && export_xls

*__________________________________________________________

&& Folosesc un tabel <ids> (tabel,id) cu cate o linie pt fiecare tabel
&& aflu id-ul urmator si il scriu in tabela <ids>
&& returnez id-ul
&& EX1: LNEW_ID=NEW_ID("GRILA_SAL") --> urmatorul id din <grila_sal> fara cautare in tabela originala
&& EX2: LNEW_ID=NEW_ID("GRILA_SAL","ID") --> urmatorul id din <grila_sal> cu cautare in tabela originala dupa campul<id>
&& ex3: LNEW_ID=NEW_ID("GRILA_SAL","ID",.T.) --> .T. INSEAMNA CA TABELUL ORIGINAL ESTE INDEXAT DUPA <ID> FAC SEEK IN LOC DE LOCATE
Procedure NEW_ID
Parameters TALIAS,TFIELD,TTAG
*WAIT WINDOW TALIAS
*ON error Errorh(ERROR(),PROGRAM(),LINENO())
LLLOOKUP=Iif(Type("tfield")="C",.T.,.F.)
LLTAG=Iif(Type("TTAG")="C",.T.,.F.)
TALIAS=Upper(Alltrim(TALIAS))


*** Save Stats
LCOLDALIAS = Alias()			       && keep current work area
LNOLDRECNO = Iif(!Eof(),Recno(),0)       && save record number

LCSETDEL=Set("deleted")
&& lnmaxval = (10^pcidsize)-1			   && wrap around after this val

***
&& PUN ORDINEA PE ID
If LLLOOKUP And LLTAG
	Sele (TALIAS)
	Set Order To &TTAG
Endif
***
LCNEWID = 0						   && our return result - NULL if failed
Select IDS
Locate For Upper(Alltrim(TABEL))=TALIAS
If !Found()
	If Flock()
		Append Blank
		Replace TABEL With TALIAS
		Unlock
	Endif

Endif

Set Deleted Off
&& acum sunt pe inregistrarea corecta


*** lock counter table and update counter
Select IDS
If Rlock()
*** Avoid use of Macros - Convert to mem var & update it
	LNCOUNTERVAL = NEW_ID

*** VERIFY ID NUMBER - search 'til no match
	Do While .T.
*** increase the counter - update field and var
		LNCOUNTERVAL = LNCOUNTERVAL+1

*!*	      *** check for wraparound
*!*	      IF lncounterval > lnmaxval
*!*	         lncounterval = 1
*!*	      ENDIF

		Select (TALIAS)
		If LLLOOKUP
			If LLTAG
				LCAUT="SEEK "+Allt(Str(LNCOUNTERVAL))
			Else
				LCAUT="LOCATE FOR "+Allt(TFIELD)+"="+Allt(Str(LNCOUNTERVAL))
*** now see if it exists
				&LCAUT
*					LOCATE FOR &TFIELD=LNCOUNTERVAL
				If !Found()
*** No match - DONE
					Exit
				Endif && !found()
			Endif && lltag
		Else
			Exit
		Endif && lllokup

	Enddo								&& done

	Sele IDS
	Replace NEW_ID With LNCOUNTERVAL
	LCNEWID=LNCOUNTERVAL

	Unlock In IDS
Endif									&& rlock()

*** Reset record number on original file

If !Empty(LCOLDALIAS)
	Sele (LCOLDALIAS)
	If LNOLDRECNO#0
		Goto LNOLDRECNO
	Endif
Endif
Set Deleted &LCSETDEL

Return LCNEWID

Endproc && NEW_ID


***-------------------------------------------------------------------------------------------------------

* Foloseste comment de la coloane si tooltiptext de la grid pt a salva recordsource si controlsource din grid inainte de reconstructie
Procedure SAVE_GRID
Param toGrid
*wait wind 'save_grid'
Private pogrid
If Param()=0 Or Type('togrid')!="O"
	Return .F.
Endif

pogrid=toGrid

* remember control sources in the column's comment field
With pogrid
	Local nColumnIndex
	For m.nColumnIndex = 1 To .ColumnCount
		.Columns(m.nColumnIndex).Tag = .Columns(m.nColumnIndex).ControlSource
	Endfor
	.ToolTipText=.RecordSource
	.RecordSource=""
Endwith

Return .T.
Endproc && SAVE_GRID
***--------------------------------------------------------------
Procedure RESTORE_GRID
Param toGrid

*wait wind 'restore_grid'
Private pogrid
If Param()=0 Or Type('togrid')!="O"
	Return .F.
Endif

pogrid=toGrid


With pogrid
* restore record source
	.RecordSource = .ToolTipText
* restore control sources
	For m.nColumnIndex = 1 To .ColumnCount
		.Columns(m.nColumnIndex).ControlSource = .Columns(m.nColumnIndex).Tag
	Endfor
	.ToolTipText=""
Endwith
Return .T.
Endproc && RESTORE_GRID

******

* Foloseste comment de la coloane si tooltiptext de la grid pt a salva recordsource si controlsource din grid inainte de reconstructie
Procedure SAVE_GRID_COMMENT
Param toGrid
*wait wind 'save_grid'
Private pogrid
If Param()=0 Or Type('togrid')!="O"
	Return .F.
Endif

pogrid=toGrid

* remember control sources in the column's comment field
With pogrid
	Local nColumnIndex
	For m.nColumnIndex = 1 To .ColumnCount
		.Columns(m.nColumnIndex).Comment = .Columns(m.nColumnIndex).ControlSource
	Endfor
	.ToolTipText=.RecordSource
	.RecordSource=""
Endwith

Return .T.
Endproc && SAVE_GRID_COMMENT
***--------------------------------------------------------------
Procedure RESTORE_GRID_COMMENT
Param toGrid

*wait wind 'restore_grid'
Private pogrid
If Param()=0 Or Type('togrid')!="O"
	Return .F.
Endif

pogrid=toGrid


With pogrid
* restore record source
	.RecordSource = .ToolTipText
* restore control sources
	For m.nColumnIndex = 1 To .ColumnCount
		.Columns(m.nColumnIndex).ControlSource = .Columns(m.nColumnIndex).Comment
	Endfor
	.ToolTipText=""
Endwith
Return .T.
Endproc && RESTORE_GRID_COMMENT


* Foloseste comment de la coloane si tooltiptext de la grid pt a salva recordsource si controlsource din grid inainte de reconstructie
Procedure SAVE_GRID_TAG
Param toGrid
*wait wind 'save_grid'
Private pogrid
If Param()=0 Or Type('togrid')!="O"
	Return .F.
Endif

pogrid=toGrid

* remember control sources in the column's comment field
With pogrid
	Local nColumnIndex
	For m.nColumnIndex = 1 To .ColumnCount
		.Columns(m.nColumnIndex).Tag = .Columns(m.nColumnIndex).ControlSource
	Endfor
	.ToolTipText=.RecordSource
	.RecordSource=""
Endwith

Return .T.
Endproc && SAVE_GRID_TAG
***--------------------------------------------------------------
Procedure RESTORE_GRID_TAG
Param toGrid

*wait wind 'restore_grid'
Private pogrid
If Param()=0 Or Type('togrid')!="O"
	Return .F.
Endif

pogrid=toGrid


With pogrid
* restore record source
	.RecordSource = .ToolTipText
* restore control sources
	For m.nColumnIndex = 1 To .ColumnCount
		.Columns(m.nColumnIndex).ControlSource = .Columns(m.nColumnIndex).Tag
	Endfor
	.ToolTipText=""
Endwith
Return .T.
Endproc && RESTORE_GRID_TAG


*-------------------------------------------
* Function...: Xmenu
* Author.....: MARTIN
* Date.......: 04/06/1997
* Notes......: Based on an idea from Steve Zimmelman for FoxPro 2.x
* Parameters.: tcItems = Semicolon-separated String with the various options
* ...........: tnBar   = Initially selected item (default=1)
* Returns....: Selected item number
* See Also...: PROMPT() [FoxPro Native]
*
Procedure XMENU
Lparameters TCITEMS, TNBAR

Local NITEMCOUNT, AITEMS, X, NROW, NCOL, CTITLE, NLASTPOS, CCOLOR, AITEMS

Private CPOPMENU, NSELECT	&& They flow into the GetChoice internal procedure

If Pcount() < 2
	TNBAR = 1
Endif

Activate Screen

* Parse every item
*
m.NITEMCOUNT = Occurs( ';', TCITEMS ) + 1
Dimen AITEMS[ m.nItemCount ]
m.NLASTPOS = 1

For m.X = 1 To m.NITEMCOUNT

	If m.X < m.NITEMCOUNT

		AITEMS[ m.x ] = Subs( m.TCITEMS, m.NLASTPOS, ;
			( At( ';', m.TCITEMS, m.X ) - 1 ) - m.NLASTPOS + 1 )
	Else
		AITEMS[ m.x ] = Subs( m.TCITEMS, m.NLASTPOS, ;
			( Len( m.TCITEMS ) - m.NLASTPOS ) + 1 )
	Endif

	If AITEMS[ m.x ] # "\-"

		AITEMS[ m.x ] = Allt( AITEMS[ m.x ] )
	Endif

	m.NLASTPOS=At( ';', m.TCITEMS, m.X ) + 1
Next

* Calculates the mouse pointer position
*
m.NROW = Iif( Mrow() + m.NITEMCOUNT < Srow(), Mrow() - 1, Srow() - m.NITEMCOUNT )
m.NCOL = Iif( Mcol() + 10 < Scol(), Mcol() - 3, Mcol() - 13 )

* Gets an unique name for the pop-up
*
m.CPOPMENU = 'M' + Sys(3) + "_"

Define Popup ( m.CPOPMENU ) SHORTCUT Relative From NROW, NCOL

For m.X = 1 To m.NITEMCOUNT

	Define Bar m.X Of ( m.CPOPMENU ) Prompt AITEMS[ m.x ]
Next

m.CANS = ""
m.NSELECT = 0
Clear Type

On Selection Popup ( m.CPOPMENU ) Do GETCHOICE

Activate Popup ( m.CPOPMENU ) Bar TNBAR

Pop Key
Release Popup ( m.CPOPMENU )

Return Iif( Lastkey()=27, 0, m.NSELECT )

Endproc && XMENU

*--------------------
Procedure GETCHOICE

m.NSELECT = Bar()

Deactivate Popup ( m.CPOPMENU )

Return
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& MENIU &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Procedure lista2array
Parameters tcLISTA,taArray,tcSeparator
&& tcLista este un sir de caractere care contine elementele separate prin <;> default
&& tarray este vectorul care se completeaza - trebuie dat prin referinta
&& tcSeparator separatorul de elemente din tcLista - default este ";" - este optional
&& intoarce numarul de elemente gasite

&& ex: lnNr = lista2array("ana;are;mere",@alista,";")
External Array taArray
Local lcLista,lcSeparator,lnNRF,lcF1,i

lnNRF = 0

lcLista=Upper(Allt(tcLISTA))
If Parameters()<3 Or Empty(tcSeparator)
	lcSeparator=";"
Else
	lcSeparator=Alltrim(tcSeparator)
Endif

If Right(lcLista,1)!=lcSeparator
	lcLista=lcLista+lcSeparator
Endif

lnNRF=Occurs(lcSeparator,lcLista)

If lnNRF>0
	Dimension taArray[lnNrf,1]

	For i=1 To lnNRF
		lcF1=Left(lcLista,At(lcSeparator,lcLista)-1)

		If i!=lnNRF
			lcLista=Substr(lcLista,At(lcSeparator,lcLista)+1)
		Endif

		taArray[i]=lcF1
	Endfor
Else
	lnNRF = 0
Endif

Return lnNRF

Endproc && lista2array


***-------------------------------------------------------------------------------------------
Procedure get_mask
Parameters tnint, tndec

Local lnint, lndec
lnint = tnint
lndec = tndec
lnrest = Mod(lnint,3)

lcString = Replicate("9",lnrest)
lnint_ramas = lnint - lnrest
Do While lnint_ramas > 0
	lcString = lcString + " "+ Replicate("9",3)
	lnint_ramas = lnint_ramas - 3
Enddo
If lndec > 0
	lcString = lcString +"."+Replicate("9",tndec)
Endif

Return lcString

Endproc && get_mask
***-----------------------------------------------------------


*******************************************************************
* PROCEDURE Get_Version(  )
* Date : 17/11/2004, 16:34:20
* author : marius.mutu
* description:

****** PARAMETER BLOCK **************
* Parameters : 0
*
******************************************* INCEPUT:Get_Version *******************************************
Procedure Get_Version(tlNoRevision,tlInfo,tcfilename)
Local laVersion,lcVersion,lcFileName

*-- Get Version Information
*-- Added 4-1-98 BDC
Local lcVersionText, lcFileName,llNoRevision,llInfo

Dimension aVersion(12)

If Empty(tcfilename)
	lcFileName = Sys(16,0)
Else
	lcFileName = tcfilename
Endif
llNoRevision = tlNoRevision
llInfo = tlInfo



*** EGL: 2002.1.2 17:06 -  switched to AGETFILEVERSION().
If Val(Substr(Version(), 15)) >= 6
* The AGETFILEVERSION() function was introduced in VFP 6

*!*			DECLARE STRING GetCommandLine IN Kernel32
*!*			lcFileName = GetCommandLine()
	lcVersionText = ""

*!*	IF GetFileVersion(&lcFileName,@aVersion) = 0
	If Agetfileversion(aVersion, lcFileName) > 0
		If !llInfo
* daca vreau doar numarul versiunii
			lcVersion = Allt(aVersion(4))
			If llNoRevision
* daca nu vreau si revizia
				lnPos = Rat('.',lcVersion,1)
			Else
				lnPos = Len(lcVersion)
			Endif
			lcVersionText = Left(lcVersion,lnPos)
		Else
* vreau toata informatia despre fisier
			If Not Empty(aVersion(1))
				lcVersionText = Allt(aVersion(1))
			Endif

			If Not Empty(aVersion(2))
				lcVersionText = lcVersionText+Chr(10)+"Produs de: "+ Allt(aVersion(2))
			Endif

			If Not Empty(aVersion(3))
				lcVersionText = lcVersionText+Chr(10)+"Descriere: "+ Allt(aVersion(3))
			Endif

			If Not Empty(aVersion(4))
				lcVersionText = lcVersionText+Chr(10)+"Versiune fisier: "+ Allt(aVersion(4))
			Endif

			If Not Empty(aVersion(5))
				lcVersionText = lcVersionText+Chr(10)+"Nume intern: "+ Allt(aVersion(5))
			Endif

			If Not Empty(aVersion(6))
				lcVersionText = lcVersionText+Chr(10)+"Copyright: "+ Allt(aVersion(6))
			Endif

			If Not Empty(aVersion(7))
				lcVersionText = lcVersionText+Chr(10)+"Marca inregistrata: "+ Allt(aVersion(7))
			Endif

			If Not Empty(aVersion(8))
				lcVersionText = lcVersionText+Chr(10)+"Nume fisier: "+ Allt(aVersion(8))
			Endif

			If Not Empty(aVersion(9))
				lcVersionText = lcVersionText+Chr(10)+"Private Build: "+ Allt(aVersion(9))
			Endif

			If Not Empty(aVersion(10))
				lcVersionText = lcVersionText+Chr(10)+"Nume produs: "+ Allt(aVersion(10))
			Endif

			If Not Empty(aVersion(11))
				lcVersionText = lcVersionText+Chr(10)+"Versiune produs: "+ Allt(aVersion(11))
			Endif

			If Not Empty(aVersion(12))
				lcVersionText = lcVersionText+Chr(10)+"Special Build: "+ Allt(aVersion(12))
			Endif

			If Empty(lcVersionText)
				lcVersionText = "Versiune necunoscuta."
			Endif
		Endif
	Else

		lcVersionText = "Versiune necunoscuta."

	Endif

Else
	lcVersionText = "Versiune necunoscuta."
Endif
Return lcVersionText

Endproc
******************************************* SFARSIT: Get_Version *******************************************


* PROCEDURE Get_Hexa( tnDeca )
* Date : 18/11/2004, 17:56:48
* author : marius.mutu
* description: transforma un Deca in Hexa

****** PARAMETER BLOCK **************
* Parameters : 1
* Parameter 1: Numarul in Deca
*
******************************************* INCEPUT:Get_Hexa *******************************************
Procedure Get_Hexa( tnDeca )
Local laHexa,lnHexa,lnDeca


If Empty(tnDeca)
	lnDeca = 0
Else
	lnDeca = tnDeca
Endif

Dimension laHexa[16]
laHexa[1] = '0'
laHexa[2] = '1'
laHexa[3] = '2'
laHexa[4] = '3'
laHexa[5] = '4'
laHexa[6] = '5'
laHexa[7] = '6'
laHexa[8] = '7'
laHexa[9] = '8'
laHexa[10] = '9'
laHexa[11] = 'A'
laHexa[12] = 'B'
laHexa[13] = 'C'
laHexa[14] = 'D'
laHexa[15] = 'E'
laHexa[16] = 'F'

lnHexa = ''

Do While lnDeca > 0
	lnrest = Mod(lnDeca,16)
	lcHexa = laHexa[lnRest+1]
	lnDeca = Int(lnDeca/16)

	lnHexa = lcHexa + lnHexa
	lnrest = Mod(lnDeca,16)

Enddo

Return lnHexa

Endproc
******************************************* SFARSIT: Get_Hexa *******************************************
&& completeaza cu spatii si CRLF un mesaj a.i. pe fiecare linie sa fie lnLength caractere
Function format_msg
Parameters tcErrMsg,tnLength
Local lnLength,lcLinie,lcMesaj,lnPoz,lnCate,i,j
lcMesaj=""
If Empty(tnLength)
	lnLength=50			&& numarul de caractere pe linie
Else
	lnLength=tnLength
Endif
i=1
If At(Chr(13)+Chr(10),tcErrMsg,i)>0
	lnCate=At(Chr(13)+Chr(10),tcErrMsg,i)+1
	i=i+1
Else
	lnCate=Min(lnLength,Rat(' ',Substr(tcErrMsg,1,lnLength))-1)
Endif
lnPoz=1
*!*	lcLinie=Substr(tcErrMsg,1,lnCate)

Do While lnPoz<Len(tcErrMsg)
	lcLinie=Substr(tcErrMsg,lnPoz,lnCate)

	If Right(lcLinie,2)=Chr(13)+Chr(10)
		lcLinie=Alltrim(Substr(lcLinie,1,Len(lcLinie)-2))
	Else
		lcLinie=Alltrim(lcLinie)
	Endif

	j=Int((lnLength-Len(lcLinie))/2)
	lcLinie=Iif(!Empty(lcLinie),Space(j)+lcLinie+Space(j),"")
	lcMesaj=lcMesaj+lcLinie+Chr(13)+Chr(10)

	lnPoz=lnPoz+lnCate

	If At(Chr(13)+Chr(10),tcErrMsg,i)>0
		lnCate=At(Chr(13)+Chr(10),tcErrMsg,i)+2-lnPoz
		i=i+1
	Else
		lcNextChar=Substr(tcErrMsg,lnPoz+lnLength,1)
		lcLinieNoua=Substr(tcErrMsg,lnPoz,lnLength)
		If lcNextChar!=' ' And Len(lcLinieNoua)>=lnLength
			lnCate=Min(lnLength,Rat(' ',lcLinieNoua)-1)
		Else
			lnCate=lnLength
		Endif
	Endif
Enddo
Return lcMesaj
Endfunc		&& format_msg
***---------------------------------------------------------------------------------------------
Procedure C_LUNA
Parameters tnnrluna
Do Case
Case tnnrluna=1
	Return "IANUARIE"
Case tnnrluna=2
	Return "FEBRUARIE"
Case tnnrluna=3
	Return "MARTIE"
Case tnnrluna=4
	Return "APRILIE"
Case tnnrluna=5
	Return "MAI"
Case tnnrluna=6
	Return "IUNIE"
Case tnnrluna=7
	Return "IULIE"
Case tnnrluna=8
	Return "AUGUST"
Case tnnrluna=9
	Return "SEPTEMBRIE"
Case tnnrluna=10
	Return "OCTOMBRIE"
Case tnnrluna=11
	Return "NOIEMBRIE"
Case tnnrluna=12
	Return "DECEMBRIE"
Otherwise
	Return ""
Endcase
Endproc &&c_luna
***--------------------------------------------------------------------------------------
***--------------------------------------------------------------------------------------
Procedure CLUNA3
Parameters tnnrluna
Do Case
Case tnnrluna=1
	Return "Ian"
Case tnnrluna=2
	Return "Feb"
Case tnnrluna=3
	Return "Mar"
Case tnnrluna=4
	Return "Apr"
Case tnnrluna=5
	Return "Mai"
Case tnnrluna=6
	Return "Iun"
Case tnnrluna=7
	Return "Iul"
Case tnnrluna=8
	Return "Aug"
Case tnnrluna=9
	Return "Sep"
Case tnnrluna=10
	Return "Oct"
Case tnnrluna=11
	Return "Noi"
Case tnnrluna=12
	Return "Dec"
Otherwise
	Return Space(3)
Endcase
Endproc &&cluna3
***--------------------------------------------------------------------------------------
***------------------------------------------------------------------------------------
Procedure cluna
Parameters tcGrup,tcTipCumul,tcAn

lcTipCumul=Upper(Alltrim(tcTipCumul))
lcAn=Alltrim(tcAn)
lcgrup=Alltrim(tcGrup)
lnGrup=Val(lcgrup)
Do Case
Case lcTipCumul="T"
	lcret="Trim. "+lcgrup+" "+lcAn
Case lcTipCumul="S"
	lcret="Sem. "+lcgrup+" "+lcAn
Case lcTipCumul="A"
	lcret="Anul "+lcAn
Otherwise
	Do Case
	Case lnGrup=1
		lcret="Ian "+lcAn
	Case lnGrup=2
		lcret="Feb "+lcAn
	Case lnGrup=3
		lcret="Mar "+lcAn
	Case lnGrup=4
		lcret="Apr "+lcAn
	Case lnGrup=5
		lcret="Mai "+lcAn
	Case lnGrup=6
		lcret="Iun "+lcAn
	Case lnGrup=7
		lcret="Iul "+lcAn
	Case lnGrup=8
		lcret="Aug "+lcAn
	Case lnGrup=9
		lcret="Sep "+lcAn
	Case lnGrup=10
		lcret="Oct "+lcAn
	Case lnGrup=11
		lcret="Noi "+lcAn
	Case lnGrup=12
		lcret="Dec "+lcAn
	Otherwise
		lcret=lcAn
	Endcase
Endcase
Return lcret
Endproc &&cluna
***------------------------------------------------------------------------------------
***------------------------------------------------------------------------------------
Procedure get_trimestru
Parameters tnNrTrim
Do Case
Case tnNrTrim = 1
	Return "Trim. I"
Case tnNrTrim = 2
	Return "Trim. II"
Case tnNrTrim = 3
	Return "Trim. III"
Case tnNrTrim = 4
	Return "Trim. IV"
Otherwise
	Return Space(7)
Endcase
Endproc && get_trimestru
***--------------------------------------------------------------------------------------
Procedure get_semestru
Parameters tnNrSem
Do Case
Case tnNrSem = 1
	Return "Sem. I"
Case tnNrSem = 2
	Return "Sem. II"
Otherwise
	Return Space(7)
Endcase
Endproc && get_semestru
***--------------------------------------------------------------------------------------
Function Lista_Campuri
Lparameters tcAlias

Local lcSelect, i, lcAlias, lcLista
lcLista = []
lcSelect = Select()
lcAlias = tcAlias

Select (lcAlias)
lnFields = Fcount()
For i = 1 To lnFields
	lcField = Field(i)
	lcLista = lcLista + [,] + lcField
Endfor
If !Empty(lcLista)
	lcLista = Substr(lcLista,2)
Endif

Select (lcSelect)
Return lcLista

Endfunc && Lista_Campuri
***----------------------------------------

Procedure NRORD
Parameters ALI
Sele &ALI
A=Reccount()
If A=0
	Return
Endif
If A>65000
	Return 0
Endif
Declare NROR(A)
K=0
Scan
	K=K+1
	NROR(K)=Recno()
Endscan
Return

********************
Function NRCRT
NR=Ascan(NROR,Recno())
Return NR
**********************

***----------------------------------------
Function caps_first
Lparameters tcMesaj
Local lcMesaj
If !Empty(tcMesaj) And Len(tcMesaj)>1
	lcMesaj=Upper(Substr(tcMesaj,1,1))+Strtran(Lower(Substr(tcMesaj,2)),[oracle],[Oracle])
Else
	lcMesaj=Upper(tcMesaj)
Endif
Return lcMesaj
Endfunc	&&	caps_first
***----------------------------------------

*!*	FUNCTION ultima_zi_din_luna
*!*	PARAMETERS tcAnul, tcLuna
*!*
*!*	LOCAL ldData
*!*	ldData = DATE(VAL(tcAnul),VAL(tcLuna), 1)
*!*	ldData = GOMONTH(ldData,1)
*!*	ldData = DATE(YEAR(ldData),MONTH(ldData), 1) - 1
*!*	RETURN ldData
*!*	ENDFUNC

Function ultima_zi_din_luna
Parameters tcAnul, tcLuna

Local ldData, lcAnul, lcLuna

If Type('tcAnul') = 'N'
	lcAnul = Transform(tcAnul)
Else
	lcAnul = tcAnul
Endif
If Type('tcLuna') = 'N'
	lcLuna = Transform(tcLuna)
Else
	lcLuna = tcLuna
Endif

ldData = Date(Val(lcAnul),Val(lcLuna), 1)
ldData = Gomonth(ldData,1)
ldData = Date(Year(ldData),Month(ldData), 1) - 1
Return ldData
Endfunc



******************************************************************************

Procedure viz_prg_instalat
If Used('v_programe_instalate')
	Use In v_programe_instalate
Endif
*!*	lcSql = [select * from vdef_util_programe where id_util=]+Alltrim(Str(gnIdUtil))+;
*!*		[ order by ordine]
lcSql = [{call contafin_oracle.pack_drepturi.programe_utilizator(]+Alltrim(Str(gnIdUtil))+[)}]
lcCursor = [v_programe_instalate]
lnSucces = goExecutor.oExecute(lcSql,lcCursor)
goExecutor.Oreset()

Endproc
******************************************************************************
Procedure lansare_toolbar

Do viz_prg_instalat In oproceduri_comune.prg

If Used('v_programe_instalate') And Reccount('v_programe_instalate') > 0

	otool = Createobject('toolset')

	With otool.tool1
		If Used('v_programe_favorite')
			Use In v_programe_favorite
		Endif
		Select * From v_programe_instalate Where favorit=1 Order By ordine_favorit Into Cursor v_programe_favorite
		Select v_programe_favorite
		Scan

			If Type('gcappname')='C'
				If gcappname=Upper(Alltrim(nume))
					Loop
				Endif
			Endif

			lnParametru_prog = parametru_prog && pt. programul de Contracte - clienti si furnizori
			lcParametru_prog = Alltrim(Str(Nvl(lnParametru_prog,0)))

			lnIdProgram=id_program
			lcIdProgram=Alltrim(Str(lnIdProgram))
			lcNumeProgram=Proper(Alltrim(explicatie))

			lcImagine=Upper(Alltrim(nume))+".png"				&&nume poza

			lcCaleImagine=gcappPath+'grafice\'+lcImagine		&&cale imagine
			If !File(lcCaleImagine)
				lcImagine = 'na.png'
				lcCaleImagine=gcappPath+'grafice\na.png'
			Endif
			lnIdGrupProg=id_grup_prog
			lnIdGrupProgFav=0
			lcCaleProgram = dirgen+Iif(Empty(Director),Juststem(nume),Alltrim(Director))+[\]+;   &&cale program
			Juststem(Alltrim(nume))+[.exe]
			lcParametru = gcHost + [;] + gcuserName + [;] + gcPassword + [;] + Alltrim(Str(gnIdUtil)) + [;] + ;
				lcIdProgram + [;] + lcParametru_prog + [;]  &&parametri
			lcComandaProgram=[run /n ] + lcCaleProgram +[ ]+lcParametru

			lcImgNume="img_"+lcIdProgram+"_"+lcParametru_prog

			If lnIdProgram>0
				.AddObject(lcImgNume,'img_program')
				.&lcImgNume..comanda_program = lcComandaProgram			&&adaug poza
				.&lcImgNume..Picture = lcImagine
				.&lcImgNume..ToolTipText = lcNumeProgram
				.&lcImgNume..Visible=.T.
			Endif


		Endscan

		.Dock(0)
		.Show
	Endwith
Endif

If Used('v_programe_instalate')
	Use In v_programe_instalate
Endif

If Used('v_programe_favorite')
	Use In v_programe_favorite
Endif

Endproc
***---------------------------------------------------------------------------------------------------------------------------------------
***---------------------------------------------------------------------------------------------------------------------------------------
Procedure ceretitlu_rap
Parameters tcMesaj,tctitlu

Local lcTitlu
lcTitlu = tctitlu
obj1=Createobject("frm_cere_titlu")
obj1.clb_tx_simplu1.lb_simplu1.Caption = tcMesaj
obj1.clb_tx_simplu1.text_simplu1.ControlSource = 'lctitlu'
obj1.Show(1)
Return lcTitlu

Endproc
***---------------------------------------------------------------------------------------------------------------------------------------
***-------------------------------------------------------------------------------------------
Procedure cursor2lista
Lparameters tcCursor, tcColumn,tcSeparator
&& tcCursor - cursor
&& tcColumn - coloana din cursor care va constitui lista
&& tcSeparator separatorul de elemente din tcLista - default este ";" - este optional
&& intoarce lista de valori separate prin separatori
&& ex: lcLista = cursor2lista("cursor","id",";")
Local lcLista,lcSeparator, lcSelect

lcLista = ""
lcSeparator = Iif(!Empty(tcSeparator) And Type('tcSeparator') = 'C', tcSeparator, ";")
If Used(tcCursor)
	lcSelect = Select()
	lcColumn = tcCursor + "." + tcColumn
	If Type(lcColumn) # 'U'
		Select &tcColumn From (tcCursor) Into Cursor crsListaTemp

		Select crsListaTemp
		Scan
			lcLista = lcLista + Alltrim(Transform(Evaluate(tcColumn))) + lcSeparator
		Endscan
		Use In crsListaTemp

		If !Empty(lcLista)
			lcLista = Left(lcLista, Len(lcLista) - 1)
		Endif
	Endif


	Select (lcSelect)
Endif

Return lcLista

Endproc && cursor2lista

***-------------------------------------------------------------------------------------------
***-------------------------------------------------------------------------------------------
Procedure GETCALLSTACK
Local nPos
nPos=Program(-1) - 2


Local cCallStack,i
cCallStack=""
For i=nPos To 1 Step -1
	cCallStack=cCallStack + Program(i) + Chr(13)+Chr(10)
Endfor


Return cCallStack

Endproc && GETCALLSTACK
***-------------------------------------------------------------------------------------------
&& -------------------------- INCEPUT verific_cont ------------------------------
Procedure verific_cont
Parameters tcCont, tlNoMessage

Private pcCont
pcCont = Alltrim(tcCont)

&& verificare contului cu Planul de Conturi
lcSel = [SELECT cont from ] + GCS + [.vplcont_sintetic WHERE TRIM(cont) = ?pcCont and an = ?gnAn ]
lcCursor = 'crs_verific'
lnSucces = goExecutor.oExecute(lcSel,lcCursor)
If lnSucces < 0
	AMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
Endif

If lnSucces > 0
	If Reccount('crs_verific')=0
		lnSucces = -1
	Endif
Endif

If lnSucces < 0 And !tlNoMessage
	AMESSAGEBOX('Acest cont nu este definit in planul de conturi!',0+48, 'Atentie')
Endif

Return lnSucces

Endproc

&& -------------------------- SFARSIT verific_cont ------------------------------

* ===================== GetHash ====================================
* INTOARCE UN OBIECT DE TIP HASH CREAT DIN tcPropertyValueList
*!*	loHash = GetHash([cselect=>select id, name from test??cwhere=>id=pnId??corder=>name])
*!*	lnMembers = AMEMBERS(laMembers, loHash)
*!*	FOR i = 1 TO lnMembers
*!*		MESSAGEBOX(loHash.&laMembers(i))
*!*	ENDFOR
* ==================================================================
Function GetHash
Lparameters tcPropertyValueList

Local loHash

loHash = Createobject("MyHash", tcPropertyValueList)
Return loHash

Endfunc


* ===================== MyHash ====================================
* OBIECT EMULARE HASH
* loHash = GetHash([cselect=>select id, name from test??cwhere=>id=pnId??corder=>name])
* ==================================================================
Define Class MyHash As Custom


	Procedure ReadMe
	If .F.
		Local loHash
		loHash = Createobject("MyHash", [cselect=>select id, name from test??cwhere=>id=pnId??corder=>name])
	Endif
	Endproc && readme

*!* sir "proprietate1=>valoare1??proprietate2=>valoare2"
*!* genereaza proprietati si valori din sirul initial
	Procedure Init
	Lparameters tcPropertyValueList

	Local i, lnProperties, lcPropertyValue, lcValue, luValue

&& tcPropertyValueList = [cselect =>ala bala portocala??cfiltru=>un filtru - atentie la spatiile din stanga valorii]
	If Type('tcPropertyValueList') = 'C' And !Empty(tcPropertyValueList)
		lnProperties = Getwordcount(tcPropertyValueList,'??')
		For i = 1 To lnProperties
			lcPropertyValue = Alltrim(Getwordnum(tcPropertyValueList,i,'??'))
			If At('=>', lcPropertyValue) > 0
				lcProperty = Getwordnum(Strtran(lcPropertyValue,'=>',Chr(18)), 1, Chr(18))
				lcValue =  Getwordnum(Strtran(lcPropertyValue,'=>',Chr(18)), 2, Chr(18))
				luValue = This.GetDefaultValue(lcProperty, lcValue)
				This.SetValue(lcProperty, luValue)
			Endif
		Endfor
	Endif
	Endproc && INIT

*!* Seteaza valoarea unei proprietati daca exista sau adauga proprietatea, si intoarce valoarea
	Procedure SetValue
	Lparameters tcProperty, tuValue

	If Type('THIS.&tcProperty') <> 'U'
		This.&tcProperty = tuValue
	Else
		This.AddProperty(tcProperty, tuValue)
	Endif

	Return This.&tcProperty

	Endproc && SetValue

*!* Intoarce valoarea unei proprietati daca exista, altfel valoarea empty() corespunzator tipului proprietatii
	Function GetValue
	Lparameters tcProperty

	Local lcProperty, luValue
	lcProperty = 'THIS.' + tcProperty

	If Type('THIS.&tcProperty') <> 'U'
		luValue = This.&tcProperty
	Else
		luValue = This.GetDefaultValue(tcProperty)
	Endif
	Return luValue

	Endfunc && GetValue

*!* Intoarce valoarea empty() a unei proprietati dupa tip = prima litera din numele proprietatii daca nu primeste decat tcProperty
*!* Converteste tcValue la tipul variabilei tcProperty  daca tcValue e primit ca parametru
	Function GetDefaultValue
	Lparameters tcProperty, tcValue

	Local lcType, luValue
	luValue = ""
	lcType = Upper(Left(tcProperty,1))
	llEmptyValue = Iif(Pcount() = 1, .T., .F.)

	Do Case
	Case lcType $ "CM"
		luValue = Iif(llEmptyValue, '', tcValue)
	Case lcType $ "NIF"
		luValue = Iif(llEmptyValue, 0, Val(tcValue))
	Case lcType = "T"
		luValue = Iif(llEmptyValue, Dtot({}), Ctot(tcValue))
	Case lcType = "D"
		luValue = Iif(llEmptyValue, {}, Ctod(tcValue))
	Case lcType = "L"
		luValue = Iif(llEmptyValue, .F., Iif(tcValue = "1" Or Upper(tcValue) = "T" Or Upper(tcValue) = '.T.' Or Upper(tcValue) = 'YES', .T., .F.))
	Otherwise
		luValue = ""
	Endcase

	Return luValue
	Endfunc && GetDefaultValue

*!* Intoarce .T. daca exista proprietatea
	Function HasProperty
	Lparameters tcProperty

	Local lcProperty, llReturn
	lcProperty = 'THIS.' + tcProperty
	llReturn = .F.

	If Type('THIS.&tcProperty') <> 'U'
		llReturn = .T.
	Endif

	Return llReturn

	Endfunc && HasProperty

Enddefine && Hash

Function  get_zileluc(  )

lnzileluc = 0
lcSql = [select zileluc from ] + GCS + [.sal_calendar where an=?gnan and luna=?gnluna]
lcCursor = [v_zileluc]
lnSucces = goExecutor.oExecute(lcSql,lcCursor)
goExecutor.Oreset()
If lnSucces < 0
	AMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
	Return
Else
	Select 	v_zileluc
	lnzileluc = zileluc
Endif
Return lnzileluc

*******************************************
* PROCEDURE param_listari( tcraport, tcTitlu, tcSemnaturi )
* Date : 07/28/05, 14:04:21
* author : liana.macinic
* description:

****** PARAMETER BLOCK **************
* Parameters : 3
* Parameter 1:
* Parameter 2:
* Parameter 3:
*
*******************************************
Procedure param_listari( tcraport, tctitlu, tcSemnaturi, tlFaraTab)
Store '' To tctitlu, tcSemnaturi

Local lnIdRaport
If Used('v_raport')
	Use In v_raport
Endif

lcSql = [select id_raport,titlu from ] + GCS + [.sal_nom_rapoarte where UPPER(raport) = ']+Upper(Alltrim(tcraport))+[']
lcCursor = [v_raport]
lnSucces = goExecutor.oExecute(lcSql,lcCursor)
goExecutor.Oreset()
If lnSucces < 0
	AMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
	Return
Endif
Select v_raport
lnIdRaport = v_raport.id_raport
tctitlu = v_raport.titlu
Use


If Used('v_date')
	Use In v_date
Endif

lcSql = [select semnatura,NUME from ] + GCS + [.sal_semnaturi_rap where id_raport = ]+Alltrim(Str(lnIdRaport))+[ and sters = 0  order by ordine]
lcCursor = [v_date]
lnSucces = goExecutor.oExecute(lcSql,lcCursor)
goExecutor.Oreset()
If lnSucces < 0
	AMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
	Return
Endif

Local lcSemn,lcNumeRap,lcListaNumeRap
Store '' To lcSemn,lcNumeRap,lcListaNumeRap


Select v_date
Scan
	Scatter Name lcDateRap Memo
	lcSemn = Alltrim(Nvl(lcDateRap.semnatura,""))
	lcNumeRap = Alltrim(Nvl(lcDateRap.nume,''))
	If Len(lcSemn) => Len(lcNumeRap)
		lcNumeRap = Padr(lcNumeRap,Len(lcSemn)," ")
	Else
		lcSemn= Padr(lcSemn,Len(lcNumeRap)," ")
	Endif
	If tlFaraTab
		tcSemnaturi = tcSemnaturi+lcSemn
	Else
		tcSemnaturi = tcSemnaturi+Chr(9)+Chr(9)+lcSemn
	Endif

	If tlFaraTab
		lcListaNumeRap = lcListaNumeRap + lcNumeRap
	Else
		lcListaNumeRap = lcListaNumeRap + +Chr(9)+Chr(9)+lcNumeRap
	Endif
Endscan

tcSemnaturi = tcSemnaturi + Chr(13) + lcListaNumeRap
*!*	SELECT v_date
*!*	SCAN
*!*		tcSemnaturi = tcSemnaturi+CHR(9)+CHR(9)+ALLTRIM(v_date.nume)
*!*	ENDSCAN
*!*	tcSemnaturi = tcSemnaturi+CHR(9)+CHR(9)+CHR(9)+CHR(9)
Select v_date
Use
Endproc
*----------------------------------sfarsit procedura param_listari----------------------------------
** --------------------------------INCEPUT: facturi_duplicate ------------------------------
Procedure facturi_duplicate
Parameters tcCont, tnId_Part, tnNract, tcMesajReturn

Private pcCont, pnNract, pnId_part 
Local lcMesaj, MesajReturn
lcMesaj = ''
pcCont = tcCont
pnId_part = tnId_Part
pnNract = tnNract
lcMesajReturn = tcMesajReturn

If !(Alltrim(Str(pnNract))$lcMesajReturn)
	If Inlist(Allt(pcCont),'4111','401','404')
		lnTotctva = 0
		Do Case
		Case Allt(pcCont) = '4111'
			lcSql = [select count(*) as nr_ireg, sum(debit) as debit from ireg_parteneri ]+;
				[ where an=?gnAn and luna=?gnLuna and cont = ?pcCont and nract = ?pnNract]+;
				[ and extract(year from dataireg)*12+extract(month from dataireg) = ?gnAn*12+?gnLuna ]
			lcCursor = [crsFactDbl]
			lnSucces = goExecutor.oExecute(lcSql,lcCursor)
			goExecutor.Oreset()

			If lnSucces < 0
				AMESSAGEBOX(goExecutor.cEroare,0+16,'Eroare')
				Return
			Endif

			Select crsFactDbl
			If nr_ireg > 0
				lnTotctva = debit
				lcMesaj = 'Factura '+Allt(Str(pnNract)) + ", "+ Alltrim(Transform(lnTotctva, get_mask(14,GnPA)))+' lei, mai exista inregistrata in luna curenta.'
			Endif

		Case Allt(pcCont) = '401'
			lcSql = [select count(*) as nr_ireg, sum(credit) as credit from ireg_parteneri ]+;
				[ where an=?gnAn and luna=?gnLuna and cont = ?pcCont and nract = ?pnNract]+;
				[ and extract(year from dataireg)*12+extract(month from dataireg) = ?gnAn*12+?gnLuna ]+;
				[ and id_part = ?pnId_part]
			lcCursor = [crsFactDbl]
			lnSucces = goExecutor.oExecute(lcSql,lcCursor)
			goExecutor.Oreset()

			If lnSucces < 0
				AMESSAGEBOX(goExecutor.cEroare,0+16,'Eroare')
				Return
			Endif

			Select crsFactDbl
			If nr_ireg > 0
				lnTotctva = credit
				lcMesaj = 'Factura '+Allt(Str(pnNract)) + ", "+ Alltrim(Transform(lnTotctva, get_mask(14,GnPA)))+' lei, mai exista inregistrata in luna curenta.'
			Endif
		Case Allt(pcCont) = '404'
			lcSql = [select count(*) as nr_ireg, sum(credit) as credit from vireg_parteneri ]+;
				[ where an=?gnAn and luna=?gnLuna and cont = ?pcCont and nract = ?pnNract]+;
				[ and extract(year from dataireg)*12+extract(month from dataireg) = ?gnAn*12+?gnLuna ]+;
				[ and id_part = ?pnId_part]
			lcCursor = [crsFactDbl]
			lnSucces = goExecutor.oExecute(lcSql,lcCursor)
			goExecutor.Oreset()

			If lnSucces < 0
				AMESSAGEBOX(goExecutor.cEroare,0+16,'Eroare')
				Return
			Endif

			Select crsFactDbl
			If nr_ireg > 0
				lnTotctva = credit
				lcMesaj = 'Factura '+Allt(Str(pnNract)) + ", "+ Alltrim(Transform(lnTotctva, get_mask(14,GnPA)))+' lei, mai exista inregistrata in luna curenta.'
			Endif
		Endcase

	Endif
Endif

Return lcMesaj

Endproc  && facturi_duplicate
&& ------------------------------SFARSIT: facturi_duplicate ------------------------------




