PROCEDURE jurnal
	IF USED('xmf')
		USE IN xmf
	ENDIF
	USE &DATE\mflun ALIAS xmf IN 0 SHARED AGAIN
	SELECT xmf 
*	INDEX ON denumire+ALLTRIM(nrinv)+DTOS(dataora) TAG numeinv OF &LOC\&NFSCURT\TEMPO\mfj
	primadata1=.F.
	PRIVATE pnsuma1,pnsuma2
	STORE 0 TO pnsuma1,pnsuma2
	SELECT xmf
	omisc=CREATEOBJECT('jurnal_nou')
	omisc.gridb1.column5.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column28.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column19.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column20.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column29.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column13.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column15.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column16.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column30.inputmask = get_mask(12,gnZ)
	omisc.SHOW(1)
ENDPROC
*----------------------------------------------
PROCEDURE jurnal_total
	IF USED('xmf')
		USE IN xmf
	ENDIF
	USE &CALEFIRMA\DATEAN\mfanual ALIAS xmf IN 0 SHARED AGAIN
	SELECT xmf 
*	INDEX ON denumire+ALLTRIM(nrinv)+DTOS(dataora) TAG numeinv OF &LOC\&NFSCURT\TEMPO\mfj
	primadata1=.F.
	
	PRIVATE pnsuma1,pnsuma2
	STORE 0 TO pnsuma1,pnsuma2
	
	SELECT xmf
	omisc=CREATEOBJECT('jurnal_nou')
	omisc.titlufrumos1.caption='JURNAL TOTAL'
	omisc.gridb1.column5.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column28.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column19.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column20.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column29.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column13.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column15.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column16.inputmask = get_mask(12,gnZ)
	omisc.gridb1.column30.inputmask = get_mask(12,gnZ)
	omisc.SHOW(1)
ENDPROC
*___________________________________________
PROCEDURE introducere_in_curs
		
	LOCAL lcmax
		
	STORE '' TO m.denumire, m.nrinv, m.numegest, m.respons, m.nrord
	STORE 0 TO m.nract,m.valoare
	STORE DATE() TO dataact
	m.scd=' 231'
	
	SELE mf
		
	CALCULATE MAX(VAL(nrinv)) FOR ALLTRIM(UPPER(fel)) == "C" TO lcmax
	lnmax = lcmax + 1
	m.nrinv = ALLTRIM(STR(lnmax)) 
	
	ov=CREATE('incurs')
	ov.cmdlist2.VISIBLE=.F.
	ov.titlufrumos1.CAPTION='Introducere Imobilizari in Curs'
	ov.text4.inputmask = get_mask(12,gnZ)
	ov.SHOW(1)

	IF buton=2
		RETURN
	ENDIF

	IF EMPTY(m.valoare) OR EMPTY(m.nract) OR EMPTY(m.nrinv)
		DO mesaj WITH 'Nu s-a inregistrat aceasta imobilizare','din lipsa de date.'
		RETURN
	ENDIF
	SELE mf
	m.cod=-1
	APPE BLANK
	IF FLOCK()
		GATHER MEMVAR
		REPLACE fel WITH 'C'
	ENDIF
	UNLOCK

	SELECT mflun
	APPEND BLANK
	IF FLOCK()
		GATHER MEMVAR
		REPLACE explicatia WITH 'Introducere',dataora WITH DATETIME()
		REPLACE codop WITH 2
	ENDIF
	UNLOCK

	SELECT mfanual
	APPEND BLANK
	IF FLOCK()
		GATHER MEMVAR
		REPLACE explicatia WITH 'Introducere',dataora WITH DATETIME()
		REPLACE codop WITH 2
	ENDIF
	UNLOCK

	buton=1
	odanu=CREATEOBJ('danu')
	odanu.SHOW(1)
	IF buton==2
		RETURN
	ELSE
		DO introducere_in_curs
	ENDIF
ENDPROC && introducere_in_curs

*______________________________________________

PROCEDURE preluare_corporale
*!*		SELECT DISTINCT cod, fdoc, dataact, nract, nume, explicatia, scd, ascd, SUMA ;
*!*			FROM act WHERE LEFT(scd, 2) = '21' AND LEFT(scc, 3) # '231' INTO CURSOR actcs
*!*		STORE 1 TO m.tipcalcul

	SELECT mf
	SCATTER MEMVAR BLANK 
	
	SELECT DISTINCT act.cod,act.fdoc,act.dataact,act.nract,act.nume,act.explicatia,act.scd,act.SUMA, 0 as intr ;
		FROM act WHERE LEFT(act.scd,2)='21' AND LEFT(act.scc,3)#'231' AND act.nract#0 INTO CURSOR actcs READWRITE 
		
	IF _tally # 0
		SELECT actcs
		SCAN
			SCATTER NAME oact
			lnVal = 0
			SELECT mf
			SUM valoare FOR EMPTY(fel) AND nract = oact.nract AND dataact = oact.dataact AND scd = oact.scd AND !inactiv TO lnVal
			DO CASE 
				CASE lnVal = 0
					lnIntr = 0
				CASE lnVal = oact.suma
					lnIntr = 1
				CASE lnVal # oact.suma
					lnIntr = 2
			ENDCASE 
			SELECT actcs
			REPLACE intr WITH lnIntr
		ENDSCAN 
	ENDIF  
	
	STORE 1 TO m.tipcalcul
	STORE '' TO nrord
	PRIVATE INTRODUSTOT
	INTRODUSTOT=.F.
	OI=CREATE('frm_preluare')
	OI.FEL_IMOB='C'
	*OI.label10.CAPTION="INTRODUCERE IMOBILIZARI CORPORALE in luna"
	oi.titlufrumos1.CAPTION="INTRODUCERE IMOBILIZARI CORPORALE in luna"
	oi.text4.inputmask = get_mask(12,gnZ)
	oi.grid1.column6.inputmask = get_mask(12,gnZ)
	OI.SHOW(1)
ENDPROC && preluare_corporale

*______________________________________________
PROCEDURE preluare_necorporale
*!*		SELECT DISTINCT cod, fdoc, dataact, nract, nume, explicatia, scd, ascd, SUMA ;
*!*			FROM act WHERE LEFT(scd, 2) = '20' AND LEFT(scc, 3) # '233' INTO CURSOR actcs
*!*		STORE 1 TO m.tipcalcul

	SELECT mf
	SCATTER MEMVAR BLANK 
	SELECT DISTINCT act.cod,act.fdoc,act.dataact,act.nract,act.nume,act.explicatia,act.scd,act.SUMA, 0 as intr ;
	FROM act WHERE LEFT(act.scd,2)='20' AND LEFT(act.scc,3)#'233' AND act.nract#0 INTO CURSOR actcs READWRITE 
	
	IF _tally # 0
		SELECT actcs
		SCAN
			SCATTER NAME oact
			lnVal = 0
			SELECT mf
			SUM valoare FOR fel = 'N' AND nract = oact.nract AND dataact = oact.dataact AND scd = oact.scd AND !inactiv TO lnVal
			DO CASE 
				CASE lnVal = 0
					lnIntr = 0
				CASE lnVal = oact.suma
					lnIntr = 1
				CASE lnVal # oact.suma
					lnIntr = 2
			ENDCASE 
			SELECT actcs
			REPLACE intr WITH lnIntr
		ENDSCAN 
	ENDIF  
	
	STORE 1 TO m.tipcalcul
	PRIVATE INTRODUSTOT
	INTRODUSTOT=.F.
	OI=CREATE('frm_preluare')
	OI.FEL_IMOB='N'
	*OI.label10.CAPTION="INTRODUCERE IMOBILIZARI NECORPORALE in luna"
	oi.titlufrumos1.CAPTION="INTRODUCERE IMOBILIZARI NECORPORALE in luna"
	oi.text4.inputmask = get_mask(12,gnZ)
	oi.grid1.column6.inputmask = get_mask(12,gnZ)
	OI.SHOW(1)
ENDPROC && preluare_necorporale

*______________________________________________

PROCEDURE preluare_incurs
*!*		SELECT DISTINCT cod, fdoc, dataact, nract, nume, explicatia, scd, ascd, SUMA ;
*!*			FROM act WHERE INLIST(LEFT(scd,3),'231','233') INTO CURSOR actcs
	SELECT mf
	SCATTER MEMVAR BLANK 
	SELECT DISTINCT act.cod,act.fdoc,act.dataact,act.nract,act.nume,act.explicatia,act.scd,act.SUMA, 0 as intr ;
		FROM act WHERE INLIST(LEFT(act.scd,3),'231','233') AND act.nract#0 INTO CURSOR actcs READWRITE 
		
	IF _tally # 0
		SELECT actcs
		SCAN
			SCATTER NAME oact
			lnVal = 0
			SELECT mf
			SUM valoare FOR fel = 'C' AND nract = oact.nract AND dataact = oact.dataact AND scd = oact.scd TO lnVal
			DO CASE 
				CASE lnVal = 0
					lnIntr = 0
				CASE lnVal = oact.suma
					lnIntr = 1
				CASE lnVal # oact.suma
					lnIntr = 2
			ENDCASE 
			SELECT actcs
			REPLACE intr WITH lnIntr
		ENDSCAN 
	ENDIF  
	
	M.ID_SECTIE=0		
	PRIVATE INTRODUSTOT
	INTRODUSTOT=.F.
	OI=CREATE('frm_preluare_in_curs')
	*OI.label10.CAPTION="INTRODUCERE IMOBILIZARI IN CURS in luna"
	oi.titlufrumos1.CAPTION="INTRODUCERE IMOBILIZARI IN CURS in luna"
	oi.text4.inputmask = get_mask(12,gnZ)
	oi.grid1.column6.inputmask = get_mask(12,gnZ)
	OI.SHOW(1)
ENDPROC && preluare_incurs

*______________________________________________

PROCEDURE introducere_corporale
	SELECT mf
	SCATTER MEMVAR BLANK 
	
	CALCULATE MAX(VAL(nrinv)) FOR EMPTY(fel) TO lcmax
	lnmax = lcmax+1
	m.nrinv = ALLTRIM(STR(lnmax)) 
	
	STORE 0 TO m.valrez
	STORE 1 TO m.tipcalcul
	PRIVATE M.ID_SECTIE
	STORE '' TO m.id_sectie
	
	opr=CREATEOBJECT('preluare')
	opr.FEL_IMOB='C'
	opr.titlufrumos1.CAPTION="Introducere imobilizari corporale"
	opr.label30.visible=.f.
	opr.optiongroup1.visible=.f.
	opr.text4.inputmask = get_mask(12,gnZ)
	opr.txt15.inputmask = get_mask(12,gnZ)
	opr.text22.inputmask = get_mask(12,gnZ)
	opr.SHOW(1)
ENDPROC  && introducere_corporale

*______________________________________________

PROCEDURE introducere_necorporale
	SELECT mf
	SCATTER MEMVAR BLANK 
	
	CALCULATE MAX(VAL(nrinv)) FOR ALLTRIM(UPPER(fel)) == "N" TO lcmax
	lnmax = lcmax+1
	m.nrinv = ALLTRIM(STR(lnmax))
	
	STORE 0 TO m.valrez
	STORE 1 TO m.tipcalcul
	PRIVATE M.ID_SECTIE
	STORE '' TO m.id_sectie
	
	oprel=CREATEOBJ('preluare')
	oprel.FEL_IMOB='N'
	oprel.titlufrumos1.CAPTION="Introducere imobilizari necorporale"
	oprel.label30.visible=.f.
	oprel.optiongroup1.visible=.f.
	oprel.text4.inputmask = get_mask(12,gnZ)
	oprel.txt15.inputmask = get_mask(12,gnZ)
	oprel.text22.inputmask = get_mask(12,gnZ)
	oprel.SHOW(1)
ENDPROC && introducere_necorporale

*______________________________________________

PROCEDURE viz_corporale
	IF USED('xmf')
		USE IN xmf
	ENDIF
	USE &DATE\mf AGAIN IN 0 SHARED ALIAS xmf
	
	ON ERROR DO a
	IF COMPARTABELE('mf')=.F.
		DO MESAJ WITH 'Reindexati fisierele','<MENU / UTILE / REINDEXARE>'
		*THIS.cmdTERMIN1.CLICK
		RETURN 
	ENDIF
	ON ERROR

	SELECT xmf
	SCATTER MEMVAR BLANK 
	SET FILTER TO fel=" "

	REPLACE ALL dataeval WITH datapif FOR EMPTY(dataeval)
	IF VAL(m.an) >= 2005
		&& din 2005 s-a schimbat programul
		&& pana in 2005 dataeval se schimba abia la calcul_reevaluare => se stergeau reevaluarile cu valin = 0
		REPLACE ALL valin WITH valoare FOR EMPTY(valin) AND dataeval = datapif 
	ENDIF 
	
	SET ORDER TO nrdata
	PRIVATE FELUL,pdata3,pdata4,pnsuma1,pnsuma2,pdata5,pdata6, pnSectie,pnsuma3,pnsuma4, PcNrord
	STORE ' ' TO FELUL, PcNrord
	STORE DATE() TO pdata3,pdata4,pdata5,pdata6,pdata7, pdata8
	STORE 0 TO pnsuma1,pnsuma2, pnSectie,pnsuma3,pnsuma4
	
	PRIVATE pcTitluA
	STORE "CALCUL AMORTIZARE IN LUNA " + ALLTRIM(M.NL) + ' ' + ALLTRIM(M.AN) TO pcTitluA
	
	ov=CREATE('vizP')
	ov.label10.CAPTION="Lista imobilizarilor corporale"
	ov.grid1.column6.inputmask = get_mask(12,gnZ)
	ov.grid1.column26.inputmask = get_mask(12,gnZ)
	ov.grid1.column22.inputmask = get_mask(12,gnZ)
	ov.grid1.column27.inputmask = get_mask(12,gnZ)
	ov.grid1.column24.inputmask = get_mask(12,gnZ)
	ov.grid1.column18.inputmask = get_mask(12,gnZ)
	ov.grid1.column19.inputmask = get_mask(12,gnZ)
	ov.grid1.column29.inputmask = get_mask(12,gnZ)
	ov.grid1.column12.inputmask = get_mask(12,gnZ)
	ov.t3.inputmask = get_mask(14,gnZ)
	ov.text1.inputmask = get_mask(14,gnZ)
	ov.text2.inputmask = get_mask(14,gnZ)
	ov.pcFel = felul
	ov.SHOW(1)

	SELECT mf
	SET ORDER TO TAG dataact
ENDPROC && viz_corporale

*______________________________________________

PROCEDURE viz_necorporale
	IF USED('xmf')
		USE IN xmf
	ENDIF
	USE &DATE\mf AGAIN IN 0 SHARED ALIAS xmf
	
	ON ERROR DO a
	IF COMPARTABELE('mf')=.F.
		DO MESAJ WITH 'Reindexati fisierele','<MENU / UTILE / REINDEXARE>'
		RETURN 
	ENDIF
	ON ERROR

	SELECT xmf
	SCATTER MEMVAR BLANK 
	SET FILTER TO UPPER(fel)="N"
	REPLACE ALL dataeval WITH datapif FOR EMPTY(dataeval)
	IF VAL(m.an) >= 2005
		&& din 2005 s-a schimbat programul
		&& pana in 2005 dataeval se schimba abia la calcul_reevaluare => se stergeau reevaluarile cu valin = 0
		REPLACE ALL valin WITH valoare FOR EMPTY(valin) AND dataeval = datapif 
	ENDIF 
	
	SET ORDER TO nrdata	
*!*		INDEX ON nrinv TAG nrinv OF &LOC\&NFSCURT\TEMPO\xmf
*!*		SET ORDER TO TAG nrinv
	
	PRIVATE FELUL,pdata3,pdata4,pnsuma1,pnsuma2,pdata5,pdata6, pnSectie, PcNrord
	STORE DATE() TO pdata3,pdata4,pdata5,pdata6,pdata7, pdata8
	STORE 0 TO pnsuma1,pnsuma2, pnSectie
	STORE 'N' TO FELUL
	STORE '' TO PcNrord
	
	PRIVATE pcTitluA
	STORE "CALCUL AMORTIZARE IN LUNA " + ALLTRIM(M.NL) + ' ' + ALLTRIM(M.AN) TO pcTitluA
	
	ov=CREATE('vizP')
	ov.label10.CAPTION="Lista imobilizarilor necorporale"
	ov.grid1.column6.inputmask = get_mask(12,gnZ)
	ov.grid1.column26.inputmask = get_mask(12,gnZ)
	ov.grid1.column22.inputmask = get_mask(12,gnZ)
	ov.grid1.column27.inputmask = get_mask(12,gnZ)
	ov.grid1.column24.inputmask = get_mask(12,gnZ)
	ov.grid1.column18.inputmask = get_mask(12,gnZ)
	ov.grid1.column19.inputmask = get_mask(12,gnZ)
	ov.grid1.column29.inputmask = get_mask(12,gnZ)
	ov.grid1.column12.inputmask = get_mask(12,gnZ)
	ov.t3.inputmask = get_mask(14,gnZ)
	ov.text1.inputmask = get_mask(14,gnZ)
	ov.text2.inputmask = get_mask(14,gnZ)
	ov.pcFel = felul
	ov.SHOW(1)

ENDPROC && viz_necorporale

*______________________________________________

PROCEDURE viz_in_curs
	PRIVATE FELUL
	STORE 'C' TO FELUL
	ov=CREATE('vizc')
	ON ERROR DO a
	ov.t3.inputmask = get_mask(14,gnZ)
	ov.grid1.column6.inputmask = get_mask(12,gnZ)
	ov.SHOW(1)
ENDPROC && viz_in_curs

*______________________________________________
PROCEDURE list_corp_general
	DO caut_alf WITH 'Numegest','numegest','NUMELE GESTIUNII','M.NUMEGEST'
	IF buton=2
		RETURN
	ENDIF

	SELE numegest
	LOCATE FOR numegest=m.numegest
	SCATTER MEMVAR

	SET SAFETY OFF
	SELE mf
	IF m.gest=-1
		SET FILTER TO fel=" " AND !CASAT AND !inactiv
	ELSE
		SET FILTER TO gest=m.gest AND fel=" " AND !CASAT AND !inactiv
	ENDIF
	SELECT mf
	INDEX ON DTOS(dataact)+nrinv TAG datapif OF &LOC\&NFSCURT\TEMPO\mfi
	SELE mf
	titlu="Lista imobilizarilor corporale in luna"
	REPORT FORM listmfcota TO PRINTER PROMPT PREVIEW
	DO totv

ENDPROC && list_corp_general

*__________________________________________________________________

PROCEDURE list_corp_peluni

	DO caut_alf WITH 'Numegest','numegest','NUMELE GESTIUNII','M.NUMEGEST'
	IF buton=2
		RETURN
	ENDIF

	SELE numegest
	LOCATE FOR numegest=m.numegest
	SCATTER MEMVAR


	SELE mf
	IF m.gest=-1
		SET FILTER TO fel=" " AND !CASAT AND !inactiv
	ELSE
		SET FILTER TO gest=m.gest AND fel=" " AND !CASAT AND !inactiv
	ENDIF
	titlu="Lista imobilizarilor corporale in luna"
	SELECT mf
	INDEX ON DTOS(datapif)+ALLTRIM(nrinv) TAG datapif OF &LOC\&NFSCURT\TEMPO\mfi
	SELE mf
	REPORT FORM listmfLUNICOTA TO PRINTER PROMPT PREVIEW
	SELECT mf
	SET FILTER TO
	DO totv && list_corp_peluni

	*_____________________________________________________________________________

PROCEDURE list_corp_pegrup
	DO caut_alf WITH 'Numegest','numegest','NUMELE GESTIUNII','M.NUMEGEST'
	IF buton=2
		RETURN
	ENDIF

	SELE numegest
	LOCATE FOR numegest=m.numegest
	SCATTER MEMVAR


	SELE mf
	*USE
	*SELECT 0
	*USE &DATE\MF.DBF EXCLU ALIAS MF
	IF m.gest=-1
		SET FILTER TO fel=" " AND !CASAT AND !inactiv
	ELSE
		SET FILTER TO gest=m.gest AND fel=" " AND !CASAT AND !inactiv
	ENDIF
	titlu="Lista imobilizarilor corporale in luna"
	SELECT mf
	*INDEX ON scd+DTOC(datapif)+nrinv+denumire TAG scdden of &loc\&nfscurt\tempo\mfi ascending
	INDEX ON PADR(scd,4," ")+STR(VAL(nrinv)) TAG SCDNRINV OF &LOC\&NFSCURT\TEMPO\mfi ASCENDING

	SELECT mf
	REPORT FORM listmfSCDCOTA TO PRINTER PROMPT PREVIEW
	*sele mf
	*USE
	*SELECT 0
	*USE &DATE\MF.DBF ALIAS MF
	DO totv
ENDPROC && list_corp_pegrup

*__________________________________________________________________________________________

PROCEDURE list_necorp_general
	DO caut_alf WITH 'Numegest','numegest','NUMELE GESTIUNII','M.NUMEGEST'
	IF buton=2
		RETURN
	ENDIF

	SELE numegest
	LOCATE FOR numegest=m.numegest
	SCATTER MEMVAR

	SET SAFETY OFF
	SELE mf
	*USE
	*SELECT 0
	*USE &DATE\MF.DBF EXCLU ALIAS MF
	IF m.gest=-1
		SET FILTER TO UPPER(fel)="N" AND !CASAT AND !inactiv
	ELSE
		SET FILTER TO gest=m.gest AND UPPER(fel)="N" AND !CASAT AND !inactiv
	ENDIF
	INDEX ON DTOS(dataact)+nrinv TAG datapif OF &LOC\&NFSCURT\TEMPO\mfi
	SELE mf
	titlu="Lista imobilizarilor necorporale in luna"

	REPORT FORM listmfcota TO PRINTER PROMPT PREVIEW
	*sele mf
	*USE
	*SELECT 0
	*USE &DATE\MF.DBF ALIAS MF
	DO totv
ENDPROC && list_necorp_general

*_________________________________________________________________________

PROCEDURE list_necorp_pegrup
	DO caut_alf WITH 'Numegest','numegest','NUMELE GESTIUNII','M.NUMEGEST'
	IF buton=2
		RETURN
	ENDIF

	SELE numegest
	LOCATE FOR numegest=m.numegest
	SCATTER MEMVAR


	SELE mf
	*USE
	*SELECT 0
	*USE &DATE\MF.DBF EXCLU ALIAS MF
	IF m.gest=-1
		SET FILTER TO UPPER(fel)="N" AND !CASAT AND !inactiv
	ELSE
		SET FILTER TO gest=m.gest AND UPPER(fel)="N" AND !CASAT AND !inactiv
	ENDIF

	*INDEX ON scd+DTOC(dataact)+denumire TAG scdden of &loc\&nfscurt\tempo\mfi ascending
	*INDEX ON SCD+ALLTRIM(nrinv)+DTOS(DATAact) TAG DATAPIF of &loc\&nfscurt\tempo\mfi
	INDEX ON PADR(scd,4," ")+STR(VAL(nrinv)) TAG SCDNRINV OF &LOC\&NFSCURT\TEMPO\mfi ASCENDING

	SELE mf
	titlu="Lista imobilizarilor necorporale in luna"
	REPORT FORM listmfSCDCOTA TO PRINTER PROMPT PREVIEW
	*sele mf
	*USE
	*SELECT 0
	*USE &DATE\MF.DBF ALIAS MF
	DO totv

ENDPROC && list_necorp_pegrup

*_________________________________________________________________________

PROCEDURE list_necorp_peluni
	DO caut_alf WITH 'Numegest','numegest','NUMELE GESTIUNII','M.NUMEGEST'
	IF buton=2
		RETURN
	ENDIF

	SELE numegest
	LOCATE FOR numegest=m.numegest
	SCATTER MEMVAR


	SELE mf
	*USE
	*SELECT 0
	*USE &DATE\MF.DBF EXCLU ALIAS MF
	IF m.gest=-1
		SET FILTER TO UPPER(fel)="N" AND !CASAT AND !inactiv
	ELSE
		SET FILTER TO gest=m.gest AND UPPER(fel)="N" AND !CASAT AND !inactiv
	ENDIF
	*INDEX ON DTOC(DATAPIF)+SCD TAG DATAPIF of &loc\&nfscurt\tempo\mfi
	INDEX ON DTOS(datapif)+nrinv TAG datapif OF &LOC\&NFSCURT\TEMPO\mfi
	SELE mf
	titlu="Lista imobilizarilor necorporale in luna"
	REPORT FORM listmfLUNICOTA TO PRINTER PROMPT PREVIEW
	*sele mf
	*USE
	*SELECT 0
	*USE &DATE\MF.DBF ALIAS MF
	SELECT mf
	SET FILTER TO
	DO totv

ENDPROC && list_necorp_peluni

*_________________________________________________________________________

PROCEDURE list_incurs
	SELECT mf
	SET FILTER TO UPPER(fel)="C" AND !CASAT AND !inactiv
	*INDEX ON ALLTRIM(nrinv)+DTOS(dataact) TAG datapif of &loc\&nfscurt\tempo\mfi
	INDEX ON PADR(scd,4," ")+STR(VAL(nrinv)) TAG SCDNRINV OF &LOC\&NFSCURT\TEMPO\mfi ASCENDING
	REPORT FORM listimobcurs TO PRINTER PROMPT PREVIEW

ENDPROC && list_incurs

*_________________________________________________________________________

PROCEDURE lista_fiselor_corp
	SELE mf
	SET FILTER TO fel=' ' AND !inactiv && and !casat
	REPORT FORM fisa_mf2 TO PRINTER PROMPT PREVIEW
	SELECT mf
	SET FILTER TO
ENDPROC && lista_fiselor_corp

*_________________________________________________________________________

PROCEDURE lista_fiselor_corp_istoric
	select *, 00000000000000 AS amortlunv from mf WHERE fel = ' ' AND !inactiv into cursor qry_mf READWRITE 
*	ALTER TABLE qry_mf ADD COLUMN amortlunv n(14)
	
	IF USED('mfold')
		USE IN mfold
	ENDIF 
	
	SELECT qry_mf
	SCAN FOR dataeval # datapif AND !EMPTY(dataeval)
		SCATTER NAME omf 
		lcnl=ALLTRIM(STR(MONTH(dataeval)))
		IF LEN(lcnl) = 1
			lcnl = '0' + lcnl
		ENDIF 
		lcAn=ALLTRIM(STR(YEAR(dataeval)))
		lcdate='&calefirma\an'+lcAn+'\date'+lcNl+'\mf.dbf'
		IF FILE(lcDate)
			USE &lcDate IN 0 ALIAS mfold SHARED 
			SELECT mfold
			LOCATE FOR UPPER(ALLTRIM(denumire))=UPPER(ALLTRIM(omf.denumire)) AND datapif=omf.datapif AND nrpif=omf.nrpif
			IF FOUND()
				lnAmortLun = amortlun
				SELECT qry_mf
				REPLACE amortlunv WITH lnAmortlun
			ENDIF 
			USE IN mfold 
		ENDIF 
		RELEASE omf 
		SELECT qry_mf
	ENDSCAN 
	
	SELE qry_mf
	REPORT FORM fisa_mf_istoric TO PRINTER PROMPT PREVIEW
	USE IN qry_mf
ENDPROC && lista_fiselor_corp_istoric 
*_________________________________________________________________________

PROCEDURE lista_fiselor_necorp
	SELE mf
	SET FILTER TO UPPER(fel)='N' AND !inactiv && and !casat
	REPORT FORM fisa_mf2 TO PRINTER PROMPT PREVIEW
	SELECT mf
	SET FILTER TO
ENDPROC && lista_fiselor_necorp

*_________________________________________________________________________

PROCEDURE rulaj_amortizment
	PRIVATE pcfelul
	pcfelul=[' ','N']
	
	lcAlias =  sitan() && sitan.prg
	lcCaleFis = rulaje('amortlun',lcAlias) && IN sitan.prg
	
	IF EMPTY(lcCaleFis)
		RETURN
	ENDIF 
	
	USE (lcCaleFis) IN 0 ALIAS rulaje
	SELECT rulaje
	ov=CREATE('sit')
	ov.TITLU1.CAPTION='SITUATIE ANALITICA - RULAJ AMORTIZMENTE (In anul curent pana in luna curenta)'
	ov.SHOW(1)
	USE IN rulaje

ENDPROC && rulaj_amortizment

*_________________________________________________________________________

PROCEDURE total_amortizment
	PRIVATE pcfelul
	pcfelul=[' ','N']

	lcAlias =  sitan() && sitan.prg
	lcCaleFis = rulaje('amorttot',lcAlias) && IN sitan.prg
	
	IF EMPTY(lcCaleFis)
		RETURN
	ENDIF 
	
	USE (lcCaleFis) IN 0 ALIAS rulaje

	ov=CREATE('sit')
	ov.TITLU1.CAPTION='SITUATIE ANALITICA - TOTAL AMORTIZMENTE (In anul curent pana in luna curenta)'
	ov.SHOW(1)
	USE IN rulaje

ENDPROC && total_amortizment

*_________________________________________________________________________
PROCEDURE list_inchid_amortizari

ldDATAACT=GOMONTH(CTOD('01/'+m.nl+'/'+m.AN),1)-1

buton=1
od=Create('danu')
od.label1.Caption=[Se calculeaza inchiderea dupa sectie?]
od.Show(1)
If buton = 2
	plCampSectie = .F.
Else
	plCampSectie = .T.
ENDIF

IF !USED('plcont')
	USE &CALEFIRMA\DATEAN\plcont IN 0 SHARED ALIAS plcont 
ENDIF 

SELECT DISTINCT sectie, id_sectie FROM sectie INTO CURSOR crsSectie

IF plCampSectie
	SELECT ldDATAACT as dataact, i.SCD, '281' + SUBSTR(i.scd,3,1) AS SCC, SUM(i.amortlun) as suma, i.id_sectie, NVL(p.cimp2,SPACE(30)) as nume_2, NVL(s.sectie,SPACE(30)) as sectie ;
	FROM mf i ;
	LEFT JOIN plcont p ON i.scd = p.cimp1 ; 
	LEFT JOIN crsSectie s ON i.id_sectie = s.id_sectie ;
	WHERE ALLTRIM(i.FEL)=[] AND !i.CASAT AND !i.inactiv;
	INTO CURSOR tinchid READWRITE ;
	GROUP BY i.scd, i.ascd, i.id_sectie

ELSE 
	SELECT ldDATAACT as dataact, i.SCD, '281' + SUBSTR(i.scd,3,1) AS SCC, SUM(i.amortlun) as suma, NVL(p.cimp2,SPACE(30)) as nume_2, SPACE(30) as sectie ;
	FROM mf i ;
	LEFT JOIN plcont p ON i.scd = p.cimp1 ; 
	WHERE ALLTRIM(i.FEL)=[] AND !i.CASAT AND !i.inactiv;
	INTO CURSOR tinchid READWRITE ;
	GROUP BY i.scd, i.ascd
ENDIF 

pcTitlu = [INCHIDERE AMORTIZARE - IMOBILIZARI CORPORALE]
SELECT tinchid
REPLACE ALL scd WITH [6811]
REPORT FORM act TO PRINTER PROMPT PREVIEW 
IF USED('tinchid')
	USE IN tinchid
ENDIF 
IF USED('crsSectie')
	USE IN crsSectie
ENDIF 
IF USED('plcont')
	USE IN plcont
ENDIF 

ENDPROC && list_inchid_amortizari

*----------------------------------------------------
PROCEDURE list_inchid_amortizari_nec


ldDATAACT=GOMONTH(CTOD('01/'+m.nl+'/'+m.AN),1)-1

buton=1
od=Create('danu')
od.label1.Caption=[Se calculeaza inchiderea dupa sectie?]
od.Show(1)
If buton = 2
	plCampSectie = .F.
Else
	plCampSectie = .T.
ENDIF

IF !USED('plcont')
	USE &CALEFIRMA\DATEAN\plcont IN 0 SHARED ALIAS plcont 
ENDIF 

SELECT DISTINCT sectie, id_sectie FROM sectie INTO CURSOR crsSectie

IF plCampSectie
	SELECT ldDATAACT as dataact, i.SCD, '280' + SUBSTR(i.scd,3,1) AS SCC, SUM(i.amortlun) as suma, i.id_sectie, NVL(p.cimp2,SPACE(30)) as nume_2, NVL(s.sectie,SPACE(30)) as sectie ;
	FROM mf i ;
	LEFT JOIN plcont p ON i.scd = p.cimp1 ; 
	LEFT JOIN crsSectie s ON i.id_sectie = s.id_sectie ;
	WHERE ALLTRIM(UPPER(i.FEL))=[N] AND !i.CASAT AND !i.inactiv;
	INTO CURSOR tinchid READWRITE ;
	GROUP BY i.scd, i.ascd, i.id_sectie

ELSE 
	SELECT ldDATAACT as dataact, i.SCD, '280' + SUBSTR(i.scd,3,1) AS SCC, SUM(i.amortlun) as suma, NVL(p.cimp2,SPACE(30)) as nume_2, SPACE(30) as sectie ;
	FROM mf i ;
	LEFT JOIN plcont p ON i.scd = p.cimp1 ; 
	WHERE ALLTRIM(UPPER(i.FEL))=[N] AND !i.CASAT AND !i.inactiv;
	INTO CURSOR tinchid READWRITE ;
	GROUP BY i.scd, i.ascd
ENDIF 

pcTitlu = [INCHIDERE AMORTIZARE - IMOBILIZARI NECORPORALE]
SELECT tinchid
REPLACE ALL scd WITH [6811]
REPORT FORM act TO PRINTER PROMPT PREVIEW 
IF USED('tinchid')
	USE IN tinchid
ENDIF 
IF USED('crsSectie')
	USE IN crsSectie
ENDIF 
IF USED('plcont')
	USE IN plcont
ENDIF 

ENDPROC && list_inchid_amortizari_nec


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

PROCEDURE list_amort_tot

SELECT xmf
SCATTER NAME omf

pcNl=m.nl
pcAn=m.an

loLuna=ret_luna("Selectati luna de inceput")
lddata1=Ctod('01/'+loLuna.nl+'/'+loLuna.an) && 01/01/2003
lddata2=Ctod('01/'+pcNl+'/'+pcAn)       	&& 01/07/2003- luna contabila curenta

SELECT m.*, SPACE(4) as an, SPACE(2) as nl from mf m WHERE 1=2 INTO CURSOR mfsel READWRITE 

SELECT an,nl FROM calendar INTO CURSOR tcalendar

SELECT tcalendar
SCAN FOR Ctod('01/'+nl+'/'+an)>=lddata1 AND Ctod('01/'+nl+'/'+an)<=lddata2
	lcnl=nl
	lcAn=an
		lcdate='&calefirma\an'+lcAn+'\date'+lcNl+'\mf.dbf'
		IF FILE(lcDate)
			SELECT mfsel
			APPEND FROM &lcDate FOR UPPER(ALLTRIM(denumire))=UPPER(ALLTRIM(omf.denumire)) ;
			AND datapif=omf.datapif AND nrpif=omf.nrpif AND !inactiv
			REPLACE an WITH lcan,nl WITH lcnl
		ENDIF 
	SELECT tcalendar
ENDSCAN

SELECT mfsel 
REPORT FORM amortanaliz2 TO PRINTER PROMPT PREVIEW 
m.nl=pcNl
m.an=pcAn

RELEASE omf
IF USED('mfsel' )
	USE IN mfsel 
ENDIF 
IF USED('tcalendar')
	USE IN tcalendar 
ENDIF 

ENDPROC 

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

PROCEDURE initializ_jurnal

*!*	SELECT mf
*!*	SCAN FOR normat2lun # 0 OR normat2 # 0 AND !casat

*!*		SCATTER NAME omf
*!*		
*!*	*!*		SELECT mflun
*!*	*!*		IF FLOCK()
*!*	*!*			APPEND BLANK
*!*	*!*			GATHER NAME omf
*!*	*!*			REPLACE explicatia WITH 'Introdus',dataora WITH DATETIME(),util WITH m.util
*!*	*!*			REPLACE codop WITH 99
*!*	*!*		ENDIF
*!*	*!*		UNLOCK

*!*	*!*		SELECT MFANUAL
*!*	*!*		IF FLOCK()
*!*	*!*			APPEND BLANK
*!*	*!*			GATHER NAME omf
*!*	*!*			REPLACE explicatia WITH 'Introdus',dataora WITH DATETIME(),util WITH m.util
*!*	*!*			REPLACE codop WITH 99
*!*	*!*		ENDIF
*!*	*!*		UNLOCK
*!*		
*!*		*SELECT mf
*!*		REPLACE normat WITH normat2lun, normaan WITH normat2, normat2 WITH 0, normat2lun WITH 0
*!*		SCATTER NAME omf
*!*		
*!*		SELECT mflun
*!*		IF FLOCK()
*!*			APPEND BLANK
*!*			GATHER NAME omf
*!*			REPLACE explicatia WITH 'Transformare DNS',dataora WITH DATETIME(),util WITH m.util
*!*			REPLACE codop WITH 99
*!*		ENDIF
*!*		UNLOCK

*!*		SELECT MFANUAL
*!*		IF FLOCK()
*!*			APPEND BLANK
*!*			GATHER NAME omf
*!*			REPLACE explicatia WITH 'Transformare DNS',dataora WITH DATETIME(),util WITH m.util
*!*			REPLACE codop WITH 99
*!*		ENDIF
*!*		UNLOCK

*!*	SELECT mf
*!*	ENDSCAN 

*!*	DO mesaj WITH 'Transformarea s-a incheiat !',''
ENDPROC 

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

PROCEDURE evidenta_mf

SELECT scd,sum(valin) as valin,sum(amorttot) as amorttot,sum(valramasa) as valramasa, ;
sum(valin-amorttot) as valramb,sum(valrez) as valrez, sum(amortlun) as amortlun,count(*) as numar ;
FROM mf ;
WHERE !casat AND fel=' ' AND !inactiv;
GROUP BY scd INTO CURSOR tevidenta ORDER BY scd

SELECT tevidenta
REPORT FORM evidenta_mf TO PRINTER PROMPT PREVIEW 

USE IN tevidenta

ENDPROC 
****-----------------------------------------------------------------

PROCEDURE lista_invn

PRIVATE pddata

ldatacrt = "01/" + m.nl + "/" + m.an 
	ldata=GOMONTH(CTOD(ldatacrt),1)
	dataref=ldata-1
	datarefi = dataref
	ooo=CREATEOBJECT("cautintre")
	ooo.text1.controlsource='dataref'
	ooo.label1.caption='Data de referinta:'
	ooo.text2.visible=.f.
	ooo.label2.visible=.f.
	ooo.show(1)

pddata = dataref 	
	
SELECT * from mf WHERE !casat AND !inactiv INTO CURSOR cLista
SELECT cLista 
REPORT FORM nota_inv2005 TO PRINTER PROMPT PREVIEW 
IF USED("cLista")
	USE IN cLista
ENDIF 
ENDPROC && lista_invn

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

PROCEDURE list_amort_tot_nou
PARAMETERS tcFis

lcFis = ALLTRIM(tcFis)
pcNl=m.nl
pcAn=m.an

loLuna=ret_luna("Selectati luna de inceput")
lddata1=Ctod('01/'+loLuna.nl+'/'+loLuna.an) && 01/01/2003
lddata2=Ctod('01/'+pcNl+'/'+pcAn)       	&& 01/07/2003- luna contabila curenta

pcTitluA = 'EVIDENTA MIJLOACE FIXE - RAPORT PENTRU PERIOADA ' + loLuna.nl+'.'+loLuna.an + ' - ' + pcNl+'.'+pcAn
DO FORM frm_introd_titlu


SELECT m.*, SPACE(4) as an, SPACE(2) as nl, ;
0000000000000000 as majorare, 00000000000 as id_mf  ;
from (lcFis) m WHERE 1=2 INTO CURSOR mfsel READWRITE 
SELECT an,nl FROM calendar INTO CURSOR tcalendar

LOCAL i
i = 0
SELECT (lcFis)
SCAN 
	SCATTER NAME omf
	i = i + 1
	SELECT tcalendar
	SCAN FOR Ctod('01/'+nl+'/'+an)>=lddata1 AND Ctod('01/'+nl+'/'+an)<=lddata2
		lcnl = nl
		lcAn = an
		lcdate = '&calefirma\an' + lcAn + '\date' + lcNl + '\mf.dbf'
		IF FILE(lcDate)
			SELECT mfsel
			APPEND FROM &lcDate ;
			FOR UPPER(ALLTRIM(denumire)) = UPPER(ALLTRIM(omf.denumire)) ;
			AND datapif = omf.datapif AND nrpif = omf.nrpif AND !inactiv
			REPLACE an WITH lcan, nl WITH lcnl, id_mf WITH i FOR EMPTY(an) AND EMPTY(nl) AND EMPTY(id_mf) AND UPPER(ALLTRIM(denumire)) = UPPER(ALLTRIM(omf.denumire)) AND datapif = omf.datapif AND nrpif = omf.nrpif
		ENDIF 
		SELECT tcalendar
	ENDSCAN
	SELECT (lcFis)
ENDSCAN 
RELEASE omf

lnNumarDeMf = i


FOR i = 1 TO lnNumarDeMf
	j = 0
	lnMajorare = 0 
	SELECT mfsel
	SCAN FOR id_mf = i
		j = j + 1
		IF j = 1
			lnMajorare = valin
		ELSE 
			REPLACE majorare WITH valin - lnMajorare
			lnMajorare = valin
		ENDIF 
	ENDSCAN 
ENDFOR 


SELECT mfsel 			
REPORT FORM amortanaliz_grup TO PRINTER PROMPT PREVIEW 
m.nl=pcNl
m.an=pcAn


IF USED('mfsel' )
	USE IN mfsel 
ENDIF 
IF USED('tcalendar')
	USE IN tcalendar 
ENDIF 

ENDPROC 

*_____________________________________________________________________________

PROCEDURE list_corp_peSECTII
PARAMETERS tcFel

	IF TYPE('tcFel') # 'C' 
		lcFel = []
	ELSE 
		lcFel = UPPER(ALLTRIM(tcFel))
	ENDIF 

	SELECT * from sectie INTO CURSOR tsectie READWRITE ORDER BY sectie, id_sectie
	
	SELECT tsectie 
	APPEND BLANK 
	REPLACE sectie WITH [<TOATE SECTIILE>], id_sectie WITH [-1]
	
	PRIVATE pcSectie 
	STORE [] TO pcSectie 
	locauta = caut_alfa_cursor('TSECTIE','SECTIE','NUMELE SECTIEI')

	IF buton=2 
		RETURN
	ENDIF
	
	IF ALLTRIM(locauta.ID_SECTIE) = [-1] AND ALLTRIM(locauta.sectie) = [<TOATE SECTIILE>]
		lcCond = [.t.]
	ELSE
		lcCond = [id_sectie = locauta.id_SECTIE]
	ENDIF
	
	SELECT * ;
	from mf ;
	WHERE UPPER(ALLTRIM(fel))= lcFel AND !CASAT AND !inactiv AND &lcCond INTO CURSOR tmf ORDER BY scd, id_sectie

	IF lcFel = [N]	
		titlu="Lista imobilizarilor necorporale in luna"
	ELSE 
		titlu="Lista imobilizarilor corporale in luna"
	ENDIF 
	pcGrup1 = [scd]
	pcHeaderGrup1 = [Cont]
	pcGrup2 = [id_sectie]
	pcHeaderGrup2 = [sectie]
	
	SELECT tmf
	REPORT FORM ListMf_Grup TO PRINTER PROMPT PREVIEW
	
	IF USED('tmf')
		USE IN tmf
	ENDIF 
	IF USED('tsectie')
		USE IN tsectie
	ENDIF 
	
ENDPROC && list_corp_peSectii