DEFINE CLASS  export_sf_access AS custom 
	cPathKIT = "c:\bilant\"
	cPathTempo = "c:\Temp\"
	cBilant = "date1"
	cCPP = "date2"
	cDateInf = "date3"
	cActive = "date4"
	cFirma = "Date5"
&& ------------------------------INCEPUT: Init ------------------------------
	*!* Procedura:  Init
	*!* Parametri:
	*!* Data/Ora generarii: 17/02/2004 10:56
	*!* Autor: MARIUS.MUTU
	PROCEDURE  INIT
		LPARAMETERS tcPathKIT, tcPathTempo

		IF TYPE('tcPathKIT')='C'
			THIS.cPathKIT = ADDBS(tcPathKIT)
		ENDIF
		THIS.Init_Directoare(THIS.cPathKIT)

		IF TYPE('tcPathTempo')='C'
			THIS.cPathTempo = ADDBS(tcPathTempo)
		ENDIF
		THIS.Init_Directoare(THIS.cPathTempo)

	ENDPROC
&& ------------------------------SFARSIT: Init ------------------------------

&& ------------------------------INCEPUT: Error ------------------------------
	*!* Functia:  Error
	*!* Parametri: tnError, tcProcedura, tcMesaj
	*!* Data/Ora generarii: 17/02/2004 11:35
	*!* Autor: MARIUS.MUTU
	FUNCTION ERRORH
		LPARAMETERS tnError, tcProcedura, tnLinieMesaj

		lcErrorNumber = ALLTRIM(STR(tnError))
		lcProcedura = ALLTRIM(tcProcedura)
		lcLinieMesaj = ALLTRIM(STR(tnLinieMesaj))
		lcMesaj = MESSAGE(1)
		lcText = "Eroarea nr. " + lcErrorNumber + CHR(13) + CHR(10) +;
			"Procedura: " + lcProcedura + CHR(13) + CHR(10) +;
			"Mesaj: " + lcMesaj + CHR(13) + CHR(10) +;
			"Linia: " + lcLinieMesaj 
		= MESSAGEBOX(lcText)


	ENDFUNC
&& ------------------------------SFARSIT: Error ------------------------------

&& ------------------------------INCEPUT: Init_Directoare ------------------------------
	*!* Procedura:  Init_Directoare
	*!* Parametri: tcPath
	*!* Data/Ora generarii: 17/02/2004 10:47
	*!* Autor: MARIUS.MUTU

	PROCEDURE  Init_Directoare
		LPARAMETERS tcPath

		lcPath = ADDBS(tcPath)

		IF !DIRECTORY(lcPath)
			MD (lcPath)
		ENDIF

	ENDPROC
&& ------------------------------SFARSIT: Init_Directoare ------------------------------

&& ------------------------------INCEPUT: Copie_Fisiere_Vide ------------------------------
	*!* Procedura:  Copie_Fisiere_Vide
	*!* Parametri: tcSPath, tcDPath, tcFileName
	*!* Data/Ora generarii: 17/02/2004 11:07
	*!* Autor: MARIUS.MUTU
	PROCEDURE  Copie_Fisiere_Vide
		LPARAMETERS tcSPath, tcDPath, tcFileName

		IF !DIRECTORY(tcSPath)
			RETURN .F.
		ENDIF

		IF !DIRECTORY(tcDPath)
			THIS.Init_Directoare(tcDPath)
		ENDIF

		IF EMPTY(tcFileName)
			lcFileName = "*.*"
		ELSE
			lcFileName = ALLTRIM(tcFileName)+".*"
		ENDIF

		lcSFile = ADDBS(tcSPath) + lcFileName
		lcDFile = ADDBS(tcDPath) + lcFileName

		COPY FILE (lcSFile) TO (lcDFile)

		RETURN .T.

	ENDPROC
&& ------------------------------SFARSIT: Copie_Fisiere_Vide ------------------------------

&& ------------------------------INCEPUT: Completeaza_Date_Bilant ------------------------------
	*!* Procedura:  Completeaza_Date_Bilant
	*!* Parametri: tcAliasBilant
	*!* Data/Ora generarii: 17/02/2004 11:12
	*!* Autor: MARIUS.MUTU
	PROCEDURE  Completeaza_Date_Bilant
		LPARAMETERS tcAliasBilant

		LOCAL lnNrRanduri, lcBilant, lcFisBilant, loBilant, llUsed
		lnNrRanduri = 34

		lcBilant = ALLTRIM(THIS.cBilant)
		lcFisBilant = ADDBS(THIS.cPathKIT) + lcBilant + ".dbf"

		IF !FILE(lcFisBilant)
			RETURN .F.
		ENDIF

		llUsed = .T.
		IF !USED(lcBilant)
			llUsed = .F.
			USE (lcFisBilant) IN 0 ALIAS (lcBilant)
		ENDIF



		IF USED('tBilant')
			USE IN tBilant
		ENDIF

		SELECT PADL(ALLTRIM(a.nr),2,"0") AS RAND, a.suma2 AS suma1, a.suma AS suma2 ;
			FROM (tcAliasBilant) a;
			WHERE VAL(a.nr)!=0 ;
			INTO CURSOR tBilant




		SELECT (lcBilant)
		SCATTER NAME loBilant BLANK

		lcOldError = ON("error")
		ON ERROR * && daca lipsesc coloane din tabelul (lcActive) nu procesez eroarea

		SELECT tBilant
		SCAN
			lcVar1 = "loBilant.F10_"+PADL(ALLTRIM(RAND),3,'0')+'1'
			&lcVar1 = suma1

			lcVar2 = "loBilant.F10_"+PADL(ALLTRIM(RAND),3,'0')+'2'
			&lcVar2 = suma2
		ENDSCAN

		ON ERROR &lcOldError

		SELECT (lcBilant)
		GATHER NAME loBilant

		USE IN tBilant

		IF !llUsed
			USE IN (lcBilant)
		ENDIF

	ENDPROC
&& ------------------------------SFARSIT: Completeaza_Date_Bilant ------------------------------

&& ------------------------------INCEPUT: Completeaza_Date_Cpp ------------------------------
	*!* Procedura:  Completeaza_Date_Cpp
	*!* Parametri:
	*!* Data/Ora generarii: 17/02/2004 11:12
	*!* Autor: MARIUS.MUTU
	PROCEDURE  Completeaza_Date_Cpp
		LPARAMETERS tcAliasCPP

		LOCAL lnNrRanduri, lcCPP, lcFisCPP, loCPP, llUsed
		lnNrRanduri = 63

		lcCPP = ALLTRIM(THIS.cCPP)
		lcFisCPP = ADDBS(THIS.cPathKIT) + lcCPP + ".dbf"

		IF !FILE(lcFisCPP)
			RETURN .F.
		ENDIF

		llUsed = .T.
		IF !USED(lcCPP)
			llUsed = .F.
			USE (lcFisCPP) IN 0 SHARED ALIAS (lcCPP)
		ENDIF



		IF USED('tCPP')
			USE IN tCPP
		ENDIF

		SELECT PADL(ALLTRIM(a.RAND),2,"0") AS RAND, a.sumai AS suma1, a.sumac AS suma2 ;
			FROM (tcAliasCPP) a;
			WHERE VAL(a.RAND)!=0 ;
			INTO CURSOR tCPP



		lcOldError = ON("error")
		ON ERROR * && daca lipsesc coloane din tabelul (lcActive) nu procesez eroarea


		SELECT (lcCPP)
		SCATTER NAME loCPP BLANK

		SELECT tCPP
		SCAN
			lcVar1 = "loCPP.F20_"+PADL(ALLTRIM(RAND),3,'0')+'1'
			&lcVar1 = suma1

			lcVar2 = "loCPP.F20_"+PADL(ALLTRIM(RAND),3,'0')+'2'
			&lcVar2 = suma2
		ENDSCAN

		ON ERROR &lcOldError

		SELECT (lcCPP)
		GATHER NAME loCPP

		USE IN tCPP

		IF !llUsed
			USE IN (lcCPP)
		ENDIF

	ENDPROC
&& ------------------------------SFARSIT: Completeaza_Date_Cpp ------------------------------


&& ------------------------------INCEPUT: Completeaza_Date_Date_informative ------------------------------
	*!* Procedura:  Completeaza_Date_Date_informative
	*!* Parametri:
	*!* Data/Ora generarii: 17/02/2004 11:13
	*!* Autor: MARIUS.MUTU
	PROCEDURE  Completeaza_Date_Date_informative
		LPARAMETERS tcAliasDateInf

		LOCAL lnNrRanduri, lcDateInf, lcFisDateInf, loDateInf, llUsed
		lnNrRanduri = 22

		lcDateInf = ALLTRIM(THIS.cDateInf)
		lcFisDateInf = ADDBS(THIS.cPathKIT) + lcDateInf + ".dbf"


		IF !FILE(lcFisDateInf)
			RETURN .F.
		ENDIF

		llUsed = .T.
		IF !USED(lcDateInf)
			llUsed = .F.
			USE (lcFisDateInf) IN 0 SHARED ALIAS (lcDateInf)
		ENDIF



		IF USED('tDateInf1')
			USE IN tDateInf1
		ENDIF
		IF USED('tDateInf2')
			USE IN tDateInf2
		ENDIF

		lcAliasDateInf = ALLTRIM(tcAliasDateInf)
		lcAliasDateInf1 = lcAliasDateInf+"1R"
		lcAliasDateInf2 = lcAliasDateInf+"2R"


		SELECT PADL(ALLTRIM(a.RAND),2,"0") AS RAND, a.unitati AS suma1, a.sume AS suma2 ;
			FROM (lcAliasDateInf1) a;
			WHERE VAL(a.RAND)!=0 ;
			INTO CURSOR tDateInf1

		SELECT PADL(ALLTRIM(a.RAND),2,"0") AS RAND, a.sold AS suma1, a.col2 AS suma2, a.col3 AS suma3 ;
			FROM (lcAliasDateInf2) a ;
			WHERE VAL(a.RAND)!=0 ;
			INTO CURSOR tDateInf2



		*** DATEINF1
		SELECT (lcDateInf)
		SCATTER NAME loDateInf BLANK

		lcOldError = ON("error")
		ON ERROR * && daca lipsesc coloane din tabelul (lcActive) nu procesez eroarea

		SELECT tDateInf1
		SCAN
			lcVar1 = "loDateInf.F30_"+PADL(ALLTRIM(RAND),3,'0')+'1'
			&lcVar1 = suma1

			lcVar2 = "loDateInf.F30_"+PADL(ALLTRIM(RAND),3,'0')+'2'
			&lcVar2 = suma2
		ENDSCAN

		ON ERROR &lcOldError

		SELECT (lcDateInf)
		GATHER NAME loDateInf

		USE IN tDateInf1


		*** DATEINF2

		lcOldError = ON("error")
		ON ERROR * && daca lipsesc coloane din tabelul (lcActive) nu procesez eroarea

		SELECT tDateInf2
		SCAN
			lcVar1 = "loDateInf.F30_"+PADL(ALLTRIM(RAND),3,'0')+'1'
			&lcVar1 = suma1

			lcVar2 = "loDateInf.F30_"+PADL(ALLTRIM(RAND),3,'0')+'2'
			&lcVar2 = suma2

			lcVar3 = "loDateInf.F30_"+PADL(ALLTRIM(RAND),3,'0')+'3'
			&lcVar3 = suma3
		ENDSCAN


		ON ERROR &lcOldError

		SELECT (lcDateInf)
		GATHER NAME loDateInf

		USE IN tDateInf2

		IF !llUsed
			USE IN (lcDateInf)
		ENDIF

	ENDPROC
&& ------------------------------SFARSIT: Completeaza_Date_Date_informative ------------------------------

&& ------------------------------INCEPUT: Completeaza_Date_Active_Imobilizate ------------------------------
	*!* Procedura:  Completeaza_Date_Active_Imobilizate
	*!* Parametri:
	*!* Data/Ora generarii: 17/02/2004 11:13
	*!* Autor: MARIUS.MUTU
	PROCEDURE  Completeaza_Date_Active_Imobilizate
		LPARAMETERS tcAliasActive

		LOCAL lnNrRanduri, lcActive, lcFisActive, loActive, llUsed
		lnNrRanduri = 33

		lcActive = ALLTRIM(THIS.cActive)
		lcFisActive = ADDBS(THIS.cPathKIT) + lcActive + ".dbf"

		IF !FILE(lcFisActive)
			RETURN .F.
		ENDIF

		llUsed = .T.
		IF !USED(lcActive)
			llUsed = .F.
			USE (lcFisActive) IN 0 SHARED ALIAS (lcActive)
		ENDIF



		IF USED('tActive')
			USE IN tActive
		ENDIF

		SELECT PADL(ALLTRIM(a.nr),2,"0") AS RAND, a.soldi AS suma1, a.crestere AS suma2, a.reducere AS suma3, a.casare AS suma4, a.soldf AS suma5 ;
			FROM (tcAliasActive) a ;
			WHERE VAL(a.nr)!=0 ;
			INTO CURSOR tActive


		lcOldError = ON("error")
		ON ERROR * && daca lipsesc coloane din tabelul (lcActive) nu procesez eroarea

		SELECT (lcActive)
		SCATTER NAME loActive BLANK

		SELECT tActive
		SCAN
			lcVar1 = "loActive.F40_"+PADL(ALLTRIM(RAND),3,'0')+'1'
			&lcVar1 = suma1

			lcVar2 = "loActive.F40_"+PADL(ALLTRIM(RAND),3,'0')+'2'
			&lcVar2 = suma2

			lcVar3 = "loActive.F40_"+PADL(ALLTRIM(RAND),3,'0')+'3'
			&lcVar3 = suma3

			lcVar4 = "loActive.F40_"+PADL(ALLTRIM(RAND),3,'0')+'4'
			&lcVar4 = suma4

			lcVar5 = "loActive.F40_"+PADL(ALLTRIM(RAND),3,'0')+'5'
			&lcVar5 = suma5

		ENDSCAN

		ON ERROR &lcOldError

		SELECT (lcActive)
		GATHER NAME loActive

		USE IN tActive

		IF !llUsed
			USE IN (lcActive)
		ENDIF

	ENDPROC
&& ------------------------------SFARSIT: Completeaza_Date_Active_Imobilizate ------------------------------

&& ------------------------------INCEPUT: Completeaza_Date_Firma ------------------------------
	*!* Procedura:  Completeaza_Date_Firma
	*!* Parametri:
	*!* Data/Ora generarii: 17/02/2004 11:14
	*!* Autor: MARIUS.MUTU
	PROCEDURE  Completeaza_Date_Firma
		LPARAMETERS tcAliasFirma

		LOCAL lnNrRanduri, lcFirma, lcFisFirma, loFirma, llUsed


		lcFirma = ALLTRIM(THIS.cFirma)
		lcFisFirma = ADDBS(THIS.cPathKIT) + lcFirma + ".dbf"

		IF !FILE(lcFisFirma)
			RETURN .F.
		ENDIF

		llUsed = .T.
		IF !USED(lcFirma)
			llUsed = .F.
			USE (lcFisFirma) IN 0 SHARED ALIAS (lcFirma)
		ENDIF

		SELECT (lcFirma)
		SCATTER NAME loFirma BLANK

		SELE firma
		LOCA FOR ALLT(fscurt)=ALLT(nfscurt)
		loFirma.codi=VAL(ALLT(STRTRAN(UPPE(cod_fiscal),'R','')))

		SELECT (lcFirma)
		GATHER NAME loFirma

		IF !llUsed
			USE IN (lcFirma)
		ENDIF

	ENDPROC
&& ------------------------------SFARSIT: Completeaza_Date_Firma ------------------------------

&& ------------------------------INCEPUT: Date_Noi_Bilant------------------------------
	*!* Procedura:  Date_Noi_Bilant
	*!* Parametri:
	*!* Data/Ora generarii: 17/02/2004 14:26
	*!* Autor: MARIUS.MUTU
	PROCEDURE Date_Noi_Bilant
		
		LOCAL lnRaspuns 
		lnRaspuns = 7
		
		lnFisiere = 5
		DECLARE laFisiere[lnFisiere,2]

		laFisiere[1,1] = "Bilant"
		laFisiere[2,1] = "Cont Profit si Pierdere"
		laFisiere[3,1] = "Date Informative"
		laFisiere[4,1] = "Active Imobilizate"
		laFisiere[5,1] = "Firma"

		laFisiere[1,2] = "date1"
		laFisiere[2,2] = "date2"
		laFisiere[3,2] = "date3"
		laFisiere[4,2] = "date4"
		laFisiere[5,2] = "date5"

		FOR i = 1 TO lnFisiere
			
			lcMesaj = "Doriti sa creati un fisier gol pentru "+laFisiere[i,1]+"?"
			lnRaspuns = AMESSAGEBOX(lcMesaj,4+32) 

			IF lnRaspuns = 7 && buton=2
				LOOP
			ENDIF
			
			lcSpath = ADDBS(dirgen)+"_alfa\date_bilant\"
			lcDPath = this.cPathKIT
			lcFileName = laFisiere[i,2]
		
			THIS.Copie_Fisiere_Vide(lcSpath, lcDPath, lcFileName)
			
			IF i=1 && bilant -> copii si bazele de data access
				lcFileName = [*.mdb]
				lcFileS = lcSPath + lcFileName
				lcFileD = lcDPath + lcFileName				
				COPY FILE (lcFileS) TO (lcFileD)
			ENDIF 

		ENDFOR

	ENDPROC
&& ------------------------------SFARSIT: Date_Noi_Bilant------------------------------

ENDDEFINE



