*!* 19.02.2010
*!* marius.mutu lans_nir_bon - crsconfigcvc (coresp_cont_venchelt) 
*!* este nevoie de conturi corespondente si pentru operatiile 264,265 finalizare aprovizionare

*!* 19.04.2010
*!* marius.mutu
*!* vizualizeaza_inventar_magazin - creez cursor cote_tva

*!* 29.05.2010
*!* marius.mutu
*!* lans_nir_bon - id_set 266 - mf pret de achizitie *  > facturi nesosite pret de lista

*!* 07.09.2009
*!*	marius.mutu
*!*	vizualizeaza_inventar_magazin - use in actactan
	
*!* 31.01.2011
*!*	marius.mutu
*!* vizualizeaza_inventar
*!* completat select si schema (dadea eroare la adaugarea in crs_inventar NULL)
*!* #2876 

*!* 26.10.2011	
*!* lans_nir_bon id_set 247 ( NIR cu lista de preturi)
*!* daca dau renunt la transferul articolelor din nir in alta gestiune, se in actbaza2007.release se dezaloca numarul de NIR

*!* 21.12.2011
*!* marius.mutu
*!* vizualizeaza_inventar, vizualizeaza_inventar_magazin 
*!* parametru suplimentar inventar corectie

*!* 19.03.2014
*!* marius.mutu
*!* vizualizeaza_inventar - stoc_scriptic nu avea zecimale la selectia din baza de date #3953 

*!*	14.08.2014
*!*	marius.mutu
*!*	achizitie_import
*!*	s-a tratat factura TVA Incasare - se schimba 4426>4428, explicatia_tva

*!* 14.01.2015
*!* marius.mutu
*!* NU se executa avizul de transfer automat llAvizTransferAutomat daca optiunea RG_AVIZ_TRANSFER_NIR6/RG_AVIZ_TRANSFER_NIR7 este 0

*!*	04.01.2016
*!*	marius.mutu
*!* achizitiile si livrarile pe 2015 trebuie sa propuna TVA 24%. 
*!* In xsets s-a modificat 20% de la 01.01.2016

*!* 03.01.2017
*!* achizitie_import: In 2016 lucrez cu TVA 20%. Transform TVA din 19% in 20%	
*!* lans_nir_bon: achizitiile si livrarile pe 2016 trebuie sa propuna TVA 20%. In xsets s-a modificat 19% de la 01.01.2017

*!* 18.08.2017
*!* lans_Nir_Bon
*!* adaugare parametru tcNumeObje = 'corectie,1234' pentru modificarea NIR/BON

*!* 05.09.2017
*!* vizualizeaza_inventar_magazin - se transmit in clar gnAn, gnLuna, pnIdFact - nu mai folosea indexul si facea full scan pe act

*!* lans_Nir_Bon
*!* corectie NIR/Bon - stergere document original inainte de scrierea celui modificat

*!* 05.01.2018
*!* vizualizeaza_inventar + coloana dataora

*!* 15.05.2018
*!* marius.mutu
*!* lans_Nir_Bon - la modificare NIR/BON se sterge documentul original inainte de scrierea celui nou, doar daca s-a dat terminat la NIR/BON. Se stergea chiar daca se dadea renunt.

*!* 12.11.2019
*!* marius.mutu
*!* lans_nir_bon - se initializeaza poDate pentru oscrie_vanzare_din_stoc()


*!*	17.07.2025
*!*	marius.mutu
*!*	lans_Nir_Bon = cota TVA 19%-21% pentru perioada de tranzitie
*!* achizitiile si livrarile < 08/2025 trebuie sa propuna TVA 19%
*!* In xsets s-a modificat 21% de la 01.08.2025


*!*	28.07.2026
*!*	marius.mutu
*!*	achizitie_import - blocul de TVA din DVI poate avea valuta si curs proprii, diferite de ale
*!*	facturii (inclusiv fara valuta), iar factura poate avea discount financiar; cursorul introdc
*!*	primeste coloanele rand_dvi si valuta_proprie.


#Define CRLF Chr(13) + Chr(10)

********* INCEPUT: lans_Nir_Bon ***********
Procedure lans_Nir_Bon
	Parameters tnIdSet, tcObj, tcNumeObj
	Local llReturn,llGestin,llGestout, lnTip
	Local lcSelect, lcCursor,lnPornire	&&	modificare ROAPRODUCTIE v 2.0.0 : am adaugat lnPornire
	llReturn = .T.
	Store .F. To llGestin,llGestout

	Local lnNir
	Store 0 To lnNir

	llCorectie = (TYPE('tcNumeObj') = 'C' AND LOWER(LEFT(m.tcNumeObj, 8)) = 'corectie')
	lnCod = IIF(m.llCorectie, INT(VAL(GETWORDNUM(m.tcNumeObj,2, ','))), 0)

	*!* v 2.0.28
	*!* LA NIR BILETE RATC - CALCULUL, NOTELE CONTABILE, LISTAREA SE FAC:
	*!* VALOAREA CU TVA
	*!* VALOAREA TVA = VALOAREA CU TVA * (PROC_TVA - 1)/ PROC_TVA
	*!* VALOAREA FARA TVA = VALOAREA CU TVA - VALOAREA TVA
	Private plNIRBONPretCuTVA
	plNIRBONPretCuTVA = IsNIRBONPretCuTVA(tnIdSet) && NIR BILETE RATC
	*!* v 2.0.28 ^

	Select xsets
	Locate For id_set = tnIdSet
	Scatter Name oSet
	*!*	modificare JC/JV 2007
	If gnNeplatitoare_tva = 1
		oSet.id_jtax = oSet.id_jtaxn
		oSet.id_jnetax = oSet.id_jtaxn
	Endif
	*!*	modificare JC/JV 2007	^
	
	DO CASE 
		CASE BETWEEN(m.gnAn*12+m.gnLuna,2018*12+1, 2025*12+7)
			* achizitiile si livrarile inainte de 08/2025 trebuie sa propuna TVA 19%. 
			* In xsets s-a modificat 21% de la 01.08.2025
			DO case
				CASE INLIST(oset.id_jtax, 208)
					oset.id_jtax = 105 && ACH. INT. 19%
				CASE INLIST(oset.id_jtax, 216)
					oset.id_jtax = 141 && TX. INV. 19%
				CASE INLIST(oset.id_jtax, 220) 
					oset.id_jtax = 118 && ACH. IMP. 19%
				CASE oset.id_jtax = 35 
					oset.id_jtax = 1 && LIVR.INTERN 19%
			ENDCASE

		CASE BETWEEN(m.gnAn, 2016, 2017)
			* achizitiile si livrarile pe 2016 trebuie sa propuna TVA 20%. 
			* In xsets s-a modificat 19% de la 01.01.2017
			DO case
				CASE INLIST(oset.id_jtax, 101, 103, 105)
					oset.id_jtax = 176 && ACH. INT. 20%
				CASE INLIST(oset.id_jtax, 137, 139, 141)
					oset.id_jtax = 186 && TX. INV. 20%
				CASE INLIST(oset.id_jtax, 114, 116, 118) 
					oset.id_jtax = 180 && ACH. IMP. 20%
				CASE oset.id_jtax = 1 
					oset.id_jtax = 27 && LIVR.INTERN 20%
			ENDCASE
		CASE gnAn <= 2015
			* achizitiile si livrarile pe 2015 trebuie sa propuna TVA 24%. 
			* In xsets s-a modificat 20% de la 01.01.2016
			DO case
				CASE oset.id_jtax = 176
					oset.id_jtax = 156
				CASE oset.id_jtax = 186 
					oset.id_jtax = 162
				CASE oset.id_jtax = 180 
					oset.id_jtax = 158
				CASE oset.id_jtax = 27 
					oset.id_jtax = 15
			ENDCASE
	ENDCASE 
	

	*!* 30.10.2008 NIR DEPOZIT
	*!* NIR PE BAZA NIR DEPOZIT (CODURI DE BARE  + CANTITATE CITITE DE GESTIONAR)
	*!* CAUT NIR-UL DUPA NUMAR, DATA - DACA EXISTA - VERIFIC DACA EXISTA ARTICOLE NOI CARE TREBUIE ADAUGATE IN NOMENCLATOR
	If oSet.model = 2 && NIR
		Do COMPLETEAZA_ARTICOLE_DEP_NIR With poAct.nract, poAct.dataact In OINTRODUCERI.PRG
		If gnButon = 2 && DACA AM ALES RENUNT - NU MERG MAI DEPARTE
			Return gnButon
		Endif
	Endif
	*!* 30.10.2008 ^

	lFactura = oSet.factura
	lFacturaVal = oSet.cursval		&&	modificare	21.09.2007
	lAdaos = oSet.adaos
	lDiscount = oSet.discount
	lcTipFrm = Upper(oSet.explicatia)
	lcFormCereDate = Alltrim(oSet.frm_date)

	lcObj = Alltrim(tcObj)
	If !Inlist(Left(Alltrim(Upper(lcObj)),6), "WEBNIR","VALOAR","SCHIMB","INVENT","RESTNI")
		pcObj = &tcObj
	Endif
	If oSet.model = 4 And oSet.factura   && facturi retur
		If Used('xcont')
			Select xcont
			Locate For Val(contpart) = 4111
			lnIdPart = idPart
			lcTitlu = numepart
			lcCursor = 'crs_facturi_emise'

			pcListaFacturi = aleg_facturi_pt_retur(lnIdPart,'4111',lcTitlu,lcCursor)
			If Empty(pcListaFacturi)
				Return 2   && renunt
			Endif
		Endif
	Endif

	Select selectii
	Locate For id_sel = oSet.id_selSt
	If Found()
		Scatter Name ost Memo
	Else
		amessagebox('NECONFIGURAT!',0+48,'Atentie!')
		Return 2 && renunt
	Endif

	***---------------------
	*!* v 2.0.87 - gestselectii - coloane ordonate din optiuni utilizator
	llElementeEgale = .F.
	lcWidth_coloane = ''
	lnPornire = 1 && v 2.0.90
	lcGestSelectii = citeste_optiune_utilizator('GEST_SELECTII')
	If !Empty(lcGestSelectii)
		Xmltocursor(lcGestSelectii, "crsGestSelectiiUtilizator")

		Select crsGestSelectiiUtilizator
		Locate For id_sel = oSet.id_selSt
		If Found()
			**-- compara daca am aceleasi coloane (control source) pe server si in tabelul din proiect (gest_selectii)
			Create Cursor crsLista1 (element C(100))
			Create Cursor crsLista2 (element C(100))

			lista2cursor(crsGestSelectiiUtilizator.nume_col,"crsLista1","element",";")
			lista2cursor(ost.nume_col,"crsLista2","element",";")

			Select * From crsLista1 ;
				ORDER By element ;
				INTO Cursor crsListaOrd1

			Select * From crsLista2 ;
				ORDER By element ;
				INTO Cursor crsListaOrd2

			lcSirOrdonat1 = cursor2lista("crsListaOrd1","element",";")
			lcSirOrdonat2 = cursor2lista("crsListaOrd2","element",";")

			If Used('crsLista1')
				Use In crsLista1
			Endif
			If Used('crsLista2')
				Use In crsLista2
			Endif
			If Used('crsListaOrd1')
				Use In crsListaOrd1
			Endif
			If Used('crsListaOrd2')
				Use In crsListaOrd2
			Endif

			If lcSirOrdonat1 = lcSirOrdonat2
				llElementeEgale = .T.
			Endif
			**--
			If llElementeEgale
				Select crsGestSelectiiUtilizator
				Locate For id_sel = oSet.id_selSt

				ost.titlu_col = titlu_col
				ost.nume_col = nume_col
				ost.ordine = ordine
				lcWidth_coloane = width_col
				If Type("pornire")<>"U" && ver. 2.0.90
					lnPornire = pornire
				Endif
			Endif
		Endif
	Else
		Create Cursor crsGestSelectiiUtilizator (id_sel I, titlu_col M, nume_col M, ordine C(50), width_col M, pornire N(2))
	Endif

	*!* v 2.0.87 - gestselectii ^
	***---------------------
	Select selectii
	Locate For id_sel = oSet.id_selDr
	If Found()
		Scatter Name odr Memo
	Else
		amessagebox('NECONFIGURAT!',0+48,'Atentie!')
		Return 2 && renunt
	Endif

	lcFiltruOrig = Alltrim(ost.filtruOrig)
	If Empty(lcFiltruOrig)
		lcFiltruOrig = [2=2]
	Else
		lcFiltruOrig = &lcFiltruOrig
	Endif
	Local lcNrSt
	Store 0 To lcNrSt

	Do While ("??"$ost.titlu_grid)
		lcNrSt = lcNrSt + 1
		ost.titlu_grid = Stuff(ost.titlu_grid ,At("??",ost.titlu_grid ,1),At("??",ost.titlu_grid,2)-At("??",ost.titlu_grid ,1)+2,Alltrim(Evaluate(Substr(ost.titlu_grid ,At("??",ost.titlu_grid ,1)+2,At("??",ost.titlu_grid ,2)-At("??",ost.titlu_grid ,1)-2))))
	Enddo
	Release lcNrSt
*!*	modificare	v 2.1.19
*!*		lcSelSt = Alltrim(ost.cselect) + [ from ] + gcs + [.] + Alltrim(ost.cfrom) + [ where ] + Iif(!Empty(ost.FILTRU),Alltrim(ost.FILTRU),[])+Iif(!Empty(ost.CWHERE),Iif(!Empty(ost.FILTRU),[ AND ],[ ])+Alltrim(ost.CWHERE),[])
	* 3 = BON CONSUM
	IF oxset.model = 3 AND INLIST(gnFifoLifo,1,2)
		lcOrdineSelectie = IIF(gnFifoLifo=1,[],[ desc])
		lcSelSt = STRTRAN(Alltrim(ost.cselect),[select ],;
		[select row_number() over (partition by id_articol,id_gestiune order by denumire,id_articol,id_gestiune,datain] + lcOrdineSelectie + [) as nrordine,]) + ;
			[ from ] + gcs + [.] + Alltrim(ost.cfrom) + [ where ] + Iif(!Empty(ost.FILTRU),Alltrim(ost.FILTRU),[])+Iif(!Empty(ost.CWHERE),Iif(!Empty(ost.FILTRU),[ AND ],[ ])+Alltrim(ost.CWHERE),[])
*!*			ost.ordine = [denumire,id_articol,id_gestiune,datain]+lcOrdineSelectie
	else
		lcSelSt = Alltrim(ost.cselect) + [ from ] + gcs + [.] + Alltrim(ost.cfrom) + [ where ] + Iif(!Empty(ost.FILTRU),Alltrim(ost.FILTRU),[])+Iif(!Empty(ost.CWHERE),Iif(!Empty(ost.FILTRU),[ AND ],[ ])+Alltrim(ost.CWHERE),[])
	ENDIF
*!*	modificare	v 2.1.19	^	
	lcSchemaSt = Alltrim(ost.cschema)

	*AMESSAGEBOX('lcFiltruOrig: '+lcFiltruOrig)

	odr.filtruOrig = Iif(Empty(odr.filtruOrig), [2=2], Alltrim(odr.filtruOrig))
*!*	modificare	v 2.1.19
*!*		lcSelDr = Alltrim(odr.cselect) + [ from ] + gcs + [.] + Alltrim(odr.cfrom) + [ where ] + Alltrim(odr.FILTRU)
	IF oxset.model = 3 AND INLIST(gnFifoLifo,1,2)
		lcSelDr = Alltrim(odr.cselect) + [,0 as nrordine from ] + gcs + [.] + Alltrim(odr.cfrom) + [ where ] + Alltrim(odr.FILTRU)		
	ELSE
		lcSelDr = Alltrim(odr.cselect) + [ from ] + gcs + [.] + Alltrim(odr.cfrom) + [ where ] + Alltrim(odr.FILTRU)
	ENDIF
*!*	modificare	v 2.1.19	^
	lcSchemaDr = Alltrim(odr.cschema)

	*!*	modificare	v 2.0.6
	*!*	If Type('pcobj.id_gestout') # 'U' And !Empty(pcObj.id_gestout)
	If Type('pcobj.id_gestout') # 'U' And !Empty(pcObj.id_gestout) And !Inlist(oSet.id_set,215,216,257)
		*!*	modificare	v 2.0.6	^
		llGestout = .T.
	Endif

	If Type('pcobj.id_gestin') # 'U' And !Empty(pcObj.id_gestin)
		llGestin = .T.
	Endif
	If Inlist(oSet.id_selSt, 1, 22) && selectie din vnom_articole
		llAdMod = .T.
	Else
		llAdMod = .F.
	Endif

	If Inlist(Left(Alltrim(Upper(lcObj)),6), 'WEBNIR',"RESTNI")
		LcNumeObj = Alltrim(Upper(lcObj)) && 'WEBNIR'

		Private pnAdaosTotal
		Store 0 To pnAdaosTotal

		Private pnId_lista, pdDataI, pdDataF, pcDataI, pcDataF, pcPerioada, pcDataOra
		ltDataora = get_ora()
		ldDataora = Ttod(ltDataora)
		pnId_lista = 0
		pdDataI = DTOT(MIN(DATE(gnAn,gnLuna,1),ldDataora)) && DATE()-1
		pdDataF = Dtot(MIN(GOMONTH(DATE(gnAn,gnLuna,1),1)-1,ldDataora))+24*60*60-1 && DATE()-1
		pcDataI = ''
		pcDataF = ''
		pcPerioada = ""
		pcDataOra = get_ora(2)
		***--------- combo liste preturi
		Private pnId_lista, pnId_produs
		Store 0 To pnId_lista, pnId_produs

		Private poListe_pret
		Store '' To poListe_pret

		Local lcSchema1, lcSelect1, lcOrder1, lcFiltru1, llAfiseaza
		lcSchema1 = []
		lcSelect1 = [select * from vcrm_politici_preturi]
		lcOrder1 = [nume_lista_preturi]
		lcgroup = []
		lcFiltru1 = [2=2]
		lcFiltruOriginal = []
		llModParam = .T.
		llAfiseaza = .F.

		gencursor('poListe_pret','cListePret', lcSelect1, lcFiltru1, lcSchema1, lcOrder1, llAfiseaza,  lcgroup, llModParam, lcFiltruOriginal)
		poListe_pret.ca_baza1.afisare()

		Select cListePret
		***------------------
		Private pnIdGest_InProd, pnIdGest_InMarf
		Store 0 To pnIdGest_InProd, pnIdGest_InMarf

		Private poGestiuni
		Store '' To poGestiuni

		Local lcSchema1, lcSelect1, lcOrder1, lcFiltru1, llAfiseaza
		lcSchema1 = []
		lcSelect1 = [select id_gestiune, nume_gestiune, cgest, nr_pag, cont, acont, inactiv, nume_tip from vnom_gestiuni]
		lcOrder1 = [cgest]
		lcgroup = []
		lcFiltru1 = [2=2]
		If Empty(gcGestPermis)
			lcFiltruOriginal = [1=2]
		Else
			lcFiltruOriginal = [id_gestiune in (]+ gcGestPermis + [)]
		Endif
		llModParam = .T.
		llAfiseaza = .F.

		gencursor('poGestiuni','crsGestiuni', lcSelect1, lcFiltru1, lcSchema1, lcOrder1, llAfiseaza,  lcgroup, llModParam, lcFiltruOriginal)
		poGestiuni.ca_baza1.afisare()
		***------------------
	Else
		* IF oSet.id_set = 105 && NIR de marfa la pret de vanzare
		Private pnId_lista, pnId_produs
		Store 0 To pnId_lista, pnId_produs

		Private poListe_pret
		Store '' To poListe_pret

		Local lcSchema1, lcSelect1, lcOrder1, lcFiltru1, llAfiseaza
		lcSchema1 = []
		lcSelect1 = [select * from vcrm_politici_preturi]
		lcOrder1 = [nume_lista_preturi]
		lcgroup = []
		lcFiltru1 = [2=2]
		lcFiltruOriginal = []
		llModParam = .T.
		llAfiseaza = .F.

		gencursor('poListe_pret','cListePret', lcSelect1, lcFiltru1, lcSchema1, lcOrder1, llAfiseaza,  lcgroup, llModParam, lcFiltruOriginal)
		poListe_pret.ca_baza1.afisare()
		* ENDIF

		If !Inlist(Left(Alltrim(Upper(lcObj)),6), "WEBNIR","VALOAR","SCHIMB","INVENT","RESTNI")
			LcNumeObj = "nir"
		Else
			LcNumeObj = Alltrim(Upper(lcObj))
		Endif
	Endif

	
	*!*	modificare	04.10.2007
	*!* 19.02.2010
	*!*		If Inlist(oSet.model,3,4)
	*!* 19.02.2010 ^
		If update_corespondente_cvc() < 0
			Return
		Endif
	*!*		Endif
	*!*	modificare	04.10.2007	^
	

	*!*	modificare	21.02.2007
	If update_jtva_coloane([],[jtva_temp]) > 0
		*!*	modificare	ROAGEST v 2.2.0
*!*			Select * From jtva_temp Where JC = 1 Into Cursor jtva_achizitie
*!*			Select * From jtva_temp Where JV = 1 Into Cursor jtva_vanzare
		If type('pcObj') = 'O' and pemstatus(pcObj, "tva_incasare", 5) and Empty(pcObj.tva_incasare)
			Select * From jtva_temp Where JC = 1 And Isnull(id_jtva_ex) Into Cursor jtva_achizitie
			Select * From jtva_temp Where JV = 1 And Isnull(id_jtva_ex) Into Cursor jtva_vanzare
		Else
			Select * From jtva_temp Where JC = 1 And Isnull(id_jtva_neex) Into Cursor jtva_achizitie
			Select * From jtva_temp Where JV = 1 And Isnull(id_jtva_neex) Into Cursor jtva_vanzare
		Endif
		*!*	modificare	ROAGEST v 2.2.0	^
		If Used('jtva_temp')
			Use In jtva_temp
		Endif
	Else			&&	adaugare 04.10.2007
		Return		&&	adaugare 04.10.2007
	Endif
	*!*	modificare	21.02.2007	^

	If oSet.productie And !Empty(oSet.formproduc)
		*!* modificare ROAPRODUCTIE v 2.0.2 : am adaugat pnInStoc,pnInCrm,pcUm
		Private pnId_articol, pcDenumire, pnCant, pnId_gestiune, pcGestiune, pcCont_articol,pnInStoc,pnInCrm,pcUm, pcLot, pcSerie
		Store 0 To pnId_articol, pnId_gestiune,pnInCrm
		Store 1 To pnCant,pnInStoc
		Store '' To pcDenumire, pcGestiune, pcCont_articol,pcUm, pcLot, pcSerie
		***---------------------------------------------------------------------------------------
		Private pnId_sectie, pcSectie, pnId_comanda, pcNr_comanda, pnValoareDecontata, pnCheltuieliDirecte
		Store 0 To pnId_sectie, pnId_comanda, pnValoareDecontata, pnCheltuieliDirecte
		Store '' To pcSectie, pcNr_comanda

		lcFormProductie = Alltrim(Upper(oSet.formproduc))
		loap = Createobject(lcFormProductie)
		*loap = Createobject('frm_alege_prod_cant')
		loap.Show(1)
		*!*	modificare ROAPRODUCTIE v 2.0.0
		If gnButon = 2
			Return gnButon
		Endif
		*!*	modificare ROAPRODUCTIE v 2.0.0	^
	Endif

	If Alltrim(Upper(LcNumeObj)) <> 'INVENTAR_STOC'
		onirbon = Createobject(LcNumeObj)
		If Type('onirbon.cObj') # 'U'
			onirbon.cObj = lcObj
		Endif
		If Type('onirbon.cTip_frm') # 'U'
			onirbon.cTip_frm = lcTipFrm
		Endif
		If Type('onirbon.cFrm_cereDate') # 'U'
			onirbon.cFrm_cereDate = lcFormCereDate
		Endif

		If !Inlist(Left(Alltrim(Upper(lcObj)),6), "WEBNIR","VALOAR","SCHIMB","INVENT","RESTNI")
			onirbon.ct_Factura1.Visible = lFactura
			onirbon.ct_factura2.Visible = lFacturaVal
			onirbon.ct_Adaos1.Visible = lAdaos
			onirbon.ct_Discount1.Visible = lDiscount
			&& daca onirbon.ct_factura2 este vizibil il trec in fata
			If lFacturaVal
				onirbon.ct_factura2.ZOrder(0)
			Endif
			&& daca onirbon.ct_Discount1 este vizibil il trec in fata ( )
			If lDiscount
				onirbon.ct_Discount1.ZOrder(0)
			Endif

			*** INITIALIZEZ PROPRIETATILE CONTAINER STANGA
			With onirbon.ct_grid_search1
				.cselect = lcSelSt
				.cschema = lcSchemaSt
				.cTitlu_coloane = Alltrim(ost.titlu_col)
				.cNume_coloane = Alltrim(ost.nume_col)
				.cMask = Alltrim(ost.mask_col)
				.cWidth_coloane = Alltrim(lcWidth_coloane)
				.nPornire = lnPornire

				.cFiltruOriginal = lcFiltruOrig
				.cFiltru = Alltrim(ost.FILTRU)
				.cOrder = Alltrim(ost.ordine)

				.cTitlu = Alltrim(ost.titlu_grid)
				.cb_tx_gestout.Visible = llGestout
				.CWHERE = Alltrim(ost.CWHERE)
				.but_nou1.Visible = llAdMod
				*	.but_modifica1.VISIBLE = llAdMod
				*!*	modificare	03.10.2007
				If Inlist(oxset.model,4,6)	&&	Retur
					.RemoveObject([Cb_tx_gestout])
				Endif
				*!*	modificare	03.10.2007	^
			Endwith

			*** INITIALIZEZ PROPRIETATILE CONTAINER DREAPTA
			With onirbon.ct_grid_order1
				.cselect = lcSelDr
				.cTitlu_coloane = Alltrim(odr.titlu_col)
				.cNume_coloane = Alltrim(odr.nume_col)
				.cMask = Alltrim(odr.mask_col)
				*!*	modificare	v 2.0.6
				*!*	modificare	15.02.2008
				*!*				.cFiltruOriginal = Alltrim(odr.filtruOrig)
				*!*				.cFiltru = Alltrim(odr.FILTRU)
				*!*				.cFiltruOriginal = Evaluate(Alltrim(odr.fpfiltruOr))
				*!*				.cFiltru = Evaluate(Alltrim(odr.fpFILTRU))
				*!*	modificare	15.02.2008	^
				.cFiltruOriginal = Alltrim(odr.fpfiltruOr)
				.cFiltru = Alltrim(odr.FILTRU)
				*!*	modificare	v 2.0.6	^
				.cOrder = Alltrim(odr.ordine)
				.cTitlu = Alltrim(odr.titlu_grid)
				.cb_tx_gestin.Visible = llGestin
			Endwith

			onirbon.osel_dr = odr
		Endif
		
		onirbon.addproperty('lCorectie', m.llCorectie)
		onirbon.addproperty('nCod', m.lnCod)
		
		onirbon.Show()
	Endif

	Clear Class (LcNumeObj)

	&&	modificare 06.03
	&&	casa de marcat

	If buton = 1

		If Type('glListareBonFiscal')<>'U' And glListareBonFiscal
			&&E500
			&&	lcSirBonFiscal (explicatii) :
			&&	1 (vanzare);nume articol;u.m.;departament;cota tva;pret*10^2;cantitate*10^3;0 (articolul va fi vandut)

			&&MP500
			&&	lcSirBonFiscal (explicatii) :
			&& S (vanzare),nr logic,zona rezervata;Parametrii
			&&Parametrii : denumire c(22);pret 99999999;cantitate 99999.999;numar departament de la 1 la 8;
			&& 			   numar grupa de articole de la 1 la 99;numar grupa tva de la 1 la 8

			If pnTipCasaMarcat=1
				lcSirBonFiscal=[]
			Else
				lcSirBonFiscal=[H,1,______,_,__;]+CRLF
			Endif
			Local lnValMp500

			lnValMp500 = 0

			Select rul_temp
			Scan
				If pnTipCasaMarcat=1
					lcSirBonFiscal=lcSirBonFiscal+[1;]+Substr(Alltrim(denumire),1,14)+[;1;2;1;]+;
						ALLTRIM(Str(Round(Round(pretv,gnPPretV)+Round(tvav,gnPPretV),2)*100))+[;]++Alltrim(Str(cante*1000))+[;0]+CRLF
				Else
					lnValMp500 = round(Round(pretv,gnPPretV)+Round(tvav,gnPPretV),2)
					*!*					pnSumamp500 = pnSumamp500 + lnValMp500*cante
					lcSirBonFiscal=lcSirBonFiscal+[S,1,______,_,__;]+Left(Alltrim(denumire),22)+[;]+;
						ALLTRIM(Str(lnValMp500*100,8))+[;]+Alltrim(Str(cante,9,3))+[;1;1;1;0;0;]+CRLF
				Endif

			Endscan

			&&	lcSirBonFiscal (explicatii) :
			&&	5 (incasare);suma achitata;0(numerar);0(moneda);0(numar card credit)

			Select actactan
			*!*			modificare 23.02.2007
			*!*				LOCATE FOR scd='5311'
			*!*				IF FOUND()
			*!*					lnNumarBonFiscal=nract
			*!*					IF pnTipCasaMarcat=1
			*!*						lcSirBonFiscal=lcSirBonFiscal+[5;]+ALLTRIM(STR(suma*100))+[;0;0;0]+CRLF+CRLF
			*!*					ENDIF
			*!*					ldDataBonFiscal=get_ora()
			*!*				ENDIF
			Calculate Sum(suma) For scd='5311' To lnSuma
			If lnSuma > 0
				lnNumarBonFiscal=nract
				If pnTipCasaMarcat=1
					lcSirBonFiscal=lcSirBonFiscal+[5;]+Alltrim(Str(lnSuma*100))+[;0;0;0]+CRLF+CRLF
				Endif
				ldDataBonFiscal=get_ora()
			Endif
			*!*			modificare 23.02.2007 ^
		Endif

		If Alltrim(LcNumeObj) =  'WEBNIR'
			Select actactan
			Locate For scc='371' And id_set = oSet.id_set
			If Found()
				lnNir = nnir
			Endif
		Endif

		If INLIST(Alltrim(LcNumeObj),'WEBNIR_RETETAR',"RESTNIR_RETETAR","RESTNIR_RETETAR_CUM") Or poAct.id_set = 26002
			Select actactan
			Locate For scc='301' And id_set = oSet.id_set
			If Found()
				lnNir = nnir
			Endif
		Endif


		If Alltrim(LcNumeObj) =  'INVENTAR_STOC'
			*!*	modificare ROAPRODUCTIE	v 2.0.0
			*!*			Do nota_inventar With .F., .T. In OINTRODUCERI.PRG
			Private pnIdCInventar
			Store 0 To pnIdCInventar
			lcSql = [begin pack_inventar.adauga_inventar(] + Alltrim(Str(gnLuna)) + [,] + Alltrim(Str(gnAn)) + [,] + ;
				['] + Alltrim(poAct.gestout) + [','] + Alltrim(Str(poAct.id_gestiune)) + [|',] + Alltrim(Str(gnIdUtil)) + [,] + ;
				[3,?gnIdSucursala,?@pnIdCInventar); end;]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
				Return 2
			Else
				Do vizualizeaza_inventar With pnIdCInventar In OINTRODUCERI.PRG
			Endif
			*!*	modificare ROAPRODUCTIE	v 2.0.0	^
		Endif

		*** Modificare NIR/BON - se sterger documentului original inainte de scrierea celui nou
		IF m.llCorectie
			lcSql = [begin pack_contafin.sterge_document(] + ALLTRIM(STR(m.lnCod)) + [,] + ALLTRIM(STR(m.gnAn)) + [,] + ALLTRIM(STR(m.gnLuna)) + [,] + ALLTRIM(STR(gnIdUtil)) + [); end;]
			llSucces = goExecutor.oExecuta(lcSql)
				
			buton = IIF(m.llSucces, 1, 2)
			IF buton = 2
				MESSAGEBOX('Nu s-a putut sterge documentul original! Nu se va scrie nici documentul modificat!',0+48,_screen.Caption)
			ENDIF 
		ENDIF && m.llCorectie

	ENDIF && buton = 1
	&&	sfarsit modificare 06.03


	&&	modificare 25.10.2006
	*!* 236, 240 = marfa pv > transfer > retur din gestiune valorica - aviz expeditie - lista preturi
	*!* 241, 242 = marfa pa > transfer > retur din gestiune valorica - aviz expeditie - lista preturi
	*!*	modificare	v 2.0.188 : am adaugat 233
	If buton = 1 And (Inlist(oSet.id_set,73,79,83,206,61,62,63,64,65, 102, 103,222,223,224,225,226,227,236,238,239,240,241,242,243,244) Or Inlist(oSet.id_set,233,252,255,256,258,259,260,261,262,267,270,272)) And oSet.model > 1
		*!*	modificare	13.08.2007
		If Used('rul_temp')
			Select rul_temp
			Replace nract With poAct.nract,serie_Act With poAct.serie_Act All
		Endif
		If Used('rul_temp_obinv')
			Select rul_temp_obinv
			Replace nract With poAct.nract,serie_Act With poAct.serie_Act All
		Endif
		*!*	modificare	13.08.2007	^
		*!* 12.11.2019 poDate se initializeaza doar in initializeaza_vanzare_din_stoc() pentru vanzarea din stoc
		IF TYPE('poDate') = 'U'
			Private poDate 
			lnTip = IdSet2TipFacturare(oSet.id_set)
			poDate = CREATEOBJECT("oDateFactura",oSet.id_set, m.lnTip)
		ENDIF 
		*!* 12.11.2019 ^
		lnButon = 1
		lnSucces = oscrie_vanzare_din_stoc(oSet)	&&	ofacturare_stoc.prg
		If lnSucces < 0
			lnButon = 2
		Endif
	Else
		&&	modificare 25.10.2006	^
		If buton = 1 And oSet.model > 1
			*!*	modificare	13.08.2007
			If Used('rul_temp')
				Select rul_temp
				Replace nract With poAct.nract,serie_Act With poAct.serie_Act All
			Endif
			If Used('rul_temp_obinv')
				Select rul_temp_obinv
				Replace nract With poAct.nract,serie_Act With poAct.serie_Act All
			Endif
			*!*	modificare	13.08.2007	^
			lnButon = 1
			lnSucces = oscrie_in_fisiere(0,.F.,.T.)
			If lnSucces < 0
				lnButon = 2
			Endif
			*!*	modificare ROAPRODUCTIE	v 2.0.0
			If poAct.id_set = 26000
				If lnSucces < 0
					lcSql = [update ] + gcs + [.GEST_CENTR_INVENTAR set sters = 1, dataoras = sysdate,id_utils=?gnIdUtil  where id_c_inventar =?pnIdCInventar]
				Else
					lcSql = [update ] + gcs + [.GEST_CENTR_INVENTAR set validat = 1, dataorav = sysdate,id_utilv=?gnIdUtil  where id_c_inventar =?pnIdCInventar]
				Endif
				lnSucces2 = goExecutor.oExecute(lcSql)
				If lnSucces2 < 0
					amessagebox(goExecutor.cEroare,0+16,"Eroare")
				Endif
				Release pnIdCInventar
			Endif
			*!*	modificare ROAPRODUCTIE	v 2.0.0	^
			*!* 29.05.2010
			*!* 231 mf pret de vanzare > facturi neplatite pret de lista
			*!* 247 mf pret de achizitie *  > facturi neplatite pret de lista			
			*!* 266 mf pret de achizitie *  > facturi nesosite pret de lista
			llAvizTransferAutomat = IIF(oSet.id_set = 231 and ((TYPE('gnRG_AVIZ_TRANSFER_NIR6') <> 'U' and m.gnRG_AVIZ_TRANSFER_NIR6 = 1) or TYPE('gnRG_AVIZ_TRANSFER_NIR6') = 'U'), .T., ;
				IIF(INLIST(oSet.id_set, 247, 266) and ((TYPE('gnRG_AVIZ_TRANSFER_NIR7') <> 'U' and m.gnRG_AVIZ_TRANSFER_NIR7 = 1) or TYPE('gnRG_AVIZ_TRANSFER_NIR7') = 'U'), .T., .F.))

			If buton = 1 And lnSucces > 0 And Inlist(oSet.id_set, 231, 247, 266) AND m.llAvizTransferAutomat
			*!* 29.05.2010 ^		
				*!* 26.10.2011	
				*!* daca dau renunt la transferul articolelor din nir in alta gestiune, se in actbaza2007.release se dezaloca numarul de NIR
				lnOldButon = buton
				Do ofactureaza.PRG
				buton = lnOldButon
				pnButon = lnOldButon
				gnButon = lnOldButon
				*!* 26.10.2011 				
			Endif
		Else
			lnButon = 2
		Endif

		lnTipGest = gnTipGest

		If lnButon # 2 And !Empty(oSet.listare)
			lcProcName = Alltrim(oSet.listare)
			lcParametersList = Alltrim(oSet.param2)  && pcObj.nnir,gnTipGest IN oproceduri_listari
			If INLIST(Left(Alltrim(LcNumeObj),6),'WEBNIR',"RESTNI")
				lnNr_pag = 0
				Do Case
					Case LcNumeObj = 'WEBNIR' And (oSet.id_set = 91 Or oSet.id_set = 96 Or oSet.id_set = 97 OR oSet.id_set = 106)
						lnNr_pag = 5
						Do &lcProcName With lnNir, lnNr_pag In oproceduri_listari
					Case LcNumeObj = 'WEBNIR' And oSet.id_set = 95
						lnNr_pag = 6
						Do &lcProcName With lnNir, lnNr_pag In oproceduri_listari
					Case INLIST(LcNumeObj,'WEBNIR_RETETAR',"RESTNIR_RETETAR","RESTNIR_RETETAR_CUM")
						lnNr_pag = 2
						Do listare_descarcare_productie With lnNir, lnNr_pag In oproceduri_listari
				Endcase
			Else
				Do Case
					Case LcNumeObj = 'INVENTAR_STOC'
						lnNr_pag = 0 && 4
						Do &lcProcName With poAct.nract, lnNr_pag In oproceduri_listari

						If poAct.id_set = 26000 && Bon de consum cu inventar
							Private pnId_gestiune, pcNumeGestiune, pnNr
							pnId_gestiune = poAct.id_gestiune
							pcNumeGestiune = poAct.nume_gestiune
							pnNr = poAct.nract

							lcSel = [{call pack_productie.get_stoc(?gnAn, ?gnLuna, ?pnId_gestiune, ?gnIdSucursala)}]

							lcCursor = 'cStoc'
							lnSucces = goExecutor.oExecute(lcSel, lcCursor)

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

							Private pcTitlu, pcDataOra
							pcTitlu = "INVENTAR la data de "+Dtoc(poAct.dataact)
							pcDataOra = get_ora(2)

							Select cStoc
							Report Form rap_inventariere_bon.frx To Printer Prompt Preview

							If Used('cStoc')
								Use In cStoc
							Endif
						Endif
						*!*				Case poact.id_set = 26002 && Inregistrare productie si consum de materii prime
						*!*					lnNr_pag = 2
						*!*					Do listare_descarcare_productie With lnNir, lnNr_pag In oproceduri_listari
					Otherwise
						Do &lcProcName With &lcParametersList && IN oproceduri_listari
				Endcase
			Endif
		Endif
		&&	modificare 25.10.2006
	Endif
	&&	modificare 25.10.2006	^


	&&	modificare 06.03
	&&	casa de marcat
	If lnButon#2 And Type('glListareBonFiscal')<>'U' And glListareBonFiscal
		If pnTipCasaMarcat=1
			imprimare_bon_fiscal(lcSirBonFiscal,ldDataBonFiscal,lnNumarBonFiscal)
		Else
			If Type('lcStringmp500')='C'
				lcSirBonFiscal=lcSirBonFiscal+lcStringmp500
			Else
				lcSirBonFiscal=lcSirBonFiscal+[T,1,______,_,__;]+CRLF+[F,1,______,_,__;]+CRLF
			Endif
			imprimare_bon_mp500(lcSirBonFiscal,ldDataBonFiscal,lnNumarBonFiscal)
		Endif
	Endif
	&&	sfarsit modificare 06.03

	Use In (Select('actactan'))
	Use In (Select('rul_temp'))
	Use In (Select('rul_temp_obinv'))
	Use In (Select('jtva_achizitie'))
	Use In (Select('jtva_vanzare'))
	Use In (Select('crsconfigcvc'))
	Use In (Select('crsGestSelectiiUtilizator'))

	*!* modificare ROAPRODUCTIE v 2.0.2
	If oSet.productie And !Empty(oSet.formproduc)
		Release pnId_articol, pcDenumire, pnCant, pnId_gestiune, pcGestiune, pcCont_articol,pnInStoc,pnInCrm,pcUm, pcLot, pcSerie
	ENDIF
	*!* modificare ROAPRODUCTIE v 2.0.2	^

	Release oSet
	Release ost
	Release odr
	
	Return lnButon

	********* SFARSIT: lans_Nir_Bon ***********

	****************************************************************************************************
Function IsNIRBONPretCuTVA
	Lparameters tnIdSet
	Local llNIRBONPretCuTVA
	&&23.10.2008 adaugat 248 - bilete ratc in gestiunea hibrid
	llNIRBONPretCuTVA = Iif(Inlist(tnIdSet, 234,248),.T.,.F.) && NIR BILETE RATC

	Return llNIRBONPretCuTVA
Endfunc && IsNIRBONPretCuTVA
****************************************************************************************************

********* INCEPUT: aleg_facturi_pt_retur ***********
Procedure aleg_facturi_pt_retur
	Parameters tnIdPart,tcCont,tcTitlu,tcCursor

	If Empty(tcTitlu)
		lcTitlu = [Facturi emise]
	Else
		lcTitlu = Upper(Alltrim(tcTitlu))
	Endif

	*** aflu numele partenerului
	*!*	lcNumePart=''

	*!*	lcSel = [select nume from ] + gcs + [.vnom_parteneri where id_part = ?tnIdPart]
	*!*	lccursor = [crsNumePart]
	*!*	lnsucces = goExecutor.oExecute(lcSel,lccursor)
	*!*	IF lnsucces < 0
	*!*		lcmesaj = goExecutor.cEroare
	*!*		ofrm_er = CREATEOBJECT('frm_mesaj','Eroare','exclam.ico','Avertizare',lcmesaj)
	*!*		ofrm_er.show(1)
	*!*		RELEASE ofrm_er
	*!*	ENDIF
	*!*	SELECT crsNumePart
	*!*	LOCATE
	*!*	lcNumePart = ALLTRIM(nume)
	*!*	USE IN crsNumePart

	*** perioada din luna curenta
	pdDataI = Ctod('01/' + pcNl + '/' + pcAn)
	pdDataF = ultimazi(pcAn,pcNl)

	lcSel = [{call facturi_emise(?gcS,?tcCont,?tnIdPart,?pdDataI,?pdDataF)}]
	lcSchema = ['']  &&['ceck n(1),totdebit n(16,gnPa),totcredit n(16,gnPa),id_fact n(10),id_part n(10),nume c(50),dataact D,dataireg D,nract n(14),datascad D,cont c(4),acont c(4)']
	lcCursor = Iif(!Empty(tcCursor),Alltrim(tcCursor),'crs_facturi_emise')
	lnSucces = goExecutor.oExecute(lcSel,lcCursor)

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

	ofact = Createobject('facturi_retur')
	With ofact.ct_grid_order1
		.cselect = lcSel
		.cschema = lcSchema
		.cTitlu_coloane = [Alege,Serie factura,Nr.factura,Data factura,Data scadenta,Cont,Analitic,Total cu TVA,Achitat,Sold]
		.cNume_coloane = [ceck;serie_act;nract;dataact;datascad;cont;acont;totdebit;totcredit;totdebit-totcredit]
		.cFiltruOriginal = []
		.cFiltru = []
		.cOrder = [dataact]
		.cTitlu = [Client: ] + lcTitlu
		.cnrcoloane_check = [1]
		.cnumeCursor = lcCursor
		.lmodparam = .T.
	Endwith

	ofact.Show(1)

	Select (lcCursor)
	lcFacturiAlese = []
	Select (lcCursor)
	Scan For ceck = 1
		lcFacturiAlese = lcFacturiAlese + [,] + Alltrim(Str(id_fact))
	Endscan
	lcFacturiAlese = Substr(lcFacturiAlese,2)
	If Used(lcCursor)
		Use In (lcCursor)
	Endif

	Return lcFacturiAlese
Endproc
********* SFARSIT: aleg_facturi_pt_retur ***********

********* INCEPUT: lista_inventar ***********
Procedure lista_inventar
	Lparameters tnTip
	Local lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcgroup, llModParam, lcFiltruOriginal
	Local llAfiseaza
	Private poInventare
	poInventare = Null

	lcSchema = [id_c_inventar n(20),data_inventar t,id_util n(10),an n(4),luna n(2), ] + ;
		[descriere c(240),validat n(1),dataorav t,id_utilv n(10),util c(240),utilv c(240), tip n(2), ] + ;
		[id_sucursala n(5), sucursala c(100), nract n(14), nnir n(14), id_fact n(20), ] + ;
		[id_gestiuni M, id_subgrupe_articole M, id_articole M]

	lcSelect = [select id_c_inventar,data_inventar,id_util,an,luna, ] + ;
		[descriere,validat,dataorav,id_utilv,util,utilv,tip,id_sucursala,sucursala, nract, nnir, id_fact, id_gestiuni, id_subgrupe_articole, id_articole ] + ;
		[ from vgest_centr_inventar]
	lcFiltru = [an*12+luna <= ] + ALLTRIM(STR(m.gnAn*12+m.gnLuna))
	lcOrder = [2 desc]
	llAfisare=.F.
	lcgroup = []
	llModParam = .T.
	*!*	modificare	ROAVIN v 2.0.0
	*!*	lcFiltruOriginal = Iif(!Empty(gcCondSucursala), Substr(gcCondSucursala,6), [])
	lcFiltruOriginal = Substr(gcCondSucursala + Iif(!Empty(tnTip),[ and tip = ] + Alltrim(Str(tnTip)),[]),6)
	*!*	modificare	ROAVIN v 2.0.0	^
	gencursor('poInventare','crsinventare',lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcgroup, llModParam, lcFiltruOriginal)
	poInventare.ca_baza1.afisare()
	*!*	modificare	ROAVIN v 2.0.0
	*!*	loFrmInventare = Createobject('frm_inventar_centralizator')
	loFrmInventare = Createobject('frm_inventar_centralizator',tnTip)
	*!*	modificare	ROAVIN v 2.0.0	^
	loFrmInventare.Show(1)
	Use In (Select('crsInventare'))
	Release loFrmInventare,poInventare
Endproc	&&	lista_inventar
********* SFARSIT: lista_inventar ***********

********* INCEPUT: vizualizeaza_inventar ***********
Procedure vizualizeaza_inventar
	Lparameters tnIdCInventar, tlCorectie
	*** tlCorectie: .T. daca inventarul este validat si se doreste corectarea lui
	
	LOCAL llCorectie
	llCorectie = IIF(PCOUNT() >=2, tlCorectie, .F.)
	
	Local llBonConsum, llObinvent, llInventarROAVin,llMagazin
	Local lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcgroup, llModParam, lcFiltruOriginal
	Local lnValidat, lnTip, ldDataInventar
	lnValidat = 0
	lnTip = 1

	Local llCreareGeneratorNumere
	*!* 15.06.2010
	Private pdDataRef, pdDataInceputInventar, pdDataSfarsitInventar, pnNract, pnNnir, pdDataNotaInventar, pcTextLunaAn, pcChiosc, pcTextLunaAnNecompletat
	PRIVATE pnIdFact, pnCod,pnIdInventar
	pnCod = 0
	pnIdFact = 0
	pnNract = 0
	pnNnir = 0
	pdDataNotaInventar = {}
	pcTextLunaAn = ''
	pcTextLunaAnNecompletat = ''
	pcChiosc = ''

	*!* 15.06.2010 ^
*!*		12.01.2015
	pnIdInventar = tnIdCInventar	
*!*		12.01.2015 ^
		
	llCreareGeneratorNumere = .F.
	If Type('poGeneratorNumere') = 'U'
		Private poGeneratorNumere
		poGeneratorNumere = Createobject('oGeneratorNumere')
		llCreareGeneratorNumere = .T.
	Endif

	*!* 16.06.2010
	lcSql = "select validat, dataorav, tip, id_gestiuni, descriere, optiuneinventar, numarluni, data_inventar, id_fact, nract, nnir, dataact from VGEST_CENTR_INVENTAR where id_c_inventar=?pnIdInventar"
	lcCursor = 'crsGestCentrInventarTemp'
	lnSucces = goExecutor.oExecute(m.lcSql, m.lcCursor)
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Return
	ENDIF
	
	*!* 21.12.2011
	*** trebuie act.cod pentru nota de completare din inventarul de corectie
	pnIdFact = NVL(crsGestCentrInventarTemp.id_fact, 0)
	IF m.llCorectie
*!*			lnSucces = goExecutor.oSelect2Value("SELECT MAX(cod) FROM act WHERE an = ?gnAn and luna = ?gnLuna and id_fact = ?pnIdFact", @pnCod)
		lnSucces = goExecutor.oSelect2Value("SELECT MAX(cod) FROM act WHERE an = " + ALLTRIM(STR(m.gnAn)) + " and luna = " + ALLTRIM(STR(m.gnLuna)) + " and id_fact = " + ALLTRIM(STR(m.pnIdFact)), @pnCod)		
		IF m.lnSucces < 0
			amessagebox(goExecutor.cEroare,0+16,"Eroare")
			Return	
		ENDIF 
	ENDIF 	
	*!* 21.12.2011 ^

	Select crsGestCentrInventarTemp
	lnValidat = Validat
	lnTip = tip
	lcId_gestiuni = Alltrim(id_gestiuni)
	lcDescriere = Alltrim(descriere)
	lnOptiuneInventar = optiuneinventar
	ldDataInventar = data_inventar
	pdDataRef = data_inventar
	pdDataInceputInventar = data_inventar
	pdDataSfarsitInventar = dataorav
	pnNract = nract
	pnNnir = nnir
	pdDataNotaInventar = dataact
	pcChiosc = ALLTRIM(NVL(descriere,''))
	pcTextLunaAn = 'Luna contabila ' + PADL(allt(str(m.gnLuna)),2, '0') + '/' + allt(str(m.gnAn)) + ;
		' Inventar ' + transform(m.pdDataInceputInventar)+ ;
		IIF(!EMPTY(NVL(m.pdDataSfarsitInventar,{})), ' -  ' + transform(m.pdDataSfarsitInventar), '') + ;
		IIF(!EMPTY(m.lcDescriere), ' | ' + m.lcDescriere , '') + ;
		IIF(!EMPTY(NVL(m.pnNract, 0)), ' | Nr. doc. ' + alltrim(str(pnNract)),'') + ;
		IIF(!EMPTY(NVL(m.pnNnir,0)), ' | Nr. bon ' + alltrim(str(pnNnir)),'') + ;
		IIF(!EMPTY(NVL(m.pdDataNotaInventar,{})), ' | Data doc. ' + transform(m.pdDataNotaInventar), '')	

	pcTextLunaAnNecompletat = 'Luna contabila ' + PADL(allt(str(m.gnLuna)),2, '0') + '/' + allt(str(m.gnAn)) + ;
		IIF(!EMPTY(m.lcDescriere), ' | ' + m.lcDescriere , '')  && fara data inceput inventar si numar/data bon, se poate lista si ulterior, la contabilitate si nu trebuie data generarii inventarului
				
	Use In (Select('crsGestCentrInventarTemp'))
	*!* 16.06.2010 ^	

	llBonConsum = lnTip = 3
	llObinvent = lnTip = 2
	llInventarROAVin = lnTip = 4
	llMagazin = lnTip = 5

	lcNumeCursor = 'crs_inventar'
	*!* 31.01.2011
	IF llInventarROAVin
		lcSelect = [SELECT ID_INVENTAR,ID_ARTICOL,ID_GESTIUNE,STOC_FAPTIC,PRET,PRETV,TVA,TVAV,CANTS,CANT,CANTE,CONT,PRETD,ACONT,DATAIN,DATAOUT,PROC_TVAV,ID_STOC,DATA_REFERINTA,ID_RESPONSABIL,DATAPIF,DNS_LUNI,DNS_LUNI_FAPTIC,UZURA_FAPTIC,DNS_RAMAS,STOC_SCRIPTIC,DEPRECIERE, ] + ;
			[MOTIV_DEPRECIERE,ID_UTIL,SERIE,PRET_UNITAR,DENUMIRE,CODMAT,UM,DNF,ID_GRUPA,ID_SUBGRUPA,GRUPA,SUBGRUPA,CGEST,NUME_GESTIUNE,NR_PAG,UTILIZATOR,ID_MESERIA,ID_FORMATIA,DATAANG,DATALIC,DATA_EXPIRARE,ID_RUL_AUX,ID_PART_REZ,ID_LUCRARE_REZ,ID_CATEG_CALITATE, ] + ;
			[ID_VIN_STADIU,ID_VENCHELT,CATEGORIE_CALITATE,CANT_ZAHAR,GRADE_ALCOOL,POTENTIAL,AN_PROD,ACRONIM,STADIU,EXPLICATIE,ID_VALUTA,VALUTA,LOT,ADATA_EXPIRARE,ID_C_INVENTAR,ID_SUCURSALA,PRETCTVAV, ] + ;
			[VALIDAT, DATAORA_VALIDAT, ID_FURNIZOR, FURNIZOR, DATAORA ] + ;
			[FROM vvin_gest_inventar]

		lcSchema = [ID_INVENTAR N(20) NOT NULL,ID_ARTICOL N(10) NOT NULL,ID_GESTIUNE N(5) NOT NULL,STOC_FAPTIC N(14,3) NOT NULL,PRET N(16,4) NOT NULL,PRETV N(16,4) NOT NULL,TVA N(16,4) NOT NULL,TVAV N(16,4) NOT NULL,CANTS N(14,3) NOT NULL,CANT N(14,3) NOT NULL, ] + ;
			[CANTE N(14,3) NOT NULL,CONT V(4) NULL,PRETD N(16,4) NOT NULL,ACONT V(4) NULL,DATAIN T NULL,DATAOUT T NULL,PROC_TVAV N(5,2) NOT NULL,ID_STOC N(10) NOT NULL,DATA_REFERINTA T NULL,ID_RESPONSABIL N(10) NULL,DATAPIF T NULL,DNS_LUNI N(10) NOT NULL, ] + ;
			[DNS_LUNI_FAPTIC N(10) NULL,UZURA_FAPTIC N(3) NULL,DNS_RAMAS N(10) NOT NULL,STOC_SCRIPTIC N(14,3) NULL,DEPRECIERE N(16,4) NOT NULL,MOTIV_DEPRECIERE V(50) NULL,ID_UTIL N(5) NOT NULL,SERIE V(100) NULL,PRET_UNITAR N(16, 4) NULL,DENUMIRE V(100) NULL, ] + ;
			[CODMAT V(50) NULL,UM V(10) NULL,DNF N(5) NULL,ID_GRUPA N(5) NULL,ID_SUBGRUPA N(5) NULL,GRUPA V(100) NULL,SUBGRUPA V(100) NULL,CGEST V(20) NULL,NUME_GESTIUNE V(50) NULL,NR_PAG N(2) NULL,UTILIZATOR V(30) NULL,ID_MESERIA N(5) NULL,ID_FORMATIA N(5) NULL, ] + ;
			[DATAANG T NULL,DATALIC T NULL,DATA_EXPIRARE T NULL,ID_RUL_AUX N(10) NULL,ID_PART_REZ N(10) NULL,ID_LUCRARE_REZ N(10) NULL,ID_CATEG_CALITATE N(10) NULL,ID_VIN_STADIU N(10) NULL,ID_VENCHELT N(10) NULL,CATEGORIE_CALITATE V(100) NULL,CANT_ZAHAR N(18, ] + ;
			[4) NULL,GRADE_ALCOOL N(18,4) NULL,POTENTIAL N(18,4) NULL,AN_PROD N(4) NULL,ACRONIM V(15) NULL,STADIU V(50) NULL,EXPLICATIE V(200) NULL,ID_VALUTA N(5) NULL,VALUTA V(10) NULL,LOT V(20) NULL,ADATA_EXPIRARE T NULL,ID_C_INVENTAR N(20) NULL, ] + ;
			[ID_SUCURSALA N(5) NULL,PRETCTVAV N(20,4) NULL, VALIDAT N(1) NULL, DATAORA_VALIDAT T NULL, ID_FURNIZOR I, FURNIZOR C(100), DATAORA T ]
*		lcSchema = ""			
	ELSE 
		lcSelect = [SELECT ID_INVENTAR,ID_ARTICOL,ID_GESTIUNE,STOC_FAPTIC,STOC_FAPTIC1,STOC_FAPTIC2,STOC_FAPTIC3,STOC_FAPTIC4,STOC_FAPTIC5,PRET,PRETV,TVA,TVAV,CANTS,CANT,CANTE,CONT,PRETD,ACONT,DATAIN,DATAOUT,PROC_TVAV,ID_STOC,DATA_REFERINTA,ID_RESPONSABIL,DATAPIF,DNS_LUNI, ] + ;
			[DNS_LUNI_FAPTIC,UZURA_FAPTIC,DNS_RAMAS,STOC_SCRIPTIC,DEPRECIERE,MOTIV_DEPRECIERE,PRET_UNITAR,DENUMIRE,CODMAT,CODBARE,UM,DNF,ID_GRUPA,ID_SUBGRUPA,GRUPA,SUBGRUPA,CGEST,NUME_GESTIUNE,ID_UTIL,NR_PAG,UTILIZATOR,RESPONSABIL,ID_MESERIA,MESERIE,ID_FORMATIA, ] + ;
			[FORMATIA,DATAANG,DATALIC,DATA_EXPIRARE,ID_RUL_AUX,SERIE,ID_VALUTA,VALUTA,ID_PART_REZ,ID_LUCRARE_REZ,PART_REZ,NRORD_REZ,LOT,ADATA_EXPIRARE,ID_C_INVENTAR,ID_SUCURSALA,ID_SUCURSALA_GESTIUNE,PRETCTVAV,ID_SECTIE,SECTIE,FIRST_UPDATED_AT, ] + ;
			[VALIDAT, DATAORA_VALIDAT, ID_FURNIZOR, FURNIZOR, DATAORA ] + ;
			[FROM vgest_inventar]
			
		lcSchema = [ID_INVENTAR N(20) NOT NULL,ID_ARTICOL N(10) NOT NULL,ID_GESTIUNE N(5) NOT NULL,STOC_FAPTIC N(14,3) NOT NULL,STOC_FAPTIC1 N(14,3) NOT NULL,STOC_FAPTIC2 N(14,3) NOT NULL,STOC_FAPTIC3 N(14,3) NOT NULL,STOC_FAPTIC4 N(14,3) NOT NULL,STOC_FAPTIC5 N(14, ] + ;
			[3) NOT NULL,PRET N(16,4) NOT NULL,PRETV N(16,4) NOT NULL,TVA N(16,4) NOT NULL,TVAV N(16,4) NOT NULL,CANTS N(14,3) NOT NULL,CANT N(14,3) NOT NULL,CANTE N(14,3) NOT NULL,CONT V(4) NULL,PRETD N(16,4) NOT NULL,ACONT V(4) NULL,DATAIN T NULL, ] + ;
			[DATAOUT T NULL,PROC_TVAV N(5,2) NOT NULL,ID_STOC N(10) NOT NULL,DATA_REFERINTA T NULL,ID_RESPONSABIL N(10) NULL,DATAPIF T NULL,DNS_LUNI N(10) NOT NULL,DNS_LUNI_FAPTIC N(10) NULL,UZURA_FAPTIC N(3) NULL,DNS_RAMAS N(10) NOT NULL,STOC_SCRIPTIC N(14,3) NULL, ] + ;
			[DEPRECIERE N(16,4) NOT NULL,MOTIV_DEPRECIERE V(50) NULL,PRET_UNITAR N(16,4) NULL,DENUMIRE V(100) NULL,CODMAT V(50) NULL,CODBARE V(50) NULL,UM V(10) NULL,DNF N(5) NULL,ID_GRUPA N(5) NULL,ID_SUBGRUPA N(5) NULL,GRUPA V(100) NULL,SUBGRUPA V(100) NULL, ] + ;
			[CGEST V(20) NULL,NUME_GESTIUNE V(50) NULL,ID_UTIL N(5) NOT NULL,NR_PAG N(2) NULL,UTILIZATOR V(30) NULL,RESPONSABIL V(70) NULL,ID_MESERIA N(5) NULL,MESERIE V(64) NULL,ID_FORMATIA N(5) NULL,FORMATIA V(64) NULL,DATAANG T NULL,DATALIC T NULL, ] + ;
			[DATA_EXPIRARE T NULL,ID_RUL_AUX N(10) NULL,SERIE V(100) NULL,ID_VALUTA N(5) NULL,VALUTA V(10) NULL,ID_PART_REZ N(10) NULL,ID_LUCRARE_REZ N(10) NULL,PART_REZ V(70) NULL,NRORD_REZ V(100) NULL,LOT V(20) NULL,ADATA_EXPIRARE T NULL, ] + ;
			[ID_C_INVENTAR N(20) NULL,ID_SUCURSALA N(5) NULL,ID_SUCURSALA_GESTIUNE N(10) NULL,PRETCTVAV N(20,4) NULL,ID_SECTIE N(5) NULL,SECTIE V(50) NULL,FIRST_UPDATED_AT T NULL, VALIDAT N(1) NULL, DATAORA_VALIDAT T NULL, ID_FURNIZOR I, FURNIZOR C(100), DATAORA T ]
*		lcSchema = ""
	ENDIF 	
	*!* 31.01.2011 ^
	lcFiltru= [] && + Iif(glEMama,[ and id_sucursala is null],gcCondSucursala)
	lcOrder = [denumire]
	llAfisare = .F.
	llModParam = .T.
	lcgroup = []
	lcFiltruOriginal = [id_c_inventar = ] + Alltrim(Str(tnIdCInventar))

	If Used(lcNumeCursor)
		Use In &lcNumeCursor
	Endif
	Private podecabaza
	podecabaza = ''
	gencursor('podecabaza',lcNumeCursor,lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcgroup, llModParam, lcFiltruOriginal)
	podecabaza.ca_baza1.afisare()
	gnButon = 2


*!*		lnData = 12*gnAn + gnLuna
*!*		lcSel = [Select MAX(data_referinta) as data_referinta from ] + gcs + [.gest_inventar where 12*extract(YEAR from data_referinta) +extract(MONTH from data_referinta) <=?lnData]

*!*		lcSchema = ['']
*!*		lcCursor = [crs_data]
*!*		lnSucces = goExecutor.oExecute(lcSel,lcCursor)
*!*		If lnSucces < 0
*!*			amessagebox(goExecutor.cEroare,0+16,"Eroare")
*!*		Endif
*!*		pdDataRef = data_referinta
*!*		If Used('crs_data')
*!*			Use In crs_data
*!*		Endif
*!*	modificare	ROAVIN v 2.0.1 ( 19.05.2011 )
	If update_corespondente_cvc() < 0
		Return
	Endif	

*!*	modificare	ROAVIN v 2.0.1 ( 19.05.2011 )	^
	Select crs_inventar
	lnid_c_inventar=id_c_inventar
	oInventar = Createobject('inventar_stoc',tnIdCInventar)
	oInventar.ocursor = podecabaza
	oInventar.cnumeCursor = lcNumeCursor
	*!*	modificare	v 2.2.6
	oInventar.cId_gestiuni = iif(!empty(nvl(lcId_gestiuni,'')),left(Strtran(lcId_gestiuni,[|],[,]),len(lcId_gestiuni)-1),'')
	*!*	modificare	v 2.2.6	^
	oInventar.cFiltruOriginal = lcFiltru
	oInventar.lObinv = llObinvent
	oInventar.lBonConsum = llBonConsum
	oInventar.lInventarROAVin = llInventarROAVin
	oInventar.lValidat = lnValidat = 1
	oInventar.lCorectie = m.llCorectie	
	oInventar.lMagazin = llMagazin
	oInventar.dDataInventar = ldDataInventar
	oInventar.nCod = m.pnCod
	oInventar.nIdFact = m.pnIdFact	
	
*!*		If lnValidat = 1 AND !m.llCorectie
*!*			oInventar.but_nou1.Visible = .F. && adaugare
*!*			oInventar.but_termin1.Visible = .F.
*!*			oInventar.but_sterge1.Visible = .F. && stergere
*!*		Endif	
	oInventar.Show()


	If !llBonConsum And gnButon = 1
		lnSucces = oscrie_in_fisiere(0,.F.,.T.)
		If lnSucces < 0
			If Type([_Screen.nId_tipdoc]) = 'N' And !Empty(_Screen.nid_tipdoc)
				poGeneratorNumere.dezaloca_numar(_Screen.nid_tipdoc)
			Endif
		ELSE
			*!* 15.06.2010
			pnIdFact = 0
			lnSucces = goExecutor.oFunction2Value("pack_contafin.GET_IDFACT()", @pnIdFact)
			If lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
			Endif			

			TEXT TO lcSql NOSHOW
			begin
    			update GEST_CENTR_INVENTAR set validat = 1, id_fact = ?pnIdFact, dataorav = sysdate, id_utilv = ?gnIdUtil where id_c_inventar = ?lnid_c_inventar;
	    		update gest_inventar set validat = 1, dataora_validat = sysdate where id_c_inventar = ?lnid_c_inventar AND validat = 0 ;			
			end;
			ENDTEXT 
*!*				lcSql = [update GEST_CENTR_INVENTAR set validat = 1, id_fact = ?pnIdFact, dataorav = sysdate, id_utilv=?gnIdUtil where id_c_inventar = ] + ALLTRIM(STR(lnid_c_inventar))
			
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
			Endif
		Endif
	Endif
	If llCreareGeneratorNumere
		Release poGeneratorNumere
	Endif
	*!*	modificare	23.10.2012
	Use In (Select(lcNumeCursor))
	Use In (Select('rul_temp'))
	Use In (Select('rul_temp_obinv'))
	Use In (Select('actactan'))
	*!*	modificare	23.10.2012	^
*!*	modificare	ROAVIN v 2.0.1 ( 19.05.2011 )
	Use In (Select('crsconfigcvc'))
*!*	modificare	ROAVIN v 2.0.1 ( 19.05.2011 )	^
Endproc	&&	vizualizeaza_inventar
********* SFARSIT: vizualizeaza_inventar ***********

********* INCEPUT: nota_inventar ***********
Procedure nota_inventar
	Parameters tlObinvent, tlBonConsum, tlInventarROAVin

	&& tlBonConsum - RoaProductie - bon consum productie

	Private pdDataRef, tnRefacInventar
	Local llCallProc,crsUtilNev
	Store .F. To llCallProc
	Store 0 To tnRefacInventar

	*!*	modificare serii numere - 10.2007
	Local llCreareGeneratorNumere
	llCreareGeneratorNumere = .F.
	If Type('poGeneratorNumere') = 'U'
		Private poGeneratorNumere
		poGeneratorNumere = Createobject('oGeneratorNumere')
		llCreareGeneratorNumere = .T.
	Endif
	*!*	modificare serii numere - 10.2007	^

	If tlObinvent
		lcCondSpec = [cont = ?gcContObInv ] + Iif(glEMama,[and id_sucursala is null],gcCondSucursala)
	Else
		lcCondSpec = [cont <> ?gcContObInv ] + Iif(glEMama,[and id_sucursala is null],gcCondSucursala)
	Endif

	If !tlBonConsum

		lnData = 12*gnAn + gnLuna
		lcSel = [Select MAX(data_referinta) as data_referinta from ] + gcs + [.gest_inventar ] + ;
			[where 12*extract(YEAR from data_referinta) +extract(MONTH from data_referinta) <=?lnData ] + ;
			[and validat = 0 and ] + lcCondSpec
		lcSchema = ['']
		lcCursor = [crs_data]
		lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		If lnSucces < 0
			amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Endif

		If lnSucces > 0
			Select crs_data
			Locate
			pdDataRef = data_referinta
			If Used('crs_data')
				Use In crs_data
			Endif
			If !Isnull(pdDataRef)

				lcSel = [select distinct id_util,utilizator,validat from vgest_inventar ] + ;
					[where id_util != 0 and validat = 0 ] + Iif(glEMama,[and id_sucursala is null],gcCondSucursala)
				lcSchema = ['']
				lccrsUtilizatori="crsUtilNev"
				lnSucces = goExecutor.oExecute(lcSel,lccrsUtilizatori)
				If lnSucces < 0
					amessagebox(goExecutor.cEroare,0+16,"Eroare")
				Endif
				lnNrUtilNev=0
				lcListaUtilNev=""
				If Reccount("&lccrsUtilizatori")>0
					lnNrUtilNev = Reccount("&lccrsUtilizatori")
					Select &lccrsUtilizatori

					Scan
						lcListaUtilNev=lcListaUtilNev + Alltrim(&lccrsUtilizatori..utilizator) + ","
					Endscan

					lcListaUtilNev=Substr(lcListaUtilNev,1,Len(lcListaUtilNev)-1)

				Endif
				
				If lnNrUtilNev =0
					lnRaspuns = amessagebox("Doriti sa continuati inventarierea stocului la " + Dtoc(pdDataRef) + "?" , 4+32, "Inventariere")
				Else
					lnRaspuns = amessagebox("Doriti sa continuati inventarierea stocului la " + Dtoc(pdDataRef) + "?" + CRLF + ;
						"ATENTIE! Daca se incepe o inventariere noua se vor suprascrie modificarile nevalidate ale utilizatorilor : " + lcListaUtilNev + "!", 4+32, "Inventariere")
				Endif

				*!*				If buton = 2 && NU
				If lnRaspuns # 6
					llCallProc = .T.
				Endif
			Else
				llCallProc = .T.
			Endif
		Endif
	Else
		llCallProc = .T.
	Endif

	If llCallProc And lnSucces > 0
		tnRefacInventar = 1
		pdDataRef = ultima_zi_din_luna(gnAn, gnLuna)
		*oCere = CREATEOBJECT('frm_cere_titlu','Data de referinta:','pdDataRef')
		*oCere.SHOW()

		Do While pdDataRef > ultima_zi_din_luna(gnAn, gnLuna)
			amessagebox('Data trebuie sa fie din luna curenta!',0,'Atentie')
			pdDataRef = ultima_zi_din_luna(gnAn, gnLuna)
			*	oCere = CREATEOBJECT('frm_cere_titlu','Data de referinta:','pdDataRef')
			*	oCere.SHOW()
		Enddo

	Endif

	If lnSucces > 0
		If tlObinvent
			pnObinv = 1
		Else
			pnObinv = 0
		Endif

		lcSel = [{call inventar_stoc(?tnRefacInventar, ?gcS, TO_DATE(']+Dtos(pdDataRef)+[','YYYY-MM-DD'),] + ;
			[?pnObinv, ?gnIdSucursala)}]
		*	lcSel = [{call inventar_stoc(?tnRefacInventar, ?gcS, ?pdDataRef, ?pnObinv)}]
		lcSchema = ['']
		*!*		lcCursor ='crs_inventar'
		*!*		lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		lnSucces = goExecutor.oExecute(lcSel)
		If lnSucces < 0
			amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Endif
	Endif

	If lnSucces > 0
		lcNumeCursor = 'crs_inventar'
		lcSelect = [select * from ] + Iif(tlInventarROAVin,[vvin_gest_inventar],[vgest_inventar]) + [ where 1=2]
		If tlBonConsum
			lcFiltru = [id_gestiune=]+Alltrim(Str(poAct.id_gestiune)) + [ and data_referinta = ?pdDataRef and ] + lcCondSpec
		Else
			lcFiltru = [data_referinta = ?pdDataRef and ] + lcCondSpec
		Endif
		lcSchema = []
		lcOrder = [denumire]
		llAfisare = .F.
		llModParam = .F.

		If Used(lcNumeCursor)
			Use In &lcNumeCursor
		Endif
		Private podecabaza
		podecabaza = ''

		gencursor('podecabaza',lcNumeCursor,lcSelect,[2=2],lcSchema,lcOrder,llAfisare,'',llModParam,lcFiltru)
		podecabaza.ca_baza1.afisare()

		gnButon = 2

		*!*	modificare serii numere	- 10.2007
		*!*		If Pemstatus(_Screen,'nIdSerie',5)
		*!*			_Screen.nIdSerie = 0
		*!*		Endif
		*!*	modificare serii numere	- 10.2007	^

		Select crs_inventar
		oInventar = Createobject('inventar_stoc')
		oInventar.ocursor = podecabaza
		oInventar.cnumeCursor = lcNumeCursor
		oInventar.cFiltruOriginal = lcFiltru
		oInventar.lObinv = tlObinvent
		oInventar.lBonConsum = tlBonConsum
		oInventar.lInventarROAVin = tlInventarROAVin
		oInventar.Show()
		If !tlBonConsum And gnButon = 1
			lnSucces = oscrie_in_fisiere(0,.F.,.T.)
			If lnSucces < 0
				*!*	modificare serii numere	- 10.2007
				If Type([_Screen.nId_tipdoc]) = 'N' And !Empty(_Screen.nid_tipdoc)
					poGeneratorNumere.dezaloca_numar(_Screen.nid_tipdoc)
				Endif
				*!*				If Pemstatus(_Screen,'nIdSerie',5)
				*!*					lnIdSerieBon =  Str(_Screen.nIdSerie) && il salvez in item.when
				*!*					If Type('lnIdSerieBon') = 'N'
				*!*						lcSql = [update ] + gcs + [.serii_numere  set alocat = 0 where ] +;
				*!*							[ id_numar = ?lnIdSerieBon]
				*!*						lnSucces = goExecutor.oExecute(lcSql)
				*!*						If lnSucces < 0
				*!*							lcTitlu = [Eroare]
				*!*							lcTip = [Avertizare]
				*!*							lcImagine = [exclam.ico]
				*!*							lcMesaj = goExecutor.cEroare
				*!*							ofrm_eroare = Createobject('frm_mesaj',lcTitlu,lcImagine,lcTip,lcMesaj)
				*!*							ofrm_eroare.Show(1)
				*!*							Release ofrm_eroare
				*!*						Endif
				*!*					Endif
				*!*				Endif
				*!*	modificare serii numere	- 10.2007	^
			Else

				lcSql = [update ] + gcs + [.gest_inventar set validat = 1, dataora_validat = pack_contafin.GET_DATAORA() ] + ;
					[where data_referinta = ?pdDataRef and stoc_faptic <> cants+cant-cante and validat = 0 ] + ;
					[AND id_util = ?gnIdUtil] + Iif(glEMama,[ and id_sucursala is null],gcCondSucursala)
				lnSucces = goExecutor.oExecute(lcSql)
				If lnSucces < 0
					amessagebox(goExecutor.cEroare,0+16,"Eroare")
				Endif
			Endif
		endif
		*!*	modificare	23.10.2012
		Use In (lcNumeCursor)
		*!*	modificare	23.10.2012	^
	Endif

	*!*	modificare serii numere - 	10.2007
	If llCreareGeneratorNumere
		Release poGeneratorNumere
	Endif
	*!*	modificare serii numere - 	10.2007	^

Endproc && nota_inventar
********* SFARSIT: nota_inventar ***********

********* INCEPUT: achizitie_import ***********
Procedure achizitie_import
	Parameters tnIdSet, tlIntern

	Local I
	Private pnIdSet
	pnIdSet = tnIdSet
	If Empty(pnIdSet)
		Return
	Endif
	If Type('poGeneratorNumere') = 'U'
		Private poGeneratorNumere
		poGeneratorNumere = Createobject('oGeneratorNumere')
		llCreareGeneratorNumere = .T.
	Endif

	lnButon = lans(pnIdSet)

	If lnButon = 2
		If Used('actactan')
			Use In actactan
		Endif
		Return
	Endif

	Select actactan
	Locate
	Scatter Name poAct
	Zap

	If Used('introdc')
		Use In introdc
	Endif
	lcSql = [select id_note, explicatie as explicatia, scd, ascd, scc, ascc, cu_tva, id_set, ordine, in_valuta, id_jtva_coloana, ptva, explicatie_tva, tipjurnal,taxcode,paymentcode from vnote_contabile ] + ;
		[where id_set = ?pnIdSet]
	lcCursor = [cnote_contabile]
	lnSucces = goExecutor.oExecute(lcSql,lcCursor)
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
		Return
	Endif

		DO CASE 
			CASE m.gnAn < 2017
			* In 2016 lucrez cu TVA 20%. Transform TVA din 19% in 20%
			* Ach int 20%
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 176, explicatie_tva = 'ACH. INT. 20%' where INLIST(id_jtva_coloana, 101, 103, 105) && 19%
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 177, explicatie_tva = 'TVA ACH. INT. 20%' where INLIST(id_jtva_coloana, 102, 104, 106) && 19%

			update cnote_contabile  set ptva = 20, id_jtva_coloana = 178, explicatie_tva = 'ACH. INT. NEEX. 20%' where id_jtva_coloana = 188
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 179, explicatie_tva = 'TVA ACH. INT. NEEX. 20%' where id_jtva_coloana = 189
			
			* Ach. b. imp. 20%
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 180, explicatie_tva = 'ACH. IMP. 20%' where INLIST(id_jtva_coloana, 114, 116, 118)
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 181, explicatie_tva = 'TVA ACH. IMP. 20%' where INLIST(id_jtva_coloana, 115, 117, 119)
			
			* Ach b. CE 20%
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 182, explicatie_tva = 'ACH. BUNURI CE. 20%' where INLIST(id_jtva_coloana, 127, 129, 133)
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 183, explicatie_tva = 'TVA ACH. BUNURI CE. 20%' where INLIST(id_jtva_coloana, 128, 130, 134)

			* Ach Tx inversa 20%
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 186, explicatie_tva = 'TX. INV. 20%' where INLIST(id_jtva_coloana, 137, 139, 141)
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 187, explicatie_tva = 'TVA TX. INV. 20%' where INLIST(id_jtva_coloana, 138, 140, 142)

			* LIV INT 20%
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 27, explicatie_tva = 'LIVR.INTERN 20%' where id_jtva_coloana = 1
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 28, explicatie_tva = 'TVA LIVR.INTERN 20%' where id_jtva_coloana = 2

			update cnote_contabile  set ptva = 20, id_jtva_coloana = 29, explicatie_tva = 'LIVR.INTERN NEEX. 20%' where id_jtva_coloana = 31
			update cnote_contabile  set ptva = 20, id_jtva_coloana = 30, explicatie_tva = 'TVA LIVR.INTERN NEEX. 20%' where id_jtva_coloana = 32
			
		CASE gnAn <= 2015
			* In 2015 lucrez cu TVA 24%. Transform TVA din 20% in 24%		
			* Ach int 24% - 20%
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 156, explicatie_tva = 'ACH. INT. 24%' where id_jtva_coloana = 176
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 157, explicatie_tva = 'TVA ACH. INT. 24%' where id_jtva_coloana = 177

			update cnote_contabile  set ptva = 24, id_jtva_coloana = 170, explicatie_tva = 'ACH. INT. NEEX. 24%' where id_jtva_coloana = 178
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 171, explicatie_tva = 'TVA ACH. INT. NEEX. 24%' where id_jtva_coloana = 179
			
			* Ach. b. imp. 24%
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 158, explicatie_tva = 'ACH. IMP. 24%' where id_jtva_coloana = 180
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 159, explicatie_tva = 'TVA ACH. IMP. 24%' where id_jtva_coloana = 181
			
			* Ach b. CE 24%
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 160, explicatie_tva = 'ACH. BUNURI CE. 24%' where id_jtva_coloana = 182
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 161, explicatie_tva = 'TVA ACH. BUNURI CE. 24%' where id_jtva_coloana = 183

			* Ach Tx inversa 24%
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 162, explicatie_tva = 'TX. INV. 24%' where id_jtva_coloana = 186
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 163, explicatie_tva = 'TVA TX. INV. 24%' where id_jtva_coloana = 187

			* LIV INT 24%
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 15, explicatie_tva = 'LIVR.INTERN 24%' where id_jtva_coloana = 27
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 16, explicatie_tva = 'TVA LIVR.INTERN 24%' where id_jtva_coloana = 28

			update cnote_contabile  set ptva = 24, id_jtva_coloana = 21, explicatie_tva = 'LIVR.INTERN NEEX. 24%' where id_jtva_coloana = 29
			update cnote_contabile  set ptva = 24, id_jtva_coloana = 22, explicatie_tva = 'TVA LIVR.INTERN NEEX. 24%' where id_jtva_coloana = 30			
		ENDCASE  && gnAn <= 2015

	* La facturile cu TVA Incasare modific 4426 in 4428 si explicatiile de TVA
	IF m.tlIntern AND poAct.tva_incasare = 1
		SELECT cnote_contabile
		SCAN
			IF scd = '4426' 
				REPLACE scd WITH '4428'
				loTVA = GeTvaColoana(id_jtva_coloana, 1, 'JC')
			ELSE 	
				loTVA = GeJtvaColoana(id_jtva_coloana, 1, 'JC')
			ENDIF 
			SELECT cnote_contabile
			REPLACE id_jtva_coloana WITH loTVA.id_jtva_coloana, explicatie_tva WITH loTVA.denumire
		ENDSCAN 
	ENDIF 
	
	*!* 22.05.2008
	*!* id_valuta - dadea eroare la verificare_note_contabile
	*!*	modificare v 2.1.39	:	am adaugat data_act, fdoc, id_fdoc, se_scrie
	*!*	modificare v 2.2.6	:	am adaugat tva_incasare		#3649
	Select N.*, ;
		00000000000000.0000 As suma, 00000000000000.0000 As SUMA_val, 00000000000000  As id_partd, 00000000000000  As id_partc, Space(100) As partd, Space(100) As partc, ;
		00000000000000 As id_fact, 00000000000000 As id_factd, 00000000000000 As id_factc, 00000000000000 As pereched, 00000000000000 As perechec, ;
		00000000000000 As nract, Space(10) As serie_Act,Space(50) As explicatia4, Space(50) As explicatia5, .T. As participa_valuta, ;
		poAct.id_valuta As id_valuta, poAct.Curs As Curs, poAct.nume_val As nume_val, poAct.dataact as dataact, poAct.fdoc as fdoc, poAct.id_fdoc as id_fdoc, 0 as se_scrie, poAct.tva_incasare as tva_incasare, ;
		16777215 As doc_color, Space(10) As doc_label, ;
		'B' As tip_rand, Space(80) As doc_key, 00000000 As nr_doc, ;
		00000000000000.0000 As suma_doc, 00000000000000.0000 As suma_doc_val, 0 As mod_manual, 0 As expl_manual, ;
		Space(20) As scd_orig, Space(20) As ascd_orig, 0 As rand_dvi, 0 As valuta_proprie ;
		FROM cnote_contabile N ;
		WHERE N.id_set = poAct.id_set ;
		INTO Cursor introdc Readwrite Order By ordine
	*!* 22.05.2008 ^

	*!* Directia A (11.07.2026): introdc porneste GOL; perechea-sablon (primele 2 linii,
	*!* baza + TVA) se pastreaza in introdc_sablon ca sursa de clonare pentru "Adauga factura".
	Select * From introdc Where Recno('introdc') <= 2 Into Cursor introdc_sablon Readwrite
	*!* 16.07.2026 claude - marcaj tip_rand pe sablon (baza/TVA), inlocuieste paritatea Recno
	Select introdc_sablon
	Go 1
	Replace tip_rand With 'B'
	Go 2
	Replace tip_rand With 'T'
	Go Top
	Select introdc
	Zap

	Use In (SELECT('cnote_contabile'))

	If !Used('saft_taxtable')
		update_saft_taxtable()
	ENDIF 	
	If !Used('saft_mecanisme_plati')
		update_saft_mecanisme_plati()
	ENDIF 	

	* Actualizez taxcode SAFT in functie de furnizori RTVAI
	IF m.gl406
		SELECT introdc
		SCAN FOR INLIST(ALLTRIM(NVL(tipjurnal,'')), 'JC', 'JV')
			lnIdJtva = introdc.id_jtva_coloana
			lnIdPart = NVL(introdc.id_partc, introdc.id_partd)
			lnTaxCode = GetTaxCodeIdPart(m.gnAn, m.gnLuna, poAct.DataAct, m.lnIdJtva, m.lnIdPart)
			SELECT introdc
			REPLACE taxcode WITH m.lnTaxCode 
		ENDSCAN 
	ENDIF 
	GO TOP IN introdc

	Select ordine, ID_JTVA_coloana, denumire, JC, JV, AFISAT, COLOANA_JC, COLOANA_JV, COTA_TVA, ID_TVA ;
		FROM jtva_coloane ;
		WHERE ID_JTVA_coloana > 0 ;
		UNION ;
		SELECT 0 As ordine, 0 As ID_JTVA_coloana, '' As denumire, 0 As JC, 0 As JV, 1 As AFISAT, '' As COLOANA_JC, '' As COLOANA_JV, 0 As COTA_TVA, 0 As ID_TVA ;
		FROM jtva_coloane ;
		WHERE Recno() = 1 ;
		INTO Cursor jtva_coloane2 NOFILTER ;
		ORDER By 1

	gnZvama = 0
	gnButon = 1

	*!* 16.07.2026 claude - F1: index unic de sortare pe introdc, o singura data, inainte de Show
	*!* (niciodata re-INDEX ulterior sub grid - vezi docs/propuneri_import_unificat.md)
	SELECT introdc
	INDEX ON Str(Nvl(nr_doc,0),8) + Icase(tip_rand='B','1', tip_rand='S','2', tip_rand='G','3', tip_rand='T','4', tip_rand='D','5', '6') + Padr(Nvl(scd,''),10) TAG ord_doc
	SET ORDER TO ord_doc

	SELECT introdc
	obj = Createobject('IMPORT_nota', tlIntern)
	*!* 16.07.2026 claude (T3) - Init poate intoarce .F. (esec Oracle la crearea rul_temp) -> obiect nul
	If Vartype(obj) <> 'O'
		Use In (SELECT('introdc'))
		Use In (SELECT('introdc_sablon'))
		Use In (SELECT('actactan'))
		Use In (SELECT('jtva_coloane2'))
		Return
	Endif
	obj.oact = poAct
	obj.Show()

	If gnButon=2
		If Type('poGeneratorNumere') <> 'U'
			poGeneratorNumere.dezaloca_numere()
			poGeneratorNumere.ResetAll()
		Endif
	ENDIF
	
	Use In (SELECT('introdc'))
	Use In (SELECT('introdc_sablon'))
	Use In (SELECT('cote_tva'))
	Use In (SELECT('actactan'))
	Use In (SELECT('rul_temp'))
	USE IN (SELECT('rul_temp_obinv'))
	Use In (SELECT('jtva_coloane2'))
	
ENDPROC && achizitie_import	

	


Procedure completare_parteneri_gestiune

	*!* 02.06.2008
	*!* completez partenerii corespondenti pentru cont-gestin, cont-gestout
	lcSql = [Select cont, id_gestiune, id_part, denumire from vasociere_parteneri_gestiuni]
	lnSucces = goExecutor.oExecute(lcSql, "crsGestiuniParteneri")
	If lnSucces < 0
		amessagebox(goExecutor.oExecute,0+16,"Eroare")
	Else
		Select actactan
		Scan For Empty(id_partd) Or Empty(id_partc)
			Scatter Name loRec
			If Empty(actactan.id_partd)
				Select crsGestiuniParteneri
				Locate For Alltrim(Cont) == Alltrim(loRec.scd) And id_gestiune = Iif(!Empty(loRec.id_gestin), loRec.id_gestin, loRec.id_gestout)
				If Found()
					Replace id_partd With crsGestiuniParteneri.id_part, partd With crsGestiuniParteneri.denumire In actactan
				Endif
			Endif
			If Empty(actactan.id_partc)
				Select crsGestiuniParteneri
				Locate For Alltrim(Cont) == Alltrim(loRec.scc) And id_gestiune = Iif(!Empty(loRec.id_gestout), loRec.id_gestout, loRec.id_gestin)
				If Found()
					Replace id_partc With crsGestiuniParteneri.id_part, partc With crsGestiuniParteneri.denumire In actactan
				Endif
			Endif

		Endscan
		Use In (Select('crsGestiuniParteneri'))
	Endif

Endproc && completare_parteneri_gestiune

********* INCEPUT: lista_inventar_magazin ***********
Procedure lista_inventar_magazin
	Local lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcgroup, llModParam, lcFiltruOriginal
	Local llAfiseaza
	Private poInventare
	poInventare = Null
	lcFiltru = []
	lcSchema = [id_c_inventar n(20),data_inventar t,id_util n(10),an n(4),luna n(2), ] + ;
		[descriere c(240),validat n(1),dataorav t,id_utilv n(10),util c(240),utilv c(240), tip n(2), id_sucursala n(5), sucursala c(100)]

	lcSelect = [select id_c_inventar,data_inventar,id_util,an,luna, ] + ;
		[descriere,validat,dataorav,id_utilv,util,utilv,tip,id_sucursala,sucursala] + ;
		[ from vgest_centr_inventar]
	lcOrder = [2 desc]
	llAfisare=.F.
	lcgroup = []
	llModParam = .T.
	lcFiltruOriginal = Iif(!Empty(gcCondSucursala), Substr(gcCondSucursala,6)+[ and tip = 5 ], [ tip = 5 ])
	gencursor('poInventare','crsinventare',lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcgroup, llModParam, lcFiltruOriginal)
	poInventare.ca_baza1.afisare()
	loFrmInventare = Createobject('frm_inventar_magazin_centralizator') &&oinventar.vcx
	loFrmInventare.Show(1)
	Use In (Select('crsInventare'))
	Release loFrmInventare,poInventare
Endproc	&&	lista_inventar_magazin
********* SFARSIT: lista_inventar_magazin ***********
********* INCEPUT: vizualizeaza_inventar_magazin ***********
Procedure vizualizeaza_inventar_magazin
	Lparameters tnIdCInventar, tlCorectie
	*** tlCorectie: .T. daca inventarul este validat si se doreste corectarea lui
	LOCAL llCorectie, llNuSuprascrieCod
	llNuSuprascrieCod = .F.
	llCorectie = IIF(PCOUNT() >=2, tlCorectie, .F.)
	
	Private pdDataRef, pdDataInceputInventar, pdDataSfarsitInventar, pnNract, pnNnir, pdDataNotaInventar, pcTextLunaAn, pcTextLunaAnNecompletat, pcChiosc
	*!* 15.06.2010
	PRIVATE pnIdFact, pnCod,pnIdInventar 
	pnCod = 0
	pnIdFact = 0
	pnNract = 0
	pnNnir = 0
	pdDataNotaInventar = {}
	pcTextLunaAn = ''
	pcChiosc = ''
	*!* 15.06.2010 ^
*!*		12.01.2015
	pnIdInventar = tnIdCInventar
*!*		12.01.2015 ^
	pcTextLunaAnNecompletat = ''
		
	Local lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcgroup, llModParam, lcFiltruOriginal
	Local lnValidat, lnTip,lcId_gestiuni,lcDescriere, lnOptiuneInventar, ldDataInventar
	lnValidat = 0
	lnTip = 1
	
	Local llCreareGeneratorNumere
	Private pdDataRef
	llCreareGeneratorNumere = .F.
	If Type('poGeneratorNumere') = 'U'
		Private poGeneratorNumere
		poGeneratorNumere = Createobject('oGeneratorNumere')
		llCreareGeneratorNumere = .T.
	ENDIF
		

	*!* 16.06.2010
	lcSql = "select validat, dataorav, tip, id_gestiuni, descriere, optiuneinventar, numarluni, data_inventar, id_fact, nract, nnir, dataact from VGEST_CENTR_INVENTAR where id_c_inventar=?pnIdInventar"
	*!* 16.06.2010 ^	
	lcCursor = 'crsGestCentrInventarTemp'
	lnSucces = goExecutor.oExecute(m.lcSql, m.lcCursor)
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,"Eroare")
		Return
	ENDIF
	
	*!* 21.12.2011
	*** trebuie act.cod pentru nota de completare din inventarul de corectie
	pnIdFact = NVL(crsGestCentrInventarTemp.id_fact, 0)
	IF m.llCorectie
		lnSucces = goExecutor.oSelect2Value("SELECT MAX(cod) FROM act WHERE an = " + ALLTRIM(STR(m.gnAn)) + " and luna = " + ALLTRIM(STR(m.gnLuna)) + " and id_fact = " + ALLTRIM(STR(m.pnIdFact)), @pnCod)
		IF lnSucces < 0
			amessagebox(goExecutor.cEroare,0+16,"Eroare")
			Return	
		ENDIF 
	ENDIF 	
	*!* 21.12.2011 ^
		
	Select crsGestCentrInventarTemp
	lnValidat = Validat
	lnTip = tip
	lcId_gestiuni = Alltrim(id_gestiuni)
	lcDescriere = Alltrim(descriere)
	lnOptiuneInventar = optiuneinventar
	ldDataInventar = data_inventar
	pdDataRef = data_inventar
	pdDataInceputInventar = data_inventar
	pdDataSfarsitInventar = dataorav
	pnNract = nract
	pnNnir = nnir
	pdDataNotaInventar = TTOD(NVL(dataact,{//::}))
	pcChiosc = ALLTRIM(NVL(descriere,''))
	pcTextLunaAn = 'Luna contabila ' + PADL(allt(str(m.gnLuna)),2, '0') + '/' + allt(str(m.gnAn)) + ;
		' Inventar ' + transform(m.pdDataInceputInventar)+ ;
		IIF(!EMPTY(NVL(m.pdDataSfarsitInventar,{})), ' -  ' + transform(m.pdDataSfarsitInventar), '') + ;
		IIF(!EMPTY(m.lcDescriere), ' | ' + m.lcDescriere , '') + ;		
		IIF(!EMPTY(NVL(m.pnNract, 0)), ' | Nr. doc. ' + alltrim(str(pnNract)),'') + ;
		IIF(!EMPTY(NVL(m.pnNnir,0)), ' | Nr. bon ' + alltrim(str(pnNnir)),'') + ;
		IIF(!EMPTY(NVL(m.pdDataNotaInventar,{})), ' | Data doc. ' + transform(m.pdDataNotaInventar), '')	
	Use In (Select('crsGestCentrInventarTemp'))

	pcTextLunaAnNecompletat = 'Luna contabila ' + PADL(allt(str(m.gnLuna)),2, '0') + '/' + allt(str(m.gnAn)) + ;
		IIF(!EMPTY(m.lcDescriere), ' | ' + m.lcDescriere , '') && fara data inceput inventar si numar/data bon, se poate lista si ulterior, la contabilitate si nu trebuie data generarii inventarului

	
	lcNumeCursor = 'crs_inventar'
	lcSelect = [select * from vgest_inventar]
	lcSchema = []
	lcFiltru= [] && + Iif(glEMama,[ and id_sucursala is null],gcCondSucursala)
	lcOrder = [denumire]
	llAfisare = .F.
	llModParam = .T.
	lcgroup = []
	lcFiltruOriginal = [id_c_inventar = ] + Alltrim(Str(tnIdCInventar))

	If Used(lcNumeCursor)
		Use In &lcNumeCursor
	Endif
	Private podecabaza
	podecabaza = ''
	gencursor('podecabaza',lcNumeCursor,lcSelect, lcFiltru, lcSchema, lcOrder, llAfisare, lcgroup, llModParam, lcFiltruOriginal)
	podecabaza.ca_baza1.afisare()
	gnButon = 2


	lcId_gestiuni = Strtran(lcId_gestiuni,[|],[,])
	If Right(Alltrim(lcId_gestiuni),1) = [,]
		lcId_gestiuni = Left(Alltrim(lcId_gestiuni),Len(Alltrim(lcId_gestiuni))-1)
	Endif
	If Empty(Nvl(lcId_gestiuni,''))
		lcSel = [Select nume_gestiune,id_gestiune from vnom_gestiuni]
	Else
		lcSel = [Select nume_gestiune,id_gestiune from vnom_gestiuni where id_gestiune in (]+lcId_gestiuni +[)]
	Endif

	lcSchema = ['']
	lcCursor = [crs_gest]
	lnSucces = goExecutor.oExecute(lcSel,lcCursor)
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,"Eroare")
	Endif
	Select crs_gest
	lcNume_gest = crs_gest.nume_gestiune
	lnId_gestiune = crs_gest.id_gestiune
	If Used('crs_gest')
		Use In crs_gest
	ENDIF

	*!* 19.04.2010
	update_cote_TVA() && updateserver.prg -> cursorul cote_tva
	*!* 19.04.2010

	Select crs_inventar
	lnid_c_inventar=id_c_inventar


	Scatter Name oinv Blank
	oInventar = Createobject('inventar_stoc_magazin',tnIdCInventar)
	oInventar.ocursor = podecabaza
	oInventar.cnumeCursor = lcNumeCursor
	oInventar.cFiltruOriginal = lcFiltru
	oInventar.lValidat = lnValidat = 1
	oInventar.lCorectie = m.llCorectie
	oInventar.cId_gestiuni = lcId_gestiuni
	oInventar.cNume_gest = lcNume_gest
	oInventar.nId_gestiune = lnId_gestiune
	oInventar.cdescriere = lcDescriere
	oInventar.nOptiuneInventar = lnOptiuneInventar
	oInventar.dDataInventar = ldDataInventar
	oInventar.nCod = m.pnCod
	oInventar.nIdFact = m.pnIdFact
	If lnValidat = 1 AND !m.llCorectie
		oInventar.but_nou1.Visible = .F. && adaugare
		oInventar.but_termin1.Visible = .F.
		oInventar.but_copiaza1.Visible = .F. && copiere
		oInventar.but_stergex.Visible = .F. && stergere
		oInventar.Ct_clb_gestiune.Visible = .F.
		oInventar.Clb_tx_codbare.Visible = .F.
*!*			oInventar.Ct_clb_articol.Visible = .F.
		oInventar._shape3.Visible = .F.
	Endif
	oInventar.Show()


	If  gnButon = 1
	*!* 21.12.2011
*!*			daca rulajele din inventarul de corectie au acelasi cod ca rulajele initiale, nu se pot sterge rulajele daca se sterge nota
*!*			llNuSuprascrieCod = !m.llCorectie
		llNuSuprascrieCod = .F.
	*!* 21.12.2011 ^
		lnSucces = oscrie_in_fisiere(0,.F., .T., m.llNuSuprascrieCod)
		If lnSucces < 0
			If Type([_Screen.nId_tipdoc]) = 'N' And !Empty(_Screen.nid_tipdoc)
				poGeneratorNumere.dezaloca_numar(_Screen.nid_tipdoc)
			Endif
		ELSE
			IF EMPTY(m.pnIdFact)
				*!* 15.06.2010
				pnIdFact = 0
				lnSucces = goExecutor.oFunction2Value("pack_contafin.GET_IDFACT()", @pnIdFact)
				If lnSucces < 0
					amessagebox(goExecutor.cEroare,0+16,"Eroare")
				Endif			
			ENDIF 	

			*!* 21.12.2011
			*			lcSql = [update ] + gcs + [.gest_inventar set validat = 1, dataora_validat = pack_contafin.GET_DATAORA() where data_referinta = ?pdDataRef and stoc_faptic <> cants+cant-cante]
			TEXT TO lcSql NOSHOW
			begin
    			update GEST_CENTR_INVENTAR set validat = 1, id_fact = ?pnIdFact, dataorav = sysdate, id_utilv = ?gnIdUtil where id_c_inventar = ?lnid_c_inventar;
	    		update gest_inventar set validat = 1, dataora_validat = sysdate where id_c_inventar = ?lnid_c_inventar AND validat = 0 ;			
			end;
			ENDTEXT  
*!*				lcSql = [update ] + gcs + [.GEST_CENTR_INVENTAR set validat = 1, id_fact = ?pnIdFact, dataorav = sysdate,id_utilv=?gnIdUtil  where id_c_inventar =?lnid_c_inventar]
			*!* 21.12.2011 ^
			*!* 15.06.2010 ^			
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
			ENDIF
		Endif

		If llCreareGeneratorNumere
			Release poGeneratorNumere
		Endif		
	ENDIF
	*!*	modificare	23.10.2012
	Use In (Select(lcNumeCursor))
	Use In (Select('rul_temp_obinv'))
	*!*	modificare	23.10.2012	^
	*!* 07.09.2009
	USE IN (SELECT('actactan'))
	USE IN (SELECT('rul_temp'))	
	*!* 07.09.2009 ^
	*!* 19.04.2010
	USE IN (SELECT('cote_tva'))
	*!* 19.04.2010 ^	
Endproc	&&	vizualizeaza_inventar_magazin
********* SFARSIT: vizualizeaza_inventar_magazin ***********

*!* 30.10.2008 NIR DEPOZIT
Procedure COMPLETEAZA_ARTICOLE_DEP_NIR
	Parameters tnNract, tdDataact

	Local lcSelect, lcSql, lcCursor, lnSucces, llContinuare
	llContinuare = .T.

	lcSelect = Select()

	lcSql = [SELECT ND.ID, ND.ID_ARTICOL, ND.CODBARE, ND.DENUMIRE, ND.CANTITATE FROM DEP_NIR_DETALII ND JOIN DEP_NIR N ON ND.ID_NIR = N.ID WHERE N.NUMARACT = ?tnNract AND trunc(N.DATAACT) = ?tdDataact AND NVL(ID_ARTICOL,0) = 0]
	lcCursor = [crsArticoleNoiTemp]
	lnSucces = goExecutor.oExecute(lcSql, lcCursor)
	If lnSucces < 0
		amessagebox(goExecutor.cEroare,0+16,'Eroare')
	Else
		If Reccount(lcCursor) > 0
			loFrmArticoleNir = Createobject("frm_articole_noi") && ointroduceri_depozit.vcx
			loFrmArticoleNir.lb_titlu_alb_b121.Caption = "FACTURA " + Alltrim(Str(tnNract)) + " / " + Alltrim(Transform(tdDataact)) + " - Articole noi"
			loFrmArticoleNir.Show(1)
			llContinuare = gnButon = 1
		Endif
	Endif

	If llContinuare
		lcSql = [SELECT COUNT(*) as nr FROM DEP_NIR N WHERE N.NUMARACT = ?tnNract AND trunc(N.DATAACT) = ?tdDataact]
		lcCursor = [crsArticoleCount]
		lnSucces = goExecutor.oExecute(lcSql, lcCursor)
		If lnSucces < 0
			amessagebox(goExecutor.cEroare,0+16,'Eroare')
		Else
			*!* TEMPORAR - PANA II FAC UN SET DISTINCT ???
			If Nvl(crsArticoleCount.nr,0) > 0
				oSet.id_selSt = 30 && vnom_articole_dep_nir
			Endif
			*!* TEMPORAR ^
			Use In (Select(lcCursor))
		Endif
	Endif && llcContinuare
	Select (lcSelect)

Endproc && COMPLETEAZA_ARTICOLE_DEP_NIR
*!* 30.10.2008 ^
