*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="start00.scx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS dataenvironment AS dataenvironment 
 	*< CLASSDATA: Baseclass="dataenvironment" Timestamp="" Scale="" Uniqueid="" ClassIcon="1" />

	*<PropValue>
		Name = "Dataenvironment"
	*</PropValue>

ENDDEFINE

DEFINE CLASS ffergen1 AS ffergen OF "..\clase\ferestrebaza.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="img_start" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="img_ter_al" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cboLuna" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cboFirma" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblFirma" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblLuna" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblAnul" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="img_start_al" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cboAnul" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: cindmaus
		*m: go
		*m: lasfirsit
		*m: validfirma
		*m: validluna
		*p: tt1
		*p: tt2
		*p: tt3
		*p: ttanul
		*p: ttdata
		*p: ttfirma
		*p: ttluna
	*</DefinedPropArrayMethod>

	*<PropValue>
		AutoCenter = .T.
		BackColor = 255,255,255
		BorderStyle = 0
		DoCreate = .T.
		Height = 153
		Name = "Ffergen1"
		Picture = ..\grafice\backgrnd.bmp
		TabStop = .F.
		tt1 = ""
		tt2 = ""
		tt3 = ""
		ttanul = ""
		ttdata = ""
		ttfirma = ""
		ttluna = "
		Width = 529
		WindowState = 0
		WindowType = 1
	*</PropValue>

	ADD OBJECT 'cboAnul' AS combobox WITH ;
		Alignment = 0, ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		ControlSource = "thisform.ttAnul", ;
		FontName = "Arial", ;
		FontSize = 9, ;
		ForeColor = 0,0,0, ;
		Format = "", ;
		Height = 20, ;
		Left = 267, ;
		Name = "cboAnul", ;
		RowSource = "1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020", ;
		RowSourceType = 1, ;
		SpecialEffect = 2, ;
		Style = 2, ;
		TabIndex = 2, ;
		TabStop = .F., ;
		Top = 47, ;
		Value = 2000, ;
		Visible = .T., ;
		Width = 247, ;
		ZOrderSet = 35
		*< END OBJECT: BaseClass="combobox" />

	ADD OBJECT 'cboFirma' AS combobox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		ControlSource = "thisform.ttFirma", ;
		FontName = "Arial", ;
		FontSize = 9, ;
		ForeColor = 0,0,0, ;
		Format = "", ;
		Height = 20, ;
		InputMask = "", ;
		Left = 267, ;
		Name = "cboFirma", ;
		RowSource = "firma.firma", ;
		RowSourceType = 2, ;
		SpecialEffect = 2, ;
		Style = 2, ;
		TabIndex = 1, ;
		TabStop = .F., ;
		Top = 10, ;
		Visible = .T., ;
		Width = 247, ;
		ZOrderSet = 17
		*< END OBJECT: BaseClass="combobox" />

	ADD OBJECT 'cboLuna' AS combobox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		ControlSource = "thisform.ttluna", ;
		FontName = "Arial", ;
		FontSize = 9, ;
		ForeColor = 0,0,0, ;
		Format = "", ;
		Height = 20, ;
		Left = 267, ;
		Name = "cboLuna", ;
		RowSource = "lunilean.numeluna", ;
		RowSourceType = 6, ;
		SpecialEffect = 2, ;
		Style = 2, ;
		TabIndex = 3, ;
		TabStop = .F., ;
		Top = 85, ;
		Visible = .T., ;
		Width = 247, ;
		ZOrderSet = 27
		*< END OBJECT: BaseClass="combobox" />

	ADD OBJECT 'img_start' AS image WITH ;
		Height = 156, ;
		Left = 0, ;
		Name = "img_start", ;
		Picture = ..\grafice\start.bmp, ;
		Stretch = 2, ;
		Top = 0, ;
		Width = 529, ;
		ZOrderSet = 0
		*< END OBJECT: BaseClass="image" />

	ADD OBJECT 'img_start_al' AS image WITH ;
		BackStyle = 0, ;
		Height = 28, ;
		Left = 80, ;
		Name = "img_start_al", ;
		Picture = ..\grafice\start_albastru.bmp, ;
		Stretch = 2, ;
		Top = 120, ;
		Width = 108, ;
		ZOrderSet = 21
		*< END OBJECT: BaseClass="image" />

	ADD OBJECT 'img_ter_al' AS image WITH ;
		BackStyle = 0, ;
		Height = 34, ;
		Left = 336, ;
		Name = "img_ter_al", ;
		Picture = ..\grafice\terminat_a.bmp, ;
		Stretch = 2, ;
		Top = 116, ;
		Width = 128, ;
		ZOrderSet = 2
		*< END OBJECT: BaseClass="image" />

	ADD OBJECT 'lblAnul' AS label WITH ;
		Alignment = 1, ;
		AutoSize = .T., ;
		BackColor = 255,255,255, ;
		BackStyle = 0, ;
		Caption = "Anul:", ;
		FontBold = .T., ;
		FontName = "Courier New", ;
		FontShadow = .F., ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Height = 18, ;
		Left = 209, ;
		Name = "lblAnul", ;
		TabIndex = 6, ;
		Top = 49, ;
		Width = 42, ;
		ZOrderSet = 20
		*< END OBJECT: BaseClass="label" />

	ADD OBJECT 'lblFirma' AS label WITH ;
		Alignment = 1, ;
		AutoSize = .T., ;
		BackColor = 255,255,255, ;
		BackStyle = 0, ;
		Caption = "Firma:", ;
		FontBold = .T., ;
		FontName = "Courier New", ;
		FontShadow = .F., ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Height = 18, ;
		Left = 201, ;
		Name = "lblFirma", ;
		TabIndex = 5, ;
		Top = 13, ;
		Width = 50, ;
		ZOrderSet = 18
		*< END OBJECT: BaseClass="label" />

	ADD OBJECT 'lblLuna' AS label WITH ;
		Alignment = 1, ;
		AutoSize = .T., ;
		BackColor = 255,255,255, ;
		BackStyle = 0, ;
		Caption = "Luna contabila:", ;
		FontBold = .T., ;
		FontName = "Courier New", ;
		FontShadow = .F., ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Height = 18, ;
		Left = 129, ;
		Name = "lblLuna", ;
		TabIndex = 4, ;
		Top = 87, ;
		Width = 122, ;
		ZOrderSet = 6
		*< END OBJECT: BaseClass="label" />
	
	PROCEDURE Activate
		*
	ENDPROC

	PROCEDURE cindmaus
	ENDPROC

	PROCEDURE go
		IF THISFORM.VALIDLUNA()
		 THISFORM.VISIBLE=.F.
		
		 THISFORM.LASFIRSIT
		
		
		 do totv
		
		 DO INIT_OPTIUNI
		
		 THISFORM.RELEASE
		ENDIF
		
		
	ENDPROC

	PROCEDURE Init
		CLOSE DATABASES 
		calefirma=dirgen
		Do des With 'FIRMA' IN totv.prg
		
		Sele FIRMA
		Go Top
		If !Eof()
			Local II,ESTE
			II=1
			ESTE=.F.
			For II = 1 To Fcount( )
				If Allt(Field(II))='PERMIS'
					ESTE=.T.
				Endif
			Next
			If ESTE
				Sele FIRMA
				Repl All PERMIS With '*' For Empty(PERMIS)
				UTILIZATOR=Allt(UTILIZATOR)
				Set Filter To Allt(PERMIS)='*' Or Like('*'+UTILIZATOR+'*',PERMIS) And !Empty(Allt(PERMIS))
			Endif
			Sele FIRMA
			Go Top
			m.flung=FIRMA
			thisform.ttfirma=ALLTRIM(firma)
			m.antet=Alltrim(M.flung)
			nfscurt=Alltrim(fscurt)
			m.CALEFIRM=ADDBS(Alltrim(CALEFIRM))
			calefirma=M.CALEFIRM
			IF !Start_Nou()
				LOC=ALLT(LOCTEMPO)
			ELSE
				LOC = ADDBS(gcTempPath)
			ENDIF
			If ESERVER And !Empty(CALES)
				calefirma=ADDBS(STRTRAN(CALES+'\'+nfscurt,"\\","\"))
		
			Endif
		
		Else
			Do Form STARTFIRMA
			Do mesaj With 'Pentru initializare programul trebuie restartat',''
			QUIT 
		Endif
		
		*** compar calendarmf.dbf cu calendar.dbf
		DO compar_calendare WITH 'calendarmf','calendar'
		
		*** aleg ultima luna deschisa
		Do des With 'CALENDAR' IN totv.prg
		SELECT calendar
		Go Bottom
		Scatter Memvar
		thisform.ttanul=an
		lc_luna=nl
		lc_anul=an
		
		
		Do des With 'LUNILEAN' IN totv.prg
		Seek(lc_luna)
		Scatter Memvar
		m.luna=numeluna
		thisform.ttluna=numeluna
		
		
		THIS.CBOFirma.SetFocus
		
		
		
	ENDPROC

	PROCEDURE KeyPress
		LPARAMETERS nKeyCode, nShiftAltCtrl
		if nkeycode=13
			this.go()
		ELSE
			DODEFAULT ()
		endif
	ENDPROC

	PROCEDURE lasfirsit
		
		*capapl="CONT2000      Firma "+numefirma+"- Luna contabila: "+RTRIM(M.luna)+" "+M.AN+"  "
		SELECT lunilean
		LOCATE FOR nl=m.nl
		m.luna=numeluna
		
		
		
		
		&&ESTE CUMVA LUNA BLOCATA?
		SELE calendar
		LOCA for nl=m.nl and AN=m.AN
		SCAT memv
		luna_inchisa=smf
		
		&&ESTE CUMVA LUNA NEPLATITA?
		*sele calendar
		*loca for nl=m.nl and an=m.an
		*SKIP
		*IF EOF()
		IF e_ultima_luna()
		*	SELE 0
		*	USE &DIRGEN\_ALFA\DATEAN\CUL ALIAS CUL
			DO DES WITH 'CUL' IN totv.prg
			IF SERIA_LUNARA_E_CORECTA()
				LUNA_NEPLATITA=.F.
			ELSE
				LUNA_NEPLATITA=.T.
			ENDIF
			SELE cul
			USE
		ELSE
			LUNA_NEPLATITA=.F.
		ENDIF
		
		Select FIRMA
		Scatter Name poFirma && OBIECT GLOBAL
		
		Select calendar
		Scatter Name poCalendar && OBIECT GLOBAL
		
		NUMEFIRMA=UPPER(rTRIM(poFirma.firma))
		*NUMEPROGRAM=UPPER(ALLTRIM(PCNUMEAPP))
		
		capapl=NUMEPROGRAM+"      Firma "+NUMEFIRMA+"- Luna contabila: "+RTRIM(M.luna)+" "+M.AN+"  "
		goApp.SetCaption(capapl)
		
	ENDPROC

	PROCEDURE validfirma
		Sele FIRMA
		*Loca For FIRMA=M.FLUNG
		Scatter Memvar
		
		antet=ALLTRIM(M.FLUNG)
		NFSCURT=Alltrim(m.FSCURT)
		CALEFIRMA=Alltrim(M.CALEFIRM)
		IF !Start_Nou()
			LOC=ALLT(LOCTEMPO)
		ELSE
			LOC = ADDBS(gcTempPath)
		ENDIF
		DIRFIRM=addbs(loc)+nfscurt+"\"
		
		If ESERVER And !Empty(CALES)
			CALEFIRMA=CALES+'\'+NFSCURT
		Endif
		
		*daca firma a fost creata in sal2000__________
		*!*	If !File('&CALEFIRMA\datean\calendar.DBF') And File('&CALEFIRMA\datean\calensal.DBF')
		*!*		Do firmadinsal
		*!*		Do DES With 'LUNILEAN'
		*!*		Do DES With 'CALENDAR'
		*!*	Endif
		
		IF USED('CALENDAR')
			USE IN calendar
		ENDIF
		
		*** compar calendarmf.dbf cu calendar.dbf
		DO compar_calendare WITH 'calendarmf','calendar'
		
		*** aleg ultima luna deschisa
		Do DES With 'CALENDAR'
		Sele calendar
		Go Bottom
		Scatter Memvar
		THIS.TTAnul=AN
		
		Sele lunilean
		Seek(m.nl)
		Scatter Memvar
		m.luna=m.numeluna
		THIS.TTLUNA=LUNA
		
		THIS.CBOAnul.Refresh
		THIS.CBOLuna.Refresh 
	ENDPROC

	PROCEDURE validluna
		local amin,amax,lmin,lmax,_an,_luna
		*m.an=thisform.ttanul
		_AN = THIS.TTANUL 
		_LUNA = THIS.TTLUNA 
		m.an = THIS.TTANUL 
		SELECT lunilean
		SCATTER MEMVAR
		_NL=NL
		*!*	m.luna=numeluna
		
		
		
		sele calendar
		LOCATE FOR !EMPTY(an) AND !EMPTY(nl)
		IF FOUND()
			amin=an
			lmin=nl
		endif
		
		go bottom
		amax=an
		lmax=nl
		
		&& verific daca luna aleasa este mai mica decat luna maxima deschisa inscrisa in tabelul start_meniuri
		 
		lnLunaC = VAL(m.an)*12+VAL(m.nl)
		lcCaleFirma = ADDBS(calefirma)
		lcFscurt = ALLTRIM(nfscurt)
		lcLunaS = Citeste_Firma_Luna(lcCaleFirma,lcFscurt) && proceduri_verificare_luna.prg
		lcLuna = m.nl
		lcAn = m.an
		lnPos = AT("\",lcLunaS)
		IF lnPos = 0
			lnLunaS = 0
		ELSE 
			lcAn = LEFT(lcLunaS,lnPos - 1)
			lcLuna = SUBSTR(lcLunaS,lnPos+1)
			lnLunaS = VAL(lcAn)*12 + VAL(lcLuna)
		ENDIF
		IF lnLunaC>lnLunaS
			DO mesaj WITH "Ultima luna deschisa este: "+lcLuna+" "+lcAn,""
			sele calendar
			LOCATE FOR VAL(an) = VAL(lcAn) AND VAL(nl) = VAL(lCLuna)
			IF FOUND()
				scatter memvar
				sele lunilean
				seek(m.nl)
				m.luna=numeluna
				THIS.TTANUL  = m.an
			ENDIF 
			RETURN .F.
		ENDIF 
		&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
		
		
		*daca luna nu e dechisa___________
		if VAL(_an)*12+VAL(_NL)>VAL(amax)*12+VAL(lmax)
			do mesaj with "Luna "+rtrim(_NL)+" "+_an+" nu a fost deschisa!","Ultima luna deschisa este: "+lmax+" "+amax
			*WAIT WINDOW "Ultima luna deschisa este: "+lmax+" "+amax
			sele calendar
			go bottom
			scatter memvar
			thisform.ttanul=an
			
			sele lunilean
			seek(M.nl)
			IF FOUND()
				m.luna=numeluna
				THISFORM.TTLUNA=NUMELUNA
			ENDIF 
			THIS.CBOAnul.Refresh
			THIS.CBOLuna.Refresh 
			RETURN .F.
		endif
		
		*daca luna nu exista_________________
		if VAL(_an)*12+VAL(_NL)<VAL(amin)*12+VAL(lmin)
			do mesaj with "Nu sunt inregistrate date in luna  "+rtrim(_NL)+" "+_an+" !",;
				"Prima luna deschisa a fost: "+lmin+" "+amin
			sele calendar
			go bottom
			scatter memvar
			thisform.ttanul=an
			
			sele lunilean
			seek(M.nl)
			IF FOUND()
				m.luna=numeluna
				THISFORM.TTLUNA=NUMELUNA
			ENDIF 
			THIS.CBOAnul.Refresh
			THIS.CBOLuna.Refresh 
			RETURN .F.
		endif
		m.nl=_NL
		m.an=_an
		
		
		
	ENDPROC

	PROCEDURE cboAnul.Valid
		
		
		
	ENDPROC

	PROCEDURE cboFirma.Valid
		thisform.validfirma()
	ENDPROC

	PROCEDURE cboLuna.Valid
		
		
		
		
		
		
		
	ENDPROC

	PROCEDURE img_start_al.Click
		thisform.go()
		
	ENDPROC

	PROCEDURE img_start_al.MouseEnter
		LPARAMETERS nButton, nShift, nXCoord, nYCoord
		this.Picture=addbs(gcAppPath)+'GRAFICE\START_GALBEN.BMP'
		
	ENDPROC

	PROCEDURE img_start_al.MouseLeave
		LPARAMETERS nButton, nShift, nXCoord, nYCoord
		this.Picture=addbs(gcAppPath)+'GRAFICE\start_albastru.bmp'
	ENDPROC

	PROCEDURE img_ter_al.Click
		quit
	ENDPROC

	PROCEDURE img_ter_al.MouseEnter
		LPARAMETERS nButton, nShift, nXCoord, nYCoord
		this.Picture=addbs(gcAppPath)+'GRAFICE\terminat_g.BMP'
	ENDPROC

	PROCEDURE img_ter_al.MouseLeave
		LPARAMETERS nButton, nShift, nXCoord, nYCoord
		this.Picture=addbs(gcAppPath)+'GRAFICE\terminat_a.BMP'
	ENDPROC

ENDDEFINE
