*!* citeste_optiune, scrie_optiune +parametru tValue2

*** OINIT_OPTIUNI.PRG

glLuna_neplatita = .F.
glLunaInchisa = .F.

*!*	gnLuna = Round(Val(goCalendar.nl),0)
*!*	gnAn = Round(Val(goCalendar.An),0)

gnLuna = goCalendar.luna
gnAn = goCalendar.anul

pcNl = Padl(Alltrim(Str(gnLuna)), 2, '0')
pcAn = Alltrim(Str(gnAn))
m.nl = m.pcNl
m.an = m.pcAn
gcFirma = Upper(Alltrim(goFirma.firma))
If Type('gnIdFirma') <> 'U'
	gnIdFirma = goFirma.Id_Firma
Endif
gnIdFirma = goFirma.Id_Firma


*!* 08.02.2008 SUCURSALE
Public gnIdSucursala, gnIdMama, glEMama, gcCondSucursala
gnIdSucursala = Iif(Nvl(goFirma.id_mama, 0) <> 0, goFirma.Id_Firma, Null) && DACA ESTE SUCURSALA - ID-UL SUCURSALA PE CARE IL SCRIU IN TABELE
*gnIdSucursala = Iif(Nvl(goFirma.id_firma,0) <> 0, goFirma.Id_Firma, Null)
gnIdMama = Iif(Nvl(goFirma.id_mama, 0) <> 0, goFirma.id_mama, Null)
glEMama = Nvl(goFirma.e_mama, 0) <> 0
gcCondSucursala = Iif(!Isnull(gnIdSucursala), ' AND id_sucursala = ?gnIdSucursala ', '') && CONDITIA FOLOSITA LA SELECTIILE DIN JURNAL, RULAJ, IREG_PARTENERI
*!* 08.02.2008 SUCURSALE ^

*!*	gcSchemaPath = ADDBS(dirgen) + gcS + "\"
*!*	m.calefirma = gcSchemaPath
*!*	IF !DIRECTORY(gcSchemaPath)
*!*		MD (gcSchemaPath)
*!*	ENDIF

*!*	gnNivelUtilizator = getNivel(gnIdProgram,gnIdUtil,gnId_Firma)
*!*	gcAcces = getAcces(gnIdProgram,gnIdUtil,gnId_Firma)


m.an = Alltrim(Str(gnAn))
m.nl = Padl(Alltrim(Str(gnLuna)), 2, '0')
m.NumeFirma = gcFirma
m.flung = gcFirma
m.numeluna = m.nl
m.luna = m.nl
m.ctvam = goCalendar.ctvam
m.ctvai = goCalendar.ctvai
m.antet = goFirma.antet
gcAntet = goFirma.antet
*!*	adaugat 25.02.2014 / liana neagu /ROARES
Public gcNumeUtilEnt
gcNumeUtilEnt = []
lcSql = [begin pack_def.citesteNumeEnt(?gnIdUtil,?@gcNumeUtilEnt); end;]
If !goExecutor.oExecuta(lcSql)
	gcNumeUtilEnt = gcUserNameApp
Endif
*!*	adaugat 25.02.2014 ^

*!*	adaugat 23.09.2011 / MARIUS ATANASIU / ROAAUTO
Public gnCotaTVAStandard
gnCotaTVAStandard = goCalendar.ctvam
*!*	adaugat 23.09.2011	^
*** ADAUGAT 01.11.2005
*** MARIUS MUTU
glLunaInchisa = is_luna_blocata(gcS, gnId_Prg_Owner, gnAn, gnLuna)


*!* 25.01.2012
lcDeclarant = Alltrim(goFirma.declarant)
AddProperty(goFirma, 'nume_declarant', m.lcDeclarant)
AddProperty(goFirma, 'prenume_declarant', '')
lnNraparitie = At(" ", m.lcDeclarant)
If lnNraparitie > 0
	goFirma.nume_declarant = Substr(m.lcDeclarant, 1, m.lnNraparitie)
	goFirma.prenume_declarant = Substr(m.lcDeclarant, m.lnNraparitie + 1)
Endif
*!* 25.01.2012 ^

verificare_versiune()
*---------------------- deschid lunilean , sa iau denumirea completa a lunii
Local lcNumeLuna
Store "" To lcNumeLuna
If Used("v_lunilean")
	Use In v_lunilean
Endif
lcSelect = [select * from lunilean ]
lcCursor = [v_lunilean]
lnSucces = goExecutor.oExecute(lcSelect, lcCursor)
If lnSucces < 0
	AMESSAGEBOX('Eroare la selectie ' + goExecutor.cEroare)
	Return
Endif
Select v_lunilean
Locate For nrluna = gnLuna
If Found()
	lcNumeLuna = Alltrim(v_lunilean.numeluna)
Endif
*----------------------deschid lunilean , sa iau denumirea completa a lunii
If Type("NUMEPROGRAM") <> 'C' Or Empty(NUMEPROGRAM)
	NUMEPROGRAM = gcAppName
Endif
capapl = NUMEPROGRAM + "      Firma " + NumeFirma + "- Luna contabila: " + lcNumeLuna + " " + M.an + "  "
*-----------------------
goApp.SetCaption(capapl)
Release lcNumeLuna

If Used("v_lunilean")
	Use In v_lunilean
Endif

*!*	06.09.2012	/	marius.atanasiu
*!*	daca schimbam luna, nu se schimba gcTempPath si la BackupXML imi cauta xml-urile in firma anterioara
*!*	*!* 07.06.2007
*!*	*!* marius.mutu
*!*	*!* daca este definita gcTempPath in main.prg - goApi.GetTempPath()
*!*	If Empty(gcTempPath) OR 'SITFIN'$UPPER(gcAppName)
*!*	*!*		gcTempPath = [c:\contafin\temp\] + gcS + [\]
*!*	*!*		IF !DIRECTORY(gcTempPath)
*!*	*!*			MD (gcTempPath)
*!*	*!*		ENDIF
&& obiectul public goApi trebuie creat in programul principal, daca nu,  este creat in oinit_optiuni.prg
If Type('goApi') = 'U'
	Public goApi
	goApi = Newobject("wwAPI", "wwAPI.prg")
Endif
gcTempPath = Addbs(shortpath(goApi.GetTempPath())) + gcS + [\] && WWAPI.PRG
If !Directory(gcTempPath)
	Md (gcTempPath)
Endif
*!*	Endif
*!*	06.09.2012	^
m.NIVEL = 0
m.UTILIZATOR = gcUserNameApp



*!*	STORE 0 TO gnPA && nr. de zecimale afisare
*!*	STORE 0 TO gnPC && nr. de zecimale calcul

If lnSucces > 0
	&& setez variabilele de sesiune pe server
	lnSucces = InitSesiune() && IN oInit_Optiuni.prg
Endif

If lnSucces > 0
	Do optiuni_firma
	Do coresp_cont_tipgest
	Do actualizeaza_optiuni_utilizator
	Do actualizeaza_optiuni
Endif

If Type('gnTraducere') = 'N'
	glTraducere = gnTraducere = 1
Endif

Return lnSucces

************************************** INCEPUT: actualizeaza_optiuni_program ***************************************
Function actualizeaza_optiuni_program
	Local llReturn
	Store .F. To llReturn
	lcSql = 'select * from ' + gcS + '.optiuni where program = ?gcNumeProgram order by varname'
	lcCursor = 'v_optiuni'

	lnSucces = goExecutor.oExecute(lcSql, lcCursor)

	If lnSucces < 0
		AMESSAGEBOX('ACTUALIZEAZA_OPTIUNI_PROGRAM ' + goExecutor.cEroare, 0 + 16, "Eroare")
		Return
	Else
		Select(lcCursor)
		Scan For !Empty(varname)
			lcvarname = Alltrim(&lcCursor..varname)
			lcvartype = Upper(Alltrim(&lcCursor..Vartype))
			Do Case
				Case lcvartype = "CHARACTER"
					Public gc&lcvarname.
					luvarvalue = Alltrim(&lcCursor..varvalue)
					gc&lcvarname. = luvarvalue
				Case lcvartype = "CURRENCY"
					Public gy&lcvarname.
					luvarvalue = Ntom(Val(&lcCursor..varvalue))
					gy&lcvarname. = luvarvalue
				Case lcvartype = "NUMERIC"
					Public gn&lcvarname.
					luvarvalue = Val(&lcCursor..varvalue)
					gn&lcvarname. = luvarvalue
				Case lcvartype = "DATETIME"
					Public gt&lcvarname.
					luvarvalue = Ctot(&lcCursor..varvalue)
					gt&lcvarname. = luvarvalue
				Case lcvartype = "DATE"
					Public gd&lcvarname.
					luvarvalue = Ctod(&lcCursor..varvalue)
					gd&lcvarname. = luvarvalue
				Case lcvartype = "LOGICAL"
					Public gl&lcvarname.
					luvarvalue = Iif(Inlist(Upper(Left(&lcCursor..varvalue, 1)), "T", "Y"), .T., .F.)
					gl&lcvarname. = luvarvalue
				Otherwise
					pcmsgbuff = "Tip de variabila globala invalid!"
					pcmsgbuff = pcmsgbuff + Chr(13) + Chr(13) + "Numele variabilei: " + lcvarname
					pcmsgbuff = pcmsgbuff + Chr(13) + "Tipul variabilei: " + lcvartype
					pcmsgbuff = pcmsgbuff + Chr(13) + Chr(13) + "Contactati suportul tehnic."
					= AMESSAGEBOX(pcmsgbuff, 48)
					pcmsgbuff = ""
			Endcase
		Endscan

		llReturn = .T.
		If Used('v_optiuni')
			Use In v_optiuni
		Endif
	Endif
	Return llReturn
Endfunc
******************************************* SFARSIT: actualizeaza_optiuni_program *******************************************



* PROCEDURE optiuni_firma(  )
* Date : 15.11.2004, 09:33:59
* author : catalin.neagu
* description:

****** PARAMETER BLOCK **************
* Parameters : 0
*
******************************************* INCEPUT:optiuni_f *******************************************
Procedure optiuni_firma

	*!* modificat 22.03.2006
	*!* mutu.marius
	*!* am folosit gcUserName in loc de gcS (adica "CONTAFIN_ORACLE") si am modificat procedura SCRIE_OPTIUNI

	lcSql = [begin SCRIE_OPTIUNI('] + gcUserName + ['); end;]
	lnSucces = goExecutor.oExecute(lcSql)

	If lnSucces < 0
		AMESSAGEBOX('SCRIE_OPTIUNI ' + goExecutor.cEroare, 0 + 16, "Eroare")
		Return
	Endif
	lnSucces = -1
	lnSucces = update_optiuni()

	If lnSucces > 0
		LCFIS = 'v_optiuni'

		*-- DECLAR VARIABILELE PUBLICE SI LE INITIALIZEZ ex: pcEroriPath,pcServerPath

		Select(LCFIS)
		Scan For !Empty(varname) And (Isnull(programe) Or gcNumeProgram $ programe)
			lcvarname = Alltrim(&LCFIS..varname)
			lcvartype = Upper(Alltrim(&LCFIS..Vartype))
			Do Case
				Case lcvartype = "CHARACTER"
					Public gc&lcvarname.
					luvarvalue = Alltrim(&LCFIS..varvalue)
					luvarvalue2 = Alltrim(&LCFIS..varvalue2)
					IF !EMPTY(NVL(luvarvalue,'')) OR (EMPTY(NVL(luvarvalue,'')) AND EMPTY(NVL(luvarvalue2,'')))
						gc&lcvarname. = m.luvarvalue
					ELSE 
						gc&lcvarname. = m.luvarvalue2
					ENDIF 
				Case lcvartype = "CURRENCY"
					Public gy&lcvarname.
					luvarvalue = Ntom(Val(&LCFIS..varvalue))
					gy&lcvarname. = luvarvalue
				Case lcvartype = "NUMERIC"
					Public gn&lcvarname.
					luvarvalue = Val(&LCFIS..varvalue)
					gn&lcvarname. = luvarvalue
				Case lcvartype = "DATETIME"
					Public gt&lcvarname.
					luvarvalue = Ctot(&LCFIS..varvalue)
					gt&lcvarname. = luvarvalue
				Case lcvartype = "DATE"
					Public gd&lcvarname.
					luvarvalue = Ctod(&LCFIS..varvalue)
					gd&lcvarname. = luvarvalue
				Case lcvartype = "LOGICAL"
					Public gl&lcvarname.
					luvarvalue = Iif(Inlist(Upper(Left(&LCFIS..varvalue, 1)), "T", "Y"), .T., .F.)
					gl&lcvarname. = luvarvalue
				Otherwise
					pcmsgbuff = "Tip de variabila globala invalid!"
					pcmsgbuff = pcmsgbuff + Chr(13) + Chr(13) + "Numele variabilei: " + lcvarname
					pcmsgbuff = pcmsgbuff + Chr(13) + "Tipul variabilei: " + lcvartype
					pcmsgbuff = pcmsgbuff + Chr(13) + Chr(13) + "Contactati suportul tehnic."
					= AMESSAGEBOX(pcmsgbuff, 48)
					pcmsgbuff = ""
			Endcase
		Endscan

		If Used('v_optiuni')
			Use In v_optiuni
		Endif
		Public gnZ
		m.gnZ = 0
		If Type('gnPA') = 'N'
			gnZ = m.gnPA
		Endif
		lnSucces = optiuni_speciale()
	Endif
	Return lnSucces
Endproc
******************************************* SFARSIT: optiuni_f *******************************************

* PROCEDURE viz_optiuni(  )
* Date : 15.11.2004, 12:31:24
* author : catalin.neagu
* description:

****** PARAMETER BLOCK **************
* Parameters : 0
*
******************************************* INCEPUT:viz_optiuni *******************************************
Procedure viz_optiuni
	Lparameters tcS, tnId_prg_owner

	Local lnSucces, lcS
	If Empty(tcS)
		lcS = "CONTAFIN_ORACLE"
	Else
		lcS = tcS
	Endif

	Private popt
	Store '' To popt

	Local lcschema, lcSelect
	lcschema = []
	lcSelect = [select * from ] + lcS + [.optiuni ]
	lcfiltru = []
	If !Empty(tnId_prg_owner)
		lcFiltuOriginal = [id_prg_owner=] + Alltrim(Str(tnId_prg_owner))
	Else
		lcFiltuOriginal = []
	Endif
	lcOrder = [varname]
	lcGroup = []
	llModParam = .T.
	llAfisare = .F.
	gencursor('popt', 'v_optiuni', lcSelect, lcfiltru, lcschema, lcOrder, llAfisare, lcGroup, llModParam, lcFiltuOriginal)
	popt.ca_baza1.afisare()

	ofrmopt = Createobject('frm_optiuni')
	ofrmopt.cSchema = lcS
	ofrmopt.Show(1)
	Release ofrmopt

Endproc
******************************************* SFARSIT: viz_optiuni *******************************************

Procedure optiuni_cote_tva

	lcSql = [begin SCRIE_COTE_TVA('] + gcS + [',] + pcAn + [, ] + pcNl + [); end;]
	lnSucces = goExecutor.oExecute(lcSql)

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

* PROCEDURE viz_cote_tva( Tcs )
* Date : 04/01/05, 11:22:25
* author : catalin.neagu
* description:

****** PARAMETER BLOCK **************
* Parameters : 1
* Parameter 1:
*
******************************************* INCEPUT:viz_cote_tva *******************************************
Procedure viz_cote_tva
	LPARAMETERS tcS, tnAn, tnLuna

	Local lnSucces, lcS
	If Empty(tcS)
		lcS = "CONTAFIN_ORACLE"
	Else
		lcS = tcS
	Endif
	lcAn = Alltrim(Str(tnAn))
	lcLuna = Alltrim(Str(tnLuna))
	Private pcot, pcschema1, pcselect1
	Store '' To pcot
	pcschema1 = ['']
	pcselect1 = ['select * from ] + lcS + [.cote_tva where 1=2']
	pcfiltru1 = [ an = ] + lcAn + [and luna = ] + lcLuna
	pcOrder1 = [an, luna]
	gencursor('pcot', 'v_cote_tva', pcselect1, pcfiltru1, pcschema1, pcOrder1)
	pcot.ca_baza1.afisare()
	ofrmcot = Createobject('frm_cote_tva')
	ofrmcot.cSchema = lcS
	ofrmcot.Show(1)
	Release ofrmcot

Endproc
******************************************* SFARSIT: viz_cote_tva *******************************************

* PROCEDURE optiuni_plcont( tcs )
* Date : 04/01/05, 13:04:09
* author : catalin.neagu
* description:

****** PARAMETER BLOCK **************
* Parameters : 1
* Parameter 1:
*
******************************************* INCEPUT:optiuni_plcont *******************************************
Procedure optiuni_plcont()

	lcSql = [begin SCRIE_PLCONT('] + gcS + [',] + gnAn + [); end;]
	lnSucces = goExecutor.oExecute(lcSql)

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


******************************************* SFARSIT: optiuni_plcont *******************************************
* PROCEDURE optiuni_notec(  )
* Date : 04/01/05, 13:05:32
* author : catalin.neagu
* description:

****** PARAMETER BLOCK **************
* Parameters : 0
*
******************************************* INCEPUT:optiuni_notec *******************************************
Procedure optiuni_notec(  )

	lcSql = [begin SCRIE_notec('] + gcS + ['); end;]
	lnSucces = goExecutor.oExecute(lcSql)

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

******************************************* SFARSIT: optiuni_notec *******************************************

* PROCEDURE viz_exceptii(  )
* Date : 04/01/05, 13:40:35
* author : catalin.neagu
* description:

****** PARAMETER BLOCK **************
* Parameters : 0
*
******************************************* INCEPUT:viz_exceptii *******************************************
Procedure viz_exceptii( tcS )
	Local lnSucces, lcS
	If Empty(tcS)
		lcS = "CONTAFIN_ORACLE"
	Else
		lcS = tcS
	Endif
	Private pex, pcschema1, pcselect1
	Store '' To pex
	pcschema1 = ['']
	pcselect1 = ['select * from ] + lcS + [.exceptii_ireg where 1=2']
	pcfiltru1 = [2=2]
	gencursor('pex', 'v_exceptii_ireg', pcselect1, pcfiltru1, pcschema1)
	pex.ca_baza1.afisare()
	ofrmex = Createobject('frm_exceptii_ireg')
	ofrmex.cSchema = lcS
	ofrmex.Show(1)
	Release ofrmex

Endproc
******************************************* SFARSIT: viz_exceptii *******************************************

Procedure coresp_cont_tipgest

	lcSql = [begin SCRIE_CORESP_CONT_TIPGEST('] + gcS + ['); end;]
	lnSucces = goExecutor.oExecute(lcSql)

	If lnSucces < 0
		lcMesaj = 'SCRIE_CORESP_CONT_TIPGEST ' + goExecutor.cEroare
		ofrm_er = Createobject([frm_mesaj], [Eroare], [exclam.ico], [Avertizare], lcMesaj)
		ofrm_er.Show(1)
		Release ofrm_er
		Return
	Endif

Endproc



********************* INCEPUT Optiuni_speciale **********************
* PROCEDURE Optiuni_speciale
* Date : 03/31/05, 08:48:45
* author : marius.mutu
* description:

Procedure optiuni_speciale
	Public gnLunaRon, gnAnRon, gl406, glEFactura

	gnLunaRon = Val(Substr(Alltrim(gcDataRon), 1, 2))
	gnAnRon = Val(Substr(Alltrim(gcDataRon), 4, 4))
	If gnAn * 12 + gnLuna < gnAnRon * 12 + gnLunaRon
		Store 0 To gnPA && nr. de zecimale afisare
		Store 0 To gnPC && nr. de zecimale calcul
		Store 0 To gnPCurs && nr. de zecimale curs
		Store 0 To gnPPretV &&	nr. de zecimale pret vanzare
		Store 0 To gnZ && gnPA
		*!*	ELSE
		*!*		Store 2 To gnPA && nr. de zecimale afisare
		*!*		Store 2 To gnPC && nr. de zecimale calcul
		*!*		Store 4 To gnPCurs && nr. de zecimale curs
	ENDIF

	* Firma are activata SAFT 406
	gl406 = (TYPE('gnD406') = 'N' and m.gnD406 = 1)
	* Firma are activata Efactura
	glEFactura = (TYPE('gnEFactura') = 'N' and m.gnEFactura = 1)

Endproc
********************* SFARSIT Optiuni_speciale **********************

*!* marius.mutu
*!* 21.02.2006
*!* Seteaza variabile de sesiune: pack_sesiune.id_util, pack_sesiune.Luna, pack_sesiune.An,  pack_sesiune.data_ron,  pack_contafin.data_ron
*** InitSesiune ===========================================================================
Procedure InitSesiune

	Local lnSucces
	lnSucces = 1

	&& setez variabilele de sesiune pe server
	If lnSucces > 0
		lcSql = [begin pack_sesiune.set_Id_Util(?gnIdUtil); end;]
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
		Endif
	Endif

	If lnSucces > 0
		lcSql = [begin pack_sesiune.setluna(?gnLuna); pack_sesiune.setan(?gnAn); end;]
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
		Endif
	Endif

	*!* 09.04.2008
	*!* setare lunabal si anbal pentru view-urile vbalmama si vbalanamama
	If lnSucces > 0
		lcSql = [begin pack_sesiune.setlunabal(?gnLuna); pack_sesiune.setanbal(?gnAn); end;]
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
		Endif
	Endif
	*!* 09.04.2008 ^

	If lnSucces > 0
		lcSql = [begin pack_contafin.SET_DATA_RON(?gcS); end;]
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
		Endif
	Endif
	If lnSucces > 0
		lcSql = [begin pack_sesiune.set_data_ron(?gcS); end;]
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
		Endif
	Endif

	llSucces = initializeaza_sucursala()
	If llSucces
		llSucces = initializeaza_firma()
	Endif

	lnSucces = Iif(llSucces, 1, -1)

	Return lnSucces

Endproc && InitSesiune
*** END InitSesiune ===========================================================================
Procedure actualizeazaSetare
	Lparameters tcSetare, tdData
	Private pcSetare, pdData, pcValoareSetare, pcTipSetare
	pcSetare = tcSetare
	pdData = Date()
	pcValoareSetare = [-]
	pcTipSetare = [-]
	lcSql = [{call citeste_ora_optiune(?pcSetare,?@pdData,?@pcValoareSetare,?@pcTipSetare)}]
	lnSucces = goExecutor.oExecute(lcSql)
	If lnSucces < 0
		AMESSAGEBOX(goExecutor.oPrelucrareEroare(), 0 + 16, "Eroare")
	Else
		Do Case
			Case pcTipSetare = "CHARACTER"
				luvarvalue = Alltrim(pcValoareSetare)
				gc&pcSetare. = luvarvalue
			Case pcTipSetare = "CURRENCY"
				luvarvalue = Ntom(Val(pcValoareSetare))
				gy&pcSetare. = luvarvalue
			Case pcTipSetare = "NUMERIC"
				luvarvalue = Val(pcValoareSetare)
				gn&pcSetare. = luvarvalue
			Case pcTipSetare = "DATETIME"
				luvarvalue = Ctot(pcValoareSetare)
				gt&pcSetare. = luvarvalue
			Case pcTipSetare = "DATE"
				luvarvalue = Ctod(pcValoareSetare)
				gd&pcSetare. = luvarvalue
			Case pcTipSetare = "LOGICAL"
				luvarvalue = Iif(Inlist(Upper(Left(pcValoareSetare, 1)), "T", "Y"), .T., .F.)
				gl&pcSetare. = luvarvalue
			Otherwise
				pcmsgbuff = "Tip de variabila globala invalid!"
				pcmsgbuff = pcmsgbuff + Chr(13) + Chr(13) + "Numele variabilei: " + pcSetare
				pcmsgbuff = pcmsgbuff + Chr(13) + "Tipul variabilei: " + pcTipSetare
				pcmsgbuff = pcmsgbuff + Chr(13) + Chr(13) + "Contactati suportul tehnic."
				= AMESSAGEBOX(pcmsgbuff, 48)
				pcmsgbuff = ""
		Endcase
		tdData = pdData
	Endif
Endproc &&	actualizeazaSetare
***********************************************************************

*!* 16.06.2007
*!* marius.mutu
*!* verificare versiune program - versiune baza date
*!* procedura de pe server intoarce nume_program:versiune_program daca este nevoie de actualizarea programului la versiunea <versiune_program>
*!* sau db:versiune_db daca este nevoie de actualizarea bazei de date la versiunea <versiune_db>
Procedure verificare_versiune
	Local lcFileVersiuneDB, llOk, lcMesaj
	Private pcReturnValue, pcNumeProgram, pcVersiuneDB, pcVersiuneProgram
	llOk = .T.
	lcMesaj = ""
	pcReturnValue = "" && roacont:1.0.25 sau db:2007_06_16_2
	pcNumeProgram = Upper(gcNumeProgram)
	pcVersiuneDB = ""

	pcVersiuneProgram = Get_Version()
	lcFileVersiuneDB = gcAppPath + "versiune_db.txt"
	If File(lcFileVersiuneDB)
		pcVersiuneDB = Alltrim(Filetostr(lcFileVersiuneDB)) && 2007_06_15_01
	Endif

	lnSucces = goExecutor.oFunction2Value("pack_migrare.VerificaVersiune('" + pcNumeProgram + "', '" + pcVersiuneProgram + "', '" + pcVersiuneDB + "')", @pcReturnValue)
	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
	Else
		*!*			SELECT COUNT(*) AS nr FROM versiune WHERE SUBSTR(script_final,4,13) = lcVersiuneDB INTO CURSOR crsVersiuneTemp
		Do Case
			Case pcNumeProgram $ Upper(pcReturnValue)
				llOk = .F.
				lcMesaj = "Trebuie actualizat " + pcNumeProgram + " la versiunea " + Getwordnum(pcReturnValue, 2, ":") + Chr(13) + Chr(10) + ;
					"Versiunea actuala este " + Getwordnum(pcReturnValue, 3, ":")

			Case "DB" $ Upper(pcReturnValue)
				llOk = .F.
				lcMesaj = "Trebuie actualizata baza de date la versiunea " + Getwordnum(pcReturnValue, 2, ":") + Chr(13) + Chr(10) + ;
					"Versiunea actuala este " + Getwordnum(pcReturnValue, 3, ":")
		Endcase
	Endif

	*!*		SELECT versiune_program, versiune_bd FROM versiune_programe WHERE UPPER(PROGRAM) = UPPER(gcNumeProgram)
	If !Empty(lcMesaj)
		AMESSAGEBOX(lcMesaj, 0 + 48, "Actualizare")
	Endif
	Return llOk
Endproc && verificare_versiune
******************************************************************************************
Function initializeaza_sucursala()
	Local lcSel, lnSucces, llReturn
	llReturn = .T.
	lcSel = [begin pack_contafin.set_id_sucursala(?gnIdSucursala); end;]
	lnSucces = goExecutor.oExecute(lcSel)
	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
		llReturn = .F.
	Endif
	Release lcSel, lnSucces
	Return llReturn
Endfunc
******************************************************************************************
Function initializeaza_firma()
	Local lcSel, lnSucces, llReturn
	llReturn = .T.
	lcSel = [begin pack_contafin.set_id_firma(?gnIdFirma); end;]
	lnSucces = goExecutor.oExecute(lcSel)
	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
		llReturn = .F.
	Endif
	Release lcSel, lnSucces
	Return llReturn
Endfunc
************************************* INCEPUT: actualizeaza_optiuni_utilizator ***************************************
Procedure actualizeaza_optiuni_utilizator
	Local lnSucces
	Store .F. To llReturn
	lcSql = 'select * from optiuni_util where id_util = ?gnIdUtil order by varname'
	lcCursor = 'crsOptiuniUtilizator'

	lnSucces = goExecutor.oExecute(lcSql, lcCursor)

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

	Return lnSucces
Endproc
******************************************* SFARSIT: actualizeaza_optiuni_utilizator *******************************************
******************************************* INCEPUT: citeste_optiune_utilizator*******************************************
Function citeste_optiune_utilizator
	Lparameters tcOptiune

	Local lcOptiune, lcValOptiune
	lcOptiune = tcOptiune
	lcValOptiune = ''
	If Used('crsOptiuniUtilizator')
		Select Nvl(varvalue, '') As varvalue ;
			From crsOptiuniUtilizator ;
			With (Buffering = .T.) ;
			Where Upper(Alltrim(varname)) = Upper(Alltrim(tcOptiune)) ;
			Into Cursor crsOptiuneUtilizator

		Select crsOptiuneUtilizator
		lcValOptiune = varvalue
	Endif
	Return m.lcValOptiune
Endfunc && citeste_optiune_utilizator
******************************************* SFARSIT: citeste_optiune_utilizator *******************************************
******************************************* INCEPUT: scrie_optiune_utilizator*******************************************
Procedure scrie_optiune_utilizator
	Parameters tcOptiune, tcValOptiune, tcDescriereOptiune

	Private pcOptiune, pcValOptiune, pcDescriereOptiune
	pcOptiune = Upper(tcOptiune)
	pcValOptiune = tcValOptiune
	pcDescriereOptiune = tcDescriereOptiune

	*lcSql='update optiuni_util set varvalue = ?pcValOptiune where varname=?pcOptiune and id_util = ?gnIdUtil'

	*!*	lcSql=[MERGE INTO optiuni_util ]+;
	*!*		[USING dual ]+;
	*!*		[on (UPPER(varname) = ?pcOptiune and id_util = ?gnIdUtil) ]+;
	*!*		[WHEN MATCHED THEN ]+;
	*!*		[ UPDATE SET varvalue = ?pcValOptiune ]+;
	*!*		[WHEN NOT MATCHED THEN ]+;
	*!*		[INSERT (varname, id_util, varvalue) ]+;
	*!*		[VALUES (?pcOptiune, ?gnIdUtil, ?pcValOptiune);]

	lcSql = [begin PACK_SESIUNE.SetOptiuneUtilizator(?pcOptiune,?gnIdUtil, ?pcValOptiune, ?pcDescriereOptiune); end;]
	lnSucces = goExecutor.oExecute(lcSql)

	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
	Else
		Select crsOptiuniUtilizator
		Locate For Upper(varname) = pcOptiune
		If Found()
			Replace varvalue With pcValOptiune
		Else
			Insert Into crsOptiuniUtilizator (varname, id_util, vardesc, varvalue) Values (m.pcOptiune, m.gnIdUtil, m.pcDescriereOptiune, m.pcValOptiune)
		Endif
	ENDIF
	TABLEUPDATE( 1, .F., 'crsOptiuniUtilizator')

	Return lnSucces
Endproc && scrie_optiune_utilizator
******************************************* SFARSIT: scrie_optiune_utilizator *******************************************

Procedure actualizeaza_optiuni
	Local lnSucces
	llReturn = .F.
	lcSql = 'select * from optiuni order by varname'
	lcCursor = 'crsOptiuni'

	USE IN (SELECT('crsOptiuni'))
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)

	If m.lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
	Endif

	Return m.lnSucces
Endproc
******************************************* SFARSIT: actualizeaza_optiuni *******************************************

******************************************* INCEPUT: citeste_optiune *******************************************
Function citeste_optiune
	Parameters tcOptiune, tlValue2
	* tlValue2: .T. optiunea se citeste din optiuni.varvalue2, in loc de optiuni.varvalue

	Local lcOptiune, lcValOptiune, lcSelect
	lcOptiune = tcOptiune
	lcValOptiune = ''
	lcSelect = Select()

	Select crsOptiuni
	Locate For Upper(Alltrim(varname)) = Upper(Alltrim(m.tcOptiune))
	If Found()
		If m.tlValue2
			lcValOptiune = varvalue2
		Else
			lcValOptiune = varvalue
		Endif
	Endif

	Select (m.lcSelect)
	Return lcValOptiune
Endfunc && citeste_optiune
******************************************* SFARSIT: citeste_optiune *******************************************

******************************************* INCEPUT: scrie_optiune *******************************************
Procedure scrie_optiune
	Lparameters tcOptiune, tcValOptiune, tcDescriereOptiune, tlValue2
	* tlValue2: .T. optiunea se scrie in optiuni.varvalue2, in loc de optiuni.varvalue

	Private pcOptiune, pcValOptiune, pcDescriereOptiune, pcTipOptiune

	Local lcSql, lcValOptiune, lnSucces
	pcOptiune = Upper(tcOptiune)
	pcValOptiune = m.tcValOptiune
	lcValOptiune = m.tcValOptiune
	pcDescriereOptiune = tcDescriereOptiune
	Do Case
		Case Type('tcValOptiune') = 'C'
			pcTipOptiune = 'CHARACTER'
		Case Type('tcValOptiune') = 'N'
			pcTipOptiune = 'NUMERIC'
			lcValOptiune = TRANSFORM(m.tcValOptiune)
		Case Inlist(Type('tcValOptiune'), 'D', 'T')
			pcTipOptiune = 'DATE'
			lcValOptiune = DTOC(m.tcValOptiune)
		Case Type('tcValOptiune') = 'L'
			pcTipOptiune = 'LOGICAL'
			lcValOptiune = TRANSFORM(m.tcValOptiune)			
		Otherwise
			pcTipOptiune = 'CHARACTER'
	Endcase

	If m.tlValue2
		lcSql = [begin PACK_SESIUNE.SetOptiune2(?pcOptiune, ?pcValOptiune, ?pcTipOptiune, ?pcDescriereOptiune); end;]
	Else
		lcSql = [begin PACK_SESIUNE.SetOptiune(?pcOptiune, ?pcValOptiune, ?pcTipOptiune, ?pcDescriereOptiune); end;]
	Endif
	lnSucces = goExecutor.oExecute(lcSql)

	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
	Else
		Select crsOptiuni
		Locate For Upper(varname) = pcOptiune
		If Found()
			If m.tlValue2
				Replace varvalue2 With m.lcValOptiune
			Else
				Replace varvalue With m.lcValOptiune
			Endif
		Else
			If m.tlValue2
				Insert Into crsOptiuni (varname, vardesc, varvalue2) Values (m.pcOptiune, m.pcDescriereOptiune, m.lcValOptiune)
			Else
				Insert Into crsOptiuni (varname, vardesc, varvalue) Values (m.pcOptiune, m.pcDescriereOptiune, m.lcValOptiune)
			Endif
		ENDIF
		TABLEUPDATE( 1, .F., 'crsOptiuni')
	Endif

	Return lnSucces
Endproc && scrie_optiune