*!* 24.07.2009
*!* marius.mutu
*!* CAUT_ARTICOL (tlCautPlus - daca se foloseste formularul caut_alfa_form_plus cu butonul but_start_criterii)

*!*	04.09.2009
*!*	marius.mutu
*!*	caut_gestiune_xml ( + tnPornire)

*!* 22.02.2010
*!*	marius.mutu
*!*	caut_gestiune_xml gcCondSucursala

*!* 06.07.2011
*!* marius.mutu
*!* caut_politici_preturi
*!* cautare in vcrm_politici_preturi dupa drepturi utilizator

*!* 19.12.2011
*!* marius.mutu
*!* caut_parteneri_xml - selectie inclusiv parteneri vechi unificati si transformati in parteneri noi

*!* 01.02.2013
*!* marius.mutu
*!* caut_gestiune_xml - corectat c.id_sucursala in loc de a.id_sucursala

*!* 06.01.2014
*!* marius.mutu
*!* caut_gestiune_dest - am mutat conditia de la planul de conturi sintetic si analitic in join, in loc de where - nu mergea in unele cazuri

*!* 28.09.2018
*!* marius.mutu
*!* caut_parteneri + parametru tlInactiv: daca arat si partenerii inactivi (ex: la fisa de cont, cand un partener s-a unificat, partenerul vechi este inactiv)

*!* 17.01.2020
*!* marius.mutu
*!* caut_responsabil - include CNP, se foloseste in baza.vcx > item.gotfocus, ca sa se afiseza si marca responsabilului

*!*	12.12.2024
*!*	marius.mutu
*!*	caut_client_contract_activ - nu se iau contracte active de pe clienti inactivi

*!*	27.07.2026
*!*	marius.mutu
*!*	verificare ANAF la alegerea partenerului: banda de stare sub gridul de cautare arata starea la data
*!*	documentului, codul fiscal invalid, inexistent la ANAF sau nenumeric pe randul curent, imediat ce apar
*!*	rezultatele cautarii si la fiecare schimbare de rand; F4 deschide detaliile, iar alegerea altei variante
*!*	de partener se propune doar cand codul difera de ANAF; optiunea RC_ANAF_VERIF_SELECTIE; cand serviciul
*!*	ANAF nu raspunde, verificarile se opresc pe 10 minute si banda arata ca au fost sarite; la deschiderea
*!*	formularului, daca starea serviciului nu e cunoscuta, pleaca o sonda asincrona care stabileste
*!*	disponibilitatea fara sa blocheze interfata, iar randul curent asteapta rezultatul ei

*!*	27.07.2026
*!*	marius.mutu
*!*	verificare ANAF: banda de stare arata si perioada de inregistrare in scopuri de TVA, cu eticheta
*!*	explicita ('inregistrat TVA' / 'cod TVA anulat din'), doar cand starea difera de ROA, partenerul e
*!*	inactiv sau perioada s-a incheiat deja; F4 arata intotdeauna perioada completa si mesajul primit
*!*	de la ANAF, inclusiv cand nu exista partener cu codul corect

*!*	28.07.2026
*!*	marius.mutu
*!*	optiunea de verificare ANAF arata separat setarea utilizatorului, setarea firmei, implicitul
*!*	programului si starea de pe calculator; utilizatorul isi poate sterge propria setare, ca sa revina
*!*	la setarea firmei sau la implicitul programului

*!*	30.07.2026
*!*	marius.mutu
*!*	verificare ANAF: cand serviciul e cazut sau apelul esueaza, verdictul se citeste din istoricul de
*!*	coduri fiscale (cache Oracle), daca istoricul are ceva proaspat; banda de stare si detaliile (F4)
*!*	arata atunci data verificarii citite din istoric, cu mentiune explicita cand ANAF e indisponibil;
*!*	ordinea de incercare ANAF/istoric e configurabila per firma

*!*	02.08.2026
*!*	marius.mutu
*!*	verificarea ANAF se poate cere si la caut_partener (parametri optionali de verificare
*!*	si de data a documentului), pentru achizitia de import si pentru schimbarea furnizorului pe rulaj

*!*	#DEFINE CRLF CHR(13) + CHR(10)
#INCLUDE COMUN\ROA.H

Procedure ANAF_StarePartener
	Lparameters tcCodFiscal, tdData, tlDoarCache, tlNecesitaApel, tlNegasit, tcClasaEsec, tnTipPersoana

	Local lcCodFiscal, lcCui, loRezANAF, lcCheieCache, lnI, llValid, loOut, ldData, llNegasit, lcStareServiciu
	Local lcOrdine, loVerificareANAF As "VerificareANAF", lcSelectOrig

	tlNecesitaApel = .F.
	tlNegasit = .F.
	tcClasaEsec = ''
	*** guard mediu partajat - ocautare.prg e inclus si de alte produse ROA fara validare.prg/goLog incarcate
	If !('VALIDARE' $ Upper(Set('Procedure'))) Or Type('goLog') <> 'O'
		Return .Null.
	Endif
	lcCodFiscal = Alltrim(Nvl(m.tcCodFiscal, ''))
	If Empty(m.lcCodFiscal)
		Return .Null.
	Endif
	*** normalizare + excludere persoane fizice (CNP 13 cifre) / semnalizare coduri nenumerice dupa eliminarea RO
	lcCui = NormalizeazaCUI(m.lcCodFiscal)
	llValid = !Empty(m.lcCui)
	If m.llValid
		For lnI = 1 To Len(m.lcCui)
			If !Isdigit(Substr(m.lcCui, lnI, 1))
				llValid = .F.
				Exit
			Endif
		Endfor
	Endif
	If m.llValid And Len(m.lcCui) = 13 And !(Vartype(m.tnTipPersoana) = 'N' And m.tnTipPersoana = 1)
		tcClasaEsec = 'CNP'
		Return .Null.
	Endif
	If !m.llValid
		tcClasaEsec = 'COD_NENUMERIC'
		Return .Null.
	Endif
	ldData = ANAF_CaData(m.tdData)
	If Empty(m.ldData) And Type('poAct.dataact') $ 'DT'
		ldData = ANAF_CaData(poAct.dataact)
	Endif
	If Empty(m.ldData)
		ldData = Date()
	Endif
	*** cache pe sesiune (cheie = CUI normalizat + data verificarii) + apel ANAF (wrapper single-CUI, validare.prg), fara Wait Window
	If Type('goCacheANAF_Sesiune') <> 'O'
		Public goCacheANAF_Sesiune
		goCacheANAF_Sesiune = Createobject('Collection')
	Endif
	lcCheieCache = 'C' + m.lcCui + '_' + Dtos(m.ldData)
	If goCacheANAF_Sesiune.GetKey(m.lcCheieCache) = 0
		*** ordinea ANAF/istoric (OPTIUNI.ANAFCACHEORDINE_UNIC, VerificareANAF.OrdineCache din validare.prg);
		*** implicit ANAF,CACHE - pe CACHE,ANAF se incearca intai istoricul, iar apelul ANAF se sare cand e proaspat
		lcOrdine = 'ANAF,CACHE'
		lcSelectOrig = Select()
		Try
			loVerificareANAF = Createobject("VerificareANAF")
			lcOrdine = loVerificareANAF.OrdineCache('UNIC')
		Catch
		Endtry
		If Select() <> m.lcSelectOrig And Used(m.lcSelectOrig)
			Select (m.lcSelectOrig)
		Endif
		If m.lcOrdine == 'CACHE,ANAF'
			loRezANAF = ANAF_CitesteDinIstoric(m.lcCui, m.ldData, 'CACHE')
		Endif
		If Vartype(m.loRezANAF) <> 'O'
			lcStareServiciu = ANAF_StareServiciu()
			Do Case
				Case m.lcStareServiciu == 'CAZUT'
					tlNecesitaApel = .F.
					tcClasaEsec = 'FARA_RASPUNS'
					*** plasa de siguranta: ANAF cazut - verdict din istoric, daca e proaspat, etichetat distinct
					loRezANAF = ANAF_CitesteDinIstoric(m.lcCui, m.ldData, 'CACHE_INDISP')
					If Vartype(m.loRezANAF) = 'O'
						tcClasaEsec = ''
					Endif
				Case m.lcStareServiciu == 'SE_TESTEAZA'
					tlNecesitaApel = .T.
					tcClasaEsec = 'SE_TESTEAZA'
				Otherwise
					tlNecesitaApel = .T.
					If !m.tlDoarCache
						llNegasit = .F.
						loRezANAF = ANAF_VerificaCuiSingle(m.lcCui, m.ldData, @llNegasit, @tcClasaEsec)
						Do Case
							Case m.tcClasaEsec == 'FARA_RASPUNS'
								ANAF_SeteazaStareServiciu('CAZUT', 'CUI=' + m.lcCui)
								*** plasa de siguranta: apelul a esuat - acelasi fallback pe istoric
								loRezANAF = ANAF_CitesteDinIstoric(m.lcCui, m.ldData, 'CACHE_INDISP')
								If Vartype(m.loRezANAF) = 'O'
									tcClasaEsec = ''
								Endif
							Case m.tcClasaEsec == ''
								ANAF_SeteazaStareServiciu('VIU', 'CUI=' + m.lcCui)
						Endcase
					Endif
			Endcase
		Endif
		If Vartype(m.loRezANAF) = 'O'
			goCacheANAF_Sesiune.Add(m.loRezANAF, m.lcCheieCache)
		Endif
	Else
		loRezANAF = goCacheANAF_Sesiune.Item(m.lcCheieCache)
	Endif
	If Vartype(m.loRezANAF) <> 'O'
		tlNegasit = m.llNegasit
		Return .Null.
	Endif
	*** verdict
	loOut = Createobject("Empty")
	Addproperty(loOut, "cCui", m.lcCui)
	Addproperty(loOut, "lAreRO", Left(Upper(Alltrim(m.lcCodFiscal)), 2) = 'RO')
	Addproperty(loOut, "lPlatitorANAF", loRezANAF.scpTVA)
	Addproperty(loOut, "lInactivANAF", loRezANAF.statusInactivi)
	Addproperty(loOut, "cDenumireANAF", Alltrim(Nvl(loRezANAF.denumire, '')))
	Addproperty(loOut, "lDiscordanta", (loRezANAF.scpTVA <> loOut.lAreRO) Or loRezANAF.statusInactivi)
	Addproperty(loOut, "dInceputScpTVA", Iif(Pemstatus(loRezANAF, 'dInceputScpTVA', 5), Nvl(loRezANAF.dInceputScpTVA, {}), {}))
	Addproperty(loOut, "dSfarsitScpTVA", Iif(Pemstatus(loRezANAF, 'dSfarsitScpTVA', 5), Nvl(loRezANAF.dSfarsitScpTVA, {}), {}))
	Addproperty(loOut, "dAnulareScpTVA", Iif(Pemstatus(loRezANAF, 'dAnulareScpTVA', 5), Nvl(loRezANAF.dAnulareScpTVA, {}), {}))
	Addproperty(loOut, "cMesajScpTVA", Iif(Pemstatus(loRezANAF, 'cMesajScpTVA', 5), Alltrim(Nvl(loRezANAF.cMesajScpTVA, '')), ''))
	Addproperty(loOut, "dData", m.ldData)
	Addproperty(loOut, "cSursa", Iif(Pemstatus(loRezANAF, 'cSursa', 5), loRezANAF.cSursa, 'ANAF'))
	Addproperty(loOut, "dDataSursa", Iif(Pemstatus(loRezANAF, 'dDataSursa', 5), Nvl(loRezANAF.dDataSursa, {}), {}))
	Return loOut
Endproc && ANAF_StarePartener

*************************************
*** Citeste din ISTORIC_CODURI_FISCALE (VerificareANAF.CitesteIstoricPentruCoduri, validare.prg) verdictul
*** cache pentru un singur CUI normalizat, daca e proaspat; tcSursa eticheteaza rezultatul ('CACHE' sau
*** 'CACHE_INDISP'). Intoarce .NULL. cand istoricul nu are nimic proaspat pentru codul dat, fara eroare
*************************************
Procedure ANAF_CitesteDinIstoric
	Lparameters tcCui, tdData, tcSursa

	Local loVerificareANAF As "VerificareANAF", lcAliasCache, loRez, lcSelectOrig
	loRez = .Null.
	lcAliasCache = 'crsANAFIstoricOcautare'
	lcSelectOrig = Select()
	Try
		Use In (Select(m.lcAliasCache))
		loVerificareANAF = Createobject("VerificareANAF")
		loVerificareANAF.CitesteIstoricPentruCoduri(m.tcCui, m.tdData, m.lcAliasCache)
		If Used(m.lcAliasCache) And Reccount(m.lcAliasCache) > 0
			Select (m.lcAliasCache)
			Go Top
			If !Empty(Nvl(denumire, ''))
				loRez = Createobject("Empty")
				Addproperty(loRez, "cui", cui)
				Addproperty(loRez, "scpTVA", Nvl(scpTVA, .F.))
				Addproperty(loRez, "statusInactivi", Nvl(statusInactivi, .F.))
				Addproperty(loRez, "denumire", Nvl(denumire, ""))
				Addproperty(loRez, "mesaj", Nvl(mesaj, ""))
				Addproperty(loRez, "dInceputScpTVA", Nvl(data_inceput_ScpTVA, {}))
				Addproperty(loRez, "dSfarsitScpTVA", Nvl(data_sfarsit_ScpTVA, {}))
				Addproperty(loRez, "dAnulareScpTVA", Nvl(data_anul_imp_ScpTVA, {}))
				Addproperty(loRez, "cMesajScpTVA", Nvl(mesaj_ScpTVA, ""))
				Addproperty(loRez, "cSursa", m.tcSursa)
				Addproperty(loRez, "dDataSursa", Nvl(data_sursa, {}))
			Endif
		Endif
	Catch
		loRez = .Null.
	Endtry
	If Used(m.lcAliasCache)
		Use In (Select(m.lcAliasCache))
	Endif
	If Select() <> m.lcSelectOrig And Used(m.lcSelectOrig)
		Select (m.lcSelectOrig)
	Endif
	Return m.loRez
Endproc && ANAF_CitesteDinIstoric

Procedure ANAF_StareServiciu
	If Type('gcANAF_StareServiciu') = 'U'
		Public gcANAF_StareServiciu, gtANAF_StareServiciuMoment, gnANAF_StareServiciuStamp
		gcANAF_StareServiciu = 'NECUNOSCUT'
		gtANAF_StareServiciuMoment = Datetime()
		gnANAF_StareServiciuStamp = 0
	Endif
	If gcANAF_StareServiciu == 'CAZUT' And (Datetime() - gtANAF_StareServiciuMoment) >= 600
		ANAF_SeteazaStareServiciu('NECUNOSCUT', 'expirare CAZUT dupa 10 minute')
	Endif
	Return gcANAF_StareServiciu
Endproc && ANAF_StareServiciu

Procedure ANAF_SeteazaStareServiciu
	Lparameters tcStare, tcMotiv
	If Type('gcANAF_StareServiciu') = 'U'
		ANAF_StareServiciu()
	Endif
	If gcANAF_StareServiciu == m.tcStare
		Return
	Endif
	If Type('goLog') = 'O'
		goLog.Log('ANAF stare serviciu: ' + gcANAF_StareServiciu + ' -> ' + m.tcStare + ' (' + Alltrim(Nvl(m.tcMotiv, '')) + ')', 'anaf_verif_cautare')
	Endif
	gcANAF_StareServiciu = m.tcStare
	gtANAF_StareServiciuMoment = Datetime()
	gnANAF_StareServiciuStamp = gnANAF_StareServiciuStamp + 1
Endproc && ANAF_SeteazaStareServiciu

*** interogheaza sonda de disponibilitate (validare.prg) din timerul existent; termen de viata 10 secunde,
*** guard de reintrare (timerele VFP pot trage in timpul pomparii de mesaje dintr-un AMESSAGEBOX)
Procedure ANAF_SondaVerifica
	Local llReusit
	If ANAF_StareServiciu() <> 'SE_TESTEAZA'
		Return
	Endif
	If Type('glANAF_SondaInterogareInCurs') = 'U'
		Public glANAF_SondaInterogareInCurs
		glANAF_SondaInterogareInCurs = .F.
	Endif
	If glANAF_SondaInterogareInCurs
		Return
	Endif
	glANAF_SondaInterogareInCurs = .T.
	Try
		If (Datetime() - gtANAF_StareServiciuMoment) >= 10
			ANAF_SondaOpreste()
			ANAF_SeteazaStareServiciu('CAZUT', 'sonda expirata dupa 10 secunde')
		Else
			If ANAF_SondaAuSositRaspunsul()
				llReusit = ANAF_SondaAReusit()
				ANAF_SondaOpreste()
				ANAF_SeteazaStareServiciu(Iif(m.llReusit, 'VIU', 'CAZUT'), 'sonda de disponibilitate')
			Endif
		Endif
	Finally
		glANAF_SondaInterogareInCurs = .F.
	Endtry
Endproc && ANAF_SondaVerifica

Procedure ANAF_ValidareCod
	Lparameters tcCodFiscal, tnTipPersoana

	Local lcCodFiscal, lcCui, loVerificareCod, lnTipPersoana, llCnp
	If !('VALIDARE' $ Upper(Set('Procedure')))
		Return ''
	Endif
	lcCodFiscal = Alltrim(Nvl(m.tcCodFiscal, ''))
	If Empty(m.lcCodFiscal)
		Return ''
	Endif
	loVerificareCod = Createobject("VerificareCod")
	lcCui = NormalizeazaCUI(m.lcCodFiscal)
	lnTipPersoana = Nvl(m.tnTipPersoana, 0)
	llCnp = Iif(m.lnTipPersoana = 2, .T., Iif(m.lnTipPersoana = 1, .F., Len(m.lcCui) = 13))
	If m.llCnp
		Return Iif(loVerificareCod.VALIDARE_CNP(m.lcCui), '', 'CNP invalid (' + m.lcCui + ')')
	Endif
	Return Iif(loVerificareCod.VALIDARE_CIF(m.lcCui), '', 'CIF invalid (' + m.lcCui + ')')
Endproc && ANAF_ValidareCod

Procedure ANAF_CaData
	*** data documentului poate veni si ca DateTime (ex. tact.dataact din note contabile)
	Lparameters tuValoare
	Do Case
		Case Vartype(m.tuValoare) = 'D'
			Return m.tuValoare
		Case Vartype(m.tuValoare) = 'T'
			Return Ttod(m.tuValoare)
		Otherwise
			Return {}
	Endcase
Endproc && ANAF_CaData

Procedure ANAF_NivelVerificare
	*** cascada RC_ANAF_VERIF_SELECTIE: 0=oprit, 1=verdict pe rand (implicit), 2=rezervat (tratat ca 1), 3=verdict+confirmare
	Local lcSel, lcCheie, lnNivel, lcVal

	*** kill-switch - doar valoarea explicita '0' opreste; absenta NU seteaza nivelul
	If Alltrim(Nvl(getini(gcGeneralIniFile, 'anaf', 'verificare_selectie'), '')) == '0'
		Return 0
	Endif

	*** cache pe sesiune - cheia (schema + utilizator) invalideaza automat la schimbarea firmei/utilizatorului
	lcCheie = 'N' + Iif(Type('gcS') = 'C', gcS, '') + '_' + Iif(Type('gnIdUtil') = 'N', Transform(gnIdUtil), '')
	If Type('goCacheANAF_Nivel') <> 'O'
		Public goCacheANAF_Nivel
		goCacheANAF_Nivel = Createobject('Collection')
	Endif
	If goCacheANAF_Nivel.GetKey(m.lcCheie) <> 0
		Return goCacheANAF_Nivel.Item(m.lcCheie)
	Endif

	lnNivel = 1
	lcSel = Select()
	If 'OINIT_OPTIUNI' $ Upper(Set('Procedure'))
		lcVal = Iif(Used('crsOptiuniUtilizator'), Alltrim(Nvl(citeste_optiune_utilizator('RC_ANAF_VERIF_SELECTIE'), '')), '')
		If Empty(m.lcVal) And Used('crsOptiuni')
			lcVal = Alltrim(Nvl(citeste_optiune('RC_ANAF_VERIF_SELECTIE'), ''))
		Endif
		If !Empty(m.lcVal)
			lnNivel = Int(Val(m.lcVal))
		Endif
	Endif
	Select (m.lcSel)

	goCacheANAF_Nivel.Add(m.lnNivel, m.lcCheie)
	Return m.lnNivel
Endproc && ANAF_NivelVerificare

Procedure ANAF_CautaPereche
	Lparameters tcCui, tcCursor

	Local lcSelect, lnSucces
	lcSelect = [SELECT ID_PART, DENUMIRE, COD_FISCAL, INACTIV FROM NOM_PARTENERI ] + ;
		[WHERE STERS = 0 AND (UPPER(REPLACE(COD_FISCAL,' ','')) = '] + m.tcCui + [' ] + ;
		[OR UPPER(REPLACE(COD_FISCAL,' ','')) = 'RO] + m.tcCui + [') ORDER BY UPPER(DENUMIRE), ID_PART]
	If Used(m.tcCursor)
		Use In (m.tcCursor)
	Endif
	lnSucces = goExecutor.oExecute(m.lcSelect, m.tcCursor)
	If m.lnSucces < 0
		goLog.Log('ANAF_CautaPereche: ' + goExecutor.cEroare, 'ANAF_CautaPereche')
		If Used(m.tcCursor)
			Use In (m.tcCursor)
		Endif
		Return .F.	&& degradare tacuta
	Endif
	Return .T.
Endproc && ANAF_CautaPereche

Procedure AplicaInlocuirePartenerANAF
	Lparameters toPartener, toInlocuire, tcTipuriParteneri

	Local lnRecCnt
	If Vartype(m.toInlocuire) <> 'O' Or Isnull(m.toPartener) Or Type('toPartener.id_part') <> 'N'
		Return
	Endif
	toPartener.id_part = toInlocuire.nIdPart
	If Type('toPartener.denumire') = 'C'
		toPartener.denumire = toInlocuire.cDenumire
	Endif
	If Type('toPartener.nume') = 'C'
		toPartener.nume = toInlocuire.cDenumire
	Endif
	toPartener.cod_fiscal = toInlocuire.cCodFiscal
	*** recalculeaza tip pentru id-ul perechii, acelasi criteriu ca SELECT-ul gridului (coresp_tip_part)
	If Type('toPartener.tip') = 'N' And !Empty(Nvl(m.tcTipuriParteneri, ''))
		lnRecCnt = 0
		goExecutor.oSelect2Value([SELECT COUNT(*) AS NR FROM CORESP_TIP_PART WHERE ID_PART = ] + Transform(toInlocuire.nIdPart) + ;
			[ AND ID_TIP_PART IN (] + m.tcTipuriParteneri + [)], @lnRecCnt)
		toPartener.tip = Iif(Nvl(m.lnRecCnt, 0) > 0, 0, 1)
	Endif
	goLog.Log('ANAF: inlocuire partener -> id_part=' + Transform(toInlocuire.nIdPart), 'AplicaInlocuirePartenerANAF')
Endproc && AplicaInlocuirePartenerANAF

Procedure ANAF_ComutaVerificare
	*** valori: 0 = oprit, 1 = starea pe randul curent, 3 = starea si confirmarea la partener discordant, 9 = oprit pe acest calculator
	Local lcSel, lcOptiune, lcEticheta, lcValIni, lcValUtil, lcValFirma, lcSursa, lnNivel, lnNou, lcMesaj, lnRasp

	lcEticheta = 'Verificare ANAF la alegerea partenerului'
	lcOptiune = 'RC_ANAF_VERIF_SELECTIE'
	lcSel = Select()
	lcValIni = Alltrim(Nvl(getini(gcGeneralIniFile, 'anaf', 'verificare_selectie'), ''))
	lcValUtil = ''
	lcValFirma = ''
	If 'OINIT_OPTIUNI' $ Upper(Set('Procedure'))
		lcValUtil = Iif(Used('crsOptiuniUtilizator'), Alltrim(Nvl(citeste_optiune_utilizator(m.lcOptiune), '')), '')
		lcValFirma = Iif(Used('crsOptiuni'), Alltrim(Nvl(citeste_optiune(m.lcOptiune), '')), '')
	Endif
	Select (m.lcSel)

	lnNivel = ANAF_NivelVerificare()
	Do Case
		Case m.lcValIni == '0'
			lcSursa = 'oprita pe acest calculator (settings.ini)'
		Case !Empty(m.lcValUtil)
			lcSursa = 'setata pentru utilizatorul curent'
		Case !Empty(m.lcValFirma)
			lcSursa = 'setata pentru firma'
		Otherwise
			lcSursa = 'implicita'
	Endcase

	lcMesaj = 'Acum: ' + Transform(m.lnNivel) + ' - ' + ANAF_TextNivel(m.lnNivel) + Chr(13) + ;
		'(' + m.lcSursa + ')' + Chr(13) + Chr(13) + ;
		'  Utilizatorul curent : ' + ANAF_TextSetare(m.lcValUtil) + Chr(13) + ;
		'  Firma               : ' + ANAF_TextSetare(m.lcValFirma) + Chr(13) + ;
		'  Implicit program    : 1 - ' + ANAF_TextNivel(1) + Chr(13) + ;
		'  Acest calculator    : ' + Iif(m.lcValIni == '0', 'verificare oprita', 'verificare pornita') + Chr(13) + Chr(13) + ;
		'  0 = ' + ANAF_TextNivel(0) + Chr(13) + ;
		'  1 = ' + ANAF_TextNivel(1) + Chr(13) + ;
		'  3 = ' + ANAF_TextNivel(3) + Chr(13) + ;
		'  9 = ' + ANAF_TextNivel(9) + Chr(13) + Chr(13) + ;
		'Valorile 0, 1 si 3 va urmaresc pe orice calculator.' + Chr(13) + Chr(13) + ;
		'Da = aleg o valoare, Nu = revin la setarea firmei / implicita, Renunta = las asa'
	lnRasp = Amessagebox(m.lcMesaj, 3 + 32, m.lcEticheta)
	If m.lnRasp = 7
		ANAF_ReseteazaVerificare(m.lcOptiune, m.lcEticheta, m.lcValUtil, m.lcValFirma)
		Return
	Endif
	If m.lnRasp <> 6
		Return
	Endif
	lnNou = aInputBox('Valoarea noua (0, 1, 3 sau 9):', m.lcEticheta, Iif(m.lcValIni == '0', 9, m.lnNivel))
	If Vartype(m.lnNou) <> 'N' Or !Inlist(m.lnNou, 0, 1, 3, 9)
		Return
	Endif

	If m.lnNou = 9
		setini(gcGeneralIniFile, 'anaf', 'verificare_selectie', '0')
	Else
		If m.lcValIni == '0'
			setini(gcGeneralIniFile, 'anaf', 'verificare_selectie', '1')
		Endif
		If !('OINIT_OPTIUNI' $ Upper(Set('Procedure'))) Or !Used('crsOptiuniUtilizator')
			Amessagebox('Optiunea nu poate fi salvata: lipseste lista de optiuni ale utilizatorului.', 0 + 48, lcEticheta)
			Return
		Endif
		lcSel = Select()
		scrie_optiune_utilizator(m.lcOptiune, Alltrim(Str(m.lnNou)), 'VERIFICARE ANAF LA ALEGEREA PARTENERULUI')
		Select (m.lcSel)
	Endif
	If Type('goCacheANAF_Nivel') = 'O'
		Release goCacheANAF_Nivel
	Endif
Endproc && ANAF_ComutaVerificare

Procedure ANAF_ReseteazaVerificare
	Lparameters tcOptiune, tcEticheta, tcValUtil, tcValFirma

	Local lnNivel
	If Empty(m.tcValUtil)
		Amessagebox('Nu exista o setare proprie de sters: se foloseste deja ' + ;
			Iif(Empty(m.tcValFirma), 'valoarea implicita a programului.', 'setarea firmei.'), 0 + 64, m.tcEticheta)
		Return
	Endif
	If !ANAF_StergeOptiuneUtilizator(m.tcOptiune)
		Return
	Endif
	If Type('goCacheANAF_Nivel') = 'O'
		Release goCacheANAF_Nivel
	Endif
	lnNivel = ANAF_NivelVerificare()
	Amessagebox('Acum: ' + Transform(m.lnNivel) + ' - ' + ANAF_TextNivel(m.lnNivel), 0 + 64, m.tcEticheta)
Endproc && ANAF_ReseteazaVerificare

Procedure ANAF_StergeOptiuneUtilizator
	Lparameters tcOptiune

	Local lcSel, lcSql, lnSucces
	lcSel = Select()
	lcSql = [DELETE FROM OPTIUNI_UTIL WHERE UPPER(VARNAME) = '] + Upper(Alltrim(m.tcOptiune)) + ;
		[' AND ID_UTIL = ] + Transform(gnIdUtil)
	lnSucces = goExecutor.oExecute(m.lcSql)
	If m.lnSucces < 0
		Amessagebox(goExecutor.cEroare, 0 + 16, 'Eroare')
		Select (m.lcSel)
		Return .F.
	Endif
	actualizeaza_optiuni_utilizator()
	Select (m.lcSel)
	Return .T.
Endproc && ANAF_StergeOptiuneUtilizator

Procedure ANAF_TextSetare
	Lparameters tcVal

	Local lnNivel
	If Empty(Nvl(m.tcVal, ''))
		Return 'nesetata'
	Endif
	lnNivel = Int(Val(m.tcVal))
	Return Transform(m.lnNivel) + ' - ' + ANAF_TextNivel(m.lnNivel)
Endproc && ANAF_TextSetare

Procedure ANAF_TextNivel
	Lparameters tnNivel
	Do Case
		Case m.tnNivel = 0
			Return 'fara verificare'
		Case m.tnNivel = 9
			Return 'oprita pe acest calculator, pentru toti utilizatorii lui'
		Case m.tnNivel >= 3
			Return 'arata starea si intreaba la alegerea unui partener discordant'
		Otherwise
			Return 'arata starea partenerului la ANAF pe randul curent'
	Endcase
Endproc && ANAF_TextNivel

DEFINE CLASS anaf_timer AS Timer
	oOwner = .Null.
	Interval = 400
	Enabled = .F.

	PROCEDURE Timer
		This.Enabled = .F.
		ANAF_SondaVerifica()
		If Vartype(This.oOwner) = 'O'
			This.oOwner.EvalueazaRand(.T.)
		Endif
	ENDPROC
ENDDEFINE

DEFINE CLASS anaf_label AS Label
	FontName = 'Arial'
	FontSize = 10
	BackStyle = 0
ENDDEFINE

DEFINE CLASS anaf_verif_cautare AS Custom
	oForm = .Null.
	oTimer = .Null.
	nIdPart = 0
	oStare = .Null.
	cCui = ''
	dDataDoc = {}
	oCandidati = .Null.
	nNivel = 1
	lNegasit = .F.
	lDecis = .F.
	lVerificareInCurs = .F.
	nStareServiciuStamp = 0
	cClasaEsec = ''

	PROCEDURE Activeaza
		Lparameters toForm
		Local lcCursor, llCreat
		If Vartype(m.toForm) <> 'O' Or toForm.lAles
			Return
		Endif
		lcCursor = toForm.crs_cursor
		If !Used(m.lcCursor) Or Type(m.lcCursor + '.cod_fiscal') <> 'C' Or Type(m.lcCursor + '.id_part') <> 'N'
			Return
		Endif
		llCreat = .F.
		Try
			toForm.NewObject('lb_anaf', '_label', '_baza.vcx')
			llCreat = .T.
		Catch
			llCreat = .F.
		Endtry
		If !m.llCreat
			Try
				toForm.AddObject('lb_anaf', 'anaf_label')
				llCreat = .T.
			Catch
				llCreat = .F.
			Endtry
		Endif
		If !m.llCreat
			Return
		Endif
		This.oForm = toForm
		This.oTimer = Createobject('anaf_timer')
		This.oTimer.oOwner = This
		If Type('toForm._GRID1') = 'O' And Bitand(toForm._GRID1.Anchor, 8) = 8
			toForm._GRID1.Anchor = toForm._GRID1.Anchor - 8	&& inaltimea gridului o dau eu, in AjusteazaBanda
		Endif
		toForm.Height = toForm.Height + 54
		With toForm.lb_anaf
			.AutoSize = .F.
			.BackStyle = 1
			.BackColor = Rgb(240, 240, 240)
			.WordWrap = .T.
			.MousePointer = 15
			.Left = 8
			.Width = toForm.Width - 20
			.Height = 46
			.Top = toForm.Height - 50
			.Caption = ''
			.Visible = .T.
			.Anchor = 14
		Endwith
		Bindevent(toForm.lb_anaf, 'Click', This, 'Detalii')
		Bindevent(toForm, 'Resize', This, 'AjusteazaBanda')
		Bindevent(toForm, 'Activate', This, 'AjusteazaBanda')
		If Pemstatus(toForm, 'do_cauta', 5)
			Bindevent(toForm, 'do_cauta', This, 'DupaCautare', 1)
		Endif
		If ANAF_StareServiciu() == 'NECUNOSCUT'
			If ANAF_SondaPorneste()
				ANAF_SeteazaStareServiciu('SE_TESTEAZA', 'sonda pornita la deschidere formular')
			Endif
		Endif
		This.AjusteazaBanda()
		Bindevent(toForm._GRID1, 'AfterRowColChange', This, 'DupaRand')
		This.AfiseazaPrompt()
	ENDPROC

	PROCEDURE AjusteazaBanda
		*** gridul ramane ancorat jos; il opresc doar sa intre peste banda labelului
		Local lnMax
		If Vartype(This.oForm) <> 'O' Or Type('This.oForm._GRID1') <> 'O'
			Return
		Endif
		If Bitand(This.oForm._GRID1.Anchor, 8) = 8
			This.oForm._GRID1.Anchor = This.oForm._GRID1.Anchor - 8
		Endif
		lnMax = This.oForm.Height - 58 - This.oForm._GRID1.Top
		If m.lnMax > 60
			This.oForm._GRID1.Height = m.lnMax
		Endif
	ENDPROC

	PROCEDURE Dezactiveaza
		Local llSondaOprita
		llSondaOprita = ANAF_SondaOpreste()
		If m.llSondaOprita And ANAF_StareServiciu() == 'SE_TESTEAZA'
			ANAF_SeteazaStareServiciu('NECUNOSCUT', 'formular inchis cu sonda in aer')
		Endif
		If Vartype(This.oTimer) = 'O'
			This.oTimer.Enabled = .F.
			This.oTimer.oOwner = .Null.
			This.oTimer = .Null.
		Endif
		If Vartype(This.oForm) = 'O'
			Try
				Unbindevents(This.oForm, 'Resize', This, 'AjusteazaBanda')
				Unbindevents(This.oForm, 'Activate', This, 'AjusteazaBanda')
				Unbindevents(This.oForm, 'do_cauta', This, 'DupaCautare')
			Catch
			Endtry
			If Type('This.oForm.lb_anaf') = 'O'
				Try
					Unbindevents(This.oForm.lb_anaf)
				Catch
				Endtry
			Endif
			If Type('This.oForm._GRID1') = 'O'
				Try
					Unbindevents(This.oForm._GRID1)
				Catch
				Endtry
			Endif
		Endif
		This.oForm = .Null.
	ENDPROC

	PROCEDURE DupaRand
		Lparameters nColIndex
		This.EvalueazaRand(.F.)
	ENDPROC

	PROCEDURE DupaCautare
		This.EvalueazaRand(.T.)
	ENDPROC

	PROCEDURE VerificaRand
		Lparameters tlSincron
		Return This.EvalueazaRand(.T.)
	ENDPROC

	PROCEDURE EvalueazaRand
		Lparameters tlPermiteApel
		Local lcCursor, lnId, lcCodFiscal, loStare, lnTipPersoana, lcCodInvalid, llNecesitaApel, llNegasit, lcClasaEsec
		If Vartype(This.oForm) <> 'O'
			Return .F.
		Endif
		If Vartype(This.oTimer) = 'O'
			This.oTimer.Enabled = .F.
		Endif
		lcCursor = This.oForm.crs_cursor
		If !Used(m.lcCursor) Or Reccount(m.lcCursor) = 0
			This.nIdPart = 0
			This.oStare = .Null.
			This.cCui = ''
			This.lNegasit = .F.
			This.cClasaEsec = ''
			This.AfiseazaPrompt()
			Return .F.
		Endif
		lnId = Nvl(Evaluate(m.lcCursor + '.id_part'), 0)
		lcCodFiscal = Alltrim(Nvl(Evaluate(m.lcCursor + '.cod_fiscal'), ''))
		If m.lnId = 0
			This.AfiseazaPrompt()
			Return .F.
		Endif
		If Type('gnANAF_StareServiciuStamp') = 'N' And gnANAF_StareServiciuStamp <> This.nStareServiciuStamp
			This.nStareServiciuStamp = gnANAF_StareServiciuStamp
			This.nIdPart = 0
		Endif
		If m.lnId = This.nIdPart
			Return !Isnull(This.oStare)
		Endif
		lnTipPersoana = Iif(Type(m.lcCursor + '.tip_persoana') = 'N', Nvl(Evaluate(m.lcCursor + '.tip_persoana'), 0), 0)
		lcCodInvalid = ANAF_ValidareCod(m.lcCodFiscal, m.lnTipPersoana)
		If !Empty(m.lcCodInvalid)
			This.nIdPart = m.lnId
			This.oStare = .Null.
			This.cCui = ''
			This.lNegasit = .F.
			This.cClasaEsec = 'COD_INVALID'
			This.SeteazaLabel(m.lcCodInvalid + '  (F4 = detalii)', .T.)
			goLog.Log('Cod fiscal invalid: ' + m.lcCodInvalid + ' id_part=' + Transform(m.lnId), 'anaf_verif_cautare')
			Return .F.
		Endif
		If This.lVerificareInCurs
			Return .F.
		Endif
		llNecesitaApel = .F.
		llNegasit = .F.
		lcClasaEsec = ''
		This.lVerificareInCurs = .T.
		Try
			loStare = ANAF_StarePartener(m.lcCodFiscal, This.dDataDoc, !m.tlPermiteApel, @llNecesitaApel, @llNegasit, @lcClasaEsec, m.lnTipPersoana)
		Finally
			This.lVerificareInCurs = .F.
		Endtry
		If m.lcClasaEsec == 'SE_TESTEAZA'
			This.SeteazaLabel('ANAF: se verifica ' + Alltrim(m.lcCodFiscal) + '...', .F., .T.)
			If Vartype(This.oTimer) = 'O'
				This.oTimer.Enabled = .T.
			Endif
			Return .F.
		Endif
		If !m.tlPermiteApel And m.llNecesitaApel
			This.SeteazaLabel('ANAF: se verifica ' + Alltrim(m.lcCodFiscal) + '...', .F., .T.)
			If Vartype(This.oTimer) = 'O'
				This.oTimer.Enabled = .T.
			Endif
			Return .F.
		Endif
		This.nIdPart = m.lnId
		This.oStare = m.loStare
		This.lNegasit = m.llNegasit
		This.cClasaEsec = m.lcClasaEsec
		This.cCui = Iif(Isnull(m.loStare), '', loStare.cCui)
		Do Case
			Case Isnull(m.loStare) And m.llNegasit
				This.SeteazaLabel('Cod fiscal inexistent la ANAF (' + Alltrim(m.lcCodFiscal) + ')  (F4 = detalii)', .T.)
				goLog.Log('Cod fiscal inexistent la ANAF: ' + Alltrim(m.lcCodFiscal) + ' id_part=' + Transform(m.lnId), 'anaf_verif_cautare')
				Return .F.
			Case Isnull(m.loStare) And Inlist(m.lcClasaEsec, 'FARA_RASPUNS', 'RASPUNS_NEINTELES')
				This.SeteazaLabel('ANAF nu a raspuns - verificare sarita', .F., .T.)
				Return .F.
			Case Isnull(m.loStare) And m.lcClasaEsec == 'COD_NENUMERIC'
				This.SeteazaLabel('Cod fiscal nenumeric - nu se poate verifica la ANAF', .F., .T.)
				goLog.Log('Cod fiscal nenumeric: ' + Alltrim(m.lcCodFiscal) + ' id_part=' + Transform(m.lnId), 'anaf_verif_cautare')
				Return .F.
			Case Isnull(m.loStare) And m.lcClasaEsec == 'CNP'
				This.SeteazaLabel('Persoana fizica - CNP corect', .F., .T.)
				Return .F.
			Case Isnull(m.loStare)
				This.AfiseazaPrompt()
				Return .F.
			Case !loStare.lDiscordanta
				This.SeteazaLabel(This.TextAnaf(m.loStare, .F., 24) + '  (F4 = detalii)', .F.)
			Otherwise
				This.SeteazaLabel(This.TextAnaf(m.loStare, .F., 24) + '  (F4 = detalii)', .T.)
				goLog.Log('Discordanta ANAF: CUI=' + loStare.cCui + ' id_part=' + Transform(m.lnId) + ;
					' scpTVA=' + Transform(loStare.lPlatitorANAF) + ' inactivANAF=' + Transform(loStare.lInactivANAF), 'anaf_verif_cautare')
		Endcase
		Return .T.
	ENDPROC

	PROCEDURE AfiseazaPrompt
		This.SeteazaLabel('Verificare ANAF la alegerea partenerului (F4 = detalii)', .F., .T.)
	ENDPROC

	PROCEDURE SeteazaLabel
		Lparameters tcText, tlAvertisment, tlNeutru
		If Vartype(This.oForm) <> 'O'
			Return
		Endif
		With This.oForm.lb_anaf
			.Caption = Iif(Empty(m.tcText), '', ' ' + Chr(149) + '  ' + m.tcText)
			.ForeColor = Iif(m.tlAvertisment, Rgb(192, 0, 0), Iif(m.tlNeutru, Rgb(112, 112, 112), Rgb(0, 128, 0)))
			.FontBold = m.tlAvertisment
		Endwith
		This.oForm.lb_anaf.Refresh()
	ENDPROC

	PROCEDURE TextStare
		Lparameters toStare, tcPerioada
		Return Iif(toStare.lPlatitorANAF, 'Platitor TVA', 'Neplatitor TVA') + Nvl(m.tcPerioada, '') + Iif(toStare.lInactivANAF, ', Inactiv', '')
	ENDPROC

	PROCEDURE SufixPerioadaTVA
		Lparameters toStare
		If !(toStare.lDiscordanta Or !Empty(toStare.dAnulareScpTVA) Or (!Empty(toStare.dSfarsitScpTVA) And toStare.dSfarsitScpTVA < Date()))
			Return ''
		Endif
		Do Case
			Case !Empty(toStare.dAnulareScpTVA)
				Return ', cod TVA anulat din ' + Dtoc(toStare.dAnulareScpTVA)
			Case !Empty(toStare.dSfarsitScpTVA) And !Empty(toStare.dInceputScpTVA)
				Return ', inregistrat TVA ' + Dtoc(toStare.dInceputScpTVA) + ' - ' + Dtoc(toStare.dSfarsitScpTVA)
			Case !Empty(toStare.dInceputScpTVA)
				Return ', inregistrat TVA din ' + Dtoc(toStare.dInceputScpTVA)
		Endcase
		Return ''
	ENDPROC

	PROCEDURE TextAnaf
		Lparameters toStare, tlCuVirgula, tnMaxLen
		Local lcCodOk, lcDenANAF, lcDenFull, lcPerioada
		lcCodOk = Iif(toStare.lPlatitorANAF, 'RO', '') + toStare.cCui
		lcDenFull = Alltrim(Nvl(toStare.cDenumireANAF, ''))
		lcDenANAF = lcDenFull
		If Vartype(m.tnMaxLen) = 'N' And m.tnMaxLen > 0 And Len(m.lcDenFull) > m.tnMaxLen
			lcDenANAF = Left(m.lcDenFull, m.tnMaxLen) + '...'
		Endif
		lcPerioada = This.SufixPerioadaTVA(toStare)
		Return 'ANAF: ' + This.TextStare(toStare, m.lcPerioada) + ' (' + ;
			Iif(Empty(m.lcDenANAF), '', m.lcDenANAF + Iif(m.tlCuVirgula, ', ', ' ')) + m.lcCodOk + ')' + ;
			Iif(Empty(m.lcPerioada), ' la ' + Dtoc(toStare.dData), '') + ;
			This.SufixSursa(toStare)
	ENDPROC

	PROCEDURE SufixSursa
		Lparameters toStare
		*** eticheteaza verdictele care nu vin dintr-un raspuns ANAF proaspat, ci din istoricul cache (contract 4.5)
		If !Pemstatus(m.toStare, 'cSursa', 5)
			Return ''
		Endif
		*!* 01.08.2026 marius.mutu: marcaj explicit al sursei, la fel ca in grid si in dialogul de verificare
		Do Case
			Case toStare.cSursa == 'ANAF'
				Return ' (sursa: ANAF)'
			Case toStare.cSursa == 'CACHE'
				Return ' (sursa: CACHE ' + Dtoc(Nvl(toStare.dDataSursa, Date())) + ')'
			Case toStare.cSursa == 'CACHE_INDISP'
				Return ' (sursa: CACHE ' + Dtoc(Nvl(toStare.dDataSursa, Date())) + ', ANAF indisponibil)'
		Endcase
		Return ''
	ENDPROC

	PROCEDURE TextPerioadaTVA
		Lparameters toStare
		Local lcTxt
		lcTxt = ''
		If !Empty(toStare.dInceputScpTVA)
			lcTxt = m.lcTxt + 'Inceput inregistrare TVA: ' + Dtoc(toStare.dInceputScpTVA) + Chr(13)
		Endif
		If !Empty(toStare.dSfarsitScpTVA)
			lcTxt = m.lcTxt + 'Sfarsit inregistrare TVA: ' + Dtoc(toStare.dSfarsitScpTVA) + Chr(13)
		Endif
		If !Empty(toStare.dAnulareScpTVA)
			lcTxt = m.lcTxt + 'Anulare din oficiu: ' + Dtoc(toStare.dAnulareScpTVA) + Chr(13)
		Endif
		If !Empty(toStare.cMesajScpTVA)
			lcTxt = m.lcTxt + 'Mesaj ANAF: ' + Alltrim(toStare.cMesajScpTVA) + Chr(13)
		Endif
		If !Empty(m.lcTxt)
			lcTxt = m.lcTxt + Chr(13)
		Endif
		Return m.lcTxt
	ENDPROC

	PROCEDURE AntetDialog
		Lparameters tcDenAles, tcCodAles
		Local lcAntet
		lcAntet = Alltrim(m.tcDenAles) + '  (CUI: ' + Alltrim(m.tcCodAles) + ', ID: ' + Transform(This.nIdPart) + ')' + Chr(13) + Chr(13)
		If !Isnull(This.oStare)
			lcAntet = m.lcAntet + This.TextAnaf(This.oStare, .T.) + Chr(13) + Chr(13)
		Endif
		Return m.lcAntet
	ENDPROC

	PROCEDURE ListaCorecti
		Lparameters tnCandidati, tnCandidat, tcDenPereche, tlEroare
		Local lcCursorP, lcLista, lcCodOk, loCandidat
		lcCodOk = Iif(This.oStare.lPlatitorANAF, 'RO', '') + This.cCui
		lcLista = ''
		tnCandidati = 0
		tnCandidat = 0
		tcDenPereche = ''
		tlEroare = .F.
		This.oCandidati = Createobject('Collection')
		lcCursorP = Sys(2015)
		If ANAF_CautaPereche(This.cCui, m.lcCursorP)
			Select (m.lcCursorP)
			Scan For Chrtran(Upper(Alltrim(Nvl(cod_fiscal, ''))), ' ', '') == Upper(m.lcCodOk) And id_part <> This.nIdPart
				tnCandidati = m.tnCandidati + 1
				lcLista = m.lcLista + '  ' + Transform(m.tnCandidati) + '. ' + Alltrim(Nvl(denumire, '')) + ;
					' (ID: ' + Transform(id_part) + ')' + Iif(Nvl(inactiv, 0) = 1, '  inactiv', '') + Chr(13)
				loCandidat = Createobject('Empty')
				Addproperty(loCandidat, 'nIdPart', id_part)
				Addproperty(loCandidat, 'cDenumire', Alltrim(Nvl(denumire, '')))
				Addproperty(loCandidat, 'lInactiv', Nvl(inactiv, 0) = 1)
				Addproperty(loCandidat, 'lAreDocumente', .F.)
				This.oCandidati.Add(loCandidat)
				If m.tnCandidati = 1
					tnCandidat = id_part
					tcDenPereche = Alltrim(Nvl(denumire, ''))
				Endif
			Endscan
			Use In (m.lcCursorP)
		Else
			tlEroare = .T.
		Endif
		Return m.lcLista
	ENDPROC

	PROCEDURE MarcheazaDocumente
		*** discriminator "are documente in perioada" - un singur SELECT, apelat doar din Detalii
		Local lcSirId, lcCursorD, lnI, loCand
		If Vartype(This.oCandidati) <> 'O' Or This.oCandidati.Count = 0 Or Type('gnAn') <> 'N' Or Type('gnLuna') <> 'N'
			Return
		Endif
		lcSirId = ''
		For lnI = 1 To This.oCandidati.Count
			lcSirId = m.lcSirId + Iif(Empty(m.lcSirId), '', ',') + Transform(This.oCandidati.Item(m.lnI).nIdPart)
		Endfor
		lcCursorD = Sys(2015)
		If goExecutor.oExecute([SELECT DISTINCT ID_PART FROM IREG_PARTENERI WHERE AN = ] + Transform(gnAn) + ;
				[ AND LUNA = ] + Transform(gnLuna) + [ AND ID_PART IN (] + m.lcSirId + [)], m.lcCursorD) < 0
			goLog.Log('MarcheazaDocumente: ' + goExecutor.cEroare, 'anaf_verif_cautare')
			If Used(m.lcCursorD)
				Use In (m.lcCursorD)
			Endif
			Return
		Endif
		Select (m.lcCursorD)
		Scan
			For lnI = 1 To This.oCandidati.Count
				loCand = This.oCandidati.Item(m.lnI)
				If loCand.nIdPart = id_part
					loCand.lAreDocumente = .T.
				Endif
			Endfor
		Endscan
		Use In (m.lcCursorD)
	ENDPROC

	PROCEDURE TextListaCandidati
		Local lcLista, lnI, loCand
		lcLista = ''
		If Vartype(This.oCandidati) = 'O'
			For lnI = 1 To This.oCandidati.Count
				loCand = This.oCandidati.Item(m.lnI)
				lcLista = m.lcLista + '  ' + Transform(m.lnI) + '. ' + Alltrim(loCand.cDenumire) + ;
					' (ID: ' + Transform(loCand.nIdPart) + ')' + Iif(loCand.lInactiv, '  inactiv', '') + ;
					Iif(loCand.lAreDocumente, '  are documente in perioada', '') + Chr(13)
			Endfor
		Endif
		Return m.lcLista
	ENDPROC

	PROCEDURE Detalii
		Local lcCursor, lcDenAles, lcCodAles, lcCodOk, lcLista, lcMesaj, lnCandidati, lnCandidat, lcDenPereche
		Local lnRasp, lnAles, loAles, llEroare, lcPerioadaTVA
		If Vartype(This.oForm) <> 'O'
			Return
		Endif
		poANAFInlocuire = .Null.

		lcCursor = This.oForm.crs_cursor
		*** cursorul de cautare are, dupa formular, fie denumire, fie nume
		lcDenAles = Iif(Type(m.lcCursor + '.denumire') = 'C', Alltrim(Nvl(Evaluate(m.lcCursor + '.denumire'), '')), ;
			Iif(Type(m.lcCursor + '.nume') = 'C', Alltrim(Nvl(Evaluate(m.lcCursor + '.nume'), '')), ''))
		lcCodAles = Alltrim(Nvl(Evaluate(m.lcCursor + '.cod_fiscal'), ''))

		If Isnull(This.oStare)
			Amessagebox(This.AntetDialog(m.lcDenAles, m.lcCodAles) + ;
				Iif(This.lNegasit, 'Codul fiscal nu exista la ANAF.', ;
				Iif(This.cClasaEsec == 'COD_NENUMERIC', 'Codul fiscal nu este numeric - nu se poate verifica la ANAF.', ;
				Iif(This.cClasaEsec == 'CNP', 'Persoana fizica - CNP corect.', ;
				Iif(This.cClasaEsec == 'COD_INVALID', 'Cod fiscal invalid - nu s-a interogat ANAF. Corectati codul in fisa partenerului.', ;
				'ANAF nu a raspuns - verificarea a fost sarita.')))), ;
				0 + 64, 'Verificare partener ANAF')
			Return
		Endif

		lcPerioadaTVA = This.TextPerioadaTVA(This.oStare)

		If This.oStare.lAreRO = This.oStare.lPlatitorANAF
			Amessagebox(This.AntetDialog(m.lcDenAles, m.lcCodAles) + m.lcPerioadaTVA + ;
				Iif(This.oStare.lInactivANAF, 'Nu exista alta varianta de partener de ales.', 'Codul fiscal corespunde.'), ;
				0 + 64, 'Verificare partener ANAF')
			Return
		Endif

		lcCodOk = Iif(This.oStare.lPlatitorANAF, 'RO', '') + This.cCui
		lnCandidati = 0
		lnCandidat = 0
		lcDenPereche = ''
		llEroare = .F.
		This.ListaCorecti(@lnCandidati, @lnCandidat, @lcDenPereche, @llEroare)

		If m.llEroare
			Amessagebox(This.AntetDialog(m.lcDenAles, m.lcCodAles) + m.lcPerioadaTVA + 'Nu s-a putut citi lista de parteneri.', ;
				0 + 64, 'Verificare partener ANAF')
			Return
		Endif

		If m.lnCandidati = 0
			Amessagebox(This.AntetDialog(m.lcDenAles, m.lcCodAles) + m.lcPerioadaTVA + ;
				'Nu exista partener cu CUI ' + m.lcCodOk + ' (il puteti crea cu butonul Nou).', 0 + 64, 'Verificare partener ANAF')
			Return
		Endif

		This.MarcheazaDocumente()
		lcLista = This.TextListaCandidati()
		lcMesaj = This.AntetDialog(m.lcDenAles, m.lcCodAles) + m.lcPerioadaTVA + 'Parteneri ROA cu CUI ' + m.lcCodOk + ':' + Chr(13) + m.lcLista + Chr(13) + ;
			'Da = Pastreaza selectia' + Chr(13) + ;
			Iif(m.lnCandidati = 1, 'Nu = Alege 1 ' + m.lcDenPereche + ' (ID: ' + Transform(m.lnCandidat) + ')', ;
			'Nu = Alege din lista (1-' + Transform(m.lnCandidati) + ')') + Chr(13) + ;
			'Abandon = Renunta'
		Do While .T.
			lnRasp = Amessagebox(m.lcMesaj, 3 + 48, 'Verificare partener ANAF')
			Do Case
				Case m.lnRasp = 7	&& Nu - alege alt partener din lista
					lnAles = 1
					If m.lnCandidati > 1
						lnAles = aInputBox('Numarul variantei (1-' + Transform(m.lnCandidati) + ')', 'Verificare ANAF', 1)
						If Vartype(m.lnAles) <> 'N' Or m.lnAles < 1 Or m.lnAles > m.lnCandidati
							Loop
						Endif
					Endif
					loAles = This.oCandidati.Item(m.lnAles)
					poANAFInlocuire = Createobject('Empty')
					Addproperty(poANAFInlocuire, 'nIdPart', loAles.nIdPart)
					Addproperty(poANAFInlocuire, 'cDenumire', loAles.cDenumire)
					Addproperty(poANAFInlocuire, 'cCodFiscal', m.lcCodOk)
					goLog.Log('Decizie ANAF (Detalii): ALEGE PERECHEA id_part=' + Transform(loAles.nIdPart), 'anaf_verif_cautare')
					This.lDecis = .T.
					Exit
				Case m.lnRasp = 6	&& Da - pastreaza selectia curenta
					goLog.Log('Decizie ANAF (Detalii): CONTINUA CU ALEGEREA', 'anaf_verif_cautare')
					This.lDecis = .T.
					Exit
				Otherwise	&& Abandon - renunta la alegerea unei variante
					poANAFInlocuire = .Null.
					goLog.Log('Decizie ANAF (Detalii): RENUNTA', 'anaf_verif_cautare')
					Exit
			Endcase
		Enddo
		If (m.lnRasp = 6 Or m.lnRasp = 7) And Pemstatus(This.oForm, 'do_termin', 5)
			This.oForm.do_termin()
		Endif
	ENDPROC

	PROCEDURE VerificaAlegere
		Lparameters toForm
		Local lcCursor, lcDenAles, lcCodAles, lcCodOk, lnCandidati, lnCandidat, lcDenPereche
		Local lcLista, lcMesaj, lnRasp, lnAles, loAles, llEroare, lnIdCurent

		If Vartype(This.oForm) <> 'O'
			Return .T.
		Endif
		If This.lDecis
			Return .T.
		Endif

		If This.nNivel < 3
			*** nivel 1/2: fara apel ANAF nou - se logheaza doar starea deja cunoscuta din navigarea prin grid
			lcCursor = This.oForm.crs_cursor
			If Used(m.lcCursor) And Reccount(m.lcCursor) > 0
				lnIdCurent = Nvl(Evaluate(m.lcCursor + '.id_part'), 0)
				If m.lnIdCurent = This.nIdPart And !Isnull(This.oStare) And This.oStare.lDiscordanta
					goLog.Log('Alegere partener discordant ANAF (fara confirmare): CUI=' + This.cCui + ' id_part=' + Transform(This.nIdPart) + ;
						' scpTVA=' + Transform(This.oStare.lPlatitorANAF) + ' inactivANAF=' + Transform(This.oStare.lInactivANAF), 'anaf_verif_cautare')
				Endif
			Endif
			Return .T.
		Endif

		If Inlist(ANAF_StareServiciu(), 'CAZUT', 'SE_TESTEAZA')
			Return .T.
		Endif
		*** nivel 3: comportamentul de azi, neschimbat (verificare sincrona + confirmare)
		If !This.VerificaRand(.T.)
			Return .T.
		Endif
		If Isnull(This.oStare) Or !This.oStare.lDiscordanta
			Return .T.
		Endif

		lcCursor = This.oForm.crs_cursor
		*** cursorul de cautare are, dupa formular, fie denumire, fie nume
		lcDenAles = Iif(Type(m.lcCursor + '.denumire') = 'C', Alltrim(Nvl(Evaluate(m.lcCursor + '.denumire'), '')), ;
			Iif(Type(m.lcCursor + '.nume') = 'C', Alltrim(Nvl(Evaluate(m.lcCursor + '.nume'), '')), ''))
		lcCodAles = Alltrim(Nvl(Evaluate(m.lcCursor + '.cod_fiscal'), ''))
		lcCodOk = Iif(This.oStare.lPlatitorANAF, 'RO', '') + This.cCui

		If This.oStare.lAreRO = This.oStare.lPlatitorANAF
			lcMesaj = This.AntetDialog(m.lcDenAles, m.lcCodAles) + ;
				'De acord = Pastreaza selectia' + Chr(13) + ;
				'Abandon = Inapoi la cautare'
			lnRasp = Amessagebox(m.lcMesaj, 1 + 48, 'Verificare ANAF')
			goLog.Log('Decizie ANAF (inactiv la ANAF): rasp=' + Transform(m.lnRasp), 'anaf_verif_cautare')
			Return (m.lnRasp = 1)
		Endif

		lnCandidati = 0
		lnCandidat = 0
		lcDenPereche = ''
		llEroare = .F.
		lcLista = This.ListaCorecti(@lnCandidati, @lnCandidat, @lcDenPereche, @llEroare)

		lcMesaj = This.AntetDialog(m.lcDenAles, m.lcCodAles)
		If m.llEroare
			lcMesaj = m.lcMesaj + 'Nu s-a putut citi lista de parteneri.' + Chr(13) + Chr(13) + ;
				'De acord = Pastreaza selectia' + Chr(13) + ;
				'Abandon = Inapoi la cautare'
			lnRasp = Amessagebox(m.lcMesaj, 1 + 48, 'Verificare ANAF')
			goLog.Log('Decizie ANAF (lista indisponibila): rasp=' + Transform(m.lnRasp), 'anaf_verif_cautare')
			Return (m.lnRasp = 1)
		Endif
		If m.lnCandidati = 0
			lcMesaj = m.lcMesaj + 'Nu exista partener cu CUI ' + m.lcCodOk + ' (il puteti crea cu butonul Nou).' + Chr(13) + Chr(13) + ;
				'De acord = Pastreaza selectia' + Chr(13) + ;
				'Abandon = Inapoi la cautare'
			lnRasp = Amessagebox(m.lcMesaj, 1 + 48, 'Verificare ANAF')
			goLog.Log('Decizie ANAF (fara pereche): rasp=' + Transform(m.lnRasp), 'anaf_verif_cautare')
			Return (m.lnRasp = 1)
		Endif
		lcMesaj = m.lcMesaj + 'Parteneri ROA cu CUI ' + m.lcCodOk + ':' + Chr(13) + m.lcLista + Chr(13) + ;
			'Da = Pastreaza selectia' + Chr(13) + ;
			Iif(m.lnCandidati = 1, 'Nu = Alege 1 ' + m.lcDenPereche + ' (ID: ' + Transform(m.lnCandidat) + ')', ;
			'Nu = Alege din lista (1-' + Transform(m.lnCandidati) + ')') + Chr(13) + ;
			'Abandon = Inapoi la cautare'
		Do While .T.
			lnRasp = Amessagebox(m.lcMesaj, 3 + 48, 'Verificare ANAF')
			Do Case
				Case m.lnRasp = 7	&& Nu - alternativa cu cod fiscal corect (numarul cerut daca sunt mai multe)
					lnAles = 1
					If m.lnCandidati > 1
						lnAles = aInputBox('Numarul variantei (1-' + Transform(m.lnCandidati) + ')', 'Verificare ANAF', 1)
						If Vartype(m.lnAles) <> 'N' Or m.lnAles < 1 Or m.lnAles > m.lnCandidati
							Loop
						Endif
					Endif
					loAles = This.oCandidati.Item(m.lnAles)
					poANAFInlocuire = Createobject('Empty')
					Addproperty(poANAFInlocuire, 'nIdPart', loAles.nIdPart)
					Addproperty(poANAFInlocuire, 'cDenumire', loAles.cDenumire)
					Addproperty(poANAFInlocuire, 'cCodFiscal', m.lcCodOk)
					goLog.Log('Decizie ANAF: ALEGE PERECHEA id_part=' + Transform(loAles.nIdPart), 'anaf_verif_cautare')
					Return .T.
				Case m.lnRasp = 6	&& Da - continua cu selectia curenta
					goLog.Log('Decizie ANAF: CONTINUA CU ALEGEREA', 'anaf_verif_cautare')
					Return .T.
				Otherwise	&& Abandon - inapoi la cautare
					goLog.Log('Decizie ANAF: RAMAI IN CAUTARE', 'anaf_verif_cautare')
					Return .F.
			Endcase
		Enddo
	ENDPROC
ENDDEFINE

************************************************************************************************************************
* CautPartenerContabilitate(cTitlu, cTipuriParteneri)
* Date : 04/10/2006
* author : marius.mutu
* se cauta un partener dupa o lista de tipuri partener in toti partenerii
* se ordoneaza lista de parteneri - intai partenerii cu tip in lista de tipuri, apoi restul
* se coloreaza partenerii care nu au tip in lista de tipuri
* se poate da un cont - se obtine lista de tipuri partener din coresp_tip_cont
* se pot adauga corespondentele daca aleg un partener care nu are tipurile asociate
* loCauta = CautPartenerContabilitate(GetHash([cTitlu=>Alegeti partenerul 401??lAdaugCorespondente=>1??cCont=>401])
******************************************* INCEPUT:CautPartenerContabilitate*******************************************
Procedure CautPartenerContabilitate
	Lparameters toHash
	&& ctitlu: Nume client/furnizor etc.
	&& cTipuriParteneri: lista de id-uri tipuri partener delimitata prin ','
	&& cCont: contul pentru care se obtine lista de tipuri partener
	&& llAdaugCorespondente: daca se adauga corespondente partener - tipuri partener



	Local loHash As MyHash, lcSelect, lcTitlu, lcTipuriParteneri, lnSucces, llAllInList, lnPornire, lcFiltruOrig, lcNumeProcedura, llAdaugCorespondente
	Local lVerificaANAF, ldDataDoc, lnNivelANAF

	*!* parametrii
	lcTitlu = toHash.GetValue("cTitlu")
	lcTipuriParteneri = toHash.GetValue("cTipuriParteneri")
	lcCont = toHash.GetValue("cCont")
	llAdaugCorespondente = toHash.GetValue("lAdaugCorespondente")
	lcNumeProcedura = toHash.GetValue("cNumeProc")
	lcFiltruOrig = toHash.GetValue("cFiltruOrig")
	llAllInList = toHash.GetValue("lAllInList")
	lnPornire = toHash.GetValue("nPornire")
	lVerificaANAF = toHash.GetValue("lVerificaANAF")
	ldDataDoc = toHash.GetValue("dDataDoc")

	*!* parametrii

	If Empty(lcTitlu)
		lcTitlu = 'Alegeti partenerul'
	Endif

	&& se obtine lista de tipuri parteneri asociata unui cont
	If !Empty(lcCont) And Empty(lcTipuriParteneri)
		lcSelect = [SELECT stringAgg(to_char(id_tip_part)) FROM coresp_tip_cont WHERE cont = '] + lcCont + [']
		lnSucces = goExecutor.oSelect2Value(lcSelect, @lcTipuriParteneri)
		If lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare, 0 + 16, 'Eroare')
		Endif
	Endif
	lcTipuriParteneri = Nvl(lcTipuriParteneri, '')

	If !Empty(lcTipuriParteneri)
		*!* selectia se face din corespondente tipuri partener
		lcSelect = [SELECT MIN(CASE WHEN A.ID_TIP_PART in (] + lcTipuriParteneri + [) THEN 0 ELSE 1 END) AS TIP,] + ;
			[B.ID_PART, B.DENUMIRE AS NUME, B.COD_FISCAL, B.DENUMIRE, B.TIP_PERSOANA ] + ;
			[ FROM CORESP_TIP_PART A ] + ;
			[ LEFT JOIN NOM_PARTENERI B ON A.ID_PART = B.ID_PART ]
	Else
		*!* selectia se face din parteneri
		lcSelect = [SELECT 0 as TIP, B.ID_PART, B.DENUMIRE AS NUME, B.COD_FISCAL, B.DENUMIRE, B.TIP_PERSOANA ] + ;
			[ FROM NOM_PARTENERI B ]
	Endif

	loHash = GetHash()
	With loHash
		.SetValue("cSelect", lcSelect)
		.SetValue("cFiltru", "1=2")
		.SetValue("cOrder", "1,NUME")
		If !Empty(Nvl(lcTipuriParteneri, ''))
			.SetValue("cGroup", "B.ID_PART, B.DENUMIRE, B.COD_FISCAL, B.TIP_PERSOANA")
		Endif
		.SetValue("cColoana", "denumire,cod_fiscal,id_part")
		.SetValue("cTitlu", lcTitlu)
		.SetValue("cTitluColoana", "Nume,Cod fiscal,ID")
		If !Empty(lcFiltruOrig)
			lcFiltruOrig = [B.STERS = 0 AND B.INACTIV = 0 AND ] + lcFiltruOrig
		Else
			lcFiltruOrig = [B.STERS = 0 AND B.INACTIV = 0]
		Endif
		.SetValue("cFiltruOriginal", lcFiltruOrig)
		*!*			IF EMPTY(lcTipuriParteneri)
		*!*				&& daca nu exista tipuri la un cont
		*!*				.SetValue("cFiltruOriginal", "1=2")
		*!*			ENDIF
		.SetValue("cPrimaColoana", "denumire")
		If Empty(lcNumeProcedura)
			.SetValue("cNumeProc", [nom_parteneri;"] + lcTipuriParteneri + ["])
		Else
			.SetValue("cNumeProc", lcNumeProcedura)
		ENDIF
		.SetValue("cProceduraVerifica", "nom_parteneri_verifica")
		.SetValue("cProceduraCopiaza", "nom_parteneri_copiaza")
		If !Empty(lcTipuriParteneri)
			*!* daca partenerii sunt ordonati dupa tip - coloreaza partenerii care au tip = 1
			.SetValue("cGridDynamicBackColor", [IIF(TIP = 1, RGB(225,225,225), RGB(255,255,255))])
			.SetValue("cGridToolTip", "Partenerii de alt tip sunt colorati gri.")
		Endif
		.SetValue("lAllInList", llAllInList)
		.SetValue("nPornire", lnPornire)

	Endwith


	Private poVerifAlegere, poANAFInlocuire
	poVerifAlegere = .Null.
	poANAFInlocuire = .Null.
	If m.lVerificaANAF
		lnNivelANAF = ANAF_NivelVerificare()
		If m.lnNivelANAF > 0
			poVerifAlegere = Createobject('anaf_verif_cautare')
			poVerifAlegere.dDataDoc = ANAF_CaData(m.ldDataDoc)
			poVerifAlegere.nNivel = m.lnNivelANAF
		Endif
	Endif

	loCauta = cauta_alfa_hash(loHash)	&&	11.07.2007

	If Type('gnbuton') = 'N' And gnbuton = 1
		AplicaInlocuirePartenerANAF(loCauta, poANAFInlocuire, lcTipuriParteneri)
	Endif

	*!* ADAUG TIPURI DE PARTENER - PARTENER DACA NU EXISTA
	If llAdaugCorespondente And !Isnull(loCauta) And Type('loCauta.id_part') = 'N' And loCauta.id_part <> 0 And !Empty(lcTipuriParteneri) And loCauta.tip = 1
		Do ADAUGA_CORESP_TIP_PART With loCauta.id_part, lcTipuriParteneri In oproceduri_parteneri.prg
	Endif

	Return loCauta

Endproc && CautPartenerContabilitate
******************************************* SFARSIT: CautPartenerContabilitate*******************************************

* PROCEDURE caut_parteneri( tcCont )
* Date : 04/11/2004, 14:01:21
* author : lavinia.viziru
******************************************* INCEPUT:caut_parteneri *******************************************
Procedure caut_parteneri( tcCont, tcTitlu, tlToateIreg, tlNou, tlInactiv, tlVerificaANAF, tdDataDoc)
	Local  lcCont, loCauta, lcFiltruOriginal
	Local lcTitlu, lcFiltru, lcSchema, lcOrder, lcNumeProc, lcTitluColoane
	Store "" To loCauta
	lcCont = tcCont
	llInactiv = m.tlInactiv  && daca arat si partenerii inactivi (ex: la fisa de cont, cand un partener s-a unificat, partenerul vechi este inactiv)

	lcSelect = [select distinct p.denumire, p.nume, p.cod_fiscal, p.id_part, p.inactiv, p.tip_persoana FROM Vcoresp_tip_part p ] + ;
		[ join vcoresp_tip_cont c on p.id_tip_part=c.id_tip_part  ]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [P.denumire]
	lccoloane = [denumire, nume, cod_fiscal, id_part, inactiv]
	If Empty(lcCont)
		lcFiltruOriginal = IIF(m.llInactiv, [1=1],[p.inactiv = 0])
	Else
		lcFiltruOriginal = IIF(m.llInactiv, [1=1],[p.inactiv = 0]) + [ and c.cont='] + Alltrim(lcCont) + [']
	Endif
	If Empty(tcTitlu)
		lcTitlu = "Alegeti partenerul"
	Else
		lcTitlu = tcTitlu
	Endif
	If tlNou
		lcNumeProc = [nom_parteneri]
	Else
		lcNumeProc = []
	ENDIF

	lcTitluColoane = [Denumire, Nume,Cod fiscal, Id, Inactiv]

	Local lnNivelANAF
	Private poVerifAlegere, poANAFInlocuire
	poVerifAlegere = .Null.
	poANAFInlocuire = .Null.
	If m.tlVerificaANAF
		lnNivelANAF = ANAF_NivelVerificare()
		If m.lnNivelANAF > 0
			poVerifAlegere = Createobject('anaf_verif_cautare')
			poVerifAlegere.dDataDoc = ANAF_CaData(m.tdDataDoc)
			poVerifAlegere.nNivel = m.lnNivelANAF
		Endif
	Endif

	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruOriginal)		&& 11.07.2007

	If Type('gnbuton') = 'N' And gnbuton = 1
		AplicaInlocuirePartenerANAF(loCauta, poANAFInlocuire)
	Endif

	Return loCauta

Endproc
******************************************* SFARSIT: caut_parteneri *******************************************
******************************************* INCEPUT:caut_parteneri_xml *******************************************
*** se cauta inclusiv partenerii vechi care au fost unificati in parteneri noi
Procedure caut_parteneri_xml( tcCont, tcTitlu, tlToateIreg, tlNou)
	Local  lcCont, loCauta, lcFiltruOriginal
	Local lcTitlu, lcFiltru, lcSchema, lcOrder, lcNumeProc, lcTitluColoane
	Store "" To loCauta
	lcCont = tcCont

	TEXT TO lcSelect NOSHOW
select distinct 
 case when p2.id_part <> p1.id_part then p1.denumire || ' <<< 'else '' end || nvl(p2.denumire, p1.denumire) as denumire,
       p2.nume,
       p2.cod_fiscal,
       CASE WHEN NVL(p2.inactiv,0) <> 0 THEN 'INACTIV' ELSE '       ' END AS inactiv,
       p2.id_part
  FROM CORESP_TIP_PART p
  JOIN CORESP_TIP_CONT c
    on p.id_tip_part = c.id_tip_part
  left join nom_parteneri_modificari pm
    on p.id_part = pm.id_part_vechi
  left JOIN NOM_PARTENERI p1
    on pm.id_part_NOU = p1.ID_PART
  left join nom_parteneri p2
    on p.id_part = p2.ID_PART
	ENDTEXT 

*!*		lcSelect = [select distinct p.denumire, p.nume, p.cod_fiscal, p.id_part FROM Vcoresp_tip_part p ]+;
*!*			[ join vcoresp_tip_cont c on p.id_tip_part=c.id_tip_part  ]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [3]
	lccoloane = [denumire, nume, cod_fiscal, inactiv, id_part]
*!*			lcFiltruOriginal = [p.inactiv = 0]
	lcFiltruOriginal = []
	If !Empty(lcCont)
*!*			lcFiltruOriginal = [p.inactiv = 0 and c.cont=']+ Alltrim(lcCont) + [']
*!*	modificare	ROACONT v 2.5.40
		lcFiltruOriginal = lcFiltruOriginal + [c.cont='] + Alltrim(lcCont) + [']
	Endif
	If Empty(tcTitlu)
		lcTitlu = "Alegeti partenerul (mouse-click pe nume sau apasati SPACE)"
	Else
		lcTitlu = tcTitlu + " (mouse-click pe nume sau apasati SPACE)"
	Endif
	If tlNou
		lcNumeProc = [nom_parteneri]
	Else
		lcNumeProc = []
	Endif
	lcTitluColoane = [Denumire, Nume, Cod fiscal, Inactiv, Id]
	lnTipReturn = 1 && XML
*!*		lcPrimaColoana = "denumire"
	lcPrimaColoana = "nvl(p1.denumire, p2.denumire)"
	lcIdColumn = "id_part"
	lcNume_Proc = []
	lnPornire = 1
	lcXMLParteneri = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNume_Proc, tlToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)
	Return lcXMLParteneri
Endfunc && caut_parteneri_xml
******************************************* SFARSIT: caut_parteneri_xml *******************************************
* PROCEDURE caut_partener()
* author : paula.mutu
* -- SIR CU ID-URI TIP PARTENER PENTRU -1,-2 (CLIENT/FURNIZOR)
******************************************* INCEPUT:caut_partener *******************************************
Procedure caut_partener(tcIdTipPart, tcTitlu, tlToateIreg, tlNou, tlVerificaANAF, tdDataDoc)

	Private pnIdTip, pcSir_Id_tip_part
	Store '' To pcSir_Id_tip_part
	pnIdTip = tcIdTipPart
	&& pnIdTip  && -1 - Clienti; -2 - Furnizori
	lcSql = [begin pack_def.get_conturi_tip_part(?pnIdTip, ?@pcSir_Id_tip_part); end;]
	lnSucces = goExecutor.oExecute(lcSql)
	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare, 0 + 16, 'Eroare')
		Return
	Endif

	Local  lcCont, loCauta, lcFiltruOriginal
	Local lcTitlu, lcFiltru, lcSchema, lcOrder, lcNumeProc, lcTitluColoane
	Store "" To loCauta

	lcSelect = [select denumire, cod_fiscal, id_part, tip_persoana from vnom_parteneri ]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [denumire]
	lccoloane = [denumire, cod_fiscal, id_part]
	If Empty(pcSir_Id_tip_part) Or Isnull(pcSir_Id_tip_part)
		lcFiltruOriginal = [inactiv = 0]
	Else
		lcFiltruOriginal = [inactiv = 0 and id_part in (select distinct id_part from coresp_tip_part where id_tip_part in (] + pcSir_Id_tip_part + [))]
	Endif

	If Empty(tcTitlu)
		lcTitlu = "Alegeti partenerul"
	Else
		lcTitlu = tcTitlu
	Endif
	If tlNou
		lcNumeProc = [nom_parteneri]
	Else
		lcNumeProc = []
	Endif
	lcTitluColoane = [Denumire,Cod fiscal,Id]

	Local lnNivelANAF
	Private poVerifAlegere, poANAFInlocuire
	poVerifAlegere = .Null.
	poANAFInlocuire = .Null.
	If m.tlVerificaANAF
		lnNivelANAF = ANAF_NivelVerificare()
		If m.lnNivelANAF > 0
			poVerifAlegere = Createobject('anaf_verif_cautare')
			poVerifAlegere.dDataDoc = ANAF_CaData(m.tdDataDoc)
			poVerifAlegere.nNivel = m.lnNivelANAF
		Endif
	Endif

	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruOriginal)		&& 11.07.2007

	If Type('gnbuton') = 'N' And gnbuton = 1
		AplicaInlocuirePartenerANAF(loCauta, poANAFInlocuire)
	Endif

	Return loCauta

Endproc
******************************************* SFARSIT: caut_partener *******************************************

******************************************* INCEPUT: caut_partener_dupa_tip *******************************************
Procedure caut_partener_dupa_tip
	Lparameters tnIdTipPart, tcTitlu, tnIdPart, tcNumePart, tcSirIdTipPart
	Local loCauta, llReturn
	Store "" To loCauta
	Store .F. To llReturn
	pcselect = [select id_part,denumire from vcoresp_tip_part]
	pcFiltruOrig = [id_tip_part=] + Alltrim(Str(tnIdTipPart))
	lcProceduraNou = [nom_parteneri;] + Alltrim(Str(tnIdTipPart)) + [,'Entitate',1,2]
	If !Empty(tcSirIdTipPart)
		pcFiltruOrig = pcFiltruOrig + [and id_part not in (select id_part from coresp_tip_part where id_tip_part in (] + tcSirIdTipPart + [))]
	Endif
	pcfiltru = [1=2]
	pcschema = []
	pcorder = [2]
	pccoloane = [denumire]
	pcTitlu = Iif(!Empty(tcTitlu), tcTitlu, [Alegeti partenerul])
	pcTitluColoane = [Nume]
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, lcProceduraNou, .F., pcFiltruOrig)		&& 11.07.2007
	If !Empty(loCauta.id_part)
		tnIdPart = loCauta.id_part
		tcNumePart = Alltrim(loCauta.denumire)
		llReturn = .T.
	Endif
	Return llReturn
Endproc
******************************************* SFARSIT: caut_partener_dupa_tip *******************************************
******************************************* INCEPUT: caut_categorie_entitate *******************************************
Procedure caut_categorie_entitate
	Local loCauta, llReturn
	Store "" To loCauta
	Store .F. To llReturn
	pcselect = [select id_categorie_entitate,categorie_entitate from vnom_categorii_entitati]
	pcfiltru = [1=2]
	pcschema = []
	pcorder = [2]
	pccoloane = [categorie_entitate]
	pcTitlu = [Alegeti categoria]
	pcTitluColoane = [Categorie entitate]
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "")		&& 11.07.2007
	Return loCauta
Endproc
******************************************* SFARSIT: caut_categorie_entitate *******************************************
******************************************* INCEPUT: caut_marca_masina *******************************************
Procedure caut_marca_masina
	Local loCauta, llReturn
	Store "" To loCauta
	Store .F. To llReturn
	pcselect = [select id_marca_masina,marca_masina from vnom_marci_masini]
	pcfiltru = [1=2]
	pcschema = []
	pcorder = [2]
	pccoloane = [marca_masina]
	pcTitlu = [Alegeti marca masinii]
	pcTitluColoane = [Marca]
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "")		&& 11.07.2007
	Return loCauta
Endproc
******************************************* SFARSIT: caut_marca_masina *******************************************

* PROCEDURE caut_lucrare
* Date : 31.07.2006
* author : marius.mutu
******************************************* INCEPUT:caut_lucrare *******************************************
Procedure caut_lucrare(tlToateIreg, tlNou, tcFiltruOriginal)
	*!*	modificare 30.06.2011 ( ROAAUTO v 2.0.28 ) : am adaugat tcFiltruOriginal

	Local  loCauta, lcFiltruOriginal
	Local lcTitlu, lcFiltru, lcSchema, lcOrder, lcNumeProc, lcTitluColoane
	Store Null To loCauta

	lcSelect = [select nrord, id_lucrare from vnom_lucrari]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [nrord]
	lccoloane = [nrord,id_lucrare]
	lcFiltruOriginal = [inactiv = 0] + IIF(!EMPTY(tcfiltruOriginal), [ and ] + tcFiltruOriginal, [])

	lcTitlu = "Alegeti lucrarea"
	If tlNou
		lcNumeProc = [nom_lucrari]
	Else
		lcNumeProc = []
	Endif
	lcTitluColoane = [Lucrare,Id]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruOriginal)		&& 11.07.2007

	Return loCauta

Endproc
******************************************* SFARSIT: caut_lucrare *******************************************

******************************************* INCEPUT:caut_articol *******************************************
Function caut_articol
	Lparameters tntipg, tlToateIreg, tlMultipleArticles, tlCRM, tlCautPlus, tlFaraAdaugare, tnIdGrupa, tlInactive
	Store "" To loCauta
	*!* tlCautPlus - daca se foloseste formularul caut_alfa_form_plus cu butonul but_start_criterii
	*!* 24.07.2009
	*!*	29.01.2013 : am adaugat um2 in selectie
	*!*	19.07.2013 : am adaugat in_stoc in selectie
	*!*	11.09.2013 : am adaugat tlInactive
	Local lcStringCriterii
	lcStringCriterii = ""
	If tlCautPlus
		lcStringCriterii = "Cod material\codmat\T\none\" + crlf + ;
			"Denumire articol\denumire\T\id_articol\nom_articol" + crlf + ;
			"Subgrupa articol\none\I\id_subgrupa\nom_subgrupa_articol" + crlf
		lcTitluColoane = [Cod Material, Denumire,Subgrupa, Cod bare,U.M.,Cont,Id]
		lccoloane = [codmat,denumire,subgrupa,codbare,um,cont,id_articol]
	Else
		lccoloane = [denumire,codmat,codbare,um,cont,id_articol]
		lcTitluColoane = [Denumire,Cod Material,Cod bare,U.M.,Cont,Id]
	Endif
	*!* 24.07.2009 ^

	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [denumire]
	lcNumeProc = []

	If tlMultipleArticles
		lcTitlu = [Alegeti articolele (mouse-click pe denumire sau apasati SPACE)]
	Else
		lcTitlu = [Alegeti articolul]
	Endif

	llMultipleArticles = tlMultipleArticles
	If tlCRM
		lcSelect = [select distinct a.denumire,a.codmat,a.codbare,a.um,a.um2,a.cont, ] + ;
			[ a.id_articol, 0 as id_tipgest,a.in_stoc, a.inactiv from vnom_articole_crm a ]
		lcFiltruOriginal = IIF(tlInactive, [2=2], [a.inactiv=0])
		*lcNumeProc = [nom_articole2]
		*!*	modificare	03.02.2010
		*!*	lcNumeProc = [nom_articole]
		If !tlFaraAdaugare
			lcNumeProc = [nom_articole]
		Endif
		*!*	modificare	03.02.2010	^
	Else
		If Type('tnTipg') = 'N' And tntipg > 0
			lcSelect = [select distinct a.denumire,a.codmat,a.codbare,a.um,a.um2,a.cont,a.acont, ] + ;
				[a.id_articol, a.grupa, a.subgrupa, a.id_grupa, a.id_subgrupa, a.dnf, b.id_tipgest, a.in_stoc, a.inactiv from vnom_articole a  inner join coresp_cont_tipgest b on a.cont = b.cont]
			lcFiltruOriginal = IIF(tlInactive, [], [ a.inactiv=0 and]) + [ b.id_tipgest = ] + Alltrim(Str(tntipg))
		Else
			lcSelect = [select distinct a.denumire,a.codmat,a.codbare,a.um,a.um2,a.cont,a.acont,] + ;
				[a.id_articol, a.grupa, a.subgrupa, a.id_grupa, a.id_subgrupa, a.dnf, 0 as id_tipgest, a.in_stoc, a.inactiv from vnom_articole a ]
			lcFiltruOriginal = IIF(tlInactive, [2=2], [a.inactiv=0])
		Endif
		*!*	modificare	03.02.2010
		*!*	lcNumeProc = [nom_articole]
		If !tlFaraAdaugare
			lcNumeProc = [nom_articole]
		Endif
		*!*	modificare	03.02.2010	^
	Endif
	*!*	modificare	v 10.01.2011
	IF !EMPTY(tnIdGrupa)
		lcFiltruOriginal = lcFiltruOriginal + [ and a.id_subgrupa in (select id_subgrupa from vgest_art_sbgr where id_grupa = ] + ALLTRIM(STR(tnIdGrupa)) + [)]
	ENDIF
	*!*	modificare	v 10.01.2011	^	
	llToateIreg = tlToateIreg
	lcPrimaColoana = [denumire]
	lnPornire = 1
	lnTipReturn = Iif(tlMultipleArticles, 1, 0)
	lcIdColumn = "id_articol"

	*!* 24.07.2009
	loHash = GetHash()
	With loHash
		.SetValue("cSelect", lcSelect)
		.SetValue("cFiltru", lcFiltru)
		.SetValue("cSchema", lcSchema)
		.SetValue("cOrder", lcOrder)
		.SetValue("cColoana", lccoloane)
		.SetValue("cTitlu", lcTitlu)
		.SetValue("cTitluColoana", lcTitluColoane)
		.SetValue("cNumeProc", lcNumeProc)
		.SetValue("lToateIreg", llToateIreg)
		.SetValue("cFiltruOriginal", lcFiltruOriginal)
		.SetValue("cPrimaColoana", lcPrimaColoana)
		.SetValue("nPornire", lnPornire)
		.SetValue("nTipReturn", lnTipReturn)
		.SetValue("cIdColumn", lcIdColumn)
		.SetValue("cStringCriterii", lcStringCriterii)
		If tlInactive
			.SetValue("cGridDynamicBackColor", [IIF(inactiv = 1, RGB(225,225,225), RGB(255,255,255))])
		Endif
	Endwith
	*!*	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn , lcIdColumn, lcStringCriterii)		&& 11.07.2007
	loCauta = cauta_alfa_hash(loHash)
	*!* 24.07.2009 ^

	Return loCauta && caut_articol

	******************************************* SFARSIT: caut_articol *******************************************

Function cauta_articole
	Lparameters tcFiltruOriginal, tnPornire, tlLoud, tcListaId, tcListaDenumire
	*** tnPornire: incepe cu...,1,este...,2,nu este...,3,contine...,4,nu contine...,5,toate,6
	*** tlLoud = .T. daca apare messagebox "Nu ati selectat nici o inregistare" pentru cautarea multipla. Default = .F.
	*** tcListaId = parametru OUT - lista id-uri articole
	*** tcListaDenumire = parametru OUT - lista denumiri articole

	Local lcFiltru, lcFiltruOriginal, lcIdColumn, lcNumeProc, lcOrder, lcPrimaColoana, lcSchema
	Local lcSelect, lcTitlu, lcTitluColoane, lccoloane, llMultipleArticles, llToateIreg, lnPornire
	Local lnTipReturn, loCauta, loLista

	Store "" To loCauta

	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [denumire]
	lccoloane = [denumire,codmat,codbare,um,grupa,subgrupa,cont,acont,dnf,id_articol]
	lcTitlu = [Alegeti articolele (mouse-click pe denumire sau apasati SPACE)]
	lcTitluColoane = [Denumire,Cod Material,Cod bare,UM,Grupa,Subgrupa,Cont,Analitic,DNF,Id]
	llMultipleArticles = .T.
	lcSelect = [select a.denumire,a.codmat,a.codbare,a.um, a.grupa, a.subgrupa, a.id_grupa, a.id_subgrupa,a.dnf,a.cont, a.acont, a.inactiv, a.id_articol from vnom_articole a ]
	lcFiltruOriginal = Iif(!Empty(tcFiltruOriginal), Alltrim(tcFiltruOriginal), "")
	lcNumeProc = [nom_articole]
	llToateIreg = .F.
	lcPrimaColoana = [denumire]
	lnPornire = Iif(Empty(m.tnPornire), CA_PORNIRE_INCEPE, m.tnPornire)
	lnTipReturn = Iif(llMultipleArticles, 1, 0)
	lcIdColumn = "id_articol"
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)		&& 11.07.2007

	*!* 24.08.2011
	IF m.llMultipleArticles
		loLista = XML2ListaIDDescriere(loCauta, "id_articol", "denumire", tlLoud)
		tcListaId = loLista.ListaId
		tcListaDenumire = loLista.ListaDenumire
	ENDIF
	*!* 24.08.2011

	Return loCauta && cauta_articole

Endfunc && cauta_articole
******************************************* SFARSIT: cauta_articole *******************************************
Function cauta_nom_articole
	Lparameters tcFiltruOriginal, tnPornire, tlLoud, tcListaId, tcListaDenumire
	*** tnPornire: incepe cu...,1,este...,2,nu este...,3,contine...,4,nu contine...,5,toate,6
	*** tlLoud = .T. daca apare messagebox "Nu ati selectat nici o inregistare" pentru cautarea multipla. Default = .F.
	*** tcListaId = parametru OUT - lista id-uri articole
	*** tcListaDenumire = parametru OUT - lista denumiri articole
	Local lcFiltru, lcFiltruOriginal, lcIdColumn, lcNumeProc, lcOrder, lcPrimaColoana, lcSchema, lnPornire
	Local lcSelect, lcTitlu, lcTitluColoane, lccoloane, llMultipleArticles, llToateIreg, lnTipReturn
	Local loCauta, loLista
	Store "" To loCauta

	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [denumire]
	lccoloane = [denumire,codmat,codbare,um,grupa,subgrupa,cont,acont,dnf,id_articol]
	lcTitlu = [Alegeti articolele (mouse-click pe denumire sau apasati SPACE)]
	lcTitluColoane = [Denumire,Cod Material,Cod bare,UM,Grupa,Subgrupa,Cont,Analitic,DNF,Id]
	llMultipleArticles = .T.
	lcSelect = [select a.denumire,a.codmat,a.codbare,a.um, a.grupa, a.subgrupa, a.id_grupa, a.id_subgrupa,a.dnf,a.cont, a.acont, a.inactiv, a.id_articol,] + ;
		[ a.um2, a.um_iso, a.cod_um_iso, a.cant_bax, a.in_crm, a.in_stoc, a.codmatf, a.conditii_pastrare,] + ;
		[ a.id_part, a.partener, a.indicativ, a.taxa_reconditionare, a.id_articol_general, a.articol_general,] + ;
		[ a.listare_codbare, a.tip, a.timpn, a.codnc8, a.greutate, a.id_tara_origine, a.tara_origine, a.codcpv] + ;
		[ from ] + gcS + [.vnom_articole_toate a ]
	lcFiltruOriginal = Iif(!Empty(tcFiltruOriginal), Alltrim(tcFiltruOriginal) + [ and ], "") + [a.inactiv = 0]
	lcNumeProc = [nom_articole]
	llToateIreg = .F.
	lcPrimaColoana = [denumire]
	lnPornire = Iif(Empty(m.tnPornire), CA_PORNIRE_INCEPE, m.tnPornire)
	lnTipReturn = Iif(llMultipleArticles, 1, 0)
	lcIdColumn = "id_articol"
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)		&& 11.07.2007

	*!* 24.08.2011
	IF m.llMultipleArticles
		loLista = XML2ListaIDDescriere(loCauta, "id_articol", "denumire", tlLoud)
		tcListaId = loLista.ListaId
		tcListaDenumire = loLista.ListaDenumire
	ENDIF
	*!* 24.08.2011

	Return loCauta && cauta_nom_articole

Endfunc && cauta_nom_articole
******************************************* SFARSIT: cauta_nom_articole *******************************************

*** transforma un xml din cautare alfa multipla intr-o lista cu id-uri si o lista cu denumiri
*** ex: lista xml articole -> lista id-uri articole (100|101|102|) si lista denumiri articole (banana,morcov,telina)
*** intoarce un obiect cu 2 proprietati: ocautare.listaid, ocautare.listadenumire
FUNCTION XML2ListaIDDescriere
	LPARAMETERS tcXML, tcCampId, tcCampDenumire, tlLoud
	*** tcXML = xml cursor cautare alfa
	*** tcCampId = nume camp ID din cursor. Ex: id_articol
	*** tcCampDenumire = nume camp Denumire din cursor. Ex: denumire
	*** tlLoud = .T. daca apare messagebox "Nu ati selectat nici o inregistare", Default = .F.

	LOCAL lcXML, llLoud, loCautare, lcSelect

	lcSelect = SELECT()
	lcXML = IIF(TYPE('tcXML') <> 'C' or PCOUNT() < 1, "", m.tcXML)
	lcCampId = IIF(TYPE('tcCampId') <> 'C' or PCOUNT() < 2, "", m.tcCampId)
	lcCampDenumire = IIF(TYPE('tcCampDenumire') <> 'C' or PCOUNT() < 3, "", m.tcCampDenumire)
	llLoud = IIF(TYPE('tlLoud') <> 'L' or PCOUNT() < 4, .F., m.tlLoud)

	loCautare = CREATEOBJECT("empty")
	ADDPROPERTY(loCautare, "ListaId", "")
	ADDPROPERTY(loCautare, "ListaDenumire", "")

	If Empty(m.lcXML) OR EMPTY(m.lcCampId) OR EMPTY(m.lcCampDenumire)
		SELECT (lcSelect)
		RETURN loCautare
	ENDIF

	Xmltocursor(lcXML, "crsXMLTemp")
	If Reccount('crsXMLTemp') = 0 AND m.llLoud
		AMessageBox('Nu ati selectat nici o inregistrare!', 0 + 48, _screen.caption)
		USE IN (SELECT("crsXMLTemp"))
		SELECT (lcSelect)
		RETURN loCautare
	ENDIF

	Select crsXMLTemp
	Locate For &lcCampId = 0
	If Found() And Reccount('crsXMLTemp') = 1
		loCautare.ListaId = [NULL]
		loCautare.ListaDenumire = [TOATE INREGISTRARILE]
	Else
		loCautare.ListaId = ['] + cursor2lista("crsXMLTemp", lcCampId, "|")
		loCautare.ListaDenumire = cursor2lista("crsXMLTemp", lcCampDenumire, ",")
	Endif
	Use In (SELECT('crsXMLTemp'))
	If(Right(loCautare.ListaId, 1) # "|" And loCautare.ListaId # [NULL])
		loCautare.ListaId = loCautare.ListaId + "|"
	Endif
	If loCautare.ListaId <> [NULL]
		loCautare.ListaId = loCautare.ListaId + "'"
	Endif

	SELECT (lcSelect)
	RETURN loCautare
ENDFUNC && XML2ListaIDDescriere
******************************************* INCEPUT: caut_articol_gs *******************************************
Function caut_articol_gs
	Lparameters tntipg, tlToateIreg, tlMultipleArticles, tcFiltruCont
	Store "" To loCauta

	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [denumire]
	lccoloane = [denumire,codmat,codbare,id_articol]
	lcTitlu = [Alegeti articolul]
	lcTitluColoane = [Denumire,Cod Material,Cod bare,Id]
	llMultipleArticles = tlMultipleArticles
	If Type('tnTipg') = 'N' And tntipg > 0
		lcSelect = [select distinct a.denumire,a.codmat,a.codbare,a.um,a.cont,a.acont,] + ;
			[a.id_articol, a.grupa, a.subgrupa, a.id_grupa, a.id_subgrupa, a.dnf, b.id_tipgest from vnom_articole a ] + ;
			[inner join coresp_cont_tipgest b on a.cont = b.cont where 2=2 ]
		lcFiltruOriginal = [ b.id_tipgest = ] + Alltrim(Str(tntipg))
	Else
		lcSelect = [select distinct a.denumire,a.codmat,a.codbare,a.um,a.cont,a.acont,] + ;
			[a.id_articol, a.grupa, a.subgrupa, a.id_grupa, a.id_subgrupa, a.dnf, 0 as id_tipgest ] + ;
			[from vnom_articole a where 2=2 ]
		lcFiltruOriginal = [ 2=2 ]
	Endif
	*!*	modificare 10.02.2010	ROAGRESTAURANT v 0.0.17
	IF !EMPTY(tcFiltruCont)
		*!*	tcFiltruCont poate fi : 34% / 345 / 345,371  
		Do Case
			CASE AT([%], tcFiltruCont) > 0
				lcFiltruOriginal = lcFiltruOriginal + [ and a.cont like '] + Alltrim(tcFiltruCont) + [']
			CASE AT([,], tcFiltruCont) > 0
				lcFiltruOriginal = lcFiltruOriginal + [ and a.cont in ('] + Strtran(Alltrim(tcFiltruCont), [,], [',']) + [')]
			Otherwise
				lcFiltruOriginal = lcFiltruOriginal + [ and a.cont = '] + Alltrim(tcFiltruCont) + [']
		Endcase
	ENDIF
	*!*	modificare 10.02.2010	ROAGRESTAURANT	v 0.0.17 ^
	lcNumeProc = [nom_articole]
	llToateIreg = tlToateIreg
	lcPrimaColoana = [denumire]
	lnPornire = 1
	lnTipReturn = Iif(tlMultipleArticles, 1, 0)
	lcIdColumn = "id_articol"
	loCauta = cauta_alfa_gs(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)		&& 11.07.2007

	Return loCauta && caut_articol_gs

Endfunc && caut_articol_gs
******************************************* SFARSIT: caut_articol_gs *******************************************

******************************************* INCEPUT: cauta_articole_alege *******************************************
*!* cautare dupa codmat, denumire, subgrupa si bifarea articolelor dorite
Function cauta_articole_alege
	Private poArticole
	poArticole = Null
	gencursor('deca_baza1', lcCursor, tcselect, tcfiltru, tcschema, tcorder, .F., lcGroup, llModParam, lcFiltOriginal)
	deca_baza1.ca_baza1.afisare()
Endfunc && cauta_articole_alege
******************************************* SFARSIT: cauta_articole_alege *******************************************

******************************************* INCEPUT: caut_cont *******************************************
Function caut_cont
	Lparameters tntipg, tcListaConturi, tlToateIreg, tlDoarConturi

	Store "" To loCauta
	Local llToateIreg
	llToateIreg = tlToateIreg

	pcfiltru = [1=2]
	pcschema = []
	pcorder = [cont,acont]
	pcTitlu = [Alegeti contul]
	If tlDoarConturi
		pccoloane = [cont,explicatie,tip_sold]
		pcTitluColoane = [Cont,Explicatie,Tip sold]
	Else
		pccoloane = [cont,acont,explicatie,tip_sold]
		pcTitluColoane = [Cont,Analitic,Explicatie,Tip sold]
	Endif

	If Empty(tntipg) And Empty(tcListaConturi)
		If llToateIreg
			pcselect = [select a.explicatie,rpad(a.cont,22) as cont,] + ;
				IIF(tlDoarConturi, [], [a.acont,]) + [a.id_plcont,a.tip_sold from vplcont_used a ]
		Else
			pcselect = [select a.explicatie,a.cont,] + ;
				IIF(tlDoarConturi, [], [a.acont,]) + [a.id_plcont,a.tip_sold from vplcont_used a ]
		Endif
		pcFiltruOriginal = [ a.an=] + Alltrim(Str(gnan)) + IIF(tlDoarConturi, [ and a.acont is null], [])
	Endif

	If !Empty(tcListaConturi) And Empty(tntipg)
		pcselect = [select a.explicatie,a.cont,] + ;
			IIF(tlDoarConturi, [], [a.acont,]) + [a.id_plcont,a.tip_sold from vplcont_used a ]
		pcFiltruOriginal = [ a.an=] + Alltrim(Str(gnan)) + [ and a.cont in (] + Alltrim(tcListaConturi) + [)] + ;
			IIF(tlDoarConturi, [ and a.acont is null], [])
	Endif

	If !Empty(tntipg) And Empty(tcListaConturi)
		pcselect = [select a.explicatie,a.cont,] + ;
			IIF(tlDoarConturi, [], [a.acont,]) + [a.id_plcont,a.tip_sold,b.id_tipgest from vplcont_used a inner join coresp_cont_tipgest b on a.cont = b.cont ]
		pcFiltruOriginal = [ b.id_tipgest = ] + Alltrim(Str(tntipg)) + [ and a.an=] + Alltrim(Str(gnan)) + ;
			IIF(tlDoarConturi, [ and a.acont is null], [])
	Endif

	If !Empty(tntipg) And !Empty(tcListaConturi)
		pcselect = [select a.explicatie,a.cont,] + ;
			IIF(tlDoarConturi, [], [a.acont,]) +  [a.id_plcont,a.tip_sold,b.id_tipgest from vplcont_used a inner join coresp_cont_tipgest b on a.cont = b.cont ]
		pcFiltruOriginal = [ b.id_tipgest = ] + Alltrim(Str(tntipg)) + [ and a.an=] + Alltrim(Str(gnan)) + ;
			[ and a.cont in (] + Alltrim(tcListaConturi) + [)] + ;
			IIF(tlDoarConturi, [ and a.acont is null], [])
	Endif

	lcNumeProc = []
	lcPrimaColoana = [a.cont]
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, lcNumeProc, llToateIreg, pcFiltruOriginal, lcPrimaColoana)		&& 11.07.2007

	Return loCauta
	******************************************* SFARSIT: caut_cont *******************************************


	******************************************* INCEPUT:caut_acont *******************************************

Function caut_acont
	Lparameters tncont

	lcCont = tncont
	Store "" To loCauta
	pcselect = [select a.acont,a.explicatie,a.id_plcont,a.an FROM vplcont_used_analitic a ]
	pcfiltru = [1=2]
	pcschema = []
	pcorder = [acont]
	pccoloane = [acont,explicatie]
	If Pcount() < 1
		pcTitlu = [Alegeti contul analitic]
	Else
		pcTitlu = [Alegeti contul analitic pentru contul ] + Alltrim(lcCont)
	Endif
	pcTitluColoane = [Acont,Explicatie]
	If Pcount() < 1
		pcFiltruOriginal = [1=2]
	Else
		pcFiltruOriginal = [ a.cont=] + Alltrim(lcCont) + [ and a.an=] + Alltrim(Str(gnan))
	Endif
	lcNumeProc = []
	llToateIreg = .F.
	lcPrimaColoana = [a.acont]
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, lcNumeProc, llToateIreg, pcFiltruOriginal, lcPrimaColoana)		&& 11.07.2007

	Return loCauta

	******************************************* SFARSIT: caut_acont *******************************************

	******************************************* INCEPUT:caut_gestiune *******************************************

Function caut_gestiune
	Lparameters tntipg, tnid_util, tlToateIreg, tcTitlu

	Store "" To loCauta
	pcselect = [select distinct nume_gestiune,cgest,id_gestiune,nr_pag,cont from vgest_gestiuni_util ]
	pcfiltru = [1=2]
	pcschema = []
	pcorder = [nume_gestiune]
	pccoloane = [nume_gestiune,cgest]
	pcTitlu = Iif(Empty(tcTitlu), [Alegeti gestiunea], Alltrim(Upper(tcTitlu)))
	pcTitluColoane = [Gestiune,Cgest]
	lncount = Pcount()

	Do Case
		Case Type('tnId_Util') = 'N'
			If Empty(tntipg)
				pcFiltruOriginal = [inactiv = 0 and id_util = ] + Alltrim(Str(tnid_util))
			Else
				pcFiltruOriginal = [inactiv = 0 and nr_pag = ] + Alltrim(Str(tntipg)) + [ and id_util = ] + Alltrim(Str(tnid_util))
			Endif
		Case Type('tnTipg') = 'N'
			pcFiltruOriginal = [inactiv = 0]
		Otherwise
			pcselect = [select nume_gestiune,cgest,id_gestiune,nr_pag,cont from vnom_gestiuni ]
			pcFiltruOriginal = [inactiv = 0]
	Endcase

	lcNumeProc = []
	llToateIreg = tlToateIreg
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, lcNumeProc, llToateIreg, pcFiltruOriginal)		&& 11.07.2007

	Return loCauta

	******************************************* SFARSIT: caut_gestiune *******************************************
	Function caut_gestiune_sectie
	Lparameters tntipg, tnIdSectie, tnid_util, tcTitlu

	Store "" To loCauta
	pcselect = [select distinct nume_gestiune,cgest,id_gestiune,nr_pag,cont from vgest_gestiuni_util ]
	pcfiltru = [1=2]
	pcschema = []
	pcorder = [nume_gestiune]
	pccoloane = [nume_gestiune,cgest]
	pcTitlu = Iif(Empty(tcTitlu), [Alegeti gestiunea], Alltrim(Upper(tcTitlu)))
	pcTitluColoane = [Gestiune,Cgest]

	pcFiltruOriginal = [inactiv = 0]
	if Type('tnTipg') = 'N'
		pcFiltruOriginal = pcFiltruOriginal + [ and nr_pag = ] + Alltrim(Str(tntipg))
	endif
	if Type('tnIdSectie') = 'N'
		pcFiltruOriginal = pcFiltruOriginal + [ and id_sectie = ] + Alltrim(Str(tnIdSectie))
	Endif
	if Type('tnId_Util') = 'N'
		pcFiltruOriginal = pcFiltruOriginal + [ and id_util = ] + Alltrim(Str(tnid_util))
	Endif
	lcNumeProc = []
	llToateIreg = .F.
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, lcNumeProc, llToateIreg, pcFiltruOriginal)

	Return loCauta

	******************************************* SFARSIT: caut_gestiune *******************************************
	******************************************* INCEPUT: caut_gestiune_xml *******************************************
Function caut_gestiune_xml
	Lparameters tnTip, tlToateIreg, tnPornire, tlLoud, tcListaId, tcListaDenumire
	&& tnTip : 1 = toate gestiunile; 2 = gestiunile pe care are drept utilizatorul
	*** tnPornire: incepe cu...,1,este...,2,nu este...,3,contine...,4,nu contine...,5,toate,6
	*** tlLoud = .T. daca apare messagebox "Nu ati selectat nici o inregistare" pentru cautarea multipla. Default = .F.
	*** tcListaId = parametru OUT - lista id-uri articole
	*** tcListaDenumire = parametru OUT - lista denumiri articole

	*!*	04.09.2009
	Local lnPornire
	Local lcFiltru, lcIdColumn, lcNume_Proc, lcPrimaColoana, lcTitlu, lcXMLGestiuni, lnTipReturn
	Local loLista
	Local lnTip, llAllInList
	Local lcSelect, lcSchema, lcOrder, llAfisare, lcGroup, llModParam, lcFiltruOriginal, lcCOloana, lcTitluColoana, lnPornire

	lnPornire = Iif(Empty(tnPornire), CA_PORNIRE_TOATE, tnPornire)

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

	If lnTip = 1
		lcSelect = [select distinct a.nume_gestiune,a.cgest,a.id_gestiune,a.nr_pag,a.cont from vgest_gestiuni_util a]
	*!* 22.02.2010
*!*			lcFiltruOriginal = []
		*!*	modificare	ROAGEST v 2.2.4
		*!*	lcFiltruOriginal = SUBSTR(gcCondSucursala, 6)
		lcFiltruOriginal = SUBSTR(STRTRAN(gcCondSucursala, [id_sucursala], [a.id_sucursala]), 6)
		*!*	modificare	ROAGEST v 2.2.4	^				
	*!* 22.02.2010 ^
		lcFiltruOriginal = lcFiltruOriginal + [ and a.inactiv = 0 ] 	&&	modificare	ROAGEST v 2.2.4
	Else
		lcSelect = [select distinct c.nume_gestiune,c.cgest,b.id_gestiune,c.nr_pag,c.cont ] + ;
			[from gest_coresp_util_grupe a ] + ;
			[left join gest_coresp_grupe_gestiuni b on a.id_grupe=b.id_grupe ] + ;
			[left join nom_gestiuni c on b.id_gestiune=c.id_gestiune ]

		*!* 22.02.2010
		*!*			lcFiltruOriginal = [a.id_util = ] + Alltrim(Str(gnIdUtil))
		*!*	modificare	ROAGEST v 2.2.4
		*!*	lcFiltruOriginal = [a.id_util = ] + Alltrim(Str(gnIdUtil)) + gcCondSucursala
		lcFiltruOriginal = [a.id_util = ] + Alltrim(Str(gnIdUtil)) + STRTRAN(gcCondSucursala, [id_sucursala], [c.id_sucursala])
		*!*	modificare	ROAGEST v 2.2.4	^
		*!* 22.02.2010 ^		
		lcFiltruOriginal = lcFiltruOriginal + [ and c.inactiv = 0 ] 	&&	modificare	ROAGEST v 2.2.4
	Endif

	lcFiltru = []
	lcSchema = [nume_gestiune C(50),cgest C(20),id_gestiune N(5),nr_pag N(2),cont C(4)]
	lcOrder = [nume_gestiune]
	llAfisare = .F.
	lcGroup = []
	llModParam = .T.


	lcCOloana = "nume_gestiune,cgest,nr_pag,cont"
	lcTitluColoana = "Nume, Cgest, Nr.pag, Cont"
	llAllInList = tlToateIreg
	lcPrimaColoana = "nume_gestiune"
	lcNume_Proc = ""
	lcTitlu = "Alegeti gestiunea (mouse-click pe nume sau apasati SPACE)"
	lnTipReturn = 1 && XML
	lcIdColumn = "id_gestiune"
	lcXMLGestiuni = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcCOloana, lcTitlu, lcTitluColoana, lcNume_Proc, llAllInList, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)		&& 11.07.2007

	*!*	XMLTOCURSOR(lcXMLFacturi, "crsFacturi",0)
	*!* 24.08.2011
	loLista = XML2ListaIDDescriere(lcXMLGestiuni, "id_gestiune", "nume_gestiune", m.tlLoud)
	tcListaId = loLista.ListaId
	tcListaDenumire = loLista.ListaDenumire
	*!* 24.08.2011

	Return lcXMLGestiuni
Endfunc && caut_gestiune_xml
******************************************* SFARSIT: caut_gestiune_xml *******************************************
******************************************* INCEPUT:caut_responsabil *******************************************
Function caut_responsabil
	Lparameters tlToateIreg

	Local  lcCont, loCauta

	Store "" To loCauta

	pcselect = [select id_responsabil, nume, marca, cnp, formatie, meserie FROM Vnom_responsabili ]
	pcfiltru = [1=2]
	pcschema = []
	pcorder = [NUME, marca]
	pccoloane = [nume,marca,cnp,formatie,meserie,id_responsabil]
	pcTitlu = [Alegeti responsabilul]
	pcTitluColoane = [Nume,Marca,CNP,formatie,meserie,Id]
	pcFiltruOriginal = [inactiv = 0]
	lcNumeProc = [nom_parteneri;] + Alltrim(Str(gnIdTipResponsabili)) + [,'RESPONSABIL',1,2]
	llToateIreg = tlToateIreg

	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, lcNumeProc, llToateIreg, pcFiltruOriginal)		&& 11.07.2007

	Return loCauta
	******************************************* SFARSIT: caut_responsabil *******************************************
	******************************************* INCEPUT:caut_responsabil_stoc *******************************************
Function caut_responsabil_stoc
	Lparameters tlToateIreg

	Local  lcCont, loCauta

	Store "" To loCauta

	pcselect = [select distinct s.id_responsabil, p.denumire, sp.marca ] + ;
		[ from stoc_obinv s left join nom_parteneri p on s.id_responsabil = p.id_part ] + ;
		[ left join sal_personal sp on s.id_responsabil = sp.id_part ]
	pcfiltru = [1=2]
	pcschema = [id_responsabil n(10), denumire c(50), marca n(10)]
	pcorder = [denumire, marca]
	pccoloane = [denumire, Marca, id_responsabil]
	pcTitlu = [Alegeti responsabilul]
	pcTitluColoane = [Nume,Marca,Id]
	pcFiltruOriginal = [s.an = ?gnAn and s.luna = ?gnLuna] + Strtran(gcCondSucursala, [id_sucursala], [s.id_sucursala])
	lcNumeProc = [nom_parteneri;] + Alltrim(Str(gnIdTipResponsabili)) + [,'RESPONSABIL',1,2]
	llToateIreg = tlToateIreg

	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, lcNumeProc, llToateIreg, pcFiltruOriginal)		&& 11.07.2007

	Return loCauta
	******************************************* SFARSIT: caut_responsabil_stoc *******************************************
	******************************************* INCEPUT: caut_delegati *******************************************
Procedure caut_delegati
	Lparameters tnIdPart
	Local loCauta, llReturn, lcSelect, lcProcedura
	Store "" To loCauta
	Store .F. To llReturn
	If !Empty(tnIdPart)
		lcSelect = [select id_responsabil,nume,bi,cnp,eliberatde from vnom_delegati_part]
		lcFiltruOrig = [id_part=] + Alltrim(Str(tnIdPart))
		lcProcedura = [nom_parteneri;] + Alltrim(Str(gnIdTipDelegati)) + [,'DELEGAT',1,2,] + Alltrim(Str(tnIdPart))
	Else
		lcSelect = [select id_responsabil,nume,bi,cnp,eliberatde from vnom_delegati]
		lcProcedura = [nom_parteneri;] + Alltrim(Str(gnIdTipDelegati)) + [,'DELEGAT',1,2]
		lcFiltruOrig = []
	Endif
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [2]
	lccoloane = [nume,bi,cnp]
	lcTitlu = [Alegeti delegatul]
	lcTitluColoane = [Nume,BI/CI,CNP]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcProcedura, .F., lcFiltruOrig)		&& 11.07.2007
	Return loCauta
Endproc
******************************************* SFARSIT: caut_delegati *******************************************
***************************************** INCEPUT: caut_delegati_hash *****************************************
Procedure caut_delegati_hash
	Lparameters tnIdPart, tlAdaugaCoresp
	Local loCauta, llReturn, lcSelect, lcProcedura
	Store "" To loCauta
	Store .F. To llReturn
	If Empty(tnIdPart)
		loCauta = caut_delegati()
	Else
		lcSelect = [select MIN(case when c.id_part = ] + Alltrim(Str(tnIdPart)) + [ then 0 ] + ;
			[when b.id_tip_part = ] + Alltrim(Str(gnIdTipDelegati)) + [ then 2 ] + ;
			[else 1 end) as tip,] + ;
			[a.id_part as id_responsabil,a.denumire as nume,a.reg_comert as bi,a.cod_fiscal as cnp,] + ;
			[a.localitate_inreg as eliberatde,a.telefon as telefon1,a.telefon2 ] + ;
			[from vnom_parteneri a ] + ;
			[join coresp_tip_part b on a.ID_PART = b.id_part ] + ;
			[left join coresp_delegati_part c on b.id_part = c.id_delegat and c.sters = 0 ]
		lcFiltruOrig = [a.inactiv = 0]
		lcProcedura = [nom_parteneri;] + Alltrim(Str(gnIdTipDelegati)) + [,'DELEGAT',1,2,] + Alltrim(Str(tnIdPart))
		lcFiltru = [1=2]
		lcSchema = []
		lcGroup = [a.id_part, a.denumire, a.reg_comert, a.cod_fiscal, a.localitate_inreg, a.telefon, a.telefon2]
		lcOrder = [min(case when c.id_part = ] + Alltrim(Str(tnIdPart)) + [ then 0 else 1 end),a.denumire]
		lccoloane = [nume,bi,cnp]
		lcTitlu = [Alegeti delegatul]
		lcTitluColoane = [Nume,BI/CI,CNP]
		loHash = GetHash()
		With loHash
			.SetValue("cSelect", lcSelect)
			.SetValue("cFiltru", lcFiltru)
			.SetValue("cGroup", lcGroup)
			.SetValue("cOrder", lcOrder)
			.SetValue("cColoana", lccoloane)
			.SetValue("cTitlu", lcTitlu)
			.SetValue("cTitluColoana", lcTitluColoane)
			.SetValue("cFiltruOriginal", lcFiltruOrig)
			.SetValue("cPrimaColoana", "nume")
			.SetValue("cNumeProc", lcProcedura)
			.SetValue("cGridDynamicBackColor", [IIF(TIP = 2, Rgb(180,180,180), Iif(TIP=1, RGB(225,225,225), RGB(255,255,255) ))])
			.SetValue("cGridToolTip", "Parteneri colorati in gri deschis nu sunt delegati ai acestui partener." + ;
				    Chr(13) + Chr(10) + "Partenerii colorati in gri inchis nu sunt delegati.")
		Endwith

		loCauta = cauta_alfa_hash(loHash)

		If tlAdaugaCoresp And !Isnull(loCauta) And Type('loCauta.id_responsabil') = 'N' And loCauta.id_responsabil <> 0 And loCauta.tip <> 0
			If loCauta.tip = 1
				Do ADAUGA_CORESP_DELEGAT With loCauta.id_responsabil, tnIdPart In oproceduri_parteneri.prg
			Else
				Do Adauga_Delegat_Partener With loCauta.id_responsabil, tnIdPart In oproceduri_parteneri.prg
			Endif
		Endif
	Endif
	Return loCauta
Endproc	&&	caut_delegati_hash
***************************************** SFARSIT: caut_delegati_hash *****************************************
******************************************* INCEPUT: caut_grupa_articole *******************************************
Procedure caut_grupa_articole
	Lparameters tlToateIreg
	Local loCauta, llReturn
	Store "" To loCauta
	Store .F. To llReturn
	pcselect = [select id_grupa,grupa from vgest_art_gr]
	pcfiltru = [1=2]
	pcschema = []
	pcorder = [2]
	pccoloane = [grupa]
	pcTitlu = [Alegeti grupa de articole]
	pcTitluColoane = [Grupa]
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "", tlToateIreg)		&& 11.07.2007
	Return loCauta
Endproc
****************************************** SFARSIT: caut_grupa_articole *******************************************
******************************************* INCEPUT: caut_grupa_articole_xml *******************************************
Procedure caut_grupa_articole_xml
	Lparameters tlToateIreg
	Local loCauta, llReturn
	Store "" To loCauta
	Store .F. To llReturn
	pcselect = [select id_grupa,grupa from vgest_art_gr]
	pcfiltru = [1=2]
	pcschema = []
	pcorder = [2]
	pccoloane = [grupa]
	pcTitlu = [Alegeti grupele (mouse-click pe nume sau apasati SPACE)]
	pcTitluColoane = [Grupa]

	lcFiltruOriginal = [2=2]
	lcPrimaColoana = "grupa"
	lnPornire = 5
	lnTipReturn = 1 && XML
	lcIdColumn = "id_grupa"
	lcXMLGrupe = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "", tlToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)

	Return lcXMLGrupe
Endproc
****************************************** SFARSIT: caut_grupa_articole_xml *******************************************
**************************************** INCEPUT: caut_subgrupa_articole ******************************************
Procedure caut_subgrupa_articole
	LPARAMETERS tcFiltruOriginal, tlToateIreg, tlMultipleArticles, tnPornire, tlLoud, tcListaId, tcListaDenumire
	*** tnPornire: incepe cu...,1,este...,2,nu este...,3,contine...,4,nu contine...,5,toate,6
	*** tlLoud = .T. daca apare messagebox "Nu ati selectat nici o inregistare" pentru cautarea multipla. Default = .F.
	*** tcListaId = parametru OUT - lista id-uri articole
	*** tcListaDenumire = parametru OUT - lista denumiri articole

	Local loCauta, llReturn, loLista
	Local lcFiltruOriginal, lcIdColumn, lcNumeProc, lcPrimaColoana, lcTitlu, lcTitluColoane, lccoloane
	Local lcfiltru, lcorder, lcschema, lcselect, llMultipleArticles, llToateIreg, lnPornire, lnTipReturn

	loCauta = ""
	llReturn = .F.
	lcselect = [select id_subgrupa,subgrupa,grupa,indicativ from vgest_art_sbgr]
	lcfiltru = [1=2]
	lcschema = []
	lcorder = [2]
	lccoloane = [subgrupa,grupa,indicativ]
	lcIdColumn = "id_subgrupa"
	lcPrimaColoana = "subgrupa"

	lcTitluColoane = [Subgrupa,Grupa,Indicativ]
	llToateIreg = tlToateIreg
	If tlMultipleArticles
		lcTitlu = [Alegeti subgrupele (mouse-click pe denumire sau apasati SPACE)]
	Else
		lcTitlu = [Alegeti subgrupa de articole]
	Endif
	lcNumeProc = ""
	lcFiltruOriginal = Iif(!Empty(tcFiltruOriginal), Alltrim(tcFiltruOriginal), "")
	llMultipleArticles = tlMultipleArticles
	llToateIreg = tlToateIreg
	lnPornire = Iif(Empty(m.tnPornire), CA_PORNIRE_INCEPE, m.tnPornire)
	lnTipReturn = Iif(tlMultipleArticles, 1, 0)

	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)		&& 11.07.2007

	*!* 24.08.2011
	IF m.llMultipleArticles
		loLista = XML2ListaIDDescriere(loCauta, "id_subgrupa", "subgrupa", tlLoud)
		tcListaId = loLista.ListaId
		tcListaDenumire = loLista.ListaDenumire
	ENDIF
	*!* 24.08.2011

	Return loCauta
Endproc
******************************************* SFARSIT: caut_delegati *******************************************
******************************************* INCEPUT:caut_grupa_gestiune *******************************************
Function caut_grupa_gestiune
	Lparameters tnIdGrupa, tlToateIreg

	** tnIdGrupa = arat toate grupele in afara (eventual) de grupa pe care am selectat-o in cazul alegerii grupei parinte
	Local  lcCont, loCauta

	Store "" To loCauta
	If Pcount() = 2
		llToateIreg = tlToateIreg
	ELSE
		llToateIreg = .T.
	Endif

	pcselect = [select id_grupe, nume_grupa FROM vgest_nom_grupe]
	pcfiltru = []
	pcschema = []
	pcorder = [nume_grupa]
	pccoloane = [nume_grupa]
	pcTitlu = [Grupa]
	pcTitluColoane = [Grupa]
	pcFiltruOriginal = [inactiv = 0 ] + Iif(!Empty(tnIdGrupa), [ and id_grupe <> ] + Transform(tnIdGrupa), [])
	lcNumeProc = []
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, lcNumeProc, llToateIreg, pcFiltruOriginal)		&& 11.07.2007

	Return loCauta
Endfunc && caut_grupa_gestiune
******************************************* SFARSIT: caut_grupa_gestiune *******************************************


******************************************* INCEPUT:caut_valuta *******************************************
Function caut_valuta
	Parameters tnPornire, tlDesktop, tlFaraMonedaNationala

	Local  lcCont, loCauta, lnPornire, llDesktop
	lnPornire = tnPornire && 1-incepe cu...6-toate
	llDesktop = tlDesktop
	llFaraMonedaNationala = tlFaraMonedaNationala
	Store "" To loCauta

	lcSelect = [select id_valuta, nume_val, nume_val2, moneda_nationala FROM vnom_valute]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [nume_val]
	lccoloane = [nume_val,nume_val2]
	lcTitlu = [Alegeti valuta]
	lcTitluColoane = [Valuta,Simbol]
	If llFaraMonedaNationala
		lcFiltruOriginal = [inactiv = 0 and moneda_nationala = 0]
	Else
		lcFiltruOriginal = [inactiv = 0]
	Endif
	lcNumeProc = []
	llToateIreg = .F.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, , lnPornire, , , llDesktop)		&& 11.07.2007

	Return loCauta
Endfunc && caut_valuta
******************************************* SFARSIT: caut_valuta *******************************************
******************************************* INCEPUT:caut_valuta_iso *******************************************
Function cauta_valuta_iso
	Lparameters tnTipCautare, tcParametru
*!*	tnTipCautare
*!*		1	-	arata pe toate
*!*		2	-	arata pe toate in afara de cele care se afla deja in nom_valute si nu sunt sterse/inactive 
*!*		3	-	nu arata formularul de cautare, ci cauta direct in baza de date o valuta care sa aiba iso-ul ca tcParametru
	Local lcValutaIso, loCauta, lcSelect, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcFiltruOriginal, lcNumeProc, llToateIreg, lnSucces, lcCursor, lnTipCautare
	Store "" To loCauta
	lcSelect = [select id_valuta_iso,nume_valuta,iso_valuta from syn_vnom_valute_iso]
	lcFiltru = IIF(!EMPTY(tcParametru), [iso_valuta like '] + Upper(Alltrim(tcParametru)) + [%'], [1=2])
	lnTipCautare = IIF(EMPTY(tnTipCautare), 1, tnTipCautare)
	If Inlist(lnTipCautare, 1, 2)
		lcSchema = []
		lcOrder = [iso_valuta]
		lcColoane = [nume_valuta,iso_valuta]
		lcTitlu = [Alegeti simbolul ISO]
		lcTitluColoane = [Denumire,Simbol ISO]
		If lnTipCautare = 2
			lcFiltruOriginal = [id_valuta_iso not in (select id_valuta_iso from nom_valute where sters = 0 and inactiv = 0 and id_valuta_iso is not null)]
		Else
			lcFiltruOriginal = [2=2]
		Endif
		lcNumeProc = []
		llToateIreg = .F.
		loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal)
	Else
		If lcFiltru <> [1=2]
			lcSelect = lcSelect + [ where ] + lcFiltru
			lcCursor = Sys(2015)
			lnSucces = goExecutor.oExecute(lcSelect, lcCursor)
			If lnSucces < 0
				amessagebox(goExecutor.cEroare, 64, "Eroare")
			Else
				If Reccount(lcCursor) = 1
					Select (lcCursor)
					Scatter Name loCauta
				Endif
				Use In (lcCursor)
			Endif
		Endif
	Endif
	Release lcValutaIso, lcSelect, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcFiltruOriginal, lcNumeProc, llToateIreg, lnSucces, lcCursor
	Return IIF(TYPE('loCauta') = 'C', NULL, loCauta)
Endfunc && caut_valuta_iso
******************************************* SFARSIT: caut_valuta_iso *******************************************
******************************************* INCEPUT:caut_fdoc *******************************************
Function caut_fdoc
	Parameters llToateIreg, tlNou
	Local  lcCont, loCauta

	Store "" To loCauta

	lcSelect = [select id_fdoc, fel_document, tip_doc, descriere FROM vnom_fdoc]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [fel_document]
	lccoloane = [fel_document, tip_doc, descriere]
	lcTitlu = [Alegeti felul documentului]
	lcTitluColoane = [Fel Document, Tip, Descriere]
	lcFiltruOriginal = [inactiv = 0]
	If tlNou
		lcNumeProc = [nom_fdoc]
	Else
		lcNumeProc = []
	Endif

	llToateIreg = .F.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal)		&& 11.07.2007

	Return loCauta
	******************************************* SFARSIT: caut_fdoc *******************************************
Procedure caut_alfa_beta
	Lparameters tcTabela, tcSuperCombo, tnvalueSC	&& tcSuperCombo = "nume_camp:tip_data;"


	lcTabela = Alltrim(tcTabela)
	lcSC = Alltrim(tcSuperCombo)

	lnLen = Getwordcount(lcSC, ';')

	Dimension taSC[lnLen, 5]  &&1-camp,2-tip_data,3-nrzec,4-inputmask,5-rezervat filtru

	For i = 1 To lnLen
		lcSc1 = Getwordnum(lcSC, i, ';')
		taSC[i, 1] = Getwordnum(lcSc1, 1, ':')
		taSC[i, 2] = Getwordnum(lcSc1, 2, ':')
		taSC[i, 3] = Getwordnum(lcSc1, 3, ':')
		taSC[i, 4] = Getwordnum(lcSc1, 4, ':')
	Endfor

	Return @taSC

Endproc

*****************************************************************************
Procedure update_articole
	If Used('v_articole')
		Use In v_articole
	Endif
	lcSql = [select id_articol, codmat, denumire as nume_articol, um, cant_bax, um2,compus from vnom_articole_crm order by denumire ]
	lnSucces = goExecutor.oExecute(lcSql, 'v_articole')
	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare, 0 + 16, 'Eroare')
	Endif
	goExecutor.oReset()
	Return lnSucces

Endproc	&&	update_articole
*****************************************************************************
******************************************* INCEPUT:caut_sectie *******************************************
Function caut_sectie
	Parameters tnPornire, tlDesktop, tlToateIreg, tlNou, tcFiltruOriginal

	Local  lcCont, loCauta, lnPornire, llDesktop
	lnPornire = tnPornire && 1-incepe cu...6-toate
	llDesktop = tlDesktop

	Store "" To loCauta

	lcSelect = [select id_sectie, sectie, csectie FROM vnom_sectii]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [sectie]
	lccoloane = [sectie, csectie]
	lcTitlu = [Alegeti sectia]
	lcTitluColoane = [Sectie, Indicativ]
	lcFiltruOriginal = [inactiv = 0] + gcCondSucursala + IIF(!EMPTY(tcfiltruOriginal), [ and ] + tcFiltruOriginal, [])	
	lcNumeProc = IIF(m.tlNou, [nom_sectii], [])
	llToateIreg = m.tlToateIreg
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, , lnPornire, , , llDesktop)		&& 11.07.2007

	Return loCauta
Endfunc && caut_sectie
******************************************* SFARSIT: caut_sectie *******************************************

******************************************* INCEPUT:caut_venchelt *******************************************
Function caut_venchelt
	Parameters tnPornire, tlDesktop, tnTip, tnId, tlToateIreg, tlNou, tcFiltruOriginal

	Local  lcCont, loCauta, lnPornire, llDesktop
	lnPornire = Iif(!Empty(tnPornire), 1, tnPornire) && 1-incepe cu...6-toate
	llDesktop = Iif(!Empty(tlDesktop), tlDesktop, .F.) && formulare desktop = .T.
	&& tnTip: 1 = cheltuieli, ,2 = venituri

	Store "" To loCauta
	lcFiltruOriginal = [inactiv = 0] + IIF(!EMPTY(m.tcFiltruOriginal), [ and ] + m.tcFiltruOriginal, [])
	If !Empty(tnId)
		lcFiltruOriginal = lcFiltruOriginal + [ and id_venchelt <> ] + Alltrim(Str(tnId))
	Endif
	If !Empty(tnTip)
		lcFiltruOriginal = lcFiltruOriginal + [ and tip_venchelt = ] + Alltrim(Str(tnTip))
	Endif

	lcSelect = [select id_venchelt, explicatie, (case tip_venchelt when 1 then 'C' else 'V' end) as tip_venchelt FROM vnom_venchel ]
	lcFiltru = [1=2]
	lcSchema = [id_venchelt n(10),explicatie c(100),tip_venchelt c(1)]
	lcOrder = [explicatie]
	lccoloane = [explicatie,tip_venchelt]
	lcTitlu = [Alegeti venitul/cheltuiala]
	lcTitluColoane = [Explicatia, Tip]
	lcNumeProc = IIF(m.tlNou, [nom_venchel], [])
	llToateIreg = m.tlToateIreg
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, , lnPornire, , , llDesktop)		&& 11.07.2007

	Return loCauta
Endfunc && caut_venchelt
******************************************* SFARSIT: caut_venchelt *******************************************
******************************************* INCEPUT:caut_ven *******************************************
Function caut_ven
	Parameters tnPornire, tlDesktop

	Local  lcCont, loCauta, lnPornire, llDesktop
	lnPornire = tnPornire && 1-incepe cu...6-toate
	llDesktop = tlDesktop

	Store "" To loCauta

	lcSelect = [select id_venchelt, explicatie FROM vnom_venchel ]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [explicatie]
	lccoloane = [explicatie]
	lcTitlu = [Alegeti venitul]
	lcTitluColoane = [Explicatia]
	lcFiltruOriginal = [inactiv = 0 and tip_venchelt <> 1]
	lcNumeProc = []
	llToateIreg = .F.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, , lnPornire, , , llDesktop)		&& 11.07.2007

	Return loCauta
Endfunc && caut_ven
******************************************* SFARSIT: caut_ven *******************************************



*------------------------------------------------------------
* Description: INTOARCE XML CU FACTURI ALESE DIN FACTURI EMISE IN PERIOADA
* Parameters:  tcCont, tnIdPart, tdData1, tdData2
* Return: lcXMLFacturi
* Use: lcXMLFacturi = Caut_Facturi(lcCont, lnIdPart, ldData1, ldData2)
*------------------------------------------------------------
* Id Date        By         Description
*  1 23/06/2006  marius.mutu Initial Creation
*------------------------------------------------------------
Function caut_facturi
	Lparameters tcCont, tnIdPart, tdData1, tdData2

	Local  loCauta, ldData1, ldData2, lnTipCont

	Store Null To loCauta
	ldData1 = tdData1
	ldData2 = tdData2


	Private pnNrLuna1, pnNrLuna2, pnIdPart, pcCont
	pnNrLuna1 = Year(ldData1) * 12 + Month(ldData1)
	pnNrLuna2 = Year(ldData2) * 12 + Month(ldData2)
	pnIdPart = tnIdPart
	pcCont = tcCont

	lnTipCont = GetTipContIreg(pcCont)

	lcSelect = [select i.id_ireg_part, i.an, i.luna, i.nume, i.cont, i.acont, i.id_fact, i.serie_act, i.nract, i.dataact, i.datascad, i.preccred + i.credit as totctva FROM VIREG_EMISE_IN_PERIOADA i]
	lcFiltru = []
	lcSchema = [id_ireg_part N(20), AN N(4), LUNA N(2), NUME C(100), CONT C(4), ACONT C(4), ID_FACT N(20), SERIE_ACT C(10), NRACT N(20), DATAACT D, DATASCAD D, TOTCTVA N(20,4)]
	lcOrder = [i.dataact, i.nract]
	llAfisare = .F.
	lcGroup = []
	llModParam = .T.
	lcFiltruOriginal = [i.an * 12 + i.luna between ?pnNrLuna1 and ?pnNrLuna2 and i.id_part = ?pnIdPart AND i.cont in (SELECT x AS cont FROM table(charc2collection(?pcCont, ',')))]

	lcCOloana = "nume, serie_act, nract, dataact, datascad, totctva"
	lcTitluColoana = "Nume, Serie act, Numar act, Data act, Data scad, Total factura"
	llAllInList = .F.
	lnPornire = 6 && TOATE
	lcPrimaColoana = "NUME"
	lcNume_Proc = ""
	lcTitlu = "Alegeti facturile (mouse-click pe nume sau apasati SPACE)"
	lnTipReturn = 1 && XML
	lcIdColumn = "id_ireg_part"
	lcXMLFacturi = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcCOloana, lcTitlu, lcTitluColoana, lcNume_Proc, llAllInList, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)		&& 11.07.2007

	*!*	XMLTOCURSOR(lcXMLFacturi, "crsFacturi",0)

	Return lcXMLFacturi
Endfunc && caut_facturi
******************************************* SFARSIT: caut_facturi *******************************************

*------------------------------------------------------------
*  caut factura in luna curenta dupa nume, numar si intorc id_fact
*------------------------------------------------------------
Function caut_factura
	Lparameters tcCont, tdData1, tdData2

	Local  loFactura, ldData1, ldData2

	loFactura = NULL
	ldData1 = tdData1
	ldData2 = tdData2
	
	Private pnNrLuna1, pnNrLuna2, pcCont
	pnNrLuna1 = Year(ldData1) * 12 + Month(ldData1)
	pnNrLuna2 = Year(ldData2) * 12 + Month(ldData2)
	pcCont = tcCont
	
	lcSelect = [select i.id_ireg_part, i.an, i.luna, i.nume, i.cont, i.acont, i.id_fact, i.serie_act, i.nract, i.dataact, i.datascad, i.preccred + i.credit as totctva FROM VIREG_EMISE_IN_PERIOADA i]
	lcFiltru = []
	lcSchema = [id_ireg_part N(20), AN N(4), LUNA N(2), NUME C(100), CONT C(4), ACONT C(4), ID_FACT N(20), SERIE_ACT C(10), NRACT N(20), DATAACT D, DATASCAD D, TOTCTVA N(20,4)]
	lcOrder = [i.dataact, i.nract]
	llAfisare = .F.
	lcGroup = []
	llModParam = .T.
	lcFiltruOriginal = [i.an * 12 + i.luna between ?pnNrLuna1 and ?pnNrLuna2 AND i.cont in (SELECT x AS cont FROM table(charc2collection(?pcCont, ',')))]

	lcCOloana = "nume, serie_act, nract, dataact, datascad, totctva, id_fact"
	lcTitluColoana = "Nume, Serie act, Numar act, Data act, Data scad, Total factura, Id Fact"
	llAllInList = .F.
	lnPornire = 1 && INCEPE CU
	lcPrimaColoana = "NUME"
	lcNume_Proc = ""
	lcTitlu = "Alegeti factura"
	lnTipReturn = 0 && object
	lcIdColumn = "id_fact"
	loFactura = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcCOloana, lcTitlu, lcTitluColoana, lcNume_Proc, llAllInList, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)		&& 11.07.2007

	Return loFactura
Endfunc && caut_facturi
******************************************* SFARSIT: caut_facturi *******************************************

*------------------------------------------------------------
* Description: INTOARCE TIPUL SOLDULUI CONTULUI (0 = ACTIV/DEBITOR, 1 = PASIV/CREDITOR)
* Parameters:  <tcCont>
* Return: 0 (DEBITOR), 1 (CREDITOR)
* Use: lnTip = GetTipContIreg("401")
*------------------------------------------------------------
* Id Date        By         Description
*  1 23/06/2006  marius.mutu Initial Creation
*------------------------------------------------------------
Function GetTipContIreg
	Parameters tcCont

	Local lcSql, lcCursor, lnSucces, lnTip

	lnTip = 0

	lcSql = [select FEL_CONT from config_cont_ireg WHERE CONT = ?tcCont]
	lcCursor = [crsTipContIreg]
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)
	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
	Else
		Select crsTipContIreg
		If Reccount('crsTipContIreg') > 0
			Go Top
			lnTip = FEL_CONT
		Endif
		Use In 	crsTipContIreg
	Endif

	Return lnTip
Endfunc && GetTipContIreg


*!* 04.07.2006
*!* marius.mutu
*!* adaugat cauta_utilizator si cauta_client din roaauto\programe\update_devize.prg
***********************************************************************
Function cauta_utilizator
	Lparameters	tnIdUtil, tcUtilizator
	Local loCauta, llReturn
	Store "" To loCauta
	Store .F. To llReturn
	pcselect = [select id_util,utilizator from syn_vutilizatori]
	pcfiltru = [1=2]
	pcschema = []
	pcorder = [utilizator]
	pccoloane = [Utilizator]
	pcTitlu = [Alegeti utilizatorul]
	pcTitluColoane = [Utilizator]
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "")		&& 11.07.2007
	If !Empty(loCauta.id_util)
		tnIdUtil = loCauta.id_util
		tcUtilizator = Alltrim(loCauta.utilizator)
		llReturn = .T.
	Endif
	Return llReturn
Endfunc	&&	cauta_utilizator
***********************************************************************
Function cauta_utilizator_firma
	Parameters tnPornire, tlDesktop
	Local  lcCont, loCauta, lnPornire, llDesktop
	***** 17.11.2008 *****

	lnPornire = tnPornire && 1-incepe cu...6-toate
	llDesktop = tlDesktop
	Store "" To loCauta

	lcSelect = [select distinct b.utilizator,a.id_util from syn_vdef_util_firme a ] + ;
		[left join syn_vutilizatori b on a.id_util = b.id_util ]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [b.utilizator]
	lccoloane = [utilizator]
	lcTitlu = [Alegeti utilizatorul]
	lcTitluColoane = [Utilizator]
	lcFiltruOriginal = [a.id_firma = ?gnIdFirma]
	lcNumeProc = []
	llToateIreg = .F.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, , lnPornire, , , llDesktop)		&& 11.07.2007

	Return loCauta
Endfunc	&&	cauta_utilizatori_firma
***********************************************************************
Function cauta_client
	Lparameters	tnIdPartener, tcNume
	Local loCauta, llReturn
	Store "" To loCauta
	Store .F. To llReturn
	pcselect = [select p.id_part,p.nume,p.cod_fiscal from vcoresp_tip_part p ] + ;
		[join vcoresp_tip_cont c on p.id_tip_part=c.id_tip_part]
	pcFiltruOrig = [c.cont ='4111' and p.inactiv=0]
	pcfiltru = [1=2]
	pcschema = ['id_part n(10),nume c(100),cod_fiscal c(100)']
	pcorder = [nume]
	pccoloane = [nume,cod_fiscal]
	pcTitlu = [Alegeti clientul]
	pcTitluColoane = [Client,Cod fiscal]
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "", .F., pcFiltruOrig)		&& 11.07.2007
	If !Empty(loCauta.id_part)
		tnIdPartener = loCauta.id_part
		tcNume = Alltrim(loCauta.nume)
		llReturn = .T.
	Endif
	Return llReturn
Endfunc
***********************************************************************


*------------------------------------------------------------
* Description: INTOARCE PRIMUL ID_TIP_PART PENTRU UN CONT
* Parameters:  <tcCont>
* Return: ID_TIP_PART
* Use: lnIdTipPart = GetContIdTipPart("4111")
*------------------------------------------------------------
* Id Date        By         Description
*  1 14/07/2006  marius.mutu Initial Creation
*------------------------------------------------------------
Function GetContIdTipPart
	Parameters tcCont

	Local lcSql, lcCursor, lnSucces, lnIdTipPart

	lnIdTipPart = 0

	lcSql = [select id_tip_part from coresp_tip_cont WHERE CONT = ?tcCont]
	lcCursor = [crsTipPartTemp]
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)
	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
	Else
		If Reccount('crsTipPartTemp') > 0
			Select crsTipPartTemp
			Go Top
			lnIdTipPart = id_tip_part
		Endif
		Use In 	crsTipPartTemp
	Endif

	Return lnIdTipPart
Endfunc && GetContIdTipPart



*** modificare serii numere	-	10.2007
*!*	Procedure getNirPlajaCMP
*!*	Lparameters tnPlaja1, tnPlaja2

*!*	&& PLAJE NIR-URI CMP
*!*	lnTip = 4 && NIR PT CMP
*!*	lnSerie = 2
*!*	lnId_entitate = 0
*!*	tnPlaja1 = 0
*!*	tnPlaja2 = 0
*!*	lcSelect = [select id_plaja,pl_inf,pl_sup from vplaje_numere where ] +;
*!*		[inactiv = 0 and tip = ] + Alltrim(Str(lnTip)) + [ and serie = ] + ;
*!*		ALLTRIM(Str(lnSerie)) + [ and id_entitate = ] + Alltrim(Str(lnId_entitate))
*!*	lcCursor = [crsplaja]
*!*	lnSucces = goExecutor.oExecute(lcSelect,lcCursor)
*!*	If lnSucces < 0
*!*		AMESSAGEBOX(goExecutor.cEroare,0+16, 'Eroare')
*!*	Else
*!*		Select crsPlaja
*!*		tnPlaja1= pl_inf
*!*		tnPlaja2 = pl_sup
*!*		Use In crsPlaja
*!*	Endif

*!*	&&(NNIR NOT BETWEEN ] + TRANSFORM(lnNnir1) + [ AND ] + TRANSFORM(lnNnir2) + [)]
*!*	&& getNirPlajaCMP(@lnPlaja1, @lnPlaja2)

*!*	Endproc &&getNirPlajaCMP
*** modificare serii numere	-	10.2007	^
*******************************************************************************************************************
Function GetTipGestiune
	Lparameters tnIdGestiune
	Local lnTipGestiune, lcCursor
	lnTipGestiune = -1
	lcCursor = [crsTipGest]
	If Used(lcCursor)
		Use In (lcCursor)
	Endif

	lcSql = [select nr_pag from ] + gcS + [.vnom_gestiuni where id_gestiune = ] + Alltrim(Str(tnIdGestiune))
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)
	If lnSucces < 0
		AMESSAGEBOX(goExecutor.cEroare, 16, "Eroare")
	Else
		If Reccount(lcCursor) > 0
			Select (lcCursor)
			lnTipGestiune = nr_pag
		Endif
	Endif

	If Used(lcCursor)
		Use In (lcCursor)
	Endif
	Return lnTipGestiune
Endfunc	&&	GetTipGestiune
*******************************************************************************************************************

* PROCEDURE caut_gruputilizatori
* Date : 18.09.2006
* author : marius.mutu
******************************************* INCEPUT:caut_gruputilizatori *******************************************
Procedure caut_gruputilizatori(tlToateIreg, tlNou)

	Local  loCauta, lcFiltruOriginal
	Local lcTitlu, lcFiltru, lcSchema, lcOrder, lcNumeProc, lcTitluColoane
	Store Null To loCauta

	lcSelect = [select id_grup, id_tata, denumire_grup, inactiv, nume_parinte from vgrupuri_utilizatori]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [denumire_grup]
	lccoloane = [denumire_grup,id_grup]
	lcFiltruOriginal = [inactiv = 0]


	lcTitlu = "Alegeti grupul"
	If tlNou
		lcNumeProc = [nom_gruputilizatori]
	Else
		lcNumeProc = []
	Endif
	lcTitluColoane = [Grup, Id]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruOriginal)		&& 11.07.2007

	Return loCauta

Endproc
******************************************* SFARSIT: caut_gruputilizatori *******************************************



* PROCEDURE caut_sucursala
* Date : 18.09.2006
* author : marius.mutu
******************************************* INCEPUT:caut_sucursala *******************************************
Procedure caut_sucursala(tlToateIreg, tlNou, tlBlank)
	&& tlBlank = .T. => arat o inregistrare goala (daca vreau sa aleg sucursala NULL pentru mama in initializari balante)

	Local  loCauta, lcFiltruOriginal
	Local lcTitlu, lcFiltru, lcSchema, lcOrder, lcNumeProc, lcTitluColoane
	Store Null To loCauta

	lcSelect = [select id_sucursala, sucursala, inactiv from vnom_sucursale]
	If tlBlank
		lcSelect = [select cast (null as number(5)) as id_sucursala, rpad(' ',100, ' ') as sucursala, 0 as inactiv from dual ] + ;
			[ UNION ] + ;
			lcSelect
	Endif
	lcFiltru = []
	lcSchema = []
	lcOrder = [sucursala]
	lccoloane = [sucursala,id_sucursala]
	If glEMama && daca este mama - arat doar sucursalele ei
		lcFiltruOriginal = [inactiv = 0 and id_mama = ?gnIdFirma]
	Else && daca este sucursala nu arat nimic
		lcFiltruOriginal = [1=2]
	Endif


	lcTitlu = "Alegeti sucursala"
	If tlNou
		lcNumeProc = [nom_sucursale]
	Else
		lcNumeProc = []
	Endif
	lcTitluColoane = [Sucursala, Id]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruOriginal)		&& 11.07.2007

	Return loCauta

Endproc
******************************************* SFARSIT: caut_gruputilizatori *******************************************
******************************************* INCEPUT: caut_masina_gs *******************************************
Function caut_masina_gs
	Lparameters tlToateIreg, tlMaiMulteMasini
	Store "" To loCauta

	lcFiltru = [1=2]
	lcSchema = [id_masina n(20),nrinmat c(35),marca_masina c(24),model_masina c(20)]
	lcOrder = [nrinmat]
	lccoloane = [nrinmat,marca_masina,model_masina]
	lcTitlu = [Alegeti maºina]
	lcTitluColoane = [Nr.inmatriculare,Marca,Model]
	llMaiMulteMasini = tlMaiMulteMasini
	lcSelect = [select id_masina,nrinmat,marca_masina,model_masina from vnom_masini where 2=2]
	lcFiltruOriginal = [2=2]
	lcNumeProc = [nom_masini]
	llToateIreg = tlToateIreg
	lcPrimaColoana = [nrinmat]
	lnPornire = 1
	lnTipReturn = Iif(tlMaiMulteMasini, 1, 0)
	lcIdColumn = "id_masina"
	loCauta = cauta_alfa_gs(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)

	Return loCauta
Endfunc && caut_masina_gs
******************************************* SFARSIT: caut_masina_gs *******************************************

* primeste un hash cu parametri: cTitlu, cText, cTip, cEnums
* afiseaza un textbox/editbox/combobox initializat cu cText si intoarce textul modificat
* daca tipul este COMBO - trebuie si parametrul cEnums (sir separat prin virgula cu valorile de afisat in combo)
* lcText = GetText(GetHash("cTitlu=>titlul meu??cText=>text initial??cTip=>TEXT/COMBO/EDIT??cEnums=>DA,NU"))
Procedure GetText
	Parameters toHash

	Local lcText, lcTitlu, lcTip
	Private pcText

	lcTitlu = toHash.GetValue("cTitlu")
	pcText = toHash.GetValue("cText")
	lcTip = Upper(Alltrim(toHash.GetValue("cTip"))) && text/edit/combo
	lcEnums = toHash.GetValue("cEnums")

	If Empty(lcTitlu)
		lcTitlu = "Valoare"
	Endif
	If Empty(lcTip)
		lcTip = "TEXT"
	Endif
	lcText = pcText

	Do Case
		Case lcTip = 'TEXT'
			loText = Newobject("frm_textbox", "cautare.vcx")
			loText.ct_text.text_simplu1.ControlSource = "pcText"
			loText.ct_text.lb_simplu1.Caption = lcTitlu

		Case lcTip = 'COMBO'
			loText = Newobject("frm_combobox", "cautare.vcx")
			With loText.ct_text._cbbase1
				.ControlSource = "pcText"
				.RowSourceType = 1 && value
				.RowSource = lcEnums && sir valori
				.ColumnCount = 1 && sir valori
			Endwith
			loText.ct_text._lbbase1.Caption = lcTitlu

		Otherwise && EDIT
			loText = Newobject("frm_editbox", "cautare.vcx")
			loText.ct_text._edbase1.ControlSource = "pcText"
			loText.ct_text._lbbase1.Caption = lcTitlu

	Endcase

	loText.lb_titlu_alb_b121.Caption = lcTitlu

	loText.Show(1)
	If gnButon = 1
		lcText = pcText
	Endif

	Return lcText
Endproc && GetText

******************************************* INCEPUT:caut_politici_preturi *******************************************
Function caut_politici_preturi
	Local lcCont, loCauta

	Store "" To loCauta

	*!* 06.07.2011
*!*		lcSelect = [select NUME_LISTA_PRETURI,DATAI,DATAS,ID_POL FROM vcrm_politici_preturi ]
	lcSelect = [select nume_lista_preturi, datai, datas, id_pol from crm_vpolpretcurutil]
	*!* 06.07.2011 ^	
	lcFiltru = [1=2]
	lcSchema = [NUME_LISTA_PRETURI C(100),DATAI D,DATAS D,ID_POL N(10)]
	lcOrder = [nume_lista_preturi]
	lccoloane = [NUME_LISTA_PRETURI,DATAI,DATAS,ID_POL]
	lcTitlu = [Alegeti lista de pre_uri]
	lcTitluColoane = [LISTA PRETURI,DATA INCEPUT,DATA SFARSIT,ID]
	*!* 06.07.2011
*!*		lcFiltruOriginal = [inactiv = 0]
	lcFiltruOriginal = [id_util = ?gnIdUtil] + m.gcCondSucursala
	*!* 06.07.2011 ^	
	lcNumeProc = []
	llToateIreg = .F.

	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal)		&& 11.07.2007

	Return loCauta
	******************************************* SFARSIT:caut_politici_preturi *******************************************
	******************************************* INCEPUT:caut_imprimanta *******************************************
Function caut_imprimanta
	Local loCauta
	Store [] To loCauta

	Create Cursor crsprinters (imprimanta C(100), port C(20))
	Aprinters(laPrinters)
	Insert Into crsprinters From Array laPrinters
	lcSelect = [select imprimanta,port from crsprinters]
	lcFiltru = [1=2]
	lcSchema = [imprimanta c(100),port c(20)]
	lcOrder = [imprimanta]
	lccoloane = [imprimanta,port]
	lcTitlu = [Alegeti imprimanta]
	lcTitluColoane = [Imprimanta,Port de conectare]
	lcFiltruOriginal = []
	lcNumeProc = []
	llToateIreg = .F.

	loCauta = cauta_alfa_vfp(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal)		&& 11.07.2007

	Release laPrinters
	Return loCauta
Endproc	&&caut_imprimanta
******************************************* SFARSIT:caut_imprimanta *******************************************
************************************** INCEPUT:caut_politici_curente_util *************************************
Procedure caut_politici_curente_util
	Local loCauta, llReturn
	Store "" To loCauta
	Store .F. To llReturn
	lcSelect = [select id_pol,nume,datai,datas from crm_vpolpretcurutil]
	lcFiltru = [1=2]
	lcSchema = [id_pol n(5), nume c(100), datai d,datas d]
	lcOrder = [2]
	lccoloane = [nume,datai,datas]
	lcTitlu = [Alegeti politica de pre_uri]
	lcTitluColoane = [Nume,Data inceput,Data sfarsit]
	lcNumeProc = []
	llToateIreg = .F.
	lcFiltruOriginal = [id_util = ?gnIdUtil]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal)		&& 11.07.2007
	Return loCauta
Endproc &&	caut_politici_curente_util
************************************** SFARSIT: caut_politici_curente_util **************************************
***************************************** INCEPUT:caut_explicatie_tva *******************************************
Function caut_explicatie_tva
	Parameters tnIdJtva, tnPornire, tlDesktop, tlTipEx
	*!*	tlTipEx	=	0	-	toate
	*!*			=	1	-	doar TVA exigibil din JC
	*!*			=	2	-	doar TVA neexigibil din JC
	*!*			=	3	-	doar TVA exigibil din JV
	*!*			=	4	-	doar TVA neexigibil din JV
	*!*			=	5	-	doar TVA exigibil ( JC + JV )
	*!*			=	6	-	doar TVA neexigibil ( JC + JV )

	Local  lcCont, loCauta, lnPornire, llDesktop
	lnPornire = tnPornire && 1-incepe cu...6-toate
	llDesktop = tlDesktop
	lnIdJtva = Iif(Empty(tnIdJtva), -1, tnIdJtva)

	Store "" To loCauta

	lcSelect = [select id_jtva_coloana, denumire, cota_tva FROM vjtva_coloane]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [denumire]
	lccoloane = [denumire,cota_tva]
	lcTitlu = [Alegeti explica_ia TVA]
	lcTitluColoane = [Explicatie TVA,Cota TVA]
	*!*	modificare	ROACONT v 2.4.4
	do case
		case empty(tlTipEx)
			lcFiltruOriginal = [id_jtva_coloana > 0]
		case tlTipEx = 1
			lcFiltruOriginal = [id_jtva_coloana in (select id_tva from vjtva_coloane where ] + ;
				[jc = 1 and id_jtva_neex is not null)]
		case tlTipEx = 2
			lcFiltruOriginal = [id_jtva_coloana in (select id_tva from vjtva_coloane where ] + ;
				[jc = 1 and id_jtva_ex is not null)]
		case tlTipEx = 3
			lcFiltruOriginal = [id_jtva_coloana in (select id_tva from vjtva_coloane where ] + ;
				[jv = 1 and id_jtva_neex is not null)]
		case tlTipEx = 4
			lcFiltruOriginal = [id_jtva_coloana in (select id_tva from vjtva_coloane where ] + ;
				[jv = 1 and id_jtva_ex is not null)]
		case tlTipEx = 5
			lcFiltruOriginal = [id_jtva_coloana in (select id_tva from vjtva_coloane where ] + ;
				[id_jtva_neex is not null)]
		Otherwise
			lcFiltruOriginal = [id_jtva_coloana in (select id_tva from vjtva_coloane where ] + ;
				[id_jtva_ex is not null)]
	Endcase
*!*		*!*	If tnIdJtva > 0
*!*		*!*		lcFiltruOriginal = [jc * 4 + jv * 2 + decode(afisat,0,0,1) in ] + ;
*!*		*!*			[(select jc * 4 + jv * 2 + decode(afisat,0,0,1) from ] + gcS + [.vjtva_coloane ] + ;
*!*		*!*			[where id_jtva_coloana = ] + Alltrim(Str(lnIdJtva)) + [) and id_jtva_coloana > 0]
*!*		*!*	ELSE
*!*		lcFiltruOriginal = [id_jtva_coloana > 0]
*!*		*!*	Endif
	*!*	modificare	ROACONT v 2.4.4	^
	lcNumeProc = []
	llToateIreg = .F.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, , lnPornire, , , llDesktop)		&& 11.07.2007

	Return loCauta
Endfunc && caut_explicatie_tva
***************************************** SFARSIT: caut_explicatie_tva *******************************************

* PROCEDURE caut_formatie
* Date : 26.03.2007
* author : paula.mutu
******************************************* INCEPUT: caut_formatie *******************************************
Procedure caut_formatie
	Lparameters tlToateIreg, tlNou, tlTranse
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg
	lcSelect = [select * from sal_vnom_formatii]
	lcFiltruInitial = [inactiv = 0]
	lcFiltru = [1=1]
	lcSchema = []
	lcOrder = [denumire]
	lcColoane = [denumire,sectie] + IIF(tlTranse, [,transa], [])
	lcTitlu = [Alegeti forma_ia]
	If tlNou
		lcNumeProc = [sal_nom_formatii] && [nom_formatie]
	Else
		lcNumeProc = []
	Endif
	lcTitluColoane = [Formatie,Sectia] + IIF(tlTranse, [,Transa], [])
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruInitial)		&& 11.07.2007
	Return Iif(gnButon = 2, Null, loCauta)
Endproc && caut_formatie
***************************************** SFARSIT: caut_formatie *******************************************
******************************************* INCEPUT: caut_gestiune_dest *******************************************
Function caut_gestiune_dest
	Lparameters tnIdGestiune, tcTip, tnTip
	*!*	tnIdGestiune 	-	daca e diferit de zero atunci exclude din rezultate gestiunea cu id-ul respectiv
	*!*	tcTip			-	lista cu tipurile de gestiuni
	*!*	tnTip			-	daca e 1 atunci arata doar gestiunile, fara conturi si analitice
	Local lcTip, lnTip
	Store "" To loCauta, lcTip
	If Empty(tcTip)
		lcTip = [2,4,5,6,7]
	Else
		lcTip = tcTip
	Endif
	If Empty(tnTip)
		lnTip = 0
	Else
		lnTip = tnTip
	Endif
	pcFiltruOriginal = [a.id_util=?gnIdUtil and a.sters=0 and b.sters=0 and c.sters=0 and c.nr_pag in (] + Alltrim(lcTip) + [)]
	If !Empty(Nvl(tnIdGestiune, 0))
		pcFiltruOriginal = pcFiltruOriginal + [ and b.id_gestiune!=] + Alltrim(Str(tnIdGestiune))
	Endif

	If lnTip = 1
		pcselect = [select distinct c.nume_gestiune,c.cgest,b.id_gestiune ] + ;
			[from gest_coresp_util_grupe a ] + ;
			[left join gest_coresp_grupe_gestiuni b on a.id_grupe=b.id_grupe ] + ;
			[left join nom_gestiuni c on b.id_gestiune=c.id_gestiune ]
		pcorder = [nume_gestiune]
		pccoloane = [nume_gestiune,cgest]
		pcTitlu = [Alegeti gestiunea destina_ie]
		pcTitluColoane = [Gestiune,Cgest]
	Else
		pcselect = [select distinct c.nume_gestiune,c.cgest,b.id_gestiune,d.id_tipgest,] + ;
			[NVL(c.cont, d.cont) as cont,NVL(c.acont, p.acont) as acont ] + ;
			[from gest_coresp_util_grupe a ] + ;
			[left join gest_coresp_grupe_gestiuni b on a.id_grupe=b.id_grupe ] + ;
			[left join nom_gestiuni c on b.id_gestiune=c.id_gestiune ] + ;
			[left join coresp_cont_tipgest d on c.nr_pag=d.id_tipgest ] + ;
			[left join vplcont_analitic p on NVL(c.cont, d.cont) = p.cont and p.an = ?gnAn and p.inactiv = 0 ] + ;
			[left join vplcont_sintetic s on NVL(c.cont, d.cont) = s.cont and s.an = ?gnAn and s.inactiv = 0 ]
		*!*	modificare	ROAFACTURARE	v 2.0.19	^
		pcorder = [nume_gestiune,cgest,cont,acont]
		pccoloane = [nume_gestiune,cgest,cont,acont]
		pcTitlu = [Alegeti gestiunea ºi contul de transfer]
		pcTitluColoane = [Gestiune,Cgest,Cont,Analitic]
*!*			pcFiltruOriginal = pcFiltruOriginal + [ and s.an=?gnAn and s.inactiv = 0 and NVL(p.an,?gnAn)=?gnAn and NVL(p.inactiv,0) = 0]	&&	modificare v 2.2.25
	Endif
	pcfiltru = [1=2]
	pcschema = []
	lcNumeProc = []
	llToateIreg = .F.
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, lcNumeProc, llToateIreg, pcFiltruOriginal)		&& 11.07.2007

	Return loCauta
Endfunc
******************************************* SFARSIT: caut_gestiune_dest *******************************************
******************************************* INCEPUT:caut_mediu_transmisie *******************************************
Function caut_mediu_transmisie
	Parameters llToateIreg, tlNou
	Local  lcCont, loCauta

	Store "" To loCauta

	lcSelect = [select id_mediu, mediu_transmisie FROM vnom_medii_transmisie]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [mediu_transmisie]
	lccoloane = [mediu_transmisie]
	lcTitlu = [Alegeti mediul de transmisie]
	lcTitluColoane = [Mediu transmisie]
	lcFiltruOriginal = []
	If tlNou
		lcNumeProc = [nom_medii_transmisie]
	Else
		lcNumeProc = []
	Endif

	llToateIreg = .F.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal)		&& 11.07.2007

	Return loCauta
	******************************************* SFARSIT: caut_mediu_transmisie *******************************************
	******************************************* INCEPUT:caut_contract *******************************************
Function caut_contract
	Lparameters tnIdTipCtr, tnIdPart, tlToate
	*!*	0	-	toate
	*!*	-1	-	clienti
	*!*	-2	-	furnizori
	Local loCauta, lcFiltru
	lcFiltru = []
	Store "" To loCauta
	If !Empty(tnIdPart)
		lcFiltru = [ and id_part = ] + Alltrim(Str(tnIdPart))
	Endif
	If !Empty(tnIdTipCtr)
		lcFiltru = lcFiltru + [ and id_tip_ctr = ] + Alltrim(Str(tnIdTipCtr))
	Endif
	If tlToate
		pcselect = [select id_ctr,id_part,denumire,data,numar_aa,numar,data_inceput,data_sfarsit,id_responsabil,observatii,] + ;
			[responsabil,contract,descriere from ] + gcS + [.vcontracte_toate ]
		pcorder = [data,numar_aa]
		pccoloane = [numar_aa,data,denumire,data_inceput,data_sfarsit,responsabil]
	Else
		pcselect = [select id_ctr,id_part,denumire,data,numar,data_inceput,data_sfarsit,id_responsabil,observatii,] + ;
			[responsabil,contract,descriere from ] + gcS + [.vcontracte ]
		pcorder = [data,numar]
		pccoloane = [numar,data,denumire,data_inceput,data_sfarsit,responsabil]
	Endif
	pcfiltru = [1=2]
	pcschema = ['']
	pcTitlu = [Alegeti contractul]
	pcTitluColoane = [Numar,Data,Denumire,Data inceput,Data sfarsit,Responsabil]
	pcFiltruOriginal = Substr(lcFiltru, 5)
	lcNumeProc = [contracte]
	llToateIreg = .F.
	loCauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, lcNumeProc, llToateIreg, pcFiltruOriginal)

	Return loCauta
	******************************************* SFARSIT: caut_contract *******************************************
	******************************************* INCEPUT: caut_raport *******************************************
Procedure caut_raport
	Lparameters tnIdFormular, tlDrepturi
	Local loCauta, lcSelect
	loCauta = NULL

	IF m.tlDrepturi
		lcSelect = [select r.id_raport,Substr(denumire,1,254) as denumire,titlu, dataora, utilizator from vrapoarte r join rapoarte_utilizatori ru on r.id_raport = ru.id_raport]
	ELSE
		lcSelect = [select r.id_raport,Substr(denumire,1,254) as denumire,titlu, dataora, utilizator from vrapoarte r]
	ENDIF

	loHash = GetHash()
	loHash.SetValue("cSelect", lcSelect)
	loHash.SetValue("cFiltru", [1=2])
	loHash.SetValue("cSchema", [id_raport n(10),denumire c(254),titlu c(150),dataora t,utilizator c(100)])
	loHash.SetValue("cOrder", [denumire])
	loHash.SetValue("cColoana", [denumire,titlu,utilizator,dataora])
	loHash.SetValue("cTitlu", [Alegeti raportul])
	loHash.SetValue("cTitluColoana", [Denumire,Titlu,Utilizator,Dataora])
	loHash.SetValue("lToateIreg", .F.)
	loHash.SetValue("cFiltruOriginal", [r.id_formular_raport = ] + Alltrim(Str(m.tnIdFormular)) + IIF(m.tlDrepturi, [ and ru.id_utilizator = ] + ALLTRIM(STR(m.gnIdUtil)), []))
	loHash.SetValue("cIdColumn", "id_raport")
	loHash.SetValue('lModParam', .T.)

	loCauta = cauta_alfa_hash(loHash)
	Return loCauta
Endproc	&&	caut_raport
******************************************* SFARSIT: caut_raport *******************************************
************************************************************************************************************
Procedure caut_sectie_util
	Lparameters tnIdUtil, tnIdSucursala
	Local loCauta, lcFiltru
	Store "" To loCauta
	If Empty(tnIdSucursala)
		lcFiltruOriginal = [ and id_sectie in (select a1.id_sectie from asociere_parteneri_sectii a1 ] + ;
			[left join nom_sectii a2 on a1.id_sectie = a2.id_sectie ] + ;
			[where a1.id_tip = 2 and a2.sters = 0 and a1.id_part in ] + ;
			[(select id_partener from vutilizatori_rol_intern where id_util = ] + Alltrim(Str(tnIdUtil)) + [))]
	Else
		lcFiltruOriginal = [ and id_sectie in (select a1.id_sectie from asociere_parteneri_sectii a1 ] + ;
			[left join nom_sectii a2 on a1.id_sectie = a2.id_sectie ] + ;
			[where a1.id_tip = 2 and a2.sters = 0 and a1.id_part in ] + ;
			[(select id_partener from vutilizatori_rol_intern where id_util = ] + Alltrim(Str(tnIdUtil)) + [) ] + ;
			[and a2.id_sucursala = ] + Alltrim(Str(tnIdSucursala)) + [)]
	Endif
	lcFiltruOriginal  = [inactiv = 0] + lcFiltruOriginal
	lcSelect = [select id_sectie, sectie, csectie from ] + gcS + [.vnom_sectii ]
	lcOrder = [sectie]
	lccoloane = [sectie,csectie]
	lcFiltru = [1=2]
	lcSchema = ['id_sectie n(10),sectie c(254),csectie c(50)']
	lcTitlu = [Alegeti sec_ia]
	lcTitluColoane = [Sectie, Indicativ]
	llToateIreg = .T.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, [], llToateIreg, lcFiltruOriginal)
	Return loCauta
Endproc
************************************************************************************************************
Procedure caut_lucrare_sectie
	Lparameters tnIdUtil, tnIdSectie, tnIdSucursala
	Local loCauta, lcFiltru
	Store "" To loCauta
	If !Empty(tnIdSectie)
		lcFiltruOriginal  = [ and id_sectie = ] + Alltrim(Str(tnIdSectie))
	Else
		If Empty(tnIdSucursala)
			lcFiltruOriginal = [ and id_sectie in (select a1.id_sectie from asociere_parteneri_sectii a1 ] + ;
				[left join nom_sectii a2 on a1.id_sectie = a2.id_sectie ] + ;
				[where a1.id_tip = 2 and a2.sters = 0 and a1.id_part in ] + ;
				[(select id_partener from vutilizatori_rol_intern where id_util = ] + Alltrim(Str(tnIdUtil)) + [))]
		Else
			lcFiltruOriginal = [ and id_sectie in (select a1.id_sectie from asociere_parteneri_sectii a1 ] + ;
				[left join nom_sectii a2 on a1.id_sectie = a2.id_sectie ] + ;
				[where a1.id_tip = 2 and a2.sters = 0 and a1.id_part in ] + ;
				[(select id_partener from vutilizatori_rol_intern where id_util = ] + Alltrim(Str(tnIdUtil)) + [) ] + ;
				[and a2.id_sucursala = ] + Alltrim(Str(tnIdSucursala)) + [)]
		Endif
	Endif
	lcFiltruOriginal = [inactiv = 0] + lcFiltruOriginal
	lcSelect = [select id_lucrare,nrord from ] + gcS + [.vlucrari_sectii ]
	lcOrder = [nrord]
	lccoloane = [nrord]
	lcFiltru = [1=2]
	lcSchema = ['id_lucrare n(10),nrord c(200)']
	lcTitlu = [Alegeti lucrarea]
	lcTitluColoane = [Lucrare]
	llToateIreg = .T.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, [], llToateIreg, lcFiltruOriginal)
	Return loCauta
Endproc
************************************************************************************************************
Procedure caut_sucursala_sectii
	Lparameters tnIdUtil
	Local loCauta, lcFiltru
	Store "" To loCauta
	lcFiltruOriginal = [inactiv = 0 and id_sucursala in (select id_sucursala from nom_sectii where id_sectie in (] + ;
		[select id_sectie from asociere_parteneri_sectii where id_tip = 2 and id_part in ] + ;
		[(select id_partener from vutilizatori_rol_intern where id_util = ] + Alltrim(Str(tnIdUtil)) + [)) and sters = 0)]
	lcSelect = [select id_sucursala,sucursala from ] + gcS + [.vnom_sucursale ]
	lcOrder = [sucursala]
	lccoloane = [sucursala]
	lcFiltru = [1=2]
	lcSchema = ['id_sucursala n(10),sucursala c(200)']
	lcTitlu = [Alegeti sucursala]
	lcTitluColoane = [Sucursale]
	llToateIreg = .T.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, [], llToateIreg, lcFiltruOriginal)
	Return loCauta
Endproc
************************************************************************************************************
*!* 11.11.2009
Procedure caut_tipuri_imobilizare
	Local loHash, loCauta
	loHash = GetHash()
	With loHash
		.SetValue("cSelect", [select id_tip_imobilizare, denumire from imob_tipuri_imobilizare])
		*!*		.SetValue("cFiltru", "sters = 0 and inactiv = 0")
		.SetValue("cOrder", "id_tip_imobilizare")
		.SetValue("cColoana", "denumire, id_tip_imobilizare")
		.SetValue("cTitlu", "Tipuri imobilizari")
		.SetValue("cTitluColoana", "Denumire,Id")
		.SetValue("cFiltruOriginal", "sters = 0 and inactiv = 0")

		.SetValue("cPrimaColoana", "denumire")
		*!*		.SetValue("cNumeProc", lcNumeProcedura)
		.SetValue("nPornire", 6) && TOATE

	Endwith

	loCauta = cauta_alfa_hash(loHash)
	Return loCauta
Endproc && caut_tipuri_imobilizare
*!* 11.11.2009 ^
************************************************************************************************************
Function caut_cass
	Lparameters tlNou
	Local loHash, loCauta
	loHash = GetHash()
	With loHash
		.SetValue("cSelect", [select numecasa,judet,id_caseasig,indicativ from sal_vcaseasig])
		.SetValue("cOrder", "numecasa,judet")
		.SetValue("cColoana", "numecasa,judet")
		.SetValue("cTitlu", "Alegeti casa de sanatate")
		.SetValue("cTitluColoana", "Casa asigurari,Judet")
		.SetValue("cFiltruOriginal", "2=2")
		If tlNou
			.SetValue("cNumeProc", "sal_caseasig")
		Endif
	Endwith
	loCauta = cauta_alfa_hash(loHash)
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
************************************************************************************************************
Function caut_salariat
	Local lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select nume,prenume,marca,id_stat,id_salariat from sal_vnom_pers ]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [nume,prenume]
	lcColoane = [nume,prenume,marca,id_stat,id_salariat]
	lcTitlu = [Angaja_i]
	lcTitluColoane = [Nume,Prenume,Marca]
	locauta = cauta_alfa(lcselect, lcfiltru, lcschema, lcorder, lccoloane, lcTitlu, lcTitluColoane,,,,[nume,prenume,marca])
*!*		
*!*								tcselect,tcfiltru,tcschema,tcorder,tccoloana,tcTitlu,tcTitluColoana, ;
*!*			tcNume_Proc,tl_AllInList,tcFiltruOriginal,tcPrimaColoana,
		
		
	Return IIF(gnbuton = 2, Null, locauta)
Endfunc
************************************************************************************************************
Function caut_salariat_spec
	Lparameters tnTip, tlToti
	Local lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	If tlToti
		lcSelect = [select distinct id_part,nume,prenume,codpers from spec_vvenituri_tot]
	Else
		lcSelect = [select id_venit,codpers,nume,prenume,judet,sector,localitate,] + ;
			[strada,numar,bloc,scara,etaj,apart,codpostal,id_colaborator,id_part from spec_vvenituri]
	Endif
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [nume,prenume]
	lcColoane = [nume,prenume,codpers]
	lcTitluColoane = [Nume,Prenume,CNP]
	If tnTip = 0
		lcTitlu = [Alegeti persoana]
		locauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane)
		Return Iif(gnbuton = 2, Null, locauta)
	Else
		lcTitlu = [Alegeti persoanele (mouse-click pe nume sau apasati SPACE)]
		lnTipReturn = 1 && XML
		lcPrimaColoana = "nume"
		lcIdColumn = "id_venit"
		lnPornire = 1
		lcXMLParteneri = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, [], .F., [2=2], lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)
		Return lcXMLParteneri
	Endif
Endfunc
************************************************************************************************************
FUNCTION caut_tip_cm
	Local lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcFiltruOriginal
	lcSelect = [select * from ] + gcS + [.sal_vnom_cm]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [ordine,cod_cm,conc_med]
	lcColoane = [cod_cm,conc_med]
	lcTitlu = [Cod CM,Concediu]
	lcTitluColoane = [Cod CM,Concediu]
	lcFiltruOriginal = [sters = 0 ]
	locauta = cauta_alfa(lcselect, lcfiltru, lcschema, lcorder, lccoloane, lcTitlu, lcTitluColoane, [], .F., lcFiltruOriginal )&&30iul2007
	Return IIF(gnbuton = 2, Null, locauta)
Endfunc
************************************************************************************************************
FUNCTION caut_loc_prescriere
	Local lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcFiltruOriginal
	lcSelect = [select * from sal_loc_prescriere]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [cod_pres]
	lcColoane = [locPrescriere]
	lcTitlu = [Loc Prescriere]
	lcTitluColoane = [Loc Prescriere]
	lcFiltruOriginal = [sters = 0 ]
	locauta = cauta_alfa(lcselect, lcfiltru, lcschema, lcorder, lccoloane, lcTitlu, lcTitluColoane, [], .F., lcFiltruOriginal )&&30iul2007
	Return IIF(gnbuton = 2, Null, locauta)
endfunc
************************************************************************************************************
FUNCTION caut_tip_spor
	Local lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcFiltruOriginal
	lcSelect = [select id_tip_spor,nume_tip_spor,cod_categorie from syn_sal_nom_tip_spor]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [cod_categorie desc,id_tip_spor]
	lcColoane = [nume_tip_spor]
	lcTitlu = [Tip sporuri]
	lcTitluColoane = [Tip spor]
	lcFiltruOriginal = [NVL(data_inactiv,to_date('20991231','YYYYMMDD')) > to_date('] + ALLTRIM(STR(gnAn)) + ALLTRIM(STR(gnLuna)) + [','YYYYMM')]
	locauta = cauta_alfa(lcselect, lcfiltru, lcschema, lcorder, lccoloane, lcTitlu, lcTitluColoane, [], .F., lcFiltruOriginal )&&30iul2007
	Return IIF(gnbuton = 2, Null, locauta)
endfunc
***********************************************************************************************************
Function caut_tara
	Lparameters tnIdCetatenie
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from syn_nom_tari]
	lcFiltruInitial = [sters = 0]
	If !Empty(tnIdCetatenie)
		lcFiltruInitial = lcFiltruInitial + [ and id_cetatenie = ] + Alltrim(Str(tnIdCetatenie))
	Endif
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [tara]
	lcColoane = [tara,prescurtare]
	lcTitlu = [Na_ionalitate]
	lcTitluColoane = [Tara,Abreviere]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
***********************************************************************************************************
Function caut_judet
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from syn_vnom_judete]
	lcFiltruInitial = [inactiv=0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [judet,indicativ]
	lcColoane = [judet,indicativ]
	lcTitlu = [Jude_]
	lcTitluColoane = [Judet,Indicativ]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
***********************************************************************************************************
Function caut_localitate
	Lparameters tnIdJudet, tnIdTara
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from syn_vnom_localitati]
	lcFiltruInitial = Iif(!Empty(Nvl(tnIdJudet, 0)), [id_judet = ] + Alltrim(Str(tnIdJudet)), IIF(!EMPTY(NVL(tnIdTara, 0)), [id_tara = ] + ALLTRIM(STR(tnIdTara)), [2=2]))
	lcFiltru = [inactiv=0]
	lcSchema = []
	lcOrder = [localitate]
	lcColoane = [localitate,siruta,judet,tara]
	lcTitlu = [Localita_i]
	lcTitluColoane = [Localitate,Siruta,Judet,Tara]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, [nom_localitati], , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
***********************************************************************************************************
Function caut_tipautorizatie
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select id_tipautorizatie,denumire from syn_sal_nom_tipautorizatie]
	lcFiltruInitial = [sters=0 and inactiv = 0]
	lcFiltru = [2=2]
	lcSchema = [id_tipautorizatie n(10),denumire c(250)]
	lcOrder = [denumire]
	lcColoane = [denumire]
	lcTitlu = [Tipuri de autoriza_ie]
	lcTitluColoane = [Tip autorizatie]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
***********************************************************************************************************     
Function caut_cetatenie
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from syn_nom_cetatenii]
	lcFiltruInitial = [sters=0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [denumire]
	lcColoane = [denumire]
	lcTitlu = [Ceta_enie]
	lcTitluColoane = [Cetatenie]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
***********************************************************************************************************     
Function caut_tipact
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from ] + gcS + [.sal_nom_tip_acte]
	lcFiltruInitial = [sters=0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [denumire]
	lcColoane = [denumire]
	lcTitlu = [Tip act identitate]
	lcTitluColoane = [Act]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
***********************************************************************************************************     
Function caut_tipcontract
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from ] + gcS + [.sal_vnom_tipctr]
	lcFiltruInitial = [sters=0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [tip_contract]
	lcColoane = [tip_contract]
	lcTitlu = [Tip Contract]
	lcTitluColoane = [Tip Contract]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
***********************************************************************************************************  
Function caut_meserie
	LPARAMETERS tnTip
	*!*	1 = meseria ; 2 = profesia
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from ] + gcS + [.sal_nom_mes]
	lcFiltruInitial = [sters=0 and inactiv = 0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [meserie]
	If tnTip = 1
		lcColoane = [meserie,cod_meserie]
		lcTitlu = [Meserii]
		lcTitluColoane = [Meserie,Cod]
	Else
		lcColoane = [meserie]
		lcTitlu = [Profesii]
		lcTitluColoane = [Profesie]
	Endif
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, 'sal_nom_mes', , lcFiltruInitial,[meserie,cod_meserie])
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
***********************************************************************************************************  
FUNCTION caut_grupamunca 
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from ] + gcS + [.sal_coef_cas]
	lcFiltruInitial = [sters=0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [dengrupa]
	lcColoane = [dengrupa]
	lcTitlu = [Grupa de munca]
	lcTitluColoane = [Denumire]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
ENDFUNC
***********************************************************************************************************  
Function caut_clasasal
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from ] + gcS + [.sal_vnom_clasesal]
	lcFiltruInitial = [sters=0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [cod]
	lcColoane = [cod,tarifar]
	lcTitlu = [Clase salarizare]
	lcTitluColoane = [Cod,Tarifar]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
***********************************************************************************************************
Function caut_bancasal
	Lparameters tlNou
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc
	lcSelect = [select id_banca,denumire from ] + gcS + [.sal_nom_banci]
	lcFiltruInitial = [sters=0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [denumire]
	lcColoane = [denumire]
	lcTitlu = [Banca]
	lcTitluColoane = [Banca]
	If tlNou
		lcNumeProc = [sal_nom_banci]
	Else
		lcNumeProc = []
	Endif
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
*********************************************************************************************************** 
Function caut_contract_activ
	Lparameters tnIdTipCtr, tnIdPart, tdActivLaData
	*!*	0	-	toate
	*!*	-1	-	clienti
	*!*	-2	-	furnizori
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, lcPrimaColoana
	Store "" To loCauta
	lcSelect = [select id_ctr,id_part,denumire,data,numar,data_inceput,data_sfarsit,id_responsabil,observatii,] + ;
		[responsabil,contract,descriere from ] + gcS + [.vcontracte ]
	lcFiltru = [1=2]
	lcSchema = ['']
	lcOrder = [data,numar]
	lcColoane = [numar,data,denumire,data_inceput,data_sfarsit,responsabil]
	lcTitlu = [Alegeti contractul]
	lcTitluColoane = [Numar,Data,Denumire,Data inceput,Data sfarsit,Responsabil]
	lcFiltruInitial = []
	If !Empty(tnIdPart)
		lcFiltruInitial = [ and id_part = ] + Alltrim(Str(tnIdPart))
	Endif
	If !Empty(tdActivLaData)
		lcFiltruInitial = lcFiltruInitial + [ and NVL(data_sfarsit,to_date('] + DTOC(tdActivLaData, 1) + [','YYYYMMDD')) >= to_date('] + DTOC(tdActivLaData, 1) + [','YYYYMMDD')]
	Else
		lcFiltruInitial = lcFiltruInitial + [ and data_sfarsit is null]
	Endif
	lcFiltruInitial = [incetat = 0] + gcCondSucursala + lcFiltruInitial
	lcNumeProc = [contracte]
	lcPrimaColoana = [numar,denumire]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, , lcFiltruInitial, lcPrimaColoana)

	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
*********************************************************************************************************** 	
FUNCTION caut_sporuri
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from ] + gcS + [.sal_vnom_sporuri]
	lcFiltruInitial = [sters=0 and inactiv = 0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [nume_spor]
	lcColoane = [nume_spor,nume_tip_spor]
	lcTitlu = [Sporuri]
	lcTitluColoane = [Nume spor,Tip spor]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
ENDFUNC
*********************************************************************************************************** 	
Function caut_formatii_xml
	Lparameters tlToateIreg, tlNou
	Local loCauta, lcFiltruOriginal
	Local lcTitlu, lcFiltru, lcSchema, lcOrder, lcNumeProc, lcTitluColoane
	Store "" To loCauta
	lcSelect = [select * from sal_vnom_formatii]
	lcFiltru = [1=1]
	lcSchema = []
	lcOrder = [denumire]
	lccoloane = [denumire,sectie,semnatura,directie,transa,id_formatia]
	lcFiltruOriginal = [inactiv = 0]
	lcTitlu = [Alegeti forma_ia (mouse-click pe nume sau apasati SPACE)]
	If tlNou
		lcNumeProc = [sal_nom_formatii]
	Else
		lcNumeProc = []
	Endif
	lcTitluColoane = [Formatia,Sectie,Semnatura,Directie,Transa,Id_formatia]
	lnTipReturn = 1 && XML
	lcPrimaColoana = "denumire"
	lcIdColumn = "id_formatia"
	lnPornire = 1
	lcXMLFormatii = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)
	Return lcXMLFormatii
Endfunc && caut_formatii_xml
*********************************************************************************************************** 	
Procedure caut_transa
	Lparameters tlToateIreg, tlNou
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc
	lcSelect = [select * from sal_vnom_transe]
	lcFiltruInitial = [inactiv = 0]
	lcFiltru = [1=1]
	lcSchema = []
	lcOrder = [transa]
	lcColoane = [transa]
	lcTitlu = [Alegeti tranºa]
	If tlNou
		lcNumeProc = [sal_nom_transe]
	Else
		lcNumeProc = []
	Endif
	lcTitluColoane = [Transa]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruInitial)		&& 11.07.2007
	Return Iif(gnButon = 2, Null, loCauta)
Endproc && caut_transa
*********************************************************************************************************** 	
Procedure caut_partener_adresa
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg
	lcSelect = [select id_part, nume, prenume, cod_fiscal, reg_comert, eliberatde, dataeliberat, judet, id_judet,] + ;
		[ localitate, id_loc, strada, numar, bloc, scara, etaj, apart, cont_banca, banca from vnom_parteneri]
	lcFiltruInitial = [inactiv = 0 and tip_persoana = 2]
	lcFiltru = [1=1]
	lcSchema = []
	lcOrder = [nume,prenume,cod_fiscal]
	lcColoane = [nume,prenume,cod_fiscal]
	lcTitlu = [Alegeti persoana]
	lcNumeProc = []
	lcTitluColoane = [Nume,Prenume,CNP]
	llToateIreg = .F.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
endproc
*********************************************************************************************************** 	
Procedure cauta_facturaTVAEx
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc
	lcCursor = [crsfacturiTvaEx]
	lcSql = [{call pack_contab.cauta_facturaTVAEx(?gnLuna,?gnAn)}]
	if goExecutor.oExecuta(lcSql, lcCursor)
		lcSelect = [select id_part,denumire,cod_fiscal,serie_act,nract,dataact,id_fact,tip from ] + lcCursor
		lcFiltru = [1=2]
		lcSchema = [id_part n(10),denumire c(100),cod_fiscal c(20),serie_act c(20),nract N(20),dataact d,id_fact n(20),tip c(30)]
		lcOrder = [denumire]
		lccoloane = [denumire,cod_fiscal,serie_act,nract,dataact,tip]
		lcTitlu = [Alegeti factura]
		lcTitluColoane = [Denumire,Cod fiscal,Serie,Nr.act,Data act,Tip]
		lcFiltruOriginal = []
		lcNumeProc = []
		llToateIreg = .F.
		loCauta = cauta_alfa_vfp(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal)
		Use In (lcCursor)
	else
		gnButon = 2
	Endif
	Return Iif(gnButon = 2, Null, loCauta)
endproc
*********************************************************************************************************** 	
Function cauta_tehnician_deviz
	Lparameters tlInactivi
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg
	lcSelect = [select id_mecanic,denumire as nume,sectie from devize_vtehnicieni]
	lcFiltruInitial = Iif(!Empty(tlInactivi), [2=2], [inactiv = 0])
	lcFiltru = [1=1]
	lcSchema = []
	lcOrder = [decode(id_mecanic,1,0,1),denumire]
	lcColoane = [nume,sectie]
	lcTitlu = [Alegeti tehnicianul]
	lcNumeProc = []
	lcTitluColoane = [Nume,Sectie]
	llToateIreg = .F.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
Endfunc
*********************************************************************************************************** 	


******************************************* INCEPUT: caut_adresa *******************************************
Function caut_adresa
	Lparameters tnIdPartener
	Local lcColoane, lcFiltru, lcFiltruInitial, lcNumeProc, lcOrder, lcSchema, lcSelect, lcTitlu
	Local lcTitluColoane, llToateIreg, loCauta
	loCauta = NULL
	PRIVATE pnIdPartener
	pnIdPartener = tnIdPartener


	lcSelect = [select id_adresa, id_part, denumire_adresa, adresa, principala from vadrese_parteneri]
	lcFiltruInitial = [id_part = ?pnIdPartener]
	lcFiltru = [2=2]
	lcSchema = [id_adresa n(20), id_part n(20), denumire_adresa c(100), adresa c(250), principala n(1)]
	lcOrder = [principala desc, denumire_adresa]
	lcColoane = [adresa, denumire_adresa, principala]
	lcTitlu = [Alegeti adresa]
	lcNumeProc = []
	lcTitluColoane = [Adresa,Denumire,Principala]
	llToateIreg = .F.
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)

Endfunc && caut_adresa
******************************************* SFARSIT: caut_adresa *******************************************
* PROCEDURE caut_formatie_sal_salspec
* Date : 06.04.2016
* author : liana.neagu
******************************************* INCEPUT: caut_formatie_sal_salspec *******************************************
Procedure caut_formatie_sal_salspec
	Lparameters tlToateIreg, tlNou, tlTranse
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg
	lcSelect = [select id_formatia,id_sectie,id_transa,denumire,sectie,transa,inactiv,1 as dinSalarii from sal_vnom_formatii ]+;
				[ union ]+;
				[ select id_formatia,id_sectie,0 as id_transa,formatia as denumire, sectie,'' as transa,inactiv, 0 as dinSalarii from spec_vnom_formatii]
	lcFiltruInitial = [inactiv = 0]
	lcFiltru = [1=1]
	lcSchema = []
	lcOrder = [denumire]
	lcColoane = [denumire,sectie] + IIF(tlTranse, [,transa], [])
	lcTitlu = [Alegeti forma_ia]
	If tlNou
		lcNumeProc = [sal_nom_formatii] && [nom_formatie]
	Else
		lcNumeProc = []
	Endif
	lcTitluColoane = [Formatie,Sectia] + IIF(tlTranse, [,Transa], [])
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruInitial)		&& 11.07.2007
	Return Iif(gnButon = 2, Null, loCauta)
Endproc && caut_formatie
***************************************** SFARSIT: caut_formatie *******************************************
Function caut_apatrid
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from syn_nom_tipapatrid]
	lcFiltruInitial = [sters=0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [id_tipapatrid]
	lcColoane = [denumire]
	lcTitlu = [Apatrid]
	lcTitluColoane = [Apatrid]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
ENDFUNC
***********************************************************************************************************     
FUNCTION caut_scutireimpozit
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select * from ] + gcS + [.SAL_NOM_SCUTIRIIMP]
	lcFiltruInitial = [sters=0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [tip_scutire]
	lcColoane = [scutireimpozit]
	lcTitlu = [Impozitare]
	lcTitluColoane = [Denumire]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
ENDFUNC

***********************************************************************************************************     
Function caut_client_contract_activ
	Lparameters tcCond, tnIdPart, tnIdCtr
	*** tnIdCtr: daca dau id_ctr direct (facturile de penalitati) selectez numai acest contractul indiferent de iscontract_valid()
	
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, lcPrimaColoana
	Local lcFiltruContract, lcFiltruPartener, lcFiltruContractActiv, lcFiltruConditie, lcAnLuna, lcSql, lcFiltruTipPart
	PRIVATE pnIdTip, pcSir_Id_tip_part
	pnIdTip = -1 && CLIENTI
	pcSir_Id_tip_part = ''
	
	loCauta = NULL
	lcFiltruContract = ''
	lcFiltruPartener = ''
	lcFiltruContractActiv = ''
	lcFiltruConditie = ''
	lcFiltruTipPart = ''
	
	If Type('tnIdCtr') = 'N' And !Empty(m.tnIdCtr)
		lcFiltruContract = [ and (c.id_ctr = ] + Alltrim(Str(m.tnIdCtr)) + [)]
	ENDIF 
	If Type('tnIdPart') = 'N' And !Empty(m.tnIdPart)
		lcFiltruPartener = [ and p.id_part = ] + Alltrim(Str(m.tnIdPart))
	Endif

	lcSql = [begin pack_def.get_conturi_tip_part(?pnIdTip, ?@pcSir_Id_tip_part); end;]
	llSucces = goExecutor.oExecuta(m.lcSql)

	If llSucces AND !Empty(NVL(m.pcSir_Id_tip_part,''))
		lcFiltruTipPart = [ and p.id_part in (select distinct id_part from coresp_tip_part where id_tip_part in (] + m.pcSir_Id_tip_part + [))]
	ENDIF
			
	lcAnLuna = Alltrim(Str(m.gnAn)) + Padl(m.gnLuna, 2, '0')
	lcFiltruContractActiv = [ and ] + Alltrim(Str(m.gnAn * 12 + m.gnLuna)) + [ between extract(year from data_inceput) * 12 + extract(month from data_inceput) and ] + ;
		[extract(year from nvl(data_sfarsit, to_date('] + m.lcAnLuna + [', 'yyyymm'))) * 12 + extract(month from nvl(data_sfarsit, to_date('] + m.lcAnLuna + [', 'yyyymm')))]

	lcFiltruConditie = Iif(!Empty(m.tcCond),  [ and (] + m.tcCond + [)], [])
	
	TEXT TO lcSelect TEXTMERGE NOSHOW 
select id_ctr, id_part, denumire, cod_fiscal, data, numar, data_inceput, data_sfarsit, nr_zile_scadenta, tip_curs from
(select CAST (null as Number(10)) as id_ctr, id_part, denumire, cod_fiscal, CAST(null as date) as data, CAST(null as Varchar2(100)) as numar, CAST(null as date) as data_inceput, CAST(null as date) as data_sfarsit, CAST(null as number(5)) as nr_zile_scadenta, CAST(null as number(1)) as  tip_curs from nom_parteneri p
	WHERE STERS = 0 AND INACTIV = 0 <<m.lcFiltruPartener>> <<m.lcFiltruTipPart>>
union
select c.id_ctr, c.id_part, p.denumire, p.cod_fiscal, c.data, c.numar, c.data_inceput, c.data_sfarsit, c.scadenta_incasare as nr_zile_scadenta, c.tip_curs from contracte c JOIN nom_parteneri p ON c.id_part = p.id_part
	where c.sters = 0 and c.inactiv = 0 and p.sters = 0 and p.inactiv = 0 <<m.gcCondSucursala>> <<m.lcFiltruPartener>> <<m.lcFiltruTipPart>> <<m.lcFiltruContract>> <<m.lcFiltruContractActiv>> <<m.lcFiltruConditie>>)
	ENDTEXT 
		
	lcFiltru = [1=2]
	lcSchema = [id_ctr I, id_part I, denumire C(100), cod_fiscal C(50), data D, numar C(100), data_inceput D,data_sfarsit D, nr_zile_scadenta N(10), tip_curs N(10)]
	lcOrder = [denumire, data_inceput]
	lcColoane = [denumire,cod_fiscal,numar,data,data_inceput,data_sfarsit, id_part, id_ctr]
	lcTitlu = [Alegeti contractul]
	lcTitluColoane = [Denumire,Cod fiscal,Contract,Data,Data inceput,Data sfarsit,IdPart,IdCtr]
	lcFiltruInitial = []

	lcNumeProc = []
	lcPrimaColoana = [denumire,numar]

	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, , lcFiltruInitial, lcPrimaColoana)

	Return loCauta
ENDFUNC
*********************************************************************************************************** 	
Function caut_meserii_xml
	Lparameters tlToateIreg, tlNou
	Local loCauta, lcFiltruOriginal
	Local lcTitlu, lcFiltru, lcSchema, lcOrder, lcNumeProc, lcTitluColoane
	Store "" To loCauta
	lcSelect = [select meserie,cod_meserie,id_meseria from sal_vnom_mes]
	lcFiltru = [1=1]
	lcSchema = []
	lcOrder = [meserie]
	lccoloane = [meserie,cod_meserie,id_meseria]
	lcFiltruOriginal = [inactiv = 0]
	lcTitlu = [Alegeti meseriile (mouse-click pe nume sau apasati SPACE)]
	If tlNou
		lcNumeProc = [nom_meserii]
	Else
		lcNumeProc = []
	Endif
	lcTitluColoane = [Meserie,Cod_meserie,Id_meseria]
	lnTipReturn = 1 && XML
	lcPrimaColoana = "meserie"
	lcIdColumn = "id_meseria"
	lnPornire = 1
	lcXMLFormatii = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)
	Return lcXMLFormatii
Endfunc && caut_formatii_xml
*********************************************************************************************************** 	
******************************************* INCEPUT: caut_formatie *******************************************
Procedure caut_locmunca
	Lparameters tlToateIreg, tlNou, tlTranse,tcLocate
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg,lcLocate
	lcSelect = [select * from sal_vnom_locmunca ]
	lcFiltruInitial = [inactiv = 0 and sters = 0]
	lcFiltru = [1=1]
	lcSchema = []
	lcOrder = [denumire]
	lcColoane = [denumire,sectie] + IIF(tlTranse, [,transa], [])
	lcTitlu = [Alegeti locul de munca]
	If tlNou
		lcNumeProc = [sal_nom_locmunca] && [nom_formatie]
	Else
		lcNumeProc = []
	ENDIF
	IF EMPTY(tcLocate)
		lcLocate = []
	ELSE 
		lcLocate = tcLocate
	ENDIF 
	lcTitluColoane = [Loc munca,Sectia] + IIF(tlTranse, [,Activitate], [])
*!*		loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruInitial)		&& 11.07.2007
	
	loCauta = cauta_alfa(lcSelect,lcFiltru,lcSchema,lcOrder,lcColoane,lcTitlu,lcTitluColoane,lcNumeProc,tlToateIreg,lcFiltruInitial,,,,,,,,,,,,,lcLocate) && 19 mai 2021
*!*		loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, 'sal_nom_mes', , lcFiltruInitial,[meserie,cod_meserie])
		
	Return Iif(gnButon = 2, Null, loCauta)
Endproc && caut_formatie
***************************************** SFARSIT: caut_formatie *******************************************

*********************************************************************************************************** 	
Function caut_locmunca_xml
	Lparameters tlToateIreg, tlNou
	Local loCauta, lcFiltruOriginal
	Local lcTitlu, lcFiltru, lcSchema, lcOrder, lcNumeProc, lcTitluColoane
	Store "" To loCauta
	lcSelect = [select * from sal_vnom_locmunca ]
	lcFiltru = [1=1]
	lcSchema = []
	lcOrder = [denumire]
	lccoloane = [denumire,sectie,semnatura,directie,transa,id_locmunca]
	lcFiltruOriginal = [inactiv = 0]
	lcTitlu = [Alegeti forma_ia (mouse-click pe nume sau apasati SPACE)]
	If tlNou
		lcNumeProc = [sal_nom_formatii]
	Else
		lcNumeProc = []
	Endif
	lcTitluColoane = [Loc Munca,Sectie,Semnatura,Directie,Activitate,Id_locmunca]
	lnTipReturn = 1 && XML
	lcPrimaColoana = "denumire"
	lcIdColumn = "id_locmunca"
	lnPornire = 1
	lcXMLFormatii = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, tlToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)
	Return lcXMLFormatii
Endfunc && caut_formatii_xml
*-------------------------------------
Function caut_tipsal
	Local lcSelect, lcFiltruInitial, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane
	lcSelect = [select id_tippontaj,(case when nume_tip = 'Z' and id_tippontaj = -100 then 'L' else 'O' end) as nume_tip, inactiv,sters from ] + gcS + [.sal_vnom_pont]
	lcFiltruInitial = [sters=0]
	lcFiltru = [2=2]
	lcSchema = []
	lcOrder = [nume_tip]
	lcColoane = [nume_tip]
	lcTitlu = [Tip Salariu]
	lcTitluColoane = [Tip Salariu]
	loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcColoane, lcTitlu, lcTitluColoane, , , lcFiltruInitial)
	Return Iif(gnButon = 2, Null, loCauta)
ENDFUNC

*------------------------------------------------------------
*  caut imobilizare si intorc obiect din imob_vsituatie_lunara
*------------------------------------------------------------
Function caut_imobilizare
	Lparameters tnTip
	* tnTip: 1 = corporale, 2 = necorporale, 3 = in curs

	PRIVATE pdDataI
	Local lcColoana, lcFiltru, lcFiltruOriginal, lcGroup, lcIdColumn, lcNume_Proc, lcOrder
	Local lcPrimaColoana, lcSchema, lcSelect, lcTitlu, lcTitluColoana, llAfisare, llAllInList
	Local llModParam, llSucces, lnPornire, lnTipReturn, loRec

	pdDataI = Date(gnAn, gnLuna, 1)
	llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')

	lcSelect = [SELECT * FROM imob_vsituatie_lunara]
	lcFiltru = [1=2]
	lcSchema = []
	lcOrder = [nr_inventar, denumire,data_pif]
	llAfisare = .F.
	lcGroup = []
	llModParam = .T.
	lcFiltruOriginal = [id_tip_imobilizare = ] + Alltrim(Str(m.tnTip)) + [ AND IESIT_DIN_GEST = 0 ] + m.gcCondSucursala

	lcColoana = "nr_inventar, denumire, data_pif"
	lcTitluColoana = "Numar inventar, Denumire, Data PIF"
	llAllInList = .F.
	lnPornire = 1 && INCEPE CU
	lcPrimaColoana = "nr_inventar"
	lcNume_Proc = ""
	lcTitlu = "Alegeti imobilizarea"
	lnTipReturn = 0 && object
	lcIdColumn = "id_mf"
	loRec = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lcCOloana, lcTitlu, lcTitluColoana, lcNume_Proc, llAllInList, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn, lcIdColumn)

	Return loRec
Endfunc && caut_imobilizare
******************************************* SFARSIT: caut_imobilizare ******************************************* 

FUNCTION GetImobilizareById
	Lparameters tnTip, tnIdMf, tlBlank, tcAlias
	* tnTip: 1 = corporale, 2 = necorporale, 3 = in curs
	* tnIdMf: imob_nom_mf.id_mf. Daca tlBlank = .T., nu este nevoie de tnIdMf
	* tlBlank: .T. = intoarce un obiect cu inregistrare goala tip imobilizare
	* tcAlias: completat = lasa deschis cursorul tcAlias cu imobilizarile, altfel il inchide

	PRIVATE pnIdMf, pdDataI
	Local lcSql, llSucces, loImob, lcAlias
	
	loImob = NULL
	lcAlias = IIF(!EMPTY(m.tcAlias), m.tcAlias, SYS(2015))
	pnIdMf = m.tnIdMf
	
	pdDataI = Date(gnAn, gnLuna, 1)
	llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
	IF m.llSucces 
		IF m.tnTip = 3 && in curs
			lcSql = [SELECT * FROM imob_vlista_curs where ] + IIF(m.tlBlank, [1=2], [id_mf=?pnIdMf])
		ELSE 
			lcSql = [SELECT * FROM imob_vsituatie_lunara where ] + IIF(m.tlBlank, [1=2], [id_mf=?pnIdMf])
		ENDIF 	
		llSucces = goExecutor.oExecuta(m.lcSql, m.lcAlias)
		IF m.llSucces
			SELECT (m.lcAlias)
			GO TOP 
			SCATTER NAME loImob MEMO 
		ENDIF 
		
		IF EMPTY(m.tcAlias)
			USE IN (SELECT(m.lcAlias))
		ENDIF 
			
	ENDIF 
	
	Return loImob
Endfunc && GetImobilizareById