*
Procedure redeschid_luna
PARAMETERS tcAn, tcLuna
	Local lunatrec,antrec,lcLuna,lcAn,dattrec,datcrt
	Set Safety Off
	
	IF EMPTY(tcAn) OR TYPE('tcAn') # 'C'
		lcAnCrt = m.an
	ELSE 
		lcAnCrt = ALLTRIM(tcAn)
	ENDIF 
	
	IF EMPTY(tcLuna) OR TYPE('tcLuna') # 'C'
		lcLunaCrt = m.nl
	ELSE 
		lcLunaCrt = ALLTRIM(tcLuna)
	ENDIF 
	
	Sele calendar
	Locate For an = lcAnCrt AND nl = lcLunaCrt
	Skip -1
	If Bof()
		Do mesajatent With 'Luna '+ lcLunaCrt + ' ' + lcAnCrt ,'este prima luna deschisa!'
		Return
	ENDIF
	
	lunatrec=nl
	antrec=an

	lcDatePrec = ADDBS(calefirma) + 'AN' + ADDBS(antrec) + 'DATE' + ADDBS(lunatrec) + 'mf.dbf'
	
	IF FILE(lcDatePrec)
		USE &lcDatePrec IN 0 SHARED ALIAS mfPrec
		SELECT * from mfPrec WHERE !DELETED() INTO CURSOR crs_mfPrec READWRITE 
		USE IN mfPrec
	ELSE 
		Do MESAJ With 'Nu exista date in luna precedenta! ',''
		SELECT * from mf WHERE 1=2 INTO CURSOR crs_mfPrec READWRITE 
	ENDIF 
	
	SELECT crs_mfPrec
	REPLACE ALL cod WITH 0
	REPLACE ALL amortprec WITH amorttot
	
	
	SELECT mf 
	DELETE ALL FOR cod = 0
	
	SELECT mflun 
	DELETE ALL FOR cod = 0
	
	SELECT mf
	APPEND FROM DBF('crs_mfPrec')
	
	*** stabilesc care sunt inregistrarile inactive
	SELECT * from mf WHERE cod = -1 INTO CURSOR crs_mfNoi
	SELECT crs_mfNoi
	SCAN
		SCATTER NAME omf
		SELECT mf
		REPLACE ALL inactiv WITH .t. For cod = 0 AND  fel = omf.fel AND UPPER(ALLTRIM(denumire))=UPPER(ALLTRIM(omf.denumire)) AND datapif=omf.datapif AND nrpif=omf.nrpif AND nrinv=omf.nrinv
		SELECT crs_mfNoi
	ENDSCAN 
	
	IF 12*VAL(SUBSTR(gcDataRon,4,4))+VAL(LEFT(gcDataRon,2)) = 12*VAL(lcAnCrt)+VAL(lcLunaCrt) AND verific_rolronsnr(gcCalefirma)
		lnDim = 10000
		SELECT mf
		REPLACE ALL valoare WITH ROUND(valoare/lnDim,gnZ) FOR cod # -1
		REPLACE ALL valin WITH ROUND(valin/lnDim,gnZ) FOR cod # -1
		REPLACE ALL valramasa WITH ROUND(valramasa/lnDim,gnZ) FOR cod # -1
		REPLACE ALL valrez WITH ROUND(valrez/lnDim,gnZ) FOR cod # -1
		REPLACE ALL amortprec WITH ROUND(amortprec/lnDim,gnZ) FOR cod # -1
		REPLACE ALL amortlun WITH ROUND(amortlun/lnDim,gnZ) FOR cod # -1
		REPLACE ALL amorttot WITH ROUND(amorttot/lnDim,gnZ) FOR cod # -1
		REPLACE ALL amortan WITH ROUND(amortan/lnDim,gnZ) FOR cod # -1
	ENDIF 
	
	IF USED('crs_mfNoi')
		USE IN crs_mfNoi
	ENDIF 
	IF USED('crs_mfPrec')
		USE IN crs_mfPrec
	ENDIF 

	Do MESAJ With 'Lista mijloacelor fixe din luna ',lcLunaCrt + ' ' + lcAnCrt + ' a fost actualizata!'

RETURN 

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

PROCEDURE deschid_luna_noua
PARAMETERS tcAn, tcLuna

Set Safety Off
IF EMPTY(tcAn) OR TYPE('tcAn') # 'C'
	lcAn = m.an
ELSE 
	lcAn = ALLTRIM(tcAn)
ENDIF 

IF EMPTY(tcLuna) OR TYPE('tcLuna') # 'C'
	lcLuna = m.nl
ELSE 
	lcLuna = ALLTRIM(tcLuna)
ENDIF 
	
	
Set Exclusive On
lcDateNew = ADDBS(gcCalefirma) + 'An' + lcAn + '\' + 'DATE' + lcLuna

If !Directory(lcDateNew)
	Md &lcDateNew
Endif
Set Exclusive Off

Sele CALENDAR
LOCATE FOR an = lcAn AND luna = lcLuna
IF !FOUND()
	APPEND BLANK 
	Repl nl With lcLuna
	Repl an With lcAn
ENDIF 
SCATTER MEMVAR  && pt celebrele variabile globale 

Do totv.PRG
DO init_optiuni.prg

ENDPROC && deschid_luna_noua