*:*****************************************************************************
#DEFINE uc_exp_verze 20030610



*!*********************************************************************
PROCEDURE gen_exp
PARAMETERS sumar,rok,mesiac,exp_meno
PUBLIC uct_mena
IF PARAMETERS()<4
	m.exp_meno=DTOS(DATE())
ENDIF
m.uct_mena=1
FOR i=1 TO ALEN(en_meny,1)
	IF en__meny(m.i,4)>=(m.rok+m.mesiac)
		m.uct_mena=m.i
		EXIT
	ENDIF
ENDFOR
DO CASE
	CASE LOWER(m.gcuct_typ)=="sap" AND EMPTY(m.gcuct_spec) && VDZ
		DO gen_exp_sap WITH m.exp_meno,m.rok,m.mesiac,m.sumar
	CASE LOWER(m.gcuct_typ)=="orion" && MLADOST,LOPUSNA
		IF m.sumar
			DO gen_exp_chemosvit WITH m.exp_meno,m.rok,m.mesiac
		ENDIF 
		DO gen_exp_orion_trzby WITH m.sumar,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="magma" && ELEKTROVOD - Penzion pod Skalnym mestom
		DO gen_exp_magma WITH m.exp_meno,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="sap" AND LOWER(m.gcuct_spec)="nbs" && BYSTRINA
		DO crea_xml WITH m.sumar,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="rero" && SLALOM CLUB
		DO gen_exp_rero WITH m.sumar,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="softip" && SKI CENTRE LEVOCA
		DO gen_exp_softip WITH m.sumar,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="asseco" && PATRIA
		DO gen_exp_asseco WITH m.sumar,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="pohoda" && ERB BANSKA STIAVNICA
		DO gen_exp_pohoda WITH m.sumar,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="epos" && SARIS PARK
		DO gen_exp_epos WITH m.sumar,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="ekoadam" && PRAMEN DUDINCE
		DO gen_exp_ekoadam WITH m.sumar,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)="kros" AND INLIST(LOWER(m.gcuct_spec),"kosice","xcxcmasaryk") && KOSICE HOTEL, MASARYKOV DVOR
		DO gen_exp_kros_kosice WITH m.sumar,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="kros" && ATRIUM
		DO gen_exp_kros WITH m.sumar,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="proluc" && Danubia Gate
		IF !USED("food_dat")
			IF m.issql
				USE (m.sqlprefix+"rfooddat") IN 0 ALIAS food_dat
			ELSE 
				USE (m.fn_food_dat) ALIAS food_dat IN 0
			ENDIF 
			SELECT food_dat
			LOCATE FOR ALLTRIM(pgm_param)="PROLUC"
			m.evidencia=ALLTRIM(UPPER(stredskup))
			USE
		ELSE
			SELECT food_dat
			LOCATE FOR ALLTRIM(pgm_param)="PROLUC"
			m.evidencia=ALLTRIM(UPPER(stredskup))
		ENDIF 
		IF EMPTY(m.evidencia)
			m.evidencia="INT"
		ENDIF 
		DO gen_exp_proluc WITH m.sumar,m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="karat" && OFZ
		DO gen_exp_karat WITH m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="money" && Park Piestany
		DO gen_exp_money WITH m.rok,m.mesiac
	CASE LOWER(m.gcuct_typ)=="navision" && Boboty
		DO gen_exp_navision WITH m.sumar, m.rok,m.mesiac
ENDCASE

*!*********************************************************************

*!*********************************************************************
PROCEDURE exp_new
DO pozavirej WITH "u_ex_obraty, u_ex_platby, u_ex_polozky"
WAIT "Výstupný súbor je prázdny" AT 22, 22 WIND TIME 1


*!*********************************************************************
PROCEDURE ini_files
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
	IF ! FILE (m.gcucto_path + "u_ex_obr.dbf")
		DO creafile WITH (m.gcucto_path + "u_ex_obr.dbf")
	ENDIF
	IF ! FILE (m.gccen_path + "uexarchplatby.dbf")
		DO creafile WITH (m.gccen_path + "uexarchplatby.dbf")
	ENDIF
	IF ! FILE (m.gccen_path + "uexarchpolozky.dbf")
		DO creafile WITH (m.gccen_path + "uexarchpolozky.dbf")
	ENDIF
	IF ! FILE (m.gccen_path + "uexarchobraty.dbf")
		DO creafile WITH (m.gccen_path + "uexarchobraty.dbf")
	ENDIF
	IF ! FILE (m.gccen_path + "uexarchstrava.dbf")
		DO creafile WITH (m.gccen_path + "uexarchstrava.dbf")
	ENDIF
ENDIF 
DO pozavirej WITH "u_ex_plt,u_ex_pol, u_ex_obr, u_ex, u_ex_sum, dan_dokl, uexarchpolozky, uexarchplatby, uexarchobraty"


PROCEDURE gen_exp_sap
PARAMETERS exp_meno,mrok,mmesiac,kontroluj
IF VARTYPE(m.exp_meno)="N"
	m.exp_meno=ALLTRIM(STR(m.exp_meno,10,0))
ENDIF
PRIVATE dotextu, uctfond,uctfinstred,uctfinpol,oldsetdele
m.oldsetdele=SET("dele")
SET DELETED ON
m.uctfond="07401"
m.uctfinstred="VDZF"
m.uctfinpol="633011"
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
m.gcuexp_path = ALLTRIM(m.gcuexp_path)
IF ! DIRECTORY(m.gcuexp_path)
	MKDIR (m.gcuexp_path)
ENDIF
IF USED("u_ex_obraty")
	SELECT datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka FROM u_ex_obraty GROUP BY id_man,pz,datum,doklad,datum_dokl,MD,dal INTO CURSOR u_doklady READWRITE WHERE operace<>"FA"
	DELETE FOR EMPTY(datum)
	DELETE FOR ciastka=0
	DELETE FOR LEFT(pz,2)="PV"
	DELETE FOR LEFT(pz,2)="PB"
	INDEX ON LEFT(pz,2) TAG aaa
	SELECT u_doklady
	gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
	gen_exp_had.SHOW()
	gen_exp_had.set_max(20)
	gen_exp_had.INCREMENT("Externý príjem, výdaj")
	LOCATE FOR LEFT(pz,2)="PE" .OR. LEFT(pz,2)="VE" .OR. LEFT(pz,2)="VR"
	IF FOUND()
		m.exp_subor="SKLADY" + "_" + exp_meno+ ".csv"
		IF FILE(m.gcuexp_path+m.exp_subor)
			ERASE(m.gcuexp_path+m.exp_subor)
		ENDIF
		m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
		IF m.lihandle > 0
			m.uct00=""
			m.dotextu="Sklad"
			m.datum="xsacdsa"
			m.poradie=0			
			SCAN FOR LEFT(pz,2)="PE" .OR. LEFT(pz,2)="VE" .OR. LEFT(pz,2)="VR"
				IF m.datum=u_doklady.datum
					m.poradie=m.poradie+1
				ELSE 
					m.datum=u_doklady.datum
					m.poradie=0
					DO sap_skl_00
				ENDIF 
				DO sap_skl_01 WITH m.poradie
				m.uct00=m.uct00+'40;' &&Uctovaci kluc
				m.uct00=m.uct00+ALLTRIM(u_doklady.MD)+';' &&Ucet
				DO sap_skl_koniec

				DO sap_skl_02 WITH m.poradie
				m.uct00=m.uct00+'50;' &&Uctovaci kluc
				m.uct00=m.uct00+ALLTRIM(u_doklady.dal)+';' &&Ucet
				DO sap_skl_koniec
			ENDSCAN
			=FCLOSE(m.lihandle)
		ENDIF
	ENDIF

	gen_exp_had.INCREMENT("Inventúra")
	LOCATE FOR LEFT(pz,2)="PI"
	IF FOUND()
		m.exp_subor="SKLINV" + "_" + m.exp_meno+ ".csv"
		IF FILE(m.gcuexp_path+m.exp_subor)
			ERASE(m.gcuexp_path+m.exp_subor)
		ENDIF
		m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
		IF m.lihandle > 0
			m.uct00=""
			m.datum="xsacdsa"
			m.poradie=0			
			SCAN FOR LEFT(pz,2)="PI"
				DO CASE
					CASE u_doklady.id_man="71"
						m.dotextu="Hl.sklad-inventura"
					CASE u_doklady.id_man="41"
						m.dotextu="Kuchyna-inventura"
					OTHERWISE
						m.dotextu="Bar-inventura"
				ENDCASE
				IF m.datum=u_doklady.datum
					m.poradie=m.poradie+1
				ELSE 
					m.datum=u_doklady.datum
					m.poradie=0
					DO sap_skl_00
				ENDIF 

				DO sap_skl_01 WITH m.poradie
				m.uct00=m.uct00+'40;' &&Uctovaci kluc
				IF u_doklady.ciastka<0
					m.uct00=m.uct00+ALLTRIM(u_doklady.MD)+';' &&Ucet
				ELSE
					m.uct00=m.uct00+ALLTRIM(u_doklady.dal)+';' &&Ucet
				ENDIF
				DO sap_skl_koniec

				DO sap_skl_02 WITH m.poradie
				m.uct00=m.uct00+'50;' &&Uctovaci kluc
				IF u_doklady.ciastka<0
					m.uct00=m.uct00+ALLTRIM(u_doklady.dal)+';' &&Ucet
				ELSE
					m.uct00=m.uct00+ALLTRIM(u_doklady.MD)+';' &&Ucet
				ENDIF
				DO sap_skl_koniec
			ENDSCAN
			=FCLOSE(m.lihandle)
		ENDIF
	ENDIF

	gen_exp_had.INCREMENT("Interný výdaj")
	LOCATE FOR LEFT(pz,2)="VV"
	IF FOUND()
		m.exp_subor="SKLPRV" + "_" + m.exp_meno+ ".csv"
		IF FILE(m.gcuexp_path+m.exp_subor)
			ERASE(m.gcuexp_path+m.exp_subor)
		ENDIF
		m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
		IF m.lihandle > 0
			m.uct00=""
			m.dotextu=""
			m.datum="xsacdsa"
			m.poradie=0			
			SCAN FOR LEFT(pz,2)="VV"
				DO CASE
					CASE u_doklady.id_man="71"
						DO CASE
							CASE SUBSTR(u_doklady.pz,3,2)="41"
								m.dotextu='Hl.sklad-kuchyna'
							CASE INLIST(SUBSTR(u_doklady.pz,3,2),"51","61","52")
								m.dotextu='Hl.sklad-bar'
							OTHERWISE
								m.dotextu='Hl.sklad-?'
						ENDCASE
					CASE u_doklady.id_man="41"
						DO CASE
							CASE SUBSTR(u_doklady.pz,3,2)="71"
								m.dotextu='Kuchyna-hl.sklad'
							CASE INLIST(SUBSTR(u_doklady.pz,3,2),"51","61","52")
								m.dotextu='Kuchyna-bar'
							OTHERWISE
								m.dotextu='Kuchyna-?'
						ENDCASE
					OTHERWISE
						DO CASE
							CASE SUBSTR(u_doklady.pz,3,2)="71"
								m.dotextu='Bar-hl.sklad'
							CASE SUBSTR(u_doklady.pz,3,2)="41"
								m.dotextu='Bar-kuchyna'
							OTHERWISE
								m.dotextu='Bar'
						ENDCASE
				ENDCASE
				IF m.datum=u_doklady.datum
					m.poradie=m.poradie+1
				ELSE 
					m.datum=u_doklady.datum
					m.poradie=0
					DO sap_skl_00
				ENDIF 

				DO sap_skl_01 WITH m.poradie
				m.uct00=m.uct00+'40;' &&Uctovaci kluc
				m.uct00=m.uct00+ALLTRIM(u_doklady.MD)+';' &&Ucet
				DO sap_skl_koniec

				DO sap_skl_02 WITH m.poradie
				m.uct00=m.uct00+'50;' &&Uctovaci kluc
				m.uct00=m.uct00+ALLTRIM(u_doklady.dal)+';' &&Ucet
				DO sap_skl_koniec
			ENDSCAN
			=FCLOSE(m.lihandle)
		ENDIF
	ENDIF


	gen_exp_had.INCREMENT("Spotreba")
	LOCATE FOR LEFT(pz,2)="VK"
	IF FOUND()
		m.exp_subor="SKLSPR" + "_" + m.exp_meno+ ".csv"
		IF FILE(m.gcuexp_path+m.exp_subor)
			ERASE(m.gcuexp_path+m.exp_subor)
		ENDIF
		m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
		IF m.lihandle > 0
			m.uct00=""
			m.datum="xsacdsa"
			m.poradie=0			
			SCAN FOR LEFT(pz,2)="VK"
				DO CASE
					CASE u_doklady.id_man="71"
						m.dotextu="Spotreba-hl.sklad"
					CASE u_doklady.id_man="41"
						m.dotextu="Spotreba-kuchyna"
					OTHERWISE
						m.dotextu="Spotreba-bar"
				ENDCASE
				IF m.datum=u_doklady.datum
					m.poradie=m.poradie+1
				ELSE 
					m.datum=u_doklady.datum
					m.poradie=0
					DO sap_skl_00
				ENDIF 

				DO sap_skl_01 WITH m.poradie 
				IF u_doklady.ciastka<=0
					m.uct00=m.uct00+'50;' &&Uctovaci kluc
				ELSE
					m.uct00=m.uct00+'40;' &&Uctovaci kluc
				ENDIF 			
				m.uct00=m.uct00+ALLTRIM(u_doklady.dal)+';' &&Ucet
				DO sap_skl_koniec

				DO sap_skl_02 WITH m.poradie
				IF u_doklady.ciastka<=0
					m.uct00=m.uct00+'40;' &&Uctovaci kluc
				ELSE
					m.uct00=m.uct00+'50;' &&Uctovaci kluc
				ENDIF 
				m.uct00=m.uct00+ALLTRIM(u_doklady.MD)+';' &&Ucet
				DO sap_skl_koniec
			ENDSCAN
			=FCLOSE(m.lihandle)
		ENDIF
	ENDIF
	USE IN u_doklady
ENDIF 

*** Trzby ***
IF m.gcuct_trzba AND USED("u_ex_platby") AND USED("u_ex_polozky")
	IF !m.issql
		IF !FILE(m.gccen_path+"sap_cd.dbf")
			SELECT 0
			CREATE TABLE (m.gccen_path+"sap_cd") FREE (meno c(8), pc i, rok c(4), mesiac c(2), den c(2))
			USE
		ENDIF 
	ENDIF 
	IF m.kontroluj
		IF m.issql
			USE (m.sqlprefix+"rhoruzav") ALIAS horcen IN 0
			INDEX on datum TAG datum
		ELSE 
			IF FILE(m.gccen_path+"hor_uzav.dbf")
				USE (m.gccen_path+"hor_uzav.dbf") IN 0 ALIAS horcen
			ENDIF 
		ENDIF 
		IF USED("horcen")
			DELETE FROM u_ex_platby WHERE id_kas="WH" AND uzaverka in (select uzaverka FROM horcen WHERE uctexport)
			DELETE FROM u_ex_polozky WHERE id_kas="WH" AND uzaverka in (select uzaverka FROM horcen WHERE uctexport)
			USE IN horcen
		ENDIF
		IF m.issql
			USE (m.sqlprefix+"rsksezuctoneprenesene") ALIAS sk_sez
		ELSE 
			IF FILE(m.gccen_path+"sk_sez.dbf")
				USE (m.gccen_path+"sk_sez") ORDER uzaverka ALIAS sk_sez IN 0
			ENDIF 
		ENDIF 
		IF USED("sk_sez")
			IF m.issql
				DELETE FROM u_ex_platby WHERE id_kas<>"WH" AND !(uzaverka in (select uzaverka FROM sk_sez))
				DELETE FROM u_ex_polozky WHERE id_kas<>"WH" AND !(uzaverka in (select uzaverka FROM sk_sez))
			ELSE
				DELETE FROM u_ex_platby WHERE id_kas<>"WH" AND !(uzaverka in (select uzaverka FROM sk_sez WHERE !uctexport))
				DELETE FROM u_ex_polozky WHERE id_kas<>"WH" AND !(uzaverka in (select uzaverka FROM sk_sez WHERE !uctexport))
			ENDIF 
			USE IN sk_sez
		ENDIF
	ENDIF
	*** Faktury ***
	SELECT DISTINCT datum_dokl FROM u_ex_platby WHERE LEFT(poznamka,13)="Platba N_UVER" INTO CURSOR pldni READWRITE 
	IF RECCOUNT()>0
		gen_exp_had.INCREMENT("Faktúry")
		LOCAL cislosuboru
		IF m.issql
			USE (m.sqlprefix+"rsksezuzav") IN 0 ALIAS sez
		ELSE 
			USE (m.gccen_path+"sk_txt") ORDER uzuc IN 0
		ENDIF 
		SCAN ALL
			m.plden=pldni.datum_dokl
			m.cislosuboru=dajsapcdcislo("FAKTUR",STR(YEAR(m.plden),4,0),STRTRAN(STR(MONTH(m.plden),2,0)," ","0"),STRTRAN(STR(DAY(m.plden),2,0)," ","0"))
			m.exp_subor="FAKTUR_"+DTOS(m.plden)+PADL(ALLTRIM(STR(m.cislosuboru,2,0)),2,"0")+".csv"
			IF FILE(m.gcuexp_path+m.exp_subor)
				ERASE(m.gcuexp_path+m.exp_subor)
			ENDIF
			m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
			IF m.lihandle > 0
	*** Food ***
				SELECT uzaverka, u_cis, datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_polozky GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_dokl1 WHERE id_kas<>"WH" AND datum_dokl=m.plden READWRITE 
				INDEX ON pz TAG pz
				SELECT uzaverka, u_cis, id_kas, datum, id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_platby GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_doklady WHERE LEFT(poznamka,13)="Platba N_UVER" AND id_kas<>"WH" AND datum_dokl=m.plden READWRITE 
				IF !prazdna()
					SELECT u_doklady
					m.uct00=""
					SCAN ALL
						IF m.issql
							SELECT sez
							LOCATE FOR uzaverka=u_doklady.uzaverka AND id_kas=u_doklady.id_kas
							m.hladajcuzaverka=sez.c_uzaverka
							m.hladajucet=VAL(SUBSTR(u_doklady.u_cis,3))
							IF USED("sk_txt")
								=REQUERY("sk_txt")
							ELSE
								USE (m.sqlprefix+"rsktxt1ucet") ALIAS sk_txt IN 0
							ENDIF 
						ELSE
							SELECT sk_txt
							=SEEK(u_doklady.u_cis+u_doklady.uzavrka )
						ENDIF 
						m.dotextu="Fa - služby"
						m.pz=u_doklady.pz
						DO sap_trz_00

						DO sap_trz_01_1
						m.uct00=m.uct00+ALLTRIM(sk_txt.hjmeno)+';' &&Nazov odberatela
						m.uct00=m.uct00+ALLTRIM(sk_txt.ico)+';' &&ICO odberatela
						m.uct00=m.uct00+ALLTRIM(sk_txt.adresa1)+';' &&Ulica a cislo
						m.uct00=m.uct00+ALLTRIM(sk_txt.adresa2)+';' &&Miesto

						m.psc=STRTRAN(ALLTRIM(sk_txt.adresa3)," ","")
						IF LEN(m.psc)=5
							m.psc=LEFT(m.psc,3)+" "+RIGHT(m.psc,2)
						ELSE
							m.psc="000 00"
						ENDIF
						m.uct00=m.uct00+m.psc+';' &&PSC
						m.uct00=m.uct00+'sk;' &&Krajina
						m.uct00=m.uct00+'sk;' &&Jazyk
						m.uct00=m.uct00+ALLTRIM(sk_txt.ico)+';' &&ICO
						m.uct00=m.uct00+ALLTRIM(sk_txt.dic)+';' &&DIC
						DO sap_trz_01_3

						DO sap_trz_02
						SELECT u_doklady
					ENDSCAN
				ENDIF
				DO pozavirej WITH "u_doklady, u_dokl1"
	*** Hores ***
				SELECT datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_polozky GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_dokl1 WHERE id_kas="WH" AND datum_dokl=m.plden READWRITE 
				INDEX ON pz TAG pz
				SELECT datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_platby GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_doklady WHERE id_kas="WH" AND "UVER"$poznamka  AND datum_dokl=m.plden READWRITE 
				IF !prazdna()
					SELECT 0
					SELECT * FROM (m.hor_path+"hnab") INTO TABLE (m.gcpri_path+"hnab")
					INDEX ON nabor TAG nabor
					USE
					USE IN hnab
					USE (m.gcpri_path+"hnab") ORDER nabor
					SELECT u_doklady
					SET RELATION TO LEFT(partner,5) INTO hnab
					m.uct00=""
					SCAN ALL
						m.dotextu="Fa - služby"
						m.pz=u_doklady.pz
						DO sap_trz_00

						DO sap_trz_01_1
						m.uct00=m.uct00+ALLTRIM(hnab.naborn)+';' &&Nazov
						m.uct00=m.uct00+ALLTRIM(hnab.ico)+';' &&ICO odberatela
						m.uct00=m.uct00+ALLTRIM(hnab.adr1)+';' &&Ulica a cislo
						m.uct00=m.uct00+ALLTRIM(hnab.adr2)+';' &&Miesto

						m.psc=STRTRAN(ALLTRIM(hnab.adr3)," ","")
						IF LEN(m.psc)=5
							m.psc=LEFT(m.psc,3)+" "+RIGHT(m.psc,2)
						ELSE
							m.psc="000 00"
						ENDIF
						m.uct00=m.uct00+m.psc+';' &&PSC

						m.uct00=m.uct00+STRTRAN(UPPER(ALLTRIM(hnab.zem)),"SVK","EUR")+';' &&Krajina
						m.uct00=m.uct00+STRTRAN(UPPER(ALLTRIM(hnab.zem)),"SVK","EUR")+';' &&Jazyk
						m.uct00=m.uct00+ALLTRIM(hnab.ico)+';' &&ICO
						m.uct00=m.uct00+ALLTRIM(hnab.dic)+';' &&DIC
						DO sap_trz_01_3

						DO sap_trz_02
						SELECT u_doklady
					ENDSCAN
					USE IN hnab
				ENDIF
				USE IN u_dokl1
				USE IN u_doklady
			ENDIF
			SELECT pldni
			=FCLOSE(m.lihandle)
		ENDSCAN
	ENDIF
	DO pozavirej WITH "pldni, sez, sk_txt, hnab, u_doklady, u_dokl1"

	*** Hotovost ***
	SELECT DISTINCT datum_dokl FROM u_ex_platby WHERE LEFT(poznamka,13)="Platba Hotove" INTO CURSOR pldni READWRITE 
	IF RECCOUNT()>0
		gen_exp_had.INCREMENT("Hotovosť")
		SCAN ALL
			m.plden=pldni.datum_dokl
			m.cislosuboru=dajsapcdcislo("HOTOVO",STR(YEAR(m.plden),4,0),STRTRAN(STR(MONTH(m.plden),2,0)," ","0"),STRTRAN(STR(DAY(m.plden),2,0)," ","0"))
			m.exp_subor="HOTOVO_"+DTOS(m.plden)+PADL(ALLTRIM(STR(m.cislosuboru,2,0)),2,"0")+".csv"
			IF FILE(m.gcuexp_path+m.exp_subor)
				ERASE(m.gcuexp_path+m.exp_subor)
			ENDIF
			m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
			IF m.lihandle > 0
	*** Food ***
				SELECT datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_polozky GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_dokl1 WHERE id_kas<>"WH" AND datum_dokl=m.plden READWRITE 
				INDEX ON pz TAG pz
				SELECT datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_platby GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_doklady WHERE LEFT(poznamka,13)="Platba Hotove" AND id_kas<>"WH" AND datum_dokl=m.plden READWRITE 
				IF !prazdna()
					SELECT u_doklady
					m.uct00=""
					SCAN ALL
						m.dotextu="Fa - služby"
						m.pz=u_doklady.pz
						DO sap_trz_00

						DO sap_trz_01_1
						DO sap_trz_01_2
						DO sap_trz_01_3

						DO sap_trz_02

						SELECT u_doklady
					ENDSCAN
				ENDIF
				DO pozavirej WITH "u_doklady, u_dokl1"
	*** Hores ***
				SELECT datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_polozky GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_dokl1 WHERE id_kas="WH" AND datum_dokl=m.plden READWRITE 
				INDEX ON pz TAG pz
				SELECT datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_platby GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_doklady HAVING id_kas="WH" AND "Hotove"$poznamka AND datum_dokl=m.plden READWRITE 
				IF !prazdna()
					SELECT 0
					SELECT * FROM (m.hor_path+"hnab") INTO TABLE (m.gcpri_path+"hnab")
					INDEX ON nabor TAG nabor
					USE
					USE IN hnab
					USE (m.gcpri_path+"hnab") ORDER nabor
					SELECT u_doklady
					SET RELATION TO LEFT(partner,5) INTO hnab
					m.uct00=""
					SCAN ALL
						m.dotextu="Fa - služby"
						m.pz=u_doklady.pz
						DO sap_trz_00

						DO sap_trz_01_1
						IF EMPTY(hnab.naborn)
							DO sap_trz_01_2
						ELSE
							m.uct00=m.uct00+ALLTRIM(hnab.naborn)+';' &&Nazov
							m.uct00=m.uct00+ALLTRIM(hnab.ico)+';' &&ICO odberatela
							m.uct00=m.uct00+ALLTRIM(hnab.adr1)+';' &&Ulica a cislo
							m.uct00=m.uct00+ALLTRIM(hnab.adr2)+';' &&Miesto

							m.psc=STRTRAN(ALLTRIM(hnab.adr3)," ","")
							IF LEN(m.psc)=5
								m.psc=LEFT(m.psc,3)+" "+RIGHT(m.psc,2)
							ELSE
								m.psc="000 00"
							ENDIF
							m.uct00=m.uct00+m.psc+';' &&PSC

							m.uct00=m.uct00+STRTRAN(UPPER(ALLTRIM(hnab.zem)),"SVK","EUR")+';' &&Krajina
							m.uct00=m.uct00+STRTRAN(UPPER(ALLTRIM(hnab.zem)),"SVK","EUR")+';' &&Jazyk
							m.uct00=m.uct00+ALLTRIM(hnab.ico)+';' &&ICO
							m.uct00=m.uct00+ALLTRIM(hnab.dic)+';' &&DIC
						ENDIF
						DO sap_trz_01_3

						DO sap_trz_02
						SELECT u_doklady
					ENDSCAN
					USE IN hnab
				ENDIF
				DO pozavirej WITH "u_doklady, u_dokl1"
			ENDIF
			SELECT pldni
			=FCLOSE(m.lihandle)
		ENDSCAN
	ENDIF
	USE IN pldni

	*** Kredit ***
	SELECT DISTINCT datum_dokl FROM u_ex_platby WHERE LEFT(poznamka,9)="Platba K_" INTO CURSOR pldni READWRITE 
	IF RECCOUNT()>0
		gen_exp_had.INCREMENT("Kredit")
		SCAN ALL
			m.plden=pldni.datum_dokl
			m.cislosuboru=dajsapcdcislo("KREDIT",STR(YEAR(m.plden),4,0),STRTRAN(STR(MONTH(m.plden),2,0)," ","0"),STRTRAN(STR(DAY(m.plden),2,0)," ","0"))
			m.exp_subor="KREDIT_"+DTOS(m.plden)+PADL(ALLTRIM(STR(m.cislosuboru,2,0)),2,"0")+".csv"
			IF FILE(m.gcuexp_path+m.exp_subor)
				ERASE(m.gcuexp_path+m.exp_subor)
			ENDIF
			m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
			IF m.lihandle > 0
	*** Food ***
				SELECT datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_polozky GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_dokl1 HAVING id_kas<>"WH" AND datum_dokl=m.plden READWRITE 
				INDEX ON pz TAG pz
				SELECT datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_platby GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_doklady HAVING LEFT(poznamka,9)="Platba K_" AND  id_kas<>"WH" AND datum_dokl=m.plden READWRITE 
				IF !prazdna()
					SELECT u_doklady
					m.uct00=""
					SCAN ALL
						m.dotextu="Fa - služby"
						m.pz=u_doklady.pz
						DO sap_trz_00

						DO sap_trz_01_1
						DO sap_trz_01_2
						DO sap_trz_01_3

						DO sap_trz_02
						SELECT u_doklady
					ENDSCAN
				ENDIF
				DO pozavirej WITH "u_doklady, u_dokl1"
	*** Hores ***
				SELECT datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_polozky GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_dokl1 WHERE id_kas="WH" AND datum_dokl=m.plden READWRITE 
				INDEX ON pz TAG pz
				SELECT datum,id_man, SUM(castka) AS ciastka, MD,dal,md2,dal2,pz,partner,doklad,datum_dokl,poznamka FROM u_ex_platby GROUP BY datum,datum_dokl,MD,dal,poznamka,pz INTO CURSOR u_doklady HAVING id_kas="WH" AND "K_"$poznamka AND datum_dokl=m.plden READWRITE 
				IF !prazdna()
					SELECT 0
					SELECT * FROM (m.hor_path+"hnab") INTO TABLE (m.gcpri_path+"hnab")
					INDEX ON nabor TAG nabor
					USE
					USE IN hnab
					USE (m.gcpri_path+"hnab") ORDER nabor
					SELECT u_doklady
					SET RELATION TO LEFT(partner,5) INTO hnab
					m.uct00=""
					SCAN ALL
						m.dotextu="Fa - služby"
						m.pz=u_doklady.pz
						DO sap_trz_00

						DO sap_trz_01_1
						IF EMPTY(hnab.naborn)
							DO sap_trz_01_2
						ELSE
							m.uct00=m.uct00+ALLTRIM(hnab.naborn)+';' &&Nazov
							m.uct00=m.uct00+ALLTRIM(hnab.ico)+';' &&ICO odberatela
							m.uct00=m.uct00+ALLTRIM(hnab.adr1)+';' &&Ulica a cislo
							m.uct00=m.uct00+ALLTRIM(hnab.adr2)+';' &&Miesto

							m.psc=STRTRAN(ALLTRIM(hnab.adr3)," ","")
							IF LEN(m.psc)=5
								m.psc=LEFT(m.psc,3)+" "+RIGHT(m.psc,2)
							ELSE
								m.psc="000 00"
							ENDIF
							m.uct00=m.uct00+m.psc+';' &&PSC

							m.uct00=m.uct00+STRTRAN(UPPER(ALLTRIM(hnab.zem)),"SVK","EUR")+';' &&Krajina
							m.uct00=m.uct00+STRTRAN(UPPER(ALLTRIM(hnab.zem)),"SVK","EUR")+';' &&Jazyk
							m.uct00=m.uct00+ALLTRIM(hnab.ico)+';' &&ICO
							m.uct00=m.uct00+ALLTRIM(hnab.dic)+';' &&DIC
						ENDIF
						DO sap_trz_01_3

						DO sap_trz_02
						SELECT u_doklady
					ENDSCAN
					USE IN hnab
				ENDIF
				DO pozavirej WITH "u_doklady, u_dokl1"
			ENDIF
			SELECT pldni
			=FCLOSE(m.lihandle)
		ENDSCAN
	ENDIF
	USE IN pldni

	IF m.kontroluj
		IF m.issql
			USE (m.sqlprefix+"rhoruzav") ALIAS horcen IN 0
			=CURSORSETPROP("Buffering",5,"horcen")
		ELSE
			IF FILE(m.gccen_path+"hor_uzav.dbf")
				USE (m.gccen_path+"hor_uzav") IN 0 ALIAS horcen
			ELSE 
				SELECT DISTINCT datum_dokl as datum, PADR(DTOS(datum_dokl),17) as uzaverka, .t. as uctexport  FROM u_ex_polozky WHERE id_kas="WH" INTO TABLE (m.gccen_path"hor_uzav")
			ENDIF 		
		ENDIF 
		IF USED("horcen")
			SELECT DISTINCT datum_dokl as datum, PADR(DTOS(datum_dokl),17) as uzaverka, .t. as uctexport  FROM u_ex_polozky WHERE id_kas="WH" INTO CURSOR plhores  READWRITE 
			UPDATE horcen SET uctexport=.t. from plhores WHERE horcen.uzaverka=plhores.uzaverka
			INSERT INTO horcen (uzaverka, datum, uctexport) SELECT uzaverka, datum, uctexport FROM plhores WHERE !(uzaverka in (sele uzaverka FROM horcen)) 
			IF m.issql
				=tux(.t.,.t.,"horcen")
			ENDIF
		ENDIF 
		DO pozavirej WITH "hor_uzav, horcen, plhores"
	ENDIF
ENDIF 
SET DELETED &oldsetdele
RELEASE gen_exp_had

PROCEDURE gen_exp_kros
PARAMETERS kontroluj,rokuct,mesuct
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.rokuct
m.hladajmesiac=m.mesuct
IF !m.issql
	IF !FILE(m.gccen_path+"sap_cd.dbf")
		SELECT 0
		CREATE TABLE (m.gccen_path+"sap_cd") FREE (meno c(8), pc i, rok c(4), mesiac c(2), den c(2), evidencia c(3), cisrad c(4))
		USE
	ENDIF 
ENDIF 

PRIVATE old_century,menoexp,oldsetdate,oldsetdele, riadkov, sumacelk,dokluzod,dokluzdo,prijemky, vydajky, ok
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
m.old_century=SET("century")
m.oldsetdate=SET("date")
m.oldsetdele=SET("dele")
SET DATE TO GERMAN
SET DELETED ON
m.gcuexp_path=ALLTRIM(IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path))
IF ! DIRECTORY(m.gcuexp_path)
	MKDIR (m.gcuexp_path)
ENDIF
SET CENTURY ON
IF !INLIST(LOWER(m.gcuct_spec),"kosice","masaryk")
	m.kontroluj=.f.
ENDIF 
gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
gen_exp_had.SHOW()
gen_exp_had.set_max(20)
gen_exp_had.INCREMENT("Sklady")
IF USED("u_ex_obraty")
	SELECT operace, datum, id_man, SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka,faktura,.F. AS storno,.F. AS vymaz, druh, m.hladajrok as rok, m.hladajmesiac as mesiac FROM u_ex_obraty GROUP BY id_man,pz,datum,doklad,datum_dokl,MD,dal INTO CURSOR u_doklady WHERE INLIST(LEFT(pz,1),"P","V") READWRITE 
*	REPLACE ALL druh WITH SUBSTR(pz,AT("|",pz,1)+1,10)
	IF m.gcuct_export_fa
		DELETE FOR INLIST(operace,"PE","VE","VR")
	ENDIF 	
	DELETE FOR EMPTY(datum)
	DELETE FOR EMPTY(MD) .OR. EMPTY(dal)
	SELECT u_doklady
	IF m.issql
		USE (m.sqlprefix+"ruexarchobraty_mesiacrok") ALIAS uexarch IN 0
	ELSE 
		IF !FILE(m.gccen_path+"uexarchobraty.dbf")
			DO creafile WITH (m.gccen_path+"uexarchobraty.dbf")
		ENDIF 
		IF !USED("uexarchobraty")
			USE (m.gccen_path+"uexarchobraty") IN 0
		ENDIF 
		USE vuexarchobraty_mesiacrok IN 0 ALIAS uexarch
	ENDIF 
	=CURSORSETPROP("Buffering",5,"uexarch")
	IF m.kontroluj
		DO kontrola_skladov
	ELSE
		SELECT 0
		IF m.issql
			USE (m.sqlprefix+"ruzaverka") ALIAS expuzav
			INDEX on rok+mesiac TAG kedy
		ELSE 
			USE (m.gcdat_path+"uzaverka") AGAIN ALIAS expuzav ORDER kedy
		ENDIF 
		SET FILTER TO c_stredisk=m.gic_stredisk
		GO BOTTOM
		m.rokuct=expuzav.rok
		m.mesuct=expuzav.mesiac
		IF EMPTY(m.rokuct) .OR. EMPTY(m.mesuct)
			m.rokuct=STR(YEAR(DATE()),4,0)
			m.mesuct=STRTRAN(STR(MONTH(DATE()),2,0)," ","0")
		ELSE
			m.mesuct=STRTRAN(STR(VAL(m.mesuct)+1,2,0)," ","0")
			IF m.mesuct="13"
				m.mesuct="01"
				m.rokuct=STR(VAL(m.rokuct)+1,4,0)
			ENDIF
		ENDIF
		USE IN expuzav
	ENDIF

	SELECT u_doklady
	DELETE FOR castka=0
	IF m.issql
		USE (m.sqlprefix+"rdoklady") IN 0 ALIAS doklady
		SELECT doklady
		INDEX on c_dokl TAG c_dokl
	ELSE 
		IF !USED("doklady")
			USE (m.fn_doklady) ALIAS doklady AGAIN IN 0 ORDER c_dokl
		ELSE
			SELECT doklady
			SET ORDER TO c_dokl
		ENDIF
	ENDIF 
	m.poraduz=dajsapcdcislo("Food",m.rokuct, m.mesuct,"",m.gcuct_evidencia1)
	m.evidencia=m.gcuct_evidencia1
	m.menoexp="Food"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")+".txt"


	SELECT u_doklady
	COUNT FOR !DELETED() TO assasas
	REPLACE ALL rok WITH m.rokuct, mesiac WITH m.mesuct
	SELECT id_man,SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,doklad,datum_dokl,poznamka,faktura,druh FROM u_doklady GROUP BY id_man,MD, dal, hs_md, hs_dal, md2, dal2, pz INTO CURSOR u_doklady1 ORDER BY id_man, pz READWRITE 

	IF RECCOUNT()>0
		SELECT 0
		IF FILE(m.gcuexp_path+m.menoexp)
			ERASE(m.gcuexp_path+m.menoexp)
		ENDIF
		m.lihandle= FCREATE(m.gcuexp_path + m.menoexp)
		IF m.lihandle > 0
			m.uct00=""
			m.dotextu="Sklad"
			DO kros_skl_00
			SELECT u_doklady1
			SCAN FOR LOWER(ALLTRIM(MD))<>"export" .and. castka<>0
				DO kros_skl_02
			ENDSCAN
			=FCLOSE(m.lihandle)
			IF FILE(m.gcuexp_path + m.menoexp)
				IF !EMPTY(m.uct_email_sklady)
					DO odosli_export_mailom WITH (m.gcuexp_path+m.menoexp), m.hotel_name, m.uct_email_sklady
				ENDIF
			ENDIF 
			SELECT u_doklady
			IF INLIST(LOWER(m.gcuct_spec),"kosice","masaryk")
				SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
					SELECT uexarch
					DELETE FOR datum=u_doklady.datum
					SELECT u_doklady
				ENDSCAN
				SELECT uexarch
				APPEND FROM DBF("u_doklady") FOR !storno .AND. !vymaz
				REPLACE c_data WITH m.cdata FOR c_data<>m.cdata
				REPLACE ALL mesiac WITH m.mesuct FOR mesiac<>m.mesuct
				REPLACE ALL rok WITH m.rokuct FOR rok<>m.rokuct
				=tux(.t.,.t.,"uexarch")
				DO pozavirej WITH "uexarch, uexarchobraty"
				IF !m.issql
					IF f_acc_ex(m.gcdat_path+"uexarchobraty")
						PACK
						USE
					ENDIF
				ENDIF 
			ENDIF 
		ENDIF
	ENDIF 
	DO pozavirej WITH "uexarch, uexarchobraty, u_doklady, u_doklady1, doklady, u_ex_obraty"
ENDIF 

*** Trzby ***
IF m.gcuct_trzba AND USED("u_ex_platby") AND USED("u_ex_polozky")
	gen_exp_had.INCREMENT("Tržby")
	SELECT SUM(castka) AS ciastka, md, dal, md2, dal2, hs_dal, hs_md, partner, pz, poznamka, $0 AS celkom, 1.000000000 AS koef, LEFT(pz,17) as uzaverka, SUBSTR(pz,19,2) as id_kas FROM u_ex_platby GROUP BY pz, poznamka, md, dal, md2, dal2, hs_md, hs_dal INTO CURSOR u_doklady READWRITE 
	SELECT SUM(castka) AS ciastka, pz, dal FROM u_ex_platby GROUP BY pz INTO CURSOR u_platby  READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	SELECT u_doklady
	SET RELATION TO ALLTRIM(pz) INTO u_platby
	REPLACE ALL u_doklady.celkom WITH u_platby.ciastka
	SET RELATION OFF INTO u_platby
	USE IN u_platby
	REPLACE ALL koef WITH IIF(celkom=0,1,ciastka/celkom)
	SELECT SUM(castka) AS ciastka, md, dal, hs_md, hs_dal, md2, dal2, pz, partner, poznamka, poznamka as txtdan, $0 AS danzakl, $0 AS dan, faktura FROM u_ex_polozky GROUP BY pz,poznamka, md, dal, md2, dal2, hs_md, hs_dal, faktura INTO CURSOR u_dokl1 READWRITE 
	SELECT u_dokl1
	REPLACE ALL txtdan WITH SUBSTR(txtdan,RAT(" ",ALLTRIM(txtdan)))
	REPLACE ALL dan WITH ciastka*VAL(txtdan)/(100+VAL(txtdan))
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT pz, SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, SUM(dan) as danxx, SUM(dan) as danxxx, partner, md, dal, md2, dal2, hs_md, hs_dal, poznamka, txtdan, faktura  FROM u_dokl1 GROUP BY pz, MD, dal, hs_md, hs_dal, txtdan, poznamka, faktura INTO CURSOR u_dokl2 READWRITE 
	INDEX on pz TAG pz
	SELECT pz, SUM(dan) AS dan FROM u_dokl1 GROUP BY pz INTO CURSOR u_doklxx READWRITE 
	INDEX on pz TAG pz
	USE IN u_dokl1
	SELECT u_dokl2
	SET RELATION TO pz INTO u_doklxx
	SET SKIP TO u_doklxx
	REPLACE ALL danxx WITH ground(u_doklxx.dan,2)
	SET RELATION OFF INTO u_doklxx
	USE IN u_doklxx
	REPLACE ALL ciastka WITH ground(ciastka,2), danzakl WITH ground(danzakl,2), dan WITH ground(dan,2)
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT pz, SUM(dan) AS dan FROM u_dokl2 GROUP BY pz INTO TABLE (m.gcucto_path+"u_doklxx")
	INDEX on pz TAG pz
	SELECT u_dokl2
	SET RELATION TO pz INTO u_doklxx
	SET SKIP TO u_doklxx
	REPLACE ALL danxxx WITH u_doklxx.dan
	SET RELATION OFF INTO u_doklxx
	USE IN u_doklxx
	SELECT u_dokl2
	m.ptz="yayayaya"
	SCAN ALL 	
		IF m.ptz=u_dokl2.pz
		ELSE 
			IF ALLTRIM(txtdan)<>"0"
				REPLACE dan	WITH dan+danxx-danxxx
				m.ptz=u_dokl2.pz
			ENDIF 
		ENDIF 
	ENDSCAN 
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT pz, SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2, poznamka, txtdan,SPACE(3) as typdokladu, LEFT(pz,17) as uzaverka, SUBSTR(pz,19,2) as id_kas, faktura  FROM u_dokl2 GROUP BY pz, MD, dal, md2, dal2, hs_md, hs_dal, txtdan, poznamka, faktura INTO CURSOR u_dokl READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	USE IN u_dokl2
	IF m.gcuct_perioda_trzby="D" 
		m.pouzavierkach=.t.
	ELSE
		m.pouzavierkach=m.trz_po_uzav
	ENDIF 
	SELECT u_doklady
	IF !prazdna()
		m.gcuexp_path = ALLTRIM(m.gcuexp_path)
		IF ! DIRECTORY(m.gcuexp_path)
			MKDIR (m.gcuexp_path)
		ENDIF
		SELECT uzaverka, id_kas, ciastka, md, dal as typdokladu, dal, md2, dal2, hs_dal, hs_md, poznamka, poznamka as pozn_pol, celkom, $0 AS danzakl, $0 AS dan, ;
			SPACE(5) AS sadzba, "A" as platba, SPACE(20) as faktura FROM u_doklady INTO CURSOR vondbf WHERE .f. READWRITE 
		UPDATE u_dokl SET ciastka=ROUND(u_dokl.ciastka*u_doklady.koef,2), danzakl=ROUND(u_dokl.danzakl*u_doklady.koef,2), dan=ROUND(u_dokl.dan*u_doklady.koef,2) FROM u_doklady WHERE u_dokl.pz=u_doklady.pz
		SELECT u_doklady
		IF m.pouzavierkach
			INSERT INTO vondbf (uzaverka, id_kas, ciastka, md, md2, dal2, hs_md, hs_dal, poznamka, platba, typdokladu) ;
				SELECT uzaverka, id_kas, SUM(ciastka), md, md2, dal2, hs_md, hs_dal, poznamka, "A", dal FROM u_doklady GROUP BY uzaverka, id_kas, md, dal, md2, dal2, hs_md, hs_dal, poznamka WHERE !EMPTY(md) AND ciastka<>0
		ELSE 
			INSERT INTO vondbf (id_kas, ciastka, md, md2, dal2, hs_md, hs_dal, poznamka, platba, typdokladu) ;
				SELECT id_kas, SUM(ciastka), md, md2, dal2, hs_md, hs_dal, poznamka, "A", dal FROM u_doklady GROUP BY id_kas, md, dal, md2, dal2, hs_md, hs_dal WHERE !EMPTY(md) AND ciastka<>0
		ENDIF 
		SELECT SUM(ciastka) as ciastka, uzaverka, typdokladu, ciastka as celkom, id_kas FROM vondbf INTO CURSOR aaa GROUP BY uzaverka, id_kas, typdokladu READWRITE 
		SELECT SUM(ciastka) as ciastka, uzaverka, id_kas FROM vondbf INTO CURSOR bbb GROUP BY uzaverka, id_kas
		UPDATE aaa SET celkom=bbb.ciastka FROM bbb WHERE aaa.uzaverka=bbb.uzaverka AND aaa.id_kas=bbb.id_kas
		USE IN bbb
		SELECT aaa
		SCAN ALL
			m.lidkas=aaa.id_kas
			m.uzaverka=aaa.uzaverka
			m.typdokladu=aaa.typdokladu
			m.koeficient=IIF(aaa.celkom=0,1,aaa.ciastka/aaa.celkom)
			IF m.pouzavierkach
				SELECT m.uzaverka as uzaverka, m.lidkas as id_kas, SUM(ciastka) as ciastka, md, dal, md2, dal2, hs_md, hs_dal, SUM(danzakl) as danzakl, SUM(dan) as dan, txtdan, poznamka,faktura,"B" FROM u_dokl WHERE !EMPTY(dal) AND ciastka<>0 AND uzaverka=m.uzaverka AND id_kas=m.lidkas GROUP BY md, dal, md2, dal2, hs_md, hs_dal, txtdan, poznamka, faktura INTO CURSOR bbb
				INSERT INTO vondbf (uzaverka, id_kas, ciastka, md, dal, md2, dal2, hs_md, hs_dal, danzakl, dan, sadzba, pozn_pol, platba, typdokladu, faktura) ;
					SELECT uzaverka, id_kas, ciastka*m.koeficient, md, dal, md2, dal2, hs_md, hs_dal, danzakl*m.koeficient, dan*m.koeficient, txtdan, poznamka,"B", m.typdokladu, faktura FROM bbb
			ELSE 
				SELECT "" as uzaverka, m.lidkas as id_kas, SUM(ciastka) as ciastka, md, dal, md2, dal2, hs_md, hs_dal, SUM(danzakl) as danzakl, SUM(dan) as dan, txtdan, poznamka,faktura,"B" FROM u_dokl WHERE !EMPTY(dal) AND ciastka<>0 AND id_kas=m.lidkas GROUP BY md, dal, md2, dal2, hs_md, hs_dal, txtdan, poznamka, faktura INTO CURSOR bbb
				INSERT INTO vondbf (id_kas, ciastka, md, dal, md2, dal2, hs_md, hs_dal, danzakl, dan, sadzba, pozn_pol, platba, typdokladu, faktura) ;
					SELECT id_kas, ciastka*m.koeficient, md, dal, md2, dal2, hs_md, hs_dal, danzakl*m.koeficient, dan*m.koeficient, txtdan, poznamka,"B", m.typdokladu, faktura FROM bbb
			ENDIF 
			USE IN bbb
		ENDSCAN 
		USE IN aaa
		SELECT uzaverka, id_kas, SUM(ciastka) AS ciastka, md, dal, md2, dal2, hs_md, hs_dal, SUM(danzakl) AS danzakl, SUM(dan) AS dan, sadzba, poznamka, typdokladu, pozn_pol, faktura FROM vondbf ;
			GROUP BY uzaverka, id_kas, md, dal, sadzba, md2, dal2, hs_md, hs_dal, typdokladu, pozn_pol, faktura INTO CURSOR vondbf2 READWRITE WHERE platba="B"
		SELECT uzaverka, id_kas, SUM(ciastka) AS ciastka, md, dal, md2, dal2, hs_md, hs_dal, 0000000000.00 AS cena0, 0000000000.00 AS cena5, 0000000000.00 AS cena23, 000000000.00 AS dan5, 000000000.00 AS dan23,.F. AS vymaz,.F. AS storno,poznamka, pozn_pol, typdokladu, faktura FROM vondbf WHERE platba="B";
			GROUP BY uzaverka, id_kas,  md, dal, md2, dal2, hs_md, hs_dal, pozn_pol, typdokladu, faktura INTO CURSOR vondbf1 READWRITE 
		m.riadkov=1
		SCAN ALL
			SELECT vondbf2
			SCAN FOR md=vondbf1.md .AND. dal=vondbf1.dal .AND. uzaverka=vondbf1.uzaverka .and. md2=vondbf1.md2 .and. dal2=vondbf1.dal2 .and. hs_md=vondbf1.hs_md .and. hs_dal=vondbf1.hs_dal .and. pozn_pol=vondbf1.pozn_pol .and. typdokladu=vondbf1.typdokladu .and. id_kas=vondbf1.id_kas .and. faktura=vondbf1.faktura
				DO CASE
					CASE ALLTRIM(sadzba)="0"
						REPLACE vondbf1.cena0 WITH vondbf2.danzakl
					CASE ALLTRIM(sadzba)=ALLTRIM(STR((m.uctdphlo-1)*100,10,0))
						REPLACE vondbf1.cena5 WITH vondbf2.danzakl, vondbf1.dan5 WITH vondbf2.dan
					OTHERWISE
						REPLACE vondbf1.cena23 WITH vondbf2.danzakl, vondbf1.dan23 WITH vondbf2.dan
				ENDCASE
			ENDSCAN
		ENDSCAN
		m.poraduz=dajsapcdcislo("Kasy",m.rokuct, m.mesuct,"","")
		m.evidencia=m.gcuct_evidencia2
		m.menoexp="Kasy"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,4,0)," ","0")+".txt"
		SELECT vondbf1
		COUNT TO m.assasas FOR !DELETED()
		IF m.assasas>0
			m.lihandle= FCREATE(m.gcuexp_path + m.menoexp)
			IF m.lihandle > 0
				SELECT vondbf1
				SELECT DISTINCT id_kas, uzaverka, typdokladu FROM vondbf1 INTO CURSOR kasuz
				IF RECCOUNT()>0
					IF !INLIST(LOWER(m.gcuct_spec),"masaryk")
						DO kros_trz_00
					ENDIF 
					SELECT kasuz
					SCAN ALL 
						m.lidkas=ALLTRIM(kasuz.id_kas)
						m.luzaverka=kasuz.uzaverka
						m.ltypdokladu=ALLTRIM(kasuz.typdokladu)
						SELECT SUM(ciastka) as ciastka, uzaverka, id_kas, $0 as c0,  $0 as c5, $0 as c23, $0 as d5, $0 as d23, $0 as cb FROM vondbf1 INTO CURSOR uct_polozky READWRITE WHERE uzaverka=m.luzaverka AND id_kas=m.lidkas AND typdokladu=m.ltypdokladu
						SELECT vondbf1
						SUM cena0 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))="0" .and. !("City tax"$pozn_pol) AND id_kas=lidkas AND uzaverka=luzaverka AND typdokladu=m.ltypdokladu
						SELECT uct_polozky
						REPLACE c0 WITH m.uct0
						SELECT vondbf1
						SUM cena0 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))="0" .and. ("City tax"$pozn_pol) AND id_kas=lidkas AND uzaverka=luzaverka AND typdokladu=m.ltypdokladu
						SELECT uct_polozky
						REPLACE cb WITH m.uct0
						SELECT vondbf1
						SUM cena5 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))=ALLTRIM(STR(m.uctdphlo*100-100,2,0)) AND id_kas=lidkas AND uzaverka=luzaverka AND typdokladu=m.ltypdokladu
						SELECT uct_polozky
						REPLACE c5 WITH m.uct0
						SELECT vondbf1
						SUM cena23 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))=ALLTRIM(STR(m.uctdphhi*100-100,2,0)) AND id_kas=lidkas AND uzaverka=luzaverka AND typdokladu=m.ltypdokladu
						SELECT uct_polozky
						REPLACE c23 WITH m.uct0
						SELECT vondbf1
						SUM dan5 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))=ALLTRIM(STR(m.uctdphlo*100-100,2,0)) AND id_kas=lidkas AND uzaverka=luzaverka AND typdokladu=m.ltypdokladu
						SELECT uct_polozky
						REPLACE d5 WITH m.uct0
						SELECT vondbf1
						SUM dan23 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))=ALLTRIM(STR(m.uctdphhi*100-100,2,0)) AND id_kas=lidkas AND uzaverka=luzaverka AND typdokladu=m.ltypdokladu
						SELECT uct_polozky
						REPLACE d23 WITH m.uct0
						IF !INLIST(LOWER(m.gcuct_spec),"masaryk")
							DO kros_trz_01 WITH m.luzaverka, m.ltypdokladu
						ENDIF 
						USE IN uct_polozky
						SELECT uzaverka, SUM(ciastka) as ciastka, md as u1 ,SPACE(6) as u2, poznamka as poznamka, hs_dal as stredisko, md2 as kv, hs_md as typ, faktura FROM vondbf GROUP BY poznamka, md, hs_md, hs_dal, md2, faktura WHERE id_kas=m.lidkas AND uzaverka=m.luzaverka AND typdokladu=m.ltypdokladu AND platba="A" INTO CURSOR uct_polozky READWRITE 
						SCAN FOR uct_polozky.ciastka<>0 
							IF !INLIST(LOWER(m.gcuct_spec),"masaryk")
								DO kros_trz_02
							ELSE 
								DO kros_trz_masaryk_02 WITH m.lidkas, m.luzaverka
							ENDIF 
						ENDSCAN 
						USE IN uct_polozky
						SELECT SUM(dan5+dan23) as ciastka, SPACE(6) as u1, dal2 as u2, "DPH "+IIF(m.lidkas="HO","Hores",m.lidkas) as poznamka, hs_md as stredisko, md2 as kv, hs_dal as typ, faktura FROM vondbf1 GROUP BY md, md2, dal2, hs_dal, faktura INTO CURSOR uct_polozky WHERE SUBSTR(pozn_pol,5,2)=m.lidkas AND uzaverka=m.luzaverka AND typdokladu=ltypdokladu READWRITE 
						SCAN FOR uct_polozky.ciastka<>0 
							IF !INLIST(LOWER(m.gcuct_spec),"masaryk")
								DO kros_trz_02
							ELSE 
								DO kros_trz_masaryk_02 WITH m.lidkas, m.luzaverka
							ENDIF 
						ENDSCAN 
						USE IN uct_polozky
						SELECT SUM(cena0+cena5+cena23) as ciastka, SPACE(6) as u1, dal as u2, "Trzba "+SUBSTR(pozn_pol,5) as poznamka, hs_dal as stredisko, md2 as kv, hs_md as typ, RIGHT(ALLTRIM(pozn_pol),2) as dan, faktura FROM vondbf1 GROUP BY dal, pozn_pol, md, hs_md, md2, faktura INTO CURSOR uct_polozky   WHERE SUBSTR(pozn_pol,5,2)=m.lidkas AND uzaverka=m.luzaverka AND typdokladu=m.ltypdokladu READWRITE 
						REPLACE typ WITH "V" FOR dan=" 0"
						SCAN FOR uct_polozky.ciastka<>0 
							IF !INLIST(LOWER(m.gcuct_spec),"masaryk")
								DO kros_trz_02
							ELSE 
								DO kros_trz_masaryk_02 WITH m.lidkas, m.luzaverka
							ENDIF 
						ENDSCAN
						USE IN uct_polozky
						SELECT kasuz
					ENDSCAN
					USE IN kasuz
					=FCLOSE(m.lihandle)
					IF FILE(m.gcuexp_path + m.menoexp)
						IF VARTYPE(m.uct_email_trzby)=="C" AND !EMPTY(m.uct_email_trzby)
							DO odosli_export_mailom WITH (m.gcuexp_path+m.menoexp), m.hotel_name, m.uct_email_trzby
						ENDIF
					ENDIF 
				ENDIF 
				SELECT vondbf1
			ENDIF 
		ENDIF 
		DO pozavirej WITH "uexarsk"
	ENDIF
	SET CENTURY &old_century
	SET DATE &oldsetdate
	SET DELETED &oldsetdele
	IF USED("vondbf1") AND !m.kontroluj
		SELECT disti uzaverka FROM vondbf1 INTO CURSOR sez_exp
	ENDIF 
	DO pozavirej WITH "vondbf, u_doklady, u_dokl, vondbf1, vondbf2, datumy, datumy2, u_ex_platby, u_ex_polozky, bbb"
ENDIF 
SET DELETED &oldsetdele
RELEASE gen_exp_had


PROCEDURE gen_exp_chemosvit
PARAMETERS exp_meno,m.mrok, m.mmesiac
PRIVATE kthotel,oddelovac,bolipartneri, oddelovac, oldsetdele
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.mrok
m.hladajmesiac=m.mmesiac
m.oldsetdele=SET("dele")
SET DELETED ON
m.oddelovac="|"
DO CASE
	CASE "mladost"$LOWER(m.gchom_path)
		m.kthotel="M"
	CASE "lopusna"$LOWER(m.gchom_path)
		m.kthotel="L"
	CASE "spoldom"$LOWER(m.gchom_path)
		m.kthotel="S"
	CASE "lopu"$LOWER(m.hotel_name)
		m.kthotel="L"
	CASE LOWER(m.gcuct_spec)="energochem"
		m.kzhotel="L"
	OTHERWISE
		m.kthotel="S"
ENDCASE
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
IF USED("u_ex_obraty")
	SELECT datum,id_man, SUM(castka) AS ciastka,MD,dal,hs_md,hs_dal,md2,dal2,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka,faktura FROM u_ex_obraty GROUP BY id_man,pz,datum,doklad,datum_dokl,MD,dal INTO CURSOR u_doklady READWRITE  WHERE operace<>"FA"
	DELETE FOR EMPTY(datum)
	DELETE FOR ciastka=0
	INDEX ON datum TAG aaa
	SELECT u_doklady
	IF !prazdna()
		DO pozavirej WITH "partaci"
		SELECT 0
		IF m.issql
			USE (m.sqlprefix+"rpartneriucto") ALIAS partaci
			INDEX on partner TAG partner
		ELSE 
			USE (m.gccen_path+"partneri") ORDER partner AGAIN ALIAS partaci
		ENDIF 
		SELECT u_doklady
		SET RELATION TO partner INTO partaci
		gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
		gen_exp_had.SHOW()
		gen_exp_had.set_max(20)
		gen_exp_had.INCREMENT("Externý príjem, výdaj")
		LOCATE FOR LEFT(pz,1)="P" .OR. LEFT(pz,1)="V"
		IF FOUND()
			m.gcuexp_path = ALLTRIM(m.gcuexp_path)
			IF ! DIRECTORY(m.gcuexp_path)
				MKDIR (m.gcuexp_path)
			ENDIF
			IF m.kthotel="M"
				m.exp_subor="MLADOST" + "_" + exp_meno+ ".txt"
			ELSE
				IF m.kthotel="L"
					m.exp_subor="LOPUSNA" + "_" + exp_meno+ ".txt"
				ELSE
					m.exp_subor="SPOLCENTRUM" + "_" + exp_meno+ ".txt"
				ENDIF
			ENDIF
			IF FILE(m.gcuexp_path+m.exp_subor)
				ERASE(m.gcuexp_path+m.exp_subor)
			ENDIF
			m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
			IF m.lihandle > 0
				m.uct00=""
				SCAN FOR LEFT(pz,2)<>"PB" .AND. LEFT(pz,2)<>"VB"
					m.uct00=m.kthotel+m.oddelovac					&&prevadzka "M"  Mladost, "L" / Lopusna
					m.uct00=m.uct00+u_doklady.id_man+m.oddelovac	&& sklad (71)
					m.uct00=m.uct00+STR(YEAR(u_doklady.datum_dokl))+'-'+PADL(ALLTRIM(STR(MONTH(u_doklady.datum_dokl),2,0)),2,"0")+m.oddelovac && obdobie ("2005-12")
					DO CASE 
						CASE LEFT(u_doklady.pz,2)="VR"
							m.uct00=m.uct00+"P"+m.oddelovac && typ dokladu ("P" - prijem,"V" - vydaj)
						CASE INLIST(LEFT(u_doklady.pz,2),"VC","PC")
							m.uct00=m.uct00+"V"+m.oddelovac && typ dokladu ("P" - prijem,"V" - vydaj)
						CASE INLIST(LEFT(u_doklady.pz,2),"PI")
							IF u_doklady.ciastka<0
								m.uct00=m.uct00+"V"+m.oddelovac && typ dokladu ("P" - prijem,"V" - vydaj)
							ELSE 
								m.uct00=m.uct00+"P"+m.oddelovac && typ dokladu ("P" - prijem,"V" - vydaj)
							ENDIF 
						OTHERWISE 
							m.uct00=m.uct00+LEFT(u_doklady.pz,1)+m.oddelovac && typ dokladu ("P" - prijem,"V" - vydaj)
					ENDCASE 
					IF LOWER(m.gcuct_spec)="energochem"
						m.uct00=m.uct00+PADL(ALLTRIM(u_doklady.datum),10,"0")+m.oddelovac && cislo dokladu ("00001") - c_dokl
					ELSE 
						m.uct00=m.uct00+PADL(ALLTRIM(u_doklady.doklad),5,"0")+m.oddelovac && cislo dokladu ("00001") - doklad	
					ENDIF 
					IF LEFT(pz,2)="PI" 
						IF u_doklady.ciastka>0
							m.uct00=m.uct00+ALLTRIM(u_doklady.hs_md)+m.oddelovac && stredisko MD (804)
							m.uct00=m.uct00+ALLTRIM(u_doklady.MD)+m.oddelovac && konto MD (501100)
							m.uct00=m.uct00+ALLTRIM(u_doklady.dal)+m.oddelovac && konto DAL (112410)
						ELSE
							m.uct00=m.uct00+ALLTRIM(u_doklady.hs_dal)+m.oddelovac && stredisko MD (804)
							m.uct00=m.uct00+ALLTRIM(u_doklady.md2)+m.oddelovac && konto MD (501100)
							m.uct00=m.uct00+ALLTRIM(u_doklady.dal2)+m.oddelovac && konto DAL (112410)
						ENDIF
					ELSE
						IF LEFT(pz,2)="VK" 
							IF u_doklady.ciastka<0
								m.uct00=m.uct00+ALLTRIM(u_doklady.hs_md)+m.oddelovac && stredisko MD (804)
								m.uct00=m.uct00+ALLTRIM(u_doklady.MD)+m.oddelovac && konto MD (501100)
								m.uct00=m.uct00+ALLTRIM(u_doklady.dal)+m.oddelovac && konto DAL (112410)
							ELSE 
								m.uct00=m.uct00+ALLTRIM(u_doklady.hs_md)+m.oddelovac && stredisko MD (804)
								m.uct00=m.uct00+ALLTRIM(u_doklady.Dal)+m.oddelovac && konto MD (501100)
								m.uct00=m.uct00+ALLTRIM(u_doklady.md)+m.oddelovac && konto DAL (112410)
							ENDIF 
						ELSE
							m.uct00=m.uct00+ALLTRIM(u_doklady.hs_md)+m.oddelovac && stredisko MD (804)
							m.uct00=m.uct00+ALLTRIM(u_doklady.MD)+m.oddelovac && konto MD (501100)
							m.uct00=m.uct00+ALLTRIM(u_doklady.dal)+m.oddelovac && konto DAL (112410)
						ENDIF 							
						
					ENDIF
					m.uct00=m.uct00+DTOC(u_doklady.datum_dokl)+m.oddelovac && datum pohybu na sklade ("21.3.2005")
					m.uct00=m.uct00+'0000000'+m.oddelovac && konstanta ("0000000")
					IF INLIST(LEFT(pz,2),"PC" ,"VR")
						m.uct00=m.uct00+ALLTRIM(STRTRAN(STR(u_doklady.ciastka,16,2),",","."))+m.oddelovac && cena (34.66)
					ELSE
						m.uct00=m.uct00+ALLTRIM(STRTRAN(STR(ABS(u_doklady.ciastka),16,2),",","."))+m.oddelovac && cena (34.66)
					ENDIF
					m.uct00=m.uct00+ALLTRIM(u_doklady.faktura)+m.oddelovac && dodaci list ("32564565")
					m.uct00=m.uct00+ALLTRIM(partaci.ico)+m.oddelovac && dodavatel ICO ("31747898")
					m.uct00=m.uct00+ALLTRIM(partaci.dic)+m.oddelovac && dodavatel DIC ("2020457489")
					= FPUTS(m.lihandle, m.uct00)
				ENDSCAN
				=FCLOSE(m.lihandle)
				IF FILE(m.gcuexp_path + m.exp_subor)
					DO CASE 
						CASE LOWER(m.gcuct_spec)="energochem"
							=posli_sap_energochem((m.gcuexp_path + m.exp_subor),"sklady")
						CASE !EMPTY(m.uct_email_sklady)
							LOCAL menosubjektu
							DO CASE 
								CASE m.kthotel="L"
									m.menosubjektu = "Sklady Lopušná:"+DTOC(DATE())
								CASE m.kthotel="M"
									m.menosubjektu = "Sklady Mladosť:"+DTOC(DATE())
								OTHERWISE 
									m.menosubjektu = "Sklady Spolcentrum:"+DTOC(DATE())
							ENDCASE 
							DO odosli_export_mailom WITH (m.gcuexp_path+m.exp_subor), m.menosubjektu, m.uct_email_sklady
							RELEASE menosubjektu
					ENDCASE 
				ENDIF 
			ENDIF
		ENDIF
		RELEASE gen_exp_had
	ENDIF
	**** Ak sa robil denny export faktur, musim oznacit doklady za vyexportovane
	IF USED("expfaktura")
		UPDATE expfaktura SET uctexport=.t. WHERE c_dokl IN (SELECT c_dokl FROM u_ex_obraty)
		=tux(.t.,.t.,"expfaktura")
	ENDIF 
	DO pozavirej WITH "u_doklady, partaci, u_ex_obraty"
ENDIF 
SET DELETED &oldsetdele
RETURN






PROCEDURE gen_exp_magma
PARAMETERS mexp_meno,m.mrok, m.mmesiac
PRIVATE kthotel,oddelovac,bolipartneri,oddelovac,cislodokladu,oldsetdele
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.rokuct
m.hladajmesiac=m.mesuct
m.oldsetdele=SET("dele")
SET DELETED ON
gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
gen_exp_had.SHOW()
gen_exp_had.set_max(20)
m.oddelovac=" "
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
IF USED("u_ex_obraty")
	SELECT datum,id_man, SUM(castka) AS ciastka,MD,dal,hs_md,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka,faktura FROM u_ex_obraty GROUP BY id_man,pz,datum,doklad,datum_dokl,MD,dal INTO CURSOR u_doklady READWRITE WHERE operace<>"FA"
	DELETE FOR EMPTY(datum)
	DELETE FOR ciastka=0
	INDEX ON datum TAG aaa
	SELECT u_doklady
	IF !prazdna()
		SELECT u_doklady
		gen_exp_had.INCREMENT("Externý príjem, výdaj")
		LOCATE FOR INLIST(LEFT(pz,2),"PE","VE","VK","VR")
		IF FOUND()
			m.gcuexp_path = ALLTRIM(m.gcuexp_path)
			IF ! DIRECTORY(m.gcuexp_path)
				MKDIR (m.gcuexp_path)
			ENDIF
			m.exp_subor="FOOD_" + m.mexp_meno+ ".txt"
			IF FILE(m.gcuexp_path+m.exp_subor)
				ERASE(m.gcuexp_path+m.exp_subor)
			ENDIF
			m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
			IF m.lihandle > 0
				m.uct00=""
				m.uct00="; Export udajov pre uctovnictvo"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="[Popis]"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Verzia=2"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Mandant=PEN"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Klient=0010"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Rok="+RIGHT(m.mrok,2)
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Cislo="+m.mmesiac
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Datum="+DTOC(DATE())
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Cas="+TIME()
				= FPUTS(m.lihandle, m.uct00)
				m.uct00=";"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="[DATA-Start]"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00=""
				SCAN FOR INLIST(LEFT(pz,2),"PE","VE","VK","VR")
					IF LEFT(u_doklady.pz,1)="P"
						m.uct00="DOK=PR  "+m.oddelovac  && druh dokladu C(4) od pozicie 5
						m.uct00=m.uct00+RIGHT(m.mrok,1)+PADR(ALLTRIM(STR(60000+VAL(u_doklady.doklad),7,0)),7)+m.oddelovac && cislo dokladu N(8) od pozicie 10
						m.uct00=m.uct00+SPACE(2)+m.oddelovac &&adresny box / nepotrebne C(2) od pozicie 19
						m.uct00=m.uct00+SPACE(8)+m.oddelovac &&cislo adresy / nepotrebne N(8) od pozicie 22
						m.uct00=m.uct00+LEFT(LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2),4)+RIGHT(LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2),2)+m.oddelovac	&& datum vystavenia dokladu C(6) od pozicie 31
						m.uct00=m.uct00+LEFT(LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2),4)+RIGHT(LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2),2)+m.oddelovac	&& datum odkedy sa pocitasplatnost C(6) od pozicie 38
						m.uct00=m.uct00+LEFT(LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2),4)+RIGHT(LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2),2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
	*					*Podla prikladu
						m.uct00=m.uct00+LEFT(LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2),4)+RIGHT(LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2),2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 52
						m.uct00=m.uct00+SPACE(8) && 9 prazdnych znakov od pozicie 58
						m.uct00=m.uct00+RIGHT(m.mrok,1)+PADR(ALLTRIM(STR(60000+VAL(u_doklady.doklad),11,0)),11," ")+m.oddelovac && variabilny symbol dokladu C(12) od pozicie 67
						m.uct00=m.uct00+RIGHT(m.mrok,1)+PADR(ALLTRIM(STR(60000+VAL(u_doklady.doklad),11,0)),11," ")+m.oddelovac && parovaci symbol dokladu C(12) od pozicie 80
						m.uct00=m.uct00+SPACE(12)+m.oddelovac && cislo objednavky z dokladu/ nepotrebne od pozicie 93
						m.uct00=m.uct00+"EUR "+m.oddelovac && kod meny C(3) od pozicie 106
						m.uct00=m.uct00+STR(1*1000,9,0)+m.oddelovac && kurz meny*1000 N(9) od pozicie 110
						m.uct00=m.uct00+STR(1,4,0)+m.oddelovac && pocet jednotiek meny N(4) od pozicie 120
						m.uct00=m.uct00+LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2)+m.oddelovac	&& datum kurzu C(6) od pozicie 125
						m.uct00=m.uct00+STR(ABS(u_doklady.ciastka*100),12,0)+m.oddelovac && suma v mene dokladu*100 N(12) od pozicie 132
						m.uct00=m.uct00+STR(ABS(u_doklady.ciastka*100),12,0)+m.oddelovac && suma v mene uctovnictva*100 N(12) od pozicie 146
						m.uct00=m.uct00+SPACE(12)+m.oddelovac && suma dane v mene uctovnictva*100 / nepotrebne od pozicie 160 N(12)
						m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska / nepotrebne od pozicie 174 C(10)
						m.uct00=m.uct00+SPACE(12)+m.oddelovac && oznacenie nakladovej jednotky / nepotrebne od pozicie 185 C(12)
						m.uct00=m.uct00+SPACE(10)+m.oddelovac && zakazka / nepotrebne od pozicie 198 C(10)
						m.uct00=m.uct00+SPACE(6)+m.oddelovac && oznacenie sprostredkovatela / nepotrebne od pozicie 209 N(6)
						m.uct00=PADR(m.uct00,264," ")+"666" &&& 666 podla prikladu od pozicie 265
					ELSE
						m.uct00="DOK=VYD "+m.oddelovac  && druh dokladu C(4) od pozicie 5
						IF LEFT(u_doklady.pz,2)="VE" .or. LEFT(u_doklady.pz,2)="VR"
							m.uct00=m.uct00+RIGHT(m.mrok,1)+PADR(ALLTRIM(STR(70000+VAL(u_doklady.doklad),7,0)),7)+m.oddelovac && cislo dokladu N(8) od pozicie 10
						ELSE
							m.uct00=m.uct00+RIGHT(m.mrok,1)+PADR(ALLTRIM(STR(60000+VAL(u_doklady.doklad),7,0)),7)+m.oddelovac && cislo dokladu N(8) od pozicie 10
						ENDIF
						m.uct00=m.uct00+SPACE(2)+m.oddelovac &&adresny box / nepotrebne C(2) od pozicie 19
						m.uct00=m.uct00+SPACE(8)+m.oddelovac &&cislo adresy / nepotrebne N(8) od pozicie 22
						m.uct00=m.uct00+LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2)+m.oddelovac	&& datum vystavenia dokladu C(6) od pozicie 31
						m.uct00=m.uct00+LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2)+m.oddelovac	&& datum odkedy sa pocitasplatnost C(6) od pozicie 38
						m.uct00=m.uct00+LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
	*					*Podla prikladu
						m.uct00=m.uct00+LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 52
						m.uct00=m.uct00+SPACE(8) && 9 prazdnych znakov od pozicie 58
						m.uct00=m.uct00+SPACE(12)+m.oddelovac && variabilny symbol dokladu C(12) od pozicie 67
						m.uct00=m.uct00+SPACE(12)+m.oddelovac && parovaci symbol dokladu C(12) od pozicie 80
						m.uct00=m.uct00+SPACE(12)+m.oddelovac && cislo objednavky z dokladu/ nepotrebne od pozicie 93
						m.uct00=m.uct00+"EUR" +m.oddelovac&& kod meny C(3) od pozicie 106
						m.uct00=m.uct00+STR(1*1000,9,0)+m.oddelovac && kurz meny*1000 N(9) od pozicie 110
						m.uct00=m.uct00+STR(1,4,0)+m.oddelovac && pocet jednotiek meny N(4) od pozicie 120
						m.uct00=m.uct00+LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2)+m.oddelovac	&& datum kurzu C(6) od pozicie 125
						m.uct00=m.uct00+STR(ABS(u_doklady.ciastka*100),12,0)+m.oddelovac && suma v mene dokladu*100 N(12) od pozicie 132
						m.uct00=m.uct00+STR(ABS(u_doklady.ciastka*100),12,0)+m.oddelovac && suma v mene uctovnictva*100 N(12) od pozicie 146
						m.uct00=m.uct00+SPACE(12)+m.oddelovac && suma dane v mene uctovnictva*100 / nepotrebne od pozicie 160 N(12)
						m.uct00=m.uct00+PADR("421",10," ")+m.oddelovac && oznacenie hospodarskeho strediska / nepotrebne od pozicie 174 C(10)
						m.uct00=m.uct00+SPACE(12)+m.oddelovac && oznacenie nakladovej jednotky / nepotrebne od pozicie 185 C(12)
	*					m.uct00=m.uct00+PADR("210023",10," ")+m.oddelovac && zakazka / nepotrebne od pozicie 198 C(10)
					ENDIF
					= FPUTS(m.lihandle, m.uct00)
					IF LEFT(u_doklady.pz,1)="P"
						m.uct00="UCT=PR  "+m.oddelovac  && druh dokladu C(4) od pozicie 5
						m.uct00=m.uct00+RIGHT(m.mrok,1)+PADR(ALLTRIM(STR(60000+VAL(u_doklady.doklad),7,0)),7)+m.oddelovac && cislo dokladu N(8) od pozicie 10
						m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.dal),8," ")+m.oddelovac && ucet C(8) od pozicie 19
						m.uct00=m.uct00+STR(ABS(u_doklady.ciastka*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
						m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
						m.uct00=m.uct00+"666" && text uctovneho pripadu C(30) od pozicie 44 (666 - podla prikladu)
					ELSE
						m.uct00="UCT=VYD "+m.oddelovac  && druh dokladu C(4) od pozicie 5
						IF LEFT(u_doklady.pz,2)="VE" .or. LEFT(u_doklady.pz,2)="VR"
							m.uct00=m.uct00+RIGHT(m.mrok,1)+PADR(ALLTRIM(STR(70000+VAL(u_doklady.doklad),7,0)),7)+m.oddelovac && cislo dokladu N(8) od pozicie 10
						ELSE
							m.uct00=m.uct00+RIGHT(m.mrok,1)+PADR(ALLTRIM(STR(60000+VAL(u_doklady.doklad),7,0)),7)+m.oddelovac && cislo dokladu N(8) od pozicie 10
						ENDIF
						m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.dal),8," ")+m.oddelovac && ucet C(8) od pozicie 19
						m.uct00=m.uct00+STR(ABS(u_doklady.ciastka*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
						m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
						m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.partner),30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
						m.uct00=m.uct00+PADR("421",10," ")+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
						m.uct00=m.uct00+SPACE(12)+m.oddelovac && oznacenie nakladovej jednotky C(12) od pozicie 86
	*					m.uct00=m.uct00+PADR("230023",10," ")+m.oddelovac && oznacenie zakazky C(10) od pozicie 99
						m.uct00=m.uct00+SPACE(6) && oznacenie sprostredkovatela N(6) od pozicie 110
					ENDIF
					= FPUTS(m.lihandle, m.uct00)
					IF LEFT(u_doklady.pz,1)="P"
						m.uct00="UCT=PR  "+m.oddelovac  && druh dokladu C(4) od pozicie 5
						m.uct00=m.uct00+RIGHT(m.mrok,1)+PADR(ALLTRIM(STR(60000+VAL(u_doklady.doklad),7,0)),7)+m.oddelovac && cislo dokladu N(8) od pozicie 10
						m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.MD),8," ")+m.oddelovac && ucet C(8) od pozicie 19
						m.uct00=m.uct00+STR(ABS(u_doklady.ciastka*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
						m.uct00=m.uct00+"M"+m.oddelovac && strana uctovania C(1) od pozicie 42
						m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.partner),30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					ELSE
						m.uct00="UCT=VYD "+m.oddelovac  && druh dokladu C(4) od pozicie 5
						IF LEFT(u_doklady.pz,2)="VE" .or. LEFT(u_doklady.pz,2)="VR"
							m.uct00=m.uct00+RIGHT(m.mrok,1)+PADR(ALLTRIM(STR(70000+VAL(u_doklady.doklad),7,0)),7)+m.oddelovac && cislo dokladu N(8) od pozicie 10
						ELSE
							m.uct00=m.uct00+RIGHT(m.mrok,1)+PADR(ALLTRIM(STR(60000+VAL(u_doklady.doklad),7,0)),7)+m.oddelovac && cislo dokladu N(8) od pozicie 10
						ENDIF
						m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.MD),8," ")+m.oddelovac && ucet C(8) od pozicie 19
						m.uct00=m.uct00+STR(ABS(u_doklady.ciastka*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
						m.uct00=m.uct00+"M"+m.oddelovac && strana uctovania C(1) od pozicie 42
						m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.partner),30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
						m.uct00=m.uct00+PADR("421",10," ")+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
						m.uct00=m.uct00+SPACE(12)+m.oddelovac && oznacenie nakladovej jednotky C(12) od pozicie 86
	*					m.uct00=m.uct00+PADR("230023",10," ")+m.oddelovac && oznacenie zakazky C(10) od pozicie 99
						m.uct00=m.uct00+SPACE(6) && oznacenie sprostredkovatela N(6) od pozicie 110
					ENDIF
					= FPUTS(m.lihandle, m.uct00)
					m.uct00=";"
					= FPUTS(m.lihandle, m.uct00)
				ENDSCAN
				m.uct00="[DATA-Koniec]"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00=";"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="[Koniec]"
				= FPUTS(m.lihandle, m.uct00)
				=FCLOSE(m.lihandle)
			ENDIF
		ENDIF
	ENDIF 
	TRY 
		=FCLOSE(m.lihandle)
	CATCH
	ENDTRY 
ENDIF 

gen_exp_had.INCREMENT("Tržby")
IF USED("u_ex_polozky") AND USED("u_ex_platby")
	SELECT SUM(castka) AS ciastka, MD,dal,md2,dal2,hs_dal,hs_md,partner,poznamka FROM u_ex_platby GROUP BY partner,poznamka,MD,dal INTO CURSOR u_doklady WHERE INLIST(partner,"01","02","WH","03") AND !(datum IN (SELECT DISTINCT datum FROM u_ex_polozky WHERE "ZALOHA"$poznamka)) READWRITE 
	DELETE FOR ALLTRIM(partner)<>"WH" .AND. !("hoto"$LOWER(u_doklady.poznamka)) .AND. !("k_"$LOWER(u_doklady.poznamka)) .AND. !("n_bezho2"$LOWER(u_doklady.poznamka)) .AND. !("n_pouk"$LOWER(u_doklady.poznamka))
	SELECT SUM(castka) AS ciastka, pz FROM u_ex_platby GROUP BY pz INTO CURSOR u_platby  WHERE INLIST(partner,"01","02","03") .AND.;
		("hoto"$LOWER(poznamka) .OR. "k_"$LOWER(poznamka) .OR. "n_bezho2"$LOWER(poznamka) .OR. "n_pouk"$LOWER(poznamka))  .AND. !(datum IN (SELECT DISTINCT datum FROM u_ex WHERE "ZALOHA"$poznamka)) READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	SELECT SUM(castka) AS ciastka, MD,dal,hs_md, hs_dal,md2,dal2, partner,poznamka,$0 AS danzakl, $0 AS dan FROM u_ex_polozky GROUP BY partner,poznamka,MD,dal INTO CURSOR u_dokl1 WHERE INLIST(partner,"01","02","WH","03")  .AND. !(datum IN (SELECT DISTINCT datum FROM u_ex_polozky WHERE "ZALOHA"$poznamka)) READWRITE 
	SELECT u_dokl1
	*	REPLACE ALL poznamka WITH LEFT(poznamka,RAT(" ",ALLTRIM(poznamka)))
	REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
	REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka FROM u_dokl1 GROUP BY partner, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl2 READWRITE 
	REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
	SELECT SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2 FROM u_dokl2 GROUP BY partner, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl WHERE ALLTRIM(partner)<>"41" READWRITE 



	SELECT u_doklady
	IF !prazdna()
		m.gcuexp_path = ALLTRIM(m.gcuexp_path)
		IF ! DIRECTORY(m.gcuexp_path)
			MKDIR (m.gcuexp_path)
		ENDIF
		SELECT DISTINCT ALLTRIM(partner) AS partner FROM u_dokl INTO CURSOR uexpartneri READWRITE 
		PRIVATE trzbacelk, dancelk, danzaklcelk,trzbacelkhot
		SCAN ALL
			m.exp_subor="TRZBY_" + m.mexp_meno+ALLTRIM(uexpartneri.partner)+ ".txt"
			m.cislodokladu=RIGHT(m.mrok,1)+"02900"+STRTRAN(STR((VAL(m.mmesiac)-1)*2+RECNO("uexpartneri"),2,0)," ","0")
			IF FILE(m.gcuexp_path+m.exp_subor)
				ERASE(m.gcuexp_path+m.exp_subor)
			ENDIF
			m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
			IF m.lihandle > 0
				SELECT u_dokl
				SUM ciastka TO m.trzbacelk FOR ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
				SUM dan TO m.dancelk FOR ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
				SUM danzakl TO m.danzaklcelk FOR ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
				SUM danzakl TO m.danzakl0 FOR ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. dan=0
				IF m.dancelk<>(m.trzbacelk-m.danzaklcelk)
					m.dancelk=m.trzbacelk-m.danzaklcelk
				ENDIF
				SELECT u_doklady
				SUM ciastka TO m.trzbacelkhot FOR ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. ("hoto"$LOWER(u_doklady.poznamka))
				SUM ciastka TO m.trzbacelk FOR ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. ("hoto"$LOWER(u_doklady.poznamka) .OR. "k_"$LOWER(u_doklady.poznamka) .OR. "n_bezho2"$LOWER(u_doklady.poznamka) .OR. "n_pouk"$LOWER(u_doklady.poznamka))
				IF m.dancelk<>(m.trzbacelk-m.danzaklcelk)
					m.dancelk=m.trzbacelk-m.danzaklcelk
				ENDIF
				m.uct00=""
				m.uct00="; Export udajov pre uctovnictvo"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="[Popis]"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Verzia=2"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Mandant=PEN"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Klient=0010"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Rok="+RIGHT(m.mrok,2)
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Cislo="+m.mmesiac
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Datum="+DTOC(DATE())
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="Cas="+TIME()
				= FPUTS(m.lihandle, m.uct00)
				m.uct00=";"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="[DATA-Start]"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00=""
				SELECT u_doklady
				m.uct00=""
				m.uct00="DOK=FA29"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+"ZA"+m.oddelovac &&adresny box / nepotrebne C(2) od pozicie 19
				m.uct00=m.uct00+SPACE(4)+"2040"+m.oddelovac &&cislo adresy / nepotrebne N(8) od pozicie 22
				m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum vystavenia dokladu C(6) od pozicie 31
				m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum odkedy sa pocitasplatnost C(6) od pozicie 38
				m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
	*				m.uct00=m.uct00+LEFT(LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2),4)+RIGHT(LEFT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),4)+RIGHT(STRTRAN(DTOC(u_doklady.datum_dokl),".",""),2),2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
	*				*Podla prikladu
				m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum uctovania dokladu C(6) od pozicie 52
				m.uct00=m.uct00+"DO P 21"+m.oddelovac && 8 prazdnych znakov od pozicie 59
				m.uct00=m.uct00+PADR(m.cislodokladu,12," ")+m.oddelovac && variabilny symbol dokladu C(12) od pozicie 67
				m.uct00=m.uct00+SPACE(12)+m.oddelovac && parovaci symbol dokladu C(12) od pozicie 80
				m.uct00=m.uct00+SPACE(12)+m.oddelovac && cislo objednavky z dokladu/ nepotrebne od pozicie 93
				m.uct00=m.uct00+"EUR"+m.oddelovac && kod meny C(3) od pozicie 106
				m.uct00=m.uct00+STR(1*1000,9,0)+m.oddelovac && kurz meny*1000 N(9) od pozicie 110
				m.uct00=m.uct00+STR(1,4,0)+m.oddelovac && pocet jednotiek meny N(4) od pozicie 120
				m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum kurzu C(6) od pozicie 125
				m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene dokladu*100 N(13) od pozicie 132
				m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene uctovnictva*100 N(13) od pozicie 146
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && suma dane v mene uctovnictva*100 / nepotrebne od pozicie 160 N(13)
				m.uct00=m.uct00+PADR(u_doklady.hs_md,10)+m.oddelovac && oznacenie hospodarskeho strediska / nepotrebne od pozicie 174 C(10)
				m.uct00=m.uct00+PADR("S090",12)+m.oddelovac && oznacenie nakladovej jednotky / nepotrebne od pozicie 185 C(12)
				m.uct00=m.uct00+SPACE(10)+m.oddelovac && zakazka / nepotrebne od pozicie 198 C(10)
				m.uct00=m.uct00+"  2040"+m.oddelovac && oznacenie sprostredkovatela / nepotrebne od pozicie 209 N(6)
				m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac
				= FPUTS(m.lihandle, m.uct00)

				m.uct00="DAN=FA29"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+"P 319 "+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS((m.danzaklcelk-m.danzakl0)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS((m.danzaklcelk-m.danzakl0)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				= FPUTS(m.lihandle, m.uct00)
				IF m.danzakl0<>0
					m.uct00="DAN=FA29"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+"P 300 "+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(m.danzakl0*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+STR(ABS(m.danzakl0*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+SPACE(13)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+SPACE(13)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					= FPUTS(m.lihandle, m.uct00)
				ENDIF

				SCAN FOR ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. ("hoto"$LOWER(u_doklady.poznamka) .OR. "k_"$LOWER(u_doklady.poznamka) .OR. "n_bezho2"$LOWER(u_doklady.poznamka) .OR. "n_pouk"$LOWER(u_doklady.poznamka))
					m.uct00="UCT=FA29"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.MD),8," ")+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(u_doklady.ciastka*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
					m.uct00=m.uct00+"M"+m.oddelovac && strana uctovania C(1) od pozicie 42
					DO CASE
						CASE "hoto"$LOWER(u_doklady.poznamka)
							m.uct00=m.uct00+PADR("Hotovost",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
						CASE "k_"$LOWER(u_doklady.poznamka)
							m.uct00=m.uct00+PADR("Kredit karty",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
						CASE "n_bezho2"$LOWER(u_doklady.poznamka)
							m.uct00=m.uct00+PADR("Stravne listky",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
						CASE "n_pouk"$LOWER(u_doklady.poznamka)
							m.uct00=m.uct00+PADR("Poukazky",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
						OTHERWISE
							m.uct00=m.uct00+PADR("Hotovost",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					ENDCASE
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && oznacenie nakladovej jednotky C(12) od pozicie 86
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie zakazky C(10) od pozicie 99
					m.uct00=m.uct00+"  2040" && oznacenie sprostredkovatela N(6) od pozicie 110
					= FPUTS(m.lihandle, m.uct00)
				ENDSCAN
				SELECT u_dokl
				SCAN FOR ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
					m.dal2=u_dokl.dal2
					m.uct00="UCT=FA29"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+PADR(ALLTRIM(u_dokl.dal),8," ")+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(u_dokl.danzakl*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
					m.uct00=m.uct00+PADR("Trzba",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					m.uct00=m.uct00+PADR(hs_dal,10," ")+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
					m.uct00=m.uct00+PADR("S090",12," ")+m.oddelovac && oznacenie nakladovej jednotky C(12) od pozicie 86
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie zakazky C(10) od pozicie 99
					m.uct00=m.uct00+"  2040" && oznacenie sprostredkovatela N(6) od pozicie 110
					= FPUTS(m.lihandle, m.uct00)
				ENDSCAN
				m.uct00="UCT=FA29"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+PADR(ALLTRIM(m.dal2),8," ")+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
				m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
				m.uct00=m.uct00+PADR("DPH P 319",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
				m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
				= FPUTS(m.lihandle, m.uct00)
				m.uct00=";"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="[DATA-Koniec]"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00=";"
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="[Koniec]"
				= FPUTS(m.lihandle, m.uct00)
				=FCLOSE(m.lihandle)
			ENDIF
			SELECT uexpartneri
		ENDSCAN
	ENDIF

	gen_exp_had.INCREMENT("Faktúry")
	SELECT datum,SUM(castka) AS ciastka, MD,dal,md2,dal2,hs_dal,hs_md,partner,poznamka FROM u_ex_platby GROUP BY datum,partner,poznamka,MD,dal INTO CURSOR u_doklady  WHERE ALLTRIM(poznamka)="Platba N_UVER HORES" .AND. !(datum IN (SELECT DISTINCT datum FROM u_ex WHERE "ZALOHA"$poznamka)) READWRITE 
	SELECT datum,SUM(castka) AS ciastka, MD,dal,hs_md, hs_dal,md2,dal2, partner,poznamka,$0 AS danzakl, $0 AS dan,.f. as zaloha FROM u_ex_polozky GROUP BY datum,partner,poznamka,MD,dal INTO CURSOR u_dokl1 WHERE id_kas="WH" and ALLTRIM(partner)<>"WH" .AND. !(datum IN (SELECT DISTINCT datum FROM u_ex_polozky WHERE "ZALOHA"$poznamka)) READWRITE 
	SELECT u_dokl1
	REPLACE ALL zaloha WITH "ZALOHA"$poznamka
	REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
	REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT datum,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka,zaloha FROM u_dokl1 GROUP BY datum, partner, MD, dal, hs_md, hs_dal, poznamka, zaloha INTO TABLE (m.gcucto_path+"u_dokl2")
	REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
	SELECT datum,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2,zaloha FROM u_dokl2 GROUP BY datum, partner, MD, dal, hs_md, hs_dal, poznamka, zaloha INTO TABLE (m.gcucto_path+"u_dokl") WHERE ALLTRIM(partner)<>"41"


	SELECT u_doklady
	IF !prazdna()
		m.gcuexp_path = ALLTRIM(m.gcuexp_path)
		IF ! DIRECTORY(m.gcuexp_path)
			MKDIR (m.gcuexp_path)
		ENDIF
		SELECT DISTINCT ALLTRIM(datum)+ALLTRIM(partner) AS partner FROM u_dokl INTO CURSOR uexpartneri READWRITE 
		PRIVATE trzbacelk, dancelk, danzaklcelk,trzbacelkhot
		m.exp_subor="FAKTURY_" + m.mexp_meno+ ".txt"
		IF FILE(m.gcuexp_path+m.exp_subor)
			ERASE(m.gcuexp_path+m.exp_subor)
		ENDIF
		m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
		IF m.lihandle > 0
			USE (m.hor_path+"hnab.dbf") IN 0
			USE (m.hor_path+"hmvh.dbf") IN 0
			USE (m.hor_path+"hban.dbf") IN 0
			USE (m.hor_path+"hfak.dbf") IN 0
			m.uct00=""
			m.uct00="; Export udajov pre uctovnictvo"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[Popis]"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Verzia=2"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Mandant=PEN"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Klient=0010"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Rok="+RIGHT(m.mrok,2)
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Cislo="+m.mmesiac
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Datum="+DTOC(DATE())
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Cas="+TIME()
			= FPUTS(m.lihandle, m.uct00)
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[DATA-Start]"
			= FPUTS(m.lihandle, m.uct00)
			SCAN ALL
				m.cislodokladu=RIGHT(m.mrok,1)+"06800"+STRTRAN(STR((VAL(m.mmesiac)-1)*2+RECNO("uexpartneri")+30,2,0)," ","0")
				SELECT u_dokl
				SUM ciastka TO m.trzbacelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
				SUM dan TO m.dancelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
				SUM danzakl TO m.danzaklcelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
				SUM danzakl TO m.danzakl0 FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. dan=0
				IF m.dancelk<>(m.trzbacelk-m.danzaklcelk)
					m.dancelk=m.trzbacelk-m.danzaklcelk
				ENDIF
				SELECT u_doklady
				SUM ciastka TO m.trzbacelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
				m.trzbacelkhot=m.trzbacelk
				IF m.dancelk<>(m.trzbacelk-m.danzaklcelk)
					m.dancelk=m.trzbacelk-m.danzaklcelk
				ENDIF
				SELECT u_doklady
				LOCATE FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
				SELECT hnab
				LOCATE FOR ALLTRIM(nabor)==ALLTRIM(u_doklady.partner)
				IF FOUND()
					SCATTER MEMVAR FIELDS naborn,adr1,adr2,adr3,zem, ico, dic, tel, fax, email,nabor
				ELSE
					SELECT hban
					LOCATE FOR ALLTRIM(jmeno)==ALLTRIM(u_doklady.partner)
					IF FOUND()
						m.naborn=hban.jmeno
						m.ico=""
						m.dic=""
						m.fax=""
						m.email=""
						m.nabor=STR(hban.ucet,8,0)
						SCATTER MEMVAR FIELDS adr1,adr2,adr3,zem,tel
					ELSE
						SELECT hmvh
						LOCATE FOR ALLTRIM(jmeno)==ALLTRIM(u_doklady.partner)
						IF FOUND()
							m.naborn=hmvh.jmeno
							m.ico=""
							m.dic=""
							m.fax=""
							m.email=""
							m.nabor=""
							SCATTER MEMVAR FIELDS adr1,adr2,adr3,zem,tel
						ELSE
							m.naborn=u_doklady.partner
							IF LEFT(m.naborn,4)="Ind."
								m.naborn=SUBSTR(m.naborn,AT("\",m.naborn)+1)
							ENDIF 
							m.ico=""
							m.dic=""
							m.fax=""
							m.email=""
							m.adr1=""
							m.adr2=""
							m.adr3=""
							m.zem="SVK"
							m.tel=""
							m.nabor=""
						ENDIF
					ENDIF  					
				ENDIF 


				m.uct00=""
				m.uct00="ADR="+IIF(m.zem="SVK","OT","OZ")+m.oddelovac  && adresny box C(2) od pozicie 5
				m.uct00=m.uct00+PADR(ALLTRIM(m.nabor),8)+m.oddelovac && Číslo adresy, jednoznačné označenie adresáta v rámci adresného boxu N(8) od pozicie 8
				m.uct00=m.uct00+PADR(ALLTRIM(m.naborn),15)+m.oddelovac && Matchcode=Skrátené označenie adresy C(15) od pozicie 17 
				m.uct00=m.uct00+PADR(ALLTRIM(m.naborn),30)+m.oddelovac && Nazov1 C(30) od pozicie 33
				m.uct00=m.uct00+SPACE(30)+m.oddelovac && Nazov2 C(30) od pozicie 64
				m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),30)+m.oddelovac && Kontakt C(30) od pozicie 95
				m.uct00=m.uct00+PADR(ALLTRIM(m.adr1),30)+m.oddelovac && ulica C(30) od pozicie 126
				m.uct00=m.uct00+IIF(m.zem="SVK"," SK",m.zem)+m.oddelovac && stat C(3) od pozicie 157 
				m.uct00=m.uct00+SPACE(7)+m.oddelovac && PSC C(7) od pozicie 161
				m.uct00=m.uct00+PADR(ALLTRIM(m.adr2),23)+m.oddelovac && Mesto C(23) od pozicie 169 
				m.uct00=m.uct00+PADR(ALLTRIM(m.ico),20)+m.oddelovac && ICO C(20) od pozicie 193
				m.uct00=m.uct00+PADR(ALLTRIM(m.dic),20)+m.oddelovac && DIC C(20) od pozicie 214
				m.uct00=m.uct00+PADR(ALLTRIM(m.tel),15)+m.oddelovac && Telefonne cislo C(15) od pozicie 235
				m.uct00=m.uct00+PADR(ALLTRIM(m.fax),15)+m.oddelovac && Faxove cislo C(15) od pozicie 251
				m.uct00=m.uct00+PADR(ALLTRIM(m.email),15)+m.oddelovac && e-mail C(15) od pozicie 267
				m.uct00=m.uct00+PADR("0",13)+m.oddelovac && Kredit - limit adresata*100 N(13) od pozicie 283
				m.uct00=m.uct00+PADR("0",2)+m.oddelovac && Cislo platobnej podmienky N(2) od pozicie 297
				m.uct00=m.uct00+"EUR"+m.oddelovac && Kod meny C(3) od pozicie 300
				m.uct00=m.uct00+"P"+m.oddelovac && Oznacenie dane pre doklady adresata C(1) od pozicie 304
				m.uct00=m.uct00+"  "+m.oddelovac && Oznacenie sposobu upominania C(2) od pozicie 306 
				m.uct00=m.uct00+PADR("0",5)+m.oddelovac && Percento penale pre upominanie*1000 N(5) od pozicie 309 
				= FPUTS(m.lihandle, m.uct00)

				m.uct00=""
				m.uct00="DOK=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+IIF(m.zem="SVK","OT","OZ")+m.oddelovac &&adresny box C(2) od pozicie 19
				m.uct00=m.uct00+PADR(ALLTRIM(m.nabor),8)+m.oddelovac &&cislo adresy N(8) od pozicie 22
				SELECT hfak
				GO TOP 
				LOCATE FOR ucet=VAL(u_doklady.datum)
				IF FOUND()
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum),4,0),2)+m.oddelovac	&& datum vystavenia dokladu C(6) od pozicie 31
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum),4,0),2)+m.oddelovac	&& datum odkedy sa pocitasplatnost C(6) od pozicie 38
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum+7),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum+7),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum+7),4,0),2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.odj),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.odj),2,0)," ","0")+RIGHT(STR(YEAR(hfak.odj),4,0),2)+m.oddelovac	&& datum uctovania dokladu C(6) od pozicie 52
					m.uct00=m.uct00+"PP P 21"+m.oddelovac && 8 prazdnych znakov od pozicie 59
					m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),12," ")+m.oddelovac && variabilny symbol dokladu C(12) od pozicie 67
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && parovaci symbol dokladu C(12) od pozicie 80
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && cislo objednavky z dokladu/ nepotrebne od pozicie 93
					m.uct00=m.uct00+"EUR"+m.oddelovac && kod meny C(3) od pozicie 106
					m.uct00=m.uct00+STR(1*1000,9,0)+m.oddelovac && kurz meny*1000 N(9) od pozicie 110
					m.uct00=m.uct00+STR(1,4,0)+m.oddelovac && pocet jednotiek meny N(4) od pozicie 120
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.odj),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.odj),2,0)," ","0")+RIGHT(STR(YEAR(hfak.odj),4,0),2)+m.oddelovac	&& datum kurzu C(6) od pozicie 125
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene dokladu*100 N(13) od pozicie 132
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene uctovnictva*100 N(13) od pozicie 146
					m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && suma dane v mene uctovnictva*100 / nepotrebne od pozicie 160 N(13)
					m.uct00=m.uct00+PADR(u_doklady.hs_md,10)+m.oddelovac && oznacenie hospodarskeho strediska / nepotrebne od pozicie 174 C(10)
					m.uct00=m.uct00+PADR("S090",12)+m.oddelovac && oznacenie nakladovej jednotky / nepotrebne od pozicie 185 C(12)
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && zakazka / nepotrebne od pozicie 198 C(10)
					m.uct00=m.uct00+"  2040"+m.oddelovac && oznacenie sprostredkovatela / nepotrebne od pozicie 209 N(6)
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.odj),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.odj),2,0)," ","0")+RIGHT(STR(YEAR(hfak.odj),4,0),2)+m.oddelovac	
				ELSE
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum vystavenia dokladu C(6) od pozicie 31
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum odkedy sa pocitasplatnost C(6) od pozicie 38
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum uctovania dokladu C(6) od pozicie 52
					m.uct00=m.uct00+"PP P 21"+m.oddelovac && 8 prazdnych znakov od pozicie 59
					m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),12," ")+m.oddelovac && variabilny symbol dokladu C(12) od pozicie 67
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && parovaci symbol dokladu C(12) od pozicie 80
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && cislo objednavky z dokladu/ nepotrebne od pozicie 93
					m.uct00=m.uct00+"EUR"+m.oddelovac && kod meny C(3) od pozicie 106
					m.uct00=m.uct00+STR(1*1000,9,0)+m.oddelovac && kurz meny*1000 N(9) od pozicie 110
					m.uct00=m.uct00+STR(1,4,0)+m.oddelovac && pocet jednotiek meny N(4) od pozicie 120
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum kurzu C(6) od pozicie 125
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene dokladu*100 N(13) od pozicie 132
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene uctovnictva*100 N(13) od pozicie 146
					m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && suma dane v mene uctovnictva*100 / nepotrebne od pozicie 160 N(13)
					m.uct00=m.uct00+PADR(u_doklady.hs_md,10)+m.oddelovac && oznacenie hospodarskeho strediska / nepotrebne od pozicie 174 C(10)
					m.uct00=m.uct00+PADR("S090",12)+m.oddelovac && oznacenie nakladovej jednotky / nepotrebne od pozicie 185 C(12)
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && zakazka / nepotrebne od pozicie 198 C(10)
					m.uct00=m.uct00+"  2040"+m.oddelovac && oznacenie sprostredkovatela / nepotrebne od pozicie 209 N(6)
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac
				ENDIF 
				SELECT u_doklady
				= FPUTS(m.lihandle, m.uct00)

				m.uct00="DAN=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+"P 319 "+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS((m.danzaklcelk-m.danzakl0)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS((m.danzaklcelk-m.danzakl0)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				= FPUTS(m.lihandle, m.uct00)
				IF m.danzakl0<>0
					m.uct00="DAN=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+"P 300 "+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(m.danzakl0*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+STR(ABS(m.danzakl0*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+SPACE(13)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+SPACE(13)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					= FPUTS(m.lihandle, m.uct00)
				ENDIF
				SELECT u_doklady
				SCAN FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. ALLTRIM(poznamka)="Platba N_UVER HORES"
					m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.MD),8," ")+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(u_doklady.ciastka*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
					m.uct00=m.uct00+"M"+m.oddelovac && strana uctovania C(1) od pozicie 42
					m.uct00=m.uct00+PADR("Faktura",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && oznacenie nakladovej jednotky C(12) od pozicie 86
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie zakazky C(10) od pozicie 99
					m.uct00=m.uct00+"  2040" && oznacenie sprostredkovatela N(6) od pozicie 110
					= FPUTS(m.lihandle, m.uct00)
				ENDSCAN
				SELECT u_dokl
				SCAN FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
					m.dal2=u_dokl.dal2
					m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+PADR(ALLTRIM(u_dokl.dal),8," ")+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(u_dokl.danzakl*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
					m.uct00=m.uct00+PADR("Trzba",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					m.uct00=m.uct00+PADR(hs_dal,10," ")+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
					m.uct00=m.uct00+PADR("S090",12," ")+m.oddelovac && oznacenie nakladovej jednotky C(12) od pozicie 86
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie zakazky C(10) od pozicie 99
					m.uct00=m.uct00+"  2040" && oznacenie sprostredkovatela N(6) od pozicie 110
					= FPUTS(m.lihandle, m.uct00)
				ENDSCAN
				m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+PADR(ALLTRIM(m.dal2),8," ")+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
				m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
				m.uct00=m.uct00+PADR("DPH P 319",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
				m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
				= FPUTS(m.lihandle, m.uct00)
				SELECT uexpartneri
			ENDSCAN
			USE IN hnab
			USE IN hmvh
			USE IN hban
			USE IN hfak
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[DATA-Koniec]"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[Koniec]"
			= FPUTS(m.lihandle, m.uct00)
			=FCLOSE(m.lihandle)
		ENDIF 
	ENDIF
	DO pozavirej WITH "uexpartneri, u_doklady, u_dokl, u_dokl1, u_dokl2"

	gen_exp_had.INCREMENT("Zálohy")
	SELECT datum, SUM(castka) AS ciastka, MD, dal, md2, dal2, hs_dal, hs_md, partner, poznamka, .t. as vyuct, .f. as faktura FROM u_ex_platby GROUP BY datum,partner,poznamka,MD,dal INTO  CURSOR u_doklady  WHERE  id_kas="WH" AND datum IN (SELECT DISTINCT datum FROM u_ex_polozky WHERE "ZALOHA"$poznamka) READWRITE 
	SELECT datum, SUM(castka) AS ciastka, MD, dal, hs_md, hs_dal, md2, dal2, partner, poznamka, $0 AS danzakl, $0 AS dan,.f. as zaloha, .t. as vyuct, .f. as faktura FROM u_ex_polozky GROUP BY datum, partner, poznamka, MD, dal, zaloha INTO CURSOR u_dokl1 WHERE id_kas="WH" AND datum IN (SELECT DISTINCT datum FROM u_ex_polozky WHERE "ZALOHA"$poznamka) READWRITE 
	SELECT u_dokl1
	SELECT DISTINCT datum FROM u_dokl1 INTO CURSOR u_doklx WHERE !("ZALOHA"$poznamka) READWRITE 
	INDEX ON datum TAG datum
	SELECT u_dokl1
	REPLACE ALL zaloha WITH "ZALOHA"$poznamka
	SET RELATION TO datum INTO u_doklx
	REPLACE vyuct WITH .f. FOR EMPTY(u_doklx.datum)
	SET RELATION OFF INTO u_doklx
	SELECT u_doklady
	SET RELATION TO datum INTO u_doklx
	REPLACE vyuct WITH .f. FOR EMPTY(u_doklx.datum)
	SET RELATION OFF INTO u_doklx
	USE IN u_doklx
	REPLACE faktura WITH "N_UVER"$poznamka FOR vyuct
	SELECT DISTINCT datum FROM u_doklady WHERE vyuct .AND. faktura INTO CURSOR u_doklx READWRITE 
	INDEX on datum TAG datum
	SELECT u_dokl1
	SET RELATION TO datum INTO u_doklx
	REPLACE faktura WITH .t. FOR !EMPTY(u_doklx.datum)
	SET RELATION OFF INTO u_doklx
	USE IN u_doklx
	SELECT u_dokl1
	REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
	REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT datum,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka,zaloha, vyuct FROM u_dokl1 GROUP BY datum, partner, MD, dal, hs_md, hs_dal, poznamka, zaloha INTO CURSOR u_dokl2 READWRITE 
	REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
	SELECT datum,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2,zaloha, vyuct FROM u_dokl2 GROUP BY datum, partner, MD, dal, hs_md, hs_dal, poznamka, zaloha INTO CURSOR u_dokl WHERE ALLTRIM(partner)<>"41" READWRITE 

	*** Zálohy ***
	SELECT u_doklady
	LOCATE FOR EMPTY(vyuct)
	IF FOUND()
		m.gcuexp_path = ALLTRIM(m.gcuexp_path)
		IF ! DIRECTORY(m.gcuexp_path)
			MKDIR (m.gcuexp_path)
		ENDIF
		SELECT DISTINCT ALLTRIM(datum)+ALLTRIM(partner) AS partner FROM u_dokl INTO CURSOR uexpartneri WHERE EMPTY(vyuct) READWRITE 
		PRIVATE trzbacelk, dancelk, danzaklcelk,trzbacelkhot
		m.exp_subor="ZALOHY_" + m.mexp_meno+ ".txt"
		IF FILE(m.gcuexp_path+m.exp_subor)
			ERASE(m.gcuexp_path+m.exp_subor)
		ENDIF
		m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
		IF m.lihandle > 0
			USE (m.hor_path+"hnab.dbf") IN 0
			USE (m.hor_path+"hmvh.dbf") IN 0
			USE (m.hor_path+"hban.dbf") IN 0
			USE (m.hor_path+"hfak.dbf") IN 0
			m.uct00=""
			m.uct00="; Export udajov pre uctovnictvo"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[Popis]"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Verzia=2"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Mandant=PEN"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Klient=0010"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Rok="+RIGHT(m.mrok,2)
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Cislo="+m.mmesiac
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Datum="+DTOC(DATE())
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Cas="+TIME()
			= FPUTS(m.lihandle, m.uct00)
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[DATA-Start]"
			= FPUTS(m.lihandle, m.uct00)
			SCAN ALL
				m.cislodokladu=RIGHT(m.mrok,1)+"07400"+STRTRAN(STR((VAL(m.mmesiac)-1)*2+RECNO("uexpartneri")+30,2,0)," ","0")
				SELECT u_dokl
				SUM ciastka TO m.trzbacelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) AND !vyuct
				SUM dan TO m.dancelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) AND !vyuct
				SUM danzakl TO m.danzaklcelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) AND !vyuct
				SUM danzakl TO m.danzakl0 FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. dan=0  AND !vyuct
				IF m.dancelk<>(m.trzbacelk-m.danzaklcelk)
					m.dancelk=m.trzbacelk-m.danzaklcelk
				ENDIF
				SELECT u_doklady
				SUM ciastka TO m.trzbacelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)  AND !vyuct
				m.trzbacelkhot=m.trzbacelk
				IF m.dancelk<>(m.trzbacelk-m.danzaklcelk)
					m.dancelk=m.trzbacelk-m.danzaklcelk
				ENDIF
				SELECT u_doklady
				LOCATE FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
				SELECT hnab
				LOCATE FOR ALLTRIM(nabor)==ALLTRIM(u_doklady.partner)
				IF FOUND()
					SCATTER MEMVAR FIELDS naborn,adr1,adr2,adr3,zem, ico, dic, tel, fax, email,nabor
				ELSE
					SELECT hban
					LOCATE FOR ALLTRIM(jmeno)==ALLTRIM(u_doklady.partner)
					IF FOUND()
						m.naborn=hban.jmeno
						m.ico=""
						m.dic=""
						m.fax=""
						m.email=""
						m.nabor=STR(hban.ucet,8,0)
						SCATTER MEMVAR FIELDS adr1,adr2,adr3,zem,tel
					ELSE
						SELECT hmvh
						LOCATE FOR ALLTRIM(jmeno)==ALLTRIM(u_doklady.partner)
						IF FOUND()
							m.naborn=hmvh.jmeno
							m.ico=""
							m.dic=""
							m.fax=""
							m.email=""
							m.nabor=""
							SCATTER MEMVAR FIELDS adr1,adr2,adr3,zem,tel
						ELSE
							m.naborn=u_doklady.partner
							IF LEFT(m.naborn,4)="Ind."
								m.naborn=SUBSTR(m.naborn,AT("\",m.naborn)+1)
							ENDIF 
							m.ico=""
							m.dic=""
							m.fax=""
							m.email=""
							m.adr1=""
							m.adr2=""
							m.adr3=""
							m.zem="SVK"
							m.tel=""
							m.nabor=""
						ENDIF
					ENDIF  					
				ENDIF 


				m.uct00=""
				m.uct00="ADR="+IIF(m.zem="SVK","OT","OZ")+m.oddelovac  && adresny box C(2) od pozicie 5
				m.uct00=m.uct00+PADR(ALLTRIM(m.nabor),8)+m.oddelovac && Číslo adresy, jednoznačné označenie adresáta v rámci adresného boxu N(8) od pozicie 8
				m.uct00=m.uct00+PADR(ALLTRIM(m.naborn),15)+m.oddelovac && Matchcode=Skrátené označenie adresy C(15) od pozicie 17 
				m.uct00=m.uct00+PADR(ALLTRIM(m.naborn),30)+m.oddelovac && Nazov1 C(30) od pozicie 33
				m.uct00=m.uct00+SPACE(30)+m.oddelovac && Nazov2 C(30) od pozicie 64
				m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),30)+m.oddelovac && Kontakt C(30) od pozicie 95
				m.uct00=m.uct00+PADR(ALLTRIM(m.adr1),30)+m.oddelovac && ulica C(30) od pozicie 126
				m.uct00=m.uct00+IIF(m.zem="SVK"," SK",m.zem)+m.oddelovac && stat C(3) od pozicie 157 
				m.uct00=m.uct00+SPACE(7)+m.oddelovac && PSC C(7) od pozicie 161
				m.uct00=m.uct00+PADR(ALLTRIM(m.adr2),23)+m.oddelovac && Mesto C(23) od pozicie 169 
				m.uct00=m.uct00+PADR(ALLTRIM(m.ico),20)+m.oddelovac && ICO C(20) od pozicie 193
				m.uct00=m.uct00+PADR(ALLTRIM(m.dic),20)+m.oddelovac && DIC C(20) od pozicie 214
				m.uct00=m.uct00+PADR(ALLTRIM(m.tel),15)+m.oddelovac && Telefonne cislo C(15) od pozicie 235
				m.uct00=m.uct00+PADR(ALLTRIM(m.fax),15)+m.oddelovac && Faxove cislo C(15) od pozicie 251
				m.uct00=m.uct00+PADR(ALLTRIM(m.email),15)+m.oddelovac && e-mail C(15) od pozicie 267
				m.uct00=m.uct00+PADR("0",13)+m.oddelovac && Kredit - limit adresata*100 N(13) od pozicie 283
				m.uct00=m.uct00+PADR("0",2)+m.oddelovac && Cislo platobnej podmienky N(2) od pozicie 297
				m.uct00=m.uct00+"EUR"+m.oddelovac && Kod meny C(3) od pozicie 300
				m.uct00=m.uct00+"P"+m.oddelovac && Oznacenie dane pre doklady adresata C(1) od pozicie 304
				m.uct00=m.uct00+"  "+m.oddelovac && Oznacenie sposobu upominania C(2) od pozicie 306 
				m.uct00=m.uct00+PADR("0",5)+m.oddelovac && Percento penale pre upominanie*1000 N(5) od pozicie 309 
				= FPUTS(m.lihandle, m.uct00)

				m.uct00=""
				m.uct00="DOK=FA74"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+IIF(m.zem="SVK","OT","OZ")+m.oddelovac &&adresny box C(2) od pozicie 19
				m.uct00=m.uct00+PADR(ALLTRIM(m.nabor),8)+m.oddelovac &&cislo adresy N(8) od pozicie 22
				SELECT hfak
				GO TOP 
				LOCATE FOR ucet=VAL(u_doklady.datum) AND jmeno=u_doklady.partner
				IF FOUND()
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum),4,0),2)+m.oddelovac	&& datum vystavenia dokladu C(6) od pozicie 31
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum),4,0),2)+m.oddelovac	&& datum odkedy sa pocitasplatnost C(6) od pozicie 38
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum+7),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum+7),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum+7),4,0),2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum),4,0),2)+m.oddelovac	&& datum uctovania dokladu C(6) od pozicie 52
					m.uct00=m.uct00+"PP P 21"+m.oddelovac && 8 prazdnych znakov od pozicie 59
					m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),12," ")+m.oddelovac && variabilny symbol dokladu C(12) od pozicie 67
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && parovaci symbol dokladu C(12) od pozicie 80
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && cislo objednavky z dokladu/ nepotrebne od pozicie 93
					m.uct00=m.uct00+"EUR"+m.oddelovac && kod meny C(3) od pozicie 106
					m.uct00=m.uct00+STR(1*1000,9,0)+m.oddelovac && kurz meny*1000 N(9) od pozicie 110
					m.uct00=m.uct00+STR(1,4,0)+m.oddelovac && pocet jednotiek meny N(4) od pozicie 120
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.odj),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.odj),2,0)," ","0")+RIGHT(STR(YEAR(hfak.odj),4,0),2)+m.oddelovac	&& datum kurzu C(6) od pozicie 125
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene dokladu*100 N(13) od pozicie 132
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene uctovnictva*100 N(13) od pozicie 146
					m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && suma dane v mene uctovnictva*100 / nepotrebne od pozicie 160 N(13)
					m.uct00=m.uct00+PADR(u_doklady.hs_md,10)+m.oddelovac && oznacenie hospodarskeho strediska / nepotrebne od pozicie 174 C(10)
					m.uct00=m.uct00+PADR("S090",12)+m.oddelovac && oznacenie nakladovej jednotky / nepotrebne od pozicie 185 C(12)
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && zakazka / nepotrebne od pozicie 198 C(10)
					m.uct00=m.uct00+"  2040"+m.oddelovac && oznacenie sprostredkovatela / nepotrebne od pozicie 209 N(6)
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum),4,0),2)+m.oddelovac	
				ELSE
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum vystavenia dokladu C(6) od pozicie 31
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum odkedy sa pocitasplatnost C(6) od pozicie 38
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum uctovania dokladu C(6) od pozicie 52
					m.uct00=m.uct00+"DO P 21"+m.oddelovac && 8 prazdnych znakov od pozicie 59
					m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),12," ")+m.oddelovac && variabilny symbol dokladu C(12) od pozicie 67
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && parovaci symbol dokladu C(12) od pozicie 80
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && cislo objednavky z dokladu/ nepotrebne od pozicie 93
					m.uct00=m.uct00+"EUR"+m.oddelovac && kod meny C(3) od pozicie 106
					m.uct00=m.uct00+STR(1*1000,9,0)+m.oddelovac && kurz meny*1000 N(9) od pozicie 110
					m.uct00=m.uct00+STR(1,4,0)+m.oddelovac && pocet jednotiek meny N(4) od pozicie 120
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum kurzu C(6) od pozicie 125
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene dokladu*100 N(13) od pozicie 132
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene uctovnictva*100 N(13) od pozicie 146
					m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && suma dane v mene uctovnictva*100 / nepotrebne od pozicie 160 N(13)
					m.uct00=m.uct00+PADR(u_doklady.hs_md,10)+m.oddelovac && oznacenie hospodarskeho strediska / nepotrebne od pozicie 174 C(10)
					m.uct00=m.uct00+PADR("S090",12)+m.oddelovac && oznacenie nakladovej jednotky / nepotrebne od pozicie 185 C(12)
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && zakazka / nepotrebne od pozicie 198 C(10)
					m.uct00=m.uct00+"  2040"+m.oddelovac && oznacenie sprostredkovatela / nepotrebne od pozicie 209 N(6)
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac
				ENDIF 
				SELECT u_doklady
				= FPUTS(m.lihandle, m.uct00)

				m.uct00="DAN=FA74"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+"P 319 "+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS((m.danzaklcelk-m.danzakl0)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS((m.danzaklcelk-m.danzakl0)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				= FPUTS(m.lihandle, m.uct00)
				IF m.danzakl0<>0
					m.uct00="DAN=FA74"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+"P 300 "+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(m.danzakl0*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+STR(ABS(m.danzakl0*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+SPACE(13)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+SPACE(13)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					= FPUTS(m.lihandle, m.uct00)
				ENDIF
				SELECT u_dokl
				LOCATE FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) AND !vyuct
				m.uct00="UCT=FA74"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+PADR(ALLTRIM(u_dokl.md2),8," ")+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
				m.uct00=m.uct00+"M"+m.oddelovac && strana uctovania C(1) od pozicie 42
				m.uct00=m.uct00+PADR("Faktura",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
				m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
				= FPUTS(m.lihandle, m.uct00)
				m.uct00="UCT=FA74"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+PADR(ALLTRIM(u_dokl.dal2),8," ")+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
				m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
				m.uct00=m.uct00+PADR("DPH P 319",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
				m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
				= FPUTS(m.lihandle, m.uct00)

				SELECT uexpartneri
			ENDSCAN
			USE IN hnab
			USE IN hmvh
			USE IN hban
			USE IN hfak
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[DATA-Koniec]"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[Koniec]"
			= FPUTS(m.lihandle, m.uct00)
			=FCLOSE(m.lihandle)
		ENDIF 
	ENDIF

	*** Vyúčtovanie - platba fakturou***
	SELECT u_doklady
	LOCATE FOR !EMPTY(vyuct) .and. faktura
	IF FOUND()
		SELECT 0
		USE (m.hor_path+"hfak.dbf") IN 0
		SELECT u_doklady
		SCAN FOR vyuct .AND. ALLTRIM(partner)="WH"
			SELECT hfak
			LOCATE FOR ucet=VAL(u_doklady.datum)
			IF FOUND()
				SELECT u_doklady
				REPLACE u_doklady.partner WITH hfak.jmeno
				SELECT u_dokl
				REPLACE partner WITH hfak.jmeno FOR datum=u_doklady.datum .AND. ALLTRIM(partner)=="WH"
			ENDIF 
			SELECT u_doklady
		ENDSCAN 
		USE IN hfak
		m.gcuexp_path = ALLTRIM(m.gcuexp_path)
		IF ! DIRECTORY(m.gcuexp_path)
			MKDIR (m.gcuexp_path)
		ENDIF
		IF USED("u_ex_plt")
			SELECT u_ex_plt
			m.ueplt=.t.
		ELSE
			SELECT 0
			USE (m.gcucto_path+"u_ex_plt")
			m.ueplt=.f.
		ENDIF 
		LOCATE FOR id_kas="WH" .AND. druh_pl="F"
		
		IF FOUND()
			m.fakturamd=ALLTRIM(u_ex_plt.md)
		ELSE
			m.fakturamd="311400"
		ENDIF
		IF !m.ueplt
			USE IN u_ex_plt
		ENDIF 
		RELEASE m.ueplt
		SELECT DISTINCT ALLTRIM(datum)+ALLTRIM(partner) AS partner FROM u_doklady INTO CURSOR uexpartneri WHERE vyuct AND faktura READWRITE 
		PRIVATE trzbacelk, dancelk, danzaklcelk,trzbacelkhot
		m.exp_subor="VYUCTOVANIE_" + m.mexp_meno+ ".txt"
		IF FILE(m.gcuexp_path+m.exp_subor)
			ERASE(m.gcuexp_path+m.exp_subor)
		ENDIF
		m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
		IF m.lihandle > 0
			USE (m.hor_path+"hnab.dbf") IN 0
			USE (m.hor_path+"hmvh.dbf") IN 0
			USE (m.hor_path+"hban.dbf") IN 0
			USE (m.hor_path+"hfak.dbf") IN 0
			m.uct00=""
			m.uct00="; Export udajov pre uctovnictvo"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[Popis]"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Verzia=2"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Mandant=PEN"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Klient=0010"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Rok="+RIGHT(m.mrok,2)
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Cislo="+m.mmesiac
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Datum="+DTOC(DATE())
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Cas="+TIME()
			= FPUTS(m.lihandle, m.uct00)
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[DATA-Start]"
			= FPUTS(m.lihandle, m.uct00)
			SCAN ALL
				m.cislodokladu=RIGHT(m.mrok,1)+"06800"+STRTRAN(STR((VAL(m.mmesiac)-1)*2+RECNO("uexpartneri")+30,2,0)," ","0")
				SELECT u_dokl
				SUM ciastka TO m.trzbacelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. !zaloha
				SUM ciastka TO m.trzbacelkhot FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. zaloha
				SUM dan TO m.dancelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. !zaloha
				SUM dan TO m.dancelkhot FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. zaloha
				SUM danzakl TO m.danzaklcelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. !zaloha
				SUM danzakl TO m.danzaklcelkhot FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. zaloha
				SUM danzakl TO m.danzakl0hot FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. dan=0 .AND. vyuct .AND. zaloha
				SUM danzakl TO m.danzakl0 FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. dan=0 .AND. vyuct .AND. !zaloha
				IF m.dancelk<>(m.trzbacelk-m.danzaklcelk)
					m.dancelk=m.trzbacelk-m.danzaklcelk
				ENDIF
	*			SELECT u_doklady
	*			SUM ciastka TO m.trzbacelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct
	*			m.trzbacelkhot=m.trzbacelk
				IF m.dancelk<>(m.trzbacelk-m.danzaklcelk)
					m.dancelk=m.trzbacelk-m.danzaklcelk
				ENDIF
				SELECT u_doklady
				LOCATE FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
				IF FOUND()
					m.upartner=u_doklady.partner
				ELSE
					m.upartner="WH"
				ENDIF
				SELECT hnab
				LOCATE FOR ALLTRIM(nabor)==ALLTRIM(m.upartner)
				IF FOUND()
					SCATTER MEMVAR FIELDS naborn,adr1,adr2,adr3,zem, ico, dic, tel, fax, email,nabor
				ELSE
					SELECT hban
					LOCATE FOR LEFT(ALLTRIM(jmeno),LEN(ALLTRIM(m.upartner)))==ALLTRIM(m.upartner)
					IF FOUND()
						m.naborn=hban.jmeno
						m.ico=""
						m.dic=""
						m.fax=""
						m.email=""
						m.nabor=STR(hban.ucet,8,0)
						SCATTER MEMVAR FIELDS adr1,adr2,adr3,zem,tel
					ELSE
						SELECT hmvh
						LOCATE FOR LEFT(ALLTRIM(jmeno),LEN(ALLTRIM(m.upartner)))==ALLTRIM(m.upartner)
						IF FOUND()
							m.naborn=hmvh.jmeno
							m.ico=""
							m.dic=""
							m.fax=""
							m.email=""
							m.nabor=""
							SCATTER MEMVAR FIELDS adr1,adr2,adr3,zem,tel
						ELSE
							m.naborn=m.upartner
							IF LEFT(m.naborn,4)="Ind."
								m.naborn=SUBSTR(m.naborn,AT("\",m.naborn)+1)
							ENDIF 
							m.ico=""
							m.dic=""
							m.fax=""
							m.email=""
							m.adr1=""
							m.adr2=""
							m.adr3=""
							m.zem="SVK"
							m.tel=""
							m.nabor=""
						ENDIF
					ENDIF  					
				ENDIF 


				m.uct00=""
				m.uct00="ADR="+IIF(m.zem="SVK","OT","OZ")+m.oddelovac  && adresny box C(2) od pozicie 5
				m.uct00=m.uct00+PADR(ALLTRIM(m.nabor),8)+m.oddelovac && Číslo adresy, jednoznačné označenie adresáta v rámci adresného boxu N(8) od pozicie 8
				m.uct00=m.uct00+PADR(ALLTRIM(m.naborn),15)+m.oddelovac && Matchcode=Skrátené označenie adresy C(15) od pozicie 17 
				m.uct00=m.uct00+PADR(ALLTRIM(m.naborn),30)+m.oddelovac && Nazov1 C(30) od pozicie 33
				m.uct00=m.uct00+SPACE(30)+m.oddelovac && Nazov2 C(30) od pozicie 64
				m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),30)+m.oddelovac && Kontakt C(30) od pozicie 95
				m.uct00=m.uct00+PADR(ALLTRIM(m.adr1),30)+m.oddelovac && ulica C(30) od pozicie 126
				m.uct00=m.uct00+IIF(m.zem="SVK"," SK",m.zem)+m.oddelovac && stat C(3) od pozicie 157 
				m.uct00=m.uct00+SPACE(7)+m.oddelovac && PSC C(7) od pozicie 161
				m.uct00=m.uct00+PADR(ALLTRIM(m.adr2),23)+m.oddelovac && Mesto C(23) od pozicie 169 
				m.uct00=m.uct00+PADR(ALLTRIM(m.ico),20)+m.oddelovac && ICO C(20) od pozicie 193
				m.uct00=m.uct00+PADR(ALLTRIM(m.dic),20)+m.oddelovac && DIC C(20) od pozicie 214
				m.uct00=m.uct00+PADR(ALLTRIM(m.tel),15)+m.oddelovac && Telefonne cislo C(15) od pozicie 235
				m.uct00=m.uct00+PADR(ALLTRIM(m.fax),15)+m.oddelovac && Faxove cislo C(15) od pozicie 251
				m.uct00=m.uct00+PADR(ALLTRIM(m.email),15)+m.oddelovac && e-mail C(15) od pozicie 267
				m.uct00=m.uct00+PADR("0",13)+m.oddelovac && Kredit - limit adresata*100 N(13) od pozicie 283
				m.uct00=m.uct00+PADR("0",2)+m.oddelovac && Cislo platobnej podmienky N(2) od pozicie 297
				m.uct00=m.uct00+"EUR"+m.oddelovac && Kod meny C(3) od pozicie 300
				m.uct00=m.uct00+"P"+m.oddelovac && Oznacenie dane pre doklady adresata C(1) od pozicie 304
				m.uct00=m.uct00+"  "+m.oddelovac && Oznacenie sposobu upominania C(2) od pozicie 306 
				m.uct00=m.uct00+PADR("0",5)+m.oddelovac && Percento penale pre upominanie*1000 N(5) od pozicie 309 
				= FPUTS(m.lihandle, m.uct00)

				m.uct00=""
				m.uct00="DOK=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+IIF(m.zem="SVK","OT","OZ")+m.oddelovac &&adresny box C(2) od pozicie 19
				m.uct00=m.uct00+PADR(ALLTRIM(m.nabor),8)+m.oddelovac &&cislo adresy N(8) od pozicie 22
				SELECT hfak
				GO TOP 
				LOCATE FOR ucet=VAL(u_doklady.datum)
				IF FOUND()
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum),4,0),2)+m.oddelovac	&& datum vystavenia dokladu C(6) od pozicie 31
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum),4,0),2)+m.oddelovac	&& datum odkedy sa pocitasplatnost C(6) od pozicie 38
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum+7),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum+7),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum+7),4,0),2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.odj),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.odj),2,0)," ","0")+RIGHT(STR(YEAR(hfak.odj),4,0),2)+m.oddelovac	&& datum uctovania dokladu C(6) od pozicie 52
					m.uct00=m.uct00+"PP P 21"+m.oddelovac && 8 prazdnych znakov od pozicie 59
					m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),12," ")+m.oddelovac && variabilny symbol dokladu C(12) od pozicie 67
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && parovaci symbol dokladu C(12) od pozicie 80
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && cislo objednavky z dokladu/ nepotrebne od pozicie 93
					m.uct00=m.uct00+"EUR"+m.oddelovac && kod meny C(3) od pozicie 106
					m.uct00=m.uct00+STR(1*1000,9,0)+m.oddelovac && kurz meny*1000 N(9) od pozicie 110
					m.uct00=m.uct00+STR(1,4,0)+m.oddelovac && pocet jednotiek meny N(4) od pozicie 120
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.odj),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.odj),2,0)," ","0")+RIGHT(STR(YEAR(hfak.odj),4,0),2)+m.oddelovac	&& datum kurzu C(6) od pozicie 125
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene dokladu*100 N(13) od pozicie 132
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene uctovnictva*100 N(13) od pozicie 146
					m.uct00=m.uct00+STR(ABS(m.dancelkhot*100),13,0)+m.oddelovac && suma dane v mene uctovnictva*100 / nepotrebne od pozicie 160 N(13)
					m.uct00=m.uct00+PADR(u_doklady.hs_md,10)+m.oddelovac && oznacenie hospodarskeho strediska / nepotrebne od pozicie 174 C(10)
					m.uct00=m.uct00+PADR("S090",12)+m.oddelovac && oznacenie nakladovej jednotky / nepotrebne od pozicie 185 C(12)
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && zakazka / nepotrebne od pozicie 198 C(10)
					m.uct00=m.uct00+"  2040"+m.oddelovac && oznacenie sprostredkovatela / nepotrebne od pozicie 209 N(6)
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.odj),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.odj),2,0)," ","0")+RIGHT(STR(YEAR(hfak.odj),4,0),2)+m.oddelovac	
				ELSE
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum vystavenia dokladu C(6) od pozicie 31
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum odkedy sa pocitasplatnost C(6) od pozicie 38
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum uctovania dokladu C(6) od pozicie 52
					m.uct00=m.uct00+"PP P 21"+m.oddelovac && 8 prazdnych znakov od pozicie 59
					m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),12," ")+m.oddelovac && variabilny symbol dokladu C(12) od pozicie 67
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && parovaci symbol dokladu C(12) od pozicie 80
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && cislo objednavky z dokladu/ nepotrebne od pozicie 93
					m.uct00=m.uct00+"EUR"+m.oddelovac && kod meny C(3) od pozicie 106
					m.uct00=m.uct00+STR(1*1000,9,0)+m.oddelovac && kurz meny*1000 N(9) od pozicie 110
					m.uct00=m.uct00+STR(1,4,0)+m.oddelovac && pocet jednotiek meny N(4) od pozicie 120
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum kurzu C(6) od pozicie 125
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene dokladu*100 N(13) od pozicie 132
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene uctovnictva*100 N(13) od pozicie 146
					m.uct00=m.uct00+STR(ABS(m.dancelkhot*100),13,0)+m.oddelovac && suma dane v mene uctovnictva*100 / nepotrebne od pozicie 160 N(13)
					m.uct00=m.uct00+PADR(u_doklady.hs_md,10)+m.oddelovac && oznacenie hospodarskeho strediska / nepotrebne od pozicie 174 C(10)
					m.uct00=m.uct00+PADR("S090",12)+m.oddelovac && oznacenie nakladovej jednotky / nepotrebne od pozicie 185 C(12)
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && zakazka / nepotrebne od pozicie 198 C(10)
					m.uct00=m.uct00+"  2040"+m.oddelovac && oznacenie sprostredkovatela / nepotrebne od pozicie 209 N(6)
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac
				ENDIF 
				SELECT u_doklady
				= FPUTS(m.lihandle, m.uct00)

				m.uct00="DAN=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+"P 319 "+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS((m.danzaklcelk-m.danzakl0+m.danzaklcelkhot-m.danzakl0hot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS((m.danzaklcelk-m.danzakl0+m.danzaklcelkhot-m.danzakl0hot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS((m.dancelk+m.dancelkhot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS((m.dancelk+m.dancelkhot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				= FPUTS(m.lihandle, m.uct00)
				IF m.danzakl0<>0
					m.uct00="DAN=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+"P 300 "+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS((m.danzakl0+m.danzakl0hot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+STR(ABS((m.danzakl0+m.danzakl0hot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+SPACE(13)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+SPACE(13)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					= FPUTS(m.lihandle, m.uct00)
				ENDIF
				m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+PADR(ALLTRIM(m.fakturamd),8," ")+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS(m.trzbacelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+"M"+m.oddelovac && strana uctovania C(1) od pozicie 42
				m.uct00=m.uct00+PADR("Faktura",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
				m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
				m.uct00=m.uct00+SPACE(12)+m.oddelovac && oznacenie nakladovej jednotky C(12) od pozicie 86
				m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie zakazky C(10) od pozicie 99
				m.uct00=m.uct00+"  2040" && oznacenie sprostredkovatela N(6) od pozicie 110
				= FPUTS(m.lihandle, m.uct00)
				SELECT u_dokl
				SCAN FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. !zaloha
					m.dal2=u_dokl.dal2
					m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+PADR(ALLTRIM(u_dokl.dal),8," ")+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(u_dokl.danzakl*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
					m.uct00=m.uct00+PADR("Trzba",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					m.uct00=m.uct00+PADR(hs_dal,10," ")+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
					m.uct00=m.uct00+PADR("S090",12," ")+m.oddelovac && oznacenie nakladovej jednotky C(12) od pozicie 86
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie zakazky C(10) od pozicie 99
					m.uct00=m.uct00+"  2040" && oznacenie sprostredkovatela N(6) od pozicie 110
					= FPUTS(m.lihandle, m.uct00)
				ENDSCAN
				m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+PADR(ALLTRIM(m.dal2),8," ")+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
				m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
				m.uct00=m.uct00+PADR("DPH P 319",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
				m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
				= FPUTS(m.lihandle, m.uct00)

				SELECT u_dokl
				SCAN FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. zaloha .AND. vyuct
					m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+PADR(ALLTRIM(u_dokl.dal2),8," ")+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(-ABS(u_dokl.dan*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
					m.uct00=m.uct00+PADR("DPH P 319",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
					= FPUTS(m.lihandle, m.uct00)
					m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+PADR(ALLTRIM(u_dokl.md2),8," ")+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(u_dokl.dan*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
					m.uct00=m.uct00+PADR("DPH K PRIJATEJ PLATBE",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
					= FPUTS(m.lihandle, m.uct00)
				ENDSCAN


				SELECT uexpartneri
			ENDSCAN
			USE IN hnab
			USE IN hmvh
			USE IN hban
			USE IN hfak
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[DATA-Koniec]"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[Koniec]"
			= FPUTS(m.lihandle, m.uct00)
			=FCLOSE(m.lihandle)
		ENDIF 
	ENDIF


	*!*	RELEASE gen_exp_had
	*!*	SET DELETED &oldsetdele

	*!*	USE IN uexpartneri
	*!*	USE IN u_doklady
	*!*	USE IN u_dokl
	*!*	USE IN u_dokl1
	*!*	USE IN u_dokl2


	*** Vyúčtovanie - ostatne platby okrem faktury***
	SELECT u_doklady
	LOCATE FOR !EMPTY(vyuct) .and. !faktura
	IF FOUND()
		SELECT 0
		USE (m.hor_path+"hfak.dbf") IN 0
		SELECT u_doklady
		SCAN FOR vyuct .AND. ALLTRIM(partner)="WH"
			SELECT hfak
			LOCATE FOR ucet=VAL(u_doklady.datum)
			IF FOUND()
				SELECT u_doklady
				REPLACE u_doklady.partner WITH hfak.jmeno
				SELECT u_dokl
				REPLACE partner WITH hfak.jmeno FOR datum=u_doklady.datum .AND. ALLTRIM(partner)=="WH"
			ENDIF 
			SELECT u_doklady
		ENDSCAN 
		USE IN hfak
		m.gcuexp_path = ALLTRIM(m.gcuexp_path)
		IF ! DIRECTORY(m.gcuexp_path)
			MKDIR (m.gcuexp_path)
		ENDIF
		IF USED("u_ex_plt")
			SELECT u_ex_plt
			m.ueplt=.t.
		ELSE
			SELECT 0
			USE (m.gcucto_path+"u_ex_plt")
			m.ueplt=.f.
		ENDIF 
		LOCATE FOR id_kas="WH" .AND. druh_pl="F"
		
		IF FOUND()
			m.fakturamd=ALLTRIM(u_ex_plt.md)
		ELSE
			m.fakturamd="311400"
		ENDIF
		IF !m.ueplt
			USE IN u_ex_plt
		ENDIF 
		RELEASE m.ueplt
		SELECT DISTINCT ALLTRIM(datum)+ALLTRIM(partner) AS partner FROM u_doklady INTO CURSOR uexpartneri WHERE vyuct AND !faktura READWRITE 
		PRIVATE trzbacelk, dancelk, danzaklcelk,trzbacelkhot
		m.exp_subor="VYUCTOVANIE2_" + m.mexp_meno+ ".txt"
		IF FILE(m.gcuexp_path+m.exp_subor)
			ERASE(m.gcuexp_path+m.exp_subor)
		ENDIF
		m.lihandle= FCREATE(m.gcuexp_path + m.exp_subor)
		IF m.lihandle > 0
			USE (m.hor_path+"hnab.dbf") IN 0
			USE (m.hor_path+"hmvh.dbf") IN 0
			USE (m.hor_path+"hban.dbf") IN 0
			USE (m.hor_path+"hfak.dbf") IN 0
			m.uct00=""
			m.uct00="; Export udajov pre uctovnictvo"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[Popis]"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Verzia=2"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Mandant=PEN"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Klient=0010"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Rok="+RIGHT(m.mrok,2)
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Cislo="+m.mmesiac
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Datum="+DTOC(DATE())
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="Cas="+TIME()
			= FPUTS(m.lihandle, m.uct00)
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[DATA-Start]"
			= FPUTS(m.lihandle, m.uct00)
			SCAN ALL
				m.cislodokladu=RIGHT(m.mrok,1)+"06800"+STRTRAN(STR((VAL(m.mmesiac)-1)*2+RECNO("uexpartneri")+30,2,0)," ","0")
				SELECT u_dokl
				SUM ciastka TO m.trzbacelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. !zaloha
				SUM ciastka TO m.trzbacelkhot FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. zaloha
				SUM dan TO m.dancelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. !zaloha
				SUM dan TO m.dancelkhot FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. zaloha
				SUM danzakl TO m.danzaklcelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. !zaloha
				SUM danzakl TO m.danzaklcelkhot FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct .AND. zaloha
				SUM danzakl TO m.danzakl0hot FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. dan=0 .AND. vyuct .AND. zaloha
				SUM danzakl TO m.danzakl0 FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. dan=0 .AND. vyuct .AND. !zaloha
				IF m.dancelk<>(m.trzbacelk-m.danzaklcelk)
					m.dancelk=m.trzbacelk-m.danzaklcelk
				ENDIF
	*			SELECT u_doklady
	*			SUM ciastka TO m.trzbacelk FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. vyuct
				IF m.dancelk<>(m.trzbacelk-m.danzaklcelk)
					m.dancelk=m.trzbacelk-m.danzaklcelk
				ENDIF
				SELECT u_doklady
				LOCATE FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
				IF FOUND()
					m.upartner=u_doklady.partner
				ELSE
					m.upartner="WH"
				ENDIF
				SELECT hnab
				LOCATE FOR ALLTRIM(nabor)==ALLTRIM(m.upartner)
				IF FOUND()
					SCATTER MEMVAR FIELDS naborn,adr1,adr2,adr3,zem, ico, dic, tel, fax, email,nabor
				ELSE
					SELECT hban
					LOCATE FOR LEFT(ALLTRIM(jmeno),LEN(ALLTRIM(m.upartner)))==ALLTRIM(m.upartner)
					IF FOUND()
						m.naborn=hban.jmeno
						m.ico=""
						m.dic=""
						m.fax=""
						m.email=""
						m.nabor=STR(hban.ucet,8,0)
						SCATTER MEMVAR FIELDS adr1,adr2,adr3,zem,tel
					ELSE
						SELECT hmvh
						LOCATE FOR LEFT(ALLTRIM(jmeno),LEN(ALLTRIM(m.upartner)))==ALLTRIM(m.upartner)
						IF FOUND()
							m.naborn=hmvh.jmeno
							m.ico=""
							m.dic=""
							m.fax=""
							m.email=""
							m.nabor=""
							SCATTER MEMVAR FIELDS adr1,adr2,adr3,zem,tel
						ELSE
							m.naborn=m.upartner
							IF LEFT(m.naborn,4)="Ind."
								m.naborn=SUBSTR(m.naborn,AT("\",m.naborn)+1)
							ENDIF 
							m.ico=""
							m.dic=""
							m.fax=""
							m.email=""
							m.adr1=""
							m.adr2=""
							m.adr3=""
							m.zem="SVK"
							m.tel=""
							m.nabor=""
						ENDIF
					ENDIF  					
				ENDIF 


				m.uct00=""
				m.uct00="ADR="+IIF(m.zem="SVK","OT","OZ")+m.oddelovac  && adresny box C(2) od pozicie 5
				m.uct00=m.uct00+PADR(ALLTRIM(m.nabor),8)+m.oddelovac && Číslo adresy, jednoznačné označenie adresáta v rámci adresného boxu N(8) od pozicie 8
				m.uct00=m.uct00+PADR(ALLTRIM(m.naborn),15)+m.oddelovac && Matchcode=Skrátené označenie adresy C(15) od pozicie 17 
				m.uct00=m.uct00+PADR(ALLTRIM(m.naborn),30)+m.oddelovac && Nazov1 C(30) od pozicie 33
				m.uct00=m.uct00+SPACE(30)+m.oddelovac && Nazov2 C(30) od pozicie 64
				m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),30)+m.oddelovac && Kontakt C(30) od pozicie 95
				m.uct00=m.uct00+PADR(ALLTRIM(m.adr1),30)+m.oddelovac && ulica C(30) od pozicie 126
				m.uct00=m.uct00+IIF(m.zem="SVK"," SK",m.zem)+m.oddelovac && stat C(3) od pozicie 157 
				m.uct00=m.uct00+SPACE(7)+m.oddelovac && PSC C(7) od pozicie 161
				m.uct00=m.uct00+PADR(ALLTRIM(m.adr2),23)+m.oddelovac && Mesto C(23) od pozicie 169 
				m.uct00=m.uct00+PADR(ALLTRIM(m.ico),20)+m.oddelovac && ICO C(20) od pozicie 193
				m.uct00=m.uct00+PADR(ALLTRIM(m.dic),20)+m.oddelovac && DIC C(20) od pozicie 214
				m.uct00=m.uct00+PADR(ALLTRIM(m.tel),15)+m.oddelovac && Telefonne cislo C(15) od pozicie 235
				m.uct00=m.uct00+PADR(ALLTRIM(m.fax),15)+m.oddelovac && Faxove cislo C(15) od pozicie 251
				m.uct00=m.uct00+PADR(ALLTRIM(m.email),15)+m.oddelovac && e-mail C(15) od pozicie 267
				m.uct00=m.uct00+PADR("0",13)+m.oddelovac && Kredit - limit adresata*100 N(13) od pozicie 283
				m.uct00=m.uct00+PADR("0",2)+m.oddelovac && Cislo platobnej podmienky N(2) od pozicie 297
				m.uct00=m.uct00+"EUR"+m.oddelovac && Kod meny C(3) od pozicie 300
				m.uct00=m.uct00+"P"+m.oddelovac && Oznacenie dane pre doklady adresata C(1) od pozicie 304
				m.uct00=m.uct00+"  "+m.oddelovac && Oznacenie sposobu upominania C(2) od pozicie 306 
				m.uct00=m.uct00+PADR("0",5)+m.oddelovac && Percento penale pre upominanie*1000 N(5) od pozicie 309 
				= FPUTS(m.lihandle, m.uct00)

				m.uct00=""
				m.uct00="DOK=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+IIF(m.zem="SVK","OT","OZ")+m.oddelovac &&adresny box C(2) od pozicie 19
				m.uct00=m.uct00+PADR(ALLTRIM(m.nabor),8)+m.oddelovac &&cislo adresy N(8) od pozicie 22
				SELECT hfak
				GO TOP 
				LOCATE FOR ucet=VAL(u_doklady.datum)
				IF FOUND()
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum),4,0),2)+m.oddelovac	&& datum vystavenia dokladu C(6) od pozicie 31
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum),4,0),2)+m.oddelovac	&& datum odkedy sa pocitasplatnost C(6) od pozicie 38
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.datum+7),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.datum+7),2,0)," ","0")+RIGHT(STR(YEAR(hfak.datum+7),4,0),2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.odj),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.odj),2,0)," ","0")+RIGHT(STR(YEAR(hfak.odj),4,0),2)+m.oddelovac	&& datum uctovania dokladu C(6) od pozicie 52
					m.uct00=m.uct00+"PP P 21"+m.oddelovac && 8 prazdnych znakov od pozicie 59
					m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),12," ")+m.oddelovac && variabilny symbol dokladu C(12) od pozicie 67
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && parovaci symbol dokladu C(12) od pozicie 80
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && cislo objednavky z dokladu/ nepotrebne od pozicie 93
					m.uct00=m.uct00+"EUR"+m.oddelovac && kod meny C(3) od pozicie 106
					m.uct00=m.uct00+STR(1*1000,9,0)+m.oddelovac && kurz meny*1000 N(9) od pozicie 110
					m.uct00=m.uct00+STR(1,4,0)+m.oddelovac && pocet jednotiek meny N(4) od pozicie 120
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.odj),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.odj),2,0)," ","0")+RIGHT(STR(YEAR(hfak.odj),4,0),2)+m.oddelovac	&& datum kurzu C(6) od pozicie 125
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene dokladu*100 N(13) od pozicie 132
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene uctovnictva*100 N(13) od pozicie 146
					m.uct00=m.uct00+STR(ABS(m.dancelkhot*100),13,0)+m.oddelovac && suma dane v mene uctovnictva*100 / nepotrebne od pozicie 160 N(13)
					m.uct00=m.uct00+PADR(u_doklady.hs_md,10)+m.oddelovac && oznacenie hospodarskeho strediska / nepotrebne od pozicie 174 C(10)
					m.uct00=m.uct00+PADR("S090",12)+m.oddelovac && oznacenie nakladovej jednotky / nepotrebne od pozicie 185 C(12)
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && zakazka / nepotrebne od pozicie 198 C(10)
					m.uct00=m.uct00+"  2040"+m.oddelovac && oznacenie sprostredkovatela / nepotrebne od pozicie 209 N(6)
					m.uct00=m.uct00+STRTRAN(STR(DAY(hfak.odj),2,0)," ","0")+STRTRAN(STR(MONTH(hfak.odj),2,0)," ","0")+RIGHT(STR(YEAR(hfak.odj),4,0),2)+m.oddelovac	
				ELSE
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum vystavenia dokladu C(6) od pozicie 31
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum odkedy sa pocitasplatnost C(6) od pozicie 38
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum splatnosti dokladu C(6) od pozicie 45
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum uctovania dokladu C(6) od pozicie 52
					m.uct00=m.uct00+"PP P 21"+m.oddelovac && 8 prazdnych znakov od pozicie 59
					m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.datum),12," ")+m.oddelovac && variabilny symbol dokladu C(12) od pozicie 67
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && parovaci symbol dokladu C(12) od pozicie 80
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && cislo objednavky z dokladu/ nepotrebne od pozicie 93
					m.uct00=m.uct00+"EUR"+m.oddelovac && kod meny C(3) od pozicie 106
					m.uct00=m.uct00+STR(1*1000,9,0)+m.oddelovac && kurz meny*1000 N(9) od pozicie 110
					m.uct00=m.uct00+STR(1,4,0)+m.oddelovac && pocet jednotiek meny N(4) od pozicie 120
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac	&& datum kurzu C(6) od pozicie 125
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene dokladu*100 N(13) od pozicie 132
					m.uct00=m.uct00+STR(ABS(m.trzbacelkhot*100),13,0)+m.oddelovac && suma v mene uctovnictva*100 N(13) od pozicie 146
					m.uct00=m.uct00+STR(ABS(m.dancelkhot*100),13,0)+m.oddelovac && suma dane v mene uctovnictva*100 / nepotrebne od pozicie 160 N(13)
					m.uct00=m.uct00+PADR(u_doklady.hs_md,10)+m.oddelovac && oznacenie hospodarskeho strediska / nepotrebne od pozicie 174 C(10)
					m.uct00=m.uct00+PADR("S090",12)+m.oddelovac && oznacenie nakladovej jednotky / nepotrebne od pozicie 185 C(12)
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && zakazka / nepotrebne od pozicie 198 C(10)
					m.uct00=m.uct00+"  2040"+m.oddelovac && oznacenie sprostredkovatela / nepotrebne od pozicie 209 N(6)
					m.uct00=m.uct00+RIGHT(m.mexp_meno,2)+SUBSTR(m.mexp_meno,5,2)+SUBSTR(m.mexp_meno,3,2)+m.oddelovac
				ENDIF 
				SELECT u_doklady
				= FPUTS(m.lihandle, m.uct00)

				m.uct00="DAN=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+"P 319 "+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS((m.danzaklcelk-m.danzakl0+m.danzaklcelkhot-m.danzakl0hot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS((m.danzaklcelk-m.danzakl0+m.danzaklcelkhot-m.danzakl0hot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS((m.dancelk+m.dancelkhot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+STR(ABS((m.dancelk+m.dancelkhot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				= FPUTS(m.lihandle, m.uct00)
				IF m.danzakl0<>0
					m.uct00="DAN=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+"P 300 "+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS((m.danzakl0+m.danzakl0hot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+STR(ABS((m.danzakl0+m.danzakl0hot)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+SPACE(13)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+SPACE(13)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					= FPUTS(m.lihandle, m.uct00)
				ENDIF


				SELECT u_doklady
				m.uzsuma=0
				SCAN FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner)
					m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+PADR(ALLTRIM(u_doklady.MD2),8," ")+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(u_doklady.ciastka*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
					m.uct00=m.uct00+"M"+m.oddelovac && strana uctovania C(1) od pozicie 42
					m.uzsuma=m.uzsuma+u_doklady.ciastka
					DO CASE
						CASE "hoto"$LOWER(u_doklady.poznamka)
							m.uct00=m.uct00+PADR("Hotovost",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
						CASE "k_"$LOWER(u_doklady.poznamka)
							m.uct00=m.uct00+PADR("Kredit karty",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
						CASE "n_bezho2"$LOWER(u_doklady.poznamka)
							m.uct00=m.uct00+PADR("Stravne listky",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
						CASE "n_pouk"$LOWER(u_doklady.poznamka)
							m.uct00=m.uct00+PADR("Poukazky",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
						OTHERWISE
							m.uct00=m.uct00+PADR("Hotovost",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					ENDCASE
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
					m.uct00=m.uct00+SPACE(12)+m.oddelovac && oznacenie nakladovej jednotky C(12) od pozicie 86
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie zakazky C(10) od pozicie 99
					m.uct00=m.uct00+"  2040" && oznacenie sprostredkovatela N(6) od pozicie 110
					= FPUTS(m.lihandle, m.uct00)
				ENDSCAN
				
				m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+PADR(ALLTRIM(m.fakturamd),8," ")+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS((m.trzbacelk-m.uzsuma)*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(13) od pozicie 28
				m.uct00=m.uct00+"M"+m.oddelovac && strana uctovania C(1) od pozicie 42
				m.uct00=m.uct00+PADR("Faktura",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
				m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
				m.uct00=m.uct00+SPACE(12)+m.oddelovac && oznacenie nakladovej jednotky C(12) od pozicie 86
				m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie zakazky C(10) od pozicie 99
				m.uct00=m.uct00+"  2040" && oznacenie sprostredkovatela N(6) od pozicie 110
				= FPUTS(m.lihandle, m.uct00)
				SELECT u_dokl
				SCAN FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. !zaloha
					m.dal2=u_dokl.dal2
					m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+PADR(ALLTRIM(u_dokl.dal),8," ")+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(u_dokl.danzakl*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
					m.uct00=m.uct00+PADR("Trzba",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					m.uct00=m.uct00+PADR(hs_dal,10," ")+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
					m.uct00=m.uct00+PADR("S090",12," ")+m.oddelovac && oznacenie nakladovej jednotky C(12) od pozicie 86
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie zakazky C(10) od pozicie 99
					m.uct00=m.uct00+"  2040" && oznacenie sprostredkovatela N(6) od pozicie 110
					= FPUTS(m.lihandle, m.uct00)
				ENDSCAN
				m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
				m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
				m.uct00=m.uct00+PADR(ALLTRIM(m.dal2),8," ")+m.oddelovac && ucet C(8) od pozicie 19
				m.uct00=m.uct00+STR(ABS(m.dancelk*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
				m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
				m.uct00=m.uct00+PADR("DPH P 319",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
				m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
				= FPUTS(m.lihandle, m.uct00)

				SELECT u_dokl
				SCAN FOR ALLTRIM(datum)+ALLTRIM(partner)=ALLTRIM(uexpartneri.partner) .AND. zaloha .AND. vyuct
					m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+PADR(ALLTRIM(u_dokl.dal2),8," ")+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(-ABS(u_dokl.dan*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
					m.uct00=m.uct00+PADR("DPH P 319",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
					= FPUTS(m.lihandle, m.uct00)
					m.uct00="UCT=FA68"+m.oddelovac  && druh dokladu C(4) od pozicie 5
					m.uct00=m.uct00+m.cislodokladu+m.oddelovac && cislo dokladu N(8) od pozicie 10
					m.uct00=m.uct00+PADR(ALLTRIM(u_dokl.md2),8," ")+m.oddelovac && ucet C(8) od pozicie 19
					m.uct00=m.uct00+STR(ABS(u_dokl.dan*100),13,0)+m.oddelovac && uctovana ciastka v mene uctovnictva*100 N(12) od pozicie 28
					m.uct00=m.uct00+"D"+m.oddelovac && strana uctovania C(1) od pozicie 42
					m.uct00=m.uct00+PADR("DPH K PRIJATEJ PLATBE",30," ")+m.oddelovac && text uctovneho pripadu C(30) od pozicie 44
					m.uct00=m.uct00+SPACE(10)+m.oddelovac && oznacenie hospodarskeho strediska C(10) od pozicie 75
					= FPUTS(m.lihandle, m.uct00)
				ENDSCAN


				SELECT uexpartneri
			ENDSCAN
			USE IN hnab
			USE IN hmvh
			USE IN hban
			USE IN hfak
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[DATA-Koniec]"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00=";"
			= FPUTS(m.lihandle, m.uct00)
			m.uct00="[Koniec]"
			= FPUTS(m.lihandle, m.uct00)
			=FCLOSE(m.lihandle)
		ENDIF 
	ENDIF
ENDIF 

RELEASE gen_exp_had
SET DELETED &oldsetdele
DO pozavirej WITH "uexpartneri, u_doklady, u_dokl, u_dokl1, u_dokl2, u_ex_platby, u_ex_polozky"
RETURN



PROCEDURE gen_exp_softip
PARAMETERS kontroluj,rokuct,mesuct
PRIVATE old_century,menoexp,oldsetdate,oldsetdele, riadkov, sumacelk,dokluzod,dokluzdo,prijemky, vydajky, ok
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.rokuct
m.hladajmesiac=m.mesuct
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
m.old_century=SET("century")
m.oldsetdate=SET("date")
m.oldsetdele=SET("dele")
SET DATE TO GERMAN
SET DELETED ON
m.gcuexp_path=ALLTRIM(IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path))
IF ! DIRECTORY(m.gcuexp_path)
	MKDIR (m.gcuexp_path)
ENDIF
SET CENTURY ON
gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
gen_exp_had.SHOW()
gen_exp_had.set_max(20)
gen_exp_had.INCREMENT("Sklady")
IF USED("u_ex_obraty")
	SELECT operace, datum, id_man, SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka,faktura, .F. AS storno,.F. AS vymaz FROM u_ex_obraty GROUP BY id_man,pz,datum,doklad,datum_dokl,MD,dal INTO CURSOR u_doklady WHERE INLIST(LEFT(pz,1),"P","V") READWRITE 
	DELETE FOR EMPTY(datum)
	DELETE FOR EMPTY(MD) .OR. EMPTY(dal)
	REPLACE ALL castka WITH ground(castka,2)
	DELETE FOR castka=0
	SELECT u_doklady
	SELECT 0
	IF m.issql
		USE (m.sqlprefix+"ruexarchobraty_mesiacrok") ALIAS uexarch IN 0
	ELSE 
		IF !FILE(m.gccen_path+"uexarchobraty.dbf")
			DO creafile WITH (m.gccen_path+"uexarchobraty.dbf")
		ENDIF 
		IF !USED("uexarchobraty")
			USE (m.gccen_path+"uexarchobraty") IN 0
		ENDIF 
		USE vuexarchobraty_mesiacrok IN 0 ALIAS uexarch
	ENDIF 
	=CURSORSETPROP("Buffering",5,"uexarch")
	IF m.kontroluj
		DO kontrola_skladov
	ELSE
		SELECT 0
		IF m.issql
			USE (m.sqlprefix+"ruzaverka") ALIAS expuzav
			INDEX on rok+mesiac TAG kedy
		ELSE 
			USE (m.gcdat_path+"uzaverka") AGAIN ALIAS expuzav ORDER kedy
		ENDIF 
		SET FILTER TO c_stredisk=m.gic_stredisk
		GO BOTTOM
		m.rokuct=expuzav.rok
		m.mesuct=expuzav.mesiac
		IF EMPTY(m.rokuct) .OR. EMPTY(m.mesuct)
			m.rokuct=STR(YEAR(DATE()),4,0)
			m.mesuct=STRTRAN(STR(MONTH(DATE()),2,0)," ","0")
		ELSE
			m.mesuct=STRTRAN(STR(VAL(m.mesuct)+1,2,0)," ","0")
			IF m.mesuct="13"
				m.mesuct="01"
				m.rokuct=STR(VAL(m.rokuct)+1,4,0)
			ENDIF
		ENDIF
		USE IN expuzav
	ENDIF
	SELECT u_doklady
	DELETE FOR castka=0
	SELECT DISTINCT pz FROM u_doklady WHERE !DELETED() INTO CURSOR pocetdokladov READWRITE 
	IF RECCOUNT("pocetdokladov")>0
		IF m.issql
			USE (m.sqlprefix+"rdoklady") IN 0 ALIAS doklady
			SELECT doklady
			INDEX on c_dokl TAG c_dokl
		ELSE 
			IF !USED("doklady")
				USE (m.fn_doklady) ALIAS doklady AGAIN IN 0 ORDER c_dokl
			ELSE
				SELECT doklady
				SET ORDER TO c_dokl
			ENDIF
		ENDIF 
		m.poraduz=dajsapcdcislo("Fod01B",m.rokuct, m.mesuct,"","")
		IF LOWER(m.gcuct_spec)="vodar"
			m.menoexp="Sklady"+m.rokuct+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")
			CREATE TABLE (m.gcuexp_path+m.menoexp)	FREE (strana c(20),skupina i, ucet i, poradac c(20), ciastka y, kod c(20), organiz c(20), par_znak c(20), zakazka c(20), majetok c(20), zmluva C(20),;
				naklad c(20), ekon c(20), poznamka c(20))
			USE
			SELECT SUM(castka) as ciastka, operace, md, dal, md2, hs_md, partner FROM u_doklady INTO CURSOR aaa GROUP BY operace, md, dal, md2, hs_md, partner
			INSERT INTO (m.gcuexp_path+m.menoexp) (strana, skupina, ucet, poradac, ciastka, kod, organiz, par_znak, zakazka, majetok, zmluva, naklad, ekon, poznamka);
				 SELECT "M",1,VAL(md),100, ABS(ciastka),"","008032", "", "", "", "", "", "",partner FROM aaa
			INSERT INTO (m.gcuexp_path+m.menoexp) (strana, skupina, ucet, poradac, ciastka, kod, organiz, par_znak, zakazka, majetok, zmluva, naklad, ekon, poznamka);
				 SELECT "D",1,VAL(dal),100, ABS(ciastka),"","008032", "", "", "", "", hs_md, md2,partner FROM aaa
			USE IN aaa
			SELECT (menoexp)
			EXPORT ALL TO (m.gcuexp_path+m.menoexp) TYPE XLS 
			USE IN (menoexp)
		ELSE 
			m.menoexp="Fod01B"+STRTRAN(STR(m.poraduz,2,0)," ","0")+"."+RIGHT(m.rokuct,1)+m.mesuct
			SELECT u_doklady
			SELECT u_doklady
			SET RELATION TO VAL(ALLTRIM(datum)) INTO doklady
			SELECT 0
			CREATE TABLE (m.gcuexp_path+m.menoexp)	FREE (dd c(5),CD c(15), pol N(4,0), datum d(8), ucet c(12), hs c(10), MD N(14,2), dal N(14,2),;
				cfak N(10,0), kodpu N(4,0), pcbu N(6,0), cbu N(10,0), ss N(10,0), spl d(8), tp c(3), zak c(12), oper c(40), perpen N(5,2), kodm c(3),;
				mdmena N(14,2), dmena N(14,2), clo c(1), mokod c(2), cinn_md c(4), cinn_dal c(4), uct1_md c(15), uct1_dal c(15),uct2_md c(15), uct2_dal c(15),;
				subj_id N(20,4))
			USE
			m.riadkov=1
			SELECT u_doklady
			SCAN FOR LOWER(ALLTRIM(MD))<>"export"
				INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,hs,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,ss,kodm,mdmena,dmena, hs, cinn_md, cinn_dal, zak) VALUES ;
					("880",u_doklady.datum,m.riadkov,u_doklady.datum_dokl,u_doklady.MD,u_doklady.hs_md,ABS(u_doklady.castka),0,0,0,0,0,DATE(),u_doklady.partner,0,en__meny(m.uct_mena,3),ABS(u_doklady.castka),0, u_doklady.hs_md, LEFT(ALLTRIM(u_doklady.md2),4),"",RIGHT(ALLTRIM(u_doklady.md2),2))
				INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,hs,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,ss,kodm,mdmena,dmena, hs, cinn_md, cinn_dal, zak) VALUES ;
					("880",u_doklady.datum,m.riadkov,u_doklady.datum_dokl,u_doklady.dal,u_doklady.hs_dal,0,ABS(u_doklady.castka),0,0,0,0,DATE(),u_doklady.partner,0,en__meny(m.uct_mena,3),0,ABS(u_doklady.castka), u_doklady.hs_dal, "",LEFT(ALLTRIM(u_doklady.dal2),4),RIGHT(ALLTRIM(u_doklady.dal2),2))
				m.riadkov=m.riadkov+1
			ENDSCAN
			SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
				SELECT uexarch
				DELETE FOR datum=u_doklady.datum
				SELECT u_doklady
			ENDSCAN
			SELECT uexarch
			APPEND FROM DBF("u_doklady") FOR !storno AND !vymaz
			REPLACE c_data WITH m.cdata FOR c_data<>m.cdata
			REPLACE ALL mesiac WITH m.mesuct FOR mesiac<>m.mesuct
			REPLACE ALL rok WITH m.rokuct FOR rok<>m.rokuct
			=tux(.t.,.t.,"uexarch")
		ENDIF 
		IF !m.issql
			DO pozavirej WITH "uexarchobraty"
			IF f_acc_ex(m.gcdat_path+"uexarchobraty")
				PACK
				USE
			ENDIF
		ENDIF 
		IF USED(LEFT(m.menoexp,LEN(m.menoexp)-4))
			USE IN (LEFT(m.menoexp,LEN(m.menoexp)-4))
		ENDIF
	ENDIF 
	DO pozavirej WITH "uexarch, uexarchobraty, u_doklady, pocetdokladov"
ENDIF 
IF m.gcuct_trzba AND USED("u_ex_polozky") AND USED("u_ex_platby")
	gen_exp_had.INCREMENT("Tržby")
	IF LOWER(m.gcuct_spec)="vodar" AND !EMPTY(m.gcuct_prehoducty)
		LOCAL rlist, r1, rdoklad, md1, dal1, m.xxpocet
		m.rlist=m.gcuct_prehoducty
		DO WHILE .t.
			IF EMPTY(m.rlist)
				EXIT
			ELSE
				IF AT(",",m.rlist)=0
					m.r1=m.rlist
					m.rlist=""
				ELSE 
					m.r1=LEFT(m.rlist,AT(",",m.rlist)-1)
					m.rlist=SUBSTR(m.rlist,AT(",",m.rlist)+1)
				ENDIF 
			ENDIF 
			SELECT DISTINCT doklad FROM u_ex_polozky WHERE id_kas="WH" AND SUBSTR(poznamka,11,LEN(m.r1))==m.r1 INTO CURSOR dokladynaopravu READWRITE 
			IF RECCOUNT("dokladynaopravu")>0
				SELECT dokladynaopravu
				SCAN ALL 
					m.rdoklad=dokladynaopravu.doklad
					SELECT u_ex_polozky
					COUNT TO m.xxpocet FOR doklad=m.rdoklad AND id_kas="WH"
					IF m.xxpocet=1
						LOCATE FOR doklad=m.rdoklad AND id_kas="WH"
						IF FOUND()
							m.dal1=u_ex_polozky.dal
							SELECT u_ex_platby
							COUNT TO m.xxpocet FOR doklad=m.rdoklad AND id_kas="WH"
							IF m.xxpocet=1
								LOCATE FOR doklad=m.rdoklad AND id_kas="WH"
								IF FOUND()
									m.md1=u_ex_platby.md
									REPLACE castka WITH -castka, md WITH m.dal1 FOR doklad=m.rdoklad AND id_kas="WH"
									SELECT u_ex_polozky
									REPLACE castka WITH -castka, dal WITH m.md1 FOR doklad=m.rdoklad AND id_kas="WH"
								ENDIF 
							ENDIF 
						ENDIF 
					ENDIF 
					SELECT dokladynaopravu
				ENDSCAN 
			ENDIF 
			USE IN dokladynaopravu
		ENDDO 
	ENDIF 		
	SELECT SUM(castka) AS ciastka, MD,dal,md2,dal2,hs_dal,hs_md,partner,pz, poznamka, $0 AS celkom, 1.000000000 AS koef FROM u_ex_platby GROUP BY pz,poznamka,MD,dal INTO CURSOR u_doklady READWRITE 
	SELECT SUM(castka) AS ciastka, pz FROM u_ex_platby GROUP BY pz INTO CURSOR u_platby  READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	SELECT u_doklady
	SET RELATION TO ALLTRIM(pz) INTO u_platby
	REPLACE ALL u_doklady.celkom WITH u_platby.ciastka
	SET RELATION OFF INTO u_platby
	USE IN u_platby
	REPLACE ALL koef WITH IIF(celkom=0,1,ciastka/celkom)
	SELECT SUM(castka) AS ciastka, MD,dal,hs_md, hs_dal,md2,dal2, pz, partner,poznamka,$0 AS danzakl, $0 AS dan FROM u_ex_polozky GROUP BY pz,poznamka,MD,dal INTO CURSOR u_dokl1 READWRITE 
	SELECT u_dokl1
	REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
	REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka FROM u_dokl1 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl2 READWRITE 
	USE IN u_dokl1
	REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
	SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2,poznamka FROM u_dokl2 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	USE IN u_dokl2
	SELECT u_doklady
	SELECT DISTINCT pz FROM u_doklady WHERE !DELETED() UNION SELECT DISTINCT pz FROM u_dokl WHERE !DELETED() INTO CURSOR pocetdokladov READWRITE 
	IF RECCOUNT("pocetdokladov")>0
		IF LOWER(m.gcuct_spec)="vodar"
			m.poraduz=dajsapcdcislo("TržbFood",m.rokuct, m.mesuct,"","")
			m.menoexp="TržbyFood"+m.rokuct+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")
			m.menoexp2="asasas"
			m.gcuexp_path = ALLTRIM(m.gcuexp_path)
			IF ! DIRECTORY(m.gcuexp_path)
				MKDIR (m.gcuexp_path)
			ENDIF
			CREATE TABLE (m.gcuexp_path+m.menoexp)	FREE (strana c(20),skupina i, ucet i, poradac c(20), ciastka y, kod c(20), organiz c(20), par_znak c(20), zakazka c(20), majetok c(20), zmluva C(20),;
				naklad c(20), ekon c(20), poznamka c(20))
			USE
			SELECT SPACE(17) AS uzaverka,ciastka, MD,dal,md2,dal2,hs_dal,hs_md,poznamka, celkom, $0 AS danzakl, $0 AS dan, ;
				SPACE(5) AS sadzba FROM u_doklady INTO CURSOR vondbf WHERE .f. READWRITE 
			SELECT u_doklady
			SCAN FOR !EMPTY(u_doklady.MD) .AND. !EMPTY(u_doklady.dal) .AND. u_doklady.ciastka<>0
				SELECT u_dokl
				SCAN FOR pz=u_doklady.pz .AND. !EMPTY(u_dokl.MD) .AND. !EMPTY(u_dokl.dal)
					IF u_doklady.MD=u_dokl.dal
						INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba) VALUES ;
							(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_dokl.MD,u_doklady.dal,u_dokl.md2,u_doklady.dal2,u_dokl.hs_md,u_doklady.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka)
					ELSE
						IF u_doklady.dal=u_dokl.MD
							INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba) VALUES ;
								(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_doklady.MD,u_dokl.dal,u_dokl.md2,u_dokl.dal2,u_dokl.hs_md,u_dokl.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka)
						ENDIF
					ENDIF
				ENDSCAN
				SELECT u_doklady
			ENDSCAN
			SELECT SUM(ciastka) as ciastka, uzaverka, md FROM vondbf INTO CURSOR aaa GROUP BY uzaverka, md
			INSERT INTO (m.gcuexp_path+m.menoexp) (strana, skupina, ucet, poradac, ciastka, kod, organiz, par_znak, zakazka, majetok, zmluva, naklad, ekon, poznamka);
				 SELECT "M",1,VAL(md),100, ciastka,"","008032", "", "", "", "", "", "",uzaverka FROM aaa
			USE IN aaa
			SELECT SUM(danzakl) as danzakl, uzaverka, dal, hs_dal, md2, sadzba FROM vondbf INTO CURSOR aaa GROUP BY uzaverka, dal, hs_dal, md2, sadzba
			INSERT INTO (m.gcuexp_path+m.menoexp) (strana, skupina, ucet, poradac, ciastka, kod, organiz, par_znak, zakazka, majetok, zmluva, naklad, ekon, poznamka);
				 SELECT "D",1,VAL(dal),100, danzakl,ICASE(ALLTRIM(sadzba)="20","UHD1",ALLTRIM(sadzba)="10","UDD1","    "),"008032", "", "", "", "", hs_dal, md2,uzaverka FROM aaa
			USE IN aaa
			SELECT SUM(dan) as dan, uzaverka, dal, hs_dal, dal2, sadzba FROM vondbf INTO CURSOR aaa GROUP BY uzaverka, dal, hs_dal, dal2, sadzba
			INSERT INTO (m.gcuexp_path+m.menoexp) (strana, skupina, ucet, poradac, ciastka, kod, organiz, par_znak, zakazka, majetok, zmluva, naklad, ekon, poznamka);
				 SELECT "D",1,VAL(dal2),100, dan,ICASE(ALLTRIM(sadzba)="20","UHD1",ALLTRIM(sadzba)="10","UDD1","    "),"008032", "", "", "", "", hs_dal, dal2,uzaverka FROM aaa
			USE IN aaa
			SELECT (menoexp)
			EXPORT ALL TO (m.gcuexp_path+m.menoexp) TYPE XLS 
			USE IN (menoexp)
		ELSE 
			m.poraduz=dajsapcdcislo("Kas01B",m.rokuct, m.mesuct,"","")
			m.menoexp="Kas01B"+STRTRAN(STR(m.poraduz,2,0)," ","0")+"."+RIGHT(m.rokuct,1)+m.mesuct
			m.menoexp2=STRTRAN(m.menoexp,"B","P")
			m.gcuexp_path = ALLTRIM(m.gcuexp_path)
			IF ! DIRECTORY(m.gcuexp_path)
				MKDIR (m.gcuexp_path)
			ENDIF
			CREATE TABLE (m.gcuexp_path+m.menoexp)	FREE (dd c(5),CD c(15), pol N(4,0), datum d(8), ucet c(12), hs c(10), MD N(14,2), dal N(14,2),;
				cfak N(10,0), kodpu N(4,0), pcbu N(6,0), cbu N(10,0), ss N(10,0), spl d(8), tp c(3), zak c(12), oper c(40), perpen N(5,2), kodm c(3),;
				mdmena N(14,2), dmena N(14,2), clo c(1), mokod c(2), cinn_md c(4), cinn_dal c(4), uct1_md c(15), uct1_dal c(15),uct2_md c(15), uct2_dal c(15),;
				subj_id N(20,4))
			USE
			CREATE TABLE (m.gcuexp_path+m.menoexp2)	FREE (vv c(1), dic c(14), osob c(1), dd c(5),CD c(15), dodcf N(10,0), cena0 N(13,2), cena5 N(13,2), cena23 N(13,2),;
				dan5 N(12,2),dan23 N(12,2), tuzem c(1), datvys d(8), datvzp d(8),;
				TEXT c(20), oslob c(1), dbp l(1), poloz c(1), flase l(1), datzap d(8), dd2 c(5), cd2 c(15), td c(1), subj_id N(20,4), povpl c(1),;
				intra c(1), dodcf2 c(32), dobrop2 c(32), colsadz c(4), tovar c(2), mnoz n(11,2), merjedn c(5), doklerp c(1))
			USE
			SELECT SPACE(17) AS uzaverka,ciastka, MD,dal,md2,dal2,hs_dal,hs_md,poznamka, celkom, $0 AS danzakl, $0 AS dan, ;
				SPACE(5) AS sadzba FROM u_doklady INTO CURSOR vondbf WHERE .f. READWRITE 
			SELECT u_doklady
			SCAN FOR !EMPTY(u_doklady.MD) .AND. !EMPTY(u_doklady.dal) .AND. u_doklady.ciastka<>0
				SELECT u_dokl
				SCAN FOR pz=u_doklady.pz .AND. !EMPTY(u_dokl.MD) .AND. !EMPTY(u_dokl.dal)
					IF u_doklady.MD=u_dokl.dal
						INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba) VALUES ;
							(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_dokl.MD,u_doklady.dal,u_dokl.md2,u_doklady.dal2,u_dokl.hs_md,u_doklady.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka)
					ELSE
						IF u_doklady.dal=u_dokl.MD
							INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba) VALUES ;
								(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_doklady.MD,u_dokl.dal,u_dokl.md2,u_dokl.dal2,u_dokl.hs_md,u_dokl.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka)
						ENDIF
					ENDIF
				ENDSCAN
				SELECT u_doklady
			ENDSCAN
			SELECT uzaverka,SUM(ciastka) AS ciastka,MD,dal,md2,dal2,hs_md,hs_dal, SUM(danzakl) AS danzakl, SUM(dan) AS dan, sadzba FROM vondbf ;
				GROUP BY uzaverka, MD, dal, sadzba INTO CURSOR vondbf2 READWRITE 
			SELECT uzaverka, SUM(ciastka) AS ciastka,MD,dal,md2,dal2,hs_md,hs_dal, 0000000000.00 AS cena0, 0000000000.00 AS cena5, 0000000000.00 AS cena23, 000000000.00 AS dan5, 000000000.00 AS dan23,.F. AS vymaz,.F. AS storno FROM vondbf ;
				GROUP BY uzaverka, MD, dal INTO CURSOR vondbf1 READWRITE 
			m.riadkov=1
			SCAN ALL
				SELECT vondbf2
				SCAN FOR MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. uzaverka=vondbf1.uzaverka
					DO CASE
						CASE ALLTRIM(sadzba)="0"
							REPLACE vondbf1.cena0 WITH vondbf2.danzakl
						CASE ALLTRIM(sadzba)=ALLTRIM(STR((m.uctdphlo-1)*100,10,0))
							REPLACE vondbf1.cena5 WITH vondbf2.danzakl, vondbf1.dan5 WITH vondbf2.dan
						OTHERWISE
							REPLACE vondbf1.cena23 WITH vondbf2.danzakl, vondbf1.dan23 WITH vondbf2.dan
					ENDCASE
				ENDSCAN
			ENDSCAN
			IF !m.issql
				IF FILE(m.gcdat_path+"uexarsk.dbf")
					SELECT 0
					USE (m.gcdat_path+"uexarsk.dbf")
				ELSE
					SELECT vondbf1
					COPY STRUCTURE TO (m.gcdat_path+"uexarsk.dbf")
					SELECT 0
					USE (m.gcdat_path+"uexarsk.dbf")
				ENDIF
			ENDIF 
			IF m.kontroluj
				SELECT DISTINCT uzaverka FROM vondbf1 INTO CURSOR datumy READWRITE 
				SCAN ALL
					m.hladajuzaverka=datumy.uzaverka
					m.oprava=0
					SELECT vondbf1
					SCAN FOR uzaverka=datumy.uzaverka
						IF m.issql
							IF USED("uexarsk")
								=REQUERY("uexarsk")
							ELSE
								USE (m.sqlprefix+"ruexarsk") ALIAS uexarsk IN 0
								=CURSORSETPROP("Buffering",5,"uexarsk")
							ENDIF 
						ENDIF 
						SELECT uexarsk
						LOCATE FOR uzaverka=vondbf1.uzaverka
						IF FOUND()
							LOCATE FOR uzaverka=vondbf1.uzaverka .AND. ciastka=vondbf1.ciastka .AND. MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. cena0=vondbf1.cena0 .AND. cena5=vondbf1.cena5 ;
								.AND. cena23=vondbf1.cena23 .AND. dan5=vondbf1.dan5 .AND. dan23=vondbf1.dan23 .AND. hs_md=vondbf1.hs_md .AND. hs_dal=vondbf1.hs_dal
							IF !FOUND()
								m.oprava=2
							ELSE
								m.oprava=1
							ENDIF
						ELSE
							m.oprava=0
						ENDIF
						SELECT vondbf1
						IF m.oprava=2
							EXIT
						ENDIF
					ENDSCAN
					DO CASE
						CASE m.oprava=2
							SELECT uexarsk
							SCAN FOR uzaverka=datumy.uzaverka
								INSERT INTO vondbf1 (uzaverka,ciastka,MD,dal,hs_md, hs_dal,md2,dal2,cena0,cena5,cena23,dan5,dan23,storno);
									VALUES (uexarsk.uzaverka,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,uexarsk.md2,uexarsk.dal2,-uexarsk.cena0,-uexarsk.cena5,;
									-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.T.)
							ENDSCAN
						CASE m.oprava=1
							SELECT vondbf1
							DELETE FOR uzaverka=datumy.uzaverka
					ENDCASE
					SELECT datumy
				ENDSCAN
				IF m.issql
					USE (m.sqlprefix+"ruexarsk_zoznam_uzavierok") ALIAS uexzoznam IN 0
					SELECT DISTINCT uzaverka FROM uexzoznam WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
						INTO CURSOR datumy2 READWRITE 
					USE IN uexzoznam
				ELSE 
					SELECT DISTINCT uzaverka FROM uexarsk WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
						INTO CURSOR datumy2 READWRITE 
				ENDIF 
				SCAN ALL
					m.hladajuzaverka=datumy2.uzaverka
					IF m.issql
						=REQUERY("uexarsk")
					ENDIF 
					SELECT uexarsk
					SCAN FOR uzaverka=datumy2.uzaverka
						INSERT INTO vondbf1 (uzaverka,ciastka,MD,dal,hs_md, hs_dal,cena0,cena5,cena23,dan5,dan23,storno,vymaz);
							VALUES (uexarsk.uzaverka,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,-uexarsk.cena0,-uexarsk.cena5,;
							-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.F.,.T.)
					ENDSCAN
					SELECT datumy2
				ENDSCAN
				USE IN datumy2

			ENDIF
			m.poraduz=dajsapcdcislo("Doklad", m.rokuct, m.mesuct,"","")
			SELECT vondbf1
			SCAN ALL
				m.vonuz=m.mesuct+PADL(ALLTRIM(STR(m.poraduz+m.riadkov,15,0)),5,"0")
				INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,kodm,mdmena,dmena,subj_id,cfak, cinn_md, cinn_dal, zak, hs) VALUES ;
					("166",m.vonuz,0,DATE(),vondbf1.MD,vondbf1.ciastka,0,0,0,0,0,DATE(),"",en__meny(m.uct_mena,3),vondbf1.ciastka,0,VAL(vondbf1.hs_md),VAL(LEFT(vondbf1.uzaverka,6)),"","","","")
				INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,hs,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,kodm,mdmena,dmena,subj_id,cfak, cinn_md, cinn_dal, zak, hs) VALUES ;
					("166",m.vonuz,0,DATE(),vondbf1.dal,vondbf1.hs_dal,0,vondbf1.cena0+vondbf1.cena5+vondbf1.cena23,0,0,0,0,DATE(),"",en__meny(m.uct_mena,3),0,vondbf1.cena0+vondbf1.cena5+vondbf1.cena23,VAL(vondbf1.hs_md),VAL(LEFT(vondbf1.uzaverka,6)),"",LEFT(ALLTRIM(vondbf1.md2),4),RIGHT(ALLTRIM(vondbf1.md2),2),vondbf1.hs_dal)
				INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,kodm,mdmena,dmena,subj_id,cfak) VALUES ;
					("166",m.vonuz,0,DATE(),vondbf1.dal2,0,vondbf1.dan5+vondbf1.dan23,0,0,0,0,DATE(),"",en__meny(m.uct_mena,3),0,vondbf1.dan5+vondbf1.dan23,VAL(vondbf1.hs_md),VAL(LEFT(vondbf1.uzaverka,6)))
				INSERT INTO (m.gcuexp_path+m.menoexp2) (vv,dic,dd,CD,cena0,cena5,cena23,dan5,dan23,tuzem,datvys,datvzp,TEXT,td,subj_id,povpl,dodcf,dbp,flase, doklerp) VALUES ;
					("O",m.hot_icdph,"166",m.vonuz,vondbf1.cena0,vondbf1.cena5,vondbf1.cena23,vondbf1.dan5,vondbf1.dan23,"T",DATE(),CTOD(SUBSTR(vondbf1.uzaverka,7,2)+"."+SUBSTR(vondbf1.uzaverka,5,2)+"."+LEFT(vondbf1.uzaverka,4)),"","D",VAL(vondbf1.hs_md),"T",0,.F.,.F.,"2")
				m.riadkov=m.riadkov+1
			ENDSCAN
			=setsapcdcislo("Doklad",m.rokuct, m.mesuct,m.riadkov-1)		
			SELECT vondbf1
			SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
				IF m.issql
					m.hladajuzaverka=vondbf1.uzaverka
					=REQUERY("uexarsk")
					SELECT uexarsk
					DELETE ALL 
					=tux(.t.,.t.,"uexarsk")
				ELSE 
					SELECT uexarsk
					DELETE FOR uzaverka=vondbf1.uzaverka
				ENDIF 
				SELECT vondbf1
			ENDSCAN
			IF m.issql
				m.hladajuzaverka="xxx"
				=REQUERY("uexarsk")
			ENDIF 
			SELECT uexarsk
			APPEND FROM DBF("vondbf1") FOR !storno .AND. !vymaz
			IF m.issql
				=tux(.t.,.t.,"uexarsk")
			ENDIF 
			DO pozavirej WITH "uexarsk"
			IF !m.issql
				IF f_acc_ex(m.gcdat_path+"uexarsk")
					PACK
					USE
				ENDIF
			ENDIF 
		ENDIF 
	ENDIF
	SET CENTURY &old_century
	SET DATE &oldsetdate
	SET DELETED &oldsetdele
	DO pozavirej WITH "vondbf, u_doklady, u_dokl, vondbf1, vondbf2, datumy, u_ex_platby, u_ex_polozky, pocetdokladov"
	TRY 
		IF USED(LEFT(m.menoexp,LEN(m.menoexp)-4))
			USE IN (LEFT(m.menoexp,LEN(m.menoexp)-4))
		ENDIF
	CATCH
	ENDTRY 
	TRY 
		IF USED(LEFT(m.menoexp2,LEN(m.menoexp2)-4))
			USE IN (LEFT(m.menoexp2,LEN(m.menoexp2)-4))
		ENDIF
	CATCH
	ENDTRY 
ENDIF
RELEASE gen_exp_had
RETURN

PROCEDURE gen_exp_epos
PARAMETERS kontroluj,rokuct,mesuct
PRIVATE old_century,menoexp,oldsetdate,oldsetdele, riadkov, sumacelk,dokluzod,dokluzdo,prijemky, vydajky, ok
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.rokuct
m.hladajmesiac=m.mesuct
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
m.old_century=SET("century")
m.oldsetdate=SET("date")
m.oldsetdele=SET("dele")
SET DATE TO GERMAN
SET DELETED ON
m.gcuexp_path=ALLTRIM(IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path))
IF ! DIRECTORY(m.gcuexp_path)
	MKDIR (m.gcuexp_path)
ENDIF
SET CENTURY ON
gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
gen_exp_had.SHOW()
gen_exp_had.set_max(20)
gen_exp_had.INCREMENT("Sklady")
IF USED("u_ex_obraty")
	SELECT operace, datum, id_man, SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka,faktura,.F. AS storno,.F. AS vymaz FROM u_ex_obraty GROUP BY id_man,pz,datum,doklad,datum_dokl,MD,dal INTO CURSOR u_doklady WHERE INLIST(LEFT(pz,1),"P","V") READWRITE 
	DELETE FOR EMPTY(datum)
	DELETE FOR EMPTY(MD) .OR. EMPTY(dal)
	SELECT u_doklady
	SELECT 0
	IF m.issql
		USE (m.sqlprefix+"ruexarchobraty_mesiacrok") ALIAS uexarch IN 0
	ELSE 
		IF !FILE(m.gccen_path+"uexarchobraty.dbf")
			DO creafile WITH (m.gccen_path+"uexarchobraty.dbf")
		ENDIF 
		IF !USED("uexarchobraty")
			USE (m.gccen_path+"uexarchobraty") IN 0
		ENDIF 
		USE vuexarchobraty_mesiacrok IN 0 ALIAS uexarch
	ENDIF 
	=CURSORSETPROP("Buffering",5,"uexarch")
	IF m.kontroluj
		DO kontrola_skladov
	ELSE
		IF m.issql
			USE (m.sqlprefix+"ruzaverka") ALIAS expuzav
			INDEX on rok+mesiac TAG kedy
		ELSE 
			USE (m.gcdat_path+"uzaverka") AGAIN ALIAS expuzav ORDER kedy
		ENDIF 
		SET FILTER TO c_stredisk=m.gic_stredisk
		GO BOTTOM
		m.rokuct=expuzav.rok
		m.mesuct=expuzav.mesiac
		IF EMPTY(m.rokuct) .OR. EMPTY(m.mesuct)
			m.rokuct=STR(YEAR(DATE()),4,0)
			m.mesuct=STRTRAN(STR(MONTH(DATE()),2,0)," ","0")
		ELSE
			m.mesuct=STRTRAN(STR(VAL(m.mesuct)+1,2,0)," ","0")
			IF m.mesuct="13"
				m.mesuct="01"
				m.rokuct=STR(VAL(m.rokuct)+1,4,0)
			ENDIF
		ENDIF
		USE IN expuzav
	ENDIF
	SELECT u_doklady
	DELETE FOR castka=0
	IF m.issql
		USE (m.sqlprefix+"rdoklady") IN 0 ALIAS doklady
		SELECT doklady
		INDEX on c_dokl TAG c_dokl
	ELSE 
		IF !USED("doklady")
			USE (m.fn_doklady) ALIAS doklady AGAIN IN 0 ORDER c_dokl
		ELSE
			SELECT doklady
			SET ORDER TO c_dokl
		ENDIF
	ENDIF 
	m.poraduz=dajsapcdcislo("SKLADY", m.rokuct, m.mesuct,"", "")
	m.menoexp="SKLADY"+RIGHT(m.rokuct,1)+m.mesuct+STRTRAN(STR(m.poraduz,3,0)," ","0")+".DBF"
	SELECT u_doklady
	SET RELATION TO VAL(ALLTRIM(datum)) INTO doklady
	SELECT 0
	CREATE TABLE (m.gcuexp_path+m.menoexp)	FREE (c_dokl i, datum d(8), ucet c(12), hs c(10), MD N(14,2), dal N(14,2),partner c(30))
	USE
	m.riadkov=1
	SELECT u_doklady
	SCAN FOR LOWER(ALLTRIM(MD))<>"export"
		INSERT INTO (m.gcuexp_path+m.menoexp) (c_dokl,datum,ucet,hs,MD,dal,partner) VALUES ;
			(VAL(u_doklady.datum),u_doklady.datum_dokl,u_doklady.MD,u_doklady.hs_md,ABS(u_doklady.castka),0,u_doklady.partner)
		INSERT INTO (m.gcuexp_path+m.menoexp) (c_dokl,datum,ucet,hs,MD,dal,partner) VALUES ;
			(VAL(u_doklady.datum),u_doklady.datum_dokl,u_doklady.dal,u_doklady.hs_dal,0,ABS(u_doklady.castka),u_doklady.partner)
	ENDSCAN
	SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
		SELECT uexarch
		DELETE FOR datum=u_doklady.datum
		SELECT u_doklady
	ENDSCAN
	SELECT uexarch
	APPEND FROM DBF("u_doklady") FOR !storno .AND. !vymaz
	REPLACE c_data WITH m.cdata FOR c_data<>m.cdata
	DO pozavirej WITH "u_doklady, doklady, uexarch, uexarchobraty"
	IF USED(LEFT(m.menoexp,LEN(m.menoexp)-4))
		USE IN (LEFT(m.menoexp,LEN(m.menoexp)-4))
	ENDIF
	IF !m.issql
		IF f_acc_ex(m.gcdat_path+"uexarchobraty")
			PACK
			USE
		ENDIF
	ENDIF 
ENDIF 
IF m.gcuct_trzba AND USED("u_ex_platby") AND USED("u_ex_polozky")
	gen_exp_had.INCREMENT("Tržby")
	m.poraduz=dajsapcdcislo("TRZBY",m.rokuct, m.mesuct,"","")
	m.menoexp="TRZBY"+RIGHT(m.rokuct,1)+m.mesuct+STRTRAN(STR(m.poraduz,3,0)," ","0")+".DBF"
	m.menoexp2=STRTRAN(m.menoexp,"TRZBY","DAN")
	SELECT SUM(castka) AS ciastka, MD,dal,md2,dal2,hs_dal,hs_md,partner,pz, poznamka, $0 AS celkom, 1.000000000 AS koef FROM u_ex_platby GROUP BY pz,poznamka,MD,dal INTO CURSOR u_doklady READWRITE 
	SELECT SUM(castka) AS ciastka, pz FROM u_ex_platby GROUP BY pz INTO CURSOR u_platby  READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	SELECT u_doklady
	SET RELATION TO ALLTRIM(pz) INTO u_platby
	REPLACE ALL u_doklady.celkom WITH u_platby.ciastka
	SET RELATION OFF INTO u_platby
	USE IN u_platby
	REPLACE ALL koef WITH IIF(celkom=0,1,ciastka/celkom)
	SELECT SUM(castka) AS ciastka, MD,dal,hs_md, hs_dal,md2,dal2, pz, partner,poznamka,$0 AS danzakl, $0 AS dan FROM u_ex_polozky GROUP BY pz,poznamka,MD,dal INTO CURSOR u_dokl1 READWRITE 
	SELECT u_dokl1
	REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
	REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka FROM u_dokl1 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl2 READWRITE 
	USE IN u_dokl1
	REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
	SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2,poznamka FROM u_dokl2 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	USE IN u_dokl2
	SELECT u_doklady
	IF !prazdna()
		m.gcuexp_path = ALLTRIM(m.gcuexp_path)
		IF ! DIRECTORY(m.gcuexp_path)
			MKDIR (m.gcuexp_path)
		ENDIF
		CREATE TABLE (m.gcuexp_path+m.menoexp)	FREE (uzavierka c(18), datum d(8), ucet c(12), hs c(10), MD N(14,2), dal N(14,2))
		USE
		CREATE TABLE (m.gcuexp_path+m.menoexp2) FREE (uzavierka c(18), cena0 N(13,2), cena5 N(13,2), cena23 N(13,2),;
			dan5 N(12,2),dan23 N(12,2))
		USE
		SELECT SPACE(17) AS uzaverka,ciastka, MD,dal,md2,dal2,hs_dal,hs_md,poznamka, celkom, 0000000000.00 AS danzakl, 000000000.00 AS dan, ;
			SPACE(5) AS sadzba FROM u_doklady INTO CURSOR vondbf WHERE .f. READWRITE 
		SELECT u_doklady
		SCAN FOR !EMPTY(u_doklady.MD) .AND. !EMPTY(u_doklady.dal) .AND. u_doklady.ciastka<>0
			SELECT u_dokl
			SCAN FOR pz=u_doklady.pz .AND. !EMPTY(u_dokl.MD) .AND. !EMPTY(u_dokl.dal)
				IF u_doklady.MD=u_dokl.dal
					INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba) VALUES ;
						(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_dokl.MD,u_doklady.dal,u_dokl.md2,u_doklady.dal2,u_dokl.hs_md,u_doklady.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka)
				ELSE
					INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba) VALUES ;
						(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_doklady.MD,u_dokl.dal,u_doklady.md2,u_dokl.dal2,u_doklady.hs_md,u_dokl.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka)
				ENDIF
			ENDSCAN
			SELECT u_doklady
		ENDSCAN
		SELECT uzaverka,SUM(ciastka) AS ciastka,MD,dal,md2,dal2,hs_md,hs_dal, SUM(danzakl) AS danzakl, SUM(dan) AS dan, sadzba FROM vondbf ;
			GROUP BY uzaverka, MD, dal, sadzba INTO CURSOR vondbf2 READWRITE 
		SELECT uzaverka, SUM(ciastka) AS ciastka,MD,dal,md2,dal2,hs_md,hs_dal, 0000000000.00 AS cena0, 0000000000.00 AS cena5, 0000000000.00 AS cena23, 000000000.00 AS dan5, 000000000.00 AS dan23,.F. AS vymaz,.F. AS storno FROM vondbf ;
			GROUP BY uzaverka, MD, dal INTO CURSOR vondbf1 READWRITE 
		m.riadkov=1
		SCAN ALL
			SELECT vondbf2
			SCAN FOR MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. uzaverka=vondbf1.uzaverka
				DO CASE
					CASE ALLTRIM(sadzba)="0"
						REPLACE vondbf1.cena0 WITH vondbf2.danzakl
					CASE ALLTRIM(sadzba)=ALLTRIM(STR((m.uctdphlo-1)*100,10,0))
						REPLACE vondbf1.cena5 WITH vondbf2.danzakl, vondbf1.dan5 WITH vondbf2.dan
					OTHERWISE
						REPLACE vondbf1.cena23 WITH vondbf2.danzakl, vondbf1.dan23 WITH vondbf2.dan
				ENDCASE
			ENDSCAN
		ENDSCAN
		IF !m.issql
			IF FILE(m.gcdat_path+"uexarsk.dbf")
				SELECT 0
				USE (m.gcdat_path+"uexarsk.dbf")
			ELSE
				SELECT vondbf1
				COPY STRUCTURE TO (m.gcdat_path+"uexarsk.dbf")
				SELECT 0
				USE (m.gcdat_path+"uexarsk.dbf")
			ENDIF
		ENDIF 
		IF m.kontroluj
			SELECT DISTINCT uzaverka FROM vondbf1 INTO CURSOR datumy READWRITE 
			SCAN ALL
				m.hladajuzaverka=datumy.uzaverka
				m.oprava=0
				SELECT vondbf1
				SCAN FOR uzaverka=datumy.uzaverka
					IF m.issql
						IF USED("uexarsk")
							=REQUERY("uexarsk")
						ELSE
							USE (m.sqlprefix+"ruexarsk") ALIAS uexarsk IN 0
							=CURSORSETPROP("Buffering",5,"uexarsk")
						ENDIF 
					ENDIF 
					SELECT uexarsk
					LOCATE FOR uzaverka=vondbf1.uzaverka
					IF FOUND()
						LOCATE FOR uzaverka=vondbf1.uzaverka .AND. ciastka=vondbf1.ciastka .AND. MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. cena0=vondbf1.cena0 .AND. cena5=vondbf1.cena5 ;
							.AND. cena23=vondbf1.cena23 .AND. dan5=vondbf1.dan5 .AND. dan23=vondbf1.dan23 .AND. hs_md=vondbf1.hs_md .AND. hs_dal=vondbf1.hs_dal
						IF !FOUND()
							m.oprava=2
						ELSE
							m.oprava=1
						ENDIF
					ELSE
						m.oprava=0
					ENDIF
					SELECT vondbf1
					IF m.oprava=2
						EXIT
					ENDIF
				ENDSCAN
				DO CASE
					CASE m.oprava=2
						SELECT uexarsk
						SCAN FOR uzaverka=datumy.uzaverka
							INSERT INTO vondbf1 (uzaverka,ciastka,MD,dal,hs_md, hs_dal,md2,dal2,cena0,cena5,cena23,dan5,dan23,storno);
								VALUES (uexarsk.uzaverka,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,uexarsk.md2,uexarsk.dal2,-uexarsk.cena0,-uexarsk.cena5,;
								-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.T.)
						ENDSCAN
					CASE m.oprava=1
						SELECT vondbf1
						DELETE FOR uzaverka=datumy.uzaverka
				ENDCASE
				SELECT datumy
			ENDSCAN
			IF m.issql
				USE (m.sqlprefix+"ruexarsk_zoznam_uzavierok") ALIAS uexzoznam IN 0
				SELECT DISTINCT uzaverka FROM uexzoznam WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
					INTO CURSOR datumy2 READWRITE 
				USE IN uexzoznam
			ELSE 
				SELECT DISTINCT uzaverka FROM uexarsk WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
					INTO CURSOR datumy2 READWRITE 
			ENDIF 
			SCAN ALL
				m.hladajuzaverka=datumy2.uzaverka
				IF m.issql
					=REQUERY("uexarsk")
				ENDIF 
				SELECT uexarsk
				SCAN FOR uzaverka=datumy2.uzaverka
					INSERT INTO vondbf1 (uzaverka,ciastka,MD,dal,hs_md, hs_dal,cena0,cena5,cena23,dan5,dan23,storno,vymaz);
						VALUES (uexarsk.uzaverka,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,-uexarsk.cena0,-uexarsk.cena5,;
						-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.F.,.T.)
				ENDSCAN
				SELECT datumy2
			ENDSCAN
			USE IN datumy2
		ENDIF
		SELECT vondbf1
		m.vonuz="A"
		m.uzka=""
		SCAN ALL
			IF vondbf1.uzaverka==m.uzka
				m.vonuz=CHR(ASC(m.vonuz)+1)
			ELSE
				m.vonuz="A"
				m.uzka=vondbf1.uzaverka
			ENDIF
			INSERT INTO (m.gcuexp_path+m.menoexp) (uzavierka,datum,ucet,MD,dal) VALUES ;
				(vondbf1.uzaverka+m.vonuz,CTOD(SUBSTR(vondbf1.uzaverka,7,2)+"."+SUBSTR(vondbf1.uzaverka,5,2)+"."+LEFT(vondbf1.uzaverka,4)),vondbf1.MD,vondbf1.ciastka,0)
			INSERT INTO (m.gcuexp_path+m.menoexp) (uzavierka,datum,ucet,hs,MD,dal) VALUES ;
				(vondbf1.uzaverka+m.vonuz,CTOD(SUBSTR(vondbf1.uzaverka,7,2)+"."+SUBSTR(vondbf1.uzaverka,5,2)+"."+LEFT(vondbf1.uzaverka,4)),vondbf1.dal,vondbf1.hs_dal,vondbf1.cena0+vondbf1.cena5+vondbf1.cena23,0)
			INSERT INTO (m.gcuexp_path+m.menoexp) (uzavierka,datum,ucet,MD,dal) VALUES ;
				(vondbf1.uzaverka+m.vonuz,CTOD(SUBSTR(vondbf1.uzaverka,7,2)+"."+SUBSTR(vondbf1.uzaverka,5,2)+"."+LEFT(vondbf1.uzaverka,4)),vondbf1.dal2,vondbf1.dan5+vondbf1.dan23,0)
			INSERT INTO (m.gcuexp_path+m.menoexp2) (uzavierka,cena0,cena5,cena23,dan5,dan23) VALUES ;
				(vondbf1.uzaverka+m.vonuz,vondbf1.cena0,vondbf1.cena5,vondbf1.cena23,vondbf1.dan5,vondbf1.dan23)
		ENDSCAN
		SELECT vondbf1
		SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
			IF m.issql
				m.hladajuzaverka=vondbf1.uzaverka
				=REQUERY("uexarsk")
				SELECT uexarsk
				DELETE ALL 
				=tux(.t.,.t.,"uexarsk")
			ELSE 
				SELECT uexarsk
				DELETE FOR uzaverka=vondbf1.uzaverka
			ENDIF 
			SELECT vondbf1
		ENDSCAN
		IF m.issql
			m.hladajuzaverka="xxx"
			=REQUERY("uexarsk")
		ENDIF 
		SELECT uexarsk
		APPEND FROM DBF("vondbf1") FOR !storno .AND. !vymaz
		IF m.issql
			=tux(.t.,.t.,"uexarsk")
		ENDIF 
		DO pozavirej WITH "uexarsk"
		IF !m.issql
			IF f_acc_ex(m.gcdat_path+"uexarsk")
				PACK
				USE
			ENDIF
		ENDIF 
	ENDIF
	SET CENTURY &old_century
	SET DATE &oldsetdate
	SET DELETED &oldsetdele
	DO pozavirej WITH "vondbf, u_doklady, u_dokl, vondbf1, vondbf2, datumy, u_ex_platby, u_ex_polozky"
	IF USED(LEFT(m.menoexp,LEN(m.menoexp)-4))
		USE IN (LEFT(m.menoexp,LEN(m.menoexp)-4))
	ENDIF
	IF USED(LEFT(m.menoexp2,LEN(m.menoexp2)-4))
		USE IN (LEFT(m.menoexp2,LEN(m.menoexp2)-4))
	ENDIF
ENDIF
RELEASE gen_exp_had
RETURN

PROCEDURE sap_trz_00
* Export do SAPu (VDZ) - trzby - prvy riadok zapisu
m.uct00=ALLTRIM(u_doklady.datum)+';' &&Cislo dokladu
m.uct00=m.uct00+'00;' && Cislo polozky
m.uct00=m.uct00+PADL(ALLTRIM(STR(YEAR(u_doklady.datum_dokl),4,0)),4,"0")+PADL(ALLTRIM(STR(MONTH(u_doklady.datum_dokl),2,0)),2,"0")+PADL(ALLTRIM(STR(DAY(u_doklady.datum_dokl),2,2)),2,"0")+';' &&Datum dokladu
m.uct00=m.uct00+PADL(ALLTRIM(STR(YEAR(u_doklady.datum_dokl),4,0)),4,"0")+PADL(ALLTRIM(STR(MONTH(u_doklady.datum_dokl),2,0)),2,"0")+PADL(ALLTRIM(STR(DAY(u_doklady.datum_dokl),2,2)),2,"0")+';' &&Datum uctovania
m.uct00=m.uct00+ALLTRIM(u_doklady.doklad)+';' &&Referencia
m.uct00=m.uct00+m.dotextu+';' &&Text hlavicky dokladu
m.uct00=m.uct00+';'&&Druh dokladu
m.uct00=m.uct00+'VDZF;' &&Uctovny okruh
m.uct00=m.uct00+en__meny(m.uct_mena,3)+';' &&Mena
m.uct00=m.uct00+';' &&Uctovaci kluc 01,11,40,50
m.uct00=m.uct00+';' &&Ucet
m.uct00=m.uct00+';' &&Nazov
m.uct00=m.uct00+';' &&ICO odberatela
m.uct00=m.uct00+';' &&Ulica a cislo
m.uct00=m.uct00+';' &&Miesto
m.uct00=m.uct00+';' &&PSC
m.uct00=m.uct00+';' &&Krajina
m.uct00=m.uct00+';' &&Jazyk
m.uct00=m.uct00+';' &&ICO
m.uct00=m.uct00+';' &&DIC
m.uct00=m.uct00+';' &&Kontrolny ucet HK
m.uct00=m.uct00+';' &&Konstanta 009
m.uct00=m.uct00+';' &&Ciastka
m.uct00=m.uct00+';' &&Priradenie
m.uct00=m.uct00+';' &&Text
m.uct00=m.uct00+';' &&Fond
m.uct00=m.uct00+';' &&Financne stredisko
m.uct00=m.uct00+';' &&Financna polozka
= FPUTS(m.lihandle, m.uct00)

PROCEDURE sap_trz_02
* Export do SAPu (VDZ) - trzby - treti a dalsi riadok zapisu
SELECT u_dokl1
SUM ciastka TO kkkkkk FOR pz=m.pz
IF m.kkkkkk=u_doklady.ciastka .OR. m.kkkkkk=0
	m.koefxxx=1
ELSE
	m.koefxxx=u_doklady.ciastka/m.kkkkkk
ENDIF
PRIVATE riadok
m.riadok=1
SCAN FOR pz = m.pz
	m.riadok=m.riadok+1
	m.uct00=ALLTRIM(u_dokl1.datum)+';' &&Cislo dokladu
	m.uct00=m.uct00+PADL(ALLTRIM(STR(m.riadok,2,0)),2,"0")+';' &&Cislo polozky
	m.uct00=m.uct00+';' &&Datum dokladu
	m.uct00=m.uct00+';' &&Datum uctovania
	m.uct00=m.uct00+';' &&Referencia
	m.uct00=m.uct00+';' &&Text hlavicky dokladu
	m.uct00=m.uct00+';' &&Druh dokladu
	m.uct00=m.uct00+';' &&Uctovny okruh
	m.uct00=m.uct00+';' &&Mena
	m.uct00=m.uct00+'50;' && Uctovaci kluc
	m.uct00=m.uct00+ALLTRIM(u_dokl1.dal)+';' &&Ucet
	m.uct00=m.uct00+';' &&Nazov odberatela
	m.uct00=m.uct00+';' &&ICO odberatela
	m.uct00=m.uct00+';' &&Ulica a cislo
	m.uct00=m.uct00+';' &&Miesto
	m.uct00=m.uct00+';' &&PSC
	m.uct00=m.uct00+';' &&Krajina
	m.uct00=m.uct00+';' &&Jazyk
	m.uct00=m.uct00+';' &&ICO
	m.uct00=m.uct00+';' &&DIC
	m.uct00=m.uct00+';' &&Kontrolny ucet HK
	m.uct00=m.uct00+';' &&Konstatna
	m.uct00=m.uct00+ALLTRIM(STR(u_dokl1.ciastka*m.koefxxx,16,2))+';'
	m.uct00=m.uct00+';' &&Priradenie
	DO CASE
		CASE ALLTRIM(u_dokl1.dal)="602102"
			m.dotextu="Tržby - strava"
		CASE ALLTRIM(u_dokl1.dal)="602103"
			m.dotextu="Ubytovanie"
		CASE ALLTRIM(u_dokl1.dal)="602104"
			m.dotextu="Ostatné"
		CASE ALLTRIM(u_dokl1.dal)="602105"
			m.dotextu="Miestny poplatok"
	ENDCASE
	m.uct00=m.uct00+m.dotextu+';' &&Text
	m.uct00=m.uct00+m.uctfond+';' &&Fond
	IF ALLTRIM(u_dokl1.dal)="602105"
		m.uct00=m.uct00+'VDZFM;' &&Financne stredisko
	ELSE
		m.uct00=m.uct00+m.uctfinstred+';' &&Financne stredisko
	ENDIF
	m.uct00=m.uct00+m.uctfinpol+';' &&Financna polozka
	= FPUTS(m.lihandle, m.uct00)
ENDSCAN


PROCEDURE sap_trz_01_1
* Export do SAPu (VDZ) - trzby - druhy riadok zapisu - uvod
m.uct00=ALLTRIM(u_doklady.datum)+';' &&Cislo dokladu
m.uct00=m.uct00+'01;' &&Cislo polozky
m.uct00=m.uct00+';' &&Datum dokladu
m.uct00=m.uct00+';' &&Datum uctovania
m.uct00=m.uct00+';' &&Referencia
m.uct00=m.uct00+';' &&Text hlavicky dokladu
m.uct00=m.uct00+';' &&Druh dokladu
m.uct00=m.uct00+';' &&Uctovny okruh
m.uct00=m.uct00+';' &&Mena
m.uct00=m.uct00+'01;' && Uctovaci kluc
m.uct00=m.uct00+ALLTRIM(u_doklady.dal)+';' && Ucet

PROCEDURE sap_trz_01_2
* Export do SAPu (VDZ) - trzby - druhy riadok zapisu - stred - nie vsetky platby ho maju rovnaky
m.uct00=m.uct00+'Hoteloví hostia '+ STR(YEAR(m.plden),4,0)+STRTRAN(STR(MONTH(m.plden),2,0)," ","0")+STRTRAN(STR(DAY(m.plden),2,0)," ","0")+';' &&Nazov
m.uct00=m.uct00+';' &&ICO odberatela
m.uct00=m.uct00+';' &&Ulica a cislo
m.uct00=m.uct00+'VDZ Financie Tatranská Lomnica;' &&Miesto
m.uct00=m.uct00+'059 60;' &&PSC
m.uct00=m.uct00+'SK;' &&Krajina
m.uct00=m.uct00+'SK;' &&Jazyk
m.uct00=m.uct00+';' &&ICO
m.uct00=m.uct00+';' &&DIC

PROCEDURE sap_trz_01_3
* Export do SAPu (VDZ) - trzby - druhy riadok zapisu - koniec
m.uct00=m.uct00+ALLTRIM(u_doklady.md2)+';' &&Kontrolny ucet HK
m.uct00=m.uct00+'009;' &&Konstanta 009
m.uct00=m.uct00+ALLTRIM(STR(u_doklady.ciastka,16,2))+';' &&Ciastka
m.uct00=m.uct00+';' &&Priradenie
m.uct00=m.uct00+m.dotextu+';' &&Text
m.uct00=m.uct00+m.uctfond+';' &&Fond
m.uct00=m.uct00+m.uctfinstred+';' &&Financne stredisko
m.uct00=m.uct00+m.uctfinpol+';' &&Financna polozka
= FPUTS(m.lihandle, m.uct00)

PROCEDURE sap_skl_00
* Export do SAPu (VDZ) - sklady - prvy riadok zapisu
m.uct00=ALLTRIM(u_doklady.datum)+';' &&Cislo dokladu
m.uct00=m.uct00+'00;' &&Cislo polozky
m.uct00=m.uct00+PADL(ALLTRIM(STR(YEAR(u_doklady.datum_dokl),4,0)),4,"0")+PADL(ALLTRIM(STR(MONTH(u_doklady.datum_dokl),2,0)),2,"0")+PADL(ALLTRIM(STR(DAY(u_doklady.datum_dokl),2,2)),2,"0")+';' &&Datum dokladu
m.uct00=m.uct00+PADL(ALLTRIM(STR(YEAR(u_doklady.datum_dokl),4,0)),4,"0")+PADL(ALLTRIM(STR(MONTH(u_doklady.datum_dokl),2,0)),2,"0")+PADL(ALLTRIM(STR(DAY(u_doklady.datum_dokl),2,2)),2,"0")+';' &&Datum uctovania
m.uct00=m.uct00+ALLTRIM(u_doklady.doklad)+';' &&Referencia
m.uct00=m.uct00+m.dotextu+';' &&Text hlavicky dokladu
m.uct00=m.uct00+';' &&Druh dokladu
m.uct00=m.uct00+'VDZF;' &&Uctovny okruh
m.uct00=m.uct00+en__meny(m.uct_mena,3)+';' &&Mena
m.uct00=m.uct00+';' &&Uctovaci kluc 40,50
m.uct00=m.uct00+';' &&Ucet
m.uct00=m.uct00+';' &&Ciastka
m.uct00=m.uct00+';' &&Priradenie
m.uct00=m.uct00+';' &&Text
m.uct00=m.uct00+';' &&Fond
m.uct00=m.uct00+';' &&Financne stredisko
m.uct00=m.uct00+';' &&Financna polozka
= FPUTS(m.lihandle, m.uct00)

PROCEDURE sap_skl_01
PARAMETERS korekcia
* Export do SAPu (VDZ) - sklady - druhy riadok zapisu - uvod
m.uct00=ALLTRIM(u_doklady.datum)+';' &&Cislo dokladu
m.uct00=m.uct00+PADL(ALLTRIM(STR(1+m.korekcia*2,10,0)),2,"0")+';' &&Cislo polozky
m.uct00=m.uct00+';' &&Datum dokladu
m.uct00=m.uct00+';' &&Datum uctovania
m.uct00=m.uct00+';' &&Referencia
m.uct00=m.uct00+';' &&Text hlavicky dokladu
m.uct00=m.uct00+';' &&Druh dokladu
m.uct00=m.uct00+';' &&Uctovny okruh
m.uct00=m.uct00+';' &&Mena

PROCEDURE sap_skl_02
PARAMETERS korekcia
* Export do SAPu (VDZ) - sklady - treti riadok zapisu - uvod
m.uct00=ALLTRIM(u_doklady.datum)+';' &&Cislo dokladu
m.uct00=m.uct00+PADL(ALLTRIM(STR(2+m.korekcia*2,10,0)),2,"0")+';'
m.uct00=m.uct00+';' &&Datum dokladu
m.uct00=m.uct00+';' &&Datum uctovania
m.uct00=m.uct00+';' &&Referencia
m.uct00=m.uct00+';' &&Text hlavicky dokladu
m.uct00=m.uct00+';' &&Druh dokladu
m.uct00=m.uct00+';' &&Uctovny okruh
m.uct00=m.uct00+';' &&Mena

PROCEDURE sap_skl_koniec
* Export do SAPu (VDZ) - sklady - druhy a treti riadok zapisu - koniec
m.uct00=m.uct00+ALLTRIM(STR(ABS(u_doklady.ciastka),16,2))+';' &&Ciastka
m.uct00=m.uct00+';' &&Priradenie
m.uct00=m.uct00+m.dotextu+';' &&Text
m.uct00=m.uct00+m.uctfond+';' &&Fond
m.uct00=m.uct00+m.uctfinstred+';' &&Financne stredisko
m.uct00=m.uct00+m.uctfinpol+';' &&Financna polozka
= FPUTS(m.lihandle, m.uct00)



PROCEDURE gen_exp_ekoadam
PARAMETERS kontroluj,rokuct,mesuct
PRIVATE old_century,menoexp,oldsetdate,oldsetdele, riadkov, sumacelk,dokluzod,dokluzdo,prijemky, vydajky, ok
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.rokuct
m.hladajmesiac=m.mesuct
m.menoexp="dennik.dbf"
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
m.old_century=SET("century")
m.oldsetdate=SET("date")
m.oldsetdele=SET("dele")
SET DATE TO GERMAN
SET DELETED ON
m.gcuexp_path=ALLTRIM(IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path))
IF ! DIRECTORY(m.gcuexp_path)
	MKDIR (m.gcuexp_path)
ENDIF
SET CENTURY ON
gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
gen_exp_had.SHOW()
gen_exp_had.set_max(20)
gen_exp_had.INCREMENT("Sklady")
IF USED("u_ex_obraty")
	SELECT operace, datum, id_man, SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka,faktura,.F. AS storno,.F. AS vymaz FROM u_ex_obraty GROUP BY id_man,pz,datum,doklad,datum_dokl,MD,dal INTO CURSOR u_doklady WHERE INLIST(LEFT(pz,1),"P","V") READWRITE 
	DELETE FOR EMPTY(datum)
	DELETE FOR EMPTY(MD) .OR. EMPTY(dal)
	SELECT u_doklady
	SELECT 0
	IF m.issql
		USE (m.sqlprefix+"ruexarchobraty_mesiacrok") ALIAS uexarch IN 0
	ELSE 
		IF !FILE(m.gccen_path+"uexarchobraty.dbf")
			DO creafile WITH (m.gccen_path+"uexarchobraty.dbf")
		ENDIF 
		IF !USED("uexarchobraty")
			USE (m.gccen_path+"uexarchobraty") IN 0
		ENDIF 
		USE vuexarchobraty_mesiacrok IN 0 ALIAS uexarch
	ENDIF 
	=CURSORSETPROP("Buffering",5,"uexarch")
	IF m.kontroluj
		DO kontrola_skladov
	ELSE
		IF m.issql
			USE (m.sqlprefix+"ruzaverka") ALIAS expuzav
			INDEX on rok+mesiac TAG kedy
		ELSE 
			USE (m.gcdat_path+"uzaverka") AGAIN ALIAS expuzav ORDER kedy
		ENDIF 
		SET FILTER TO c_stredisk=m.gic_stredisk
		GO BOTTOM
		m.rokuct=expuzav.rok
		m.mesuct=expuzav.mesiac
		IF EMPTY(m.rokuct) .OR. EMPTY(m.mesuct)
			m.rokuct=STR(YEAR(DATE()),4,0)
			m.mesuct=STRTRAN(STR(MONTH(DATE()),2,0)," ","0")
		ELSE
			m.mesuct=STRTRAN(STR(VAL(m.mesuct)+1,2,0)," ","0")
			IF m.mesuct="13"
				m.mesuct="01"
				m.rokuct=STR(VAL(m.rokuct)+1,4,0)
			ENDIF
		ENDIF
		USE IN expuzav
	ENDIF
	SELECT u_doklady
	DELETE FOR castka=0
	IF m.issql
		USE (m.sqlprefix+"rdoklady") IN 0 ALIAS doklady
		SELECT doklady
		INDEX on c_dokl TAG c_dokl
	ELSE 
		IF !USED("doklady")
			USE (m.fn_doklady) ALIAS doklady AGAIN IN 0 ORDER c_dokl
		ELSE
			SELECT doklady
			SET ORDER TO c_dokl
		ENDIF
	ENDIF 

	SELECT u_doklady
	SET RELATION TO VAL(ALLTRIM(datum)) INTO doklady
	IF !FILE(m.gcuexp_path+m.menoexp+".dbf")
		SELECT 0
		CREATE TABLE (m.gcuexp_path+m.menoexp) FREE (zauctovane l ,hodnota N(15,2),md_ucet c(7),md_analyt c(32), dal_ucet c(7),dal_analyt c(32),;
			druh_dokl c(4), subsystem c(3), doklad c(6), dp c(4), datum d(8), mesiac N(2,0), rezerva c(1), d_odovzd d(8), uziv c(6))
		USE
	ENDIF
	SELECT u_doklady
	SCAN FOR LOWER(ALLTRIM(MD))<>"export"
		m.dp=""
		DO CASE
			CASE LEFT(u_doklady.pz,2)="PE" .AND. SUBSTR(u_doklady.dal,4,1)="1"
				m.dp="12" && Nakup za hotove
			CASE LEFT(u_doklady.pz,2)="PE" .AND. SUBSTR(u_doklady.dal,4,1)="0"
				m.dp="10" && Nakup na fakturu
			CASE LEFT(u_doklady.pz,2)="PI" .AND. u_doklady.castka>0
				m.dp="33" && Prebytky
			CASE LEFT(u_doklady.pz,2)="PI" .AND. u_doklady.castka<0
				m.dp="70" && Manka
			CASE LEFT(u_doklady.pz,2)="VE" .AND. LEFT(u_doklady.MD,3)="501"
				m.dp="60" && Ostatna spotreba
			CASE LEFT(u_doklady.pz,2)="VE"
				m.dp="51" && Predaj nakupenych materialovych zasob
			CASE INLIST(LEFT(u_doklady.pz,2),"VV","PV")
				m.dp="60" && Ostatna spotreba
		ENDCASE
		DO CASE
			CASE INLIST(ALLTRIM(u_doklady.MD),"1110000","1310000")
				m.md_analyt=PADL(ALLTRIM(u_doklady.hs_md),4)+PADL(ALLTRIM(u_doklady.faktura),10)+PADL(ALLTRIM(u_doklady.doklad),6)
			CASE INLIST(ALLTRIM(u_doklady.MD),"1111000","1311000")
				m.md_analyt=PADL(ALLTRIM(u_doklady.faktura),10)+PADL(ALLTRIM(u_doklady.doklad),6)
			CASE INLIST(LEFT(ALLTRIM(u_doklady.MD),3),"112","121","123","132")
				m.md_analyt=PADL(ALLTRIM(u_doklady.hs_md),8)
			CASE INLIST(LEFT(ALLTRIM(u_doklady.MD),1),"5","6")
				m.md_analyt=PADL(ALLTRIM(u_doklady.hs_md),8)+PADL(ALLTRIM(u_doklady.md2),3)
			OTHERWISE
				m.md_analyt=""
		ENDCASE
		DO CASE
			CASE INLIST(ALLTRIM(u_doklady.dal),"1110000","1310000")
				m.dal_analyt=PADL(ALLTRIM(u_doklady.hs_dal),4)+PADL(ALLTRIM(u_doklady.faktura),10)+PADL(ALLTRIM(u_doklady.doklad),6)
			CASE INLIST(ALLTRIM(u_doklady.MD),"1111000","1311000")
				m.dal_analyt=PADL(ALLTRIM(u_doklady.faktura),10)+PADL(ALLTRIM(u_doklady.doklad),6)
			CASE INLIST(LEFT(ALLTRIM(u_doklady.dal),3),"112","121","123","132")
				m.dal_analyt=PADL(ALLTRIM(u_doklady.hs_dal),8)
			CASE INLIST(LEFT(ALLTRIM(u_doklady.dal),1),"5","6")
				m.dal_analyt=PADL(ALLTRIM(u_doklady.hs_dal),8)+PADL(ALLTRIM(u_doklady.dal2),3)
			OTHERWISE
				m.dal_analyt="xx"
		ENDCASE
		INSERT INTO (m.gcuexp_path+m.menoexp) (zauctovane, hodnota, md_ucet, md_analyt, dal_ucet, dal_analyt, druh_dokl, subsystem, doklad, dp, datum, mesiac) VALUES ;
			(.F.,u_doklady.castka,u_doklady.MD, m.md_analyt, u_doklady.dal, m.dal_analyt, "", "SM2", ALLTRIM(u_doklady.datum),m.dp, u_doklady.datum_dokl, VAL(m.mesuct))
	ENDSCAN
	SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
		SELECT uexarch
		DELETE FOR datum=u_doklady.datum
		SELECT u_doklady
	ENDSCAN
	SELECT uexarch
	APPEND FROM DBF("u_doklady") FOR !storno .AND. !vymaz
	REPLACE c_data WITH m.cdata FOR c_data<>m.cdata
	REPLACE ALL mesiac WITH m.mesuct FOR mesiac<>m.mesuct
	REPLACE ALL rok WITH m.rokuct FOR rok<>m.rokuct
	=tux(.t.,.t.,"uexarch")
	DO pozavirej WITH "uexarch, uexarchobraty"
	IF !m.issql
		IF f_acc_ex(m.gcdat_path+"uexarchobraty")
			PACK
			USE
		ENDIF
	ENDIF 
	DO pozavirej WITH "u_doklady, doklady, uexarch, u_ex_obraty, uexarchobraty"
	IF USED(LEFT(m.menoexp,LEN(m.menoexp)-4))
		USE IN (LEFT(m.menoexp,LEN(m.menoexp)-4))
	ENDIF
ENDIF 
RELEASE gen_exp_had
RETURN



PROCEDURE gen_exp_orion_trzby
PARAMETERS kontroluj,rokuct,mesuct
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.rokuct
m.hladajmesiac=m.mesuct
m.old_century=SET("century")
m.oldsetdate=SET("date")
m.oldsetdele=SET("dele")
SET DATE TO GERMAN
SET DELETED ON
SET CENTURY ON 
*** Trzby ***
IF !m.issql
	IF !FILE(m.gccen_path+"sap_cd.dbf")
		SELECT 0
		CREATE TABLE (m.gccen_path+"sap_cd") FREE (meno c(8), pc i, rok c(4), mesiac c(2), den c(2))
		USE
	ENDIF 
ENDIF 
m.oddelovac="|"
DO CASE
	CASE "mladost"$LOWER(m.gchom_path)
		m.kthotel="M"
	CASE "lopusna"$LOWER(m.gchom_path)
		m.kthotel="L"
	CASE "spoldom"$LOWER(m.gchom_path)
		m.kthotel="S"
	CASE "lopu"$LOWER(m.hotel_name)
		m.kthotel="L"
	OTHERWISE
		m.kthotel="S"
ENDCASE
IF m.gcuct_trzba AND USED("u_ex_platby") AND USED("u_ex_polozky")
	gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
	gen_exp_had.SHOW()
	gen_exp_had.set_max(20)
	gen_exp_had.INCREMENT("Tržby")
	SELECT SUM(castka) AS ciastka, MD, dal, md2, dal2, hs_dal, hs_md, partner, pz, poznamka, $0 AS celkom, 1.000000000 AS koef, $0 as sumazaklad, datum_dokl FROM u_ex_platby GROUP BY pz, poznamka, MD, dal INTO CURSOR u_doklady READWRITE 
	SELECT SUM(castka) AS ciastka, pz FROM u_ex_platby GROUP BY pz INTO CURSOR u_platby  READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	SELECT u_doklady
	SET RELATION TO ALLTRIM(pz) INTO u_platby
	REPLACE ALL u_doklady.celkom WITH u_platby.ciastka
	SET RELATION OFF INTO u_platby
	USE IN u_platby
	REPLACE ALL koef WITH IIF(celkom=0,1,ciastka/celkom)
	SELECT SUM(castka) AS ciastka, MD,dal,hs_md, hs_dal,md2,dal2, pz, partner,poznamka,poznamka as txtdan, $0 AS danzakl, $0 AS dan, datum_dokl FROM u_ex_polozky GROUP BY pz,poznamka,MD,dal INTO CURSOR u_dokl1 READWRITE 
	SELECT u_dokl1
	REPLACE ALL txtdan WITH SUBSTR(txtdan,RAT(" ",ALLTRIM(txtdan)))
	REPLACE ALL dan WITH ciastka*VAL(txtdan)/(100+VAL(txtdan))
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka,txtdan, datum_dokl  FROM u_dokl1 GROUP BY pz, MD, dal, hs_md, hs_dal, txtdan, poznamka INTO CURSOR u_dokl2 READWRITE 
	USE IN u_dokl1
	REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
	SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2,poznamka,txtdan, datum_dokl  FROM u_dokl2 GROUP BY pz, MD, dal, hs_md, hs_dal, txtdan, poznamka INTO CURSOR u_dokl READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	USE IN u_dokl2
	SELECT u_doklady
	IF prazdna()
		SELECT SPACE(17) AS uzaverka,SPACE(17) as ucet,ciastka, MD,dal,md2,dal2,hs_dal,hs_md,poznamka, poznamka as pozn_pol,celkom, $0 AS danzakl, $0 AS dan, ;
			SPACE(5) AS sadzba, DATE() as datum_dokl, "  " as typ FROM u_doklady ;
			INTO CURSOR vondbf WHERE .f. READWRITE 
		SELECT uzaverka, ucet, SUM(ciastka) AS ciastka, MD, dal, md2, dal2, hs_md, hs_dal, 0000000000.00 AS cena0, 0000000000.00 AS cena5, 0000000000.00 AS cena23, 000000000.00 AS dan5, 000000000.00 AS dan23,.F. AS vymaz,.F. AS storno,poznamka, pozn_pol, datum_dokl, typ FROM vondbf ;
			GROUP BY uzaverka, ucet, MD, dal,poznamka, pozn_pol INTO CURSOR vondbf1 READWRITE 
	ELSE
		m.gcuexp_path = ALLTRIM(m.gcuexp_path)
		IF ! DIRECTORY(m.gcuexp_path)
			MKDIR (m.gcuexp_path)
		ENDIF
		SELECT SPACE(17) AS uzaverka,SPACE(17) as ucet,ciastka, MD,dal,md2,dal2,hs_dal,hs_md,poznamka, poznamka as pozn_pol,celkom, $0 AS danzakl, $0 AS dan, ;
			SPACE(5) AS sadzba, DATE() as datum_dokl, "  " as typ FROM u_doklady ;
			INTO CURSOR vondbf WHERE .f. READWRITE 
		SELECT u_doklady
		SCAN FOR !EMPTY(u_doklady.MD) .AND. !EMPTY(u_doklady.dal) .AND. u_doklady.ciastka<>0
			SELECT u_dokl
			SCAN FOR pz=u_doklady.pz .AND. !EMPTY(u_dokl.MD) .AND. !EMPTY(u_dokl.dal)
				m.poznamka=u_dokl.poznamka
				IF u_doklady.MD=u_dokl.dal
					IF u_doklady.hs_dal="ZAKLAD"
						m.pz=u_doklady.pz
						m.koef=u_doklady.koef
						SELECT SUM(danzakl) as danzakl ,txtdan FROM u_dokl GROUP BY txtdan WHERE pz=m.pz AND poznamka=m.poznamka INTO CURSOR u_doklx
						SCAN ALL 
							INSERT INTO vondbf (uzaverka,ucet,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba, poznamka, pozn_pol, datum_dokl, typ) VALUES ;
								(LEFT(u_dokl.pz,17),SUBSTR(u_dokl.pz,18),ROUND(u_doklx.danzakl*u_doklady.koef,2),u_dokl.MD,u_doklady.dal,u_dokl.md2,u_doklady.dal2,u_dokl.hs_md,u_dokl.hs_dal,ROUND(u_doklx.danzakl*u_doklady.koef,2),0,"0"+u_doklx.txtdan,u_doklady.poznamka,u_dokl.poznamka, u_dokl.datum_dokl,"Z")
						ENDSCAN 
						USE IN u_doklx
					ELSE
						INSERT INTO vondbf (uzaverka,ucet,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba, poznamka, pozn_pol, datum_dokl, typ) VALUES ;
							(LEFT(u_dokl.pz,17),SUBSTR(u_dokl.pz,18),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_dokl.MD,u_doklady.dal,u_dokl.md2,u_doklady.dal2,u_dokl.hs_md,u_dokl.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.txtdan,u_doklady.poznamka,u_dokl.poznamka, u_dokl.datum_dokl, IIF(u_doklady.hs_dal="ICO","I",""))
					ENDIF 
				ELSE
					IF u_doklady.dal=u_dokl.MD
						IF u_doklady.hs_dal="ZAKLAD"
							m.pz=u_doklady.pz
							m.koef=u_doklady.koef
							SELECT SUM(danzakl) as danzakl ,txtdan FROM u_dokl GROUP BY txtdan WHERE pz=m.pz AND poznamka=m.poznamka INTO CURSOR u_doklx
							SCAN ALL 
								INSERT INTO vondbf (uzaverka,ucet,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba,poznamka,pozn_pol, datum_dokl, typ) VALUES ;
									(LEFT(u_dokl.pz,17),SUBSTR(u_dokl.pz,18),ROUND(u_doklx.danzakl*u_doklady.koef,2),u_doklady.MD,u_dokl.dal,u_doklady.md2,u_dokl.dal2,u_dokl.hs_md,u_dokl.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),0,"0"+u_doklx.txtdan,u_doklady.poznamka,u_dokl.poznamka, u_dokl.datum_dokl,"Z")
							ENDSCAN 
							USE IN u_doklx
						ELSE
							INSERT INTO vondbf (uzaverka,ucet,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba,poznamka,pozn_pol, datum_dokl, typ) VALUES ;
								(LEFT(u_dokl.pz,17),SUBSTR(u_dokl.pz,18),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_doklady.MD,u_dokl.dal,u_doklady.md2,u_dokl.dal2,u_dokl.hs_md,u_dokl.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.txtdan,u_doklady.poznamka,u_dokl.poznamka, u_dokl.datum_dokl, IIF(u_doklady.hs_dal="ICO","I",""))
						ENDIF 
					ENDIF
				ENDIF
			ENDSCAN
			SELECT u_doklady
		ENDSCAN
		SELECT vondbf
		REPLACE ucet WITH "" FOR !("POZNAMKA"$pozn_pol) AND !("UHRADA"$pozn_pol)
		SELECT uzaverka, ucet, SUM(ciastka) AS ciastka, MD, dal, md2, dal2, hs_md, hs_dal, SUM(danzakl) AS danzakl, SUM(dan) AS dan, sadzba,poznamka, pozn_pol, datum_dokl, typ FROM vondbf ;
			GROUP BY uzaverka, ucet, MD, dal, sadzba,poznamka, pozn_pol INTO CURSOR vondbf2 READWRITE 
		SELECT uzaverka, ucet, SUM(ciastka) AS ciastka, MD, dal, md2, dal2, hs_md, hs_dal, 0000000000.00 AS cena0, 0000000000.00 AS cena5, 0000000000.00 AS cena23, 000000000.00 AS dan5, 000000000.00 AS dan23,.F. AS vymaz,.F. AS storno,poznamka, pozn_pol, datum_dokl, typ FROM vondbf ;
			GROUP BY uzaverka, ucet, MD, dal,poznamka, pozn_pol INTO CURSOR vondbf1 READWRITE 
		m.riadkov=1
		SCAN ALL
			SELECT vondbf2
			SCAN FOR MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. uzaverka=vondbf1.uzaverka .and. poznamka=vondbf1.poznamka .and. pozn_pol=vondbf1.pozn_pol .and. ucet=vondbf1.ucet
				DO CASE
					CASE LEFT(ALLTRIM(sadzba),1)="0"
						REPLACE vondbf1.cena0 WITH vondbf2.danzakl
					CASE ALLTRIM(sadzba)=ALLTRIM(STR((m.uctdphlo-1)*100,10,0))
						REPLACE vondbf1.cena5 WITH vondbf2.danzakl, vondbf1.dan5 WITH vondbf2.dan
					OTHERWISE
						REPLACE vondbf1.cena23 WITH vondbf2.danzakl, vondbf1.dan23 WITH vondbf2.dan
				ENDCASE
			ENDSCAN
		ENDSCAN
		IF !m.issql
			IF FILE(m.gcdat_path+"uexarsk.dbf")
				SELECT 0
				USE (m.gcdat_path+"uexarsk.dbf")
			ELSE
				SELECT vondbf1
				COPY STRUCTURE TO (m.gcdat_path+"uexarsk.dbf")
				SELECT 0
				USE (m.gcdat_path+"uexarsk.dbf")
			ENDIF
		ENDIF 
		IF m.kontroluj
			SELECT DISTINCT uzaverka FROM vondbf1 INTO CURSOR datumy READWRITE 
			SCAN ALL
				m.hladajuzaverka=datumy.uzaverka
				m.oprava=0
				SELECT vondbf1
				SCAN FOR uzaverka=datumy.uzaverka
					IF m.issql
						IF USED("uexarsk")
							=REQUERY("uexarsk")
						ELSE
							USE (m.sqlprefix+"ruexarsk_uzaverka") ALIAS uexarsk IN 0
							=CURSORSETPROP("Buffering",5,"uexarsk")
						ENDIF 
					ENDIF 
					SELECT uexarsk
					LOCATE FOR uzaverka=vondbf1.uzaverka
					IF FOUND()
						LOCATE FOR ALLTRIM(uzaverka)=ALLTRIM(vondbf1.uzaverka) .AND. ALLTRIM(ucet)=ALLTRIM(vondbf1.ucet) .AND. ciastka=vondbf1.ciastka .AND. ALLTRIM(MD)=ALLTRIM(vondbf1.MD) .AND. ALLTRIM(dal)=ALLTRIM(vondbf1.dal) .AND. cena0=vondbf1.cena0 .AND. cena5=vondbf1.cena5 ;
							.AND. cena23=vondbf1.cena23 .AND. dan5=vondbf1.dan5 .AND. dan23=vondbf1.dan23 .AND. ALLTRIM(hs_md)=ALLTRIM(vondbf1.hs_md) .AND. ALLTRIM(hs_dal)=ALLTRIM(vondbf1.hs_dal) .and. ALLTRIM(poznamka)=ALLTRIM(vondbf1.poznamka) .and. ALLTRIM(pozn_pol)=ALLTRIM(vondbf1.pozn_pol) .and. typ=vondbf1.typ
						IF !FOUND()
							m.oprava=2
						ELSE
							m.oprava=1
						ENDIF
					ELSE
						m.oprava=0
					ENDIF
					SELECT vondbf1
					IF m.oprava=2
						EXIT
					ENDIF
				ENDSCAN
				DO CASE
					CASE m.oprava=2
						SELECT uexarsk
						SCAN FOR uzaverka=datumy.uzaverka
							INSERT INTO vondbf1 (uzaverka,ucet,ciastka,MD,dal,hs_md, hs_dal,md2,dal2,cena0,cena5,cena23,dan5,dan23,storno, poznamka, pozn_pol, datum_dokl, typ);
								VALUES (uexarsk.uzaverka,uexarsk.ucet,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,uexarsk.md2,uexarsk.dal2,-uexarsk.cena0,-uexarsk.cena5,;
								-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.T., uexarsk.poznamka, uexarsk.pozn_pol, uexarsk.datum_dokl, uexarsk.typ)
						ENDSCAN
					CASE m.oprava=1
						SELECT vondbf1
						DELETE FOR uzaverka=datumy.uzaverka
				ENDCASE
				SELECT datumy
			ENDSCAN
			IF m.issql
				USE (m.sqlprefix+"ruexarsk_zoznam_uzavierok") ALIAS uexzoznam IN 0
				SELECT DISTINCT uzaverka FROM uexzoznam WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
					INTO CURSOR datumy2 READWRITE 
				USE IN uexzoznam
			ELSE 
				SELECT DISTINCT uzaverka FROM uexarsk WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
					INTO CURSOR datumy2 READWRITE 
			ENDIF 
			SCAN ALL
				m.hladajuzaverka=datumy2.uzaverka
				IF m.issql
					=REQUERY("uexarsk")
				ENDIF 
				SELECT uexarsk
				SCAN FOR uzaverka=datumy2.uzaverka
					INSERT INTO vondbf1 (uzaverka,ucet,ciastka,MD,dal,hs_md, hs_dal,cena0,cena5,cena23,dan5,dan23,storno,vymaz, poznamka, pozn_pol, datum_dokl, typ);
						VALUES (uexarsk.uzaverka,uexarsk.ucet,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,-uexarsk.cena0,-uexarsk.cena5,;
						-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.F.,.T., uexarsk.poznamka, uexarsk.pozn_pol, uexarsk.datum_dokl, uexarsk.typ)
				ENDSCAN
				SELECT datumy2
			ENDSCAN
			USE IN datumy2
		ENDIF
		m.poraduz=dajsapcdcislo("Kasy", m.rokuct, m.mesuct,"","")
		m.menoexp="Kasy_"+m.kthotel+"_"+m.rokuct+STRTRAN(m.mesuct," ","0")+STRTRAN(STR(m.poraduz,2,0)," ","0")+".txt"
		SELECT vondbf1
		COUNT TO m.assasas FOR !DELETED()
		IF m.assasas>0
			m.lihandle= FCREATE(m.gcuexp_path + m.menoexp)
			IF m.lihandle > 0
				SELECT vondbf1
				SELECT DISTINCT SUBSTR(pozn_pol,5,2) as id_kas FROM vondbf1 INTO CURSOR uct_kasy READWRITE 
				IF RECCOUNT()>0
					SELECT SUM(ciastka) as ciastka, $0 as c0,  $0 as c5, $0 as c23, $0 as d5, $0 as d23, $0 as cb FROM vondbf1 INTO CURSOR uct_polozky READWRITE 
					SELECT vondbf1
					SUM cena0 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))="0" .and. !("City tax"$pozn_pol)
					SELECT uct_polozky
					REPLACE c0 WITH m.uct0
					SELECT vondbf1
					SUM cena0 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))="0" .and. ("City tax"$pozn_pol)
					SELECT uct_polozky
					REPLACE cb WITH m.uct0
					SELECT vondbf1
					SUM cena5 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))=ALLTRIM(STR(m.uctdphlo*100-100,2,0))
					SELECT uct_polozky
					REPLACE c5 WITH m.uct0
					SELECT vondbf1
					SUM cena23 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))=ALLTRIM(STR(m.uctdphhi*100-100,2,0))
					SELECT uct_polozky
					REPLACE c23 WITH m.uct0
					SELECT vondbf1
					SUM dan5 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))=ALLTRIM(STR(m.uctdphlo*100-100,2,0))
					SELECT uct_polozky
					REPLACE d5 WITH m.uct0
					SELECT vondbf1
					SUM dan23 TO uct0 FOR SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol)))=ALLTRIM(STR(m.uctdphhi*100-100,2,0))
					SELECT uct_polozky
					REPLACE d23 WITH m.uct0
					USE IN uct_polozky
					SELECT uct_kasy
					SCAN ALL
						SCATTER MEMVAR fields id_kas
						SELECT uzaverka,ucet,SUM(ciastka) as ciastka, md, dal,poznamka,SUM(dan5+dan23) as dan, md2, dal2,SUM(ciastka-dan5-dan23) as dz, hs_dal, hs_md, SUBSTR(pozn_pol,AT(" ",pozn_pol,2)+1,2) as id_man, PADL(SUBSTR(ALLTRIM(pozn_pol),1+RAT(" ",ALLTRIM(pozn_pol))),2) as sadzba, typ, datum_dokl, pozn_pol FROM vondbf1 GROUP BY uzaverka,ucet,poznamka, md, dal, md2, dal2 WHERE SUBSTR(pozn_pol,5,2)=m.id_kas INTO CURSOR uct_polozky READWRITE 
						REPLACE ucet WITH ALLTRIM(ucet) FOR !EMPTY(ucet)
						REPLACE ucet WITH ALLTRIM(SUBSTR(ucet,2)) FOR LEFT(ucet,2)="0 "
						SCAN ALL 
							m.uct00=""
							m.uct00=m.kthotel+m.oddelovac					&&prevadzka "M" - Mladost, "L" - Lopusna, "S" - Spolcentrum
							m.uct00=m.uct00+ALLTRIM(uct_polozky.hs_md)+m.oddelovac					&&prevadzka "M" - Mladost, "L" - Lopusna, "S" - Spolcentrum
							m.uct00=m.uct00+uct_polozky.poznamka+m.oddelovac	&& sklad (71)
							m.uct00=m.uct00+LEFT(DTOS(uct_polozky.datum_dokl),4)+'-'+SUBSTR(DTOS(uct_polozky.datum_dokl),5,2)+'-'+RIGHT(DTOS(uct_polozky.datum_dokl),2)+m.oddelovac && obdobie ("2005-12")
							m.uct00=m.uct00+uct_polozky.uzaverka+m.oddelovac && obdobie ("2005-12")
							m.uct00=m.uct00+uct_polozky.id_man+m.oddelovac && obdobie ("2005-12")
							m.uct00=m.uct00+uct_polozky.sadzba+m.oddelovac && obdobie ("2005-12")
							m.uct00=m.uct00+ALLTRIM(uct_polozky.hs_dal)+m.oddelovac && stredisko MD (804)
							m.uct00=m.uct00+ALLTRIM(uct_polozky.MD)+m.oddelovac && konto MD (501100)
							m.uct00=m.uct00+ALLTRIM(uct_polozky.dal)+m.oddelovac && konto DAL (112410)
							m.uct00=m.uct00+ALLTRIM(uct_polozky.MD2)+m.oddelovac && konto MD (501100)
							m.uct00=m.uct00+ALLTRIM(uct_polozky.dal2)+m.oddelovac && konto DAL (112410)
							m.uct00=m.uct00+ALLTRIM(STRTRAN(STR(uct_polozky.ciastka,16,2),",","."))+m.oddelovac && cena (34.66)
							m.uct00=m.uct00+ALLTRIM(STRTRAN(STR(uct_polozky.dan,16,2),",","."))+m.oddelovac && cena (34.66)
							m.uct00=m.uct00+ALLTRIM(STRTRAN(STR(uct_polozky.dz,16,2),",","."))+m.oddelovac && cena (34.66)
							DO CASE 
								CASE "POZNAMKA"$uct_polozky.pozn_pol
									m.uct00=m.uct00+"88888888"+m.oddelovac+SUBSTR(DTOS(uct_polozky.datum_dokl),5,2)+LEFT(DTOS(uct_polozky.datum_dokl),4)+m.oddelovac
								CASE "UHRADA"$uct_polozky.pozn_pol
									IF !USED("hpde")
										USE (m.hor_path+"hpde") SHARED IN 0 
									ENDIF 
									IF !USED("hfak")
										USE (m.hor_path+"hfak") SHARED IN 0 
									ENDIF 
									m.hpdepozn="88888888"
									IF USED("hpde") AND USED("hfak")
										SELECT hfak
										LOCATE FOR datum=uct_polozky.datum_dokl AND sequc=VAL(uct_polozky.ucet)
										IF FOUND()
											m.jmeno=VAL(STRTRAN(hfak.jmeno,"Doplnkový predaj ",""))
											SELECT hpde
											LOCATE FOR datum=uct_polozky.datum_dokl AND rkod=uct_polozky.id_man AND doklad=jmeno
											IF FOUND()
												m.hpdepozn=ALLTRIM(hpde.poznamka)
											ENDIF 
										ENDIF 
									ENDIF 
									m.uct00=m.uct00+ALLTRIM(m.hotel_ico)+m.oddelovac+m.hpdepozn+m.oddelovac
								CASE uct_polozky.typ="I"
									m.uct00=m.uct00+ALLTRIM(m.hotel_ico)+m.oddelovac+SUBSTR(DTOS(uct_polozky.datum_dokl),5,2)+LEFT(DTOS(uct_polozky.datum_dokl),4)+m.oddelovac
								OTHERWISE 
									m.uct00=m.uct00+m.oddelovac+m.oddelovac
							ENDCASE 
							= FPUTS(m.lihandle, m.uct00)
*!*								IF uct_polozky.typ="Z"
*!*									m.uct00=""
*!*									m.uct00=m.kthotel+m.oddelovac					&&prevadzka "M" - Mladost, "L" - Lopusna, "S" - Spolcentrum
*!*									m.uct00=m.uct00+ALLTRIM(uct_polozky.hs_md)+m.oddelovac					&&prevadzka "M" - Mladost, "L" - Lopusna, "S" - Spolcentrum
*!*									m.uct00=m.uct00+uct_polozky.poznamka+m.oddelovac	&& sklad (71)
*!*									m.uct00=m.uct00+LEFT(DTOS(uct_polozky.datum_dokl),4)+'-'+SUBSTR(DTOS(uct_polozky.datum_dokl),5,2)+'-'+RIGHT(DTOS(uct_polozky.datum_dokl),2)+m.oddelovac && obdobie ("2005-12")
*!*									m.uct00=m.uct00+uct_polozky.uzaverka+m.oddelovac && obdobie ("2005-12")
*!*									m.uct00=m.uct00+uct_polozky.id_man+m.oddelovac && obdobie ("2005-12")
*!*									m.uct00=m.uct00+uct_polozky.sadzba+m.oddelovac && obdobie ("2005-12")
*!*									m.uct00=m.uct00+ALLTRIM(uct_polozky.hs_dal)+m.oddelovac && stredisko MD (804)
*!*									m.uct00=m.uct00+ALLTRIM(uct_polozky.MD)+m.oddelovac && konto MD (501100)
*!*									m.uct00=m.uct00+ALLTRIM(uct_polozky.dal)+m.oddelovac && konto DAL (112410)
*!*									m.uct00=m.uct00+ALLTRIM(uct_polozky.MD2)+m.oddelovac && konto MD (501100)
*!*									m.uct00=m.uct00+ALLTRIM(uct_polozky.dal2)+m.oddelovac && konto DAL (112410)
*!*									m.uct00=m.uct00+ALLTRIM(STRTRAN(STR(-uct_polozky.ciastka,16,2),",","."))+m.oddelovac && cena (34.66)
*!*									m.uct00=m.uct00+ALLTRIM(STRTRAN(STR(-uct_polozky.dan,16,2),",","."))+m.oddelovac && cena (34.66)
*!*									m.uct00=m.uct00+ALLTRIM(STRTRAN(STR(-uct_polozky.dz,16,2),",","."))+m.oddelovac && cena (34.66)
*!*									= FPUTS(m.lihandle, m.uct00)
*!*								ENDIF 
						ENDSCAN 
						USE IN uct_polozky
						SELECT uct_kasy
					ENDSCAN
					DO pozavirej WITH "uct_kasy, hpde"
					=FCLOSE(m.lihandle)
				ENDIF 
				IF FILE(m.gcuexp_path + m.menoexp)
					DO CASE 
						CASE LOWER(m.gcuct_spec)="energochem"
							=posli_sap_energochem(m.gcuexp_path + m.menoexp,"trzby")
						CASE VARTYPE(m.uct_email_trzby)=="C" AND !EMPTY(m.uct_email_trzby)
							LOCAL menosubjektu
							DO CASE 
								CASE m.kthotel="L"
									m.menosubjektu = "Tržby Lopušná:"+DTOC(DATE())
								CASE m.kthotel="M"
									m.menosubjektu = "Tržby Mladosť:"+DTOC(DATE())
								OTHERWISE 
									m.menosubjektu = "Tržby Spolcentrum:"+DTOC(DATE())
							ENDCASE 
							DO odosli_export_mailom WITH (m.gcuexp_path+m.menoexp), m.menosubjektu, m.uct_email_trzby
							LOCAL menosubjektu
					ENDCASE 
				ENDIF 


				SELECT vondbf1
*				SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
*					IF m.issql
*						m.hladajuzaverka=vondbf1.uzaverka
*						=REQUERY("uexarsk")
*						SELECT uexarsk
*						DELETE ALL 
*						=tux(.t.,.t.,"uexarsk")
*					ELSE 
*						SELECT uexarsk
*						DELETE FOR uzaverka=vondbf1.uzaverka
*					ENDIF 
*					SELECT vondbf1
*				ENDSCAN
*				IF m.issql
*					m.hladajuzaverka="xxx"
*					=REQUERY("uexarsk")
*				ENDIF 
*				SELECT uexarsk
*				APPEND FROM DBF("vondbf1") FOR !storno .AND. !vymaz
*				IF m.issql
*					=tux(.t.,.t.,"uexarsk")
*				ENDIF 
			ENDIF 
		ENDIF 
		DO pozavirej WITH "uexarsk"
		IF !m.issql
			SELECT 0
			IF f_acc_ex(m.gcdat_path+"uexarsk")
				PACK
				USE
			ENDIF
		ENDIF 
	ENDIF
	IF USED("vondbf1")
		IF m.issql
			USE (m.sqlprefix+"rsksezuctoneprenesene") IN 0 ALIAS sk_sez
			=CURSORSETPROP("Buffering",5,"sk_sez")
		ELSE 
			IF !USED("sk_sez")
				USE (m.gccen_path+"sk_sez.dbf") IN 0
			ENDIF 
		ENDIF 
		UPDATE sk_sez SET uctexport=.t. WHERE uzaverka IN (SELECT DISTINCT uzaverka FROM vondbf1)
		IF m.issql
			=tux(.t.,.t.,"sk_sez")
		ENDIF 
	ENDIF 
	SET CENTURY &old_century
	SET DATE &oldsetdate
	SET DELETED &oldsetdele
	DO pozavirej WITH "vondbf, vondbf1, vondbf2, datumy, u_doklady, u_dokl, u_ex_polozky, u_ex_platby, sk_sez"
ENDIF 
SET DELETED &oldsetdele
RELEASE gen_exp_had


PROCEDURE kros_skl_00
PRIVATE m.pis_datum, m.kk
m.pis_datum=DTOC(GOMONTH(CTOD("01."+m.mesuct+"."+m.rokuct),1)-1)
* Export do KROSu - sklady
m.uct00="R00"+CHR(9) &&prvy riadok zapisu
m.uct00=m.uct00+"T00" &&EUD
= FPUTS(m.lihandle, m.uct00)
m.uct00="R01"+CHR(9) &&druhy riadok
m.uct00=m.uct00+"180"+CHR(9) &&typ dokladu
m.uct00=m.uct00+m.gcuct_evidencia1+CHR(9) &&kod evidencie
m.uct00=m.uct00+m.gcuct_cisrad1+CHR(9) &&kod cisleneho radu
*m.uct00=m.uct00+m.gcuct_cisrad1+m.mesuct+"/"+m.rokuct+"/S"+ALLTRIM(STR(m.poraduz,5,0))+CHR(9) &&cislo interne
m.uct00=m.uct00+""+CHR(9) &&cislo interne
m.uct00=m.uct00+m.gcuct_cisrad1+m.mesuct+"/"+m.rokuct+"/S"+ALLTRIM(STR(m.poraduz,5,0))+CHR(9) &&cislo externe
m.uct00=m.uct00+CHR(9) &&meno firmy
m.uct00=m.uct00+CHR(9) &&ICO
m.uct00=m.uct00+CHR(9) &&DIC
m.uct00=m.uct00+m.pis_datum+CHR(9) &&datum vystavenia
m.uct00=m.uct00+CHR(9) &&datum prijatia
m.uct00=m.uct00+m.pis_datum+CHR(9) &&datum splatnosti
m.uct00=m.uct00+m.pis_datum+CHR(9) &&datum uskutocnenia zdanitelneho plnenia
m.uct00=m.uct00+m.pis_datum+CHR(9) &&datum uskutocnenia uctovneho pripadu
m.uct00=m.uct00+"EUR"+CHR(9) &&mena
m.uct00=m.uct00+"1"+CHR(9) &&mnozstvo jednotky
m.uct00=m.uct00+"1"+CHR(9) &&kurz NBS
m.uct00=m.uct00+"0"+CHR(9) &&kurz banka
SELECT u_doklady
SUM ABS(castka) TO kk FOR LOWER(ALLTRIM(MD))<>"export"
m.uct00=m.uct00+ALLTRIM(STR(m.kk,15,2))+CHR(9) &&suma spolu CM
m.uct00=m.uct00+ALLTRIM(STR(m.kk,15,2))+CHR(9) &&suma spolu TM
m.uct00=m.uct00+ALLTRIM(STR(m.uctdphlo*100-100,5,0))+CHR(9) &&sadzba nizsia
m.uct00=m.uct00+ALLTRIM(STR(m.uctdphhi*100-100,5,0))+CHR(9) &&sadzba vyssia
m.uct00=m.uct00+"0"+CHR(9) &&zaklad 0
m.uct00=m.uct00+"0"+CHR(9) &&zaklad nizsia
m.uct00=m.uct00+"0"+CHR(9) &&zaklad vyssia
m.uct00=m.uct00+ALLTRIM(STR(m.kk,15,2))+CHR(9) &&zaklad neobsahuje
m.uct00=m.uct00+"0"+CHR(9) &&suma DPH nizsia
m.uct00=m.uct00+"0"+CHR(9) &&suma DPH vyssia
m.uct00=m.uct00+"0"+CHR(9) &&halierove vyrovnanie
m.uct00=m.uct00+"FoodMan"+CHR(9)  && zaevidoval
m.uct00=STRTRAN(m.uct00,",",".")
= FPUTS(m.lihandle, m.uct00)


PROCEDURE kros_skl_02
PRIVATE m.pis_datum, m.kk
* Export do KROSu - sklady
m.uct00="R02"+CHR(9) &&udaje
m.uct00=m.uct00+"0"+CHR(9) &&typ polozky :0=uctovny zapis
m.uct00=m.uct00+LEFT(ALLTRIM(MD),3)+CHR(9) &&MD syntetika
m.uct00=m.uct00+SUBSTR(ALLTRIM(MD),4,3)+CHR(9) &&MD analytika
m.uct00=m.uct00+LEFT(ALLTRIM(dal),3)+CHR(9) &&DAL syntetika
m.uct00=m.uct00+SUBSTR(ALLTRIM(dal),4,3)+CHR(9) &&DAL analytika
m.uct00=m.uct00+ALLTRIM(STR(ABS(u_doklady1.castka),16,2))+CHR(9) &&suma TM
m.uct00=m.uct00+ALLTRIM(STR(ABS(u_doklady1.castka),16,2))+CHR(9) &&suma CM
*m.uct00=m.uct00+ALLTRIM(SUBSTR(u_doklady1.poznamka,5,2))+" "+ALLTRIM(substr(u_doklady1.poznamka,8,2))+" "+ALLTRIM(SUBSTR(u_doklady1.poznamka,11))+" "+ALLTRIM(u_doklady1.druh)+CHR(9) &&text polozky
m.uct00=m.uct00+ALLTRIM(STRTRAN(u_doklady1.pz,"|",""))+CHR(9) &&text polozky
*m.uct00=m.uct00+ALLTRIM(u_doklady1.poznamka)+CHR(9) &&text polozky
m.uct00=m.uct00+ALLTRIM(u_doklady1.md2)+CHR(9) &&kod typu sumy
m.uct00=m.uct00+""+CHR(9) &&cislo uhradzaneho dokladu
m.uct00=m.uct00+""+CHR(9) &&cislo odpocitavaneho dokladu
m.uct00=m.uct00+ALLTRIM(u_doklady1.hs_md)+CHR(9) &&kod strediska
m.uct00=m.uct00+""+CHR(9) &&nazov strediska
m.uct00=m.uct00+ALLTRIM(u_doklady1.hs_dal)+CHR(9) &&kod zakazky
m.uct00=m.uct00+""+CHR(9) &&nazov zakazky
m.uct00=m.uct00+""+CHR(9) &&kod cinnosti
m.uct00=m.uct00+""+CHR(9) &&nazov cinnosti
m.uct00=m.uct00+""+CHR(9) &&kod pracovnika
m.uct00=m.uct00+""+CHR(9) &&priezvisko pracovnika
m.uct00=m.uct00+""+CHR(9) &&meno pracovnika
m.uct00=m.uct00+""+CHR(9) &&cislo stredisko
m.uct00=m.uct00+""+CHR(9) &&cislo zakazka
m.uct00=m.uct00+""+CHR(9) &&cislo cinnost
m.uct00=m.uct00+""+CHR(9) &&cislo pracovnik
m.uct00=m.uct00+ALLTRIM(u_doklady1.dal2)+CHR(9) &&oddiel kv dph
m.uct00=STRTRAN(m.uct00,",",".")
= FPUTS(m.lihandle, m.uct00)



PROCEDURE kros_trz_00
m.uct00="R00"+CHR(9) &&prvy riadok zapisu
m.uct00=m.uct00+"T00" &&EUD
= FPUTS(m.lihandle, m.uct00)

PROCEDURE kros_trz_01
PARAMETERS uza, tdkl
PRIVATE m.pis_datum, m.kk, m.poraduz

IF EMPTY(m.uza)
	m.pis_datum=DTOC(GOMONTH(CTOD("01."+m.mesuct+"."+m.rokuct),1)-1)
ELSE
	PRIVATE m.mesuct, m.rokuct
	m.mesuct=SUBSTR(m.uza,5,2)
	m.rokuct=LEFT(m.uza,4)
	m.pis_datum=SUBSTR(m.uza,7,2)+"."+m.mesuct+"."+m.rokuct
ENDIF 
*m.pis_datum=SUBSTR(m.uzaverka,7,2)+"."+SUBSTR(m.uzaverka,5,2)+"."+SUBSTR(m.uzaverka,1,4)
* Export do KROSu - trzby
m.uct00="R01"+CHR(9) &&druhy riadok
IF UPPER(m.tdkl)="PD"
	m.poraduz=dajsapcdcislo("Kasy",m.rokuct, m.mesuct,"",m.gcuct_evidencia4)
	m.uct00=m.uct00+"160"+CHR(9) &&typ dokladu - pokladnicny doklad
	m.uct00=m.uct00+m.gcuct_evidencia4+CHR(9) &&kod evidencie
	m.uct00=m.uct00+m.gcuct_cisrad4+CHR(9) &&kod cisleneho radu
	m.uct00=m.uct00+""+CHR(9) &&cislo interne - skusim nechat praydne, nech si to ocisluje kros sam
	IF EMPTY(m.uza)
		m.uct00=m.uct00+m.gcuct_cisrad4+m.rokuct+"/"+m.mesuct+"/"+ALLTRIM(STR(m.poraduz,5,0))+CHR(9) &&cislo externe
	ELSE 
		m.uct00=m.uct00+m.gcuct_cisrad4+m.uza+CHR(9) &&cislo externe
	ENDIF 
ELSE  
	m.uct00=m.uct00+"180"+CHR(9) &&typ dokladu - interny doklad
	m.uct00=m.uct00+m.gcuct_evidencia2+CHR(9) &&kod evidencie
	m.uct00=m.uct00+m.gcuct_cisrad2+CHR(9) &&kod cisleneho radu
	m.poraduz=dajsapcdcislo("Kasy",m.rokuct, m.mesuct,"",m.gcuct_evidencia2)
	m.uct00=m.uct00+""+CHR(9) &&cislo interne - skusim nechat praydne, nech si to ocisluje kros sam
	IF EMPTY(m.uza)
		m.uct00=m.uct00+m.gcuct_cisrad2+m.rokuct+"/"+m.mesuct+"/"+ALLTRIM(STR(m.poraduz,5,0))+CHR(9) &&cislo externe
	ELSE 
		m.uct00=m.uct00+m.gcuct_cisrad2+m.uza+CHR(9) &&cislo externe
	ENDIF 
ENDIF 
m.uct00=m.uct00+CHR(9) &&meno firmy
m.uct00=m.uct00+CHR(9) &&ICO
m.uct00=m.uct00+CHR(9) &&DIC
m.uct00=m.uct00+m.pis_datum+CHR(9) &&datum vystavenia
m.uct00=m.uct00+CHR(9) &&datum prijatia
m.uct00=m.uct00+m.pis_datum+CHR(9) &&datum splatnosti
m.uct00=m.uct00+m.pis_datum+CHR(9) &&datum uskutocnenia zdanitelneho plnenia
m.uct00=m.uct00+m.pis_datum+CHR(9) &&datum uskutocnenia uctovneho pripadu
m.uct00=m.uct00+"EUR"+CHR(9) &&mena
m.uct00=m.uct00+"1"+CHR(9) &&mnozstvo jednotky
m.uct00=m.uct00+"1"+CHR(9) &&kurz NBS
m.uct00=m.uct00+"0"+CHR(9) &&kurz banka
SELECT uct_polozky
m.uct00=m.uct00+ALLTRIM(STR(uct_polozky.ciastka,15,2))+CHR(9) &&suma spolu CM
m.uct00=m.uct00+ALLTRIM(STR(uct_polozky.ciastka,15,2))+CHR(9) &&suma spolu TM
m.uct00=m.uct00+ALLTRIM(STR(m.uctdphlo*100-100,5,0))+CHR(9) &&sadzba nizsia
m.uct00=m.uct00+ALLTRIM(STR(m.uctdphhi*100-100,5,0))+CHR(9) &&sadzba vyssia
m.uct00=m.uct00+ALLTRIM(STR(uct_polozky.c5,15,2))+CHR(9) &&zaklad nizsia
m.uct00=m.uct00+ALLTRIM(STR(uct_polozky.c23,15,2))+CHR(9) &&zaklad vyssia
m.uct00=m.uct00+ALLTRIM(STR(uct_polozky.c0,15,2))+CHR(9) &&zaklad 0
m.uct00=m.uct00+ALLTRIM(STR(uct_polozky.cb,15,2))+CHR(9) &&zaklad neobsahuje
m.uct00=m.uct00+ALLTRIM(STR(uct_polozky.d5,15,2))+CHR(9) &&suma DPH nizsia
m.uct00=m.uct00+ALLTRIM(STR(uct_polozky.d23,15,2))+CHR(9) &&suma DPH vyssia
m.uct00=m.uct00+ALLTRIM(STR(ciastka-c0-cb-c5-c23-d5-d23,15,2))+CHR(9) &&halierove vyrovnanie
m.uct00=m.uct00+"FoodMan"+CHR(9)  && zaevidoval
m.uct00=m.uct00+""+CHR(9)  && konstantny symbol
m.uct00=m.uct00+""+CHR(9)  && specificky symbol
m.uct00=m.uct00+""+CHR(9)  && interne cislo uhradzaneho dokladu
m.uct00=m.uct00+""+CHR(9)  && externe cislo uhradzaneho dokladu
m.uct00=m.uct00+""+CHR(9)  &&  pre pokladnicne doklady znamienko dokladu
m.uct00=m.uct00+""+CHR(9)  && cislo uctu partnera
m.uct00=m.uct00+ALLTRIM(m.kros_partner_platby)+CHR(9)  && interne cislo partnera
*!*	m.uct00=m.uct00+""+CHR(9)  && kod partnera
*!*	m.uct00=m.uct00+""+CHR(9)  && cas vystavenia
*!*	m.uct00=m.uct00+""+CHR(9)  && poznamka
m.uct00=m.uct00+"Tržby FoodMan"+CHR(9)  && text hlavicky
*!*	m.uct00=m.uct00+"0"+CHR(9) && splatnost
*!*	m.uct00=m.uct00+""+CHR(9)  && prijate od
*!*	m.uct00=m.uct00+""+CHR(9)  && kod ic dph 
*!*	m.uct00=m.uct00+""+CHR(9)  && ic dph 
*!*	m.uct00=m.uct00+"0"+CHR(9)  && suma preddavku
*!*	m.uct00=m.uct00+""+CHR(9)  && ico poradove cislo
*!*	m.uct00=m.uct00+""+CHR(9)  && kod schvalil
*!*	m.uct00=m.uct00+""+CHR(9)  && schvalil
*!*	m.uct00=m.uct00+""+CHR(9)  && kod zeavidoval
*!*	m.uct00=m.uct00+"0"+CHR(9)  && priznak neuctovat
*!*	m.uct00=m.uct00+""+CHR(9)  && kod zauctoval 
*!*	m.uct00=m.uct00+""+CHR(9)  && zauctoval
m.uct00=STRTRAN(m.uct00,",",".")
= FPUTS(m.lihandle, m.uct00)


PROCEDURE kros_trz_02
* Export do KROSu - trzby
m.uct00="R02"+CHR(9) &&udaje
m.uct00=m.uct00+"0"+CHR(9) &&typ polozky :0=uctovny zapis
m.uct00=m.uct00+LEFT(ALLTRIM(uct_polozky.u1),3)+CHR(9) &&MD syntetika
m.uct00=m.uct00+SUBSTR(ALLTRIM(uct_polozky.u1),4,3)+CHR(9) &&MD analytika
m.uct00=m.uct00+LEFT(ALLTRIM(uct_polozky.u2),3)+CHR(9) &&DAL syntetika
m.uct00=m.uct00+SUBSTR(ALLTRIM(uct_polozky.u2),4,3)+CHR(9) &&DAL analytika
m.uct00=m.uct00+ALLTRIM(STR(uct_polozky.ciastka,16,2))+CHR(9) &&suma TM
m.uct00=m.uct00+ALLTRIM(STR(uct_polozky.ciastka,16,2))+CHR(9) &&suma CM
m.uct00=m.uct00+ALLTRIM(uct_polozky.poznamka)+CHR(9) &&text polozky
m.uct00=m.uct00+uct_polozky.typ+CHR(9) &&kod typu sumy
m.uct00=m.uct00+""+CHR(9) &&cislo uhradzaneho dokladu
m.uct00=m.uct00+""+CHR(9) &&cislo odpocitavaneho dokladu
m.uct00=m.uct00+ALLTRIM(uct_polozky.stredisko)+CHR(9) &&kod strediska
m.uct00=m.uct00+""+CHR(9) &&nazov strediska
m.uct00=m.uct00+ALLTRIM(uct_polozky.stredisko)+CHR(9) &&kod zakazky
m.uct00=m.uct00+""+CHR(9) &&nazov zakazky
m.uct00=m.uct00+""+CHR(9) &&kod cinnosti
m.uct00=m.uct00+""+CHR(9) &&nazov cinnosti
m.uct00=m.uct00+""+CHR(9) &&kod pracovnika
m.uct00=m.uct00+""+CHR(9) &&priezvisko pracovnika
m.uct00=m.uct00+""+CHR(9) &&meno pracovnika
m.uct00=m.uct00+""+CHR(9) &&cislo stredisko
m.uct00=m.uct00+""+CHR(9) &&cislo zakazka
m.uct00=m.uct00+""+CHR(9) &&cislo cinnost
m.uct00=m.uct00+""+CHR(9) &&cislo pracovnik
m.uct00=m.uct00+ALLTRIM(uct_polozky.kv)+CHR(9) &&oddiel kv dph
m.uct00=STRTRAN(m.uct00,",",".")
= FPUTS(m.lihandle, m.uct00)

PROCEDURE kros_trz_masaryk_02
PARAMETERS m.llidkas, m.lluzaverka
LOCAL m.pis_datum
IF EMPTY(m.lluzaverka)
	m.pis_datum=DTOC(GOMONTH(CTOD("01."+m.mesuct+"."+m.rokuct),1)-1)
ELSE
	PRIVATE m.mesuct, m.rokuct
	m.mesuct=SUBSTR(m.lluzaverka,5,2)
	m.rokuct=LEFT(m.lluzaverka,4)
	m.pis_datum=SUBSTR(m.lluzaverka,7,2)+"."+m.mesuct+"."+m.rokuct
ENDIF 
* Export do KROSu - trzby
m.uct00=m.llidkas+CHR(9) &&id_kas
m.uct00=m.uct00+m.lluzaverka+CHR(9) &&uzavierka
m.uct00=m.uct00+m.pis_datum+CHR(9) &&datum dokladu
m.uct00=m.uct00+m.pis_datum+CHR(9) &&datum plnenia
IF EMPTY(uct_polozky.u1)
	m.uct00=m.uct00+"xxx"+CHR(9) &&MD
ELSE
	m.uct00=m.uct00+LEFT(ALLTRIM(uct_polozky.u1),6)+CHR(9) &&MD
ENDIF 
IF EMPTY(uct_polozky.u2)
	m.uct00=m.uct00+"xxx"+CHR(9) &&MD
ELSE
	m.uct00=m.uct00+LEFT(ALLTRIM(uct_polozky.u2),6)+CHR(9) &&DAL
ENDIF 
m.uct00=m.uct00+ALLTRIM(STR(uct_polozky.ciastka,7,2))+CHR(9) &&suma
m.uct00=m.uct00+ALLTRIM(uct_polozky.stredisko)+CHR(9) &&vykon
m.uct00=m.uct00+ALLTRIM(uct_polozky.typ)+CHR(9) &&vykon
m.uct00=m.uct00+ALLTRIM(uct_polozky.faktura)+CHR(9) &&cislo uhradzaneho dokladu
m.uct00=m.uct00+ALLTRIM(uct_polozky.poznamka)+CHR(9) &&text polozky
m.uct00=STRTRAN(m.uct00,",",".")
= FPUTS(m.lihandle, m.uct00)




PROCEDURE kontrola_skladov
SELECT DISTINCT datum FROM u_doklady INTO CURSOR datumy READWRITE 
*** Kontrola dokladov v exporte na ich stav v UEXARCH ***
*
SCAN ALL
	m.oprava=.F.
	SELECT u_doklady
	SCAN FOR datum=datumy.datum
		SELECT uexarch
		LOCATE FOR operace<>"FA" AND ALLTRIM(datum)=ALLTRIM(u_doklady.datum) .AND. id_man=u_doklady.id_man .AND. ROUND(castka,2)=ROUND(u_doklady.castka,2) .AND. ALLTRIM(MD)=ALLTRIM(u_doklady.MD) .AND. ALLTRIM(dal)=ALLTRIM(u_doklady.dal) .AND. ALLTRIM(md2)=ALLTRIM(u_doklady.md2) .AND. ALLTRIM(dal2)=ALLTRIM(u_doklady.dal2) ;
			.AND. ALLTRIM(hs_md)=ALLTRIM(u_doklady.hs_md) .AND. ALLTRIM(hs_dal)=ALLTRIM(u_doklady.hs_dal) .AND. ALLTRIM(pz)=ALLTRIM(u_doklady.pz) .AND. ALLTRIM(partner)=ALLTRIM(u_doklady.partner) .AND. doklad=VAL(u_doklady.doklad) .AND. datum_dokl=u_doklady.datum_dokl .AND. ALLTRIM(poznamka)=ALLTRIM(u_doklady.poznamka) .AND. ALLTRIM(faktura)=ALLTRIM(u_doklady.faktura)
		IF !FOUND()
			m.oprava=.T.
		ENDIF
		SELECT u_doklady
	ENDSCAN
	IF m.oprava
		SELECT uexarch
		SCAN FOR datum=datumy.datum AND operace<>"FA"
			INSERT INTO u_doklady (datum,id_man,castka,MD,dal,md2,dal2,hs_md,hs_dal,pz,partner,doklad,datum_dokl,poznamka,storno, faktura, operace);
				VALUES (uexarch.datum,uexarch.id_man,-uexarch.castka,uexarch.MD,uexarch.dal,uexarch.md2,uexarch.dal2,uexarch.hs_md,uexarch.hs_dal,uexarch.pz,uexarch.partner,STR(uexarch.doklad,10,0),uexarch.datum_dokl,uexarch.poznamka,.T., uexarch.faktura, uexarch.operace)
		ENDSCAN
	ELSE
		SELECT u_doklady
		DELETE FOR datum=datumy.datum
	ENDIF
	SELECT datumy
ENDSCAN
*
*** Kontrola dokladov v exporte na ich stav v UEXARCH ***
*** Hladanie dokladov z UEXARCH, ktore uz neexistuju a treba ich stornovat v exporte ***
*
IF USED("stred01") 
	IF m.issql
		USE (m.sqlprefix+"ruzaverka") IN 0 ALIAS expuzav
		SELECT expuzav
		INDEX on rok+mesiac TAG kedy
	ELSE 
		USE (m.gcdat_path+"uzaverka") AGAIN IN 0 ALIAS expuzav ORDER kedy
	ENDIF 
	SELECT stred01
	SCAN FOR LABEL
		m.dokluzod=0
		m.dokluzdo=0
		SELECT expuzav
		SET FILTER TO c_stredisk=stred01.c_stredisk
		SCAN FOR (expuzav.rok+expuzav.mesiac)<=(m.rokuct+m.mesuct)
			DO CASE
				CASE (expuzav.rok+expuzav.mesiac)<(m.rokuct+m.mesuct)
					m.dokluzod=expuzav.c_dokldo
				CASE (expuzav.rok+expuzav.mesiac)=(m.rokuct+m.mesuct)
					m.dokluzdo=expuzav.c_dokldo
			ENDCASE
		ENDSCAN
		SELECT DISTINCT datum FROM uexarch WHERE operace<>"FA" AND id_man=stred01.ID .AND. VAL(datum)>m.dokluzod .AND. VAL(datum)<=m.dokluzdo .AND. !(datum IN (SELECT DISTINCT datum FROM datumy));
			INTO CURSOR datumy2 READWRITE 
		SCAN ALL
			SELECT uexarch
			SCAN FOR datum=datumy2.datum AND operace<>"FA"
				INSERT INTO u_doklady (datum,id_man,castka,MD,dal,md2,dal2,hs_md,hs_dal,pz,partner,doklad,datum_dokl,poznamka,storno,vymaz,faktura);
					VALUES (uexarch.datum,uexarch.id_man,-uexarch.castka,uexarch.MD,uexarch.dal,uexarch.md2,uexarch.dal2,uexarch.hs_md,uexarch.hs_dal,uexarch.pz,uexarch.partner,uexarch.doklad,uexarch.datum_dokl,uexarch.poznamka,.F.,.T., uexarch.faktura)
			ENDSCAN
			SELECT datumy2
		ENDSCAN
		USE IN datumy2
		SELECT expuzav
		SET FILTER TO
		SELECT stred01
	ENDSCAN
	USE IN expuzav
ENDIF
*
*** Hladanie dokladov z UEXARCH, ktore uz neexistuju a treba ich stornovat v exporte ***
USE IN datumy



PROCEDURE gen_exp_pohoda
PARAMETERS kontroluj,rokuct,mesuct
PRIVATE old_century,menoexp,oldsetdate,oldsetdele, riadkov, sumacelk,dokluzod,dokluzdo,prijemky, vydajky, ok
PRIVATE m.hladajrok, m.hladajmesiac
PRIVATE m.hladajidediprev
LOCAL m.hhotel_naz1, m.x_partner, m.x_stredisk, m.menostrediska, m.hhotel_ulica, m.hhotel_psc, m.hhotel_mesto, m.hhotel_telefon, m.hhotel_osoba, m.hhotel_mail, m.hhotel_gln
PRIVATE m.cislo_objednavky
PRIVATE m.hhotel_banka, m.hhotel_ucet, m.hhotel_swift, m.hhotelreg_cislo, m.hhotelreg_vydal, m.hhotel_ico, m.hhotel_dico, m.hhotel_icdph
m.hladajrok=m.rokuct
m.hladajmesiac=m.mesuct
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
m.old_century=SET("century")
m.oldsetdate=SET("date")
m.oldsetdele=SET("dele")
SET DATE TO GERMAN
SET DELETED ON
m.gcuexp_path=ALLTRIM(IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path))
IF !DIRECTORY(m.gcuexp_path)
	MKDIR (m.gcuexp_path)
ENDIF
SET CENTURY ON
gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
gen_exp_had.SHOW()
gen_exp_had.set_max(20)
gen_exp_had.INCREMENT("Sklady")
IF USED("u_ex_obraty")
	SELECT u_ex_obraty
	REPLACE castka WITH -castka FOR operace="PI"
	SELECT operace, c_dokl, datum, id_man, SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka,faktura,.F. AS storno,.F. AS vymaz,SPACE(m.sirkastlpcadruh) as druh, SPACE(50) as txt FROM u_ex_obraty GROUP BY id_man,poznamka,datum,doklad,datum_dokl,MD,dal INTO CURSOR u_doklady WHERE INLIST(LEFT(pz,1),"P","V") READWRITE 
*	REPLACE ALL druh WITH SUBSTR(pz,AT("|",pz,1)+1,10)
	DELETE FOR EMPTY(datum)
	DELETE FOR EMPTY(MD)
	IF LOWER(gcuct_spec)="globalfina"
		IF m.issql
			USE (m.sqlprefix+"rdoklady") ALIAS doklady IN 0
			SELECT doklady
			INDEX on c_dokl TAG c_dokl
		ELSE 
			USE (m.fn_doklady) ALIAS doklady IN 0 AGAIN
		ENDIF 
		SELECT u_doklady 
		UPDATE u_doklady SET txt=fndokl.poznamka FROM fndokl WHERE u_doklady.c_dokl=fndokl.c_dokl
		REPLACE ALL txt WITH STRTRAN(STRTRAN(txt,CHR(13),""),CHR(10),"")
	ENDIF 
	SELECT u_doklady
	SELECT 0
	IF m.issql
		USE (m.sqlprefix+"ruexarchobraty_mesiacrok") ALIAS uexarch IN 0
	ELSE 
		IF !FILE(m.gccen_path+"uexarchobraty.dbf")
			DO creafile WITH (m.gccen_path+"uexarchobraty.dbf")
		ENDIF 
		IF !USED("uexarchobraty")
			USE (m.gccen_path+"uexarchobraty") IN 0
		ENDIF 
		USE vuexarchobraty_mesiacrok IN 0 ALIAS uexarch
	ENDIF 
	=CURSORSETPROP("Buffering",5,"uexarch")
	IF m.kontroluj
		DO kontrola_skladov
	ELSE
		SELECT 0
		IF m.issql
			USE (m.sqlprefix+"ruzaverka") ALIAS expuzav
			INDEX on rok+mesiac TAG kedy
		ELSE 
			USE (m.gcdat_path+"uzaverka") AGAIN ALIAS expuzav ORDER kedy
		ENDIF 
		SET FILTER TO c_stredisk=m.gic_stredisk
		GO BOTTOM
		m.rokuct=expuzav.rok
		m.mesuct=expuzav.mesiac
		IF EMPTY(m.rokuct) .OR. EMPTY(m.mesuct)
			m.rokuct=STR(YEAR(DATE()),4,0)
			m.mesuct=STRTRAN(STR(MONTH(DATE()),2,0)," ","0")
		ELSE
			m.mesuct=STRTRAN(STR(VAL(m.mesuct)+1,2,0)," ","0")
			IF m.mesuct="13"
				m.mesuct="01"
				m.rokuct=STR(VAL(m.rokuct)+1,4,0)
			ENDIF
		ENDIF
		USE IN expuzav
	ENDIF

	SELECT u_doklady
	DELETE FOR castka=0
	IF !USED("doklady")
		IF m.issql
			USE (m.sqlprefix+"rdoklady") IN 0 ALIAS doklady
			SELECT doklady
			INDEX on c_dokl TAG c_dokl
		ELSE 
			IF !USED("doklady")
				USE (m.fn_doklady) ALIAS doklady AGAIN IN 0 ORDER c_dokl
			ELSE
				SELECT doklady
				SET ORDER TO c_dokl
			ENDIF
		ENDIF 
	ELSE
		SELECT doklady
		SET ORDER TO c_dokl
	ENDIF
	m.poraduz=dajsapcdcislo("Food",m.rokuct, PADL(ALLTRIM(m.mesuct),2,"0"), "", "")
	m.menoexp="Food"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")+".xml"
	SELECT u_doklady
	COUNT FOR !DELETED() TO assasas
	SELECT id_man,SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,doklad,datum_dokl,poznamka,faktura,druh, operace, txt FROM u_doklady GROUP BY MD, dal, hs_md, hs_dal, md2, dal2, poznamka INTO CURSOR u_doklady1 ORDER BY poznamka READWRITE 

	IF RECCOUNT()>0
		SELECT 0
		IF FILE(m.gcuexp_path+m.menoexp)
			ERASE(m.gcuexp_path+m.menoexp)
		ENDIF
		m.lihandle= FCREATE(m.gcuexp_path + m.menoexp)
		IF m.lihandle > 0
			m.uct00=""
			m.dotextu="Sklad"
			DO poho_skl_00
			SELECT u_doklady1
			SCAN FOR LOWER(ALLTRIM(MD))<>"export" .and. castka<>0
				DO poho_skl_02
			ENDSCAN
			m.uct00='</dat:dataPack>'
			= FPUTS(m.lihandle, m.uct00)
			=FCLOSE(m.lihandle)
			IF FILE(m.gcuexp_path + m.menoexp)
				IF !EMPTY(m.uct_email_sklady)
					DO odosli_export_mailom WITH (m.gcuexp_path+m.menoexp), m.hotel_name, m.uct_email_sklady
				ENDIF
			ENDIF 
			SELECT u_doklady
			SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
				SELECT uexarch
				DELETE FOR datum=u_doklady.datum
				SELECT u_doklady
			ENDSCAN
			SELECT u_doklady
			IF m.archivovatprenosy
				SELECT uexarch
				APPEND FROM DBF("u_doklady") FOR !storno .AND. !vymaz
				REPLACE c_data WITH m.cdata FOR c_data<>m.cdata
				REPLACE ALL mesiac WITH m.mesuct FOR mesiac<>m.mesuct
				REPLACE ALL rok WITH m.rokuct FOR rok<>m.rokuct
				=tux(.t.,.t.,"uexarch")
			ENDIF 
			DO pozavirej WITH "uexarch, uexarchobraty"
			IF !m.issql
				IF f_acc_ex(m.gcdat_path+"uexarchobraty")
					PACK
					USE
				ENDIF
			ENDIF 
		ENDIF
	ENDIF 
	DO pozavirej WITH "uexarch, uexarchobraty, u_doklady, u_doklady1, doklady"


	*** Faktury ***
	gen_exp_had.INCREMENT("Faktúry")
	IF LOWER(m.wi_zakaz)="sushitime"
		SELECT disti c_prev FROM u_ex_obraty INTO CURSOR uexcprev
	ELSE 
		SELECT DISTINCT 0 as c_prev  FROM u_ex_obraty INTO CURSOR uexcprev
	ENDIF 
	SCAN ALL 
		m.hladajidediprev=uexcprev.c_prev
		SELECT operace, id_man,datum, SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,STR(doklad,10,0) as doklad,datum_dokl, SUM(spdan) as spdan,poznamka,faktura,.F. AS storno,.F. AS vymaz, druh, dph FROM u_ex_obraty GROUP BY id_man, datum, MD, dal, dph INTO CURSOR u_doklady WHERE INLIST(LEFT(pz,1),"F","S") AND c_prev=m.hladajidediprev READWRITE 
		REPLACE ALL druh WITH SUBSTR(pz,AT("|",pz,1)+1,10)
		DELETE FOR EMPTY(datum)
		DELETE FOR EMPTY(MD)
		SELECT u_doklady
		SELECT 0
		IF m.issql
			USE (m.sqlprefix+"ruexarchobraty_mesiacrok") ALIAS uexarch IN 0
		ELSE 
			IF !FILE(m.gccen_path+"uexarchobraty.dbf")
				DO creafile WITH (m.gccen_path+"uexarchobraty.dbf")
			ENDIF 
			IF !USED("uexarchobraty")
				USE (m.gccen_path+"uexarchobraty") IN 0
			ENDIF 
			USE vuexarchobraty_mesiacrok IN 0 ALIAS uexarch
		ENDIF 
		=CURSORSETPROP("Buffering",5,"uexarch")

		IF m.kontroluj
			DO kontrola_faktur
		ELSE
			SELECT 0
			IF m.issql
				USE (m.sqlprefix+"ruzaverka") ALIAS expuzav
				INDEX on rok+mesiac TAG kedy
			ELSE 
				USE (m.gcdat_path+"uzaverka") AGAIN ALIAS expuzav ORDER kedy
			ENDIF 
			SET FILTER TO c_stredisk=m.gic_stredisk
			GO BOTTOM
			m.rokuct=expuzav.rok
			m.mesuct=expuzav.mesiac
			IF EMPTY(m.rokuct) .OR. EMPTY(m.mesuct)
				m.rokuct=STR(YEAR(DATE()),4,0)
				m.mesuct=STRTRAN(STR(MONTH(DATE()),2,0)," ","0")
			ELSE
				m.mesuct=STRTRAN(STR(VAL(m.mesuct)+1,2,0)," ","0")
				IF m.mesuct="13"
					m.mesuct="01"
					m.rokuct=STR(VAL(m.rokuct)+1,4,0)
				ENDIF
			ENDIF
			USE IN expuzav
		ENDIF

		SELECT u_doklady
		DELETE FOR castka=0
		IF !USED("doklady")
			IF m.issql
				USE (m.sqlprefix+"rdoklady") IN 0 ALIAS doklady
				SELECT doklady
				INDEX on c_dokl TAG c_dokl
			ELSE 
				IF !USED("doklady")
					USE (m.fn_doklady) ALIAS doklady AGAIN IN 0 ORDER c_dokl
				ELSE
					SELECT doklady
					SET ORDER TO c_dokl
				ENDIF
			ENDIF 
		ELSE
			SELECT doklady
			SET ORDER TO c_dokl
		ENDIF
		IF !USED("partneri")
			IF m.issql
				SELECT 0
				USE (m.sqlprefix+"rpartneriucto") ALIAS partneri
				INDEX on partner TAG partner
			ELSE 
				USE (m.fn_partneri) ALIAS partneri AGAIN IN 0 ORDER partner
			ENDIF 
		ELSE
			SELECT partneri
			SET ORDER TO partner
		ENDIF
		IF !USED("skupiny")
			IF m.issql
				USE (m.sqlprefix+"rskupinyucto") ALIAS skupiny IN 0
				SELECT skupiny
				INDEX on druh TAG druh
			ELSE 
				USE (m.fn_skupiny) ALIAS skupiny AGAIN IN 0 ORDER druh
			ENDIF 
		ELSE
			SELECT skupiny
	*		SET ORDER TO druh
		ENDIF
		IF m.hladajidediprev=0
			m.hhotel_naz1=m.hotel_naz1
			m.hhotel_ulica=m.hotel_naz2
			m.hhotel_psc=m.hotel_naz4
			m.hhotel_mesto=m.hotel_naz3
			m.hhotel_osoba=""
			m.hhotel_telefon=""
			m.hhotel_mail=m.uct_email_sklady
			m.hhotel_ico=m.hotel_ico
			m.hhotel_dico=m.hotel_dico
			m.hhotel_icdph=m.hot_icdph
			m.hhotel_gln=IIF(EMPTY(m.hotel_edikod), ALLTRIM(m.hotel_ico), ALLTRIM(m.hotel_edikod))
			m.hhotel_banka=m.hotel_bank
			m.hhotel_ucet=m.hotel_ucet
			m.hhotel_swift=m.hotel_swift
			m.hhotelreg_cislo=m.reg_cislo
			m.hhotelreg_vydal=m.reg_vydal
			m.poraduz=dajsapcdcislo("Fakt",m.rokuct, m.mesuct,"","")
			m.menoexp="Fakt"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")+".xml"
		ELSE
			SELECT 0
			USE (m.sqlprefix+"redi_prev") ALIAS edi_prev
			LOCATE FOR idriadok=m.hladajidediprev
			IF FOUND()
				m.hhotel_naz1=ALLTRIM(edi_prev.meno)
				m.hhotel_ulica=ALLTRIM(edi_prev.ulica)
				m.hhotel_psc=ALLTRIM(edi_prev.psc)
				m.hhotel_mesto=ALLTRIM(edi_prev.mesto)
				m.hhotel_osoba=ALLTRIM(edi_prev.osoba)
				m.hhotel_telefon=ALLTRIM(edi_prev.telefon)
				m.hhotel_mail=ALLTRIM(edi_prev.mail)
				m.hhotel_ico=ALLTRIM(edi_prev.ico)
				m.hhotel_dico=ALLTRIM(edi_prev.dic)
				m.hhotel_icdph=ALLTRIM(edi_prev.ic_dph)
				m.hhotel_banka=ALLTRIM(edi_prev.banka)
				m.hhotel_ucet=ALLTRIM(edi_prev.ucet)
				m.hhotel_swift=ALLTRIM(edi_prev.swift)
				m.hhotelreg_cislo=ALLTRIM(edi_prev.reg_cislo)
				m.hhotelreg_vydal=ALLTRIM(edi_prev.reg_vydal)
			ELSE 
				m.hhotel_naz1=m.hotel_naz1
				m.hhotel_ulica=m.hotel_naz2
				m.hhotel_psc=m.hotel_naz4
				m.hhotel_mesto=m.hotel_naz3
				m.hhotel_osoba=""
				m.hhotel_telefon=""
				m.hhotel_mail=m.uct_email_sklady
				m.hhotel_ico=m.hotel_ico
				m.hhotel_dico=m.hotel_dico
				m.hhotel_icdph=m.hot_icdph
				m.hhotel_gln=IIF(EMPTY(m.hotel_edikod), ALLTRIM(m.hotel_ico), ALLTRIM(m.hotel_edikod))
				m.hhotel_banka=m.hotel_bank
				m.hhotel_ucet=m.hotel_ucet
				m.hhotel_swift=m.hotel_swift
				m.hhotelreg_cislo=m.reg_cislo
				m.hhotelreg_vydal=m.reg_vydal
				m.poraduz=dajsapcdcislo("Fakt",m.rokuct, m.mesuct,"","")
				m.menoexp="Fakt"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")+".xml"
			ENDIF 
			USE IN edi_prev
			m.poraduz=dajsapcdcislo("Fakt"+ALLTRIM(STR(m.hladajidediprev,5,0)),m.rokuct, m.mesuct,"","")
			m.menoexp="Fakt"+ALLTRIM(STR(m.hladajidediprev,5,0))+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")+".xml"
		ENDIF 
		SELECT u_doklady
		SELECT DISTINCT datum FROM u_doklady INTO CURSOR datumy READWRITE 
		IF RECCOUNT()>0
			SELECT 0
		    backslash(@m.gcuexp_path)	
			IF FILE(m.gcuexp_path+m.menoexp)
				ERASE(m.gcuexp_path+m.menoexp)
			ENDIF
			m.lihandle= FCREATE(m.gcuexp_path + m.menoexp)
			IF m.lihandle > 0
				m.uct00=""
				m.dotextu="Sklad"
				DO poho_fakt_00
				SELECT datumy
				SCAN ALL 
					SCATTER MEMVAR fields datum
					SELECT datum,SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,doklad,datum_dokl,SUM(spdan) as spdan,faktura,u_doklady.druh, dph as dan FROM u_doklady GROUP BY datum,MD, dal, hs_md, hs_dal, md2, dal2, u_doklady.druh INTO CURSOR u_doklady1 WHERE datum=m.datum READWRITE 
					SET RELATION TO partner INTO partneri
					SET RELATION TO VAL(datum) INTO doklady ADDITIVE
					m.cislo_objednavky=""
					IF !EMPTY(m.hladajidediprev) OR "sushitime"$LOWER(m.wi_zakaz)
						m.hladajcdokl=VAL(m.datum)
						IF USED("dokladxx")
							=REQUERY("dokladxx")
						ELSE
							IF m.issql
								USE (m.sqlprefix+"rprnobra") IN 0 ALIAS dokladxx
							ELSE
								USE vprnobra IN 0 ALIAS dokladxx
							ENDIF 
						ENDIF 
						IF INLIST(dokladxx.operace,"VR","VE") AND !EMPTY(dokladxx.pz1)
							m.hladajpz2=STR(dokladxx.c_dokl,15,0)
							SELECT 0
							IF m.issql
								USE (m.sqlprefix+"rdokladyziadankakvydajke") ALIAS zz1
							ELSE 
								USE vdokladyziadankakvydajke ALIAS zz1
							ENDIF 
							IF RECCOUNT("zz1")>0
								GO TOP 
								SCAN ALL 
									IF EMPTY(m.cislo_objednavky)
										m.cislo_objednavky=m.cislo_objednavky+ALLTRIM(zz1.pz1)
									ELSE 
										m.cislo_objednavky=m.cislo_objednavky+","+ALLTRIM(zz1.pz1)
									ENDIF 
								ENDSCAN 
							ELSE
								m.cislo_objednavky=ALLTRIM(dokladxx.pz1)
							ENDIF 
							DO pozavirej WITH "zz1"
						ENDIF 
					ENDIF 
					DO poho_fakt_02
					SET RELATION OFF INTO partneri
					SET RELATION OFF INTO doklady
					SELECT datumy
				ENDSCAN
				m.uct00='</dat:dataPack>'
				= FPUTS(m.lihandle, m.uct00)
				=FCLOSE(m.lihandle)
				IF FILE(m.gcuexp_path + m.menoexp)
					IF !EMPTY(m.hhotel_mail)
						DO odosli_export_mailom WITH (m.gcuexp_path+m.menoexp), m.hhotel_naz1, m.hhotel_mail
					ENDIF
				ENDIF 
				SELECT u_doklady
				SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
					SELECT uexarch
					DELETE FOR datum=u_doklady.datum AND operace="FA"
					SELECT u_doklady
				ENDSCAN
				SELECT u_doklady
				IF m.archivovatprenosy   
					SELECT uexarch
					APPEND FROM DBF("u_doklady") FOR !storno .AND. !vymaz
					REPLACE c_data WITH m.cdata FOR c_data<>m.cdata
					REPLACE ALL mesiac WITH m.mesuct FOR mesiac<>m.mesuct
					REPLACE ALL rok WITH m.rokuct FOR rok<>m.rokuct
					=tux(.t.,.t.,"uexarch")
				ENDIF 
				DO pozavirej WITH "uexarch, uexarchobraty"
				**** Zapis o prenose dokladov do doklady.dbf
				IF m.issql
					USE (m.sqlprefix+"ruexdoklady_prenos") ALIAS doklx IN 0
					=CURSORSETPROP("Buffering",5,"doklx")
					UPDATE doklx SET uctexport=.t. WHERE c_dokl in (SELECT disti c_dokl FROM u_ex_obraty WHERE operace="FA")
					=tux(.t.,.t.,"doklx")
					USE IN doklx
				ELSE 
					IF !USED("doklady")
						USE (m.fn_doklady) ALIAS doklady IN 0
						UPDATE doklady SET uctexport=.t. WHERE c_dokl in (SELECT disti c_dokl FROM u_ex_obraty WHERE operace="FA")
						USE IN doklady
					ELSE 
						UPDATE doklady SET uctexport=.t. WHERE c_dokl in (SELECT disti c_dokl FROM u_ex_obraty WHERE operace="FA")
					ENDIF 
				ENDIF 
				IF !m.issql
					IF f_acc_ex(m.gcdat_path+"uexarchobraty")
						PACK
						USE
					ENDIF
				ENDIF 
			ENDIF
		ENDIF 
		DO pozavirej WITH "u_doklady, u_doklady1, uexarch, uexarchobraty"
	ENDSCAN 
	DO pozavirej WITH "u_doklady, u_doklady1, doklady, skupiny, partneri, uexarch, uexarchobraty, u_ex_obraty, dokladxx, uexcprev"
ENDIF 
*** Trzby ***
IF m.gcuct_trzba AND USED("u_ex_platby") AND USED("u_ex_polozky")
	SELECT id_kas, uzaverka, u_cis, dan, SUM(castka) as suma, $0 as dph FROM u_ex_polozky GROUP BY id_kas, uzaverka, u_cis, dan INTO CURSOR dphvypocet READWRITE 
	REPLACE ALL dph WITH ground(suma*(dan-1)/dan,2)
	LOCAL m.idkas, m.uzaverka, m.ucis, m.sumadph, m.sumacelkom, m.sadzbadane, m.rozdieldane, m.pouctenkach
	gen_exp_had.set_max(RECCOUNT("dphvypocet"))
	SCAN ALL 
		gen_exp_had.increment("Kontrola výpočtu DPH:"+ALLTRIM(STR(RECNO("dphvypocet")))+"/"+ALLTRIM(STR(RECCOUNT("dphvypocet"))))
		m.idkas=dphvypocet.id_kas
		m.uzaverka=dphvypocet.uzaverka
		m.ucis=dphvypocet.u_cis
		m.sumadph=dphvypocet.dph
		m.sumacelkom=dphvypocet.suma
		m.sadzbadane=dphvypocet.dan
		SELECT SUM(castka) as castka, SUM(dan_zakl) as dan_zakl FROM u_ex_polozky WHERE id_kas=m.idkas AND uzaverka=m.uzaverka AND u_cis=m.ucis AND dan=m.sadzbadane INTO CURSOR dphnajdene
		IF RECCOUNT("dphnajdene")=1
			GO TOP 
			IF castka=m.sumacelkom AND (castka-dan_zakl)=m.sumadph
			ELSE
				m.rozdieldane=dphnajdene.castka-dphnajdene.dan_zakl-m.sumadph
				SELECT u_ex_polozky
				SET FILTER TO id_kas=m.idkas AND uzaverka=m.uzaverka AND u_cis=m.ucis AND dan=m.sadzbadane
				GO TOP 
				REPLACE dan_zakl WITH dan_zakl+m.rozdieldane
				SET FILTER TO 
			ENDIF 
		ENDIF 
		USE IN dphnajdene
		SELECT dphvypocet
	ENDSCAN 
	RELEASE m.idkas, m.uzaverka, m.ucis, m.sumadph, m.sumacelkom, m.sadzbadane, m.rozdieldane
	DO pozavirej WITH "dphvypocet, dphnajdene"

	SELECT SUM(castka) AS ciastka, MD,dal,md2,dal2,hs_dal,hs_md,partner,pz, poznamka, $0 AS celkom, 1.000000000 AS koef FROM u_ex_platby GROUP BY pz,poznamka,MD,dal INTO CURSOR u_doklady READWRITE  
	SELECT SUM(castka) AS ciastka, pz FROM u_ex_platby GROUP BY pz INTO CURSOR u_platby  READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	SELECT u_doklady
	SET RELATION TO ALLTRIM(pz) INTO u_platby
	REPLACE ALL u_doklady.celkom WITH u_platby.ciastka
	SET RELATION OFF INTO u_platby
	USE IN u_platby
	REPLACE ALL koef WITH IIF(celkom=0,1,ciastka/celkom)


	SELECT id_kas, uzaverka, u_cis, SUM(castka) AS ciastka, MD, dal, md2, dal2, hs_md, hs_dal, poznamka, pz, partner, SUM(dan_zakl) AS danzakl, SUM(castka-dan_zakl) as sum_dan, STR(dan*100-100,2,0) as txtdan, datum_dokl FROM u_ex_polozky GROUP BY pz, poznamka, MD, dal, md2, dal2, dan INTO CURSOR u_dokl1 READWRITE 
	SELECT u_dokl1
	REPLACE ALL poznamka WITH STRTRAN(poznamka,"POL HORES ","")
	REPLACE ALL poznamka WITH STRTRAN(poznamka,"POL ","")
		
	
	SELECT id_kas, uzaverka, SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(sum_dan) AS dan, MD, dal, md2, dal2,hs_md, hs_dal, poznamka, txtdan, pz, datum_dokl, partner FROM u_dokl1 GROUP BY id_kas, pz, MD, dal, hs_md, hs_dal, poznamka, txtdan INTO CURSOR u_dokl2 READWRITE 
	REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
	SELECT id_kas, uzaverka, SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, MD, dal, hs_md, hs_dal, md2, dal2, pz, poznamka, txtdan, partner, datum_dokl FROM u_dokl2 GROUP BY id_kas, pz, MD, dal, hs_md, hs_dal, poznamka,txtdan  INTO CURSOR u_dokl READWRITE 
	DELETE FOR ROUND(ciastka,2)=0
	INDEX ON ALLTRIM(pz) TAG pz
	SELECT u_doklady
	DO poho_trzby WITH .f.,.t.
	IF export_po_uctenkach
		DO poho_trzby WITH .t.
	ENDIF 
	SET CENTURY &old_century
	SET DATE &oldsetdate
	SET DELETED &oldsetdele
	DO pozavirej WITH "vondbf, u_doklady, u_dokl, vondbf1, vondbf2, datumy"
ENDIF 
SET DELETED &oldsetdele
RELEASE gen_exp_had


PROCEDURE poho_trzby
PARAMETERS pouctenkach, archivprenosu
IF !prazdna()
	m.gcuexp_path = ALLTRIM(m.gcuexp_path)
	IF ! DIRECTORY(m.gcuexp_path)
		MKDIR (m.gcuexp_path)
	ENDIF
	SELECT SPACE(17) AS uzaverka,SPACE(7) as u_cis, ciastka, MD,dal,md2,dal2,hs_dal,hs_md,poznamka, poznamka as pozn_pol,celkom, $0 AS danzakl, $0 AS dan, ;
		SPACE(5) AS sadzba FROM u_doklady INTO  CURSOR vondbf WHERE .f. READWRITE 
	SELECT u_doklady
	SCAN FOR ciastka<>0
		INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba, poznamka, pozn_pol, u_cis) VALUES ;
			(LEFT(u_doklady.pz,17),u_doklady.ciastka,u_doklady.MD,u_doklady.dal,u_doklady.md2,u_doklady.dal2,u_doklady.hs_md,u_doklady.hs_dal,0,0,"",u_doklady.poznamka,u_doklady.poznamka,RIGHT(ALLTRIM(u_doklady.pz),7))
	ENDSCAN 
	SELECT u_dokl
	SCAN FOR ciastka<>0
		INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba, poznamka, pozn_pol, u_cis) VALUES ;
			(LEFT(u_dokl.pz,17),u_dokl.ciastka,u_dokl.MD,u_dokl.dal,u_dokl.md2,u_dokl.dal2,u_dokl.hs_md,u_dokl.hs_dal,u_dokl.danzakl,u_dokl.dan,u_dokl.txtdan,u_dokl.poznamka,u_dokl.poznamka,RIGHT(ALLTRIM(u_dokl.pz),7))
	ENDSCAN 
	IF m.pouctenkach
		SELECT uzaverka, u_cis, SUM(ciastka) AS ciastka, MD, dal, md2, dal2, hs_md, hs_dal, SUM(danzakl) AS danzakl, SUM(dan) AS dan, sadzba, poznamka, pozn_pol FROM vondbf ;
			GROUP BY uzaverka, u_cis, MD, dal, sadzba, poznamka, pozn_pol INTO CURSOR vondbf2 READWRITE 
		SELECT uzaverka, u_cis, SUM(ciastka) AS ciastka, MD, dal, md2, dal2, hs_md, hs_dal, 0000000000.00 AS cena0, 0000000000.00 AS cena5, 0000000000.00 AS cena23, 000000000.00 AS dan5, 000000000.00 AS dan23, .F. AS vymaz, .F. AS storno, poznamka, pozn_pol FROM vondbf ;
			GROUP BY uzaverka, u_cis, MD, dal, poznamka, pozn_pol INTO CURSOR vondbf1 READWRITE 
	ELSE
		SELECT uzaverka, "" as u_cis, SUM(ciastka) AS ciastka, MD, dal, md2, dal2, hs_md, hs_dal, SUM(danzakl) AS danzakl, SUM(dan) AS dan, sadzba, poznamka, pozn_pol FROM vondbf ;
			GROUP BY uzaverka, MD, dal, sadzba,poznamka, pozn_pol INTO CURSOR vondbf2 READWRITE 
		SELECT uzaverka, "" as u_cis, SUM(ciastka) AS ciastka, MD, dal, md2, dal2, hs_md, hs_dal, 0000000000.00 AS cena0, 0000000000.00 AS cena5, 0000000000.00 AS cena23, 000000000.00 AS dan5, 000000000.00 AS dan23, .F. AS vymaz, .F. AS storno, poznamka, pozn_pol FROM vondbf ;
			GROUP BY uzaverka, MD, dal, poznamka, pozn_pol INTO CURSOR vondbf1 READWRITE 
	ENDIF 
	m.riadkov=1
	SCAN ALL
		SELECT vondbf2
		SCAN FOR MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. uzaverka=vondbf1.uzaverka  .and. u_cis=vondbf1.u_cis .and. poznamka=vondbf1.poznamka .and. pozn_pol=vondbf1.pozn_pol
			DO CASE
				CASE ALLTRIM(sadzba)="0"
					REPLACE vondbf1.cena0 WITH vondbf2.danzakl
				CASE ALLTRIM(sadzba)=ALLTRIM(STR((m.uctdphlo-1)*100,10,0))
					REPLACE vondbf1.cena5 WITH vondbf2.danzakl, vondbf1.dan5 WITH vondbf2.dan
				OTHERWISE
					REPLACE vondbf1.cena23 WITH vondbf2.danzakl, vondbf1.dan23 WITH vondbf2.dan
			ENDCASE
		ENDSCAN
	ENDSCAN
	IF !m.issql
		IF FILE(m.gcdat_path+"uexarsk.dbf")
			SELECT 0
			USE (m.gcdat_path+"uexarsk.dbf")
			IF FSIZE("u_cis")=0
				TRY 
					USE
					USE (m.gcdat_path+"uexarsk.dbf") EXCLUSIVE
					ALTER table uexarsk ADD COLUMN u_cis c(7)
					USE 
					USE (m.gcdat_path+"uexarsk.dbf")
				CATCH
					=MESSAGEBOX(jaz("form_upravit_strukturu_uexarsk"),16,"FoodMan")
					RETURN
				ENDTRY 
			ENDIF 
		ELSE
			SELECT vondbf1
			COPY STRUCTURE TO (m.gcdat_path+"uexarsk.dbf")
			SELECT 0
			USE (m.gcdat_path+"uexarsk_uzaverka.dbf")
		ENDIF
	ENDIF 
	IF m.kontroluj
		SELECT DISTINCT uzaverka, u_cis FROM vondbf1 INTO CURSOR datumy READWRITE 
		SCAN ALL
			m.hladajuzaverka=datumy.uzaverka
			m.hladajucis=datumy.u_cis
			m.oprava=0
			SELECT vondbf1
			SCAN FOR uzaverka=datumy.uzaverka AND u_cis=datumy.u_cis
				IF m.issql
					IF USED("uexarsk")
						=REQUERY("uexarsk")
					ELSE
						USE (m.sqlprefix+"ruexarsk_uzaverka_ucis") ALIAS uexarsk IN 0
						=CURSORSETPROP("Buffering",5,"uexarsk")
					ENDIF 
				ENDIF 
				SELECT uexarsk
				LOCATE FOR uzaverka=vondbf1.uzaverka AND u_cis=vondbf1.u_cis
				IF FOUND()
					LOCATE FOR ALLTRIM(uzaverka)=ALLTRIM(vondbf1.uzaverka) .AND. ALLTRIM(u_cis)=ALLTRIM(vondbf1.u_cis) .AND. ciastka=vondbf1.ciastka .AND. ALLTRIM(MD)=ALLTRIM(vondbf1.MD) .AND. ALLTRIM(dal)=ALLTRIM(vondbf1.dal) .AND. cena0=vondbf1.cena0 .AND. cena5=vondbf1.cena5 ;
						.AND. cena23=vondbf1.cena23 .AND. dan5=vondbf1.dan5 .AND. dan23=vondbf1.dan23 .AND. ALLTRIM(hs_md)=ALLTRIM(vondbf1.hs_md) .AND. ALLTRIM(hs_dal)=ALLTRIM(vondbf1.hs_dal) .and. ALLTRIM(poznamka)=ALLTRIM(vondbf1.poznamka) .and. ALLTRIM(pozn_pol)=ALLTRIM(vondbf1.pozn_pol)
					IF !FOUND()
						m.oprava=2
					ELSE
						m.oprava=1
					ENDIF
				ELSE
					m.oprava=0
				ENDIF
				SELECT vondbf1
				IF m.oprava=2
					EXIT
				ENDIF
			ENDSCAN
			DO CASE
				CASE m.oprava=2
					SELECT uexarsk
					SCAN FOR uzaverka=datumy.uzaverka AND u_cis=datumy.u_cis
						INSERT INTO vondbf1 (uzaverka,u_cis,ciastka,MD,dal,hs_md, hs_dal,md2,dal2,cena0,cena5,cena23,dan5,dan23,storno, poznamka, pozn_pol);
							VALUES (uexarsk.uzaverka,uexarsk.u_cis,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,uexarsk.md2,uexarsk.dal2,-uexarsk.cena0,-uexarsk.cena5,;
							-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.T., uexarsk.poznamka, uexarsk.pozn_pol)
					ENDSCAN
				CASE m.oprava=1
					SELECT vondbf1
					DELETE FOR uzaverka=datumy.uzaverka AND u_cis=datumy.u_cis
			ENDCASE
			SELECT datumy
		ENDSCAN
		IF m.issql
			USE (m.sqlprefix+"ruexarsk_zoznam_uzavierok_uctov") ALIAS uexzoznam IN 0
			SELECT DISTINCT uzaverka, u_cis FROM uexzoznam WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
				INTO CURSOR datumy2 READWRITE 
			USE IN uexzoznam
		ELSE 
			SELECT DISTINCT uzaverka, u_cis FROM uexarsk WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
				INTO CURSOR datumy2 READWRITE 
		ENDIF 
		SCAN ALL
			m.hladajuzaverka=datumy2.uzaverka
			m.hladajucis=datumy2.u_cis
			IF m.issql
				=REQUERY("uexarsk")
			ENDIF 
			SELECT uexarsk
			SCAN FOR uzaverka=datumy2.uzaverka AND u_cis=datumy2.u_cis
				INSERT INTO vondbf1 (uzaverka,u_cis,ciastka,MD,dal,hs_md, hs_dal,cena0,cena5,cena23,dan5,dan23,storno,vymaz, poznamka, pozn_pol);
					VALUES (uexarsk.uzaverka,uexarsk.u_cis,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,-uexarsk.cena0,-uexarsk.cena5,;
					-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.F.,.T., uexarsk.poznamka, uexarsk.pozn_pol)
			ENDSCAN
			SELECT datumy2
		ENDSCAN
		USE IN datumy2
	ENDIF

	m.poraduz=dajsapcdcislo("Kasy", m.rokuct, m.mesuct,"","")
	IF m.pouctenkach
		m.menoexp="KasyPoUctenkach"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")+".xml"
	ELSE 
		m.menoexp="Kasy"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")+".xml"
	ENDIF 
	SELECT vondbf1
	COUNT TO m.assasas FOR !DELETED()
	IF m.assasas>0
		IF m.pouctenkach
			SELECT uzaverka, u_cis, SUM(ciastka) as ciastka, md, poznamka, pozn_pol, SUM(cena0) as cena0, SUM(cena5) as cena5, SUM(cena23) as cena23, SUM(dan5) as dan5, SUM(dan23) as dan23, hs_md, md2 FROM vondbf1 INTO CURSOR vondbf12 GROUP BY uzaverka, u_cis, md, poznamka, hs_md, md2 READWRITE 
		ELSE 
			SELECT m.hladajrok+m.hladajmesiac+"01" AS uzaverka, "" AS u_cis, SUM(ciastka) as ciastka, md, poznamka, pozn_pol, SUM(cena0) as cena0, SUM(cena5) as cena5, SUM(cena23) as cena23, SUM(dan5) as dan5, SUM(dan23) as dan23, hs_md, md2 FROM vondbf1 INTO CURSOR vondbf12 GROUP BY md, poznamka, hs_md, md2 READWRITE 
		ENDIF 
		m.lihandle= FCREATE(m.gcuexp_path + m.menoexp)
		IF m.lihandle > 0
			SELECT vondbf12
			IF RECCOUNT()>0
				DO poho_trz_00
				SCAN ALL 
					DO poho_trz_01
				ENDSCAN
				m.uct00='</dat:dataPack>'
				= FPUTS(m.lihandle, m.uct00)
				=FCLOSE(m.lihandle)
				IF FILE(m.gcuexp_path + m.menoexp)
					IF !EMPTY(m.uct_email_trzby)
						DO odosli_export_mailom WITH (m.gcuexp_path+m.menoexp), m.hotel_name, m.uct_email_trzby
					ENDIF
				ENDIF 
			ENDIF 
			USE IN vondbf12
			SELECT vondbf1
			SELECT vondbf1
			IF !m.archivprenosu
				SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
					IF m.issql
						m.hladajuzaverka=vondbf1.uzaverka
						m.hladajucis=vondbf1.u_cis
						=REQUERY("uexarsk")
						SELECT uexarsk
						DELETE ALL 
						=tux(.t.,.t.,"uexarsk")
					ELSE 
						SELECT uexarsk
						DELETE FOR uzaverka=vondbf1.uzaverka AND u_cis=vondbf1.u_cis
					ENDIF 
					SELECT vondbf1
				ENDSCAN
				IF m.issql
					m.hladajuzaverka="xxx"
					=REQUERY("uexarsk")
				ENDIF 
				IF m.archivovatprenosy
					SELECT uexarsk
					APPEND FROM DBF("vondbf1") FOR !storno .AND. !vymaz
					IF m.issql
						=tux(.t.,.t.,"uexarsk")
					ENDIF 
				ENDIF 
			ENDIF 
		ENDIF 
	ENDIF 
	DO pozavirej WITH "uexarsk"
	IF !m.issql
		IF f_acc_ex(m.gcdat_path+"uexarsk")
			PACK
			USE
		ENDIF
	ENDIF 
ENDIF



PROCEDURE poho_skl_00
PRIVATE m.pis_datum, m.kk
m.pis_datum=DTOC(GOMONTH(CTOD("01."+m.mesuct+"."+m.rokuct),1)-1)
* Export do POHODY - sklady
m.uct00='<?xml version="1.0" encoding="Windows-1250"?>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='<dat:dataPack version="2.0" id="In001" ico="'+ALLTRIM(m.hotel_ico)+'" application="FoodMan" note="Zaúčtovanie skladových pohybov"'
= FPUTS(m.lihandle, m.uct00)
= FPUTS(m.lihandle, 'xmlns:dat="http://www.stormware.cz/schema/version_2/data.xsd"')
= FPUTS(m.lihandle, 'xmlns:vch="http://www.stormware.cz/schema/version_2/voucher.xsd"')
= FPUTS(m.lihandle, 'xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd"')
= FPUTS(m.lihandle, 'xmlns:inv="http://www.stormware.cz/schema/version_2/invoice.xsd"')
= FPUTS(m.lihandle, 'xmlns:int="http://www.stormware.cz/schema/version_2/intDoc.xsd">')


PROCEDURE poho_skl_02
PRIVATE m.pis_datum, m.kk
* Export do POHODY - sklady
*m.uct00='	<dat:dataPackItem version="1.0" id="'+STRTRAN(STR(u_doklady1.RECNO(),3,0)," ","0")+'">'
*= FPUTS(m.lihandle, m.uct00)
m.uct00='<dat:dataPackItem version="2.0" id="'+STRTRAN(STR(RECNO("u_doklady1"),3,0)," ","0")+'">'
= FPUTS(m.lihandle, m.uct00)
m.uct00='	<int:intDoc version="2.0">'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		<int:intDocHeader>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<int:date>'+ALLTRIM(STR(YEAR(u_doklady1.datum_dokl),4,0))+'-'+STRTRAN(STR(MONTH(u_doklady1.datum_dokl),2,0)," ","0")+'-'+STRTRAN(STR(DAY(u_doklady1.datum_dokl),2,0)," ","0")+'</int:date>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<int:dateTax>'+ALLTRIM(STR(YEAR(u_doklady1.datum_dokl),4,0))+'-'+STRTRAN(STR(MONTH(u_doklady1.datum_dokl),2,0)," ","0")+'-'+STRTRAN(STR(DAY(u_doklady1.datum_dokl),2,0)," ","0")+'</int:dateTax>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<int:dateAccounting>'+ALLTRIM(STR(YEAR(u_doklady1.datum_dokl),4,0))+'-'+STRTRAN(STR(MONTH(u_doklady1.datum_dokl),2,0)," ","0")+'-'+STRTRAN(STR(DAY(u_doklady1.datum_dokl),2,0)," ","0")+'</int:dateAccounting>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<int:accounting>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='				<typ:ids>'+ALLTRIM(u_doklady1.md)+'</typ:ids>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			</int:accounting>'
= FPUTS(m.lihandle, m.uct00)
IF !EMPTY(ALLTRIM(u_doklady1.hs_md))
	m.uct00='			<int:centre>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:ids>'+ALLTRIM(u_doklady1.hs_md)+'</typ:ids>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='			</int:centre>'
	= FPUTS(m.lihandle, m.uct00)
ENDIF 
IF !EMPTY(ALLTRIM(u_doklady1.md2))
	m.uct00='			<int:activity>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:ids>'+ALLTRIM(u_doklady1.md2)+'</typ:ids>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='			</int:activity>'
	= FPUTS(m.lihandle, m.uct00)
ENDIF 
**  stredisko by mohlo zodpovedat hs_md, cinnost by mohla zodpovedat md2
m.uct00='			<int:classificationVAT>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='				<typ:classificationVATType>inland</typ:classificationVATType>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			</int:classificationVAT>'
= FPUTS(m.lihandle, m.uct00)
IF LOWER(gcuct_spec)="globalfina" AND u_doklady1.operace="PE"
	m.uct00='			<int:text>'+ALLTRIM(u_doklady1.txt)+'</int:text>'
ELSE 
	m.uct00='			<int:text>'+ALLTRIM(STRTRAN(u_doklady1.poznamka,"|",""))+'</int:text>'
ENDIF 
= FPUTS(m.lihandle, m.uct00)
m.uct00='		</int:intDocHeader>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		<int:intDocSummary>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<int:homeCurrency>'
= FPUTS(m.lihandle, m.uct00)
DO CASE
	CASE LEFT(u_doklady1.pz,2)="VR"
		m.uct00='				<typ:priceNone>'+STRTRAN(ALLTRIM(STR(-u_doklady1.castka,16,2)),",",".")+'</typ:priceNone>'
	CASE LEFT(u_doklady1.pz,2)="VP"
		m.uct00='				<typ:priceNone>'+STRTRAN(ALLTRIM(STR(-u_doklady1.castka,16,2)),",",".")+'</typ:priceNone>'
	CASE LEFT(u_doklady1.pz,2)="VK"
		m.uct00='				<typ:priceNone>'+STRTRAN(ALLTRIM(STR(-u_doklady1.castka,16,2)),",",".")+'</typ:priceNone>'
	CASE LEFT(u_doklady1.pz,2)="SD"
		m.uct00='				<typ:priceNone>'+STRTRAN(ALLTRIM(STR(-u_doklady1.castka,16,2)),",",".")+'</typ:priceNone>'
	CASE LEFT(u_doklady1.pz,2)="VE" AND LOWER(gcuct_spec)<>"globalfina"
		m.uct00='				<typ:priceNone>'+STRTRAN(ALLTRIM(STR(-u_doklady1.castka,16,2)),",",".")+'</typ:priceNone>'
	OTHERWISE 
		m.uct00='				<typ:priceNone>'+STRTRAN(ALLTRIM(STR(u_doklady1.castka,16,2)),",",".")+'</typ:priceNone>'
ENDCASE 
= FPUTS(m.lihandle, m.uct00)
m.uct00='			</int:homeCurrency>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		</int:intDocSummary>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='	</int:intDoc>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='</dat:dataPackItem>'
= FPUTS(m.lihandle, m.uct00)



PROCEDURE poho_trz_00
* Export do POHODY - trzby
m.uct00='<?xml version="1.0" encoding="Windows-1250"?>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='<dat:dataPack version="2.0" id="In001" ico="'+ALLTRIM(m.hotel_ico)+'" application="FoodMan" note="Zaúčtovanie tržieb"'
= FPUTS(m.lihandle, m.uct00)
= FPUTS(m.lihandle, 'xmlns:dat="http://www.stormware.cz/schema/version_2/data.xsd"')
= FPUTS(m.lihandle, 'xmlns:vch="http://www.stormware.cz/schema/version_2/voucher.xsd"')
= FPUTS(m.lihandle, 'xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd"')
= FPUTS(m.lihandle, 'xmlns:inv="http://www.stormware.cz/schema/version_2/invoice.xsd"')
= FPUTS(m.lihandle, 'xmlns:int="http://www.stormware.cz/schema/version_2/intDoc.xsd">')

PROCEDURE poho_trz_01
PRIVATE m.pis_datum, m.kk
m.pis_datum=DTOC(GOMONTH(CTOD("01."+m.mesuct+"."+m.rokuct),1)-1)
*m.pis_datum=SUBSTR(m.uzaverka,7,2)+"."+SUBSTR(m.uzaverka,5,2)+"."+SUBSTR(m.uzaverka,1,4)
* Export do KROSu - trzby
m.uct00='<dat:dataPackItem version="2.0" id="'+STRTRAN(STR(RECNO("vondbf12"),3,0)," ","0")+'">'
= FPUTS(m.lihandle, m.uct00)
m.uct00='	<int:intDoc version="2.0">'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		<int:intDocHeader>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<int:date>'+LEFT(vondbf12.uzaverka,4)+'-'+SUBSTR(vondbf12.uzaverka,5,2)+'-'+SUBSTR(vondbf12.uzaverka,7,2)+'</int:date>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<int:dateTax>'+LEFT(vondbf12.uzaverka,4)+'-'+SUBSTR(vondbf12.uzaverka,5,2)+'-'+SUBSTR(vondbf12.uzaverka,7,2)+'</int:dateTax>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<int:dateAccounting>'+LEFT(vondbf12.uzaverka,4)+'-'+SUBSTR(vondbf12.uzaverka,5,2)+'-'+SUBSTR(vondbf12.uzaverka,7,2)+'</int:dateAccounting>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<int:accounting>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='				<typ:ids>'+ALLTRIM(vondbf12.md)+'</typ:ids>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			</int:accounting>'
= FPUTS(m.lihandle, m.uct00)
IF !EMPTY(ALLTRIM(vondbf12.hs_md))
	m.uct00='			<int:centre>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:ids>'+ALLTRIM(vondbf12.hs_md)+'</typ:ids>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='			</int:centre>'
	= FPUTS(m.lihandle, m.uct00)
ENDIF 
IF !EMPTY(ALLTRIM(vondbf12.md2))
	m.uct00='			<int:activity>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:ids>'+ALLTRIM(vondbf12.md2)+'</typ:ids>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='			</int:activity>'
	= FPUTS(m.lihandle, m.uct00)
ENDIF 
**  stredisko by mohlo zodpovedat hs_md, cinnost by mohla zodpovedat md2
m.uct00='			<int:classificationVAT>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='				<typ:classificationVATType>inland</typ:classificationVATType>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			</int:classificationVAT>'
= FPUTS(m.lihandle, m.uct00)
IF m.pouctenkach
	m.uct00='			<int:text>'+vondbf12.uzaverka+' '+vondbf12.u_cis+'</int:text>'
ELSE
	m.uct00='			<int:text>'+ALLTRIM(STRTRAN(vondbf12.poznamka,"|",""))+'</int:text>'
ENDIF 
= FPUTS(m.lihandle, m.uct00)
m.uct00='		</int:intDocHeader>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		<int:intDocSummary>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<int:homeCurrency>'
= FPUTS(m.lihandle, m.uct00)
IF "Platba"$vondbf12.poznamka
	m.uct00='				<typ:priceNone>'+STRTRAN(ALLTRIM(STR(vondbf12.ciastka,16,2)),",",".")+'</typ:priceNone>'
	= FPUTS(m.lihandle, m.uct00)
ELSE 
	m.uct00='				<typ:priceNone>'+STRTRAN(ALLTRIM(STR(vondbf12.cena0,16,2)),",",".")+'</typ:priceNone>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:priceLow>'+STRTRAN(ALLTRIM(STR(vondbf12.cena5,16,2)),",",".")+'</typ:priceLow>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:priceLowVAT>'+STRTRAN(ALLTRIM(STR(vondbf12.dan5,16,2)),",",".")+'</typ:priceLowVAT>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:priceLowSum>'+STRTRAN(ALLTRIM(STR(vondbf12.cena5+vondbf12.dan5,16,2)),",",".")+'</typ:priceLowSum>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:priceHigh>'+STRTRAN(ALLTRIM(STR(vondbf12.cena23,16,2)),",",".")+'</typ:priceHigh>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:priceHighVAT>'+STRTRAN(ALLTRIM(STR(vondbf12.dan23,16,2)),",",".")+'</typ:priceHighVAT>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:priceHighSum>'+STRTRAN(ALLTRIM(STR(vondbf12.cena23+vondbf12.dan23,16,2)),",",".")+'</typ:priceHighSum>'
	= FPUTS(m.lihandle, m.uct00)
ENDIF 
m.uct00='			</int:homeCurrency>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		</int:intDocSummary>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='	</int:intDoc>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='</dat:dataPackItem>'
= FPUTS(m.lihandle, m.uct00)


PROCEDURE poho_fakt_00
PRIVATE m.pis_datum, m.kk
m.pis_datum=DTOC(GOMONTH(CTOD("01."+m.mesuct+"."+m.rokuct),1)-1)
* Export do POHODY - faktury
m.uct00='<?xml version="1.0" encoding="Windows-1250"?>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='<dat:dataPack version="2.0" id="fa002" ico="'+ALLTRIM(m.hhotel_ico)+'" application="FoodMan" note="Import faktúr"'
= FPUTS(m.lihandle, m.uct00)
= FPUTS(m.lihandle, 'xmlns:dat="http://www.stormware.cz/schema/version_2/data.xsd"')
= FPUTS(m.lihandle, 'xmlns:vch="http://www.stormware.cz/schema/version_2/voucher.xsd"')
= FPUTS(m.lihandle, 'xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd"')
= FPUTS(m.lihandle, 'xmlns:inv="http://www.stormware.cz/schema/version_2/invoice.xsd"')
= FPUTS(m.lihandle, 'xmlns:int="http://www.stormware.cz/schema/version_2/intDoc.xsd">')


		

PROCEDURE poho_fakt_02
PRIVATE m.pis_datum, m.kk
LOCAL m.partnerico
* Export do POHODY - faktury
m.uct00='<dat:dataPackItem version="2.0" id="'+STRTRAN(STR(RECNO("datumy"),3,0)," ","0")+'">'
= FPUTS(m.lihandle, m.uct00)
m.uct00='	<inv:invoice version="2.0">'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		<inv:invoiceHeader>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<inv:invoiceType>issuedInvoice</inv:invoiceType>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<inv:number>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='				<typ:numberRequested>'+STRTRAN(doklady.pz2," ","")+'</typ:numberRequested>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			</inv:number>'
= FPUTS(m.lihandle, m.uct00)

m.uct00='			<inv:symVar>'+STRTRAN(doklady.pz2," ","")+'</inv:symVar>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<inv:date>'+ALLTRIM(STR(YEAR(u_doklady1.datum_dokl),4,0))+'-'+STRTRAN(STR(MONTH(u_doklady1.datum_dokl),2,0)," ","0")+'-'+STRTRAN(STR(DAY(u_doklady1.datum_dokl),2,0)," ","0")+'</inv:date>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<inv:dateTax>'+ALLTRIM(STR(YEAR(u_doklady1.datum_dokl),4,0))+'-'+STRTRAN(STR(MONTH(u_doklady1.datum_dokl),2,0)," ","0")+'-'+STRTRAN(STR(DAY(u_doklady1.datum_dokl),2,0)," ","0")+'</inv:dateTax>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<inv:dateAccounting>'+ALLTRIM(STR(YEAR(u_doklady1.datum_dokl),4,0))+'-'+STRTRAN(STR(MONTH(u_doklady1.datum_dokl),2,0)," ","0")+'-'+STRTRAN(STR(DAY(u_doklady1.datum_dokl),2,0)," ","0")+'</inv:dateAccounting>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<inv:dateDue>'+ALLTRIM(STR(YEAR(u_doklady1.datum_dokl+partneri.splatnost),4,0))+'-'+STRTRAN(STR(MONTH(u_doklady1.datum_dokl+partneri.splatnost),2,0)," ","0")+'-'+STRTRAN(STR(DAY(u_doklady1.datum_dokl+partneri.splatnost),2,0)," ","0")+'</inv:dateDue>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<inv:accounting>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='				<typ:ids>'+ALLTRIM(u_doklady1.md)+'</typ:ids>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			</inv:accounting>'
= FPUTS(m.lihandle, m.uct00)
IF !EMPTY(ALLTRIM(u_doklady1.hs_md))
	m.uct00='			<inv:centre>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:ids>'+ALLTRIM(u_doklady1.hs_md)+'</typ:ids>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='			</inv:centre>'
	= FPUTS(m.lihandle, m.uct00)
ENDIF 
m.uct00='			<inv:classificationVAT>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='				<typ:classificationVATType>inland</typ:classificationVATType>'
= FPUTS(m.lihandle, m.uct00)
IF !EMPTY(m.pohoda_fa_clen_dph)
	m.uct00='				<typ:ids>'+m.pohoda_fa_clen_dph+'</typ:ids>'
	= FPUTS(m.lihandle, m.uct00)
ENDIF 
m.uct00='			</inv:classificationVAT>'
= FPUTS(m.lihandle, m.uct00)
IF !EMPTY(m.pohoda_fa_kvdph)
	m.uct00='			<inv:classificationKVDPH>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='				<typ:ids>'+m.pohoda_fa_kvdph+'</typ:ids>'
	= FPUTS(m.lihandle, m.uct00)
	m.uct00='			</inv:classificationKVDPH>'
	= FPUTS(m.lihandle, m.uct00)
ENDIF 
m.uct00='			<inv:text>Fakturujeme Vám za dodaný tovar podľa Vašej objednávky:</inv:text>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<inv:partnerIdentity>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='				<typ:address>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:company>'+STRTRAN(ALLTRIM(partneri.fmeno),"&","&amp;")+'</typ:company>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:city>'+STRTRAN(ALLTRIM(partneri.fmesto),"&","&amp;")+'</typ:city>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:zip>'+ALLTRIM(partneri.fpsc)+'</typ:zip>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:street>'+STRTRAN(ALLTRIM(partneri.fulica),"&","&amp;")+'</typ:street>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:ico>'+ALLTRIM(partneri.ico)+'</typ:ico>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:dic>'+ALLTRIM(partneri.dic)+'</typ:dic>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:icDph>'+ALLTRIM(partneri.icdph)+'</typ:icDph>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='				</typ:address>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='				<typ:shipToAddress>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:company>'+STRTRAN(ALLTRIM(partneri.fmeno),"&","&amp;")+'</typ:company>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:street>'+STRTRAN(ALLTRIM(partneri.naz1),"&","&amp;")+'</typ:street>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:city>'+STRTRAN(ALLTRIM(partneri.naz2),"&","&amp;")+'</typ:city>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:zip>'+ALLTRIM(partneri.naz3)+'</typ:zip>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:division>'+ALLTRIM(partneri.naz4)+'</typ:division>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='					<typ:name>'+ALLTRIM(partneri.partner)+'</typ:name>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='				</typ:shipToAddress>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			</inv:partnerIdentity>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='			<inv:numberOrder>'+m.cislo_objednavky+'</inv:numberOrder>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		</inv:invoiceHeader>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		<inv:invoiceDetail>'
= FPUTS(m.lihandle, m.uct00)
IF EMPTY(m.hladajidediprev) AND !("sushitime"$LOWER(m.wi_zakaz))
	SELECT u_doklady1
	SCAN ALL 
		m.uct00='				<inv:invoiceItem>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					<inv:text>Položka</inv:text>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					<inv:quantity>1</inv:quantity>'
		= FPUTS(m.lihandle, m.uct00)
		DO CASE 
			CASE u_doklady1.dan=1
				m.uct00='					<inv:rateVAT>none</inv:rateVAT>'
			CASE u_doklady1.dan=m.uctdphlo
				m.uct00='					<inv:rateVAT>low</inv:rateVAT>'
			OTHERWISE 
				m.uct00='					<inv:rateVAT>high</inv:rateVAT>'
		ENDCASE 
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					<inv:homeCurrency>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='						<typ:unitPrice>'+STRTRAN(ALLTRIM(STR(-u_doklady1.castka,12,2)),",",".")+'</typ:unitPrice>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='						<typ:price>'+STRTRAN(ALLTRIM(STR(-u_doklady1.castka,12,2)),",",".")+'</typ:price>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='						<typ:priceVAT>'+STRTRAN(ALLTRIM(STR(-(ROUND(u_doklady1.castka*u_doklady1.dan,2)-u_doklady1.castka),12,2)),",",".")+'</typ:priceVAT>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='						<typ:priceSum>'+STRTRAN(ALLTRIM(STR(ROUND(-u_doklady1.castka*u_doklady1.dan,2),12,2)),",",".")+'</typ:priceSum>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					</inv:homeCurrency>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					<inv:accounting>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='						<typ:ids>'+ALLTRIM(u_doklady1.md)+'</typ:ids>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					</inv:accounting>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					<inv:classificationVAT>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='						<typ:classificationVATType>inland</typ:classificationVATType>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					</inv:classificationVAT>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='				</inv:invoiceItem>'
		= FPUTS(m.lihandle, m.uct00)
		IF u_doklady1.spdan<>0
			m.uct00='				<inv:invoiceItem>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='					<inv:text>Spotrebná daň</inv:text>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='					<inv:quantity>1</inv:quantity>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='					<inv:homeCurrency>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='						<typ:unitPrice>'+STRTRAN(ALLTRIM(STR(u_doklady1.spdan,12,2)),",",".")+'</typ:unitPrice>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='						<typ:price>'+STRTRAN(ALLTRIM(STR(u_doklady1.spdan,12,2)),",",".")+'</typ:price>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='						<typ:priceVAT>'+STRTRAN(ALLTRIM(STR(0,2,0)),",",".")+'</typ:priceVAT>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='						<typ:priceSum>'+STRTRAN(ALLTRIM(STR(u_doklady1.spdan,12,2)),",",".")+'</typ:priceSum>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='					</inv:homeCurrency>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='					<inv:accounting>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='						<typ:ids>'+ALLTRIM(u_doklady1.dal)+'</typ:ids>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='					</inv:accounting>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='					<inv:classificationVAT>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='						<typ:classificationVATType>inland</typ:classificationVATType>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='					</inv:classificationVAT>'
			= FPUTS(m.lihandle, m.uct00)
			m.uct00='				</inv:invoiceItem>'
			= FPUTS(m.lihandle, m.uct00)
		ENDIF 
	ENDSCAN
ELSE
	SELECT dokladxx
	PRIVATE m.serial_no, m.hladajckarty
	m.partnerico=ALLTRIM(partneri.ico)
	SCAN ALL 
		m.hladajckarty=dokladxx.c_karty
		IF USED("dodean")
			=REQUERY("dodean")
		ELSE
			IF m.issql
				USE (m.sqlprefix+"reanykukarte") ALIAS dodean IN 0
			ELSE 
				USE veanykukarte ALIAS dodean IN 0
			ENDIF 
		ENDIF 
		SELECT dodean
		IF RECCOUNT()>0
			m.dlzkaica=LEN(ALLTRIM(m.partnerico))
			IF m.dlzkaica>0
				LOCATE FOR LEFT(dodean.ean,m.dlzkaica+2)=ALLTRIM(m.partnerico)+"::"
				IF FOUND()
					m.serial_no=ALLTRIM(SUBSTR(dodean.ean,m.dlzkaica+3))
				ELSE
					IF EMPTY(dokladxx.serial_no)
						GO TOP 
						m.serial_no=ALLTRIM(dodean.ean)
					ELSE
						m.serial_no=ALLTRIM(dokladxx.serial_no)
					ENDIF 
				ENDIF 
			ELSE
				IF EMPTY(dokladxx.serial_no)
					m.serial_no=""
				ELSE
					m.serial_no=ALLTRIM(dokladxx.serial_no)
				ENDIF 
			ENDIF 
		ELSE
			IF EMPTY(dokladxx.serial_no)
				m.serial_no=""
			ELSE
				m.serial_no=ALLTRIM(dokladxx.serial_no)
			ENDIF 
		ENDIF 
		m.uct00='				<inv:invoiceItem>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					<inv:text>'+ALLTRIM(dokladxx.nazev)+' '+ALLTRIM(m.serial_no)+'</inv:text>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					<inv:quantity>'+STRTRAN(ALLTRIM(STR(-dokladxx.mnozstvi,10,2)),",",".")+'</inv:quantity>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					<inv:unit>'+RIGHT(ALLTRIM(dokladxx.nazev),3)+'</inv:unit>'
		= FPUTS(m.lihandle, m.uct00)
		DO CASE 
			CASE u_doklady1.dan=1
				m.uct00='					<inv:rateVAT>none</inv:rateVAT>'
			CASE u_doklady1.dan=m.uctdphlo
				m.uct00='					<inv:rateVAT>low</inv:rateVAT>'
			OTHERWISE 
				m.uct00='					<inv:rateVAT>high</inv:rateVAT>'
		ENDCASE 
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					<inv:homeCurrency>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='						<typ:unitPrice>'+STRTRAN(ALLTRIM(STR(dokladxx.cena_part,12,2)),",",".")+'</typ:unitPrice>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='						<typ:price>'+STRTRAN(ALLTRIM(STR(-dokladxx.cena_part*dokladxx.mnozstvi,12,2)),",",".")+'</typ:price>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='						<typ:priceVAT>'+STRTRAN(ALLTRIM(STR(ROUND(-dokladxx.cena_part*dokladxx.mnozstvi*(dokladxx.dan-1),2), 12, 2)),",",".")+'</typ:priceVAT>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='						<typ:priceSum>'+STRTRAN(ALLTRIM(STR(ROUND(-dokladxx.cena_part*dokladxx.mnozstvi*dokladxx.dan,2), 12, 2)),",",".")+'</typ:priceSum>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					</inv:homeCurrency>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					<inv:classificationVAT>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='						<typ:classificationVATType>inland</typ:classificationVATType>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='					</inv:classificationVAT>'
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='				</inv:invoiceItem>'
		= FPUTS(m.lihandle, m.uct00)
	ENDSCAN
ENDIF 
m.uct00='			</inv:invoiceDetail>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		</inv:invoice>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='	</dat:dataPackItem>'
= FPUTS(m.lihandle, m.uct00)


PROCEDURE kontrola_faktur
SELECT DISTINCT datum FROM u_doklady INTO CURSOR datumy READWRITE 
*** Kontrola dokladov v exporte na ich stav v uexfakt ***
*
SCAN ALL
	m.oprava=.F.
	SELECT u_doklady
	SCAN FOR datum=datumy.datum
		SELECT uexarch
		LOCATE FOR operace="FA" AND ALLTRIM(datum)=ALLTRIM(u_doklady.datum) .AND. id_man=u_doklady.id_man .AND. castka=u_doklady.castka .AND. ALLTRIM(MD)=ALLTRIM(u_doklady.MD) .AND. ALLTRIM(dal)=ALLTRIM(u_doklady.dal) .AND. ALLTRIM(md2)=ALLTRIM(u_doklady.md2) .AND. ALLTRIM(dal2)=ALLTRIM(u_doklady.dal2) ;
			.AND. ALLTRIM(hs_md)=ALLTRIM(u_doklady.hs_md) .AND. ALLTRIM(hs_dal)=ALLTRIM(u_doklady.hs_dal) .AND. ALLTRIM(pz)=ALLTRIM(u_doklady.pz) .AND. ALLTRIM(partner)=ALLTRIM(u_doklady.partner) .AND. ALLTRIM(doklad)=ALLTRIM(u_doklady.doklad) .AND. datum_dokl=u_doklady.datum_dokl .AND. ALLTRIM(poznamka)=ALLTRIM(u_doklady.poznamka) .AND. ALLTRIM(faktura)=ALLTRIM(u_doklady.faktura)
		IF !FOUND()
			m.oprava=.T.
		ENDIF
		SELECT u_doklady
	ENDSCAN
	IF m.oprava
		SELECT uexarch
		SCAN FOR datum=datumy.datum
			INSERT INTO u_doklady (datum,id_man,castka,MD,dal,md2,dal2,hs_md,hs_dal,pz,partner,doklad,datum_dokl,poznamka,storno, faktura, dph);
				VALUES (uexarch.datum,uexarch.id_man,-uexarch.castka,uexarch.MD,uexarch.dal,uexarch.md2,uexarch.dal2,uexarch.hs_md,uexarch.hs_dal,uexarch.pz,uexarch.partner,uexarch.doklad,uexarch.datum_dokl,uexarch.poznamka,.T., uexarch.faktura, uexarch.dph)
		ENDSCAN
	ELSE
		SELECT u_doklady
		DELETE FOR datum=datumy.datum
	ENDIF
	SELECT datumy
ENDSCAN
*
*** Kontrola dokladov v exporte na ich stav v uexarch ***
*** Hladanie dokladov z uexarch, ktore uz neexistuju a treba ich stornovat v exporte ***
*
IF USED("stred01") 
	IF m.issql
		USE (m.sqlprefix+"ruzaverka") IN 0 ALIAS expuzav
		SELECT expuzav
		INDEX on rok+mesiac TAG kedy
	ELSE 
		USE (m.gcdat_path+"uzaverka") AGAIN IN 0 ALIAS expuzav ORDER kedy
	ENDIF 
	SELECT stred01
	SCAN FOR LABEL
		m.dokluzod=0
		m.dokluzdo=0
		SELECT expuzav
		SET FILTER TO c_stredisk=stred01.c_stredisk
		SCAN FOR (expuzav.rok+expuzav.mesiac)<=(m.rokuct+m.mesuct)
			DO CASE
				CASE (expuzav.rok+expuzav.mesiac)<(m.rokuct+m.mesuct)
					m.dokluzod=expuzav.c_dokldo
				CASE (expuzav.rok+expuzav.mesiac)=(m.rokuct+m.mesuct)
					m.dokluzdo=expuzav.c_dokldo
			ENDCASE
		ENDSCAN
		SELECT DISTINCT datum FROM uexarch WHERE operace="FA" AND id_man=stred01.ID .AND. VAL(datum)>m.dokluzod .AND. VAL(datum)<=m.dokluzdo .AND. !(datum IN (SELECT DISTINCT datum FROM datumy));
			INTO CURSOR datumy2 READWRITE 
		SCAN ALL
			SELECT uexarch
			SCAN FOR datum=datumy2.datum AND operace="FA"
				INSERT INTO u_doklady (datum,id_man,castka,MD,dal,md2,dal2,hs_md,hs_dal,pz,partner,doklad,datum_dokl,poznamka,storno,vymaz,faktura);
					VALUES (uexarch.datum,uexarch.id_man,-uexarch.castka,uexarch.MD,uexarch.dal,uexarch.md2,uexarch.dal2,uexarch.hs_md,uexarch.hs_dal,uexarch.pz,uexarch.partner,uexarch.doklad,uexarch.datum_dokl,uexarch.poznamka,.F.,.T., uexarch.faktura)
			ENDSCAN
			SELECT datumy2
		ENDSCAN
		USE IN datumy2
		SELECT expuzav
		SET FILTER TO
		SELECT stred01
	ENDSCAN
	USE IN expuzav
ENDIF
*
*** Hladanie dokladov z uexarch, ktore uz neexistuju a treba ich stornovat v exporte ***
USE IN datumy


PROCEDURE gen_exp_rero
PARAMETERS kontroluj,rokuct,mesuct
PRIVATE old_century,menoexp,oldsetdate,oldsetdele, riadkov, sumacelk,dokluzod,dokluzdo,prijemky, vydajky, ok
PRIVATE bolipartneri, part_order
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.rokuct
m.hladajmesiac=m.mesuct
IF USED("partneri")
	m.bolipartneri=.t.
	SELECT partneri
	m.part_order=SET("order")
	IF " OF "$UPPER(part_order)
		m.part_order=LEFT(m.part_order,AT(" OF ",UPPER(m.part_order))-1)
	ENDIF 
	SET ORDER TO partner
ELSE
	IF m.issql
		USE (m.sqlprefix+"rpartneriucto") IN 0 ALIAS partner
		SELECT partner
		INDEX on partner TAG partner
	ELSE 
		USE (m.fn_partneri) ALIAS partneri IN 0 ORDER partner
	ENDIF 
	m.bolipartneri=.f.
	m.part_order=""
ENDIF 
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
m.old_century=SET("century")
m.oldsetdate=SET("date")
m.oldsetdele=SET("dele")
SET DATE TO GERMAN
SET DELETED ON
m.gcuexp_path=ALLTRIM(IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path))
IF ! DIRECTORY(m.gcuexp_path)
	MKDIR (m.gcuexp_path)
ENDIF
SET CENTURY ON
gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
gen_exp_had.SHOW()
gen_exp_had.set_max(20)
gen_exp_had.INCREMENT("Sklady")
IF USED("u_ex_obraty")
	SELECT operace, datum, id_man, SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka,faktura,.F. AS storno,.F. AS vymaz,SPACE(m.sirkastlpcadruh) as druh FROM u_ex_obraty GROUP BY id_man,pz,datum,doklad,datum_dokl,MD,dal INTO CURSOR u_doklady WHERE INLIST(LEFT(pz,1),"P","V") READWRITE 
	REPLACE ALL druh WITH SUBSTR(pz,AT("|",pz,1)+1,10)
	DELETE FOR EMPTY(datum)
	DELETE FOR EMPTY(MD)
	SELECT u_doklady
	SELECT 0
	IF m.issql
		USE (m.sqlprefix+"ruexarchobraty_mesiacrok") ALIAS uexarch IN 0
	ELSE 
		IF !FILE(m.gccen_path+"uexarchobraty.dbf")
			DO creafile WITH (m.gccen_path+"uexarchobraty.dbf")
		ENDIF 
		IF !USED("uexarchobraty")
			USE (m.gccen_path+"uexarchobraty") IN 0
		ENDIF 
		USE vuexarchobraty_mesiacrok IN 0 ALIAS uexarch
	ENDIF 
	=CURSORSETPROP("Buffering",5,"uexarch")
	IF m.kontroluj
		DO kontrola_skladov
	ELSE
		SELECT 0
		IF m.issql
			USE (m.sqlprefix+"ruzaverka") ALIAS expuzav
			INDEX on rok+mesiac TAG kedy
		ELSE 
			USE (m.gcdat_path+"uzaverka") AGAIN ALIAS expuzav ORDER kedy
		ENDIF 
		SET FILTER TO c_stredisk=m.gic_stredisk
		GO BOTTOM
		m.rokuct=expuzav.rok
		m.mesuct=expuzav.mesiac
		IF EMPTY(m.rokuct) .OR. EMPTY(m.mesuct)
			m.rokuct=STR(YEAR(DATE()),4,0)
			m.mesuct=STRTRAN(STR(MONTH(DATE()),2,0)," ","0")
		ELSE
			m.mesuct=STRTRAN(STR(VAL(m.mesuct)+1,2,0)," ","0")
			IF m.mesuct="13"
				m.mesuct="01"
				m.rokuct=STR(VAL(m.rokuct)+1,4,0)
			ENDIF
		ENDIF
		USE IN expuzav
	ENDIF

	SELECT u_doklady
	DELETE FOR castka=0
	IF m.issql
		USE (m.sqlprefix+"rdoklady") IN 0 ALIAS doklady
		SELECT doklady
		INDEX on c_dokl TAG c_dokl
	ELSE 
		IF !USED("doklady")
			USE (m.fn_doklady) ALIAS doklady AGAIN IN 0 ORDER c_dokl
		ELSE
			SELECT doklady
			SET ORDER TO c_dokl
		ENDIF
	ENDIF 
	m.poraduz=dajsapcdcislo("Food",m.rokuct, m.mesuct,"","")
	m.menoexp="Food"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")+".xml"

	SELECT u_doklady
	COUNT FOR !DELETED() TO assasas
	SELECT id_man,datum,SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,doklad,datum_dokl,poznamka,faktura,druh FROM u_doklady GROUP BY id_man,datum,MD, dal, hs_md, hs_dal, md2, dal2, pz INTO CURSOR u_doklady1 ORDER BY id_man, pz READWRITE  

	IF RECCOUNT()>0
		SELECT 0
		IF FILE(m.gcuexp_path+m.menoexp)
			ERASE(m.gcuexp_path+m.menoexp)
		ENDIF
		m.lihandle= FCREATE(m.gcuexp_path + m.menoexp)
		IF m.lihandle > 0
			m.uct00=""
			m.dotextu="Sklad"
			DO rero_skl_00
			SELECT u_doklady1
			SCAN FOR LOWER(ALLTRIM(MD))<>"export" .and. castka<>0
				DO rero_skl_02
			ENDSCAN
			m.uct00='</DATA>'
			= FPUTS(m.lihandle, m.uct00)
			=FCLOSE(m.lihandle)
			SELECT u_doklady
			SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
				SELECT uexarch
				DELETE FOR datum=u_doklady.datum
				SELECT u_doklady
			ENDSCAN
			SELECT u_doklady
			SELECT uexarch
			APPEND FROM DBF("u_doklady") FOR !storno .AND. !vymaz
			REPLACE ALL mesiac WITH m.mesuct FOR mesiac<>m.mesuct
			REPLACE ALL rok WITH m.rokuct FOR rok<>m.rokuct
			=tux(.t.,.t.,"uexarch")
			DO pozavirej WITH "uexarch, uexarchobraty"
			IF !m.issql
				IF f_acc_ex(m.gcdat_path+"uexarchobraty")
					PACK
					USE
				ENDIF
			ENDIF 
		ENDIF
	ENDIF 
	DO pozavirej WITH "uexarch, uexarchobraty, u_doklady, u_doklady1, u_ex_obraty"
	IF m.bolipartneri
		SELECT partneri
		SET ORDER TO &part_order
	ELSE
		USE IN partneri
	ENDIF 
ENDIF 
*** Trzby ***
IF m.gcuct_trzba AND USED("u_ex_platby") AND USED("u_ex_polozky")
	gen_exp_had.INCREMENT("Tržby")
	m.poraduz=dajsapcdcislo("Kasy",m.rokuct, m.mesuct,"","")
	m.menoexp="Kasy"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")+".xml"
	SELECT SUM(castka) AS ciastka, MD,dal,md2,dal2,hs_dal,hs_md,partner,pz, poznamka, $0 AS celkom, 1.000000000 AS koef FROM u_ex_platby GROUP BY pz,poznamka,MD,dal INTO CURSOR u_doklady READWRITE 
	SELECT SUM(castka) AS ciastka, pz FROM u_ex_platby GROUP BY pz INTO CURSOR u_platby  READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	SELECT u_doklady
	SET RELATION TO ALLTRIM(pz) INTO u_platby
	REPLACE ALL u_doklady.celkom WITH u_platby.ciastka
	SET RELATION OFF INTO u_platby
	USE IN u_platby
	REPLACE ALL koef WITH IIF(celkom=0,1,ciastka/celkom)
	SELECT SUM(castka) AS ciastka, MD,dal,hs_md, hs_dal,md2,dal2, pz, partner,poznamka,$0 AS danzakl, $0 AS dan FROM u_ex_polozky GROUP BY pz,poznamka,MD,dal INTO CURSOR u_dokl1 READWRITE 
	SELECT u_dokl1
	REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
	REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka FROM u_dokl1 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl2 READWRITE 
	USE IN u_dokl1
	REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
	SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2,poznamka FROM u_dokl2 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	USE IN u_dokl2
	SELECT u_doklady
	IF !prazdna()
		m.gcuexp_path = ALLTRIM(m.gcuexp_path)
		IF ! DIRECTORY(m.gcuexp_path)
			MKDIR (m.gcuexp_path)
		ENDIF
		SELECT SPACE(17) AS uzaverka,ciastka, MD,dal,md2,dal2,hs_dal,hs_md,poznamka, celkom, $0 AS danzakl, $0 AS dan, ;
			SPACE(5) AS sadzba FROM u_doklady INTO  CURSOR vondbf WHERE .f.
		SELECT u_doklady
		SCAN FOR !EMPTY(u_doklady.MD) .AND. !EMPTY(u_doklady.dal) .AND. u_doklady.ciastka<>0
			SELECT u_dokl
			SCAN FOR pz=u_doklady.pz .AND. !EMPTY(u_dokl.MD) .AND. !EMPTY(u_dokl.dal)
				IF u_doklady.MD=u_dokl.dal
					INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba) VALUES ;
						(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_dokl.MD,u_doklady.dal,u_dokl.md2,u_doklady.dal2,u_dokl.hs_md,u_doklady.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka)
				ELSE
					IF u_doklady.dal=u_dokl.MD
						INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba) VALUES ;
							(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_doklady.MD,u_dokl.dal,u_dokl.md2,u_dokl.dal2,u_dokl.hs_md,u_dokl.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka)
					ENDIF
				ENDIF
			ENDSCAN
			SELECT u_doklady
		ENDSCAN
		SELECT uzaverka,SUM(ciastka) AS ciastka,MD,dal,md2,dal2,hs_md,hs_dal, SUM(danzakl) AS danzakl, SUM(dan) AS dan, sadzba FROM vondbf ;
			GROUP BY uzaverka, MD, dal, sadzba INTO CURSOR vondbf2 READWRITE 
		SELECT uzaverka, SUM(ciastka) AS ciastka,MD,dal,md2,dal2,hs_md,hs_dal, 0000000000.00 AS cena0, 0000000000.00 AS cena5, 0000000000.00 AS cena23, 000000000.00 AS dan5, 000000000.00 AS dan23,.F. AS vymaz,.F. AS storno FROM vondbf ;
			GROUP BY uzaverka, MD, dal INTO CURSOR vondbf1 READWRITE 
		m.riadkov=1
		SCAN ALL
			SELECT vondbf2
			SCAN FOR MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. uzaverka=vondbf1.uzaverka
				DO CASE
					CASE ALLTRIM(sadzba)="0"
						REPLACE vondbf1.cena0 WITH vondbf2.danzakl
					CASE ALLTRIM(sadzba)=ALLTRIM(STR((m.uctdphlo-1)*100,10,0))
						REPLACE vondbf1.cena5 WITH vondbf2.danzakl, vondbf1.dan5 WITH vondbf2.dan
					OTHERWISE
						REPLACE vondbf1.cena23 WITH vondbf2.danzakl, vondbf1.dan23 WITH vondbf2.dan
				ENDCASE
			ENDSCAN
		ENDSCAN
		IF !m.issql
			IF FILE(m.gcdat_path+"uexarsk.dbf")
				SELECT 0
				USE (m.gcdat_path+"uexarsk.dbf")
			ELSE
				SELECT vondbf1
				COPY STRUCTURE TO (m.gcdat_path+"uexarsk.dbf")
				SELECT 0
				USE (m.gcdat_path+"uexarsk.dbf")
			ENDIF
		ENDIF 
		IF m.kontroluj
			SELECT DISTINCT uzaverka FROM vondbf1 INTO CURSOR datumy READWRITE 
			SCAN ALL
				m.hladajuzaverka=datumy.uzaverka
				m.oprava=0
				SELECT vondbf1
				SCAN FOR uzaverka=datumy.uzaverka
					IF m.issql
						IF USED("uexarsk")
							=REQUERY("uexarsk")
						ELSE
							USE (m.sqlprefix+"ruexarsk") ALIAS uexarsk IN 0
							=CURSORSETPROP("Buffering",5,"uexarsk")
						ENDIF 
					ENDIF 
					SELECT uexarsk
					LOCATE FOR uzaverka=vondbf1.uzaverka
					IF FOUND()
						LOCATE FOR uzaverka=vondbf1.uzaverka .AND. ciastka=vondbf1.ciastka .AND. MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. cena0=vondbf1.cena0 .AND. cena5=vondbf1.cena5 ;
							.AND. cena23=vondbf1.cena23 .AND. dan5=vondbf1.dan5 .AND. dan23=vondbf1.dan23 .AND. hs_md=vondbf1.hs_md .AND. hs_dal=vondbf1.hs_dal
						IF !FOUND()
							m.oprava=2
						ELSE
							m.oprava=1
						ENDIF
					ELSE
						m.oprava=0
					ENDIF
					SELECT vondbf1
					IF m.oprava=2
						EXIT
					ENDIF
				ENDSCAN
				DO CASE
					CASE m.oprava=2
						SELECT uexarsk
						SCAN FOR uzaverka=datumy.uzaverka
							INSERT INTO vondbf1 (uzaverka,ciastka,MD,dal,hs_md, hs_dal,md2,dal2,cena0,cena5,cena23,dan5,dan23,storno);
								VALUES (uexarsk.uzaverka,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,uexarsk.md2,uexarsk.dal2,-uexarsk.cena0,-uexarsk.cena5,;
								-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.T.)
						ENDSCAN
					CASE m.oprava=1
						SELECT vondbf1
						DELETE FOR uzaverka=datumy.uzaverka
				ENDCASE
				SELECT datumy
			ENDSCAN
			IF m.issql
				USE (m.sqlprefix+"ruexarsk_zoznam_uzavierok") ALIAS uexzoznam IN 0
				SELECT DISTINCT uzaverka FROM uexzoznam WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
					INTO CURSOR datumy2 READWRITE 
				USE IN uexzoznam
			ELSE 
				SELECT DISTINCT uzaverka FROM uexarsk WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
					INTO CURSOR datumy2 READWRITE 
			ENDIF 
			SCAN ALL
				m.hladajuzaverka=datumy2.uzaverka
				IF m.issql
					=REQUERY("uexarsk")
				ENDIF 
				SELECT uexarsk
				SCAN FOR uzaverka=datumy2.uzaverka
					INSERT INTO vondbf1 (uzaverka,ciastka,MD,dal,hs_md, hs_dal,cena0,cena5,cena23,dan5,dan23,storno,vymaz);
						VALUES (uexarsk.uzaverka,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,-uexarsk.cena0,-uexarsk.cena5,;
						-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.F.,.T.)
				ENDSCAN
				SELECT datumy2
			ENDSCAN
			USE IN datumy2
		ENDIF
		SELECT vondbf1
		m.lihandle= FCREATE(m.gcuexp_path + m.menoexp)
		IF m.lihandle > 0
			SELECT vondbf1
			IF RECCOUNT()>0
				DO rero_trz_00
				SCAN ALL 
					DO rero_trz_01
				ENDSCAN
				m.uct00='</DATA>'
				= FPUTS(m.lihandle, m.uct00)
				=FCLOSE(m.lihandle)
			ENDIF 
		ENDIF 
		SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
			IF m.issql
				m.hladajuzaverka=vondbf1.uzaverka
				=REQUERY("uexarsk")
				SELECT uexarsk
				DELETE ALL 
				=tux(.t.,.t.,"uexarsk")
			ELSE 
				SELECT uexarsk
				DELETE FOR uzaverka=vondbf1.uzaverka
			ENDIF 
			SELECT vondbf1
		ENDSCAN
		IF m.issql
			m.hladajuzaverka="xxx"
			=REQUERY("uexarsk")
		ENDIF 
		SELECT uexarsk
		APPEND FROM DBF("vondbf1") FOR !storno .AND. !vymaz
		IF m.issql
			=tux(.t.,.t.,"uexarsk")
		ENDIF 
		DO pozavirej WITH "uexarsk"
		IF !m.issql
			IF f_acc_ex(m.gcdat_path+"uexarsk")
				PACK
				USE
			ENDIF
		ENDIF 
	ENDIF
	SET CENTURY &old_century
	SET DATE &oldsetdate
	SET DELETED &oldsetdele
	DO pozavirej WITH "vondbf, u_doklady, u_dokl, vondbf1, vondbf2, datumy, u_ex_platby, u_ex_polozky"
ENDIF
RELEASE gen_exp_had
RETURN



PROCEDURE rero_skl_00
PRIVATE m.pis_datum, m.kk
m.pis_datum=DTOC(GOMONTH(CTOD("01."+m.mesuct+"."+m.rokuct),1)-1)
* Export do RERO - sklady
m.uct00='<?xml version="1.0" encoding="Windows-1250"?>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='<DATA>'
= FPUTS(m.lihandle, m.uct00)


PROCEDURE rero_skl_02
PRIVATE m.pis_datum, m.kk
* Export do RERO - sklady
*m.uct00='	<dat:dataPackItem version="1.0" id="'+STRTRAN(STR(u_doklady1.RECNO(),3,0)," ","0")+'">'
*= FPUTS(m.lihandle, m.uct00)
m.uct00='	<Doklad>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		<c_dokl>'+ALLTRIM(u_doklady1.datum)+'</c_dokl>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		<datum>'+ALLTRIM(DTOC(u_doklady1.datum_dokl))+'</datum>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		<c_stredisk>'+ALLTRIM(u_doklady1.id_man)+'</c_stredisk>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='		<suma>'+ALLTRIM(STR(u_doklady1.castka,12,2))+'</suma>'
= FPUTS(m.lihandle, m.uct00)
DO CASE 
	CASE INLIST(LEFT(u_doklady1.pz,2),"VE","PE")
		SELECT partneri
		IF SEEK(u_doklady1.partner)
			m.uct00='		<ico>'+ALLTRIM(partneri.ico)+'</ico>'
		ELSE
			m.uct00='		<ico>'+ALLTRIM(u_doklady1.partner)+'</ico>'
		ENDIF 
		SELECT u_doklady1		
		= FPUTS(m.lihandle, m.uct00)
		m.uct00='		<parovyznak>'+ALLTRIM(u_doklady1.faktura)+'</parovyznak>'
		= FPUTS(m.lihandle, m.uct00)
	CASE INLIST(LEFT(u_doklady1.pz,2),"VV","PV")
		m.uct00='		<c_partner>'+ALLTRIM(SUBSTR(u_doklady1.poznamka,5,2))+'</c_partner>'
		= FPUTS(m.lihandle, m.uct00)
ENDCASE 
m.uct00='		<ucet>'+ALLTRIM(u_doklady1.md)+'</ucet>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='	</Doklad>'
= FPUTS(m.lihandle, m.uct00)



PROCEDURE rero_trz_00
* Export do RERO - trzby
m.uct00='<?xml version="1.0" encoding="Windows-1250"?>'
= FPUTS(m.lihandle, m.uct00)
m.uct00='<DATA>'
= FPUTS(m.lihandle, m.uct00)

PROCEDURE rero_trz_01
PRIVATE m.pis_datum, m.kk
m.pis_datum=DTOC(GOMONTH(CTOD("01."+m.mesuct+"."+m.rokuct),1)-1)
*m.pis_datum=SUBSTR(m.uzaverka,7,2)+"."+SUBSTR(m.uzaverka,5,2)+"."+SUBSTR(m.uzaverka,1,4)
* Export do KROSu - trzby
m.uct00='	<Doklad>'
= FPUTS(m.lihandle, m.uct00)
*!*	m.uct00='		<c_dokl>'+ALLTRIM(u_doklady1.datum)+'</c_dokl>'
*!*	= FPUTS(m.lihandle, m.uct00)
m.uct00='	</Doklad>'
= FPUTS(m.lihandle, m.uct00)



PROCEDURE gen_exp_asseco
PARAMETERS kontroluj,rokuct,mesuct, expfaktury
PRIVATE old_century,menoexp,oldsetdate,oldsetdele, riadkov, sumacelk,dokluzod,dokluzdo,prijemky, vydajky, ok, m.cislodokladu
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.rokuct
m.hladajmesiac=m.mesuct
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
m.old_century=SET("century")
m.oldsetdate=SET("date")
m.oldsetdele=SET("dele")
SET DATE TO GERMAN
SET DELETED ON
m.gcuexp_path=ALLTRIM(IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path))
IF ! DIRECTORY(m.gcuexp_path)
	MKDIR (m.gcuexp_path)
ENDIF
SET CENTURY ON
gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
gen_exp_had.SHOW()
gen_exp_had.set_max(20)
gen_exp_had.INCREMENT("Sklady")
IF USED("u_ex_obraty")
	IF m.expfaktury
		SELECT LEFT(pz,2) as operace, val(datum) as c_dokl, id_man, SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka,faktura, .F. AS storno,.F. AS vymaz, SPACE(10) as ico, 0000000000 as c_partner FROM u_ex_obraty GROUP BY c_dokl, pz, md, dal, hs_md, hs_dal INTO CURSOR u_doklady WHERE INLIST(LEFT(pz,1),"P","V") AND !EMPTY(datum) ORDER BY md, dal, hs_md, hs_dal READWRITE 
	ELSE
		SELECT datum, id_man, SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka,faktura, .F. AS storno,.F. AS vymaz, SPACE(10) as ico, 0000000000 as c_partner FROM u_ex_obraty GROUP BY pz, md, dal, hs_md, hs_dal INTO CURSOR u_doklady WHERE INLIST(LEFT(pz,1),"P","V") AND !EMPTY(datum) ORDER BY md, dal, hs_md, hs_dal READWRITE 
	ENDIF 
	IF RECCOUNT()>0
		DELETE FOR EMPTY(MD) .OR. EMPTY(dal)
		IF !USED("doklady")
			IF m.issql
				USE (m.sqlprefix+"rdoklady") ALIAS doklady AGAIN IN 0 
			ELSE
				USE (m.fn_doklady) ALIAS doklady AGAIN IN 0 ORDER c_dokl
			ENDIF 
		ENDIF
		IF m.expfaktury
			UPDATE u_doklady SET c_partner=doklady.c_partner from doklady WHERE u_doklady.c_dokl=doklady.c_dokl
		ENDIF 
		SELECT 0
		IF !USED("partaci")
			IF m.issql
				USE (m.sqlprefix+"rpartneriucto") ALIAS partaci
				INDEX on partner TAG partner
			ELSE 
				USE (m.gccen_path+"partneri") ORDER partner AGAIN ALIAS partaci
			ENDIF 
		ENDIF 
		SELECT u_doklady
		UPDATE u_doklady SET ico=partaci.ico from partaci WHERE u_doklady.c_partner=partaci.c_partner
		UPDATE u_doklady SET ico=m.hotel_ico WHERE EMPTY(ico)
		USE IN partaci
		SELECT 0
		SELECT u_doklady
		DELETE FOR castka=0
		IF !m.expfaktury
			REPLACE ALL datum_dokl WITH GOMONTH(CTOD("01."+m.mesuct+"."+m.rokuct),1)-1
		ENDIF 
		IF m.expfaktury
			m.poraduz=dajsapcdcislo("Faktury", m.rokuct, m.mesuct,"", "")
			m.menoexp="Faktury"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")
			UPDATE u_doklady SET pz=doklady.pz1, operace=doklady.operace from doklady WHERE u_doklady.c_dokl=doklady.c_dokl
		ELSE
			m.poraduz=dajsapcdcislo("Food", m.rokuct, m.mesuct,"", "")
			m.menoexp="Food"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")
		ENDIF 
		m.cislodokladu=ALLTRIM(STR(m.poraduz-1,12,0))
		SELECT u_doklady
		SELECT 0
		IF m.expfaktury
			CREATE TABLE (m.gcuexp_path+m.menoexp) FREE (typ c(10), c_dokl i, datum d, summd1 N(14,2), sumdal1 N(14,2), pozn1 c(15), ucet c(12), summd2 N(14,2), sumdal2 N(14,2), pozn2 c(15), osx c(10), ico c(10), cfa c(30))
		ELSE
			CREATE TABLE (m.gcuexp_path+m.menoexp)	FREE (dd c(5),CD c(15), pol N(4,0), datum d(8), ucet c(12), hs c(10), MD N(14,2), dal N(14,2),;
				cfak N(10,0), kodpu N(4,0), pcbu N(6,0), cbu N(10,0), ss N(10,0), spl d(8), tp c(3), zak c(12), oper c(40), perpen N(5,2), kodm c(3),;
				mdmena N(14,2), dmena N(14,2), clo c(1), mokod c(2), cinn_md c(4), cinn_dal c(4), uct1_md c(15), uct1_dal c(15),uct2_md c(15), uct2_dal c(15),;
				subj_id N(20,4),ico C(20))
		ENDIF 
		USE 
		m.riadkov=1
		m.vondatum=GOMONTH(CTOD("01."+m.mesuct+"."+m.rokuct),1)-1
		SELECT u_doklady
		IF m.expfaktury
			SCAN FOR LOWER(ALLTRIM(MD))<>"export"
				IF u_doklady.operace="PE"
					INSERT INTO (m.gcuexp_path+m.menoexp) (typ, c_dokl, datum, summd1, sumdal1, pozn1, ucet, summd2, sumdal2, pozn2, osx, ico, cfa) VALUES ;
						("PRIJ", u_doklady.c_dokl, u_doklady.datum_dokl, u_doklady.castka, u_doklady.castka, "Externý príjem", u_doklady.MD, u_doklady.castka,0,"Príjem materiálu",u_doklady.hs_md, u_doklady.ico, u_doklady.pz)
					INSERT INTO (m.gcuexp_path+m.menoexp) (typ, c_dokl, datum, summd1, sumdal1, pozn1, ucet, summd2, sumdal2, pozn2, osx, ico, cfa) VALUES ;
						("PRIJ", u_doklady.c_dokl, u_doklady.datum_dokl, u_doklady.castka, u_doklady.castka, "Externý príjem", u_doklady.DAL, 0, u_doklady.castka,"Príjem materiálu",u_doklady.hs_dal, u_doklady.ico, u_doklady.pz)
				ELSE
					INSERT INTO (m.gcuexp_path+m.menoexp) (typ, c_dokl, datum, summd1, sumdal1, pozn1, ucet, summd2, sumdal2, pozn2, osx, ico, cfa) VALUES ;
						("VYD", u_doklady.c_dokl, u_doklady.datum_dokl, -u_doklady.castka, -u_doklady.castka, "Externý výdaj", u_doklady.MD, -u_doklady.castka,0,"Výdaj materiálu",u_doklady.hs_md, u_doklady.ico, u_doklady.pz)
					INSERT INTO (m.gcuexp_path+m.menoexp) (typ, c_dokl, datum, summd1, sumdal1, pozn1, ucet, summd2, sumdal2, pozn2, osx, ico, cfa) VALUES ;
						("VYD", u_doklady.c_dokl, u_doklady.datum_dokl, -u_doklady.castka, -u_doklady.castka, "Externý výdaj", u_doklady.DAL, 0, -u_doklady.castka,"Výdaj materiálu",u_doklady.hs_dal, u_doklady.ico, u_doklady.pz)
				ENDIF 
				m.riadkov=m.riadkov+1
			ENDSCAN
		ELSE
			SCAN FOR LOWER(ALLTRIM(MD))<>"export"
				IF LEFT(u_doklady.pz,2)="PI" AND u_doklady.castka<0
					INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,hs,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,ss,kodm,mdmena,dmena, hs, cinn_md, cinn_dal, zak, ico) VALUES ;
						("880",m.cislodokladu,m.riadkov,u_doklady.datum_dokl,u_doklady.dal,u_doklady.hs_dal,ABS(u_doklady.castka),0,0,0,0,0,m.vondatum,u_doklady.partner,0,en__meny(m.uct_mena,3),ABS(u_doklady.castka),0, u_doklady.hs_md, LEFT(ALLTRIM(u_doklady.md2),4),"",RIGHT(ALLTRIM(u_doklady.md2),2),u_doklady.ico)
					INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,hs,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,ss,kodm,mdmena,dmena, hs, cinn_md, cinn_dal, zak, ico) VALUES ;
						("880",m.cislodokladu,m.riadkov,u_doklady.datum_dokl,u_doklady.md,u_doklady.hs_md,0,ABS(u_doklady.castka),0,0,0,0,m.vondatum,u_doklady.partner,0,en__meny(m.uct_mena,3),0,ABS(u_doklady.castka), u_doklady.hs_dal, "",LEFT(ALLTRIM(u_doklady.dal2),4),RIGHT(ALLTRIM(u_doklady.dal2),2),u_doklady.ico)
				ELSE
					INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,hs,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,ss,kodm,mdmena,dmena, hs, cinn_md, cinn_dal, zak, ico) VALUES ;
						("880",m.cislodokladu,m.riadkov,u_doklady.datum_dokl,u_doklady.MD,u_doklady.hs_md,ABS(u_doklady.castka),0,0,0,0,0,m.vondatum,u_doklady.partner,0,en__meny(m.uct_mena,3),ABS(u_doklady.castka),0, u_doklady.hs_md, LEFT(ALLTRIM(u_doklady.md2),4),"",RIGHT(ALLTRIM(u_doklady.md2),2),u_doklady.ico)
					INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,hs,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,ss,kodm,mdmena,dmena, hs, cinn_md, cinn_dal, zak, ico) VALUES ;
						("880",m.cislodokladu,m.riadkov,u_doklady.datum_dokl,u_doklady.dal,u_doklady.hs_dal,0,ABS(u_doklady.castka),0,0,0,0,m.vondatum,u_doklady.partner,0,en__meny(m.uct_mena,3),0,ABS(u_doklady.castka), u_doklady.hs_dal, "",LEFT(ALLTRIM(u_doklady.dal2),4),RIGHT(ALLTRIM(u_doklady.dal2),2),u_doklady.ico)
				ENDIF 
				m.riadkov=m.riadkov+1
			ENDSCAN
		ENDIF 
		IF USED(m.menoexp)
			SELECT (m.menoexp)
			COPY all to (m.gcuexp_path+m.menoexp+".csv") type delimited with character ";"
			USE IN (m.menoexp)
		ELSE
			SELECT 0
			IF FILE(m.gcuexp_path+m.menoexp)
				USE (m.gcuexp_path+m.menoexp)
				COPY all to (m.gcuexp_path+m.menoexp+".csv") type delimited with character ";"
				USE IN (m.menoexp)
			ENDIF 
		ENDIF
	ENDIF
	IF USED("expfaktura")
		UPDATE expfaktura SET uctexport=.t. WHERE c_dokl IN (SELECT c_dokl FROM u_ex_obraty)
		=tux(.t.,.t.,"expfaktura")
	ENDIF 
	IF m.expfaktury
		DO pozavirej WITH "u_doklady, u_ex_obraty"
	ELSE
		DO pozavirej WITH "u_doklady, doklady, u_ex_obraty"
	ENDIF 
ENDIF 

IF m.gcuct_trzba AND USED("u_ex_platby") AND USED("u_ex_polozky")
	gen_exp_had.INCREMENT("Tržby")
	IF m.uct_natazene
		SELECT SUM(castka) AS ciastka, MD,dal,md2,dal2,hs_dal,hs_md,partner,pz, poznamka,$0 AS danzakl, $0 AS dan FROM u_ex_polozky GROUP BY pz,poznamka,MD,dal, hs_md, hs_dal INTO CURSOR u_doklady1 READWRITE WHERE LEFT(poznamka,7)="Platba "
		REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
		REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
		REPLACE ALL danzakl WITH ciastka-dan
		SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka FROM u_doklady1 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_doklady2 READWRITE 
		USE IN u_doklady1
		REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
		SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2,poznamka FROM u_doklady2 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_doklady READWRITE 
		IF RECCOUNT("u_doklady")>0
			m.poraduz=dajsapcdcislo("Kas01B",m.rokuct, m.mesuct,"","")
			m.menoexp="Kas01B"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(poraduz,2,0)," ","0")
			SELECT SUM(castka) AS ciastka, MD,dal,hs_md, hs_dal,md2,dal2, pz, partner,poznamka,$0 AS danzakl, $0 AS dan FROM u_ex_polozky GROUP BY pz,poznamka,MD,dal, hs_md, hs_dal INTO CURSOR u_dokl1 READWRITE WHERE LEFT(poznamka,3)="POL"
			SELECT u_dokl1
			REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
			REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
			REPLACE ALL danzakl WITH ciastka-dan
			SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka FROM u_dokl1 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl2 READWRITE 
			USE IN u_dokl1
			REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
			SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2,poznamka FROM u_dokl2 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl READWRITE 
			INDEX ON ALLTRIM(pz) TAG pz
			USE IN u_dokl2
			SELECT u_doklady
			IF !prazdna()
				m.gcuexp_path = ALLTRIM(m.gcuexp_path)
				IF ! DIRECTORY(m.gcuexp_path)
					MKDIR (m.gcuexp_path)
				ENDIF
				CREATE TABLE (m.gcuexp_path+m.menoexp)	FREE (dd c(5),CD c(15), pol N(4,0), datum d(8), ucet c(12), hs c(10), MD N(14,2), dal N(14,2),;
					cfak N(10,0), kodpu N(4,0), pcbu N(6,0), cbu N(10,0), ss N(10,0), spl d(8), tp c(3), zak c(12), oper c(40), perpen N(5,2), kodm c(3),;
					mdmena N(14,2), dmena N(14,2), clo c(1), mokod c(2), cinn_md c(4), cinn_dal c(4), uct1_md c(15), uct1_dal c(15),uct2_md c(15), uct2_dal c(15),;
					subj_id N(20,4))
				USE
				SELECT u_doklady
				m.poraduz=dajsapcdcislo("Doklad",m.rokuct, m.mesuct,"","")
				SELECT distinct pz FROM u_doklady INTO CURSOR datumy READWRITE 
				m.riadkov=1
				SCAN ALL 
					SELECT u_doklady
					GO TOP 
					SCAN FOR pz=datumy.pz
						m.uzaverka=LEFT(u_doklady.pz,17)
						m.vonuz=m.mesuct+PADL(ALLTRIM(STR(m.poraduz+m.riadkov,15,0)),5,"0")
						m.vondatum=CTOD(SUBSTR(m.uzaverka,7,2)+"."+SUBSTR(m.uzaverka,5,2)+"."+LEFT(m.uzaverka,4))
						INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,kodm,mdmena,dmena,subj_id,cfak, cinn_md, cinn_dal, zak, hs) VALUES ;
							("166",m.vonuz,0,m.vondatum,u_doklady.MD,u_doklady.ciastka,0,0,0,0,0,m.vondatum,"",en__meny(m.uct_mena,3),u_doklady.ciastka,0,VAL(u_doklady.hs_md),VAL(LEFT(m.uzaverka,6)),"","","","")
						INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,hs,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,kodm,mdmena,dmena,subj_id,cfak, cinn_md, cinn_dal, zak, hs) VALUES ;
							("166",m.vonuz,0,m.vondatum,u_doklady.dal,u_doklady.hs_dal,0,u_doklady.danzakl,0,0,0,0,m.vondatum,"",en__meny(m.uct_mena,3),0,u_doklady.danzakl,VAL(u_doklady.hs_md),VAL(LEFT(m.uzaverka,6)),"",LEFT(ALLTRIM(u_doklady.md2),4),RIGHT(ALLTRIM(u_doklady.md2),2),u_doklady.hs_dal)
						INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,kodm,mdmena,dmena,subj_id,cfak) VALUES ;
							("166",m.vonuz,0,m.vondatum,u_doklady.dal2,0,u_doklady.dan,0,0,0,0,m.vondatum,"",en__meny(m.uct_mena,3),0,u_doklady.dan,VAL(u_doklady.hs_md),VAL(LEFT(m.uzaverka,6)))
					ENDSCAN

					SELECT u_dokl
					GO TOP 
					SCAN FOR pz=datumy.pz
						m.uzaverka=LEFT(u_dokl.pz,17)
						m.vonuz=m.mesuct+PADL(ALLTRIM(STR(m.poraduz+m.riadkov,15,0)),5,"0")
						m.vondatum=CTOD(SUBSTR(m.uzaverka,7,2)+"."+SUBSTR(m.uzaverka,5,2)+"."+LEFT(m.uzaverka,4))
						INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,kodm,mdmena,dmena,subj_id,cfak, cinn_md, cinn_dal, zak, hs) VALUES ;
							("166",m.vonuz,0,m.vondatum,u_dokl.MD,u_dokl.danzakl,0,0,0,0,0,m.vondatum,"",en__meny(m.uct_mena,3),u_dokl.danzakl,0,VAL(u_dokl.hs_md),VAL(LEFT(m.uzaverka,6)),"","","","")
						INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,hs,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,kodm,mdmena,dmena,subj_id,cfak, cinn_md, cinn_dal, zak, hs) VALUES ;
							("166",m.vonuz,0,m.vondatum,u_dokl.dal,u_doklady.hs_dal,0,u_dokl.danzakl,0,0,0,0,m.vondatum,"",en__meny(m.uct_mena,3),0,u_dokl.danzakl,VAL(u_dokl.hs_md),VAL(LEFT(m.uzaverka,6)),"",LEFT(ALLTRIM(u_dokl.md2),4),RIGHT(ALLTRIM(u_dokl.md2),2),u_dokl.hs_dal)
					ENDSCAN
					m.riadkov=m.riadkov+1
					SELECT datumy
				ENDSCAN
				=setsapcdcislo("Doklad",m.rokuct, m.mesuct,m.riadkov-1) 
			ENDIF
			SET CENTURY &old_century
			SET DATE &oldsetdate
			SET DELETED &oldsetdele
			IF USED(m.menoexp)
				SELECT (m.menoexp)
			ELSE
				IF FILE(m.gcuexp_path+m.menoexp)
					SELECT 0
					USE (m.gcuexp_path+m.menoexp)
				ENDIF 
			ENDIF
			IF USED(m.menoexp)
				COPY all to (m.gcuexp_path+m.menoexp+".csv") type delimited with character ";"
				USE IN (m.menoexp)
			ENDIF 
		ENDIF 
		DO pozavirej WITH "u_doklady, u_dokl, datumy"
	ELSE 
		SELECT SUM(castka) AS ciastka, MD,dal,md2,dal2,hs_dal,hs_md,partner,pz, poznamka, $0 AS celkom, 1.000000000 AS koef FROM u_ex_platby GROUP BY pz,poznamka,MD,dal, hs_md, hs_dal INTO CURSOR u_doklady READWRITE 
		SELECT SUM(castka) AS ciastka, pz FROM u_ex_platby GROUP BY pz INTO CURSOR u_platby  READWRITE 
		INDEX ON ALLTRIM(pz) TAG pz
		SELECT u_doklady
		SET RELATION TO ALLTRIM(pz) INTO u_platby
		REPLACE ALL u_doklady.celkom WITH u_platby.ciastka
		SET RELATION OFF INTO u_platby
		USE IN u_platby
		REPLACE ALL koef WITH IIF(celkom=0,1,ciastka/celkom)
		IF RECCOUNT("u_doklady")>0
			m.poraduz=dajsapcdcislo("Kas01B", m.rokuct, m.mesuct, "" , "")
			m.menoexp="Kas01B"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")
			SELECT SUM(castka) AS ciastka, MD,dal,hs_md, hs_dal,md2,dal2, pz, partner,poznamka,$0 AS danzakl, $0 AS dan FROM u_ex_polozky GROUP BY pz,poznamka,MD,dal, hs_md, hs_dal INTO CURSOR u_dokl1 READWRITE 
			SELECT u_dokl1
			REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
			REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
			REPLACE ALL danzakl WITH ciastka-dan
			SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka FROM u_dokl1 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl2 READWRITE 
			USE IN u_dokl1
			REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
			SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2,poznamka FROM u_dokl2 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl READWRITE  
			INDEX ON ALLTRIM(pz) TAG pz
			USE IN u_dokl2
			SELECT u_doklady
			IF !prazdna()
				m.gcuexp_path = ALLTRIM(m.gcuexp_path)
				IF ! DIRECTORY(m.gcuexp_path)
					MKDIR (m.gcuexp_path)
				ENDIF
				CREATE TABLE (m.gcuexp_path+m.menoexp)	FREE (dd c(5),CD c(15), pol N(4,0), datum d(8), ucet c(12), hs c(10), MD N(14,2), dal N(14,2),;
					cfak N(10,0), kodpu N(4,0), pcbu N(6,0), cbu N(10,0), ss N(10,0), spl d(8), tp c(3), zak c(12), oper c(40), perpen N(5,2), kodm c(3),;
					mdmena N(14,2), dmena N(14,2), clo c(1), mokod c(2), cinn_md c(4), cinn_dal c(4), uct1_md c(15), uct1_dal c(15),uct2_md c(15), uct2_dal c(15),;
					subj_id N(20,4))
				USE
				SELECT SPACE(17) AS uzaverka,ciastka, MD,dal,md2,dal2,hs_dal,hs_md,poznamka, celkom, $0 AS danzakl, $0 AS dan, ;
					SPACE(5) AS sadzba, SPACE(17) as ucet FROM u_doklady ;
					INTO CURSOR vondbf WHERE .f. READWRITE 
				SELECT u_doklady
				SCAN FOR !EMPTY(u_doklady.MD) .AND. !EMPTY(u_doklady.dal) .AND. u_doklady.ciastka<>0
					SELECT u_dokl
					SCAN FOR pz=u_doklady.pz .AND. !EMPTY(u_dokl.MD) .AND. !EMPTY(u_dokl.dal)
						IF u_doklady.MD=u_dokl.dal
							INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba, ucet) VALUES ;
								(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_dokl.MD,u_doklady.dal,u_dokl.md2,u_doklady.dal2,u_dokl.hs_md,u_doklady.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka,SUBSTR(u_dokl.pz,18))
						ELSE
							IF u_doklady.dal=u_dokl.MD
								INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba, ucet) VALUES ;
									(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_doklady.MD,u_dokl.dal,u_dokl.md2,u_dokl.dal2,u_dokl.hs_md,u_dokl.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka,SUBSTR(u_dokl.pz,18))
							ENDIF
						ENDIF
					ENDSCAN
					SELECT u_doklady
				ENDSCAN
				SELECT uzaverka,SUM(ciastka) AS ciastka,MD,dal,md2,dal2,hs_md,hs_dal, SUM(danzakl) AS danzakl, SUM(dan) AS dan, sadzba FROM vondbf ;
					GROUP BY uzaverka, MD, dal, hs_md, hs_dal, sadzba INTO CURSOR vondbf2 READWRITE 
				SELECT uzaverka, SUM(ciastka) AS ciastka,MD,dal,md2,dal2,hs_md,hs_dal, 0000000000.00 AS cena0, 0000000000.00 AS cena5, 0000000000.00 AS cena23, 000000000.00 AS dan5, 000000000.00 AS dan23,.F. AS vymaz,.F. AS storno FROM vondbf ;
					GROUP BY uzaverka, MD, dal, hs_md, hs_dal INTO CURSOR vondbf1 READWRITE 
				m.riadkov=1
				SCAN ALL
					SELECT vondbf2
					SCAN FOR MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. uzaverka=vondbf1.uzaverka
						DO CASE
							CASE ALLTRIM(sadzba)="0"
								REPLACE vondbf1.cena0 WITH vondbf2.danzakl
							CASE ALLTRIM(sadzba)=ALLTRIM(STR((m.uctdphlo-1)*100,10,0))
								REPLACE vondbf1.cena5 WITH vondbf2.danzakl, vondbf1.dan5 WITH vondbf2.dan
							OTHERWISE
								REPLACE vondbf1.cena23 WITH vondbf2.danzakl, vondbf1.dan23 WITH vondbf2.dan
						ENDCASE
					ENDSCAN
				ENDSCAN
				IF !m.issql
					IF FILE(m.gcdat_path+"uexarsk.dbf")
						SELECT 0
						USE (m.gcdat_path+"uexarsk.dbf")
					ELSE
						SELECT vondbf1
						COPY STRUCTURE TO (m.gcdat_path+"uexarsk.dbf")
						SELECT 0
						USE (m.gcdat_path+"uexarsk.dbf")
					ENDIF
				ENDIF 
				IF m.kontroluj
					SELECT DISTINCT uzaverka FROM vondbf1 INTO CURSOR datumy READWRITE 
					SCAN ALL
						m.hladajuzaverka=datumy.uzaverka
						m.oprava=0
						SELECT vondbf1
						SCAN FOR uzaverka=datumy.uzaverka
							IF m.issql
								IF USED("uexarsk")
									=REQUERY("uexarsk")
								ELSE
									USE (m.sqlprefix+"ruexarsk") ALIAS uexarsk IN 0
									=CURSORSETPROP("Buffering",5,"uexarsk")
								ENDIF 
							ENDIF 
							SELECT uexarsk
							LOCATE FOR uzaverka=vondbf1.uzaverka
							IF FOUND()
								LOCATE FOR uzaverka=vondbf1.uzaverka .AND. ciastka=vondbf1.ciastka .AND. MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. cena0=vondbf1.cena0 .AND. cena5=vondbf1.cena5 ;
									.AND. cena23=vondbf1.cena23 .AND. dan5=vondbf1.dan5 .AND. dan23=vondbf1.dan23 .AND. hs_md=vondbf1.hs_md .AND. hs_dal=vondbf1.hs_dal
								IF !FOUND()
									m.oprava=2
								ELSE
									m.oprava=1
								ENDIF
							ELSE
								m.oprava=0
							ENDIF
							SELECT vondbf1
							IF m.oprava=2
								EXIT
							ENDIF
						ENDSCAN
						DO CASE
							CASE m.oprava=2
								SELECT uexarsk
								SCAN FOR uzaverka=datumy.uzaverka
									INSERT INTO vondbf1 (uzaverka,ciastka,MD,dal,hs_md, hs_dal,md2,dal2,cena0,cena5,cena23,dan5,dan23,storno);
										VALUES (uexarsk.uzaverka,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,uexarsk.md2,uexarsk.dal2,-uexarsk.cena0,-uexarsk.cena5,;
										-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.T.)
								ENDSCAN
							CASE m.oprava=1
								SELECT vondbf1
								DELETE FOR uzaverka=datumy.uzaverka
						ENDCASE
						SELECT datumy
					ENDSCAN
					IF m.issql
						USE (m.sqlprefix+"ruexarsk_zoznam_uzavierok") ALIAS uexzoznam IN 0
						SELECT DISTINCT uzaverka FROM uexzoznam WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
							INTO CURSOR datumy2 READWRITE 
						USE IN uexzoznam
					ELSE 
						SELECT DISTINCT uzaverka FROM uexarsk WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
							INTO CURSOR datumy2 READWRITE 
					ENDIF 
					SCAN ALL
						m.hladajuzaverka=datumy2.uzaverka
						IF m.issql
							=REQUERY("uexarsk")
						ENDIF 
						SELECT uexarsk
						SCAN FOR uzaverka=datumy2.uzaverka
							INSERT INTO vondbf1 (uzaverka,ciastka,MD,dal,hs_md, hs_dal,cena0,cena5,cena23,dan5,dan23,storno,vymaz);
								VALUES (uexarsk.uzaverka,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,-uexarsk.cena0,-uexarsk.cena5,;
								-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.F.,.T.)
						ENDSCAN
						SELECT datumy2
					ENDSCAN
					USE IN datumy2
				ENDIF
				m.poraduz=dajsapcdcislo("Doklad", m.rokuct, m.mesuct, "", "")
				SELECT vondbf1
				GO TOP 
				m.uzaverka=vondbf1.uzaverka
				m.vonuz=m.mesuct+PADL(ALLTRIM(STR(m.poraduz+m.riadkov,15,0)),5,"0")
				m.vondatum=CTOD(SUBSTR(vondbf1.uzaverka,7,2)+"."+SUBSTR(vondbf1.uzaverka,5,2)+"."+LEFT(vondbf1.uzaverka,4))
				SCAN ALL
					INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,kodm,mdmena,dmena,subj_id,cfak, cinn_md, cinn_dal, zak, hs) VALUES ;
						("166",m.vonuz,0,m.vondatum,vondbf1.MD,vondbf1.ciastka,0,0,0,0,0,m.vondatum,"",en__meny(m.uct_mena,3),vondbf1.ciastka,0,VAL(vondbf1.hs_md),VAL(LEFT(vondbf1.uzaverka,6)),"","","","")
					INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,hs,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,kodm,mdmena,dmena,subj_id,cfak, cinn_md, cinn_dal, zak, hs) VALUES ;
						("166",m.vonuz,0,m.vondatum,vondbf1.dal,vondbf1.hs_dal,0,vondbf1.cena0+vondbf1.cena5+vondbf1.cena23,0,0,0,0,m.vondatum,"",en__meny(m.uct_mena,3),0,vondbf1.cena0+vondbf1.cena5+vondbf1.cena23,VAL(vondbf1.hs_md),VAL(LEFT(vondbf1.uzaverka,6)),"",LEFT(ALLTRIM(vondbf1.md2),4),RIGHT(ALLTRIM(vondbf1.md2),2),vondbf1.hs_dal)
					INSERT INTO (m.gcuexp_path+m.menoexp) (dd,CD,pol,datum,ucet,MD,dal,cfak,kodpu,pcbu,cbu,spl,oper,kodm,mdmena,dmena,subj_id,cfak) VALUES ;
						("166",m.vonuz,0,m.vondatum,vondbf1.dal2,0,vondbf1.dan5+vondbf1.dan23,0,0,0,0,m.vondatum,"",en__meny(m.uct_mena,3),0,vondbf1.dan5+vondbf1.dan23,VAL(vondbf1.hs_md),VAL(LEFT(vondbf1.uzaverka,6)))
				ENDSCAN
				=setsapcdcislo("Doklad",m.rokuct, m.mesuct,m.riadkov-1)
				SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
					IF m.issql
						m.hladajuzaverka=vondbf1.uzaverka
						=REQUERY("uexarsk")
						SELECT uexarsk
						DELETE ALL 
						=tux(.t.,.t.,"uexarsk")
					ELSE 
						SELECT uexarsk
						DELETE FOR uzaverka=vondbf1.uzaverka
					ENDIF 
					SELECT vondbf1
				ENDSCAN
				IF m.issql
					m.hladajuzaverka="xxx"
					=REQUERY("uexarsk")
				ENDIF 
				SELECT uexarsk
				APPEND FROM DBF("vondbf1") FOR !storno .AND. !vymaz
				IF m.issql
					=tux(.t.,.t.,"uexarsk")
				ENDIF 
				DO pozavirej WITH "uexarsk"
				IF !m.issql
					IF f_acc_ex(m.gcdat_path+"uexarsk")
						PACK
						USE
					ENDIF
				ENDIF 
			ENDIF
			SET CENTURY &old_century
			SET DATE &oldsetdate
			SET DELETED &oldsetdele
			DO pozavirej WITH "vondbf, u_doklady, u_dokl, vondbf1, vondbf2, datumy, u_ex_polozky, u_ex_platby"
			IF USED(m.menoexp)
				SELECT (m.menoexp)
			ELSE
				IF FILE(m.gcuexp_path+m.menoexp)
					SELECT 0
					USE (m.gcuexp_path+m.menoexp)
				ENDIF 
			ENDIF
			IF USED(m.menoexp)
				COPY all to (m.gcuexp_path+m.menoexp+".csv") type delimited with character ";"
				USE IN (m.menoexp)
			ENDIF 
		ELSE
			USE IN u_doklady
		ENDIF 
	ENDIF 
ENDIF
RELEASE gen_exp_had
RETURN

PROCEDURE gen_exp_proluc
PARAMETERS kontroluj,rokuct,mesuct
PRIVATE old_century,menoexp,oldsetdate,oldsetdele, riadkov, sumacelk,dokluzod,dokluzdo,prijemky, vydajky, ok
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.rokuct
m.hladajmesiac=m.mesuct
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
m.old_century=SET("century")
m.oldsetdate=SET("date")
m.oldsetdele=SET("dele")
SET DATE TO GERMAN
SET DELETED ON
m.gcuexp_path=ALLTRIM(IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path))
IF ! DIRECTORY(m.gcuexp_path)
	MKDIR (m.gcuexp_path)
ENDIF
SET CENTURY ON
gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
gen_exp_had.SHOW()
gen_exp_had.set_max(20)
gen_exp_had.INCREMENT("Sklady")
IF USED("u_ex_obraty")
	SELECT operace, datum, id_man, SUM(castka) AS castka, MD,dal,md2,dal2,hs_md, hs_dal,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka,faktura, .F. AS storno,.F. AS vymaz FROM u_ex_obraty GROUP BY id_man,pz,datum,doklad,datum_dokl,MD,dal INTO CURSOR u_doklady WHERE INLIST(LEFT(pz,1),"P","V") READWRITE 
	DELETE FOR EMPTY(datum)
	DELETE FOR EMPTY(MD) .OR. EMPTY(dal)
	SELECT u_doklady
	SELECT 0
	IF m.issql
		USE (m.sqlprefix+"ruexarchobraty_mesiacrok") ALIAS uexarch IN 0
	ELSE 
		IF !FILE(m.gccen_path+"uexarchobraty.dbf")
			DO creafile WITH (m.gccen_path+"uexarchobraty.dbf")
		ENDIF 
		IF !USED("uexarchobraty")
			USE (m.gccen_path+"uexarchobraty") IN 0
		ENDIF 
		USE vuexarchobraty_mesiacrok IN 0 ALIAS uexarch
	ENDIF 
	=CURSORSETPROP("Buffering",5,"uexarch")
	IF m.kontroluj
		DO kontrola_skladov
	ELSE
		SELECT 0
		IF m.issql
			USE (m.sqlprefix+"ruzaverka") ALIAS expuzav
			INDEX on rok+mesiac TAG kedy
		ELSE 
			USE (m.gcdat_path+"uzaverka") AGAIN ALIAS expuzav ORDER kedy
		ENDIF 
		SET FILTER TO c_stredisk=m.gic_stredisk
		GO BOTTOM
		m.rokuct=expuzav.rok
		m.mesuct=expuzav.mesiac
		IF EMPTY(m.rokuct) .OR. EMPTY(m.mesuct)
			m.rokuct=STR(YEAR(DATE()),4,0)
			m.mesuct=STRTRAN(STR(MONTH(DATE()),2,0)," ","0")
		ELSE
			m.mesuct=STRTRAN(STR(VAL(m.mesuct)+1,2,0)," ","0")
			IF m.mesuct="13" 
				m.mesuct="01"
				m.rokuct=STR(VAL(m.rokuct)+1,4,0)
			ENDIF
		ENDIF
		USE IN expuzav
	ENDIF
	SELECT u_doklady
	DELETE FOR castka=0
	IF m.issql
		USE (m.sqlprefix+"rdoklady") IN 0 ALIAS doklady
		SELECT doklady
		INDEX on c_dokl TAG c_dokl
	ELSE 
		IF !USED("doklady")
			USE (m.fn_doklady) ALIAS doklady AGAIN IN 0 ORDER c_dokl
		ELSE
			SELECT doklady
			SET ORDER TO c_dokl
		ENDIF
	ENDIF 
	m.poraduz=dajsapcdcislo("Sklady", m.rokuct, m.mesuct, "", "")
	m.menoexp="Sklady"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")
	SELECT u_doklady
	SET RELATION TO VAL(ALLTRIM(datum)) INTO doklady
	SELECT 0
	CREATE TABLE (m.gcuexp_path+m.menoexp)	FREE (typ c(3),cislo n(10), suma N(13,2), md n(8,4), dal n(8,4), skupina n(3), dat_dph d(8), poznamka c(40), akcia n(8,2), stredisko c(5), dat_uct d(8), mena c(3), dat_mena d(8), suma_mena n(13,2), pozn c(40), dat_vzn d(8))
	USE
	m.riadkov=1
	SELECT u_doklady
	SCAN FOR LOWER(ALLTRIM(MD))<>"export"
		INSERT INTO (m.gcuexp_path+m.menoexp) (typ, cislo, suma, md, dal, skupina, poznamka, akcia, stredisko, dat_uct, pozn, dat_vzn) VALUES ;
			(m.evidencia,VAL(u_doklady.datum),ABS(u_doklady.castka), VAL(u_doklady.md), VAL(u_doklady.dal), 0, u_doklady.poznamka, 0, u_doklady.hs_dal, u_doklady.datum_dokl,"", u_doklady.datum_dokl)
		m.riadkov=m.riadkov+1
	ENDSCAN

	SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
		SELECT uexarch
		DELETE FOR datum=u_doklady.datum
		SELECT u_doklady
	ENDSCAN
	SELECT uexarch
	APPEND FROM DBF("u_doklady") FOR !storno .AND. !vymaz
	REPLACE c_data WITH m.cdata FOR c_data<>m.cdata
	REPLACE ALL mesiac WITH m.mesuct FOR mesiac<>m.mesuct
	REPLACE ALL rok WITH m.rokuct FOR rok<>m.rokuct
	=tux(.t.,.t.,"uexarch")
	DO pozavirej WITH "uexarch, uexarchobraty"
	IF !m.issql
		IF f_acc_ex(m.gcdat_path+"uexarchobraty")
			PACK
			USE
		ENDIF
	ENDIF 
	DO pozavirej WITH "u_doklady, doklady, uexarch, uexarchobraty, u_ex_obraty"
	IF USED(m.menoexp)
		SELECT (m.menoexp)
		COPY all to (m.gcuexp_path+m.menoexp+".csv") type delimited with character ";"
		USE IN (m.menoexp)
	ELSE
		SELECT 0
		IF FILE(m.gcuexp_path+m.menoexp)
			USE (m.gcuexp_path+m.menoexp)
			COPY all to (m.gcuexp_path+m.menoexp+".csv") type delimited with character ";"
			USE IN (m.menoexp)
		ENDIF 
	ENDIF
	IF FILE(m.gcuexp_path+m.menoexp+".csv")
		m.xx=FILETOSTR(m.gcuexp_path+m.menoexp+".csv")
		ERASE (m.gcuexp_path+m.menoexp+".csv")
		m.xx=STRTRAN(m.xx,'"','')
		=STRTOFILE(m.xx,m.gcuexp_path+m.menoexp+".csv")
	ENDIF 
ENDIF 
IF m.gcuct_trzba AND USED("u_ex_platby") AND USED("u_ex_polozky")
	gen_exp_had.INCREMENT("Tržby")
	m.poraduz=dajsapcdcislo("Trzby",m.rokuct, m.mesuct, "", "")
	m.menoexp="Trzby"+RIGHT(m.rokuct,2)+m.mesuct+STRTRAN(STR(m.poraduz,2,0)," ","0")
	
	SELECT SUM(castka) AS ciastka, MD,dal,md2,dal2,hs_dal,hs_md,partner,pz, poznamka, $0 AS celkom, 1.000000000 AS koef FROM u_ex_platby GROUP BY pz,poznamka,MD,dal INTO CURSOR u_doklady READWRITE 
	SELECT SUM(castka) AS ciastka, pz FROM u_ex_platby GROUP BY pz INTO CURSOR u_platby  READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	SELECT u_doklady
	SET RELATION TO ALLTRIM(pz) INTO u_platby
	REPLACE ALL u_doklady.celkom WITH u_platby.ciastka
	SET RELATION OFF INTO u_platby
	USE IN u_platby
	REPLACE ALL koef WITH IIF(celkom=0,1,ciastka/celkom)
	SELECT SUM(castka) AS ciastka, MD,dal,hs_md, hs_dal,md2,dal2, pz, partner,poznamka,$0 AS danzakl, $0 AS dan FROM u_ex_polozky GROUP BY pz,poznamka,MD,dal INTO CURSOR u_dokl1 READWRITE 
	SELECT u_dokl1
	REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
	REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka FROM u_dokl1 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl2 READWRITE 
	USE IN u_dokl1
	REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
	SELECT pz,SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2,poznamka FROM u_dokl2 GROUP BY pz, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl READWRITE 
	INDEX ON ALLTRIM(pz) TAG pz
	USE IN u_dokl2
	SELECT u_doklady
	IF !prazdna()
		m.gcuexp_path = ALLTRIM(m.gcuexp_path)
		IF ! DIRECTORY(m.gcuexp_path)
			MKDIR (m.gcuexp_path)
		ENDIF
		CREATE TABLE (m.gcuexp_path+m.menoexp)	FREE (typ c(3),cislo n(10), suma N(13,2), md n(8,4), dal n(8,4), skupina n(3), dat_dph d(8), poznamka c(40), akcia n(8,2), stredisko c(5), dat_uct d(8), mena c(3), dat_mena d(8), suma_mena n(13,2), pozn c(40), dat_vzn d(8))
		USE
		SELECT SPACE(17) AS uzaverka,ciastka, MD,dal,md2,dal2,hs_dal,hs_md,poznamka, celkom, $0 AS danzakl, $0 AS dan, ;
			SPACE(5) AS sadzba FROM u_doklady INTO CURSOR vondbf WHERE .f. READWRITE 
		SELECT u_doklady
		SCAN FOR !EMPTY(u_doklady.MD) .AND. !EMPTY(u_doklady.dal) .AND. u_doklady.ciastka<>0
			SELECT u_dokl
			SCAN FOR pz=u_doklady.pz .AND. !EMPTY(u_dokl.MD) .AND. !EMPTY(u_dokl.dal)
				IF u_doklady.MD=u_dokl.dal
					INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba) VALUES ;
						(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_dokl.MD,u_doklady.dal,u_dokl.md2,u_doklady.dal2,u_dokl.hs_md,u_doklady.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka)
				ELSE
					IF u_doklady.dal=u_dokl.MD
						INSERT INTO vondbf (uzaverka,ciastka,MD,dal,md2,dal2,hs_md,hs_dal, danzakl, dan, sadzba) VALUES ;
							(LEFT(u_dokl.pz,17),ROUND(u_dokl.ciastka*u_doklady.koef,2),u_doklady.MD,u_dokl.dal,u_dokl.md2,u_dokl.dal2,u_dokl.hs_md,u_dokl.hs_dal,ROUND(u_dokl.danzakl*u_doklady.koef,2),ROUND(u_dokl.dan*u_doklady.koef,2),u_dokl.poznamka)
					ENDIF
				ENDIF
			ENDSCAN
			SELECT u_doklady
		ENDSCAN
		SELECT uzaverka,SUM(ciastka) AS ciastka,MD,dal,md2,dal2,hs_md,hs_dal, SUM(danzakl) AS danzakl, SUM(dan) AS dan, sadzba FROM vondbf ;
			GROUP BY uzaverka, MD, dal, sadzba INTO CURSOR vondbf2 READWRITE 
		SELECT uzaverka, SUM(ciastka) AS ciastka,MD,dal,md2,dal2,hs_md,hs_dal, 0000000000.00 AS cena0, 0000000000.00 AS cena5, 0000000000.00 AS cena23, 000000000.00 AS dan5, 000000000.00 AS dan23,.F. AS vymaz,.F. AS storno FROM vondbf ;
			GROUP BY uzaverka, MD, dal INTO CURSOR vondbf1 READWRITE 
		m.riadkov=1
		SCAN ALL
			SELECT vondbf2
			SCAN FOR MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. uzaverka=vondbf1.uzaverka
				DO CASE
					CASE ALLTRIM(sadzba)="0"
						REPLACE vondbf1.cena0 WITH vondbf2.danzakl
					CASE ALLTRIM(sadzba)=ALLTRIM(STR((m.uctdphlo-1)*100,10,0))
						REPLACE vondbf1.cena5 WITH vondbf2.danzakl, vondbf1.dan5 WITH vondbf2.dan
					OTHERWISE
						REPLACE vondbf1.cena23 WITH vondbf2.danzakl, vondbf1.dan23 WITH vondbf2.dan
				ENDCASE
			ENDSCAN
		ENDSCAN
		IF !m.issql
			IF FILE(m.gcdat_path+"uexarsk.dbf")
				SELECT 0
				USE (m.gcdat_path+"uexarsk.dbf")
			ELSE
				SELECT vondbf1
				COPY STRUCTURE TO (m.gcdat_path+"uexarsk.dbf")
				SELECT 0
				USE (m.gcdat_path+"uexarsk.dbf")
			ENDIF
		ENDIF 
		IF m.kontroluj
			SELECT DISTINCT uzaverka FROM vondbf1 INTO CURSOR datumy READWRITE 
			SCAN ALL
				m.hladajuzaverka=datumy.uzaverka
				m.oprava=0
				SELECT vondbf1
				SCAN FOR uzaverka=datumy.uzaverka
					IF m.issql
						IF USED("uexarsk")
							=REQUERY("uexarsk")
						ELSE
							USE (m.sqlprefix+"ruexarsk") ALIAS uexarsk IN 0
							=CURSORSETPROP("Buffering",5,"uexarsk")
						ENDIF 
					ENDIF 
					SELECT uexarsk
					LOCATE FOR uzaverka=vondbf1.uzaverka
					IF FOUND()
						LOCATE FOR uzaverka=vondbf1.uzaverka .AND. ciastka=vondbf1.ciastka .AND. MD=vondbf1.MD .AND. dal=vondbf1.dal .AND. cena0=vondbf1.cena0 .AND. cena5=vondbf1.cena5 ;
							.AND. cena23=vondbf1.cena23 .AND. dan5=vondbf1.dan5 .AND. dan23=vondbf1.dan23 .AND. hs_md=vondbf1.hs_md .AND. hs_dal=vondbf1.hs_dal
						IF !FOUND()
							m.oprava=2
						ELSE
							m.oprava=1
						ENDIF
					ELSE
						m.oprava=0
					ENDIF
					SELECT vondbf1
					IF m.oprava=2
						EXIT
					ENDIF
				ENDSCAN
				DO CASE
					CASE m.oprava=2
						SELECT uexarsk
						SCAN FOR uzaverka=datumy.uzaverka
							INSERT INTO vondbf1 (uzaverka,ciastka,MD,dal,hs_md, hs_dal,md2,dal2,cena0,cena5,cena23,dan5,dan23,storno);
								VALUES (uexarsk.uzaverka,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,uexarsk.md2,uexarsk.dal2,-uexarsk.cena0,-uexarsk.cena5,;
								-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.T.)
						ENDSCAN
					CASE m.oprava=1
						SELECT vondbf1
						DELETE FOR uzaverka=datumy.uzaverka
				ENDCASE
				SELECT datumy
			ENDSCAN
			SELECT DISTINCT uzaverka FROM uexarsk WHERE uzaverka>m.skuzod .AND. uzaverka<=m.skuzdo .AND. !(uzaverka IN (SELECT DISTINCT uzaverka FROM datumy));
				INTO CURSOR datumy2 READWRITE 
			SCAN ALL
				SELECT uexarsk
				SCAN FOR uzaverka=datumy2.uzaverka
					INSERT INTO vondbf1 (uzaverka,ciastka,MD,dal,hs_md, hs_dal,cena0,cena5,cena23,dan5,dan23,storno,vymaz);
						VALUES (uexarsk.uzaverka,-uexarsk.ciastka,uexarsk.MD,uexarsk.dal,uexarsk.hs_md,uexarsk.hs_dal,-uexarsk.cena0,-uexarsk.cena5,;
						-uexarsk.cena23,-uexarsk.dan5,-uexarsk.dan23,.F.,.T.)
				ENDSCAN
				SELECT datumy2
			ENDSCAN
			USE IN datumy2
		ENDIF
		m.poraduz=dajsapcdcislo("Doklad",m.rokuct, m.mesuct,"", "")
		SELECT vondbf1
		m.riadkov=1
		SCAN ALL
			m.vonuz=VAL(m.mesuct+PADL(ALLTRIM(STR(m.poraduz+m.riadkov,15,0)),5,"0"))
			m.vondatum=CTOD(SUBSTR(vondbf1.uzaverka,7,2)+"."+SUBSTR(vondbf1.uzaverka,5,2)+"."+LEFT(vondbf1.uzaverka,4))
			INSERT INTO (m.gcuexp_path+m.menoexp) (typ, cislo, suma, md, dal, skupina, dat_dph, poznamka, akcia, stredisko, dat_uct, pozn, dat_vzn) VALUES ;
				(m.evidencia, m.vonuz,ABS(vondbf1.ciastka), VAL(vondbf1.md), VAL(vondbf1.dal), VAL(vondbf1.dal2), m.vondatum, vondbf1.uzaverka, 0, vondbf1.hs_dal, m.vondatum,"", m.vondatum)
*(typ c(3),cislo n(10), suma N(13,2), md n(8,4), dal n(8,4), skupina n(3), dat_dph d(8), poznamka c(40), akcia n(8,2), stredisko c(5), dat_uct d(8), mena c(3), dat_mena d(8), suma_mena n(13,2), pozn c(40), dat_vzn d(8))
			m.riadkov=m.riadkov+1
		ENDSCAN
		=setsapcdcislo("Doklad", m.rokuct, m.mesuct, m.riadkov-1)
		SELECT vondbf1
		SCAN FOR LOWER(ALLTRIM(MD))<>"export" .AND. !storno
			IF m.issql
				m.hladajuzaverka=vondbf1.uzaverka
				=REQUERY("uexarsk")
				SELECT uexarsk
				DELETE ALL 
				=tux(.t.,.t.,"uexarsk")
			ELSE 
				SELECT uexarsk
				DELETE FOR uzaverka=vondbf1.uzaverka
			ENDIF 
			SELECT vondbf1
		ENDSCAN
		IF m.issql
			m.hladajuzaverka="xxx"
			=REQUERY("uexarsk")
		ENDIF 
		SELECT uexarsk
		APPEND FROM DBF("vondbf1") FOR !storno .AND. !vymaz
		IF m.issql
			=tux(.t.,.t.,"uexarsk")
		ENDIF 
	ENDIF 
	DO pozavirej WITH "uexarsk"
	IF !m.issql
		IF f_acc_ex(m.gcdat_path+"uexarsk")
			PACK
			USE
		ENDIF
	ENDIF 
	SET CENTURY &old_century
	SET DATE &oldsetdate
	SET DELETED &oldsetdele
	DO pozavirej WITH "vondbf, u_doklady, u_dokl, condbf1, vondbf2, datumy"
	IF USED(m.menoexp)
		SELECT (m.menoexp)
		COPY all to (m.gcuexp_path+m.menoexp+".csv") type delimited with character ";"
		USE IN (m.menoexp)
	ELSE
		SELECT 0
		IF FILE(m.gcuexp_path+m.menoexp)
			USE (m.gcuexp_path+m.menoexp)
			COPY all to (m.gcuexp_path+m.menoexp+".csv") type delimited with character ";"
			USE IN (m.menoexp)
		ENDIF 
	ENDIF
	IF FILE(m.gcuexp_path+m.menoexp+".csv")
		m.xx=FILETOSTR(m.gcuexp_path+m.menoexp+".csv")
		ERASE (m.gcuexp_path+m.menoexp+".csv")
		m.xx=STRTRAN(m.xx,'"','')
		=STRTOFILE(m.xx,m.gcuexp_path+m.menoexp+".csv")
	ENDIF 
ENDIF
RELEASE gen_exp_had
RETURN





PROCEDURE gen_exp_karat
PARAMETERS m.mrok, m.mmesiac
PRIVATE kthotel,oddelovac,bolipartneri,oddelovac,cislodokladu,oldsetdele, m.nom, m.pismeno
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.mrok
m.hladajmesiac=m.mmesiac
m.oldsetdele=SET("dele")
SET DELETED ON
gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
gen_exp_had.SHOW()
gen_exp_had.set_max(20)
m.oddelovac=" "
m.nom=""
DO CASE 
	CASE "ofz"$LOWER(m.wi_zakaz)
		m.pismeno="o"
	CASE "green"$LOWER(m.gchom_path)
		m.pismeno="g"
	CASE "park"$LOWER(m.gchom_path)
		m.pismeno="p"
	CASE "kult"$LOWER(m.gchom_path)
		m.pismeno="k"
	OTHERWISE 
		m.pismeno=""
ENDCASE 
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
IF USED("u_ex_obraty")
	SELECT datum,id_man, SUM(castka) AS ciastka,MD,dal,hs_md,pz,partner,STR(doklad,10,0) as doklad,datum_dokl FROM u_ex_obraty GROUP BY id_man,pz,datum,doklad,datum_dokl,MD,dal,hs_md INTO CURSOR uidobr WHERE !EMPTY(datum) READWRITE 
	REPLACE ciastka WITH -ciastka FOR LEFT(pz,1)="V"
	SELECT SUM(ciastka) AS ciastka,MD,dal,hs_md FROM uidobr GROUP BY MD,dal,hs_md INTO CURSOR u_id_obr READWRITE 
	USE IN uidobr
	DELETE FOR ciastka=0
ENDIF 

gen_exp_had.INCREMENT("Tržby")
IF USED("u_ex_platby") AND USED("u_ex_polozky")
	SELECT SUM(castka) AS ciastka, MD,dal,md2,dal2,hs_dal,hs_md,partner,poznamka FROM u_ex_platby GROUP BY poznamka,MD,dal INTO CURSOR u_doklady  READWRITE 
	*!*	DELETE FOR ("n_uver"$LOWER(u_doklady.poznamka)) OR (EMPTY(md) AND EMPTY(dal))
	*!*	*** Vyberiem sumu platieb po uctoch, ale vyhodim uvery a platby s nevyplnenymi uctami
	*!*	SELECT SUM(castka) AS ciastka, pz FROM u_ex_platby GROUP BY pz INTO CURSOR u_platby  WHERE !("n_uver"$LOWER(u_ex.poznamka)) AND !EMPTY(md) AND !EMPTY(dal)
	*!*	INDEX ON ALLTRIM(pz) TAG pz
	*!*	*** Vyberiem sumu platiab po uctoch za vsetky platby
	*!*	SELECT SUM(castka) AS ciastka, 0001.000000000 AS koef, pz FROM u_ex_platby GROUP BY pz INTO CURSOR u_poloz
	*!*	INDEX ON ALLTRIM(pz) TAG pz
	*!*	*** Urobim relaciu a spocitam koeficient pre tie ucty, kde sa nemaju exportovat vsetky platby
	*!*	SET RELATION TO ALLTRIM(pz) INTO u_platby
	*!*	SCAN FOR u_poloz.ciastka<>u_platby.ciastka
	*!*		REPLACE u_poloz.koef WITH IIF(u_poloz.ciastka<>0,u_platby.ciastka/u_poloz.ciastka,1)
	*!*	ENDSCAN
	*!*	SET RELATION OFF INTO u_platby
	*!*	USE IN u_platby
	*!*	*** Podla spocitaneho koeficientu pre platby upravim percentualne sumu za jednotlive polozky
	*!*	SELECT u_ex_polozky
	*!*	SET RELATION TO ALLTRIM(pz) INTO u_poloz
	*!*	REPLACE ALL castka WITH castka*u_poloz.koef
	*!*	SET RELATION OFF INTO u_poloz
	*!*	USE IN u_poloz
	SELECT SUM(castka) AS ciastka, MD,dal,hs_md, hs_dal,md2,dal2, partner,poznamka,$0 AS danzakl, $0 AS dan FROM u_ex_polozky GROUP BY partner,poznamka,MD,dal INTO CURSOR u_dokl1 READWRITE 
	*!*	**** Este musim zistit sumu poloziek, ktore sa nemaju exportovat a ponizit prislusne sumy platieb

	*!*	SELECT castka, pz FROM u_ex_polozky INTO CURSOR neexp WHERE EMPTY(md) OR EMPTY(dal)
	*!*	IF RECCOUNT()>0
	*!*		SCAN ALL 
	*!*			m.pz=neexp.pz
	*!*			m.castka=neexp.castka
	*!*			SELECT poznamka FROM u_ex_platby INTO CURSOR ppl WHERE pz=m.pz
	*!*			SCAN ALL 
	*!*				m.poznamka=ppl.poznamka
	*!*				SELECT u_doklady
	*!*				REPLACE ciastka WITH ciastka-m.castka FOR poznamka=m.poznamka
	*!*				SELECT ppl
	*!*			ENDSCAN 
	*!*			USE IN ppl
	*!*			SELECT neexp
	*!*		ENDSCAN
	*!*	ENDIF 
	*!*	DO pozavirej WITH "neexp"
	*** Az teraz mozem vytvorit cursor na export platieb do uctovnictva
	SELECT ciastka, md as ucet, "M" as strana, hs_md as stredisko,2 as dph FROM u_doklady INTO CURSOR u_id_trz READWRITE 
	SELECT u_dokl1
	REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
	REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
	REPLACE ALL danzakl WITH ciastka-dan
	SELECT SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka FROM u_dokl1 GROUP BY partner, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl2 READWRITE 
	REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
	SELECT SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2 FROM u_dokl2 GROUP BY partner, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl READWRITE 
	INSERT INTO u_id_trz (ciastka, ucet, strana, stredisko, dph) SELECT danzakl as ciastka, dal as ucet, "D" as strana, hs_dal as stredisko, IIF(EMPTY(dan),0,1) as dph FROM u_dokl
	INSERT INTO u_id_trz (ciastka, ucet, strana, stredisko, dph) SELECT dan as ciastka, dal2 as ucet, "D" as strana, hs_dal as stredisko, 2 as dph FROM u_dokl
ENDIF 
IF USED("u_id_obr") OR USED("u_id_trz")
	DO karat_id
ENDIF 
DO pozavirej WITH "u_id_obr, u_id_trz, u_doklady, u_dokl, u_dokl1, u_dokl2, u_ex_platby, u_ex_polozky, u_ex_obraty"

*!*	*** Faktury ***
IF (m.gcuct_hores)
	TRY 
		IF m.hor_sql
			USE hores_hf_rad IN 0 ALIAS hf_rad
			USE hores_hf_hlv IN 0 ALIAS hf_hlv
			=CURSORSETPROP("Buffering",5,"hf_rad")
			=CURSORSETPROP("Buffering",5,"hf_hlv")
		ELSE 
			SELECT 0
			USE (m.hor_path+"hf_hlv") IN 0 SHARED 
			USE (m.hor_path+"hf_rad") IN 0 SHARED 
		ENDIF 
	CATCH
		=MESSAGEBOX(jaz("form_nedostupne_tab_horesu"),64,"FoodMan",2000)
	ENDTRY 
ENDIF 
IF !USED("hf_hlv") OR !USED("hf_rad")
	DO pozavirej WITH "hf_hlv, hf_rad"
	RETURN
ENDIF 
PRIVATE m.exportuj
m.exportuj=.t.
LOCAL m.oldproc
m.oldproc=SET("procedure")
SET PROCEDURE TO uexsk ADDITIVE 
IF !testuexplt("WH","F")
	m.exportuj=.f.
ELSE
	SELECT uexplt1
	GO TOP 
	m.ucetf=ALLTRIM(uexplt1.md)
ENDIF 
SET PROCEDURE TO &oldproc
RELEASE m.oldproc
IF !m.exportuj
	=MESSAGEBOX(jaz("form_chybaju_ucty_pre_faktury"),16,"",2000)
	RETURN
ENDIF 
IF USED("alto_hlavicky")
	SELECT alto_hlavicky
	DELETE ALL 
ELSE
	CREATE CURSOR alto_hlavicky (cislo c(8),datsku d, ico c(15), dic c(20), icdph c(20), adr1 c(30), adr2 c(30), adr3 c(30), adr4 c(30), d_splat d, d_vyst d, d_pln d, typuhr c(30), zaloha n(13,2), cel_kc n(13,2), vystav c(25), stat c(30), poloziek I, typfaktury I, mena c(3))
ENDIF 
SELECT hf_hlv
IF USED("alto_polozky")
	SELECT alto_polozky
	DELETE ALL 
ELSE
	CREATE CURSOR alto_polozky (cislo c(8), rastr c(3), cena n(13,2), dan n(13,2), zaloha n(13,2), ucet c(8), strana I, poradie I, ucetdan c(8), text1 c(50), dph n(4,1), nom c(8))
ENDIF 
SELECT hf_hlv
SCAN FOR (LEFT(DTOS(hf_hlv.datum),6)=(m.mrok+m.mmesiac) OR LEFT(DTOS(hf_hlv.opr_dat),6)=(m.mrok+m.mmesiac)) AND RIGHT(pozn3,1)<>"-"
	SCATTER MEMVAR
	m.icdph=ALLTRIM(SUBSTR(m.ico,16))
	m.ico=ALLTRIM(LEFT(m.ico,15))
	SELECT hf_rad
	m.poloziek=0
	m.sumacelkom=0
	m.sumazaloha=0
	m.exportuj=.t.
	LOCAL m.oldproc
	m.oldproc=SET("procedure")
	SET PROCEDURE TO uexsk ADDITIVE 
	SCAN FOR cislo=m.cislo AND !EMPTY(rastr) AND stav<>"S"
		m.poloziek=m.poloziek+1
		m.sumacelkom=m.sumacelkom+hf_rad.cena
		m.sumazaloha=m.sumazaloha+m.zaloha
		m.sd1=1+hf_rad.dph/100
		IF testuexpolhores(hf_rad.rastr,m.sd1)
			SELECT uexpol1
			m.ucet=uexpol1.dal
			m.ucetdan=uexpol1.dal2
			m.nom=ALLTRIM(uexpol1.hs_md)
		ELSE 
			m.exportuj=.f.
			m.ucet=""
			m.ucetdan=""
			m.nom=""
		ENDIF 
		IF m.exportuj
			INSERT INTO alto_polozky (cislo, rastr, cena, dan, zaloha, poradie, ucet, ucetdan, text1, dph, nom) VALUES (hf_rad.cislo, hf_rad.rastr, hf_rad.cena, hf_rad.dan, hf_rad.zaloha, m.poloziek, m.ucet, m.ucetdan, IIF(INLIST(LEFT(hf_rad.text1,4),"Ind.","Skp."),ALLTRIM(SUBSTR(hf_rad.text1,5)),hf_rad.text1), hf_rad.dph, m.nom)
		ENDIF 
	ENDSCAN
	SET PROCEDURE TO &oldproc
	RELEASE m.oldproc
	IF m.exportuj
		IF m.sumacelkom=m.sumazaloha
			m.typfaktury=1   && doklad k prijatej zalohe
		ELSE
			m.typfaktury=2   && vyuctovacia faktura
		ENDIF 
		INSERT INTO alto_hlavicky FROM MEMVAR 
		SELECT hf_hlv
		REPLACE pozn3 WITH LEFT(pozn3,LEN(pozn3)-1)+"-"
	ELSE
		SELECT alto_polozky
		DELETE FOR cislo=m.cislo
	ENDIF 
	
ENDSCAN
PRIVATE rowhl, rowpol, m.menoexp, m.filehl, m.filepol, m.porpol
SET ENGINEBEHAVIOR 70
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
m.gcuexp_path=ALLTRIM(IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path))
IF ! DIRECTORY(m.gcuexp_path)
	MKDIR (m.gcuexp_path)
ENDIF
SET CENTURY ON
IF USED("alto_hlavicky")
	m.rowhl=RECCOUNT("alto_hlavicky")
ELSE
	m.rowhl=0
ENDIF 
IF m.rowhl>0
	m.menoexp=m.gcuexp_path+"fv_zahlavi_f"+m.pismeno+"_"+m.mrok+m.mmesiac+".xm"
	IF FILE(m.menoexp)
		ERASE (m.menoexp)
	ENDIF 
	m.filehl=FCREATE(m.menoexp)
	m.menoexp=m.gcuexp_path+"fv_polozky_f"+m.pismeno+"_"+m.mrok+m.mmesiac+".xm"
	IF FILE(m.menoexp)
		ERASE (m.menoexp)
	ENDIF 
	m.filepol=FCREATE(m.menoexp)
	IF m.filehl>0 AND m.filepol>0
		=FPUTS(m.filehl,'<?xml version="1.0" encoding="windows-1250" standalone="no"?>')
		=FPUTS(m.filepol,'<?xml version="1.0" encoding="windows-1250" standalone="no"?>')
		=FPUTS(m.filehl,'<tabulka id="fv_zahlavi" forimport="Ano">')
		=FPUTS(m.filepol,'<tabulka id="fv_polozky" forimport="Ano">')
		SELECT alto_hlavicky
		m.rowhl=1
		m.rowpol=1
		SCAN ALL 
			=FPUTS(m.filehl,'	<row id="'+ALLTRIM(STR(m.rowhl,10,0))+'">')
			=FPUTS(m.filehl,'		<doklad>'+ALLTRIM(alto_hlavicky.cislo)+'</doklad>')
			=FPUTS(m.filehl,'		<druh_dokladu>VT</druh_dokladu>')
			=FPUTS(m.filehl,'		<typ_dokladu>'+ALLTRIM(m.karat_typ_dokladu)+'</typ_dokladu>')
			=FPUTS(m.filehl,'		<datsku>'+STR(YEAR(alto_hlavicky.d_pln),4,0)+'-'+STRTRAN(STR(MONTH(alto_hlavicky.d_pln),2,0),' ','0')+'-'+STRTRAN(STR(DAY(alto_hlavicky.d_pln),2,0),' ','0')+'</datsku>')
			=FPUTS(m.filehl,'		<ico>'+IIF(EMPTY(alto_hlavicky.ico),ALLTRIM(alto_hlavicky.adr1),ALLTRIM(alto_hlavicky.ico))+'</ico>')
			=FPUTS(m.filehl,'		<dic>'+ALLTRIM(alto_hlavicky.dic)+'</dic>')
			=FPUTS(m.filehl,'		<icdph>'+ALLTRIM(alto_hlavicky.icdph)+'</icdph>')
			=FPUTS(m.filehl,'		<zkraceny_nazev>'+ALLTRIM(STRTRAN(STRTRAN(alto_hlavicky.adr1,"&","&amp;"),"'","&apos;"))+'</zkraceny_nazev>')
			=FPUTS(m.filehl,'		<dat_vyst>'+STR(YEAR(alto_hlavicky.d_vyst),4,0)+'-'+STRTRAN(STR(MONTH(alto_hlavicky.d_vyst),2,0),' ','0')+'-'+STRTRAN(STR(DAY(alto_hlavicky.d_vyst),2,0),' ','0')+'</dat_vyst>')
			=FPUTS(m.filehl,'		<dat_spl>'+STR(YEAR(alto_hlavicky.d_splat),4,0)+'-'+STRTRAN(STR(MONTH(alto_hlavicky.d_splat),2,0),' ','0')+'-'+STRTRAN(STR(DAY(alto_hlavicky.d_splat),2,0),' ','0')+'</dat_spl>')
			=FPUTS(m.filehl,'		<dat_zd_pln>'+STR(YEAR(alto_hlavicky.d_pln),4,0)+'-'+STRTRAN(STR(MONTH(alto_hlavicky.d_pln),2,0),' ','0')+'-'+STRTRAN(STR(DAY(alto_hlavicky.d_pln),2,0),' ','0')+'</dat_zd_pln>')
			=FPUTS(m.filehl,'		<ucet>'+m.ucetf+'</ucet>')
			=FPUTS(m.filehl,'		<stredisko>'+ALLTRIM(m.karat_stredisko)+'</stredisko>')
			=FPUTS(m.filehl,'		<dealer>'+ALLTRIM(alto_hlavicky.vystav)+'</dealer>')
			=FPUTS(m.filehl,'		<var_symbol>'+ALLTRIM(alto_hlavicky.cislo)+'</var_symbol>') && cislo musi byt preformatovane tak, ako sa tlaci na fakture
			=FPUTS(m.filehl,'		<forma_uhrady>'+IIF('hoto'$LOWER(alto_hlavicky.typuhr),'PH','PP')+'</forma_uhrady>')
			=FPUTS(m.filehl,'		<id_meny>'+ALLTRIM(alto_hlavicky.mena)+'</id_meny>')
			=FPUTS(m.filehl,'		<f_text_1>'+ALLTRIM(STRTRAN(STRTRAN(alto_hlavicky.adr1,"&","&amp;"),"'","&apos;"))+'</f_text_1>')
			=FPUTS(m.filehl,'		<ulice>'+ALLTRIM(STRTRAN(STRTRAN(alto_hlavicky.adr2,"&","&amp;"),"'","&apos;"))+'</ulice>')
			=FPUTS(m.filehl,'		<obec>'+ALLTRIM(STRTRAN(STRTRAN(alto_hlavicky.adr3,"&","&amp;"),"'","&apos;"))+'</obec>')
			=FPUTS(m.filehl,'		<psc>'+ALLTRIM(STRTRAN(STRTRAN(alto_hlavicky.adr4,"&","&amp;"),"'","&apos;"))+'</psc>')
			=FPUTS(m.filehl,'		<stat>'+ALLTRIM(alto_hlavicky.stat)+'</stat>')
			=FPUTS(m.filehl,'	</row>')
			m.rowhl=m.rowhl+1
			SELECT alto_polozky
			m.porpol=1
			SCAN FOR cislo=alto_hlavicky.cislo
				IF alto_hlavicky.typfaktury=1 && doklad k prijatej platbe - exportuje sa +dph a zaklad + aj -
					=FPUTS(m.filepol,'	<row id="'+ALLTRIM(STR(m.rowpol,10,0))+'">')
					=FPUTS(m.filepol,'		<doklad>'+ALLTRIM(alto_polozky.cislo)+'</doklad>')
					=FPUTS(m.filepol,'		<poradi>'+ALLTRIM(STR(m.porpol,10,0))+'</poradi>')
*					=FPUTS(m.filepol,'		<nomenklatura>'+ALLTRIM(m.karat_nomenklatura)+'</nomenklatura>')
					=FPUTS(m.filepol,'		<nomenklatura>'+ALLTRIM(alto_polozky.ucet)+'</nomenklatura>')
					=FPUTS(m.filepol,'		<nazev>'+ALLTRIM(alto_polozky.text1)+'</nazev>')
					=FPUTS(m.filepol,'		<mnozstvi_vyd>1</mnozstvi_vyd>')
					=FPUTS(m.filepol,'		<mj_vyd>ks</mj_vyd>')
					=FPUTS(m.filepol,'		<dealer>'+alto_hlavicky.vystav+'</dealer>')
					=FPUTS(m.filepol,'		<cena_cenik>'+ALLTRIM(STR(alto_polozky.cena-alto_polozky.dan,13,2))+'</cena_cenik>')
					=FPUTS(m.filepol,'		<strana>2</strana>') && 2 = dal
					=FPUTS(m.filepol,'		<ucet>'+ALLTRIM(alto_polozky.ucet)+'</ucet>')
					=FPUTS(m.filepol,'		<stredisko>'+ALLTRIM(alto_polozky.nom)+'</stredisko>')
					=FPUTS(m.filepol,'		<dph_sazba>'+ALLTRIM(STR(alto_polozky.dph,10,0))+'</dph_sazba>')
					=FPUTS(m.filepol,'	</row>')
					m.porpol=m.porpol+1
					m.rowpol=m.rowpol+1
					=FPUTS(m.filepol,'	<row id="'+ALLTRIM(STR(m.rowpol,10,0))+'">')
					=FPUTS(m.filepol,'		<doklad>'+ALLTRIM(alto_polozky.cislo)+'</doklad>')
					=FPUTS(m.filepol,'		<poradi>'+ALLTRIM(STR(m.porpol,10,0))+'</poradi>')
					=FPUTS(m.filepol,'		<nomenklatura>'+ALLTRIM(alto_polozky.ucet)+'</nomenklatura>')
					=FPUTS(m.filepol,'		<nazev>'+ALLTRIM(alto_polozky.text1)+'</nazev>')
					=FPUTS(m.filepol,'		<mnozstvi_vyd>1</mnozstvi_vyd>')
					=FPUTS(m.filepol,'		<mj_vyd>ks</mj_vyd>')
					=FPUTS(m.filepol,'		<dealer>'+alto_hlavicky.vystav+'</dealer>')
					=FPUTS(m.filepol,'		<cena_cenik>'+ALLTRIM(STR(alto_polozky.dan-alto_polozky.cena,13,2))+'</cena_cenik>')
					=FPUTS(m.filepol,'		<strana>2</strana>') && 2 = dal
					=FPUTS(m.filepol,'		<ucet>'+ALLTRIM(alto_polozky.ucet)+'</ucet>')
					=FPUTS(m.filepol,'		<stredisko>'+ALLTRIM(alto_polozky.nom)+'</stredisko>')
					=FPUTS(m.filepol,'		<dph_sazba>'+ALLTRIM(STR(alto_polozky.dph,10,0))+'</dph_sazba>')
					=FPUTS(m.filepol,'	</row>')
					m.porpol=m.porpol+1
					m.rowpol=m.rowpol+1
					=FPUTS(m.filepol,'	<row id="'+ALLTRIM(STR(m.rowpol,10,0))+'">')
					=FPUTS(m.filepol,'		<doklad>'+ALLTRIM(alto_polozky.cislo)+'</doklad>')
					=FPUTS(m.filepol,'		<poradi>'+ALLTRIM(STR(m.porpol,10,0))+'</poradi>')
					=FPUTS(m.filepol,'		<nomenklatura>'+ALLTRIM(alto_polozky.ucet)+'</nomenklatura>')
					=FPUTS(m.filepol,'		<nazev>'+ALLTRIM(alto_polozky.text1)+'</nazev>')
					=FPUTS(m.filepol,'		<mnozstvi_vyd>1</mnozstvi_vyd>')
					=FPUTS(m.filepol,'		<mj_vyd>ks</mj_vyd>')
					=FPUTS(m.filepol,'		<dealer>'+ALLTRIM(alto_hlavicky.vystav)+'</dealer>')
					=FPUTS(m.filepol,'		<cena_cenik>'+ALLTRIM(STR(alto_polozky.dan,13,2))+'</cena_cenik>')
					=FPUTS(m.filepol,'		<strana>2</strana>') && 2 = dal
					=FPUTS(m.filepol,'		<ucet>'+ALLTRIM(alto_polozky.ucetdan)+'</ucet>')
					=FPUTS(m.filepol,'		<stredisko>'+ALLTRIM(alto_polozky.nom)+'</stredisko>')
					=FPUTS(m.filepol,'		<dph_sazba>'+ALLTRIM(STR(alto_polozky.dph,10,0))+'</dph_sazba>')
					=FPUTS(m.filepol,'	</row>')
					m.porpol=m.porpol+1
					m.rowpol=m.rowpol+1
				ELSE
					=FPUTS(m.filepol,'	<row id="'+ALLTRIM(STR(m.rowpol,10,0))+'">')
					=FPUTS(m.filepol,'		<doklad>'+ALLTRIM(alto_polozky.cislo)+'</doklad>')
					=FPUTS(m.filepol,'		<poradi>'+ALLTRIM(STR(m.porpol,10,0))+'</poradi>')
					=FPUTS(m.filepol,'		<nomenklatura>'+ALLTRIM(alto_polozky.ucet)+'</nomenklatura>')
					=FPUTS(m.filepol,'		<nazev>'+ALLTRIM(alto_polozky.text1)+'</nazev>')
					=FPUTS(m.filepol,'		<mnozstvi_vyd>1</mnozstvi_vyd>')
					=FPUTS(m.filepol,'		<mj_vyd>ks</mj_vyd>')
					=FPUTS(m.filepol,'		<dealer>'+ALLTRIM(alto_hlavicky.vystav)+'</dealer>')
					=FPUTS(m.filepol,'		<cena_cenik>'+ALLTRIM(STR(alto_polozky.cena-alto_polozky.dan,13,2))+'</cena_cenik>')
					=FPUTS(m.filepol,'		<strana>2</strana>') && 2 = dal
					=FPUTS(m.filepol,'		<ucet>'+ALLTRIM(alto_polozky.ucet)+'</ucet>')
					=FPUTS(m.filepol,'		<stredisko>'+ALLTRIM(alto_polozky.nom)+'</stredisko>')
					=FPUTS(m.filepol,'		<dph_sazba>'+ALLTRIM(STR(alto_polozky.dph,10,0))+'</dph_sazba>')
					=FPUTS(m.filepol,'	</row>')
					m.porpol=m.porpol+1
					m.rowpol=m.rowpol+1
					=FPUTS(m.filepol,'	<row id="'+ALLTRIM(STR(m.rowpol,10,0))+'">')
					=FPUTS(m.filepol,'		<doklad>'+ALLTRIM(alto_polozky.cislo)+'</doklad>')
					=FPUTS(m.filepol,'		<poradi>'+ALLTRIM(STR(m.porpol,10,0))+'</poradi>')
					=FPUTS(m.filepol,'		<nomenklatura>'+ALLTRIM(alto_polozky.ucet)+'</nomenklatura>')
					=FPUTS(m.filepol,'		<nazev>'+ALLTRIM(alto_polozky.text1)+'</nazev>')
					=FPUTS(m.filepol,'		<mnozstvi_vyd>1</mnozstvi_vyd>')
					=FPUTS(m.filepol,'		<mj_vyd>ks</mj_vyd>')
					=FPUTS(m.filepol,'		<dealer>'+ALLTRIM(alto_hlavicky.vystav)+'</dealer>')
					=FPUTS(m.filepol,'		<cena_cenik>'+ALLTRIM(STR(alto_polozky.dan,13,2))+'</cena_cenik>')
					=FPUTS(m.filepol,'		<strana>2</strana>') && 2 = dal
					=FPUTS(m.filepol,'		<ucet>'+ALLTRIM(alto_polozky.ucetdan)+'</ucet>')
					=FPUTS(m.filepol,'		<stredisko>'+ALLTRIM(alto_polozky.nom)+'</stredisko>')
					=FPUTS(m.filepol,'		<dph_sazba>'+ALLTRIM(STR(alto_polozky.dph,10,0))+'</dph_sazba>')
					=FPUTS(m.filepol,'	</row>')
					m.porpol=m.porpol+1
					m.rowpol=m.rowpol+1
				ENDIF 
			ENDSCAN 
			SELECT alto_hlavicky
		ENDSCAN
		=FPUTS(m.filehl,'</tabulka>')
		=FPUTS(m.filepol,'</tabulka>')
		=FCLOSE(m.filehl)
		=FCLOSE(m.filepol)
		pocet = ADIR(soubory, m.gcuexp_path + "*.xm")
		FOR iii = 1 TO pocet
			RENAME (m.gcuexp_path+soubory(iii, 1)) TO (m.gcuexp_path+ALLTRIM(soubory(iii, 1))+"l")
		ENDFOR
		DO pozavirej WITH "soubory"
	ELSE
		=MESSAGEBOX(jaz("form_nevytvoreny_subor"),16,"FoodMan",2000)
	ENDIF 
ELSE
	=MESSAGEBOX(jaz("form_no_faktury_na_export"),64,"",2000)
ENDIF
IF m.hor_sql
	=tux(.t.,.t.,"hf_hlv")
ENDIF 
DO pozavirej WITH "alto_hlavicky, alto_polozky, hf_hlv, hf_rad"


PROCEDURE karat_id
PRIVATE datz, m.menoexp, m.filehl, m.filepol, m.poloziek
LOCAL dodatok
m.datz=GOMONTH(CTOD("01."+m.mmesiac+"."+m.mrok),1)-1
m.dodatok=STRTRAN(STRTRAN(STRTRAN(TTOC(DATETIME())," ",""),".",""),":","")+"_"+SYS(2015)
m.menoexp=m.gcuexp_path+"vnitro_h_"+m.pismeno+"s_"+m.mrok+m.mmesiac+"_"+m.dodatok+".xm"
IF FILE(m.menoexp)
	ERASE (m.menoexp)
ENDIF 
m.filehl=FCREATE(m.menoexp)
m.menoexp=m.gcuexp_path+"vnitro_p_"+m.pismeno+"s_"+m.mrok+m.mmesiac+"_"+m.dodatok+".xm"
IF FILE(m.menoexp)
	ERASE (m.menoexp)
ENDIF 
m.filepol=FCREATE(m.menoexp)
m.rowhl=0
m.rowpol=0
IF m.filehl>0 AND m.filepol>0
	=FPUTS(m.filehl,'<?xml version="1.0" encoding="windows-1250" standalone="no"?>')
	=FPUTS(m.filepol,'<?xml version="1.0" encoding="windows-1250" standalone="no"?>')
	=FPUTS(m.filehl,'<tabulka id="vnitro_h" forimport="Ano">')
	=FPUTS(m.filepol,'<tabulka id="vnitro_p" forimport="Ano">')
	IF USED("u_id_obr") AND RECCOUNT("u_id_obr")>0
		SELECT u_id_obr
		m.rowhl=m.rowhl+1
		m.poloziek=0
		SCAN FOR !EMPTY(u_id_obr.md) AND !EMPTY(u_id_obr.ciastka) 
				m.rowpol=m.rowpol+1
				m.poloziek=m.poloziek+1
				=FPUTS(m.filepol,'	<row id="'+ALLTRIM(STR(m.rowpol,10,0))+'">')
				=FPUTS(m.filepol,'		<doklad>'+ALLTRIM(m.karat_stredisko)+m.mrok+m.mmesiac+'01'+'</doklad>')
				=FPUTS(m.filepol,'		<poradi>'+ALLTRIM(STR(m.poloziek,10,0))+'</poradi>')
				=FPUTS(m.filepol,'		<datsku>'+STR(YEAR(m.datz),4,0)+'-'+STRTRAN(STR(MONTH(m.datz),2,0),' ','0')+'-'+STRTRAN(STR(DAY(m.datz),2,0),' ','0')+'</datsku>')
				=FPUTS(m.filepol,'		<strana>1</strana>') && 1 = md
				=FPUTS(m.filepol,'		<ucet>'+ALLTRIM(u_id_obr.md)+'</ucet>')
				=FPUTS(m.filepol,'		<stredisko>'+ALLTRIM(u_id_obr.hs_md)+'</stredisko>')
				=FPUTS(m.filepol,'		<devizy>'+ALLTRIM(STR(u_id_obr.ciastka,13,2))+'</devizy>')
				=FPUTS(m.filepol,'		<id_meny>EUR</id_meny>')
				=FPUTS(m.filepol,'		<ext_cislo>'+ALLTRIM(m.karat_stredisko)+m.mrok+m.mmesiac+'01'+'</ext_cislo>')
				=FPUTS(m.filepol,'	</row>')
				m.rowpol=m.rowpol+1
				m.poloziek=m.poloziek+1
				=FPUTS(m.filepol,'	<row id="'+ALLTRIM(STR(m.rowpol,10,0))+'">')
				=FPUTS(m.filepol,'		<doklad>'+ALLTRIM(m.karat_stredisko)+m.mrok+m.mmesiac+'01'+'</doklad>')
				=FPUTS(m.filepol,'		<poradi>'+ALLTRIM(STR(m.poloziek,10,0))+'</poradi>')
				=FPUTS(m.filepol,'		<datsku>'+STR(YEAR(m.datz),4,0)+'-'+STRTRAN(STR(MONTH(m.datz),2,0),' ','0')+'-'+STRTRAN(STR(DAY(m.datz),2,0),' ','0')+'</datsku>')
				=FPUTS(m.filepol,'		<strana>2</strana>') && 1 = md
				=FPUTS(m.filepol,'		<ucet>'+ALLTRIM(u_id_obr.dal)+'</ucet>')
				=FPUTS(m.filepol,'		<stredisko>'+ALLTRIM(u_id_obr.hs_md)+'</stredisko>')
				=FPUTS(m.filepol,'		<devizy>'+ALLTRIM(STR(u_id_obr.ciastka,13,2))+'</devizy>')
				=FPUTS(m.filepol,'		<id_meny>EUR</id_meny>')
				=FPUTS(m.filepol,'		<ext_cislo>'+ALLTRIM(m.karat_stredisko)+m.mrok+m.mmesiac+'01'+'</ext_cislo>')
				=FPUTS(m.filepol,'	</row>')
		ENDSCAN 
		=FPUTS(m.filehl,'	<row id="'+ALLTRIM(STR(m.rowhl,10,0))+'">')
		=FPUTS(m.filehl,'		<doklad>'+ALLTRIM(m.karat_stredisko)+m.mrok+m.mmesiac+'01'+'</doklad>')
		=FPUTS(m.filehl,'		<datsku>'+STR(YEAR(m.datz),4,0)+'-'+STRTRAN(STR(MONTH(m.datz),2,0),' ','0')+'-'+STRTRAN(STR(DAY(m.datz),2,0),' ','0')+'</datsku>')
		=FPUTS(m.filehl,'		<stredisko>'+ALLTRIM(m.karat_stredisko)+'</stredisko>')
		=FPUTS(m.filehl,'		<rada>'+ALLTRIM(m.karat_ciselny_rad)+'</rada>')
		=FPUTS(m.filehl,'		<polozek>'+ALLTRIM(STR(m.poloziek,10,0))+'</polozek>')
		=FPUTS(m.filehl,'	</row>')
		=FPUTS(m.filehl,'</tabulka>')
		=FPUTS(m.filepol,'</tabulka>')
		=FCLOSE(m.filehl)
		=FCLOSE(m.filepol)
	ELSE 
		=FPUTS(m.filehl,'</tabulka>')
		=FPUTS(m.filepol,'</tabulka>')
		=FCLOSE(m.filehl)
		=FCLOSE(m.filepol)
		m.menoexp=m.gcuexp_path+"vnitro_h_"+m.pismeno+"s_"+m.mrok+m.mmesiac+"_"+m.dodatok+".xm"
		IF FILE(m.menoexp)
			ERASE (m.menoexp)
		ENDIF 
		m.menoexp=m.gcuexp_path+"vnitro_p_"+m.pismeno+"s_"+m.mrok+m.mmesiac+"_"+m.dodatok+".xm"
		IF FILE(m.menoexp)
			ERASE (m.menoexp)
		ENDIF 
	ENDIF 
ELSE
	=MESSAGEBOX(jaz("form_nevytvoreny_subor"),16,"FoodMan",2000)
ENDIF 
m.menoexp=m.gcuexp_path+"vnitro_h_"+m.pismeno+"t_"+m.mrok+m.mmesiac+"_"+m.dodatok+".xm"
IF FILE(m.menoexp)
	ERASE (m.menoexp)
ENDIF 
m.filehl=FCREATE(m.menoexp)
m.menoexp=m.gcuexp_path+"vnitro_p_"+m.pismeno+"t_"+m.mrok+m.mmesiac+"_"+m.dodatok+".xm"
IF FILE(m.menoexp)
	ERASE (m.menoexp)
ENDIF 
m.filepol=FCREATE(m.menoexp)
m.rowhl=0
m.rowpol=0
IF m.filehl>0 AND m.filepol>0
	=FPUTS(m.filehl,'<?xml version="1.0" encoding="windows-1250" standalone="no"?>')
	=FPUTS(m.filepol,'<?xml version="1.0" encoding="windows-1250" standalone="no"?>')
	=FPUTS(m.filehl,'<tabulka id="vnitro_h" forimport="Ano">')
	=FPUTS(m.filepol,'<tabulka id="vnitro_p" forimport="Ano">')
	IF USED("u_id_trz") AND RECCOUNT("u_id_trz")>0
		SELECT u_id_trz
		m.rowhl=m.rowhl+1
		m.poloziek=0
		SCAN FOR !EMPTY(u_id_trz.ucet) AND !EMPTY(u_id_trz.ciastka)
			m.rowpol=m.rowpol+1
			m.poloziek=m.poloziek+1
			=FPUTS(m.filepol,'	<row id="'+ALLTRIM(STR(m.rowpol,10,0))+'">')
			=FPUTS(m.filepol,'		<doklad>'+ALLTRIM(m.karat_stredisko)+m.mrok+m.mmesiac+'02'+'</doklad>')
			=FPUTS(m.filepol,'		<poradi>'+ALLTRIM(STR(m.poloziek,10,0))+'</poradi>')
			=FPUTS(m.filepol,'		<datsku>'+STR(YEAR(m.datz),4,0)+'-'+STRTRAN(STR(MONTH(m.datz),2,0),' ','0')+'-'+STRTRAN(STR(DAY(m.datz),2,0),' ','0')+'</datsku>')
			=FPUTS(m.filepol,'		<strana>'+IIF(u_id_trz.strana='M','1','2')+'</strana>') && 1 = md,2-dal
			=FPUTS(m.filepol,'		<ucet>'+ALLTRIM(u_id_trz.ucet)+'</ucet>')
			IF u_id_trz.dph<>2
				=FPUTS(m.filepol,'		<dph>'+ALLTRIM(STR(u_id_trz.dph,1,0))+'</dph>')
			ENDIF 
*			=FPUTS(m.filepol,'		<stredisko>'+ALLTRIM(m.karat_stredisko)+'</stredisko>')
			=FPUTS(m.filepol,'		<stredisko>'+ALLTRIM(u_id_trz.stredisko)+'</stredisko>')
			=FPUTS(m.filepol,'		<devizy>'+ALLTRIM(STR(u_id_trz.ciastka,13,2))+'</devizy>')
			=FPUTS(m.filepol,'		<id_meny>EUR</id_meny>')
			=FPUTS(m.filepol,'		<ext_cislo>'+ALLTRIM(m.karat_stredisko)+m.mrok+m.mmesiac+'02'+'</ext_cislo>')
			=FPUTS(m.filepol,'	</row>')
		ENDSCAN 
		=FPUTS(m.filehl,'	<row id="'+ALLTRIM(STR(m.rowhl,10,0))+'">')
		=FPUTS(m.filehl,'		<doklad>'+ALLTRIM(m.karat_stredisko)+m.mrok+m.mmesiac+'02'+'</doklad>')
		=FPUTS(m.filehl,'		<datsku>'+STR(YEAR(m.datz),4,0)+'-'+STRTRAN(STR(MONTH(m.datz),2,0),' ','0')+'-'+STRTRAN(STR(DAY(m.datz),2,0),' ','0')+'</datsku>')
		=FPUTS(m.filehl,'		<stredisko>'+ALLTRIM(m.karat_stredisko)+'</stredisko>')
		=FPUTS(m.filehl,'		<rada>'+ALLTRIM(m.karat_ciselny_rad)+'</rada>')
		=FPUTS(m.filehl,'		<polozek>'+ALLTRIM(STR(m.poloziek,10,0))+'</polozek>')
		=FPUTS(m.filehl,'	</row>')
		=FPUTS(m.filehl,'</tabulka>')
		=FPUTS(m.filepol,'</tabulka>')
		=FCLOSE(m.filehl)
		=FCLOSE(m.filepol)
	ELSE 
		=FPUTS(m.filehl,'</tabulka>')
		=FPUTS(m.filepol,'</tabulka>')
		=FCLOSE(m.filehl)
		=FCLOSE(m.filepol)
		m.menoexp=m.gcuexp_path+"vnitro_h_"+m.pismeno+"t_"+m.mrok+m.mmesiac+"_"+m.dodatok+".xm"
		IF FILE(m.menoexp)
			ERASE (m.menoexp)
		ENDIF 
		m.menoexp=m.gcuexp_path+"vnitro_p_"+m.pismeno+"t_"+m.mrok+m.mmesiac+"_"+m.dodatok+".xm"
		IF FILE(m.menoexp)
			ERASE (m.menoexp)
		ENDIF 
	ENDIF 
ELSE
	=MESSAGEBOX(jaz("form_nevytvoreny_subor"),16,"FoodMan",2000)
ENDIF 
pocet = ADIR(soubory, m.gcuexp_path + "*.xm")
FOR iii = 1 TO pocet
	RENAME (m.gcuexp_path+soubory(iii, 1)) TO (m.gcuexp_path+ALLTRIM(soubory(iii, 1))+"l")
ENDFOR
DO pozavirej WITH "soubory"

PROCEDURE gen_exp_money
PARAMETERS m.mrok, m.mmesiac
PRIVATE kthotel,oddelovac,bolipartneri,oddelovac,cislodokladu,oldsetdele, m.nom, m.pismeno
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.mrok
m.hladajmesiac=m.mmesiac
m.oldsetdele=SET("dele")
SET DELETED ON
gen_exp_had = CREATEOBJECT("had", jaz("form_generovanie_suborov_ucto"))
gen_exp_had.SHOW()
gen_exp_had.set_max(20)
m.oddelovac=" "
m.nom=""
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
IF USED("u_ex_obraty")
	SELECT datum,id_man, SUM(castka) AS ciastka,MD,dal,hs_md,hs_dal,pz,partner,STR(doklad,10,0) as doklad,datum_dokl,poznamka FROM u_ex_obraty GROUP BY id_man,pz,datum,doklad,datum_dokl,MD,dal INTO CURSOR uidobr WHERE !EMPTY(datum) READWRITE 
	REPLACE ciastka WITH -ciastka FOR LEFT(pz,1)="V"
	IF m.gcuct_inv_plus_i_min
		LOCAL m.manko_md, m.manko_dal, m.manko_hsmd, m.manko_hsdal, m.manko_idman, m.manko_druh, m.manko_partner, m.manko_cdokl
		SELECT u_ex_obraty
		SCAN FOR castka<0 AND operace="PI"
			m.manko_idman=u_ex_obraty.id_man
			m.manko_druh=u_ex_obraty.druh
			m.manko_partner=u_ex_obraty.partner
			m.manko_cdokl=u_ex_obraty.c_dokl
			IF testuexobr("PI", m.manko_druh, m.manko_partner, m.manko_idman, "-")
				SELECT uexobr1
				GO TOP 
				m.manko_md=ALLTRIM(uexobr1.md)
				m.manko_dal=ALLTRIM(uexobr1.dal)
				m.manko_hsmd=ALLTRIM(uexobr1.hs_md)
				m.manko_hsdal=ALLTRIM(uexobr1.hs_dal)
				SELECT u_ex_obraty
				REPLACE md WITH m.manko_md, dal WITH m.manko_dal, hs_md WITH m.manko_hsmd, hs_dal WITH m.manko_hsdal, castka WITH -castka
			ELSE 
				IF testuexobr("PI", "*", m.manko_partner, m.manko_idman, "-")
					SELECT uexobr1
					GO TOP 
					m.manko_md=ALLTRIM(uexobr1.md)
					m.manko_dal=ALLTRIM(uexobr1.dal)
					m.manko_hsmd=ALLTRIM(uexobr1.hs_md)
					m.manko_hsdal=ALLTRIM(uexobr1.hs_dal)
					SELECT u_ex_obraty
					REPLACE md WITH m.manko_md, dal WITH m.manko_dal, hs_md WITH m.manko_hsmd, hs_dal WITH m.manko_hsdal, castka WITH -castka
				ELSE 
					IF testuexobr("PI", m.manko_druh, "*", m.manko_idman, "-")
						SELECT uexobr1
						GO TOP 
						m.manko_md=ALLTRIM(uexobr1.md)
						m.manko_dal=ALLTRIM(uexobr1.dal)
						m.manko_hsmd=ALLTRIM(uexobr1.hs_md)
						m.manko_hsdal=ALLTRIM(uexobr1.hs_dal)
						SELECT u_ex_obraty
						REPLACE md WITH m.manko_md, dal WITH m.manko_dal, hs_md WITH m.manko_hsmd, hs_dal WITH m.manko_hsdal, castka WITH -castka
					ELSE 
						IF testuexobr("PI", "*", "*", m.manko_idman, "-")
							SELECT uexobr1
							GO TOP 
							m.manko_md=ALLTRIM(uexobr1.md)
							m.manko_dal=ALLTRIM(uexobr1.dal)
							m.manko_hsmd=ALLTRIM(uexobr1.hs_md)
							m.manko_hsdal=ALLTRIM(uexobr1.hs_dal)
							SELECT u_ex_obraty
							REPLACE md WITH m.manko_md, dal WITH m.manko_dal, hs_md WITH m.manko_hsmd, hs_dal WITH m.manko_hsdal, castka WITH -castka
						ENDIF 
					ENDIF 
				ENDIF 
			ENDIF 
		ENDSCAN 		
		RELEASE m.manko_md, m.manko_dal, m.manko_hsmd, m.manko_hsdal, m.manko_idman, m.manko_druh, m.manko_partner, m.manko_cdokl
	ENDIF 

	SELECT SUM(ciastka) AS ciastka, MD, dal, hs_md, hs_dal, poznamka, "P" as typ, $0 as dan, SPACE(40) as pz FROM uidobr GROUP BY MD,dal, poznamka INTO CURSOR u_id_obr READWRITE 
	REPLACE ALL poznamka WITH STRTRAN(poznamka, "OBR ","")
	USE IN uidobr
	*DELETE FOR EMPTY(datum)
	DELETE FOR ciastka=0
	*INDEX ON datum TAG aaa
ENDIF 
gen_exp_had.INCREMENT("Tržby")
IF USED("u_ex_platby") AND USED("u_ex_polozky")
	SELECT SUM(castka) AS ciastka, MD,dal,md2,dal2,hs_dal,hs_md,partner,poznamka, pz FROM u_ex_platby GROUP BY pz, poznamka, MD, dal INTO CURSOR u_doklady READWRITE 
	SELECT SUM(castka) AS ciastka, MD,dal,hs_md, hs_dal,md2,dal2, partner,poznamka,$0 AS danzakl, $0 AS dan, poznamka as pozn, pz FROM u_ex_polozky GROUP BY pz, partner,poznamka,MD,dal INTO CURSOR u_dokl1 READWRITE 
	REPLACE ALL pozn WITH STRTRAN(pozn,"POL HORES ","")
	REPLACE ALL pozn WITH STRTRAN(pozn,"POL ","")
	IF m.money_trzba_do_id
		IF USED("u_id_obr")
			INSERT INTO u_id_obr (ciastka, md, dal, hs_md, hs_dal, typ, poznamka, dan, pz) SELECT ciastka, md, dal, hs_md, hs_dal,"P" as typ, poznamka, $0 as dan, pz FROM u_doklady  
		ELSE
			SELECT ciastka, md, dal, hs_md, hs_dal,"P" as typ, poznamka, $0 as dan, pz FROM u_doklady  INTO CURSOR u_id_obr READWRITE 
		ENDIF 
		SELECT u_dokl1
		REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
		REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
		REPLACE ALL danzakl WITH ciastka-dan
		SELECT SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka, pozn FROM u_dokl1 GROUP BY partner, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl2 READWRITE 
		REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
		SELECT SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2, pozn, poznamka FROM u_dokl2 GROUP BY partner, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl READWRITE 
		IF USED("u_id_obr")
			INSERT INTO u_id_obr (ciastka, md, dal, hs_md, hs_dal, typ, poznamka, dan) SELECT SUM(danzakl) as ciastka, md, dal, hs_md, hs_dal,"Z" as typ, pozn as poznamka, VAL(poznamka) as dan FROM u_dokl group by md, dal, hs_md, hs_dal, md2, dal2, pozn, poznamka
		ELSE
			SELECT SUM(danzakl) as ciastka, md, dal, hs_md, hs_dal,"Z" as typ, pozn as poznamka, VAL(poznamka) as dan FROM u_dokl group by md, dal, hs_md, hs_dal, md2, dal2, pozn, poznamka INTO CURSOR u_id_obr READWRITE 
		ENDIF 
		INSERT INTO u_id_obr (ciastka, md, dal, hs_md, hs_dal, typ, poznamka, dan) SELECT SUM(dan) as ciastka, md as md, dal2 as dal, hs_md, hs_dal, "D" as typ, pozn as poznamka, VAL(poznamka) as dan FROM u_dokl GROU BY md, dal2, hs_md, hs_dal, pozn, poznamka
	ELSE
		IF USED("u_id_trz")
			INSERT INTO u_id_trz (ciastka, md, dal, hs_md, hs_dal, typ, poznamka, dan, pz) SELECT ciastka, md, dal, hs_md, hs_dal,"P" as typ, poznamka, $0 as dan, pz FROM u_doklady  
		ELSE
			SELECT ciastka, md, dal, hs_md, hs_dal,"P" as typ, poznamka, $0 as dan, pz, SPACE(8) as den FROM u_doklady  INTO CURSOR u_id_trz READWRITE 
		ENDIF 
		SELECT u_dokl1
		REPLACE ALL poznamka WITH SUBSTR(poznamka,RAT(" ",ALLTRIM(poznamka)))
		REPLACE ALL dan WITH ciastka*VAL(poznamka)/(100+VAL(poznamka))
		REPLACE ALL danzakl WITH ciastka-dan
		SELECT SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, md2, dal2,hs_md, hs_dal, poznamka, pozn, pz FROM u_dokl1 GROUP BY pz, partner, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl2 READWRITE 
		REPLACE ALL ciastka WITH ROUND(ciastka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
		SELECT SUM(ciastka) AS ciastka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, partner, MD, dal, hs_md, hs_dal, md2, dal2, pozn, poznamka, pz FROM u_dokl2 GROUP BY pz, partner, MD, dal, hs_md, hs_dal, poznamka INTO CURSOR u_dokl READWRITE 
		IF USED("u_id_trz")
			INSERT INTO u_id_trz (ciastka, md, dal, hs_md, hs_dal, typ, poznamka, dan, pz) SELECT SUM(danzakl) as ciastka, md, dal, hs_md, hs_dal,"Z" as typ, pozn as poznamka, VAL(poznamka) as dan, pz FROM u_dokl group by md, dal, hs_md, hs_dal, md2, dal2, pozn, poznamka, pz
		ELSE
			SELECT SUM(danzakl) as ciastka, md, dal, hs_md, hs_dal,"Z" as typ, pozn as poznamka, VAL(poznamka) as dan, pz, SPACE(8) as den FROM u_dokl group by md, dal, hs_md, hs_dal, md2, dal2, pozn, poznamka, pz INTO CURSOR u_id_trz READWRITE 
		ENDIF 
		INSERT INTO u_id_trz (ciastka, md, dal, hs_md, hs_dal, typ, poznamka, dan, pz) SELECT SUM(dan) as ciastka, md as md, dal2 as dal, hs_md, hs_dal, "D" as typ, pozn as poznamka, VAL(poznamka) as dan, pz FROM u_dokl GROU BY md, dal2, hs_md, hs_dal, pozn, poznamka, pz
		SELECT u_id_trz
		REPLACE ALL den WITH LEFT(pz,8)
	ENDIF 	
ENDIF 
IF USED("u_id_obr") AND RECCOUNT("u_id_obr")>0
	DO money_id
ENDIF 
IF USED("u_id_trz") AND RECCOUNT("u_id_trz")>0
	DO money_pokl_doklad
ENDIF 
DO pozavirej WITH "u_id_obr, u_doklady, u_dokl, u_dokl1, u_dokl2, u_ex_obraty, u_ex_platby, u_ex_polozky, u_id_trz"


*!*	*** Faktury ***
DO pozavirej WITH "hf_rad, hf_hlv, hfak, hfau, hras"
IF (m.gcuct_hores)
	TRY 
		IF m.hor_sql
			USE hores_hf_rad IN 0 ALIAS hf_rad
			USE hores_hf_hlv IN 0 ALIAS hf_hlv
			=CURSORSETPROP("Buffering",5,"hf_rad")
			=CURSORSETPROP("Buffering",5,"hf_hlv")
		ELSE 
			SELECT 0
			USE (m.hor_path+"hf_hlv") IN 0 SHARED 
			USE (m.hor_path+"hf_rad") IN 0 SHARED 
		ENDIF 
	CATCH
		DO pozavirej WITH "hf_rad, hf_hlv, hfak, hfau, hras"
		=MESSAGEBOX(jaz("form_nedostupne_tab_horesu"),64,"FoodMan",2000)
	ENDTRY 
ENDIF 
IF !USED("hf_hlv") OR !USED("hf_rad")
	DO pozavirej WITH "hf_hlv, hf_rad"
	RETURN
ENDIF 
PRIVATE m.exportuj
m.exportuj=.t.
LOCAL m.oldproc
m.oldproc=SET("procedure")
SET PROCEDURE TO uexsk ADDITIVE 
IF !testuexplt("WH","F")
	m.exportuj=.f.
ELSE
	SELECT uexplt1
	GO TOP 
	m.ucetf=ALLTRIM(uexplt1.md)
ENDIF 
SET PROCEDURE TO &oldproc
RELEASE m.oldproc

*!*	SELECT uexplt
*!*	LOCATE FOR (id_kas = "WH") .AND. ALLTRIM(druh_pl) = "F"
*!*	IF !FOUND()
*!*		INSERT INTO uexplt(id_kas, druh_pl, co, pz, poznamka, c_data) VALUES ("WH","F", "pole1", "DTOS(m.datum_dokl)", "Platba F HORES", m.cdata)
*!*		=tux(.t.,.t.,"uexplt")
*!*		=REQUERY("uexplt")
*!*		m.exportuj=.f.
*!*	ELSE
*!*		m.ucetf=ALLTRIM(u_ex_plt.md)
*!*	ENDIF
IF !m.exportuj
	=MESSAGEBOX(jaz("form_chybaju_ucty_pre_faktury"),16,"FoodMan",2000)
	DO pozavirej WITH "hf_rad, hf_hlv, hfak, hfau, hras"
	RETURN
ENDIF 
IF USED("alto_hlavicky")
	SELECT alto_hlavicky
	DELETE ALL 
ELSE
	CREATE CURSOR alto_hlavicky (cislo c(8),datsku d, ico c(15), dic c(20), icdph c(20), adr1 c(30), adr2 c(30), adr3 c(30), adr4 c(30), d_splat d, d_vyst d, d_pln d, typuhr c(30), zaloha n(13,2), cel_kc n(13,2), vystav c(25), stat c(30), poloziek I, typfaktury I, mena c(3))
ENDIF 
SELECT hf_hlv
IF USED("alto_polozky")
	SELECT alto_polozky
	DELETE ALL 
ELSE
	CREATE CURSOR alto_polozky (cislo c(8), rastr c(3), cena n(13,2), dan n(13,2), zaloha n(13,2), ucet c(8), strana I, poradie I, ucetdan c(8), text1 c(50), dph n(4,1), nom c(8), rezerv I, clenenie c(10))
ENDIF 
SELECT hf_hlv
SCAN FOR (LEFT(DTOS(hf_hlv.datum),6)=(m.mrok+m.mmesiac) OR LEFT(DTOS(hf_hlv.opr_dat),6)=(m.mrok+m.mmesiac)) AND RIGHT(pozn3,1)<>"-"
	SCATTER MEMVAR
	m.icdph=ALLTRIM(SUBSTR(m.ico,16))
	m.ico=ALLTRIM(LEFT(m.ico,15))
	SELECT hf_rad
	m.poloziek=0
	m.sumacelkom=0
	m.sumazaloha=0
	m.exportuj=.t.
	LOCAL m.oldproc
	m.oldproc=SET("procedure")
	SET PROCEDURE TO uexsk ADDITIVE 
	SCAN FOR cislo=m.cislo AND !EMPTY(rastr) AND stav<>"S"
		m.poloziek=m.poloziek+1
		m.sumacelkom=m.sumacelkom+hf_rad.cena
		m.sumazaloha=m.sumazaloha+m.zaloha
		m.sd1=1+hf_rad.dph/100
		IF testuexpolhores(hf_rad.rastr,m.sd1)
			SELECT uexpol1
			m.ucet=uexpol1.dal
			m.ucetdan=uexpol1.dal2
			m.nom=ALLTRIM(uexpol1.hs_md)
			m.clenenie=uexpol.hs_dal
		ELSE 
			m.exportuj=.f.
			m.ucet=""
			m.ucetdan=""
			m.nom=""
			m.clenenie=""
		ENDIF 
		IF m.exportuj
			INSERT INTO alto_polozky (cislo, rastr, cena, dan, zaloha, poradie, ucet, ucetdan, text1, dph, nom, rezerv, clenenie) VALUES (hf_rad.cislo, hf_rad.rastr, hf_rad.cena, hf_rad.dan, hf_rad.zaloha, m.poloziek, m.ucet, m.ucetdan, IIF(INLIST(LEFT(hf_rad.text1,4),"Ind.","Skp."),ALLTRIM(SUBSTR(hf_rad.text1,5)),hf_rad.text1), hf_rad.dph, m.nom, hf_rad.rezerv, m.clenenie)
		ENDIF 
	ENDSCAN
	SET PROCEDURE TO &oldproc
	RELEASE m.oldproc
	IF m.exportuj
		IF m.sumacelkom=m.sumazaloha
			m.typfaktury=1   && doklad k prijatej zalohe
		ELSE
			m.typfaktury=2   && vyuctovacia faktura
		ENDIF 
		INSERT INTO alto_hlavicky FROM MEMVAR 
		SELECT hf_hlv
		REPLACE pozn3 WITH LEFT(pozn3,LEN(pozn3)-1)+"-"
	ELSE
		SELECT alto_polozky
		DELETE FOR cislo=m.cislo
	ENDIF 
	
ENDSCAN
SELECT alto_hlavicky
REPLACE d_splat WITH d_vyst FOR d_splat<d_vyst

PRIVATE rowhl, rowpol, m.menoexp, m.filehl, m.filepol, m.porpol
SET ENGINEBEHAVIOR 70
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
m.gcuexp_path=ALLTRIM(IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path))
IF ! DIRECTORY(m.gcuexp_path)
	MKDIR (m.gcuexp_path)
ENDIF
SET CENTURY ON
IF USED("alto_hlavicky")
	m.rowhl=RECCOUNT("alto_hlavicky")
ELSE
	m.rowhl=0
ENDIF 
IF m.rowhl>0
	m.dodatok=STRTRAN(STRTRAN(STRTRAN(STRTRAN(TTOC(DATETIME())," ",""),".",""),":",""),"/","")+"_"+SYS(2015)
	m.menoexp=m.gcuexp_path+"FakturaVydana"+m.mrok+m.mmesiac+"_"+m.dodatok+".xm"
	IF FILE(m.menoexp)
		ERASE (m.menoexp)
	ENDIF 
	m.filehl=FCREATE(m.menoexp)
	IF m.filehl>0 
		=FPUTS(m.filehl,'<?xml version="1.0" encoding="windows-1250" standalone="no"?>')
		=FPUTS(m.filehl,'<S5Data>')
		=FPUTS(m.filehl,'	<FakturaVydanaList>')
		SELECT alto_hlavicky
		m.rowhl=1
		SCAN ALL 
			=FPUTS(m.filehl,'		<FakturaVydana>')
			IF !EMPTY(m.money_group_kod)
				=FPUTS(m.filehl,'			<GroupKod>'+ALLTRIM(m.money_group_kod)+'</GroupKod>')
			ENDIF 
			=FPUTS(m.filehl,'			<CisloDokladu>'+ALLTRIM(alto_hlavicky.cislo)+'</CisloDokladu>')
			=FPUTS(m.filehl,'			<DatumPlneni>'+STR(YEAR(alto_hlavicky.d_pln),4,0)+'-'+STRTRAN(STR(MONTH(alto_hlavicky.d_pln),2,0),' ','0')+'-'+STRTRAN(STR(DAY(alto_hlavicky.d_pln),2,0),' ','0')+'T00:00:00'+'</DatumPlneni>')
			=FPUTS(m.filehl,'			<DatumSkladovehoPohybu>'+STR(YEAR(alto_hlavicky.d_pln),4,0)+'-'+STRTRAN(STR(MONTH(alto_hlavicky.d_pln),2,0),' ','0')+'-'+STRTRAN(STR(DAY(alto_hlavicky.d_pln),2,0),' ','0')+'T00:00:00'+'</DatumSkladovehoPohybu>')
			=FPUTS(m.filehl,'			<DatumSplatnosti>'+STR(YEAR(alto_hlavicky.d_splat),4,0)+'-'+STRTRAN(STR(MONTH(alto_hlavicky.d_splat),2,0),' ','0')+'-'+STRTRAN(STR(DAY(alto_hlavicky.d_splat),2,0),' ','0')+'T00:00:00'+'</DatumSplatnosti>')
			=FPUTS(m.filehl,'			<DatumUcetnihoPripadu>'+STR(YEAR(alto_hlavicky.d_pln),4,0)+'-'+STRTRAN(STR(MONTH(alto_hlavicky.d_pln),2,0),' ','0')+'-'+STRTRAN(STR(DAY(alto_hlavicky.d_pln),2,0),' ','0')+'T00:00:00'+'</DatumUcetnihoPripadu>')
			=FPUTS(m.filehl,'			<DatumUplatneni>'+STR(YEAR(alto_hlavicky.d_pln),4,0)+'-'+STRTRAN(STR(MONTH(alto_hlavicky.d_pln),2,0),' ','0')+'-'+STRTRAN(STR(DAY(alto_hlavicky.d_pln),2,0),' ','0')+'T00:00:00'+'</DatumUplatneni>')
			=FPUTS(m.filehl,'			<DatumUcetnihoPripadu>'+STR(YEAR(alto_hlavicky.d_pln),4,0)+'-'+STRTRAN(STR(MONTH(alto_hlavicky.d_pln),2,0),' ','0')+'-'+STRTRAN(STR(DAY(alto_hlavicky.d_pln),2,0),' ','0')+'T00:00:00'+'</DatumUcetnihoPripadu>')
			=FPUTS(m.filehl,'			<DatumVystaveni>'+STR(YEAR(alto_hlavicky.d_vyst),4,0)+'-'+STRTRAN(STR(MONTH(alto_hlavicky.d_vyst),2,0),' ','0')+'-'+STRTRAN(STR(DAY(alto_hlavicky.d_vyst),2,0),' ','0')+'T00:00:00'+'</DatumVystaveni>')
			=FPUTS(m.filehl,'			<DIC>'+ALLTRIM(alto_hlavicky.dic)+'</DIC>')
			=FPUTS(m.filehl,'			<IC>'+ALLTRIM(alto_hlavicky.ico)+'</IC>')
			=FPUTS(m.filehl,'			<ICDPH>'+ALLTRIM(alto_hlavicky.icdph)+'</ICDPH>')
			=FPUTS(m.filehl,'			<Nazev>'+STRTRAN(STRTRAN(ALLTRIM(alto_hlavicky.adr1),"&","&amp;"),"'","&apos;")+'</Nazev>')
			=FPUTS(m.filehl,'			<OdkazNaDoklad />')
			=FPUTS(m.filehl,'			<ParovaciSymbol>'+ALLTRIM(alto_hlavicky.cislo)+'</ParovaciSymbol>')
			=FPUTS(m.filehl,'			<Poznamka />')
			=FPUTS(m.filehl,'			<PuvodniDoklad />')
			=FPUTS(m.filehl,'			<VariabilniSymbol>'+ALLTRIM(alto_hlavicky.cislo)+'</VariabilniSymbol>')
			IF alto_hlavicky.cel_kc>=0
				=FPUTS(m.filehl,'			<ZapornyPohyb>False</ZapornyPohyb>')
			ELSE
				=FPUTS(m.filehl,'			<ZapornyPohyb>True</ZapornyPohyb>')
			ENDIF 
			=FPUTS(m.filehl,'			<CleneniDPH>')
			IF alto_hlavicky.cel_kc>=0
				=FPUTS(m.filehl,'				<Kod>'+ALLTRIM(m.money_clen_dph_fa)+'</Kod>')
			ELSE
				=FPUTS(m.filehl,'				<Kod>'+ALLTRIM(m.money_clen_dph_dp)+'</Kod>')
			ENDIF 
			=FPUTS(m.filehl,'			</CleneniDPH>')
			=FPUTS(m.filehl,'			<Adresa>')
			=FPUTS(m.filehl,'				<KontaktniOsobaJmeno />')
			=FPUTS(m.filehl,'				<KontaktniOsobaNazev />')
			=FPUTS(m.filehl,'				<KontaktniOsobaPrijmeni />')
			=FPUTS(m.filehl,'				<Misto>'+STRTRAN(STRTRAN(ALLTRIM(alto_hlavicky.adr3),"&","&amp;"),"'","&apos;")+'</Misto>')
			=FPUTS(m.filehl,'				<Nazev>'+STRTRAN(STRTRAN(ALLTRIM(alto_hlavicky.adr1),"&","&amp;"),"'","&apos;")+'</Nazev>')
			=FPUTS(m.filehl,'				<PSC>'+STRTRAN(ALLTRIM(alto_hlavicky.adr4)," ","")+'</PSC>')
			=FPUTS(m.filehl,'				<Ulice>'+STRTRAN(STRTRAN(ALLTRIM(alto_hlavicky.adr2),"&","&amp;"),"'","&apos;")+'</Ulice>')
			=FPUTS(m.filehl,'				<AdresaStat>')
			=FPUTS(m.filehl,'					<Kod>'+IIF(ALLTRIM(alto_hlavicky.stat)="SVK","SK",ALLTRIM(alto_hlavicky.stat))+'</Kod>')
			=FPUTS(m.filehl,'				</AdresaStat>')
			=FPUTS(m.filehl,'				<Firma />')
			=FPUTS(m.filehl,'			</Adresa>')
			=FPUTS(m.filehl,'			<AdresaKoncovehoPrijemce>')
			=FPUTS(m.filehl,'				<KontaktniOsobaJmeno />')
			=FPUTS(m.filehl,'				<KontaktniOsobaNazev />')
			=FPUTS(m.filehl,'				<KontaktniOsobaPrijmeni />')
			=FPUTS(m.filehl,'				<Misto>'+STRTRAN(STRTRAN(ALLTRIM(alto_hlavicky.adr3),"&","&amp;"),"'","&apos;")+'</Misto>')
			=FPUTS(m.filehl,'				<Nazev>'+STRTRAN(STRTRAN(ALLTRIM(alto_hlavicky.adr1),"&","&amp;"),"'","&apos;")+'</Nazev>')
			=FPUTS(m.filehl,'				<PSC>'+STRTRAN(ALLTRIM(alto_hlavicky.adr4)," ","")+'</PSC>')
			=FPUTS(m.filehl,'				<Ulice>'+STRTRAN(STRTRAN(ALLTRIM(alto_hlavicky.adr2),"&","&amp;"),"'","&apos;")+'</Ulice>')
			=FPUTS(m.filehl,'				<AdresaStat>')
			=FPUTS(m.filehl,'					<Kod>'+IIF(ALLTRIM(alto_hlavicky.stat)="SVK","SK",ALLTRIM(alto_hlavicky.stat))+'</Kod>')
			=FPUTS(m.filehl,'				</AdresaStat>')
			=FPUTS(m.filehl,'				<Firma />')
			=FPUTS(m.filehl,'			</AdresaKoncovehoPrijemce>')
			=FPUTS(m.filehl,'			<AdresaPrijemceFaktury>')
			=FPUTS(m.filehl,'				<KontaktniOsobaJmeno />')
			=FPUTS(m.filehl,'				<KontaktniOsobaNazev />')
			=FPUTS(m.filehl,'				<KontaktniOsobaPrijmeni />')
			=FPUTS(m.filehl,'				<Misto>'+STRTRAN(STRTRAN(ALLTRIM(alto_hlavicky.adr3),"&","&amp;"),"'","&apos;")+'</Misto>')
			=FPUTS(m.filehl,'				<Nazev>'+STRTRAN(STRTRAN(ALLTRIM(alto_hlavicky.adr1),"&","&amp;"),"'","&apos;")+'</Nazev>')
			=FPUTS(m.filehl,'				<PSC>'+STRTRAN(ALLTRIM(alto_hlavicky.adr4)," ","")+'</PSC>')
			=FPUTS(m.filehl,'				<Ulice>'+STRTRAN(STRTRAN(ALLTRIM(alto_hlavicky.adr2),"&","&amp;"),"'","&apos;")+'</Ulice>')
			=FPUTS(m.filehl,'				<AdresaStat>')
			=FPUTS(m.filehl,'					<Kod>'+IIF(ALLTRIM(alto_hlavicky.stat)="SVK","SK",ALLTRIM(alto_hlavicky.stat))+'</Kod>')
			=FPUTS(m.filehl,'				</AdresaStat>')
			=FPUTS(m.filehl,'				<Firma />')
			=FPUTS(m.filehl,'			</AdresaPrijemceFaktury>')
			=FPUTS(m.filehl,'			<UcetniKurz>')
			=FPUTS(m.filehl,'				<Kurz>1.000000</Kurz>')
			=FPUTS(m.filehl,'				<Mnozstvi>1.000000</Mnozstvi>')
			=FPUTS(m.filehl,'			</UcetniKurz>')
			=FPUTS(m.filehl,'			<Mena>')
			=FPUTS(m.filehl,'				<Kod>'+ALLTRIM(alto_hlavicky.mena)+'</Kod>')
			=FPUTS(m.filehl,'			</Mena>')
			=FPUTS(m.filehl,'			<Polozky>')
			SELECT alto_polozky
			m.cislopol=1
			SCAN FOR cislo=alto_hlavicky.cislo
				=FPUTS(m.filehl,'				<PolozkaFakturyVydane>')
				DO CASE 
					CASE alto_polozky.dph=m.uctdphlo
						=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Snizena">0</DruhSazbyDPH>')
					CASE alto_polozky.dph=m.uctdphhi
						=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Zakladni">1</DruhSazbyDPH>')
					CASE alto_polozky.dph=0 OR EMPTY(alto_polozky.dph)
						=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Nulova">2</DruhSazbyDPH>')
				ENDCASE 
				=FPUTS(m.filehl,'					<JednCena>'+ALLTRIM(STR(ABS(alto_polozky.cena-alto_polozky.dan),12,2))+'</JednCena>')
				=FPUTS(m.filehl,'					<JednCenaCM>'+ALLTRIM(STR(ABS(alto_polozky.cena-alto_polozky.dan),12,2))+'</JednCenaCM>')
				=FPUTS(m.filehl,'					<Mnozstvi>1.0000</Mnozstvi>')
				=FPUTS(m.filehl,'					<Nazev>'+STRTRAN(STRTRAN(ALLTRIM(alto_polozky.text1),"&","&amp;"),"'","&apos;")+'</Nazev>')
				=FPUTS(m.filehl,'					<Poradi>'+ALLTRIM(STR(m.cislopol,3,0))+'</Poradi>')
				IF !EMPTY(alto_polozky.clenenie) AND alto_hlavicky.cel_kc>=0
					=FPUTS(m.filehl,'					<CleneniDPH>')
					=FPUTS(m.filehl,'						<Kod>'+ALLTRIM(alto_polozky.clenenie)+'</Kod>')
					=FPUTS(m.filehl,'					</CleneniDPH>')
				ENDIF 
				IF alto_polozky.zaloha<>0
					=FPUTS(m.filehl,'					<Poznamka>'+ALLTRIM(STR(alto_polozky.rezerv,10,0))+'</Poznamka>')
				ELSE
					=FPUTS(m.filehl,'					<Poznamka />')
				ENDIF
				=FPUTS(m.filehl,'					<TypCeny EnumValueName="PouzeZaklad">2</TypCeny>')
				=FPUTS(m.filehl,'					<TypObsahu EnumValueName="BezObsahu">0</TypObsahu>')
				IF alto_polozky.cena>0
					=FPUTS(m.filehl,'			<ZapornyPohyb>False</ZapornyPohyb>')
				ELSE
					=FPUTS(m.filehl,'			<ZapornyPohyb>True</ZapornyPohyb>')
				ENDIF 
				=FPUTS(m.filehl,'					<DPH>')
				=FPUTS(m.filehl,'						<Celkem>'+ALLTRIM(STR(ABS(alto_polozky.cena-alto_polozky.dan),12,2))+'</Celkem>')
				=FPUTS(m.filehl,'						<CelkemCM>'+ALLTRIM(STR(ABS(alto_polozky.cena-alto_polozky.dan),12,2))+'</CelkemCM>')
				=FPUTS(m.filehl,'						<Dan>'+ALLTRIM(STR(ABS(alto_polozky.dan),12,2))+'</Dan>')
				=FPUTS(m.filehl,'						<DanCM>'+ALLTRIM(STR(ABS(alto_polozky.dan),12,2))+'</DanCM>')
				=FPUTS(m.filehl,'						<Sazba>'+ALLTRIM(STR(alto_polozky.dph,12,2))+'</Sazba>')
				=FPUTS(m.filehl,'						<Zaklad>'+ALLTRIM(STR(ABS(alto_polozky.cena-alto_polozky.dan),12,2))+'</Zaklad>')
				=FPUTS(m.filehl,'						<ZakladCM>'+ALLTRIM(STR(ABS(alto_polozky.cena-alto_polozky.dan),12,2))+'</ZakladCM>')
				=FPUTS(m.filehl,'					</DPH>')
				=FPUTS(m.filehl,'					<UcetDal>')
				=FPUTS(m.filehl,'						<CisloUctu>'+ALLTRIM(alto_polozky.ucet)+'</CisloUctu>')
				=FPUTS(m.filehl,'					</UcetDal>')
				=FPUTS(m.filehl,'					<UcetMD>')
				=FPUTS(m.filehl,'						<CisloUctu>'+ALLTRIM(m.ucetf)+'</CisloUctu>')
				=FPUTS(m.filehl,'					</UcetMD>')
				IF alto_hlavicky.cel_kc>=0
					IF  alto_polozky.cena<0
						=FPUTS(m.filehl,'					<Vratka>True</Vratka>')
					ELSE 
						=FPUTS(m.filehl,'					<Vratka>False</Vratka>')
					ENDIF  
				ELSE 
					IF  alto_polozky.cena<0
						=FPUTS(m.filehl,'					<Vratka>False</Vratka>')
					ELSE 
						=FPUTS(m.filehl,'					<Vratka>True</Vratka>')
					ENDIF  
				ENDIF 
				=FPUTS(m.filehl,'				</PolozkaFakturyVydane>')
				IF !EMPTY(alto_polozky.ucetdan) AND !EMPTY(alto_polozky.dan)
					m.cislopol=m.cislopol+1
					=FPUTS(m.filehl,'				<PolozkaFakturyVydane>')
					DO CASE 
						CASE alto_polozky.dph=m.uctdphlo
							=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Snizena">0</DruhSazbyDPH>')
						CASE alto_polozky.dph=m.uctdphhi
							=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Zakladni">1</DruhSazbyDPH>')
						CASE alto_polozky.dph=0 OR EMPTY(alto_polozky.dph)
							=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Nulova">2</DruhSazbyDPH>')
					ENDCASE 
					=FPUTS(m.filehl,'					<JednCena>'+ALLTRIM(STR(ABS(alto_polozky.dan),12,2))+'</JednCena>')
					=FPUTS(m.filehl,'					<JednCenaCM>'+ALLTRIM(STR(ABS(alto_polozky.dan),12,2))+'</JednCenaCM>')
					=FPUTS(m.filehl,'					<Mnozstvi>1.0000</Mnozstvi>')
					=FPUTS(m.filehl,'					<Nazev>'+STRTRAN(STRTRAN(ALLTRIM(alto_polozky.text1),"&","&amp;"),"'","&apos;")+'</Nazev>')
					=FPUTS(m.filehl,'					<Poradi>'+ALLTRIM(STR(m.cislopol,3,0))+'</Poradi>')
					=FPUTS(m.filehl,'					<Poznamka />')
					=FPUTS(m.filehl,'					<TypCeny EnumValueName="PouzeDan">3</TypCeny>')
					=FPUTS(m.filehl,'					<TypObsahu EnumValueName="BezObsahu">0</TypObsahu>')
					=FPUTS(m.filehl,'					<DPH>')
					=FPUTS(m.filehl,'						<Celkem>'+ALLTRIM(STR(ABS(alto_polozky.dan),12,2))+'</Celkem>')
					=FPUTS(m.filehl,'						<CelkemCM>'+ALLTRIM(STR(ABS(alto_polozky.dan),12,2))+'</CelkemCM>')
					=FPUTS(m.filehl,'						<Dan>'+ALLTRIM(STR(ABS(alto_polozky.dan),12,2))+'</Dan>')
					=FPUTS(m.filehl,'						<DanCM>'+ALLTRIM(STR(ABS(alto_polozky.dan),12,2))+'</DanCM>')
					=FPUTS(m.filehl,'						<Sazba>'+ALLTRIM(STR(alto_polozky.dph,12,2))+'</Sazba>')
					=FPUTS(m.filehl,'						<Zaklad>'+ALLTRIM(STR(0,12,2))+'</Zaklad>')
					=FPUTS(m.filehl,'						<ZakladCM>'+ALLTRIM(STR(0,12,2))+'</ZakladCM>')
					=FPUTS(m.filehl,'					</DPH>')
					=FPUTS(m.filehl,'					<UcetDal>')
					=FPUTS(m.filehl,'						<CisloUctu>'+ALLTRIM(alto_polozky.ucetdan)+'</CisloUctu>')
					=FPUTS(m.filehl,'					</UcetDal>')
					=FPUTS(m.filehl,'					<UcetMD>')
					=FPUTS(m.filehl,'						<CisloUctu>'+ALLTRIM(m.ucetf)+'</CisloUctu>')
					=FPUTS(m.filehl,'					</UcetMD>')
					IF alto_hlavicky.cel_kc>=0
						IF  alto_polozky.dan<0
							=FPUTS(m.filehl,'					<Vratka>True</Vratka>')
						ELSE 
							=FPUTS(m.filehl,'					<Vratka>False</Vratka>')
						ENDIF  
					ELSE 
						IF  alto_polozky.dan<0
							=FPUTS(m.filehl,'					<Vratka>False</Vratka>')
						ELSE 
							=FPUTS(m.filehl,'					<Vratka>True</Vratka>')
						ENDIF  
					ENDIF 
					=FPUTS(m.filehl,'				</PolozkaFakturyVydane>')
				ENDIF 				
				m.cislopol=m.cislopol+1
			ENDSCAN
			=FPUTS(m.filehl,'			</Polozky>')
			=FPUTS(m.filehl,'		</FakturaVydana>')
			SELECT alto_hlavicky
	 	ENDSCAN 
		=FPUTS(m.filehl,'	</FakturaVydanaList>')
		=FPUTS(m.filehl,'</S5Data>')
		=FCLOSE(m.filehl)
		pocet = ADIR(soubory, m.gcuexp_path + "*.xm")
		FOR iii = 1 TO pocet
			RENAME (m.gcuexp_path+soubory(iii, 1)) TO (m.gcuexp_path+ALLTRIM(soubory(iii, 1))+"l")
		ENDFOR
		DO pozavirej WITH "soubory"
	ELSE
		=MESSAGEBOX(jaz("form_nevytvoreny_subor"),16,"FoodMan",2000)
	ENDIF 
ELSE
	=MESSAGEBOX(jaz("form_no_faktury_na_export"),64,"",2000)
ENDIF
IF m.hor_sql
	=tux(.t.,.t.,"hf_hlv")
ENDIF 
DO pozavirej WITH "alto_hlavicky, alto_polozky, hf_hlv, hf_rad"



PROCEDURE money_id
PRIVATE datz, m.menoexp, m.filehl, m.filepol, m.poloziek
LOCAL dodatok
m.datz=GOMONTH(CTOD("01."+m.mmesiac+"."+m.mrok),1)-1
m.dodatok=STRTRAN(STRTRAN(STRTRAN(STRTRAN(TTOC(DATETIME())," ",""),".",""),":",""),"/","")+"_"+SYS(2015)
m.menoexp=m.gcuexp_path+"InternyDoklad"+m.mrok+m.mmesiac+"_"+m.dodatok+".xm"
IF FILE(m.menoexp)
	ERASE (m.menoexp)
ENDIF 
m.filehl=FCREATE(m.menoexp)
m.rowhl=0
IF m.filehl>0
	=FPUTS(m.filehl,'<?xml version="1.0" encoding="windows-1250" standalone="no"?>')
	=FPUTS(m.filehl,'<S5Data>')
	=FPUTS(m.filehl,'	<InterniDokladList>')
	IF USED("u_id_obr") AND RECCOUNT("u_id_obr")>0
		=FPUTS(m.filehl,'		<InterniDoklad>')
		IF !EMPTY(m.money_group_kod_id)
			=FPUTS(m.filehl,'			<GroupKod>'+ALLTRIM(m.money_group_kod_id)+'</GroupKod>')
		ENDIF 
		=FPUTS(m.filehl,'			<CisloDokladu>'+DTOS(m.datz)+'</CisloDokladu>')
		=FPUTS(m.filehl,'			<DatumPlatby>'+LEFT(DTOS(m.datz),4)+'-'+SUBSTR(DTOS(m.datz),5,2)+'-'+SUBSTR(DTOS(m.datz),7,2)+'T00:00:00</DatumPlatby>')
		=FPUTS(m.filehl,'			<DatumPlneni>'+LEFT(DTOS(m.datz),4)+'-'+SUBSTR(DTOS(m.datz),5,2)+'-'+SUBSTR(DTOS(m.datz),7,2)+'T00:00:00</DatumPlneni>')
		=FPUTS(m.filehl,'			<DatumUcetnihoPripadu>'+LEFT(DTOS(m.datz),4)+'-'+SUBSTR(DTOS(m.datz),5,2)+'-'+SUBSTR(DTOS(m.datz),7,2)+'T00:00:00</DatumUcetnihoPripadu>')
		=FPUTS(m.filehl,'			<DatumUplatneni>'+LEFT(DTOS(m.datz),4)+'-'+SUBSTR(DTOS(m.datz),5,2)+'-'+SUBSTR(DTOS(m.datz),7,2)+'T00:00:00</DatumUplatneni>')
		=FPUTS(m.filehl,'			<DatumVystaveni>'+LEFT(DTOS(m.datz),4)+'-'+SUBSTR(DTOS(m.datz),5,2)+'-'+SUBSTR(DTOS(m.datz),7,2)+'T00:00:00</DatumVystaveni>')
		=FPUTS(m.filehl,'			<DIC>'+m.hotel_dico+'</DIC>')
		=FPUTS(m.filehl,'			<IC>'+m.hotel_ico+'</IC>')
		=FPUTS(m.filehl,'			<ICDPH>'+m.hot_icdph+'</ICDPH>')
		=FPUTS(m.filehl,'			<Nazev>FoodMan</Nazev>')
		=FPUTS(m.filehl,'			<CleneniDPH>')
		=FPUTS(m.filehl,'				<Kod>'+ALLTRIM(m.money_clen_dph_id)+'</Kod>')
		=FPUTS(m.filehl,'			</CleneniDPH>')
		=FPUTS(m.filehl,'			<Odkaz />')
		=FPUTS(m.filehl,'			<ParovaciSymbol>'+DTOS(m.datz)+'</ParovaciSymbol>')
		=FPUTS(m.filehl,'			<Poznamka />')
		=FPUTS(m.filehl,'			<VariabilniSymbol>'+DTOS(m.datz)+'</VariabilniSymbol>')
		=FPUTS(m.filehl,'			<UcetniKurz>')
		=FPUTS(m.filehl,'			<Kurz>1.000000</Kurz>')
		=FPUTS(m.filehl,'			<Mnozstvi>1.000000</Mnozstvi>')
		=FPUTS(m.filehl,'			</UcetniKurz>')
		=FPUTS(m.filehl,'			<Mena>')
		=FPUTS(m.filehl,'				<Kod>'+en__meny(m.giakt_mena,3)+'</Kod>')
		=FPUTS(m.filehl,'			</Mena>')
		=FPUTS(m.filehl,'			<Polozky>')
		SELECT u_id_obr
		SCAN FOR !EMPTY(u_id_obr.md) AND !EMPTY(u_id_obr.ciastka)
			m.rowhl=m.rowhl+1 
			=FPUTS(m.filehl,'				<PolozkaInternihoDokladu>')
          	DO CASE 
				CASE u_id_obr.dan=(m.uctdphlo*100-100)
					=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Snizena">0</DruhSazbyDPH>')
				CASE u_id_obr.dan=(m.uctdphhi*100-100)
					=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Zakladni">1</DruhSazbyDPH>')
				CASE u_id_obr.dan=0
					=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Nulova">2</DruhSazbyDPH>')
				OTHERWISE 
					=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Zakladni">1</DruhSazbyDPH>')
			ENDCASE 
			=FPUTS(m.filehl,'					<ICO />')
			=FPUTS(m.filehl,'					<JednCena>'+ALLTRIM(STR(ROUND(u_id_obr.ciastka,2),15,2))+'</JednCena>')
			=FPUTS(m.filehl,'					<JednCenaCM>'+ALLTRIM(STR(ROUND(u_id_obr.ciastka,2),15,2))+'</JednCenaCM>')
			=FPUTS(m.filehl,'					<Mnozstvi>1.0000</Mnozstvi>')
			IF "platba"$LOWER(u_id_obr.poznamka) AND "hores"$LOWER(u_id_obr.poznamka)
				m.host=ALLTRIM(SUBSTR(u_id_obr.pz,9))
				m.cislouctu=VAL(ALLTRIM(SUBSTR(m.host,AT(" ",m.host))))
				m.host=VAL(ALLTRIM(LEFT(m.host,AT(" ",m.host))))
				IF !USED("hfak")
					IF m.hor_sql
						USE hores_hfak ALIAS hfak IN 0
					ELSE 
						USE (m.hor_path+"hfak.dbf") IN 0
					ENDIF 
				ENDIF 
				SELECT hfak
				LOCATE FOR sequc=m.cislouctu
				IF FOUND()
					=FPUTS(m.filehl,'					<Nazev>'+STRTRAN(ALLTRIM(u_id_obr.poznamka),"HORES","")+" :"+ALLTRIM(hfak.jmeno)+",účet:"+ALLTRIM(STR(m.cislouctu,10,0))+'</Nazev>')
				ELSE 
					=FPUTS(m.filehl,'					<Nazev>'+ALLTRIM(u_id_obr.poznamka)+'</Nazev>')
				ENDIF 
			ELSE 
				=FPUTS(m.filehl,'					<Nazev>'+ALLTRIM(u_id_obr.poznamka)+'</Nazev>')
			ENDIF 
			=FPUTS(m.filehl,'					<Poradi>'+ALLTRIM(STR(m.rowhl,5,0))+'</Poradi>')
			=FPUTS(m.filehl,'					<Poznamka />')
			DO CASE 
				CASE u_id_obr.typ="Q"
					=FPUTS(m.filehl,'					<TypCeny EnumValueName="BezDane">0</TypCeny>')
				CASE u_id_obr.typ="Z" OR u_id_obr.typ="P"
					=FPUTS(m.filehl,'					<TypCeny EnumValueName="PouzeZaklad">2</TypCeny>')
				CASE u_id_obr.typ="D"
					=FPUTS(m.filehl,'					<TypCeny EnumValueName="PouzeDan">3</TypCeny>')
			ENDCASE 
			=FPUTS(m.filehl,'					<TypObsahu EnumValueName="BezObsahu">0</TypObsahu>')
			=FPUTS(m.filehl,'					<DPH>')
			=FPUTS(m.filehl,'						<Celkem>'+ALLTRIM(STR(ROUND(u_id_obr.ciastka,2),15,2))+'</Celkem>')
			=FPUTS(m.filehl,'						<CelkemCM>'+ALLTRIM(STR(ROUND(u_id_obr.ciastka,2),15,2))+'</CelkemCM>')
			DO CASE 
				CASE u_id_obr.typ="D"
					=FPUTS(m.filehl,'						<Dan>'+ALLTRIM(STR(ROUND(u_id_obr.ciastka,2),15,2))+'</Dan>')
					=FPUTS(m.filehl,'						<DanCM>'+ALLTRIM(STR(ROUND(u_id_obr.ciastka,2),15,2))+'</DanCM>')
				CASE u_id_obr.typ="P" OR u_id_obr.typ="Z"
					=FPUTS(m.filehl,'						<Dan>0.00</Dan>')
					=FPUTS(m.filehl,'						<DanCM>0.00</DanCM>')
			ENDCASE 
			=FPUTS(m.filehl,'						<Sazba>'+ALLTRIM(STR(u_id_obr.dan,15,2))+'</Sazba>')
			DO CASE 
				CASE u_id_obr.typ="D"
					=FPUTS(m.filehl,'						<Zaklad>0.00</Zaklad>')
					=FPUTS(m.filehl,'						<ZakladCM>0.00</ZakladCM>')
				CASE u_id_obr.typ="P" OR u_id_obr.typ="Z"
					=FPUTS(m.filehl,'						<Zaklad>'+ALLTRIM(STR(ROUND(u_id_obr.ciastka,2),15,2))+'</Zaklad>')
					=FPUTS(m.filehl,'						<ZakladCM>'+ALLTRIM(STR(ROUND(u_id_obr.ciastka,2),15,2))+'</ZakladCM>')
			ENDCASE 
			=FPUTS(m.filehl,'					</DPH>')
			=FPUTS(m.filehl,'					<UcetDal>')
			=FPUTS(m.filehl,'						<CisloUctu>'+ALLTRIM(u_id_obr.dal)+'</CisloUctu>')
			=FPUTS(m.filehl,'					</UcetDal>')
			=FPUTS(m.filehl,'					<UcetMD>')
			=FPUTS(m.filehl,'						<CisloUctu>'+ALLTRIM(u_id_obr.md)+'</CisloUctu>')
			=FPUTS(m.filehl,'					</UcetMD>')
			=FPUTS(m.filehl,'					<CleneniDPH>')
			IF u_id_obr.typ="Z" AND !EMPTY(u_id_obr.hs_dal)
				=FPUTS(m.filehl,'						<Kod>'+ALLTRIM(u_id_obr.hs_dal)+'</Kod>')
			ELSE
				=FPUTS(m.filehl,'						<Kod>'+ALLTRIM(m.money_clen_dph_id)+'</Kod>')
			ENDIF 
			=FPUTS(m.filehl,'					</CleneniDPH>')
			=FPUTS(m.filehl,'					<Stredisko>')
			=FPUTS(m.filehl,'						<Kod>'+ALLTRIM(u_id_obr.hs_md)+'</Kod>')
			=FPUTS(m.filehl,'					</Stredisko>')
			=FPUTS(m.filehl,'				</PolozkaInternihoDokladu>')
		ENDSCAN 
		=FPUTS(m.filehl,'			</Polozky>')
		=FPUTS(m.filehl,'		</InterniDoklad>')
		=FPUTS(m.filehl,'	</InterniDokladList>')
		=FPUTS(m.filehl,'</S5Data>')
		=FCLOSE(m.filehl)
	ENDIF 
ELSE
	=MESSAGEBOX(jaz("form_nevytvoreny_subor"),16,"FoodMan",2000)
ENDIF 
pocet = ADIR(soubory, m.gcuexp_path + "*.xm")
FOR iii = 1 TO pocet
	RENAME (m.gcuexp_path+soubory(iii, 1)) TO (m.gcuexp_path+ALLTRIM(soubory(iii, 1))+"l")
ENDFOR
DO pozavirej WITH "soubory,hfak"


PROCEDURE money_pokl_doklad
PRIVATE datz, m.menoexp, m.filehl, m.filepol, m.poloziek
LOCAL dodatok, poradie, pztko
m.poradie=0
IF USED("u_id_trz") AND RECCOUNT("u_id_trz")>0
	SELECT DISTINCT den, DATE() as datum FROM u_id_trz INTO CURSOR dni READWRITE 
	TRY 
		REPLACE ALL datum WITH CTOD(RIGHT(den,2)+"."+SUBSTR(den,3,2)+"."+LEFT(den,4))
	ENDTRY 
	SCAN ALL 
		m.datz=ALLTRIM(dni.den)
		m.dodatok=STRTRAN(STRTRAN(STRTRAN(STRTRAN(TTOC(DATETIME())," ",""),".",""),":",""),"/","")+"_"+SYS(2015)
		m.menoexp=m.gcuexp_path+"PokladnicnyDoklad"+ALLTRIM(dni.den)+"_"+m.dodatok+".xm"
		IF FILE(m.menoexp)
			ERASE (m.menoexp)
		ENDIF 
		m.filehl=FCREATE(m.menoexp)
		IF m.filehl>0
			=FPUTS(m.filehl,'<?xml version="1.0" encoding="windows-1250" standalone="no"?>')
			=FPUTS(m.filehl,'<S5Data>')
			=FPUTS(m.filehl,'	<PokladniDokladList>')
			SELECT DISTINCT pz FROM u_id_trz INTO CURSOR pztka WHERE den=m.datz
			SCAN ALL  
				m.pztko=pztka.pz
				m.poradie=m.poradie+1
				=FPUTS(m.filehl,'		<PokladniDoklad>')
				IF !EMPTY(m.money_group_kod_pd)
					=FPUTS(m.filehl,'			<GroupKod>'+ALLTRIM(m.money_group_kod_pd)+'</GroupKod>')
				ENDIF 
				=FPUTS(m.filehl,'			<Pokladna>')
				=FPUTS(m.filehl,'				<Kod>'+ALLTRIM(m.money_kod_pokladne)+'</Kod>')
				=FPUTS(m.filehl,'			</Pokladna>')
				=FPUTS(m.filehl,'			<CisloDokladu>'+m.datz+PADL(ALLTRIM(STR(m.poradie,4,0)),4,"0")+'</CisloDokladu>')
				=FPUTS(m.filehl,'			<DatumPlatby>'+LEFT(m.datz,4)+'-'+SUBSTR(m.datz,5,2)+'-'+SUBSTR(m.datz,7,2)+'T00:00:00</DatumPlatby>')
				=FPUTS(m.filehl,'			<DatumPlneni>'+LEFT(m.datz,4)+'-'+SUBSTR(m.datz,5,2)+'-'+SUBSTR(m.datz,7,2)+'T00:00:00</DatumPlneni>')
				=FPUTS(m.filehl,'			<DatumUcetnihoPripadu>'+LEFT(m.datz,4)+'-'+SUBSTR(m.datz,5,2)+'-'+SUBSTR(m.datz,7,2)+'T00:00:00</DatumUcetnihoPripadu>')
				=FPUTS(m.filehl,'			<DatumUplatneni>'+LEFT(m.datz,4)+'-'+SUBSTR(m.datz,5,2)+'-'+SUBSTR(m.datz,7,2)+'T00:00:00</DatumUplatneni>')
				=FPUTS(m.filehl,'			<DatumVystaveni>'+LEFT(m.datz,4)+'-'+SUBSTR(m.datz,5,2)+'-'+SUBSTR(m.datz,7,2)+'T00:00:00</DatumVystaveni>')
				=FPUTS(m.filehl,'			<DIC>'+m.hotel_dico+'</DIC>')
				=FPUTS(m.filehl,'			<IC>'+m.hotel_ico+'</IC>')
				=FPUTS(m.filehl,'			<ICDPH>'+m.hot_icdph+'</ICDPH>')
				=FPUTS(m.filehl,'			<Nazev>FoodMan tržby</Nazev>')
				=FPUTS(m.filehl,'			<CleneniDPH>')
				=FPUTS(m.filehl,'				<Kod>'+ALLTRIM(m.money_clen_dph_pd)+'</Kod>')
				=FPUTS(m.filehl,'			</CleneniDPH>')
				=FPUTS(m.filehl,'			<Odkaz />')
				=FPUTS(m.filehl,'			<ParovaciSymbol>'+m.datz+PADL(ALLTRIM(STR(m.poradie,4,0)),4,"0")+'</ParovaciSymbol>')
				=FPUTS(m.filehl,'			<Poznamka />')
				=FPUTS(m.filehl,'			<VariabilniSymbol>'+m.datz+PADL(ALLTRIM(STR(m.poradie,4,0)),4,"0")+'</VariabilniSymbol>')
				=FPUTS(m.filehl,'			<UcetniKurz>')
				=FPUTS(m.filehl,'				<Kurz>1.000000</Kurz>')
				=FPUTS(m.filehl,'				<Mnozstvi>1.000000</Mnozstvi>')
				=FPUTS(m.filehl,'			</UcetniKurz>')
				=FPUTS(m.filehl,'			<Mena>')
				=FPUTS(m.filehl,'				<Kod>'+en__meny(m.giakt_mena,3)+'</Kod>')
				=FPUTS(m.filehl,'			</Mena>')
				=FPUTS(m.filehl,'			<Polozky>')
				SELECT u_id_trz
				m.rowhl=0
				SCAN FOR !EMPTY(u_id_trz.md) AND !EMPTY(u_id_trz.ciastka) AND den=m.datz AND pz=m.pztko
					m.rowhl=m.rowhl+1 
					=FPUTS(m.filehl,'				<PolozkaPokladnihoDokladu>')
		          	DO CASE 
						CASE u_id_trz.dan=(m.uctdphlo*100-100)
							=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Snizena">0</DruhSazbyDPH>')
						CASE u_id_trz.dan=(m.uctdphhi*100-100)
							=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Zakladni">1</DruhSazbyDPH>')
						CASE u_id_trz.dan=0
							=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Nulova">2</DruhSazbyDPH>')
						OTHERWISE 
							=FPUTS(m.filehl,'					<DruhSazbyDPH EnumValueName="Zakladni">1</DruhSazbyDPH>')
					ENDCASE 
					=FPUTS(m.filehl,'					<ICO />')
					=FPUTS(m.filehl,'					<JednCena>'+ALLTRIM(STR(ROUND(u_id_trz.ciastka,2),15,2))+'</JednCena>')
					=FPUTS(m.filehl,'					<JednCenaCM>'+ALLTRIM(STR(ROUND(u_id_trz.ciastka,2),15,2))+'</JednCenaCM>')
					=FPUTS(m.filehl,'					<Mnozstvi>1.0000</Mnozstvi>')
					IF "platba"$LOWER(u_id_trz.poznamka) AND "hores"$LOWER(u_id_trz.poznamka)
						m.host=ALLTRIM(SUBSTR(u_id_trz.pz,9))
						m.cislouctu=VAL(ALLTRIM(SUBSTR(m.host,AT(" ",m.host))))
						m.host=VAL(ALLTRIM(LEFT(m.host,AT(" ",m.host))))
						IF !USED("hfak")
							IF m.hor_sql
								USE hores_hfak ALIAS hfak IN 0
							ELSE 
								USE (m.hor_path+"hfak.dbf") IN 0
							ENDIF 
						ENDIF 
						SELECT hfak
						LOCATE FOR sequc=m.cislouctu
						IF FOUND()
							=FPUTS(m.filehl,'					<Nazev>'+STRTRAN(ALLTRIM(u_id_trz.poznamka),"HORES","")+" :"+ALLTRIM(hfak.jmeno)+",účet:"+ALLTRIM(STR(m.cislouctu,10,0))+'</Nazev>')
						ELSE 
							=FPUTS(m.filehl,'					<Nazev>'+ALLTRIM(u_id_obr.poznamka)+'</Nazev>')
						ENDIF 
					ELSE 
						=FPUTS(m.filehl,'					<Nazev>'+ALLTRIM(u_id_trz.poznamka)+'</Nazev>')
					ENDIF 
					=FPUTS(m.filehl,'					<Poradi>'+ALLTRIM(STR(m.rowhl,5,0))+'</Poradi>')
					=FPUTS(m.filehl,'					<Poznamka />')
					DO CASE 
						CASE u_id_trz.typ="Q"
							=FPUTS(m.filehl,'					<TypCeny EnumValueName="BezDane">0</TypCeny>')
						CASE u_id_trz.typ="Z" OR u_id_trz.typ="P"
							=FPUTS(m.filehl,'					<TypCeny EnumValueName="PouzeZaklad">2</TypCeny>')
						CASE u_id_trz.typ="D"
							=FPUTS(m.filehl,'					<TypCeny EnumValueName="PouzeDan">3</TypCeny>')
					ENDCASE 
					=FPUTS(m.filehl,'					<TypObsahu EnumValueName="BezObsahu">0</TypObsahu>')
					=FPUTS(m.filehl,'					<DPH>')
					=FPUTS(m.filehl,'						<Celkem>'+ALLTRIM(STR(ROUND(u_id_trz.ciastka,2),15,2))+'</Celkem>')
					=FPUTS(m.filehl,'						<CelkemCM>'+ALLTRIM(STR(ROUND(u_id_trz.ciastka,2),15,2))+'</CelkemCM>')
					DO CASE 
						CASE u_id_trz.typ="D"
							=FPUTS(m.filehl,'						<Dan>'+ALLTRIM(STR(ROUND(u_id_trz.ciastka,2),15,2))+'</Dan>')
							=FPUTS(m.filehl,'						<DanCM>'+ALLTRIM(STR(ROUND(u_id_trz.ciastka,2),15,2))+'</DanCM>')
						CASE u_id_trz.typ="P" OR u_id_trz.typ="Z"
							=FPUTS(m.filehl,'						<Dan>0.00</Dan>')
							=FPUTS(m.filehl,'						<DanCM>0.00</DanCM>')
					ENDCASE 
					=FPUTS(m.filehl,'						<Sazba>'+ALLTRIM(STR(u_id_trz.dan,15,2))+'</Sazba>')
					DO CASE 
						CASE u_id_trz.typ="D"
							=FPUTS(m.filehl,'						<Zaklad>0.00</Zaklad>')
							=FPUTS(m.filehl,'						<ZakladCM>0.00</ZakladCM>')
						CASE u_id_trz.typ="P" OR u_id_trz.typ="Z"
							=FPUTS(m.filehl,'						<Zaklad>'+ALLTRIM(STR(ROUND(u_id_trz.ciastka,2),15,2))+'</Zaklad>')
							=FPUTS(m.filehl,'						<ZakladCM>'+ALLTRIM(STR(ROUND(u_id_trz.ciastka,2),15,2))+'</ZakladCM>')
					ENDCASE 
					=FPUTS(m.filehl,'					</DPH>')
					=FPUTS(m.filehl,'					<UcetDal>')
					=FPUTS(m.filehl,'						<CisloUctu>'+ALLTRIM(u_id_trz.dal)+'</CisloUctu>')
					=FPUTS(m.filehl,'					</UcetDal>')
					=FPUTS(m.filehl,'					<UcetMD>')
					=FPUTS(m.filehl,'						<CisloUctu>'+ALLTRIM(u_id_trz.md)+'</CisloUctu>')
					=FPUTS(m.filehl,'					</UcetMD>')
					=FPUTS(m.filehl,'					<CleneniDPH>')
					IF u_id_trz.typ="Z" AND !EMPTY(u_id_trz.hs_dal)
						=FPUTS(m.filehl,'						<Kod>'+ALLTRIM(u_id_trz.hs_dal)+'</Kod>')
					ELSE
						=FPUTS(m.filehl,'						<Kod>'+ALLTRIM(m.money_clen_dph_pd)+'</Kod>')
					ENDIF 
					=FPUTS(m.filehl,'					</CleneniDPH>')
					=FPUTS(m.filehl,'					<Stredisko>')
					=FPUTS(m.filehl,'						<Kod>'+ALLTRIM(u_id_trz.hs_md)+'</Kod>')
					=FPUTS(m.filehl,'					</Stredisko>')
					=FPUTS(m.filehl,'				</PolozkaPokladnihoDokladu>')
				ENDSCAN 
				=FPUTS(m.filehl,'			</Polozky>')
				=FPUTS(m.filehl,'		</PokladniDoklad>')
			ENDSCAN 
			USE IN pztka
			=FPUTS(m.filehl,'	</PokladniDokladList>')
			=FPUTS(m.filehl,'</S5Data>')
			=FCLOSE(m.filehl)
		ENDIF 
	ENDSCAN 
ELSE
		=MESSAGEBOX(jaz("form_nevytvoreny_subor"),16,"FoodMan",2000)
ENDIF 
pocet = ADIR(soubory, m.gcuexp_path + "*.xm")
FOR iii = 1 TO pocet
	RENAME (m.gcuexp_path+soubory(iii, 1)) TO (m.gcuexp_path+ALLTRIM(soubory(iii, 1))+"l")
ENDFOR
DO pozavirej WITH "soubory,hfak, dni"



PROCEDURE gen_exp_navision
PARAMETERS m.msumar, m.mrok, m.mmesiac
PRIVATE m.hladajrok, m.hladajmesiac
m.hladajrok=m.mrok
m.hladajmesiac=m.mmesiac
m.oldsetdele=SET("dele")
SET DELETED ON
gen_exp_had = CREATEOBJECT("had", "Generovanie exportných súborov")
gen_exp_had.SHOW()
m.gcuexp_path=IIF(EMPTY(m.gcuexp_path),m.gcucto_path,m.gcuexp_path)
IF USED("uexstrava")
	IF m.uctstravazam<>0
		LOCAL sumapocet, sumasuma, menoexportu
		SELECT *, $0+pocet*m.uctstravazam as suma, PADR(ALLTRIM(m.stravazammd),10) as md, PADR(ALLTRIM(m.stravazamdal),10) as dal, PADR(ALLTRIM(m.stravazamdph),10) as dph_dal, m.stravazamdphsadzba as dph  FROM uexstrava INTO CURSOR u_ex_strava READWRITE 
		SELECT id_strav, meno, priezvisko, oscislo, SUM(pocet) as pocet,$0 as suma, stredisko FROM uexstrava INTO CURSOR exportmzdy GROUP BY id_strav, priezvisko, meno, oscislo, stredisko READWRITE 
		REPLACE ALL suma WITH pocet*m.uctstravazam
		SUM pocet TO sumapocet
		SUM suma TO sumasuma
		INSERT INTO exportmzdy (priezvisko, pocet, suma) VALUES ("Spolu", m.sumapocet, m.sumasuma)
		m.menoexportu=m.gcuexp_path+"strava"+m.mrok+m.mmesiac+".xls"
		IF FILE(m.menoexportu)
			ERASE (m.menoexportu)
		ENDIF 
		EXPORT TO (m.menoexportu) TYPE XLS 
		DO pozavirej WITH "exportmzdy"
		RELEASE m.sumapocet, m.sumasuma, m.menoexportu
	ENDIF 
	IF m.uctstravafirma<>0
		IF USED("u_ex_strava")
			INSERT INTO u_ex_strava (id_strav, pocet, priezvisko, meno, datum, oscislo, stredisko, suma, md, dal, dph_dal, dph) SELECT id_strav, pocet, priezvisko, meno, datum, oscislo, stredisko, ($0+pocet*m.uctstravafirma) as suma, PADR(ALLTRIM(m.stravafirmamd),10) as md, PADR(ALLTRIM(m.stravafirmadal),10) as dal, SPACE(10) as dph_dal,1 as dph FROM uexstrava 
		ELSE
			SELECT *, ($0+pocet*m.uctstravazam) as suma, PADR(ALLTRIM(m.stravafirmamd),10) as md, PADR(ALLTRIM(m.stravafirmadal),10) as dal, SPACE(10) as dph_dal, 1 as dph FROM uexstrava INTO CURSOR u_ex_strava READWRITE 
		ENDIF 
	ENDIF 
	IF m.uctstravasocfond<>0
		IF USED("u_ex_strava")
			INSERT INTO u_ex_strava (id_strav, pocet, priezvisko, meno, datum, oscislo, stredisko, suma, md, dal, dph_dal, dph) SELECT id_strav, pocet, priezvisko, meno, datum, oscislo, stredisko, ($0+pocet*m.uctstravasocfond) as suma, PADR(ALLTRIM(m.stravasocfondmd),10) as md, PADR(ALLTRIM(m.stravasocfonddal),10) as dal, SPACE(10) as dph, 1 as dph FROM uexstrava 
		ELSE
			SELECT *, ($0+pocet*m.uctstravasocfond) as suma, PADR(ALLTRIM(m.stravasocfondmd),10) as md, PADR(ALLTRIM(m.stravasocfonddal),10) as dal, SPACE(10) as dph_dal, 1 as dph FROM uexstrava INTO CURSOR u_ex_strava READWRITE 
		ENDIF 
	ENDIF
	IF m.uctzamstravastrava<>0
		IF USED("u_ex_strava")
			INSERT INTO u_ex_strava (id_strav, pocet, priezvisko, meno, datum, oscislo, stredisko, suma, md, dal, dph_dal, dph) SELECT id_strav, pocet, priezvisko, meno, datum, oscislo, m.stravazamstravahsdal, ($0+pocet*m.uctzamstravastrava) as suma, PADR(ALLTRIM(m.stravazamstravamd),10) as md, PADR(ALLTRIM(m.stravazamstravadal),10) as dal, SPACE(10) as dph, 1 as dph FROM uexstrava 
		ELSE
			SELECT *, ($0+pocet*m.uctzamstravastrava) as suma, PADR(ALLTRIM(m.stravazamstravamd),10) as md, PADR(ALLTRIM(m.stravazamstravadal),10) as dal, SPACE(10) as dph_dal, 1 as dph FROM uexstrava INTO CURSOR u_ex_strava READWRITE 
			REPLACE ALL stredisko WITH m.stravazamstravahsdal
		ENDIF 
	ENDIF
	IF USED("u_ex_strava")
		SELECT u_ex_strava
		REPLACE dph WITH 1 FOR dph=0
		DO kontrola_stravy WITH CTOD("01."+m.mmesiac+"."+m.mrok),GOMONTH(CTOD("01."+m.mmesiac+"."+m.mrok),1)-1
		DO navision_id_strava
	ENDIF 
	DO pozavirej WITH "uexstrava"
ENDIF 
IF USED("u_ex_obraty")
	SELECT u_ex_obraty
	REPLACE castka WITH -castka FOR LEFT(operace,1)="V"
	IF m.gcuct_inv_plus_i_min
		LOCAL m.manko_md, m.manko_dal, m.manko_hsmd, m.manko_hsdal, m.manko_idman, m.manko_druh, m.manko_partner, m.manko_cdokl
		SELECT u_ex_obraty
		SCAN FOR castka<0 AND operace="PI"
			m.manko_idman=u_ex_obraty.id_man
			m.manko_druh=u_ex_obraty.druh
			m.manko_partner=u_ex_obraty.partner
			m.manko_cdokl=u_ex_obraty.c_dokl
			IF testuexobr("PI", m.manko_druh, m.manko_partner, m.manko_idman, "-")
				SELECT uexobr1
				GO TOP 
				m.manko_md=ALLTRIM(uexobr1.md)
				m.manko_dal=ALLTRIM(uexobr1.dal)
				m.manko_hsmd=ALLTRIM(uexobr1.hs_md)
				m.manko_hsdal=ALLTRIM(uexobr1.hs_dal)
				SELECT u_ex_obraty
				REPLACE md WITH m.manko_md, dal WITH m.manko_dal, hs_md WITH m.manko_hsmd, hs_dal WITH m.manko_hsdal, castka WITH -castka
			ELSE 
				IF testuexobr("PI", "*", m.manko_partner, m.manko_idman, "-")
					SELECT uexobr1
					GO TOP 
					m.manko_md=ALLTRIM(uexobr1.md)
					m.manko_dal=ALLTRIM(uexobr1.dal)
					m.manko_hsmd=ALLTRIM(uexobr1.hs_md)
					m.manko_hsdal=ALLTRIM(uexobr1.hs_dal)
					SELECT u_ex_obraty
					REPLACE md WITH m.manko_md, dal WITH m.manko_dal, hs_md WITH m.manko_hsmd, hs_dal WITH m.manko_hsdal, castka WITH -castka
				ELSE 
					IF testuexobr("PI", m.manko_druh, "*", m.manko_idman, "-")
						SELECT uexobr1
						GO TOP 
						m.manko_md=ALLTRIM(uexobr1.md)
						m.manko_dal=ALLTRIM(uexobr1.dal)
						m.manko_hsmd=ALLTRIM(uexobr1.hs_md)
						m.manko_hsdal=ALLTRIM(uexobr1.hs_dal)
						SELECT u_ex_obraty
						REPLACE md WITH m.manko_md, dal WITH m.manko_dal, hs_md WITH m.manko_hsmd, hs_dal WITH m.manko_hsdal, castka WITH -castka
					ELSE 
						IF testuexobr("PI", "*", "*", m.manko_idman, "-")
							SELECT uexobr1
							GO TOP 
							m.manko_md=ALLTRIM(uexobr1.md)
							m.manko_dal=ALLTRIM(uexobr1.dal)
							m.manko_hsmd=ALLTRIM(uexobr1.hs_md)
							m.manko_hsdal=ALLTRIM(uexobr1.hs_dal)
							SELECT u_ex_obraty
							REPLACE md WITH m.manko_md, dal WITH m.manko_dal, hs_md WITH m.manko_hsmd, hs_dal WITH m.manko_hsdal, castka WITH -castka
						ENDIF 
					ENDIF 
				ENDIF 
			ENDIF 
		ENDSCAN 		
		RELEASE m.manko_md, m.manko_dal, m.manko_hsmd, m.manko_hsdal, m.manko_idman, m.manko_druh, m.manko_partner, m.manko_cdokl
*		UPDATE u_ex_obraty SET castka=ABS(castka) WHERE operace="PI"
	ENDIF 		
	IF m.gcuct_export_fa
		SELECT STR(c_dokl) as datum, id_man, SUM(castka) AS castka, MD, dal, hs_md, hs_dal, pz, partner, STR(doklad,10,0) as doklad, datum_dokl, poznamka,.f. as oprava FROM u_ex_obraty GROUP BY id_man,pz,MD,dal INTO CURSOR u_id_obr WHERE !EMPTY(datum) AND !INLIST(operace,"FA","VE","VR","PE") READWRITE 
	ELSE
		SELECT STR(c_dokl) as datum, id_man, SUM(castka) AS castka, MD, dal, hs_md, hs_dal, pz, partner, STR(doklad,10,0) as doklad, datum_dokl, poznamka,.f. as oprava FROM u_ex_obraty GROUP BY id_man,pz,MD,dal INTO CURSOR u_id_obr WHERE !EMPTY(datum) AND operace<>"FA" READWRITE 
	ENDIF 
	REPLACE ALL poznamka WITH STRTRAN(poznamka, "OBR ",""), castka WITH ROUND(castka,2)
	DELETE FOR ROUND(castka,2)=0
	IF m.msumar
		*** Kontrola, ci je v archive uz prenos tohoto mesiaca
		IF m.issql
			USE (m.sqlprefix+"ruexarchobraty_mesiacrok") IN 0 ALIAS archivobraty
		ELSE
			IF !FILE(m.gccen_path+"uexarchobraty.dbf")
				DO creafile WITH (m.gccen_path+"uexarchobraty.dbf")
			ENDIF 
			IF !USED("uexarchobraty")
				USE (m.gccen_path+"uexarchobraty") IN 0
			ENDIF 
			USE vuexarchobraty_mesiacrok IN 0 ALIAS archivobraty
		ENDIF 
		=CURSORSETPROP("Buffering",5,"archivobraty")
		IF RECCOUNT("archivobraty")>0
			SELECT archivobraty
			SCAN ALL 
				SELECT u_id_obr
				LOCATE FOR ALLTRIM(pz)=ALLTRIM(archivobraty.pz) AND id_man=archivobraty.id_man AND ROUND(castka,2)=ROUND(archivobraty.castka,2) AND ALLTRIM(md)=ALLTRIM(archivobraty.md) AND ALLTRIM(dal)=ALLTRIM(archivobraty.dal) AND ALLTRIM(hs_md)=ALLTRIM(archivobraty.hs_md)
				IF FOUND()
					*** Ak bol presne takyto riadok uz prenasany, nemusim prenasat nic
					DELETE 
				ELSE
					*** Ak presne takyto riadok prenasany nebol, vlozim do u_id_obr povodne preneseny riadok s opacnym znamienkom v ciastke
					INSERT INTO u_id_obr (datum, id_man, castka, md, dal, hs_md, hs_dal, pz, partner, poznamka, oprava, datum_dokl) VALUES ;
						(archivobraty.datum, archivobraty.id_man, -archivobraty.castka, archivobraty.md, archivobraty.dal, archivobraty.hs_md,;
						 archivobraty.hs_dal, archivobraty.pz, archivobraty.partner, archivobraty.poznamka, .t., u_id_obr.datum_dokl)
				ENDIF 
			ENDSCAN 
		ENDIF 
	ENDIF 
ENDIF 
IF USED("u_ex_polozky") AND USED("u_ex_platby")
	gen_exp_had.INCREMENT("Tržby")
	SELECT id_kas, uzaverka, SUM(castka) AS castka, MD, dal, md2, dal2, hs_md, hs_dal, poznamka, pz, datum_dokl, oprava FROM u_ex_platby GROUP BY id_kas, pz, poznamka, MD, dal, oprava INTO CURSOR u_doklady  WHERE !(uzaverka+u_cis IN (SELECT DISTINCT uzaverka+u_cis FROM u_ex_platby WHERE "ZALOHA"$poznamka)) READWRITE 
	SELECT u_doklady
	DELETE FOR ROUND(castka,2)=0
	IF m.msumar
		IF m.issql
			USE (m.sqlprefix+"ruexarchplatby_mesiacrok") IN 0 ALIAS archivplatby
		ELSE
			USE (m.gccen_path+"uexarchplatby") IN 0
			USE vuexarchplatby_mesiacrok IN 0 ALIAS archivplatby
		ENDIF 
		=CURSORSETPROP("Buffering",5,"archivplatby")
		IF RECCOUNT("archivplatby")>0
			SELECT archivplatby
			gen_exp_had.set_max(RECCOUNT("archivplatby"))
			SCAN ALL 
				gen_exp_had.increment("Kontrola archívu prenosu platieb: "+ALLTRIM(STR(RECNO("archivplatby"),10,0))+"/"+ALLTRIM(STR(RECCOUNT("archivplatby"),10,0)))
				SELECT u_doklady
				LOCATE FOR ALLTRIM(pz)=ALLTRIM(archivplatby.pz) AND id_kas=archivplatby.id_kas AND uzaverka=archivplatby.uzaverka AND ROUND(castka,2)=ROUND(archivplatby.castka,2) AND ALLTRIM(md)=ALLTRIM(archivplatby.md);
					 AND ALLTRIM(dal)=ALLTRIM(archivplatby.dal) AND ALLTRIM(hs_md)=ALLTRIM(archivplatby.hs_md) AND ALLTRIM(hs_dal)=ALLTRIM(archivplatby.hs_dal);
					 AND ALLTRIM(poznamka)=ALLTRIM(archivplatby.poznamka)
				IF FOUND()
					*** Ak bol presne takyto riadok uz prenasany, nemusim prenasat nic
					DELETE 
				ELSE
					*** Ak presne takyto riadok prenasany nebol, vlozim do u_id_obr povodne preneseny riadok s opacnym znamienkom v ciastke
					INSERT INTO u_doklady (id_kas, uzaverka, datum_dokl, castka, md, dal, hs_md, hs_dal, pz,  poznamka, oprava) VALUES ;
						(archivplatby.id_kas, archivplatby.uzaverka, archivplatby.datum_dokl, -archivplatby.castka, archivplatby.md, archivplatby.dal, archivplatby.hs_md, ;
						archivplatby.hs_dal, archivplatby.pz, archivplatby.poznamka, .t.)
				ENDIF 
			ENDSCAN 
		ENDIF 
	ENDIF 

	SELECT id_kas, uzaverka, u_cis, dan, SUM(castka) as suma, $0 as dph FROM u_ex_polozky GROUP BY id_kas, uzaverka, u_cis, dan INTO CURSOR dphvypocet READWRITE 
	REPLACE ALL dph WITH ground(suma*(dan-1)/dan,2)
	LOCAL m.idkas, m.uzaverka, m.ucis, m.sumadph, m.sumacelkom, m.sadzbadane, m.rozdieldane
	gen_exp_had.set_max(RECCOUNT("dphvypocet"))
	SCAN ALL 

		gen_exp_had.increment("Kontrola výpočtu DPH:"+ALLTRIM(STR(RECNO("dphvypocet")))+"/"+ALLTRIM(STR(RECCOUNT("dphvypocet"))))
		m.idkas=dphvypocet.id_kas
		m.uzaverka=dphvypocet.uzaverka
		m.ucis=dphvypocet.u_cis
		m.sumadph=dphvypocet.dph
		m.sumacelkom=dphvypocet.suma
		m.sadzbadane=dphvypocet.dan
		SELECT SUM(castka) as castka, SUM(dan_zakl) as dan_zakl FROM u_ex_polozky WHERE id_kas=m.idkas AND uzaverka=m.uzaverka AND u_cis=m.ucis AND dan=m.sadzbadane INTO CURSOR dphnajdene
		IF RECCOUNT("dphnajdene")=1
			GO TOP 
			IF castka=m.sumacelkom AND (castka-dan_zakl)=m.sumadph
			ELSE
				m.rozdieldane=dphnajdene.castka-dphnajdene.dan_zakl-m.sumadph
				SELECT u_ex_polozky
				SET FILTER TO id_kas=m.idkas AND uzaverka=m.uzaverka AND u_cis=m.ucis AND dan=m.sadzbadane
				GO TOP 
				REPLACE dan_zakl WITH dan_zakl+m.rozdieldane
				SET FILTER TO 
			ENDIF 
		ENDIF 
		USE IN dphnajdene
		SELECT dphvypocet
	ENDSCAN 
	RELEASE m.idkas, m.uzaverka, m.ucis, m.sumadph, m.sumacelkom, m.sadzbadane, m.rozdieldane
	DO pozavirej WITH "dphvypocet, dphnajdene"

	SELECT id_kas, uzaverka, u_cis, SUM(castka) AS castka, MD, dal, md2, dal2, hs_md, hs_dal, poznamka, pz, SUM(dan_zakl) AS danzakl, SUM(castka-dan_zakl) as sum_dan, dan as dph, oprava, datum_dokl FROM u_ex_polozky GROUP BY pz, poznamka, MD, dal, md2, dal2, oprava INTO CURSOR u_dokl1 READWRITE 
	SELECT u_dokl1
	REPLACE ALL poznamka WITH STRTRAN(poznamka,"POL HORES ","")
	REPLACE ALL poznamka WITH STRTRAN(poznamka,"POL ","")
		
	
	SELECT id_kas, uzaverka, SUM(castka) AS castka, SUM(danzakl) AS danzakl, SUM(sum_dan) AS dan, MD, dal, md2, dal2,hs_md, hs_dal, poznamka, dph, pz, oprava, datum_dokl FROM u_dokl1 GROUP BY id_kas, pz, MD, dal, md2, dal2, hs_md, hs_dal, poznamka, oprava INTO CURSOR u_dokl2 READWRITE 
	REPLACE ALL castka WITH ROUND(castka,2), danzakl WITH ROUND(danzakl,2), dan WITH ROUND(dan,2)
	SELECT id_kas, uzaverka, SUM(castka) AS castka, SUM(danzakl) AS danzakl, SUM(dan) AS dan, MD, dal, hs_md, hs_dal, md2, dal2, pz, poznamka, dph, oprava, datum_dokl FROM u_dokl2 GROUP BY id_kas, pz, MD, dal, md2, dal2, hs_md, hs_dal, poznamka, oprava INTO CURSOR u_dokl READWRITE 
	DELETE FOR ROUND(castka,2)=0
*	REPLACE ALL dan WITH ROUND(castka*dph/(100+dph),2)
	IF m.msumar
		*** Kontrola, ci je v archive uz prenos tohoto mesiaca
		IF m.issql
			USE (m.sqlprefix+"ruexarchpolozky_mesiacrok") IN 0 ALIAS archivpolozky
		ELSE
			USE (m.gccen_path+"uexarchpolozky") IN 0
			USE vuexarchpolozky_mesiacrok IN 0 ALIAS archivpolozky
		ENDIF 
		=CURSORSETPROP("Buffering",5,"archivpolozky")
		IF RECCOUNT("archivpolozky")>0
			SELECT archivpolozky
			gen_exp_had.set_max(RECCOUNT("archivpolozky"))
			SCAN ALL 
				gen_exp_had.increment("Kontrola archívu prenosu položiek: "+ALLTRIM(STR(RECNO("archivpolozky"),10,0))+"/"+ALLTRIM(STR(RECCOUNT("archivpolozky"),10,0)))
				SELECT u_dokl
				LOCATE FOR ALLTRIM(pz)=ALLTRIM(archivpolozky.pz) AND id_kas=archivpolozky.id_kas AND uzaverka=archivpolozky.uzaverka AND ROUND(castka,2)=ROUND(archivpolozky.castka,2) AND ALLTRIM(md)=ALLTRIM(archivpolozky.md);
					 AND ALLTRIM(dal)=ALLTRIM(archivpolozky.dal) AND ALLTRIM(md2)=ALLTRIM(archivpolozky.md2) AND ALLTRIM(dal2)=ALLTRIM(archivpolozky.dal2) AND ALLTRIM(hs_md)=ALLTRIM(archivpolozky.hs_md);
					 AND ALLTRIM(hs_dal)=ALLTRIM(archivpolozky.hs_dal) AND ALLTRIM(poznamka)=ALLTRIM(archivpolozky.poznamka)
				IF FOUND()
					*** Ak bol presne takyto riadok uz prenasany, nemusim prenasat nic
					DELETE 
				ELSE
					*** Ak presne takyto riadok prenasany nebol, vlozim do u_id_obr povodne preneseny riadok s opacnym znamienkom v ciastke
					INSERT INTO u_dokl (id_kas, uzaverka, datum_dokl, castka, md, dal, hs_md, hs_dal, pz,  poznamka, oprava, md2, dal2, danzakl, dph) VALUES ;
						(archivpolozky.id_kas, archivpolozky.uzaverka, archivpolozky.datum_dokl, -archivpolozky.castka, archivpolozky.md, archivpolozky.dal, archivpolozky.hs_md, ;
						archivpolozky.hs_dal, archivpolozky.pz, archivpolozky.poznamka, .t., archivpolozky.md2, archivpolozky.dal2, -archivpolozky.dan_zakl, archivpolozky.dan_sadzba)
				ENDIF 
			ENDSCAN 
		ENDIF 
	ENDIF 
	DO pozavirej WITH "archivpolozky, archivplatby, uexarchpolozky, uexarchplatby"
ENDIF 
IF USED("u_id_obr") OR USED("u_doklady") OR USED("u_dokl")
	DO navision_id
ENDIF 

DO pozavirej WITH "u_id_obr, u_doklady, u_dokl, u_dokl1, u_dokl2, u_ex_obraty, u_ex_polozky, u_ex_platby, u_ex_strava, uexstrava"
RELEASE gen_exp_had


PROCEDURE navision_id
PRIVATE datz, m.menoexp, m.filehl, m.filepol, m.poloziek
PRIVATE m.hladajrok, m.hladajmesiac, m.hladajpz, m.hladajuzaverka, m.hladajucis
m.hladajrok=m.mrok
m.hladajmesiac=m.mmesiac
LOCAL dodatok, m.datz, m.dodatok1
m.datz=GOMONTH(CTOD("01."+m.mmesiac+"."+m.mrok),1)-1
IF USED("u_id_obr") 
	SELECT DISTINCT pz FROM u_id_obr INTO CURSOR sklady READWRITE 
	IF RECCOUNT("sklady")>0
		gen_exp_had.set_max(RECCOUNT("sklady"))
		*** Cislo riadku musim nastavit uz tu, aby sa to cele v Navision tvarilo ako jeden doklad
		m.i=1
		SCAN ALL 
			m.hladajpz=sklady.pz
			m.dodatok=m.mrok+"/"+m.mmesiac 	&&Toto bude oznacenie dokladu v Navision
			m.dodatok1=m.mrok+"/"+m.mmesiac +" - "+ALLTRIM(sklady.pz) &&Toto vytvaram, aby som zobrazil priebeh a aby som z Navision nestahoval stale vsetky riadky
			gen_exp_had.increment("Sklady:"+m.dodatok1)
			IF otvor_navision_intdokl(m.navision_firma,"intdokl","internaldocuments.DocumentNo='"+m.dodatok1+"'")
				SELECT intdokl
				REPLACE ALL curstat WITH .f.
				SELECT u_id_obr
				SCAN FOR pz=sklady.pz
					INSERT INTO intdokl (rtyp, rstat, batchname, line_no, ucet1, postdate, docno, descript, dph, ucet2, suma, gdc1, gdc2, cena_dph, jname, curstat, u_cis, rezno) VALUES ; 
						("ID", "N", "Sklady", m.i*10000, u_id_obr.md, u_id_obr.datum_dokl, m.dodatok, u_id_obr.poznamka, 0, u_id_obr.dal, ROUND(u_id_obr.castka,2), ALLTRIM(u_id_obr.hs_md)+ALLTRIM(u_id_obr.hs_dal),"",0,"INTDOKL",.t.,"","")
					m.i=m.i+1
				ENDSCAN 
				IF tux(.t.,.t.,"intdokl")
					SELECT archivobraty
					DELETE FOR pz=sklady.pz
					INSERT INTO archivobraty (datum, id_man, castka, md, dal, hs_md, hs_dal, pz, partner, poznamka, mesiac, rok, c_data);
						SELECT datum, id_man, castka, md, dal, hs_md, hs_dal, pz, partner, poznamka, m.hladajmesiac as mesiac, m.hladajrok as rok, m.cdata as c_data FROM u_id_obr WHERE pz=m.hladajpz AND !oprava
				ENDIF 
				USE IN intdokl
			ENDIF 
			SELECT sklady
		ENDSCAN 
		USE IN sklady
		=tux(.t.,.t.,"archivobraty")
		**** Zapis o prenose dokladov do doklady.dbf
		IF m.issql
			USE (m.sqlprefix+"ruexdoklady_prenos") ALIAS doklx IN 0
			=CURSORSETPROP("Buffering",5,"doklx")
			UPDATE doklx SET uctexport=.t. WHERE c_dokl in (SELECT disti c_dokl FROM u_ex_obraty)
			=tux(.t.,.t.,"doklx")
			USE IN doklx
		ELSE 
			IF !USED("doklady")
				USE (m.fn_doklady) ALIAS doklady IN 0
				UPDATE doklady SET uctexport=.t. WHERE c_dokl in (SELECT disti c_dokl FROM u_ex_obraty)
				USE IN doklady
			ELSE 
				UPDATE doklady SET uctexport=.t. WHERE c_dokl in (SELECT disti c_dokl FROM u_ex_obraty)
			ENDIF 
		ENDIF 
	ENDIF 
	DO pozavirej WITH "archivobraty, uexarchobraty"
ENDIF 
IF USED("u_doklady") AND USED("u_dokl")
	SELECT DISTINCT id_kas,uzaverka FROM u_doklady INTO CURSOR sklady ORDER BY uzaverka, id_kas READWRITE 
	*** Ak ide o opravny prenos, mozu sa prenasat iba opravy poloziek alebo platieb, preto musim skontrolovat aj prenasane uzavierky z druhej tabulky
	INSERT INTO sklady (id_kas, uzaverka) SELECT DISTINCT id_kas, uzaverka FROM u_dokl WHERE !(uzaverka+id_kas IN (SELECT DISTINCT uzaverka+id_kas FROM u_doklady)) 
	IF RECCOUNT("sklady")>0
		INDEX ON uzaverka+id_kas TAG aaa 
		gen_exp_had.set_max(RECCOUNT("sklady"))
		SCAN ALL 
			m.dodatok=LEFT(sklady.uzaverka,8)+"_"+sklady.id_kas
			m.hladajuzaverka=sklady.uzaverka
			m.hladajidkas=sklady.id_kas
			IF USED("archivplatby")
				=REQUERY("archivplatby")
			ELSE 
				IF m.issql
					USE (m.sqlprefix+"ruexarchplatby_uzaverka") IN 0 ALIAS archivplatby
				ELSE
					IF !USED("uexarchplatby")
						USE (m.gccen_path+"uexarchplatby") IN 0
					ENDIF 
					USE vuexarchplatby_uzaverka IN 0 ALIAS archivplatby
				ENDIF 
				=CURSORSETPROP("Buffering",5,"archivplatby")
			ENDIF 
			IF USED("archivpolozky")
				=REQUERY("archivpolozky")
			ELSE 
				IF m.issql
					USE (m.sqlprefix+"ruexarchpolozky_uzaverka") IN 0 ALIAS archivpolozky
				ELSE
					IF !USED("uexarchpolozky")
						USE (m.gccen_path+"uexarchpolozky") IN 0
					ENDIF 
					USE vuexarchpolozky_uzaverka IN 0 ALIAS archivpolozky
				ENDIF 
				=CURSORSETPROP("Buffering",5,"archivpolozky")
			ENDIF 
			gen_exp_had.increment("Tržby:"+m.dodatok)
			IF otvor_navision_intdokl(m.navision_firma,"intdokl","internaldocuments.DocumentNo='"+m.dodatok+"'")
				SELECT intdokl
				IF m.msumar
					REPLACE ALL curstat WITH .f.
				ENDIF 
				SELECT u_dokl
				m.i=1
				SCAN FOR id_kas=sklady.id_kas AND uzaverka=sklady.uzaverka
*!*						INSERT INTO intdokl (rtyp, rstat, batchname, line_no, ucet1, postdate, docno, descript, dph, ucet2, suma, gdc1, gdc2, cena_dph, jname, curstat, u_cis, rezno) VALUES ; 
*!*							("ID", "N", "TržbyFood", m.i*10000, u_dokl.md, u_dokl.datum_dokl, m.dodatok, u_dokl.poznamka, ROUND(u_dokl.dph*100-100,2), u_dokl.dal, ROUND(u_dokl.castka,2), ALLTRIM(u_dokl.hs_md)+ALLTRIM(u_dokl.hs_dal),"",ROUND(u_dokl.dan,2),"INTDOKL", .t., "", "")
					INSERT INTO intdokl (rtyp, rstat, batchname, line_no, ucet1, postdate, docno, descript, dph, ucet2, suma, gdc1, gdc2, cena_dph, jname, curstat, u_cis, rezno) VALUES ; 
						("ID", "N", "TržbyFood", m.i*10000, u_dokl.md, u_dokl.datum_dokl, DTOS(u_dokl.datum_dokl), u_dokl.poznamka, ROUND(u_dokl.dph*100-100,2), u_dokl.dal, ROUND(u_dokl.castka,2), ALLTRIM(u_dokl.hs_md)+ALLTRIM(u_dokl.hs_dal),"",ROUND(u_dokl.dan,2),"INTDOKL", .t., "", "")
					m.i=m.i+1
				ENDSCAN 
				SELECT u_doklady
				SCAN FOR id_kas=sklady.id_kas AND uzaverka=sklady.uzaverka
*!*						INSERT INTO intdokl (rtyp, rstat, batchname, line_no, ucet1, postdate, docno, descript, dph, ucet2, suma, gdc1, gdc2, cena_dph, jname, curstat, u_cis, rezno) VALUES ; 
*!*							("ID", "N", "TržbyFood", m.i*10000, u_doklady.md, u_doklady.datum_dokl, m.dodatok, u_doklady.poznamka, 0, u_doklady.dal, ROUND(u_doklady.castka,2), ALLTRIM(u_doklady.hs_md)+ALLTRIM(u_doklady.hs_dal),"",0,"INTDOKL", .t., SUBSTR(u_doklady.pz,19),"")
					INSERT INTO intdokl (rtyp, rstat, batchname, line_no, ucet1, postdate, docno, descript, dph, ucet2, suma, gdc1, gdc2, cena_dph, jname, curstat, u_cis, rezno) VALUES ; 
						("ID", "N", "TržbyFood", m.i*10000, u_doklady.md, u_doklady.datum_dokl, DTOS(u_doklady.datum_dokl), u_doklady.poznamka, 0, u_doklady.dal, ROUND(u_doklady.castka,2), ALLTRIM(u_doklady.hs_md)+ALLTRIM(u_doklady.hs_dal),"",0,"INTDOKL", .t., SUBSTR(u_doklady.pz,19),"")
					m.i=m.i+1
				ENDSCAN 
				IF tux(.t.,.t.,"intdokl")
					SELECT u_dokl
					SCAN FOR uzaverka=m.hladajuzaverka AND id_kas=m.hladajidkas AND oprava
						SELECT archivpolozky
						LOCATE FOR id_kas=m.hladajidkas AND uzaverka=m.hladajuzaverka AND ROUND(castka,2)=-ROUND(u_dokl.castka,2) AND ALLTRIM(md)=ALLTRIM(u_dokl.md) AND ALLTRIM(dal)=ALLTRIM(u_dokl.dal);
							 AND ALLTRIM(hs_md)=ALLTRIM(u_dokl.hs_md) AND ALLTRIM(hs_dal)=ALLTRIM(u_dokl.hs_dal) AND ALLTRIM(pz)=ALLTRIM(u_dokl.pz) AND ALLTRIM(poznamka)=ALLTRIM(u_dokl.poznamka)
						IF FOUND()
							DELETE
						ENDIF 
						SELECT u_dokl
					ENDSCAN 
					INSERT INTO archivpolozky (id_kas, uzaverka, castka, dan_zakl, dan_sadzba, md, dal, hs_md, hs_dal, md2, dal2, pz, poznamka, mesiac, rok, datum_dokl, c_data);
						SELECT id_kas, uzaverka, castka, danzakl, dph, md, dal, hs_md, hs_dal, md2, dal2, pz, poznamka, m.hladajmesiac as mesiac, m.hladajrok as rok, datum_dokl, m.cdata as c_data FROM u_dokl WHERE uzaverka=m.hladajuzaverka AND id_kas=m.hladajidkas AND !oprava
					SELECT u_doklady
					SCAN FOR uzaverka=m.hladajuzaverka AND id_kas=m.hladajidkas AND oprava
						SELECT archivplatby
						LOCATE FOR id_kas=m.hladajidkas AND uzaverka=m.hladajuzaverka AND ROUND(castka,2)=-ROUND(u_doklady.castka,2) AND ALLTRIM(md)=ALLTRIM(u_doklady.md) AND ALLTRIM(dal)=ALLTRIM(u_doklady.dal);
							 AND ALLTRIM(hs_md)=ALLTRIM(u_doklady.hs_md) AND ALLTRIM(hs_dal)=ALLTRIM(u_doklady.hs_dal) AND ALLTRIM(pz)=ALLTRIM(u_doklady.pz) AND ALLTRIM(poznamka)=ALLTRIM(u_doklady.poznamka)
						IF FOUND()
							DELETE
						ENDIF 
						SELECT u_doklady
					ENDSCAN 
					INSERT INTO archivplatby (id_kas, uzaverka, castka, md, dal, hs_md, hs_dal, md2, dal2, pz, poznamka, mesiac, rok, datum_dokl, c_data);
						SELECT id_kas, uzaverka, castka, md, dal, hs_md, hs_dal, md2, dal2, pz, poznamka, m.hladajmesiac as mesiac, m.hladajrok as rok, datum_dokl, m.cdata as c_data FROM u_doklady WHERE uzaverka=m.hladajuzaverka AND id_kas=m.hladajidkas AND !oprava
				ENDIF 
				USE IN intdokl
				=tux(.t.,.t.,"archivpolozky")
				=tux(.t.,.t.,"archivplatby")
			ENDIF 
			SELECT sklady
		ENDSCAN 
		**** Zapis o prenose uzavierok do sk_sez.dbf
		IF m.issql
			USE (m.sqlprefix+"rsksezuctoneprenesene") ALIAS sksezx IN 0
			=CURSORSETPROP("Buffering",5,"sksezx")
			UPDATE sksezx SET uctexport=.t. WHERE uzaverka in (SELECT disti uzaverka FROM sklady)
			=tux(.t.,.t.,"sksezx")
			USE IN sksezx
		ELSE 
			IF !USED("sk_sez")
				USE (m.fn_sk_sez) ALIAS sk_sez IN 0
				UPDATE sk_sez SET uctexport=.t. WHERE uzaverka in (SELECT disti uzaverka FROM sklady)
				USE IN sk_sez
			ELSE 
				UPDATE sk_sez SET uctexport=.t. WHERE uzaverka in (SELECT disti uzaverka FROM sklady)
			ENDIF 
		ENDIF 
		**** A este pripadny zapis o prenose uzavierok do hor_uzav.dbf
		IF m.gcuct_hores
			IF m.issql
				USE (m.sqlprefix+"rhoruzav") ALIAS horcen IN 0
				=CURSORSETPROP("Buffering",5,"horcen")
			ELSE
				IF FILE(m.gccen_path+"hor_uzav.dbf")	
					USE (m.gccen_path+"hor_uzav") IN 0 ALIAS horcen
				ENDIF 
			ENDIF 
			IF USED("horcen")
				SELECT uzaverka, DATE() as datum FROM sklady WHERE id_kas="WH" AND !(uzaverka in (SELECT uzaverka FROM horcen)) INTO CURSOR dopln READWRITE 
				REPLACE ALL datum WITH CTOD(SUBSTR(uzaverka,7,2)+"."+SUBSTR(uzaverka,5,2)+"."+LEFT(uzaverka,4))
				UPDATE horcen SET uctexport=.t. from sklady WHERE horcen.uzaverka=sklady.uzaverka AND sklady.id_kas="WH"
				INSERT INTO horcen (uzaverka, datum, uctexport) SELECT uzaverka, datum, .t. FROM dopln
				USE IN dopln
				IF m.issql
					=tux(.t.,.t.,"horcen")
				ENDIF
				USE IN horcen	
			ENDIF 
		ENDIF 
	ENDIF 
	DO pozavirej WITH "archivplatby, archivpolozky, uexarchplozky, uexarchplatby, sklady"
ENDIF 

FUNCTION dajsapcdcislo
PARAMETERS m.hladajmeno, m.hladajrok, m.hladajmesiac, m.hladajden, m.hladajevidencia, m.hladajcisrad
LOCAL navrat, oldsel
m.oldsel=SELECT()
IF m.issql
	DO CASE 
		CASE LOWER(m.gcuct_typ)="sap" AND LOWER(m.gcuct_spec)="nbs"
			USE (m.sqlprefix+"rsapcd") ALIAS sap_cd IN 0
		CASE !EMPTY(m.hladajcisrad) AND !EMPTY(m.hladajevidencia)
			USE (m.sqlprefix+"rsapcd_rokmesiacevidenciacisrad") ALIAS sap_cd IN 0
		CASE EMPTY(m.hladajden) AND !EMPTY(m.hladajevidencia)
			USE (m.sqlprefix+"rsapcd_rokmesiacevidencia") ALIAS sap_cd IN 0
		CASE EMPTY(m.hladajden) AND EMPTY(m.hladajevidencia)
			USE (m.sqlprefix+"rsapcd_rokmesiac") ALIAS sap_cd IN 0
		CASE !EMPTY(m.hladajden) AND EMPTY(m.hladajevidencia)
			USE (m.sqlprefix+"rsapcd_rokmesiacden") ALIAS sap_cd IN 0
		CASE EMPTY(m.hladajden) AND !EMPTY(m.hladajevidencia)
			USE (m.sqlprefix+"rsapcd_rokmesiacevidencia") ALIAS sap_cd IN 0
	ENDCASE  
	=CURSORSETPROP("Buffering",5,"sap_cd")
	IF RECCOUNT("sap_cd")=0
		DO CASE 
			CASE LOWER(m.gcuct_typ)="sap" AND LOWER(m.gcuct_spec)="nbs"
				INSERT INTO sap_cd (meno, rok, mesiac, pc) VALUES (DTOS(DATE()), m.hladajrok, m.hladajmesiac, 1)
			CASE !EMPTY(m.hladajcisrad) AND !EMPTY(m.hladajevidencia)
				INSERT INTO sap_cd (meno, rok, mesiac, evidencia, cisrad, pc) VALUES (m.hladajmeno, m.hladajrok, m.hladajmesiac, m.hladajevidencia, m.hladajcisrad, 1)
			CASE EMPTY(m.hladajden) AND EMPTY(m.hladajevidencia)
				INSERT INTO sap_cd (meno, rok, mesiac, pc) VALUES (m.hladajmeno, m.hladajrok, m.hladajmesiac,1)
			CASE !EMPTY(m.hladajden) AND EMPTY(m.hladajevidencia)
				INSERT INTO sap_cd (meno, rok, mesiac, den, pc) VALUES (m.hladajmeno, m.hladajrok, m.hladajmesiac, m.hladajden, 1)
			CASE EMPTY(m.hladajden) AND !EMPTY(m.hladajevidencia)
				INSERT INTO sap_cd (meno, rok, mesiac, evidencia, pc) VALUES (m.hladajmeno, m.hladajrok, m.hladajmesiac, m.hladajevidencia, 1)
		ENDCASE  
		IF LOWER(m.gcuct_typ)="sap" AND LOWER(m.gcuct_spec)="nbs"
			m.navrat="food_"+DTOS(DATE())+"1.xml"
		ELSE 
			m.navrat=1
		ENDIF 
	ELSE 
		SELECT sap_cd
		GO TOP 
		IF LOWER(m.gcuct_typ)="sap" AND LOWER(m.gcuct_spec)="nbs"
			IF sap_cd.meno=DTOS(DATE())
				REPLACE pc WITH pc+1
			ELSE
				REPLACE meno WITH DTOS(DATE()), pc WITH 1
			ENDIF 
			m.navrat="food_"+ALLTRIM(meno)+ALLTRIM(STR(pc,10,0))+".xml"
		ELSE 
			REPLACE pc WITH pc+1
			m.navrat=sap_cd.pc
		ENDIF 
	ENDIF 
	=tux(.t.,.t.,"sap_cd")
ELSE
	SELECT 0
	USE (m.gccen_path+"sap_cd") 
	DO CASE 
		CASE !EMPTY(m.hladajcisrad) AND !EMPTY(m.hladajevidencia)
			LOCATE FOR meno=m.hladajmeno AND rok=m.hladajrok AND mesiac=m.hladajmesiac AND evidencia=m.hladajevidencia AND cisrad=m.hladajcisrad
		CASE EMPTY(m.hladajden) AND EMPTY(m.hladajevidencia)
			LOCATE FOR meno=m.hladajmeno AND rok=m.hladajrok AND mesiac=m.hladajmesiac
		CASE !EMPTY(m.hladajden) AND EMPTY(m.hladajevidencia)
			LOCATE FOR meno=m.hladajmeno AND rok=m.hladajrok AND mesiac=m.hladajmesiac AND den=m.hladajden
		CASE EMPTY(m.hladajden) AND !EMPTY(m.hladajevidencia)
			LOCATE FOR meno=m.hladajmeno AND rok=m.hladajrok AND mesiac=m.hladajmesiac AND evidencia=m.hladajevidencia
	ENDCASE  
	IF FOUND()
		REPLACE pc WITH pc+1
		m.navrat=sap_cd.pc
	ELSE 		
		DO CASE 
			CASE !EMPTY(m.hladajcisrad) AND !EMPTY(m.hladajevidencia)
				INSERT INTO sap_cd (meno, rok, mesiac, evidencia, cisrad, pc) VALUES (m.hladajmeno, m.hladajrok, m.hladajmesiac, m.hladajevidencia, m.hladajcisrad, 1)
			CASE EMPTY(m.hladajden) AND EMPTY(m.hladajevidencia)
				INSERT INTO sap_cd (meno, rok, mesiac, pc) VALUES (m.hladajmeno, m.hladajrok, m.hladajmesiac,1)
			CASE !EMPTY(m.hladajden) AND EMPTY(m.hladajevidencia)
				INSERT INTO sap_cd (meno, rok, mesiac, den, pc) VALUES (m.hladajmeno, m.hladajrok, m.hladajmesiac, m.hladajden, 1)
			CASE EMPTY(m.hladajden) AND !EMPTY(m.hladajevidencia)
				INSERT INTO sap_cd (meno, rok, mesiac, evidencia, pc) VALUES (m.hladajmeno, m.hladajrok, m.hladajmesiac, m.hladajevidencia, 1)
		ENDCASE  
		m.navrat=1
	ENDIF 
ENDIF 
DO pozavirej WITH "sap_cd"
SELECT (m.oldsel)
RETURN m.navrat	


FUNCTION setsapcdcislo
PARAMETERS m.hladajmeno, m.hladajrok, m.hladajmesiac, m.rozdiel
LOCAL navrat, oldsel
m.oldsel=SELECT()
IF m.issql
	USE (m.sqlprefix+"rsapcd_rokmesiac") ALIAS sap_cd IN 0
	=CURSORSETPROP("Buffering",5,"sap_cd")
	IF RECCOUNT("sap_cd")=0
		GO TOP 
		REPLACE pc WITH pc+m.rozdiel
	ELSE 
		INSERT INTO sap_cd (meno, rok, mesiac, pc) VALUES (m.hladajmeno, m.hladajrok, m.hladajmesiac,m.rozdiel)
	ENDIF 
	=tux(.t.,.t.,"sap_cd")
ELSE
	SELECT 0
	USE (m.gccen_path+"sap_cd") 
	LOCATE FOR meno=m.hladajmeno AND rok=m.hladajrok AND mesiac=m.hladajmesiac
	IF FOUND()
		REPLACE pc WITH pc+m.rozdiel
	ELSE 
		INSERT INTO sap_cd (meno, rok, mesiac, pc) VALUES (m.hladajmeno, m.hladajrok, m.hladajmesiac,m.rozdiel)
	ENDIF 
ENDIF 
DO pozavirej WITH "sap_cd"
SELECT (m.oldsel)
RETURN m.navrat	




FUNCTION odosli_export_mailom
PARAMETERS menosuboru, subject, adresakam
IF EMPTY(m.subject)
	m.subject=m.hotel_name
ENDIF 
IF !EMPTY(m.food_smtpserver) AND !EMPTY(m.food_smtpport)
	=poslimailnapriamo(m.subject,"",m.menosuboru)
ELSE 
	m.gcklient = getklient()
	IF !EMPTY(m.gcklient)
		DO CASE 
			CASE "outlook"$LOWER(m.gcklient)
				olApp = CreateObject("Outlook.Application")
				olMsg = olApp.CreateItem(0)
				With olMsg
					.To = m.adresakam
					.Subject = m.subject
					.Attachments.Add(m.menosuboru)
					.send()
				ENDWITH 
				RELEASE olmsg
				RELEASE olapp
				=MESSAGEBOX(jaz("form_export_odoslany_na_mail")+" "+m.adresakam,64,"FoodMan",2000)
				=STRTOFILE(TTOC(DATETIME())+" "+"Export bol poslaný na adresu "+m.adresakam+". Meno súboru:"+m.menosuboru+CHR(13)+CHR(10),(m.gchom_path+"suboryposlanemailom.log"),1)
			CASE "thunde"$LOWER(m.gcklient)
					m.prikazmail="run /N7 "+STRTRAN(m.gcklient,'"%1"',"")+' "attachment'+"='file:///"+m.menosuboru+"',to="+m.adresakam+",subject="+m.subject+'"'
				&prikazmail
			CASE "msimn"$LOWER(m.gcklient)
				oe=CREATEOBJECT("outlookexpress")
				oe.mail_send(m.menosuboru)
				RELEASE oe
				LOCAL lnhodnota, lcwindow
				lcwindow = ALLTRIM(_SCREEN.CAPTION)
				lnhodnota = 0
				lcwindow = lcwindow+CHR(0)
				lnhodnota = findwindow(.NULL., lcwindow)
				IF lnhodnota<>0
					bringwindowtotop(lnhodnota)
					SHOWWINDOW(lnhodnota, 3)
				ENDIF
		ENDCASE
	ENDIF
ENDIF 



FUNCTION poslimailnapriamo
PARAMETERS subjekt, telo, priloha
IF EMPTY(m.telo)
	m.telo=m.subjekt
ENDIF 
LOCAL loConfig AS CDO.Configuration, loFlds AS Object, loMsg AS CDO.Message
*!*	m.smtpserver="smtp.alto.sk"
*!*	m.smtpport=587
*!*	m.smtpuser="milan.barlok.alto"
*!*	m.smtpheslo="mixxba"
*!*	m.smtpssl=.f.
*!*	m.uct_email="milan@alto.sk"
*!*	m.uct_email_from="milan.barlok@alto.sk"
loConfig = CREATEOBJECT("CDO.Configuration")
loFlds = loConfig.Fields
WITH loFlds
	*- Set the CDOSYS configuration fields to use port 25 on the SMTP server.
	.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
	*- Enter name or IP address of remote SMTP server.
	.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = m.food_smtpserver
	.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = m.food_smtpport
	*- Assign timeout in seconds
	.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
	.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = m.food_smtpssl
	*- Commit changes to the object
	IF m.smtpauth<>0
		.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = m.food_smtpuser
		.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = m.food_smtpheslo
	ENDIF 
	.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = m.food_smtpauth            
	* .item("http://schemas.microsoft.com/cdo/configuration/cdoURLProxyServer") = "smtp.mail.yahoo.com"
	.Update()
ENDWITH
*- Create and send the message.
loMsg = CREATEOBJECT("CDO.Message")
WITH loMsg
	.Configuration = loConfig
	.To = m.adresakam
	.From = m.uct_email_from
	.Subject = m.subjekt
	.HTMLBody = m.telo
	.AddAttachment(m.priloha)
	TRY
		.Send()
	CATCH TO oerr
		MESSAGEBOX(oerr.message)
	ENDTRY
ENDWITH 
=STRTOFILE(TTOC(DATETIME())+" "+"Export bol poslaný na adresu "+m.adresakam+". Meno súboru:"+m.priloha,(m.gchom_path+"suboryposlanemailom.log"),1)



PROCEDURE kontrola_stravy
PARAMETERS hladajdatumod, hladajdatumdo
IF m.issql
	USE (m.sqlprefix+"ruexarchstrava_mesiacrok") ALIAS uexarchjedla IN 0
ELSE 
	IF !FILE(m.gccen_path+"uexarchstrava.dbf")
		DO creafile WITH (m.gccen_path+"uexarchstrava.dbf")
	ENDIF 
	IF !USED("uexarchstrava")
		USE (m.gccen_path+"uexarchstrava") IN 0
	ENDIF 
	USE vuexarchstrava_mesiacrok IN 0 ALIAS uexarchjedla
ENDIF 
=CURSORSETPROP("Buffering",5,"uexarchjedla")

SELECT DISTINCT datum FROM u_ex_strava INTO CURSOR datumy READWRITE 
*** Kontrola dokladov v exporte na ich stav v UEXARCH ***
*
SCAN ALL
	m.oprava=.F.
	SELECT u_ex_strava
	SCAN FOR datum=datumy.datum
		SELECT uexarchjedla
		LOCATE FOR id_strav=u_ex_strava.id_strav AND datum=u_ex_strava.datum .AND. pocet=u_ex_strava.pocet .AND. ALLTRIM(oscislo)=ALLTRIM(u_ex_strava.oscislo) .AND. ALLTRIM(MD)=ALLTRIM(u_ex_strava.MD) .AND. ALLTRIM(dal)=ALLTRIM(u_ex_strava.dal) .AND. ALLTRIM(stredisko)=ALLTRIM(u_ex_strava.stredisko) .AND. ALLTRIM(dph_dal)=ALLTRIM(u_ex_strava.dph_dal) ;
			.AND. dph=u_ex_strava.dph .AND. suma=u_ex_strava.suma 
		IF !FOUND()
			m.oprava=.T.
		ENDIF
		SELECT u_ex_strava
	ENDSCAN
	IF m.oprava
		SELECT uexarchjedla
		SCAN FOR datum=datumy.datum
			INSERT INTO u_ex_strava (datum, id_strav, pocet, oscislo, stredisko, suma, MD, dal, dph_dal, dph);
				VALUES (uexarchjedla.datum, uexarchjedla.id_strav,-uexarchjedla.pocet, uexarchjedla.oscislo, uexarchjedla.stredisko, ;
				-uexarchjedla.suma, uexarchjedla.MD, uexarchjedla.dal, uexarchjedla.dph_dal, uexarchjedla.dph)
		ENDSCAN
	ELSE
		SELECT u_ex_strava
		DELETE FOR datum=datumy.datum
	ENDIF
	SELECT datumy
ENDSCAN
*
*** Kontrola datumov v exporte na ich stav v uexarchjedla ***
*** Hladanie datumov z uexarchjedla, ktore uz neexistuju a treba ich stornovat v exporte ***
*
SELECT DISTINCT datum FROM uexarchjedla WHERE !(datum IN (SELECT DISTINCT datum FROM datumy));
	INTO CURSOR datumy2 READWRITE 
SCAN ALL
	SELECT uexarchjedla
	SCAN FOR datum=datumy2.datum
		INSERT INTO u_ex_strava (datum, id_strav, pocet, oscislo, stredisko, suma, MD, dal, dph_dal, dph);
			VALUES (uexarchjedla.datum, uexarchjedla.id_strav,-uexarchjedla.pocet, uexarchjedla.oscislo, uexarchjedla.stredisko, ;
			-uexarchjedla.suma, uexarchjedla.MD, uexarchjedla.dal, uexarchjedla.dph_dal, uexarchjedla.dph)
	ENDSCAN
	SELECT datumy2
ENDSCAN
USE IN datumy2
*
*** Hladanie datumov z uexarchjedla, ktore uz neexistuju a treba ich stornovat v exporte ***
USE IN datumy



PROCEDURE navision_id_strava
PRIVATE datz, m.menoexp, m.filehl, m.filepol, m.poloziek
PRIVATE m.hladajrok, m.hladajmesiac, m.hladajpz, m.hladajuzaverka, m.hladajucis
m.hladajrok=m.mrok
m.hladajmesiac=m.mmesiac
LOCAL dodatok, m.datz, m.dodatok1
m.datz=GOMONTH(CTOD("01."+m.mmesiac+"."+m.mrok),1)-1
IF USED("u_ex_strava")
	SELECT datum, id_strav, SUM(pocet) as pocet, SUM(suma) as suma, md, dal, dph_dal, dph, oscislo, stredisko FROM u_ex_strava GROUP BY datum, id_strav, md, dal, dph_dal, dph, oscislo, stredisko INTO CURSOR ustrava READWRITE 
	DELETE FOR pocet=0
	SELECT SUM(pocet) as pocet, SUM(suma) as suma, md, dal, dph_dal, dph, stredisko FROM ustrava GROUP BY md, dal, dph_dal, dph, stredisko INTO CURSOR stravavon READWRITE ORDER BY stredisko
	*** Cislo riadku musim nastavit uz tu, aby sa to cele v Navision tvarilo ako jeden doklad
	m.i=1
	m.dodatok="Strava "+m.mrok+"/"+m.mmesiac 	&&Toto bude oznacenie dokladu v Navision
	m.dodatok1=m.mrok+"/"+m.mmesiac +" - Strava" &&Toto vytvaram, aby som zobrazil priebeh a aby som z Navision nestahoval stale vsetky riadky
	IF otvor_navision_intdokl(m.navision_firma,"intdokl","internaldocuments.DocumentNo='"+m.dodatok1+"'")
		SELECT stravavon
		SCAN ALL 
			INSERT INTO intdokl (rtyp, rstat, batchname, line_no, ucet1, postdate, docno, descript, dph, ucet2, suma, gdc1, gdc2, cena_dph, jname, curstat, u_cis, rezno) VALUES ; 
				("ID", "N", "Strava", m.i*10000, stravavon.md, m.datz, m.dodatok, m.dodatok, stravavon.dph*100-100, stravavon.dal, ROUND(stravavon.suma,2), ALLTRIM(stravavon.stredisko),"",ROUND(stravavon.suma*(stravavon.dph-1)/stravavon.dph,2),"INTDOKL",.t.,"","")
			m.i=m.i+1
		ENDSCAN 
		IF tux(.t.,.t.,"intdokl")
			SELECT disti datum, id_strav FROM ustrava INTO CURSOR naopravu
			LOCAL oprdatum, opridstrav
			SCAN ALL
				m.oprdatum=naopravu.datum
				m.opridstrav=naopravu.id_strav
				SELECT * FROM uexarchjedla WHERE datum=m.oprdatum AND id_strav=m.opridstrav INTO CURSOR aktstrav READWRITE 
				INSERT INTO aktstrav (datum, id_strav, pocet, suma, oscislo, stredisko, md, dal, dph_dal, dph) SELECT datum, id_strav, pocet, suma, oscislo, stredisko, md, dal, dph_dal, dph FROM ustrava WHERE datum=m.oprdatum AND id_strav=m.opridstrav
				DELETE FROM uexarchjedla WHERE datum=m.oprdatum AND id_strav=m.opridstrav 
				INSERT INTO uexarchjedla (datum, id_strav, pocet, suma, oscislo, stredisko, md, dal, dph_dal, dph) SELECT datum, id_strav, SUM(pocet) as pocet, SUM(suma) as suma, oscislo, stredisko, md, dal, dph_dal, dph FROM aktstrav group by datum, id_strav, oscislo, stredisko, md, dal, dph_dal, dph
				SELECT naopravu
			ENDSCAN 
			SELECT uexarchjedla
			=tux(.t.,.t.,"uexarchjedla")
		ENDIF 
	ENDIF 
	DO pozavirej WITH "uexarchjedla, uexarchstrava, ustrava, stravavon, intdokl, naopravu, aktstrav"
ENDIF 
