*********************************************************************************************************
Procedure imprimare_bon_mp500
Lparameters tcSir,tdDataOra,tnNrBon
Private pcCale,pcExec,pcFisierText
Store [] To pcCaleExec,pcExec,pcFisierText
Local lcSir,lcFisierRez,laCount,i,llOk
lcSir=tcSir
lcFisierRez = []
laCount = 0
i=0
lcOk = .t.

gaseste_fisier_ini_mp500()
If !Empty(pcCaleExec)
	Set Safety Off
	Strtofile(lcSir,pcCaleExec+pcFisierText,0)

	Cd (pcCaleExec)
	lcDirectorZi=Iif(Type('tdDataOra')='D',Dtos(tdDataOra),Dtos(Ttod(tdDataOra)))
	ltDataOra=Iif(Type('tdDataOra')='T',tdDataOra,Datetime())
	lcNumeFisierBon=Alltrim(Str(tnNrBon))+[_]+Alltrim(Str(Hour(ltDataOra)))+[_]+;
		ALLTRIM(Str(Minute(ltDataOra)))+[_]+Alltrim(Str(Sec(ltDataOra)))
	lnRaspuns=6
	lnNrIncercare=0
	Do While lnRaspuns=6

		lcComanda=[RUN ]+pcCaleExec+pcExec + [ ] + pcCaleExec + pcFisierText
		&lcComanda

	
		lcFisierRez = pcCaleExec+[answer.txt]
		laCount = ALINES(laFisierRez,FILETOSTR(lcFisierRez))
		
		IF laCount#0
			FOR i=1 TO laCount
				llOk = IIF(OCCURS('Er',STREXTRACT(laFisierRez[i],';',';',1))>0,.f.,.t.)
				IF llOk = .f.
					EXIT 
				ENDIF 
			ENDFOR 
		ELSE 
			llOk = .f.
		ENDIF 
		
		RELEASE laFisierRez	
		
		IF llOk = .f.
						
			lcDirector=[Bonuri err]
				lnRaspuns=aMessagebox("Eroare la listarea bonului! Doriti sa reincercati?",;
					4+16+256,"Eroare")
				lnNrIncercare=lnNrIncercare+1
		ELSE 
			lcDirector=[Bonuri ok]
				lnRaspuns=7	
				
		ENDIF 	
		If !Directory(pcCaleExec+lcDirector)
			Md (lcDirector)
		Endif
		If !Directory(pcCaleExec+lcDirector+[\]+lcDirectorZi)
			Md (pcCaleExec+lcDirector+[\]+lcDirectorZi)
		Endif	
		
		lcNumeFisierBon=lcNumeFisierBon+;
				IIF(lnNrIncercare>0,[_I]+Alltrim(Str(lnNrIncercare)),[])

			Copy File (lcFisierRez) To ;
				(pcCaleExec+[\]+lcDirector+[\]+lcDirectorZi+[\]+lcNumeFisierBon+[.txt])

	Enddo
	Cd (gcAppPath)
Endif
Endproc	&&	imprimare_bon_fiscal
*********************************************************************************************************
Procedure gaseste_fisier_ini_mp500
Local lnFileHandle,lcFisierConfigurare,lnRaspuns
lnRaspuns=6
lcFisierConfigurare=gcAppPath+[\INITIALIZARI\]+Alltrim(gcNumeProgram)+[_mp500.xml]
Do While lnRaspuns=6
	If File(lcFisierConfigurare)
		lnFileHandle=Fopen(lcFisierConfigurare,12)
		lnSize =  Fseek(lnFileHandle,0,2)
		If lnSize>0
			Fseek(lnFileHandle, 0, 0)
			lcFisier = Fread(lnFileHandle,lnSize)
			lcString = Strextract(Upper(lcFisier),;
				[<]+Upper(Alltrim(gcS))+[>],[</]+Upper(Alltrim(gcS))+[>])
			If !Empty(lcString)
				lcElement=[LAUNCH_PATH]
				pcCaleExec=Strextract(lcString,[<]+lcElement+[>],[</]+lcElement+[>])
				lcElement=[LAUNCH_FILE]
				pcExec=Strextract(lcString,[<]+lcElement+[>],[</]+lcElement+[>])
				lcElement=[LAUNCH_DATA]
				pcFisierText=Strextract(lcString,[<]+lcElement+[>],[</]+lcElement+[>])
			Else
				aMessagebox("Nu exista configurarile pentru listarea bonurilor fiscale pe aceasta firma!",0+48,"Atentie")
				pcCaleExec=[]
			Endif
		Else
			aMessagebox("Fisierul de configurari pentru bonurilor fiscale este gol!",0+48,"Atentie")
			pcCaleExec=[]
		Endif
		Fclose(lnFileHandle)
	Else
		aMessagebox("Nu exista fisierul de configurare pentru listarea bonurilor fiscale!",0+48,"Atentie")
		pcCaleExec=[]
	Endif
	If Empty(pcCaleExec)
		lnRaspuns=aMessagebox("Doriti sa mai incercati listarea bonului?",4+32+256,"Confirmare")
	Else
		lnRaspuns=7
	Endif
Enddo
Endproc	&&	gaseste_fisier_ini
*********************************************************************************************************