*!*	16.11.2009
*!*	marius.mutu
*!*	RegistruNrInventar, RegNrInvInCurs - export xls
*!* RegNrInvInCurs - conditie sucursala
*!*	ListaImobInCurs - am mutat codul din meniu in procedura

*!* 16.05.2024
*!*	marius.mutu
*!*	list_inchid_amortizari - corectie apel inchidere amortizari - defalcare dupa lucrari

*--------------------------------------------------------------------------------------------------------------
Procedure _old_listare_amortizari_lunare()
	Parameters Tip
	*!*	datain=CTOD('01/'+ALLTRIM(STR(v_luni.nrluna))+'/'+ALLTRIM(v_luni.an))
	*!*	datadela=CTOD("01/"+loluna.nl+"/"+loluna.an)

	*!*	IF Tip=1
	*!*		lcsql = "select * from "+gcS+".imob_vamortizarilunare_mf_c"
	*!*	ELSE
	*!*		lcsql = "select * from "+gcS+".imob_vamortizarilunare_mf_n"
	*!*	ENDIF
	*!*	lnSucces=goExecutor.oExecute(lcsql,'crsamortizarelunara1')
	*!*	*SELECT distinct * FROM crsamortizarelunara1 WHERE ;
	*!*	CTOD('01/'+ALLTRIM(STR(luna))+'/'+ALLTRIM(STR(an)))>=datadela AND ;
	*!*	CTOD('01/'+ALLTRIM(STR(luna))+'/'+ALLTRIM(STR(an)))<=datain INTO CURSOR crsamortizarelunara
	*!*	SELECT DISTINCT * FROM crsamortizarelunara1 WHERE;
	*!*		luna_rata >= datadela AND luna_rata <= datain INTO CURSOR crsamortizarelunara  READWRITE

	*!*	SELECT crsamortizarelunara
	*!*	REPLACE ALL data_exp WITH CTOD('01/'+STR((MONTH(data_pif)+dns_ramas%12)%12)+'/'+STR(( YEAR(data_pif)+ INT( dns_ramas/12 )+INT((MONTH(data_pif)+dns_ramas%12 )/12) )))
	*!*	*brow
	*!*	REPORT FORM amortanaliz_grup TO PRINTER PROMPT PREVIEW
	*!*	goExecutor.oReset()
Endproc
*--------------------------------------------------------------------------------------------------------------
Procedure _old_listare_la_imprimanta()
	Parameters Tip
	*!*	IF tip=1
	*!*	lcsql = "select * from "+gcS+".IMOB_Vlistimprimanta_MF_C"
	*!*	ELSE
	*!*	lcsql = "select * from "+gcS+".IMOB_Vlistimprimanta_MF_N"
	*!*	ENDIF

	*!*	lnSucces=goExecutor.oExecute(lcSql,'crslistmfcota')
	*!*	IF lnSucces<0
	*!*	MESSAGEBOX("Nu a mers SQL-ul")
	*!*	return
	*!*	ENDIF

	*!*	SELECT crslistmfcota
	Select crslista
	Report Form listmfcota To Printer Prompt Preview
	*!* goExecutor.oReset()
Endproc
*------------------------------------------------------------------------------------------------------------
Procedure _old_listare_istoric_amoritizare()
	Parameters Tip
	If Tip = 1
		lcsql = "select * from " + gcS + ".IMOB_VISTAMORTIZARE_MF_c "
	Else
		lcsql = "select * from " + gcS + ".IMOB_VISTAMORTIZARE_MF_N "
	Endif

	lnSucces = goExecutor.oExecute(lcsql, 'crsamortizare')
	If lnSucces < 0
		aMESSAGEBOX(goExecutor.cEroare, 16, "Eroare")
		Return
	Endif
	Select crsamortizare

	*REPLACE ALL data_exp WITH CTOD('01/'+STR((MONTH(luna)+dns_ramas%12)%12)+'/'+STR(( YEAR(luna)+ INT( dns_ramas/12 )+INT((MONTH(luna)+dns_ramas%12 )/12) )))

	Report Form amortizare To Printer Prompt Preview

	goExecutor.oReset()
Endproc

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

Procedure _old_list_corp_general
	list_general(1)
Endproc
*------------------------------------------------------------------------
Procedure _old_list_necorp_general
	list_general(2)
Endproc
*------------------------------------------------------------------------
Procedure _old_list_general && CORPORALE/NECORPORALE     'cu totaluri generale'
	Parameters tnTip
	* tnTip   1) Corp.    2) Necorp
	Private poLista, locauta
	Store '' To poLista
	Store "" To locauta
	Private pnIdGest, pnTip
	pcTitlu = "LISTA IMOBILIZARILOR " + Iif(tnTip = 1, "CORPORALE", "NECORPORALE") + " IN LUNA"
	pnIdGest = 0

	If Pcount() > 0 And Type('tnTip') = 'N'
		pnTip = tnTip
	Else
		pnTip = 1
	Endif

	pcselect = ['select nume_gestiune,id_gestiune FROM vnom_gestiuni where inactiv=0']
	pcfiltru = [1=2]
	pcschema = ['']
	pcorder = [nume_gestiune]
	pccoloane = [nume_gestiune]
	pcTitlu = [Alegeti gestiunea]
	pcTitluColoane = [Gestiune]
	locauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "", .T.)

	If gnButon = 2
		Release locuta
		Return
	Endif

	pcCond = [id_tip_imobilizare = ] + Alltrim(Str(m.pnTip)) + [ and id_tip_operatie <> 4]
	If !Empty(locauta.nume_gestiune) And locauta.id_gestiune <> 0
		pnIdGest = locauta.id_gestiune
		pcCond = pcCond + [ and id_gestiune = ] + Alltrim(Str(pnIdGest))
	Endif

	pdDataI = Date(gnAn, gnLuna, 1)
	pdDataF = pdDataI
	pnFiscala = 0
	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 = 'crslista'

	llExperimental = .T. && 25.11.2021 llExperimental = (goApp.nExperimental = 1)
	If m.llExperimental
		* EXPERIMENTAL SELECTIE DIN IMOB_VSITUATIE_LUNARA IN LOC DE PACK_IMOB.CALCUL_SITUATIE_LUNARA()
		* Setez luna pentru view
		lcFiltru = [id_tip_imobilizare = ] + Alltrim(Str(m.pnTip)) + [ and iesit_din_gest = 0] + Iif(!Empty(m.pnIdGest), [ and id_gestiune = ] + Alltrim(Str(m.pnIdGest)), []) + m.gcCondSucursala
		llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
		If m.llSucces
			lcSel = [SELECT * FROM ] + Iif(m.pnFiscala = 0, [imob_vsituatie_lunara], [imobf_vsituatie_lunara]) + [ WHERE ] + m.lcFiltru
			llSucces = goExecutor.oExecuta(m.lcSel, m.lcCursor)
		Endif
	Else
		lcSel = [{call pack_imob.CALCUL_SITUATIE_LUNARA(?pdDataI,?pdDataF,?pcCond,?pnFiscala,?gnIdSucursala)}]
		llSucces = goExecutor.oExecuta(lcSel, lcCursor)
	Endif

	If m.llSucces
		Select * From crslista Into Cursor crsRap Order By gestiune, data_achizitie
		Report Form listmfcota To Printer Prompt Preview
	Endif


	Release poLista
	Release locauta
	Use In (Select('crslista'))
	Use In (Select('crsRap'))

Endproc
*---------------------------------------------------------------------------
Procedure _old_list_corp_peluni
	list_peluni(1)
Endproc
*------------------------------------------------------------------------
Procedure _old_list_necorp_peluni
	list_peluni(2)
Endproc
*------------------------------------------------------------------------
Procedure _old_list_peluni  && CORPORALE/NECORPORALE      'cu totaluri pe luni'
	Parameters tnTip
	* tnTip   1) Corp.    2) Necorp
	Private poLista, locauta
	Store '' To poLista
	Store "" To locauta
	Private pnIdGest, pnTip
	pnIdGest = 0

	If Pcount() > 0 And Type('tnTip') = 'N'
		pnTip = tnTip
	Else
		pnTip = 1
	Endif

	pcselect = ['select nume_gestiune,id_gestiune FROM vnom_gestiuni where inactiv=0']
	pcfiltru = [1=2]
	pcschema = ['']
	pcorder = [nume_gestiune]
	pccoloane = [nume_gestiune]
	pcTitlu = [Alegeti gestiunea]
	pcTitluColoane = [Gestiune]
	locauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "", .T.)


	If gnButon = 2
		Release locuta
		Return
	Endif


	pcCond = [id_tip_imobilizare = ] + Alltrim(Str(pnTip)) + [ and id_tip_operatie <> 4]
	If !Empty(locauta.nume_gestiune) And locauta.id_gestiune <> 0
		pnIdGest = locauta.id_gestiune
		pcCond = pcCond + [ and id_gestiune = ] + Alltrim(Str(pnIdGest ))
	Endif

	pdDataI = Date(gnAn, gnLuna, 1)
	pdDataF = pdDataI
	pnFiscala = 0
	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 = 'crslista'

	llExperimental = .T. && 25.11.2021 llExperimental = (goApp.nExperimental = 1)
	If m.llExperimental
		* EXPERIMENTAL SELECTIE DIN IMOB_VSITUATIE_LUNARA IN LOC DE PACK_IMOB.CALCUL_SITUATIE_LUNARA()
		* Setez luna pentru view
		lcFiltru = [id_tip_imobilizare = ] + Alltrim(Str(m.pnTip)) + [ and iesit_din_gest = 0] + Iif(!Empty(m.pnIdGest), [ and id_gestiune = ] + Alltrim(Str(m.pnIdGest)), []) + m.gcCondSucursala
		llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
		If m.llSucces
			lcSel = [SELECT * FROM ] + Iif(m.pnFiscala = 0, [imob_vsituatie_lunara], [imobf_vsituatie_lunara]) + [ WHERE ] + m.lcFiltru
			llSucces = goExecutor.oExecuta(m.lcSel, m.lcCursor)
		Endif
	Else
		lcSel = [{call pack_imob.CALCUL_SITUATIE_LUNARA(?pdDataI,?pdDataF,?pcCond,?pnFiscala,?gnIdSucursala)}]
		llSucces = goExecutor.oExecuta(lcSel, lcCursor)
	Endif

	pcTitlu = "LISTA IMOBILIZARILOR " + Iif(tnTip = 1, "CORPORALE", "NECORPORALE") + " IN LUNA"

	If m.llSucces
		Select * From crslista Into Cursor crsRap Order By gestiune, data_pif, Cont
		Report Form listmflunicota To Printer Prompt Preview
	Endif

	Release poLista
	Release locauta
	If Used('crslista')
		Use In crslista
	Endif
	If Used('crsRap')
		Use In crsRap
	Endif

Endproc
*---------------------------------------------------------------------------
Procedure _old_list_corp_pegrup
	list_pegrup(1)
Endproc
*------------------------------------------------------------------------
Procedure _old_list_necorp_pegrup
	list_pegrup(2)
Endproc
*------------------------------------------------------------------------
Procedure _old_list_pegrup  && CORPORALE/NECORPORALE      'cu totaluri pe grupe'

	Parameters tnTip
	* tnTip   1) Corp.    2) Necorp
	Private poLista, locauta
	Store '' To poLista
	Store "" To locauta
	Private pnIdGest, pnTip
	pnIdGest  = 0

	If Pcount() > 0 And Type('tnTip') = 'N'
		pnTip = tnTip
	Else
		pnTip = 1
	Endif

	pcselect = ['select nume_gestiune,id_gestiune FROM vnom_gestiuni where inactiv=0']
	pcfiltru = [1=2]
	pcschema = ['']
	pcorder  = [nume_gestiune]
	pccoloane = [nume_gestiune]
	pcTitlu  = [Alegeti gestiunea]
	pcTitluColoane = [Gestiune]
	locauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "", .T.)

	If gnButon = 2
		Release locuta
		Return
	Endif

	pcCond = [id_tip_imobilizare = ] + Alltrim(Str(pnTip)) + [ and id_tip_operatie <> 4]
	If !Empty(locauta.nume_gestiune) And locauta.id_gestiune <> 0
		pnIdGest = locauta.id_gestiune
		pcCond = pcCond + [ and id_gestiune = ] + Alltrim(Str(pnIdGest ))
	Endif

	pdDataI = Date(gnAn, gnLuna, 1)
	pdDataF = pdDataI
	pnFiscala = 0
	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 = 'crslista'
	pcTitlu = "LISTA IMOBILIZARILOR " + Iif(tnTip = 1, "CORPORALE", "NECORPORALE") + " IN LUNA"

	llExperimental = .T. && 25.11.2021 llExperimental = (goApp.nExperimental = 1)
	If m.llExperimental
		* EXPERIMENTAL SELECTIE DIN IMOB_VSITUATIE_LUNARA IN LOC DE PACK_IMOB.CALCUL_SITUATIE_LUNARA()
		* Setez luna pentru view
		lcFiltru = [id_tip_imobilizare = ] + Alltrim(Str(m.pnTip)) + [ and iesit_din_gest = 0] + Iif(!Empty(m.pnIdGest), [ and id_gestiune = ] + Alltrim(Str(m.pnIdGest)), []) + m.gcCondSucursala
		llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
		If m.llSucces
			lcSel = [SELECT * FROM ] + Iif(m.pnFiscala = 0, [imob_vsituatie_lunara], [imobf_vsituatie_lunara]) + [ WHERE ] + m.lcFiltru
			llSucces = goExecutor.oExecuta(m.lcSel, m.lcCursor)
		Endif
	Else
		lcSel = [{call pack_imob.CALCUL_SITUATIE_LUNARA(?pdDataI,?pdDataF,?pcCond,?pnFiscala,?gnIdSucursala)}]
		llSucces = goExecutor.oExecuta(lcSel, lcCursor)
	Endif

	If m.llSucces
		Select * From crslista Into Cursor crsRap Order By gestiune, Cont
		Report Form listmfscdcota To Printer Prompt Preview
	Endif

	Release poLista
	Release locauta
	If Used('crslista')
		Use In crslista
	Endif
	If Used('crsRap')
		Use In crsRap
	Endif

Endproc
*---------------------------------------------------------------------------
Procedure _old_list_corp_pesectii
	list_pesectii(1)
Endproc
*------------------------------------------------------------------------
Procedure _old_list_necorp_pesectii
	list_pesectii(2)
Endproc
*------------------------------------------------------------------------
Procedure _old_list_pesectii && CORPORALE/NECORPORALE      'cu totaluri pe sectii'
	Parameters tnTip
	* tnTip   1) Corp.    2) Necorp
	Private poLista, locauta
	Store '' To poLista
	Store "" To locauta
	Private pnIdSectie, pnTip
	pnIdSectie = 0

	If Pcount() > 0 And Type('tnTip') = 'N'
		pnTip = tnTip
	Else
		pnTip = 1
	Endif

	pcselect = ['select sectie, id_sectie FROM vnom_sectii where inactiv=0']
	pcfiltru = [1=2]
	pcschema = ['']
	pcorder = [sectie]
	pccoloane = [sectie]
	pcTitlu = [Alegeti sectie]
	pcTitluColoane = [Sectii]
	locauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "", .T.)


	If gnButon = 2
		Release locuta
		Return
	Endif

	pcCond = [id_tip_imobilizare = ] + Alltrim(Str(pnTip)) + [ and id_tip_operatie <> 4]
	If !Empty(locauta.sectie) And locauta.id_sectie <> 0
		pnIdSectie = locauta.id_sectie
		pcCond = pcCond + [ and id_sectie = ] + Alltrim(Str(pnIdSectie))
	Endif

	pdDataI = Date(gnAn, gnLuna, 1)
	pdDataF = pdDataI
	pnFiscala = 0
	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 = 'crslista'
	pcTitlu = "LISTA IMOBILIZARILOR " + Iif(tnTip = 1, "CORPORALE", "NECORPORALE") + " IN LUNA"

	llExperimental = .T. && 25.11.2021 llExperimental = (goApp.nExperimental = 1)
	If m.llExperimental
		* EXPERIMENTAL SELECTIE DIN IMOB_VSITUATIE_LUNARA IN LOC DE PACK_IMOB.CALCUL_SITUATIE_LUNARA()
		* Setez luna pentru view
		lcFiltru = [id_tip_imobilizare = ] + Alltrim(Str(m.pnTip)) + [ and iesit_din_gest = 0] + Iif(!Empty(m.pnIdSectie), [ and id_sectie = ] + Alltrim(Str(m.pnIdSectie)), []) + m.gcCondSucursala
		llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
		If m.llSucces
			lcSel = [SELECT * FROM ] + Iif(m.pnFiscala = 0, [imob_vsituatie_lunara], [imobf_vsituatie_lunara]) + [ WHERE ] + m.lcFiltru
			llSucces = goExecutor.oExecuta(m.lcSel, m.lcCursor)
		Endif
	Else
		lcSel = [{call pack_imob.CALCUL_SITUATIE_LUNARA(?pdDataI,?pdDataF,?pcCond,?pnFiscala,?gnIdSucursala)}]
		llSucces = goExecutor.oExecuta(lcSel, lcCursor)
	Endif

	If m.llSucces
		Select * From crslista Into Cursor crsRap Order By gestiune, Cont, data_pif
		If Reccount('crsRap') > 0
			Private pcDataOra
			pcDataOra = get_ora(2)
			Select crsRap
			Report Form listmf_grup To Printer Prompt Preview
			Release pcDataOra
		Else
			aMESSAGEBOX("Nu exista inregistrari pentru listare!", 48, "Atentie")
		Endif
	Endif

	Release poLista
	Release locauta
	If Used('crslista')
		Use In crslista
	Endif
	If Used('crsRap')
		Use In crsRap
	Endif


Endproc
*---------------------------------------------------------------------------
Procedure lista_fiselor_corp 		&& CORPORALE 'lista fiselor'
	LPARAMETERS tlOperatii
	lnTip = 1 && corporale
	lnFiscala = 0 && amortizare contabila
	llOperatii = m.tlOperatii && standard/cu operatii

	lista_fiselor(m.lnTip, m.lnFiscala, m.llOperatii)
Endproc
*---------------------------------------------------------------------------
Procedure lista_fiselor_necorp  && NECORPORALE 'lista fiselor'
	LPARAMETERS tlOperatii
	lnTip = 2 && necorporale
	lnFiscala = 0 && amortizare contabila
	llOperatii = m.tlOperatii && standard/cu operatii

	lista_fiselor(m.lnTip, m.lnFiscala, m.llOperatii)
Endproc
*---------------------------------------------------------------------------
Procedure lista_fiselor
	Parameters tnTip, tnFiscala, tlOperatii
	****
	* 1) imob.corporale
	* 2) imob.necorporale
	****

	Local lcCursor, lcFiltru, lcSchema, lcSel, llExperimental, llSucces, lnFiscala, llOperatii
	Private pcCond, pdDataF, pdDataI, pnFiscala

	lnFiscala = IIF(!EMPTY(m.tnFiscala), m.tnFiscala, 0)
	llOperatii = IIF(!EMPTY(m.tlOperatii), m.tlOperatii, .F.)
	Use In (Select('crslista'))

	pdDataI = Date(gnAn, gnLuna, 1)
	pdDataF = pdDataI
	pcCond = [1=1]
	pnFiscala = 0
	lcSchema = ['']
	lcCursor = 'crslista'

	llExperimental = .T. && 25.11.2021 llExperimental = (goApp.nExperimental = 1)
	If m.llExperimental
		* EXPERIMENTAL SELECTIE DIN IMOB_VSITUATIE_LUNARA IN LOC DE PACK_IMOB.CALCUL_SITUATIE_LUNARA()
		* Setez luna pentru view
		lcFiltru = [id_tip_imobilizare = ] + Alltrim(Str(m.tnTip)) + [ and iesit_din_gest = 0] + m.gcCondSucursala
		llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
		If m.llSucces
			lcSel = [SELECT * FROM ] + Iif(m.pnFiscala = 0, [imob_vsituatie_lunara], [imobf_vsituatie_lunara]) + [ WHERE ] + m.lcFiltru
			llSucces = goExecutor.oExecuta(m.lcSel, m.lcCursor)
		Endif
	Else
		lcSel = [{call pack_imob.CALCUL_SITUATIE_LUNARA(?pdDataI,?pdDataF,?pcCond,?pnFiscala,?gnIdSucursala)}]
		llSucces = goExecutor.oExecuta(lcSel, lcCursor)
	Endif
	If !m.llSucces
		Return
	Endif

	Select crslista
	Set Filter To id_tip_imobilizare = tnTip And iesit_din_gest = 0
SET STEP ON 
	IF m.llOperatii
		* Jurnal operatii-rate
		lcSql = [select * from ] + Iif(m.lnFiscala = 0, [imob_vjurnal_rate],[imobf_vjurnal_rate]) + [ where id_tip_imobilizare = ] + ALLTRIM(STR(m.tnTip)) + [ order by data_operatie]
		llSucces = goExecutor.oExecuta(m.lcSql, "crsLista2")
		
		SELECT crsLista
		INDEX on id_mf TAG id_mf
		
		SELECT crsLista2
		INDEX on id_mf TAG id_mf
		SET RELATION TO crsLista.id_mf INTO crsLista2 
	ENDIF 	

	lcRaport = IIF(m.llOperatii, IIF(m.tnTip = 1, "fisa_mf_istoric_rate", "fisa_mf2"), IIF(m.tnTip = 1, "fisa_mf_istoric", "fisa_mf2"))
	goExport.export2frx([crslista], "fisa_mf_istoric", , , , , , .T.)

	Use In (SELECT('crsLista'))
	USE IN (SELECT('crsLista2'))
Endproc
*---------------------------------------------------------------------------

*!* Lista de inventar imobilizari corporale model 1 
*!* am inlocuit-o cu DO list_inventar WITH 1,0 IN oproceduri_listari.prg
Procedure lista_inv_m1_c
	lista_inv_m1(1)
Endproc
*---------------------------------------------------------------------------
*!* Lista de inventar imobilizari necorporale model 1 
*!* am inlocuit-o cu DO list_inventar WITH 2,0 IN oproceduri_listari.prg
Procedure lista_inv_m1_n
	lista_inv_m1(2)
Endproc
*---------------------------------------------------------------------------
Procedure lista_inv_m1
	Parameters tnTip
	* tnTip   1) Corp.    2) Necorp
	Private poLista, locauta
	Store '' To poLista
	Store "" To locauta
	Private pnIdGest
	pnIdGest = 0

	pcselect = ['select nume_gestiune,id_gestiune FROM ] + gcS + [.vnom_gestiuni where inactiv=0']
	pcfiltru = [1=2]
	pcschema = ['']
	pcorder = [nume_gestiune]
	pccoloane = [nume_gestiune]
	pcTitlu = [Alegeti gestiunea]
	pcTitluColoane = [Gestiune]
	locauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "", .T.)
	If !Empty(locauta.nume_gestiune)
		lcCondGestiune = [1=1]
		If Alltrim(locauta.nume_gestiune) # [<TOATE INREGISTRARILE>]
			pnIdGest = locauta.id_gestiune
			lcCondGestiune = lcCondGestiune + [ and id_gestiune = ?pnIdGest]
		Endif

		Use In (Select('crslista'))

		pdDataI = Date(gnAn, gnLuna, 1)
		pdDataF = pdDataI
		pcCond = [1=1]
		pnFiscala = 0
		lcSchema = ['']
		lcCursor = 'crslista'

		llExperimental = .T. && 25.11.2021 llExperimental = (goApp.nExperimental = 1)
		If m.llExperimental
			* EXPERIMENTAL SELECTIE DIN IMOB_VSITUATIE_LUNARA IN LOC DE PACK_IMOB.CALCUL_SITUATIE_LUNARA()
			* Setez luna pentru view
			lcFiltru = [id_tip_imobilizare = ] + Alltrim(Str(m.pnTip)) + [ and iesit_din_gest = 0] + Iif(!Empty(m.pnIdGest), [ and id_gestiune = ] + Alltrim(Str(m.pnIdGest)), []) + m.gcCondSucursala
			llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
			If m.llSucces
				lcSel = [SELECT * FROM ] + Iif(m.pnFiscala = 0, [imob_vsituatie_lunara], [imobf_vsituatie_lunara]) + [ WHERE ] + m.lcFiltru
				llSucces = goExecutor.oExecuta(m.lcSel, m.lcCursor)
			Endif
		Else
			lcSel = [{call pack_imob.CALCUL_SITUATIE_LUNARA(?pdDataI,?pdDataF,?pcCond,?pnFiscala,?gnIdSucursala)}]
			llSucces = goExecutor.oExecuta(lcSel, lcCursor)
		Endif

		If !m.llSucces
			Return
		Endif

		Select * From crslista With (Buffering = .T.) Where id_tip_imobilizare = tnTip And iesit_din_gest = 0 And &lcCondGestiune Into Cursor crs_rap Order By gestiune, Cont
		If Used('crsLista')
			Use In crslista
		Endif

		If Reccount('crs_rap') > 0
			Private pcDataOra
			pcDataOra = get_ora(2)
			Select crs_rap
			*	thisform.AlwaysOnTop = .F.
			Report Form listmf_inv To Printer Prompt Preview
			*   thisform.AlwaysOnTop = .T.
			Release pcDataOra
		Else
			aMESSAGEBOX("Nu exista inregistari pentru listare!", 48, "Atentie")
		Endif
		If Used('crslista')
			Use In crslista
		Endif
		If Used('crs_rap')
			Use In crs_rap
		Endif
	Endif

	Release poLista

Endproc
*---------------------------------------------------------------------------
Procedure lista_inv_m2_c
	lista_inv_m2(1)
Endproc
*---------------------------------------------------------------------------
Procedure lista_inv_m2_n
	lista_inv_m2(2)
Endproc
*---------------------------------------------------------------------------
Procedure lista_inv_m2
	Parameters tnTip
	* tnTip   1) Corp.    2) Necorp
	Private poLista, locauta
	Store '' To poLista
	Store "" To locauta
	Private nid_gestiune
	nid_gestiune = 0

	pcselect = ['select nume_gestiune,id_gestiune FROM ] + gcS + [.vnom_gestiuni where inactiv=0']
	pcfiltru = [1=2]
	pcschema = ['']
	pcorder = [nume_gestiune]
	pccoloane = [nume_gestiune]
	pcTitlu = [Alegeti gestiunea]
	pcTitluColoane = [Gestiune]
	locauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "", .T.)
	If !Empty(locauta.nume_gestiune)
		nid_gestiune = locauta.id_gestiune
		pcgestiune = Alltrim(locauta.nume_gestiune)

		pcschema = ['']
		pcselect = ['select * from ] + gcS + [.imob_vjurnal2 where 1=2']
		pcorder = [gestiune,denumire]
		*pcFiltru = [id_tip_imobilizare=?tnTip and iesit_din_gest=0 and id_gestiune=?nid_gestiune]
		pcfiltru = [id_tip_imobilizare=?tnTip and iesit_din_gest=0] + Iif(nid_gestiune = 0, [], [and id_gestiune=?nid_gestiune])
		llAfiseaza = .F.
		gencursor('poLista', 'crslista', pcselect, pcfiltru, pcschema, pcorder, llAfiseaza)
		poLista.ca_baza1.afisare()
		pcTitlu = "LISTA IMOBILIZARILOR " + Iif(tnTip = 1, "CORPORALE", "NECORPORALE") + " IN LUNA"

		If Reccount('crslista') > 0
			Private pcDataOra
			pcDataOra = get_ora(2)
			Select crslista
			*thisform.AlwaysOnTop = .F.
			Report Form nota_inv2005 To Printer Prompt Preview
			Release pcDataOra
			*thisform.AlwaysOnTop = .T.
		Else
			aMESSAGEBOX("Nu exista inregistrari pentru listare!", 48, "Atentie")
		Endif

	Endif
	Release poLista
Endproc
*---------------------------------------------------------------------------

Procedure evidenta_mf && CORPORALE  'Evidenta MF'
	Parameters tnTip
	Private pcDataOra

	Local lcCursor, lcFiltru, lcSchema, lcSel, llExperimental, llSucces
	Private pcCond, pdDataF, pdDataI, pnFiscala
	pcDataOra = []

	pdDataI = Date(gnAn, gnLuna, 1)
	pdDataF = pdDataI
	pcCond = [1=1]
	pnFiscala = 0

	lcSchema = ['']
	lcCursor = 'crslista'

	llExperimental = .T. && 25.11.2021 llExperimental = (goApp.nExperimental = 1)
	If m.llExperimental
		* EXPERIMENTAL SELECTIE DIN IMOB_VSITUATIE_LUNARA IN LOC DE PACK_IMOB.CALCUL_SITUATIE_LUNARA()
		* Setez luna pentru view
		lcFiltru = [id_tip_imobilizare = ] + Alltrim(Str(m.tnTip)) + m.gcCondSucursala
		llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
		If m.llSucces
			lcSel = [SELECT * FROM ] + Iif(m.pnFiscala = 0, [imob_vsituatie_lunara], [imobf_vsituatie_lunara]) + [ WHERE ] + m.lcFiltru
			llSucces = goExecutor.oExecuta(m.lcSel, m.lcCursor)
		Endif
	Else
		lcSel = [{call pack_imob.CALCUL_SITUATIE_LUNARA(?pdDataI,?pdDataF,?pcCond,?pnFiscala,?gnIdSucursala)}]
		llSucces = goExecutor.oExecuta(lcSel, lcCursor)
	Endif

	If !m.llSucces
		Return
	Endif

	Select Cont, Sum(valoare) As valoare, Sum(amort_prec + rata) As amortizare_totala, ;
		Sum(valoare - amort_prec - rata) As valoare_ramasa, Sum(valoare_ramasa) As valoare_justa, ;
		Sum(rata) As rata, Count(*) As numar ;
		From &lcCursor Where id_tip_imobilizare = tnTip And iesit_din_gest = 0 Into Cursor crsevidentamf Group By Cont Order By Cont

	If Used(lcCursor)
		Use In (lcCursor)
	Endif

	*!*	lcsql= " SELECT cont ,sum(valoare) as valoare,sum(amort_prec+rata) as amortizare_totala,"+;
	*!*		" sum(valoare_ramasa-amort_prec-rata) as valoare_ramasa,sum(valoare_ramasa-amort_prec_rata) as ramas_bilant, "+;
	*!*		" sum(rata) as rata,count(*) as numar "+;
	*!*		" FROM "+gcS+".imob_vjurnal2 where id_tip_imobilizare=1 and iesit_din_gest=0 GROUP BY cont ORDER BY cont"
	*!*	lnSucces=goExecutor.oExecute(lcsql,'crsevidentamf')
	*!*	IF lnSucces<0
	*!*		MESSAGEBOX("Nu a mers SQL-ul")
	*!*		RETURN
	*!*	ENDIF
	*STRTOFILE(lcsql,'c:\t.txt')
	If Reccount('crsevidentamf') > 0
		pcDataOra = get_ora(2)
		Select crsevidentamf
		*thisform.AlwaysOnTop = .F.
		* Report Form evidenta_mf To Printer Prompt Preview
		goExport.export2frx('crsevidentamf', "evidenta_mf", , , , , , .T.)
		*thisform.AlwaysOnTop = .T.

		Select crsevidentamf
		If Reccount() > 0
			If aMESSAGEBOX('Doriti sa exportati in format XLS?', 4 + 32, _Screen.Caption) = 6
				export_xls("crsevidentamf", "evidenta MF")
			Endif
		Endif
	Else
		aMESSAGEBOX("Nu exista inregistrari pentru listare!", 48, "Atentie")
	Endif

	Use In (SELECT('crsevidentamf'))

Endproc
*---------------------------------------------------------------------------
Procedure list_inchid_amortizari
	Lparameters tnTip

	Private pcTitlu, pcDataOra
	Local lcCursor, lnLucrare, lnSectie

	pcTitlu = "Raport amortizare lunara " + Iif(tnTip = 1, "imobilizari corporale", "imobilizari necorporale")
	pcDataOra = get_ora(2)

	Local lnTip, lnSectie
	If Empty(tnTip)
		lnTip = 1 && corporale
	Else
		lnTip = tnTip
	Endif

	lnSectie = 0
	*!* 07.05.2007
	*!* optiune inchidere nota amortizare dupa sectie
	If gnNotaImob = 2
		lnSectie = 1
	Else
		*IF gnCampSectie = 1
		If aMESSAGEBOX("Nota de inchidere amortizari se defalca dupa 'Sectie'?", 4 + 32, "Inchidere amortizari") = 6
			lnSectie = 1
		Endif
		*ENDIF
	Endif

	lnLucrare = 0
	IF m.gnCampLucrare = 1 AND AMESSAGEBOX("Inchiderea se face dupa campul 'Lucrare'?", 4 + 32, "Inchidere amortizari") = 6
		lnLucrare = 1
	ENDIF 
	
	lcCursor = GET_CURSOR_INCHIDERE_AMORTIZARI(m.lnTip, m.lnSectie, m.lnLucrare, m.gnAn, m.gnLuna, "crs_inchidere") && oproceduri_comune_imob.prg
	If Used(lcCursor)
		Select (lcCursor)
		Set Filter To suma <> 0
		goExport.export2frx(m.lcCursor, "act", , , , , , .T.)

		Select (lcCursor)
		If Reccount() > 0
			If aMESSAGEBOX('Doriti sa exportati in format XLS?', 4 + 32, _Screen.Caption) = 6
				export_xls(m.lcCursor, m.pcTitlu)
			Endif
		Endif
	Endif

	Use In (Select(lcCursor))

Endproc && list_inchid_amortizari


*----------------------------------------------------
Procedure list_inchid_amortizari_nec

Endproc && list_inchid_amortizari_nec
*-----------------------------------------------------------------------------------
Procedure rulaj_amortizment
	LPARAMETERS tnFiscala
	Private pcfelul

	lcAlias =  sitan(m.tnFiscala) && sitan.prg
	rulaje('amortizare_lunara', lcAlias) && IN sitan.prg

	Select rulaje
	Go Top
	ov = Create('frm_analitice1')
	ov.lb_titlu_alb_b121.Caption = 'SITUATIE ANALITICA - RULAJ AMORTIZMENTE (In anul curent pana in luna curenta)' + IIF(EMPTY(m.tnFiscala), ' CONTABILA', ' FISCALA')
	For i = 3 To ov._grdbase1.ColumnCount
		ov._grdbase1.Columns[i].InputMask = get_mask(14, gnPa)
	Endfor
	ov.Show(1)
	Use In rulaje

Endproc && rulaj_amortizment

*-----------------------------------------------------------------------------------
Procedure total_amortizment
	LPARAMETERS tnFiscala
	Private pcfelul

	lcAlias =  sitan(m.tnFiscala) && sitan.prg
	rulaje('amortizare_totala', lcAlias) && IN sitan.prg

	Select rulaje
	Go Top
	ov = Create('frm_analitice1')
	ov.lb_titlu_alb_b121.Caption = 'SITUATIE ANALITICA - TOTAL AMORTIZMENTE (In anul curent pana in luna curenta)' + IIF(EMPTY(m.tnFiscala), ' CONTABILA', ' FISCALA')
	For i = 3 To ov._grdbase1.ColumnCount
		ov._grdbase1.Columns[i].InputMask = get_mask(14, gnPa)
	Endfor
	ov.Show(1)
	Use In rulaje

Endproc && total_amortizment

***---------------------------------
Procedure list_situatie_lunara
	Parameters tnTip, tnFiscala
	&& tnTip : 1 = corporala, 2 = necorporala
	&& tnFiscala : 0 = contabila, 1 = fiscala

	Do Form rap_situatie_lunara With tnTip, tnFiscala

Endproc && list_situatie_lunara

***---------------------------------
Procedure list_inventar
	Parameters tnTip, tnFiscala
	&& tnTip : 1 = corporala, 2 = necorporala
	&& tnFiscala : 0 = contabila, 1 = fiscala

	Do Form rap_lista_inventar With tnTip, tnFiscala

Endproc && list_inventar

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

Procedure compar_am_contab_fiscal
	Parameters tnTip, tlXLS
	*** tlXLS: .T. = export XLS, .F. (default) = listare

	Local lcCursor, lcSchema, lcSel, llOk, lnSucces, loExcelXML
	*:Global pcCond, pcDataora, pcTitlu, pdDataF, pdDataI, pnFiscala

	pdDataI = Date(gnAn, gnLuna, 1)
	pdDataF = pdDataI
	*pcCond = [id_tip_imobilizare = ] + ALLTRIM(STR(tnTip)) && merge fffff greu
	pcCond = [1=1]
	pnFiscala = 0
	lcCursor = 'crslistaC'
	lcSchema = ['']

	llExperimental = .T. && 25.11.2021 llExperimental = (goApp.nExperimental = 1)
	If m.llExperimental
		* EXPERIMENTAL SELECTIE DIN IMOB_VSITUATIE_LUNARA IN LOC DE PACK_IMOB.CALCUL_SITUATIE_LUNARA()
		* Setez luna pentru view
		lcFiltru = [id_tip_imobilizare = ] + Alltrim(Str(m.tnTip)) + m.gcCondSucursala
		llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
		If m.llSucces
			lcSel = [SELECT * FROM ] + Iif(m.pnFiscala = 0, [imob_vsituatie_lunara], [imobf_vsituatie_lunara]) + [ WHERE ] + m.lcFiltru
			llSucces = goExecutor.oExecuta(m.lcSel, m.lcCursor)
		Endif
	Else
		lcSel = [{call pack_imob.CALCUL_SITUATIE_LUNARA(?pdDataI,?pdDataF,?pcCond,?pnFiscala,?gnIdSucursala)}]
		llSucces = goExecutor.oExecuta(lcSel, lcCursor)
	Endif

	If !m.llSucces
		Return
	Endif

	pnFiscala = 1
	lcSchema = ['']
	lcCursor = 'crslistaF'

	If m.llExperimental
		* EXPERIMENTAL SELECTIE DIN IMOB_VSITUATIE_LUNARA IN LOC DE PACK_IMOB.CALCUL_SITUATIE_LUNARA()
		* Setez luna pentru view
		lcFiltru = [id_tip_imobilizare = ] + Alltrim(Str(m.tnTip)) + m.gcCondSucursala
		llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
		If m.llSucces
			lcSel = [SELECT * FROM ] + Iif(m.pnFiscala = 0, [imob_vsituatie_lunara], [imobf_vsituatie_lunara]) + [ WHERE ] + m.lcFiltru
			llSucces = goExecutor.oExecuta(m.lcSel, m.lcCursor)
		Endif
	Else
		lcSel = [{call pack_imob.CALCUL_SITUATIE_LUNARA(?pdDataI,?pdDataF,?pcCond,?pnFiscala,?gnIdSucursala)}]
		llSucces = goExecutor.oExecuta(lcSel, lcCursor)
	Endif

	If !m.llSucces
		Return
	Endif

	Select c.denumire, c.nr_inventar, c.cod_mf, c.valoare As valoare_c, c.valoare_ramasa As valoare_justa_c, c.rata As rata_c, c.valoare - c.amort_prec - c.rata As valoare_ramasa_c, ;
		F.valoare As valoare_f, F.valoare_ramasa As valoare_justa_f, F.rata As rata_f, F.valoare - F.amort_prec - F.rata As valoare_ramasa_f ;
		From crslistaC c Join crslistaF F On c.id_mf = F.id_mf And c.id_tip_imobilizare = tnTip And F.id_tip_imobilizare = tnTip ;
		Where c.rata <> F.rata Or c.valoare <> F.valoare ;
		Order By c.nr_inventar, c.denumire ;
		Into Cursor crs_list

	pcTitlu = 'Raport diferente dintre amortizarea contabila si cea fiscala'
	If Reccount('crs_list') > 0
		pcDataOra = get_ora(2)
		Select crs_list
		If m.tlXLS
			loExcelXML = Newobject("ExcelXML", "ExcelXML.VCX")
			loExcelXML.SheetName = "Diferente amortizare"
			loExcelXML.OpenAfterSaving = .T.
			llOk = loExcelXML.Save("diferente_amortizare_" + Alltrim(Str(m.gnAn)) + Padl(m.gnLuna, 2, '0') + '.xls')
		Else
			goExport.export2frx([crs_list], "rap_diferente_cf", , , , , , .T.)
		Endif
	Else
		aMESSAGEBOX("Nu exista inregistari pentru listare!", 48, "Atentie")
	Endif

	If Used('crslistaC')
		Use In crslistaC
	Endif
	If Used('crslistaF')
		Use In crslistaF
	Endif
	If Used('crs_list')
		Use In crs_list
	Endif


Endproc && compar_am_contab_fiscal

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

Procedure istoric_operatii
	Parameters tnTip

	pcselect = ['select denumire,nr_pif FROM ] + gcS + [.imob_vnom_mf where inactiv=0 and id_tip_imobilizare = ?tnTip']
	pcfiltru = [1=2]
	pcschema = ['']
	pcorder = [denumire,nr_pif]
	pccoloane = [denumire, nr_pif]
	pcTitlu = [Alegeti MF]
	pcTitluColoane = [Denumire MF, Nr. PIF]
	locauta = cauta_alfa(pcselect, pcfiltru, pcschema, pcorder, pccoloane, pcTitlu, pcTitluColoane, "")

	If Empty(locauta.id_mf)
		Return
	Endif

	pnIdMf = locauta.id_mf

	lcsql = 'SELECT a.denumire, a.nr_pif, a.data_pif, l.nr_inventar, l.cod_mf, ' + ;
		'o.data_operatie, o.denumire as operatie, o.valoare, o.valoare_ramasa, o.dns_ramas,' + ;
		'r.rata, r.data_ultima_rata, r.luna, r.an, r.luna_exp, r.an_exp, r.cota_an, 0 as fiscal ' + ;
		'from imob_vnom_mf join a imob_vultimalista_mf l on a.id_mf = l.id_mf '


	&& neterminat

Endproc && istoric_operatii

***------------------------ INCEPUT: RegistruNrInventar ---------------------------------------
Procedure RegistruNrInventar(tnIdTipImobilizare, tnIesitDinGest)

	Private pcDataOra

	Local lcCursor, lcFiltru, lcSchema, lcSel, llExperimental, llSucces, lnSucces
	Private pcCond, pdDataF, pdDataI, pnFiscala
	Use In (Select('crslista'))


	pdDataI = Date(gnAn, gnLuna, 1)
	pdDataF = m.pdDataI
	pcCond = [1=1]
	pnFiscala = 0
	lcSchema = ['']
	lcCursor = 'crslista'

	llExperimental = .T. && 25.11.2021 llExperimental = (goApp.nExperimental = 1)
	If m.llExperimental
		* EXPERIMENTAL SELECTIE DIN IMOB_VSITUATIE_LUNARA IN LOC DE PACK_IMOB.CALCUL_SITUATIE_LUNARA()
		* Setez luna pentru view
		lcFiltru = [id_tip_imobilizare = ] + Alltrim(Str(m.tnIdTipImobilizare)) + [ and iesit_din_gest = ] + Alltrim(Str(m.tnIesitDinGest)) + m.gcCondSucursala
		llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
		If m.llSucces
			lcSel = [SELECT * FROM ] + Iif(m.pnFiscala = 0, [imob_vsituatie_lunara], [imobf_vsituatie_lunara]) + [ WHERE ] + m.lcFiltru
			llSucces = goExecutor.oExecuta(m.lcSel, m.lcCursor)
		Endif
	Else
		lcSel = [{call pack_imob.CALCUL_SITUATIE_LUNARA(?pdDataI,?pdDataF,?pcCond,?pnFiscala,?gnIdSucursala)}]
	Endif



	lnSucces = goExecutor.oExecute(lcSel, lcCursor)
	If lnSucces < 0
		aMESSAGEBOX(goExecutor.cEroare, 0 + 16, "Eroare")
		Return
	Endif

	Select denumire, cod_mf As codmf, nr_inventar As nrinv, Nvl(gestiune, "") As gestiune, Nvl(sectie, "") As sectie, ;
		Left(Alltrim(cod_mf), 3) As codleft ;
		From crslista ;
		Where id_tip_imobilizare = tnIdTipImobilizare  And iesit_din_gest = tnIesitDinGest ;
		Order By codleft, nrinv ;
		Into Cursor crsRegNrInv

	Use In crslista

	If Reccount('crsRegNrInv') > 0
		pcDataOra = get_ora(2)
		Select crsRegNrInv
		*!*			Report Form reg_nr_inv To Printer Prompt Preview
		goExport.export2frx([crsRegNrInv], [reg_nr_inv], , , , , , .T.)
		If aMESSAGEBOX('Doriti sa exportati in format XLS?', 4 + 32, _Screen.Caption) = 6
			export_xls('crsRegNrInv', 'Registru Numere Inventar')
		Endif
	Else
		aMESSAGEBOX("Nu exista inregistrari pentru listare!", 48, "Atentie")
	Endif

	Use In crsRegNrInv
Endproc && RegistruNrInventar
***======================== SFARSIT: RegistruNrInventar =================================


***------------------------ INCEPUT: ListaImobInCurs ------------------------------------
Procedure ListaImobInCurs
	LPARAMETERS tcGrupare
	* tcGrupare (optional): LUCRARE
	
	PRIVATE pcDataOra, pcGrupDenumire, pcGrupId, pcGrupTitlu
	Local lnOptiune, lcFilter, lcCursor, lcOrder
	poLista = ''
	pcDataOra = ''
	lcOrder = [data_achizitie, nr_inventar]
	
	pcGrupId = '1=1'
	pcGrupTitlu = ''
	pcGrupDenumire = 'nrord'
	If UPPER(TRANSFORM(tcGrupare)) = 'LUCRARE'
		pcGrupId = 'id_lucrare'
		pcGrupTitlu = 'Lucrare'
		pcGrupDenumire = 'nrord'
		lcOrder = [nrord, data_achizitie, nr_inventar]
	ENDIF 		
	
	lcsql = [select id_mf,id_lista_mf,nrord,nract,id_lucrare,id_responsabil,id_gestiune,] + ;
		[id_sectie,data_achizitie,nr_inventar,denumire,explicatia,] + ;
		[valoare, valoare_ramasa, cgest,gestiune,sectie,responsabil,cont,utilizator,dataora,id_operatie_mf ] + ;
		[from imob_vlista_curs ] + Iif(!Empty(gcCondSucursala), [ WHERE ] + Substr(gcCondSucursala, 6), '') + [ ORDER BY ] + m.lcOrder

	lnSucces = goExecutor.oExecute(lcsql, 'crsLista')
	If lnSucces < 0
		aMESSAGEBOX(goExecutor.cEroare, 0 + 64, 'Eroare')
		Return
	Endif
	If Reccount('crslista') > 0
		pcDataOra = get_ora(2)
		Select crslista
		*thisform.AlwaysOnTop = .F.
		*!*			Report Form listimobcurs To Printer Prompt Preview
		goExport.export2frx([crslista], [listimobcurs], , , , , , .T.)
		*thisform.AlwaysOnTop = .T.
	Else
		aMESSAGEBOX("Nu exista inregistrari pentru listare!", 48, "Atentie")
	Endif
	Release pcDataOra
Endproc && ListaImobInCurs
***======================== SFARSIT: ListaImobInCurs ====================================

***------------------------ Inceput: RegNrInvInCurs -------------------------------------
Procedure RegNrInvInCurs

	Private poLista, pcschema, pcselect, pcorder, pcfiltru
	Local llAfiseaza
	Private pcDataOra
	Store '' To poLista

	If Used('crslista')
		Use In crslista
	Endif

	pcschema = ['']
	pcselect = [select id_mf,id_lista_mf,nrord,nract,id_lucrare,id_responsabil,id_gestiune,] + ;
		[id_sectie,data_achizitie,nr_inventar,denumire,explicatia,] + ;
		[valoare,cgest,gestiune,sectie,responsabil,cont,utilizator,dataora,id_operatie_mf ] + ;
		[from ] + gcS + [.imob_vlista_curs where 2=2']
	pcorder = [data_achizitie]
	*!* 16.11.2009
	pcfiltru = [valoare > 0 ]  + Iif(!Empty(gcCondSucursala), gcCondSucursala, '')
	*!* 16.11.2009 ^
	llAfiseaza = .F.
	gencursor('poLista', 'crslista', pcselect, pcfiltru, pcschema, pcorder, llAfiseaza)
	poLista.ca_baza1.afisare()
	Select denumire, "" As codmf, nr_inventar As nrinv, Nvl(gestiune, "") As gestiune, Nvl(sectie, "") As sectie, ;
		"" As codleft ;
		From crslista ;
		Order By codleft, nrinv ;
		Into Cursor crsRegNrInv

	If Used('crslista')
		Use In crslista
	Endif

	If Reccount('crsRegNrInv') > 0
		pcDataOra = get_ora(2)
		Select crsRegNrInv
		*!*			Report Form reg_nr_inv To Printer Prompt Preview
		goExport.export2frx([crsRegNrInv], [reg_nr_inv], , , , , , .T.)
		If aMESSAGEBOX('Doriti sa exportati in format XLS?', 4 + 32, _Screen.Caption) = 6
			export_xls('crsRegNrInv', 'Registru Numere Inventar')
		Endif
	Else
		aMESSAGEBOX("Nu exista inregistrari pentru listare!", 48, "Atentie")
	Endif

	If Used('crsRegNrInv')
		Use In crsRegNrInv
	Endif
Endproc && RegNrInvInCurs
***======================== SFARSIT: RegNrInvInCurs ===================================== 

****************************************************************
* verifica daca exista diferente intre modul standard (pack_imob.calcul_situatie_lunara) si modul experimental (selectie din view imob_vsituatie_lunara) de calcul amortizare 
****************************************************************
Procedure raport_concordanta_experimental
	Lparameters tnIdTipImobilizare

	Private pdDataI, pdDataF, pcCond, pnFiscala
	Local lcsql, lcCursorS, lcCursorE

	Create Cursor cDiferenteImob (id_mf i, nr_inventar i, denumire c(200), amps N(16, 2) Null, ampe N(16, 2) Null, dif1 L, amls N(16, 2) Null, amle N(16, 2) Null, dif2 L, valas N(16, 2) Null, valae N(16, 2) Null, dif3 L, ;
		  valis N(16, 2) Null, valie N(16, 2) Null, dif4 L, valrs N(16, 2) Null, valre N(16, 2) Null, dif5 L, iesits N(1) Null, iesite N(1) Null, dif6 L, dataes D Null, dataee D Null, dif7 L, Tip N(1) Null)

	pdDataI = Date(m.gnAn, m.gnLuna, 1)
	pdDataF = m.pdDataI

	pcCond = [2=2]
	pnFiscala = 0

	* STANDARD
	lcCursorS = 'crsAmortizareStandard'
	lcsql = [{call pack_imob.CALCUL_SITUATIE_LUNARA(?pdDataI,?pdDataF,?pcCond,?pnFiscala,?gnIdSucursala)}]
	llSucces = goExecutor.oExecuta(m.lcsql, m.lcCursorS)


	* EXPERIMENTAL
	lcCursorE = 'crsAmortizareExperimentalTemp'
	llSucces = goExecutor.oExecuta('begin pack_imob.setlunacurenta(?pdDataI); end;')
	If m.llSucces
		lcFiltru = [id_tip_imobilizare = ] + Alltrim(Str(m.tnIdTipImobilizare))
		If !Isnull(m.gnIdSucursala)
			lcFiltru = m.lcFiltru + [ and ID_SUCURSALA = ] + Alltrim(Str(m.gnIdSucursala))
		Endif
		lcsql = [SELECT * FROM ] + Iif(m.pnFiscala = 0, [imob_vsituatie_lunara], [imobf_vsituatie_lunara]) + ' WHERE ' + m.lcFiltru
		llSucces = goExecutor.oExecuta(m.lcsql, m.lcCursorE)
	Endif
	Select *, .F. As verificat From (m.lcCursorE) Into Cursor crsAmortizareExperimental Readwrite

	Select crsAmortizareStandard
	Scan For id_tip_imobilizare = m.tnIdTipImobilizare
		Scatter Name loS

		Select crsAmortizareExperimental
		Locate For id_mf = loS.id_mf
		If Found()
			Scatter Name loE
			Replace verificat With .T.
		Else
			Scatter Name loE Blank
		Endif
		llDif1 = Nvl(loS.amort_prec, 0) <> Nvl(loE.amort_prec, 0)
		llDif2 = Nvl(loS.rata, 0) <> Nvl(loE.rata, 0)
		llDif3 = Nvl(loS.valoare_achizitie, 0) <> Nvl(loE.valoare_achizitie, 0) && valoare achizitie
		llDif4 = Nvl(loS.valoare, 0) <> Nvl(loE.valoare, 0) && valoare inventar
		llDif5 = Nvl(loS.valoare_ramasa, 0) <> Nvl(loE.valoare_ramasa, 0)
		llDif6 = Nvl(loS.iesit_din_gest, 0) <> Nvl(loE.iesit_din_gest, 0)
		llDif7 = Nvl(loS.data_expirare, 0) <> Nvl(loE.data_expirare, 0)
		If (m.llDif1 Or  m.llDif2 Or m.llDif3 Or m.llDif4 Or  m.llDif5 Or m.llDif6 Or m.llDif7)
			Insert Into cDiferenteImob (id_mf, nr_inventar, denumire, amps, ampe, amls, amle, valas, valae, valis, valie, valrs, valre, iesits, iesite, dataes, dataee, Tip, dif1, dif2, dif3, dif4, dif5, dif6, dif7) ;
				Values (loS.id_mf, loS.nr_inventar, loS.denumire, loS.amort_prec, loE.amort_prec, loS.rata, loE.rata, loS.valoare_achizitie, loE.valoare_achizitie, loS.valoare, loE.valoare, loS.valoare_ramasa, loE.valoare_ramasa, ;
				  loS.iesit_din_gest, loE.iesit_din_gest, loS.data_expirare, loE.data_expirare, loS.id_tip_imobilizare, m.llDif1, m.llDif2, m.llDif3, m.llDif4, m.llDif5, m.llDif6, m.llDif7)
		Endif
	Endscan && crsAmortizareStandard

	Insert Into cDiferenteImob (id_mf, nr_inventar, denumire, ampe, amle, valae, valie, valre, iesite, dataee, Tip, dif1, dif2, dif3, dif4, dif5, dif6, dif7) ;
		Select id_mf, nr_inventar, denumire, amort_prec, rata, valoare_achizitie, valoare, valoare_ramasa, iesit_din_gest, data_expirare, id_tip_imobilizare, .T., .T., .T., .T., .T., .T., .T. ;
		From crsAmortizareExperimental Where !verificat

	Use In (Select('crsAmortizareStandard'))
	Use In (Select('crsAmortizareExperimental'))

	Select cDiferenteImob
	Go Top
	If Reccount() = 0
		aMESSAGEBOX('Nu exista diferente intre calcul amortizare standard si experimental', 0 + 64, _Screen.Caption)
	Else
		Browse Title 'Diferente calcul standard - experimental'

		If aMESSAGEBOX('Doriti sa exportati in format XLS?', 4 + 32, _Screen.Caption) = 6
			export_xls('cDiferenteImob', 'Diferente calcul standard - experimental')
		Endif
	Endif
	Use In (Select('cDiferenteImob'))
Endproc && raport_concordanta_experimental

********************************
Procedure list_situatie_reevaluare
	LPARAMETERS tnIdTipImobilizare, tcIds
	* tnIdTipImobilizare: 1=corporale, 2=necorporale, 3=in curs
	* tcIds (optional): lista id_mf separate prin virgula
	
	*!*	Situatia de reevaluari a tuturor imobilizarilor
	*!*	1. Am luat "valoarea de inventar" si "durata ramasa" de la toate operatiile de tip "Reevaluare".
	*!*	2. Am comparat valoarea de inventar noua cu valoarea anterioara. Diferenta am impartit-o la durata ramasa (luni) si a rezultat o "rata".
	*!*	3. Am generat apoi atatea inregistrari pentru "rata" respectiva cate luni ramase au fost la reevaluare.
	*!*	4. Am generat aceasta situatie pentru toate lunile 2003-2020.
	*!*	Primele 2 coloane: an si luna reprezinta luna contabila in care sunt active ratele de majorare (de la luna operatiei de reevaluare pana la numarul de luni ramase).

	*!*	Exemplu: Pentru numarul de inventar 201001, AEROTERMA 15 KW sunt 2 reevaluari:
	*!*	- ianuarie 2004: valoare majorare: 304.07 lei, dns ramas: 72 luni, majorarea se imparte pana in decembrie 2009 (72 luni) in rate de 4.22 lei
	*!*	- decembrie 2006: valoare majorare: 92.76 lei, dns ramas: 36 luni, majorarea se imparte pana in noiembrie 2009 in rate de 2.58 lei
	*!*	ianuarie 2004 - noiembrie 2006: rata de 4.22 lei
	*!*	decembrie 2006 - noiembrie 2009: rata de 4.22 + 2.58 = 6.8 lei
	*!*	decembrie 2009: rata 4.22 lei

	Local lcFileName, lcsql, llSucces, loPerioada, lcSelect
	PRIVATE pnNrLuni1, pnNrLuni2, pcTitlu, pnIdTipImobilizare
	lcSelect = SELECT()
	pnIdTipImobilizare = IIF(!EMPTY(m.tnIdTipImobilizare), m.tnIdTipImobilizare, 1)
	
*!*		AMESSAGEBOX('Alegeti perioada pentru care doriti sa generati raportul!', 0 + 64, _Screen.Caption)
	loPerioada = AlegePerioada()
	If Type('loPerioada') <> 'O'
		Return
	Endif

	pnNrLuni1 = loPerioada.an1 * 12 + loPerioada.luna1
	pnNrLuni2 = loPerioada.an2 * 12 + loPerioada.luna2
	pcTitlu = 'Situatie reevaluari imobilizari ' + IIF(m.pnIdTipImobilizare = 1, 'corporale', 'necorporale') + ' ' + loPerioada.perioada

	lcsql = [select * from imob_vsituatie_reevaluare r] 
	
	IF !EMPTY(m.tcIds)
		lcsql = m.lcSql + [ JOIN (SELECT *  FROM table(cast(CHARN2COLLECTION('] + m.tcIds + [', ',') as num_tab))) i ON r.ID_MF = i.X]
	ENDIF 
	
	lcSql = m.lcSql + [ where r.an*12+r.luna between ?pnNrLuni1 and ?pnNrLuni2 and r.id_tip_imobilizare = ?pnIdTipImobilizare]
	
	llSucces = goExecutor.oExecuta(m.lcsql, "cSituatieReevaluare")
	If m.llSucces
		goExport.export2frx([cSituatieReevaluare], [situatie_reevaluare], , , , , , .T.)	
		
		If AMESSAGEBOX('Doriti sa exportati in format XLS?', 4 + 32, _Screen.Caption) = 6
			lcFileName = 'situatie_reevaluare_' + ALLTRIM(STR(INT(loPerioada.an1))) + PADL(INT(loPerioada.luna1),2,'0') + '_'  + ALLTRIM(STR(INT(loPerioada.an2))) + PADL(INT(loPerioada.luna2),2,'0')
			export_xls('cSituatieReevaluare', m.lcFileName)
		Endif
	Endif
	Use In (Select('cSituatieReevaluare'))
	SELECT (m.lcSelect)
Endproc && list_situatie_reevaluare

********************************
Procedure list_situatie_modificari
	LPARAMETERS tnIdTipImobilizare, tcIds, tnIdTipOperatie
	* tnIdTipImobilizare: 1=corporale, 2=necorporale, 3=in curs
	* tcIds (optional): lista id_mf separate prin virgula
	* tnIdTipOperatie (optional): 0/.F. = toate, 6 = majorare, 7 = reevaluare
	
	*!*	Situatia de majorari a tuturor imobilizarilor
	*!*	1. Am luat "valoarea de inventar" de la toate operatiile de tip "Majorare".
	*!*	2. Valoarea majorare = diferenta dintre valoarea de inventar noua si valoarea anterioara

	Local lcFileName, lcsql, llSucces, loPerioada, lcSelect, lcTipOperatie, lnIdTipOperatie
	PRIVATE pnNrLuni1, pnNrLuni2, pcTitlu, pnIdTipImobilizare
	lcSelect = SELECT()
	pnIdTipImobilizare = IIF(!EMPTY(m.tnIdTipImobilizare), m.tnIdTipImobilizare, 1)
	lnIdTipOperatie = IIF(!EMPTY(m.tnIdTipOperatie), m.tnIdTipOperatie, 0)
	
	lcTipOperatie = ''
	DO CASE 
		CASE m.lnIdTipOperatie = 6
			lcTipOperatie = 'majorare'
		CASE m.lnIdTipOperatie = 7
			lcTipOperatie = 'reevaluare'
	ENDCASE 		
						
*!*		AMESSAGEBOX('Alegeti perioada pentru care doriti sa generati raportul!', 0 + 64, _Screen.Caption)
	loPerioada = AlegePerioada()
	If Type('loPerioada') <> 'O'
		Return
	Endif

	pnNrLuni1 = loPerioada.an1 * 12 + loPerioada.luna1
	pnNrLuni2 = loPerioada.an2 * 12 + loPerioada.luna2
	pcTitlu = 'Situatie operatii ' + IIF(!EMPTY(m.lcTipOperatie), m.lcTipOperatie + ' ', '')  + 'imobilizari ' + IIF(m.pnIdTipImobilizare = 1, 'corporale', 'necorporale') + ' ' + loPerioada.perioada

	lcsql = [select * from imob_vsituatie_modificari r] 
	
	IF !EMPTY(m.tcIds)
		lcsql = m.lcSql + [ JOIN (SELECT *  FROM table(cast(CHARN2COLLECTION('] + m.tcIds + [', ',') as num_tab))) i ON r.ID_MF = i.X]
	ENDIF 
		
	lcSql = m.lcSql + [ where extract(year from r.data_operatie)*12+ extract(month from r.data_operatie) between ?pnNrLuni1 and ?pnNrLuni2 and r.id_tip_imobilizare = ?pnIdTipImobilizare]
	
	IF !EMPTY(m.lnIdTipOperatie)
		lcsql = m.lcSql + [ and r.id_tip_operatie = ] + ALLTRIM(STR(m.lnIdTipOperatie))
	ENDIF 
		
	llSucces = goExecutor.oExecuta(m.lcsql, "cSituatieModificari")
	If m.llSucces
		IF RECCOUNT('cSituatieModificari') > 0
			goExport.export2frx([cSituatieModificari], [situatie_modificari], , , , , , .T.)	
			
			If AMESSAGEBOX('Doriti sa exportati in format XLS?', 4 + 32, _Screen.Caption) = 6
				lcFileName = 'situatie_operatii_' + IIF(!EMPTY(m.lcTipOperatie), m.lcTipOperatie + '_', '') + ALLTRIM(STR(INT(loPerioada.an1))) + PADL(INT(loPerioada.luna1),2,'0') + '_'  + ALLTRIM(STR(INT(loPerioada.an2))) + PADL(INT(loPerioada.luna2),2,'0')
				export_xls('cSituatieModificari', m.lcFileName)
			ENDIF
		ELSE
			AMESSAGEBOX('Nu exista inregistrari pentru aceasta perioada',0+64,_screen.Caption)
		ENDIF 	
	ENDIF && llSucces
	
	Use In (Select('cSituatieModificari'))
	SELECT (m.lcSelect)
Endproc && list_situatie_modificari 