*********************************************************************************************************
Procedure imprimare_bon_fiscal
Lparameters tcSir,tdDataOra,tnNrBon
Private pcCale,pcExec,pcFisierText
Store [] To pcCaleExec,pcExec,pcFisierText
Local lcSir
lcSir=tcSir
gaseste_fisier_ini()
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
		&lcComanda
		If File(pcCaleExec+[ERR])
			lcString=Filetostr(pcCaleExec+[ERR])
			lcStringOk=Replicate([0]+Chr(13)+Chr(10),Occurs(Chr(13)+Chr(10),lcString))
			If lcString=lcStringOk
				lcDirector=[Bonuri ok]
				lnRaspuns=7
			Else
				lcDirector=[Bonuri err]
				lnRaspuns=aMessagebox("Eroare la listarea bonului! Doriti sa reincercati?",;
					4+16+256,"Eroare")
				lnNrIncercare=lnNrIncercare+1
			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 (pcCaleExec+pcFisierText) To ;
				(pcCaleExec+lcDirector+[\]+lcDirectorZi+[\]+lcNumeFisierBon+[.txt])
			Copy File (pcCaleExec+[ERR]) To ;
				(pcCaleExec+lcDirector+[\]+lcDirectorZi+[\]+lcNumeFisierBon+[.err])
			Delete File (pcCaleExec+[ERR])
		Else
			lcDirectorErr=[Bonuri err]
			If !Directory(pcCaleExec+lcDirectorErr)
				Md (lcDirectorErr)
			Endif
			If !Directory(pcCaleExec+lcDirectorErr+[\]+lcDirectorZi)
				Md (pcCaleExec+lcDirectorErr+[\]+lcDirectorZi)
			Endif
			Copy File (pcCaleExec+pcFisierText) To ;
				(pcCaleExec+lcDirectorErr+[\]+lcDirectorZi+[\]+lcNumeFisierBon+[.txt])
		Endif
	Enddo
	Cd (gcAppPath)
Endif
Endproc	&&	imprimare_bon_fiscal
*********************************************************************************************************
Procedure gaseste_fisier_ini
Local lnFileHandle,lcFisierConfigurare,lnRaspuns
lnRaspuns=6
lcFisierConfigurare=gcAppPath+[\INITIALIZARI\]+Alltrim(gcNumeProgram)+[_bon.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
*********************************************************************************************************