*************************************************************************************
DO nastavsety
DO open_database
m.vsetko=.f.
**** parameter vsetko sa myslel ako export vsetkych skladov. program sa zatial vola iba s parametrom .t.
LOCAL novinka, exportuj, aj_hores, milandatum, recpol, recplt
PRIVATE m.hladajcdokl, m.hladajcstredisk, m.hladajidman, m.hladajpgmparam, m.hladajpartner, m.hladajdoklad, m.hladajdatumdokl, m.hladajpz1, m.hladajpz2, m.hladajcmena, m.hladajcdata
DO dopln_uctden_do_sksez WITH .t.

m.hladajcstredisk=m.gic_stredisk
SELECT 0
USE (m.gcpri_path+"strediska")
SELECT * FROM strediska INTO CURSOR stredy READWRITE 
INDEX ON c_stredisk TAG c_stredisk
USE IN strediska
IF INLIST(LOWER(m.gcuct_typ),"kros","navision","orion") AND m.gcuct_export_fa
	*/* export prijatych neprenesenych faktur
	DO exp_faktur
ENDIF 
IF m.vsetko
	IF m.issql
		DO CASE
			CASE "vdz"$LOWER(m.gchom_path) OR INLIST(LOWER(m.gcuct_typ), "asseco", "money", "kros", "navision", "orion")
				*** priebezny export skladovych pohybov sa nerobi
			CASE  "bystri"$LOWER(m.gchom_path)
				USE (m.sqlprefix+"rdokladyneexportovane") ALIAS doklx IN 0
				=CURSORSETPROP("Buffering",5,"doklx")
				SELECT * FROM doklx INTO CURSOR uctexpo WHERE INLIST(operace,"PE","VE","VR","VV","PV","PI","PC") .AND. INLIST(c_stredisk,-21,-24,-26,-71) READWRITE 
			CASE LOWER(m.gcuct_typ)="ekoadam"
				USE (m.sqlprefix+"rdokladyneexportovane") ALIAS doklx IN 0
				=CURSORSETPROP("Buffering",5,"doklx")
				SELECT * FROM doklx INTO CURSOR uctexpo WHERE INLIST(operace,"PE","VE","VR","VV","PV","PI","PC") .AND. INLIST(c_stredisk,-71) READWRITE 
			OTHERWISE
				USE (m.sqlprefix+"rdokladyneexportovane") ALIAS doklx IN 0
				=CURSORSETPROP("Buffering",5,"doklx")
				SELECT * FROM doklx INTO CURSOR uctexpo READWRITE 
		ENDCASE
	ELSE 
		IF !USED("doklady")
			USE (m.fn_doklady) IN 0 ALIAS doklady
		ENDIF 
		IF !USED("partneri")
			USE (m.fn_partneri) IN 0 ALIAS partneri
		ENDIF 
		DO CASE
			CASE "vdz"$LOWER(m.gchom_path) OR INLIST(LOWER(m.gcuct_typ), "asseco", "money", "kros", "navision", "orion")
				*** priebezny export skladovych pohybov sa nerobi
			CASE  "bystri"$LOWER(m.gchom_path)
				SELECT doklady.*, partneri.partner FROM doklady LEFT JOIN partneri ON doklady.c_partner=partneri.c_partner INTO CURSOR uctexpo WHERE EMPTY(uctexport) .AND. INLIST(operace,"PE","VE","VR","VV","PV","PI","PC") .AND. INLIST(c_stredisk,-21,-24,-26,-71) READWRITE 
			CASE LOWER(m.gcuct_typ)="ekoadam"
				SELECT doklady.*, partneri.partner FROM doklady LEFT JOIN partneri ON doklady.c_partner=partneri.c_partner INTO CURSOR uctexpo WHERE EMPTY(uctexport) .AND. INLIST(operace,"PE","VE","VR","VV","PV","PI","PC") .AND. INLIST(c_stredisk,-71) READWRITE 
			OTHERWISE
				SELECT doklady.*, partneri.partner FROM doklady LEFT JOIN partneri ON doklady.c_partner=partneri.c_partner INTO CURSOR uctexpo WHERE EMPTY(uctexport) READWRITE 
		ENDCASE
	ENDIF 
ELSE
	IF m.issql
		DO CASE
			CASE "vdz"$LOWER(m.gchom_path) OR INLIST(LOWER(m.gcuct_typ), "asseco", "money", "kros", "navision", "orion")
				*** priebezny export skladovych pohybov sa nerobi
			CASE  "bystri"$LOWER(m.gchom_path)
				USE (m.sqlprefix+"rdokladyneexportovanestredisko") ALIAS doklx IN 0
				=CURSORSETPROP("Buffering",5,"doklx")
				SELECT * FROM doklx INTO CURSOR uctexpo WHERE INLIST(operace,"PE","VE","VR","VV","PV","PI","PC") .AND. INLIST(c_stredisk,-21,-24,-26,-71) READWRITE 
			CASE LOWER(m.gcuct_typ)="ekoadam"
				USE (m.sqlprefix+"rdokladyneexportovanestredisko") ALIAS doklx IN 0
				=CURSORSETPROP("Buffering",5,"doklx")
				SELECT * FROM doklx INTO CURSOR uctexpo WHERE INLIST(operace,"PE","VE","VR","VV","PV","PI","PC") .AND. INLIST(c_stredisk,-71) READWRITE 
			OTHERWISE
				USE (m.sqlprefix+"rdokladyneexportovanestredisko") ALIAS doklx IN 0
				=CURSORSETPROP("Buffering",5,"doklx")
				SELECT * FROM doklx INTO CURSOR uctexpo READWRITE 
		ENDCASE
	ELSE 
		USE (m.fn_doklady) IN 0 ALIAS doklady
		USE (m.fn_partneri) IN 0 ALIAS partneri
		DO CASE
			CASE "vdz"$LOWER(m.gchom_path) OR INLIST(LOWER(m.gcuct_typ), "asseco", "money", "kros", "navision", "orion")
				*** priebezny export skladovych pohybov sa nerobi
			CASE  "bystri"$LOWER(m.gchom_path)
				SELECT doklady.*, partneri.partner FROM doklady LEFT JOIN partneri ON doklady.c_partner=partneri.c_partner INTO CURSOR uctexpo WHERE EMPTY(uctexport) .AND. INLIST(operace,"PE","VE","VR","VV","PV","PI","PC") .AND. INLIST(c_stredisk,-21,-24,-26,-71) READWRITE 
			CASE LOWER(m.gcuct_typ)="ekoadam"
				SELECT doklady.*, partneri.partner FROM doklady LEFT JOIN partneri ON doklady.c_partner=partneri.c_partner INTO CURSOR uctexpo WHERE EMPTY(uctexport) .AND. INLIST(operace,"PE","VE","VR","VV","PV","PI","PC") .AND. INLIST(c_stredisk,-71) READWRITE  
			OTHERWISE
				SELECT doklady.*, partneri.partner FROM doklady LEFT JOIN partneri ON doklady.c_partner=partneri.c_partner INTO CURSOR uctexpo WHERE EMPTY(uctexport) AND c_stredisk=m.gic_stredisk READWRITE  
		ENDCASE
	ENDIF 
ENDIF
IF USED("uctexpo") AND RECCOUNT("uctexpo")>0
	=vytvor_obr_uex(.t.)
ELSE
	IF "vdz"$LOWER(m.gchom_path) OR INLIST(LOWER(m.gcuct_typ),"money","kros")
	ELSE
		=MESSAGEBOX("Nič nové na exportovanie obratov nepribudlo",64,"Export do účtovníctva",2000)
	ENDIF
ENDIF
DO pozavirej WITH "u_ex_sum, u_ex_obr, uctexpo, doklady, skupiny, partneri, karty, obr, obraty, doklx, stredy, obrpol, obr1"



IF m.gcuct_trzba
	IF "vdz"$LOWER(m.gchom_path)
	ELSE 
		IF LOWER(m.gcuct_typ)="kros" AND INLIST(LOWER(m.gcuct_spec),"kosice","masaryk")
			IF m.issql
				USE (m.sqlprefix+"rsksezuctoneprenesene") IN 0 ALIAS sk_sez
				IF LOWER(m.gcuct_typ)="kros" AND INLIST(LOWER(m.gcuct_spec),"kosice","masaryk")
					SELECT DISTI uzaverka, id_kas, .f. as vyber, .f. as prenos FROM sk_sez WHERE LEFT(id_kas,1)="0" INTO CURSOR sez_exp READWRITE 
	 			ELSE
					SELECT DISTI uzaverka FROM sk_sez INTO CURSOR sez_exp READWRITE 
				ENDIF			
				USE IN sk_sez
			ELSE 
				USE (m.gccen_path+"sk_sez.dbf") IN 0
				IF LOWER(m.gcuct_typ)="kros" AND INLIST(LOWER(m.gcuct_spec),"kosice","masaryk")
					SELECT DISTI uzaverka, id_kas, .f. as vyber, .f. as prenos FROM sk_sez WHERE !uctexport AND LEFT(id_kas,1)="0" INTO CURSOR sez_exp READWRITE 
				ELSE
					SELECT DISTI uzaverka FROM sk_sez WHERE !uctexport INTO CURSOR sez_exp READWRITE 
				ENDIF			
				USE IN sk_sez
			ENDIF 
			IF USED("sez_exp") AND RECCOUNT("sez_exp")>0
				IF !m.issql
					IF ! FILE(m.gcucto_path + "u_ex_plt.dbf")
						DO creafile WITH (m.gcucto_path + "u_ex_plt.dbf")
					ENDIF
					IF ! FILE(m.gcucto_path + "u_ex_pol.dbf")
						DO creafile WITH (m.gcucto_path + "u_ex_pol.dbf")
					ENDIF
					SELECT 0
					USE (m.gcucto_path + "u_ex_plt.dbf") SHARED ALIAS u_ex_plt
					SELECT 0
					USE (m.gcucto_path + "u_ex_pol.dbf") SHARED ALIAS u_ex_pol
					USE vuexplt ALIAS uexplt IN 0
					USE vuexpol ALIAS uexpol IN 0
				ELSE 
					USE (m.sqlprefix+"ruexplt") ALIAS uexplt IN 0
					USE (m.sqlprefix+"ruexpol") ALIAS uexpol IN 0
				ENDIF 		
				=CURSORSETPROP("Buffering", 5, "uexplt")
				=CURSORSETPROP("Buffering", 5, "uexpol")
				*/* vyber typu uctovnictva

				*/* uprava pre kosice hotel - vyber uzavierky trzieb, kontrola trzby, zauctovanie do ucta KROS
				DO FORM exptrzby1
				*/* koniec - kosice hotel
			ENDIF 
			DO pozavirej WITH "sez_exp"
		ELSE
			IF !uexsk (.t.,"","",IIF(m.issql,m.cdata,m.gccen_path))
				=MESSAGEBOX("Pribudli nové položky. Niektoré uzávierky budú exportované neskôr.",48,"Export do účtovníctva",2000)
			ELSE 
				DO gen_exp IN uctoexp WITH .F.,STR(YEAR(DATE()),4,0),STR(MONTH(DATE()),2,0)
			ENDIF		
		*/* koniec typ uctovnictva
		ENDIF	
	ENDIF 
ENDIF 	
*/* trzby hores
*/* ****************************************
IF (m.gcuct_hores) .AND. !EMPTY(m.hor_path) .AND. (FILE(m.hor_path+"hfak.dbf") .OR. m.hor_sql)
	SELECT 0
	IF m.hor_sql
		IF test_hor_con()
			USE hores_hfak ALIAS hfak 
			SELECT DISTINCT DTOS(datum) AS uzaverka, TTOD(datum) as datum,.F. AS uctexport FROM hfak INTO CURSOR hor_uzav READWRITE 
		ENDIF 
	ELSE  
		USE (m.hor_path+"hfak.dbf")
		SELECT DISTINCT DTOS(datum) AS uzaverka, datum,.F. AS uctexport FROM hfak INTO CURSOR hor_uzav READWRITE 
	ENDIF 
	INDEX ON datum TAG datum
	DO pozavirej WITH "hfak"
	IF USED("hor_uzav") AND RECCOUNT("hor_uzav")>0
		IF m.issql
			USE (m.sqlprefix+"ruexarchplatby_zoznam_uzavierok" ALIAS archivprenosov IN 0
			SELECT 0
			USE (m.sqlprefix+"rhoruzav") ALIAS horcen
			INDEX on datum TAG datum
			=CURSORSETPROP("Buffering",5,"horcen")
		ELSE 
			IF FILE(m.gcdat_path+"uexarchplatby.dbf")
				USE (m.gcdat_path+"uexarchplatby.dbf") IN 0
				SELECT DISTINCT uzaverka FROM uexarchplatby INTO CURSOR archivprenosov
				USE IN uexarchplatby
			ENDIF 
			IF FILE(m.gcucto_path+"u_ex.dbf")
				SELECT 0
				USE (m.gcucto_path+"u_ex")
				DELETE ALL
				USE
			ENDIF 
			IF ! FILE(m.gcucto_path + "u_ex_plt.dbf")
				DO creafile WITH (m.gcucto_path + "u_ex_plt.dbf")
			ENDIF
			IF ! FILE(m.gcucto_path + "u_ex_pol.dbf")
				DO creafile WITH (m.gcucto_path + "u_ex_pol.dbf")
			ENDIF
			IF !USED("u_ex_plt")
				USE (m.gcucto_path + "u_ex_plt.dbf") SHARED IN 0
			ENDIF
			IF !USED("u_ex_pol")
				USE (m.gcucto_path + "u_ex_pol.dbf") SHARED IN 0
			ENDIF
			IF FILE(m.gccen_path+"hor_uzav.dbf")
				SELECT 0
				USE (m.gccen_path+"hor_uzav.dbf") ALIAS horcen ORDER datum
			ENDIF 
		ENDIF 
		IF USED("horcen")
			SELECT hor_uzav
			SET RELATION TO datum INTO  horcen
			DELETE FOR !EMPTY(horcen.datum) .AND. horcen.uctexport
		ENDIF
		LOCAL m.oldproc
		m.oldproc=SET("procedure")
		SET PROCEDURE TO uexsk ADDITIVE 
		IF USED("archivprenosov")
			SELECT hor_uzav
			SCAN ALL
				SELECT archivprenosov
				LOCATE FOR uzaverka==hor_uzav.uzaverka
				IF !FOUND()
					IF !hores_sk(.t.,ALLTRIM(hor_uzav.uzaverka),ALLTRIM(hor_uzav.uzaverka))
						=MESSAGEBOX("Pribudli nové položky. Uzávierka "+hor_uzav.uzaverka+CHR(10)+"bude exportovaná neskôr.",48,"Export do účtovníctva",2000)
					ENDIF
				ENDIF
				SELECT hor_uzav
			ENDSCAN
			USE IN archivprenosov
		ELSE  
			SELECT hor_uzav
			SCAN ALL
				IF !hores_sk(.t.,ALLTRIM(hor_uzav.uzaverka),ALLTRIM(hor_uzav.uzaverka))
					=MESSAGEBOX("Pribudli nové položky. Uzávierka "+hor_uzav.uzaverka+CHR(10)+"bude exportovaná neskôr.",48,"Export do účtovníctva",2000)
				ENDIF
				SELECT hor_uzav
			ENDSCAN
		ENDIF
		SET PROCEDURE TO &oldproc
		RELEASE m.oldproc
		SELECT hor_uzav
		IF RECCOUNT()>0 AND USED("u_ex_polozky") AND USED("u_ex_platby")
			SELECT 0
			DO gen_exp IN uctoexp WITH .F.,STR(YEAR(DATE()),4,0),STR(MONTH(DATE()),2,0)
			SELECT hor_uzav
			REPLACE ALL uctexport WITH .T.
			IF USED("horcen")
				SELECT hor_uzav
				SCAN ALL
					SELECT horcen
					IF SEEK(hor_uzav.datum)
						REPLACE uctexport WITH .T.
					ELSE
						INSERT INTO horcen (datum, uzaverka, uctexport) VALUES (hor_uzav.datum,DTOS(hor_uzav.datum),.T.)
					ENDIF
					SELECT hor_uzav
				ENDSCAN
				IF m.issql
					=TABLEUPDATE(.t.,.t.,"horcen")
				ENDIF 
				USE IN horcen
				USE IN hor_uzav
			ELSE
				SELECT hor_uzav
				COPY ALL TO (m.gccen_path+"hor_uzav") WITH CDX
				USE
			ENDIF
		ELSE
			=MESSAGEBOX("Nič nové na exportovanie tržieb HORESu nepribudlo",64,"Export do účtovníctva",2000)
		ENDIF
	ELSE
		=MESSAGEBOX("Nič nové na exportovanie tržieb HORESu nepribudlo",64,"Export do účtovníctva",2000)
	ENDIF
ENDIF
*/* koniec trzby hores
	
CLOSE DATABASES
RETURN .f.




