PARAMETERS tcFisImob, tcFisCont

LOCAL lcFisImob,lcAliasImob,lcFisCont,lnSucces,lcCaleFisier
STORE '' TO lcFisImob,lcAliasImob,lcFisCont,lcCaleFisier
lnSucces = 1
lcAliasImob = [calendar]

glImobIndependent = .F.

IF EMPTY(tcFisImob) OR TYPE('tcFisImob') # 'C'
	lcFisImob = 'calendarmf'
ELSE 
	lcFisImob = ALLTRIM(tcFisImob)
ENDIF 

IF EMPTY(tcFisCont) OR TYPE('tcFisCont') # 'C'
	lcFisCont = 'calendar'
ELSE 
	lcFisCont = ALLTRIM(tcFisCont)
ENDIF 

*** verific daca in DATERETEA in tabelul start_programe.dbf am independ = .T.
*!*	IF TYPE('gcCaleDateRetea') = 'U' && in prg principal. dc am start nou
*!*		lcDateRetea = ADDBS(ALLTRIM(dirgen)) + 'DATERETEA'
*!*	ELSE 
*!*		lcDateRetea = ALLTRIM(gcCaleDateRetea)
*!*	ENDIF 

*!*	lcCaleFisier = ADDBS(lcDateRetea) + 'start_programe.dbf'
*!*	IF FILE(lcCaleFisier)
*!*		USE &lcCaleFisier IN 0 SHARED ALIAS start_prg
*!*		IF TYPE('start_prg.independ') # 'U'
*!*			SELECT start_prg
*!*			LOCATE FOR INLIST(UPPER(ALLTRIM(gcAppName)),UPPER(ALLTRIM(nume)),UPPER(ALLTRIM(director)))
*!*			IF FOUND() AND independ
*!*				gleIndependent = .T.
*!*			ENDIF 
*!*		ENDIF 
*!*	ENDIF 
***

IF glImobIndependent && dc programul ruleaza independent de contabilitate
	lcCaleFisierImob = ADDBS(CALEFIRMA) + [datean\] + lcFisImob + [.dbf]
	lcCaleFisierCont = ADDBS(CALEFIRMA) + [datean\] + lcFisCont + [.dbf]
	IF !FILE(lcCaleFisierImob)
		DO des WITH lcAliasImob && se creaza structura vida
		IF FILE(lcCaleFisierCont)
*			USE &lcCaleFisierCont IN 0 shared ALIAS calendar_cont
			SELECT (lcAliasImob) 
			APPEND FROM &lcCaleFisierCont FOR !DELETED() AND (!EMPTY(an) OR !EMPTY(nl))
		ENDIF 
	ENDIF 
ENDIF 

IF !glImobIndependent && dc programul e legat de contabilitate
	lcCaleFisierImob = ADDBS(CALEFIRMA) + [datean\] + lcFisImob + [.dbf]
	lcCaleFisierCont = ADDBS(CALEFIRMA) + [datean\] + lcFisCont + [.dbf]
	DO des WITH lcAliasImob
	IF !FILE(lcCaleFisierCont)
		DO mesaj WITH 'Nu exista fisierul calendar.dbf!','Deschideti programul de contabilitate.'
		lnSucces = -1
	ENDIF 
	IF lnSucces > 0  && compar calendarele, update calendarmf
*		USE &lcCaleFisierCont IN 0 shared ALIAS calendar_cont
		SELECT (lcAliasImob)		
		CALCULATE MAX(12*VAL(an)+VAL(nl)) TO lnMaxData
		APPEND FROM &lcCaleFisierCont FOR (12*VAL(an)+VAL(nl))>lnMaxData AND !DELETED() AND (12*VAL(an)+VAL(nl))# 0 && IN CAZUL UNUI CALENDAR CU LINII GOALE
	ENDIF 
ENDIF 

IF USED(lcAliasImob)
	USE IN &lcAliasImob
ENDIF 
IF USED('start_prg')
	USE IN start_prg
ENDIF 

RETURN lnSucces