PRIVATE m.mail_kam_poslat, m.zoznam_reportov1, m.zoznam_reportov2, m.datum_reportu1, m.datum_reportu2, m.typ_exportu, m.typ_exportu1, m.typ_exportu2
LOCAL m.kusoktextu, m.riadok, stlpec
m.mail_kam_poslat="milan@alto.sk"
*--------------------------------------
m.koniecdna="08:00:00"
m.uctdatum="FISKAL" && "CAS" - den sa konci na druhy den v hodine m.koniecdna
*--------------------------------------

m.typ_exportu1="PDF" && FDOC, FODS, FRTF
m.typ_exportu2="" && XLS 
*--------------------------------------
m.zoznam_reportov1="Sada 1"
m.zoznam_reportov2="Sada 1"

*m.zoznam_reportov1="Sada 2"
*m.zoznam_reportov2="Sada 2"

*m.zoznam_reportov1="Sada 3"
*m.zoznam_reportov2="Sada 3"

*m.zoznam_reportov1="1-1,12-1"
*m.zoznam_reportov2="1-1,12-2"
*** riadok reportu-stlpec reportu,.....
*--------------------------------------
datum_reportu1=CTOD("01."+PADL(ALLTRIM(STR(MONTH(DATE()),2,0)),2,"0")+"."+ALLTRIM(STR(YEAR(DATE()),4,0)))
datum_reportu2=DATE()
*--------------------------------------
m.s_trz_mutace = "karty.nazev1"
m.cen_hladiny="123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0"
m.gcbaraky_summary=""
datsk1 = DTOC(datum_reportu1)
datsk2 = DTOC(datum_reportu2)
m.cen_hlad_txt = ""

DO nastavsety
DO dopln_uctden_do_sksez
DO clos_data
DO open_database
chyba_pri_otevirani = .f.
TRY
	IF m.issql
		otevira_se = "fooddat"
		rv("fooddat","fd")
		otevira_se = "skupiny"
		rv("skupiny","skupiny")
		otevira_se = "karty"
		rv("karty","karty")
		SELECT karty
		INDEX ON c_karty TAG c_karty
		INDEX ON nazev TAG nazev
		otevira_se = "zosttrz_sez"
		rv("zosttrz_sez","sk_sez")
	ELSE
		otevira_se = m.fn_karty
		USE (m.fn_karty)   ALIAS karty   ORDE nazev IN 0
		otevira_se = m.fn_food_dat
		USE (m.gchom_path + "food_dat") ORDER ID ALIAS fd IN 0
		otevira_se = m.fn_skupiny
		USE (m.fn_skupiny) ALIAS skupiny ORDE druh NOUPDATE IN 0
		otevira_se = m.fn_sk_sez
		USE (m.fn_sk_sez)   ALIAS sk_sez IN 0
	ENDIF
CATCH
	chyba_pri_otevirani = .T.
ENDTRY
IF chyba_pri_otevirani
	=MESSAGEBOX(jaz("prg_dbf_neprist_skuste_pozdeji")+CHR(13)+m.otevira_se,64,"FoodMan",2)
	DO zurnal_log WITH "OPERA", jaz("form s_trzby"), jaz("nejde_otevrit") + m.otevira_se
	RETURN
ENDIF

SELECT fd
LOCATE FOR ALLTRIM(UPPER(pgm))=="KRE"
IF FOUND()
	m.crd_path=ALLTRIM(fd.dat_path)
ELSE
	m.crd_path=""
ENDIF 
SELECT DISTINCT uzaverka, id_kas, lastuzav + SPACE(20) AS lastuzav, uct_den, fd.id_zkratka, fd.stredskup, .T. AS lbl, .T. AS ukazat, .F. AS barva, SPACE(14) AS uct_den_tx ;
	FROM sk_sez LEFT JOIN fd ON fd.ID == sk_sez.id_kas ;
	INTO CURSOR uzaverky READWRITE

REPLACE FOR ISNULL(id_zkratka) id_zkratka WITH "-- " + id_kas + " --"
REPLACE FOR ISNULL(stredskup) stredskup WITH ""
REPLACE lastuzav WITH id_zkratka FOR !INLIST(LEFT(lastuzav,2),"L_","D_") .AND. RIGHT(ALLTRIM(uzaverka),3)<>"***"
REPLACE lastuzav WITH SUBSTR(lastuzav,3) FOR LEFT(lastuzav,2)="D_"
IF m.issql 
	rv("limhlmena", "limit_hl")
	SELECT limit_hl
	SELECT uzaverky
	UPDATE uzaverky SET lastuzav=limit_hl.menolimit from limit_hl WHERE VAL(SUBSTR(lastuzav,3))=limit_hl.id_limit AND LEFT(lastuzav,2)="L_"
	USE IN limit_hl
ELSE 
	IF FILE(m.gcdat_path+"limit_hl.dbf")
		USE (m.gcdat_path+"limit_hl.dbf") ORDER id_limit IN 0
		UPDATE uzaverky SET lastuzav=limit_hl.limit from limit_hl WHERE VAL(SUBSTR(lastuzav,3))=limit_hl.id_limit AND LEFT(lastuzav,2)="L_"
		USE IN limit_hl
	ENDIF
	IF FILE(m.gcdat_path+"nlimit_hl.dbf")
		USE (m.gcdat_path+"nlimit_hl.dbf") IN 0
		SELECT uzaverky
		UPDATE uzaverky SET lastuzav=nlimit_hl.menolimit from nlimit_hl WHERE VAL(SUBSTR(lastuzav,3))=nlimit_hl.id_limit AND VAL(SUBSTR(lastuzav,3))>0 AND LEFT(lastuzav,2)="L_"
		USE IN nlimit_hl
	ENDIF
ENDIF 
IF m.uctdatum="CAS"
	SELECT uzaverky
	REPLACE uct_den WITH uct_den-1 FOR DTOS(uct_den)=LEFT(uzaverka,8) AND BETWEEN(RIGHT(uzaverka,8),"00:00:00",m.koniecdna)
ENDIF
DELETE FROM uzaverky WHERE uct_den<m.datum_reportu1 OR uct_den>m.datum_reportu2 
REPLACE FOR "*" $ uzaverka lastuzav WITH id_kas + " | " + lastuzav
REPLACE ALL uct_den_tx WITH DTOC(uct_den) + " " + den_v_tydnu(uct_den)
INDEX ON DTOS(uct_den) + uzaverka TAG den_uzav

*************************
SELECT DISTI id_kas, id_zkratka, lbl, stredskup ;
	FROM uzaverky ;
	INTO CURSOR selkasy READWRITE 

INDEX ON             id_kas TAG id_kas UNIQ
INDEX ON stredskup + id_kas TAG ss_kas UNIQ
SELECT selkasy
m.gcpomocna="Pokladne: "
SCAN FOR lbl
	m.gcpomocna=m.gcpomocna+ALLTRIM(selkasy.id_zkratka)+", "
ENDSCAN 
IF LEN(ALLTRIM(m.gcpomocna))>120
	m.gcpomocna="Pokladne: "
	SCAN FOR lbl
		m.gcpomocna=m.gcpomocna+ALLTRIM(selkasy.id_kas)+", "
	ENDSCAN 
ENDIF 
m.gcpomocna=LEFT(m.gcpomocna,LEN(m.gcpomocna)-2)
GO TOP

*************************
SELECT DISTINCT c_druh, druh, .T. AS lbl, typ_skup, typ_skl, typ_kalk ;
	FROM skupiny INTO cursor seldruhy READWRITE
INSERT INTO seldruhy (druh, lbl) VALUES (m.ostatni, .T.)
INDEX ON druh TAG druh
GO TOP
m.reporty_volane_z_formu=.f.



CREATE CURSOR sestavy (druh c(55), lbl l,g1 l, g2 l, g3 l, g4 l, g5 l, dily c(5), cmd c(99), klic c(30),txt1 c(30),txt2 c(30),txt3 c(30),txt4 c(30),txt5 c(30))
*                                                                               123456789012345678901234567890
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3,txt4, txt5) VALUES ("s_trz kas po dph",    "DO s_kas_dph",		  		"s_trz kas po dph","s_trz kas po dph suma", "s_trz_sparty a platby", "s_trz kas po dph", "hlaseni k DPH")
INSERT INTO sestavy (klic, cmd,txt1,txt2)			VALUE ("s_trz kas po managerech",    "DO s_kas_man",				"s_trz trzby", "s_trz vynosy")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3)		VALUE ("s_trz kas po druzich",       "DO s_dr_str WITH 'id_kas'",	"s_trz kas po druzich", "s_trz po druzich", "s_trz po cas.atrib.")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3)		VALUE ("s_trz man po dr.",           "DO s_dr_str WITH 'id_man'",	"s_trz man po druzich", "s_trz po druzich", "s_trz po cas.atrib.")
INSERT INTO sestavy (klic, cmd,txt1,txt2)			VALUE ("s_trz po platbach/kasach",   "DO s_plat_kas",				"s_trz po platbach/kasach","s_trz po kasach/platbach")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3,txt4) VALUE ("s_trz po platbach/dph",      "DO s_plat_dph",				"s_trz platbach/dph","s_trz dph/platba","s_trz dph/platba aj sumy", "s_trz dph/platba meny")
INSERT INTO sestavy (klic, cmd,txt1,txt2)			VALUE ("s_trz casatr",               "DO s_cas_atr",				"s_trz casatr", "s_trz casatr")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3,txt4,txt5) VALUE ("s_trz prodzboz kas-man","DO s_zbozi with 'KASMAN'",	"s_trz prodzboz kas", "s_trz prodzboz man", "s_trz", "s_trz", "s_trz")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3)		VALUE ("s_trz prodzboz stredskup",   "DO s_zbozi with 'CELK'",      "s_trz prodzboz celkem", "s_trz prodzboz stredskup","s_trz_prodzboz_kalk")
INSERT INTO sestavy (klic, cmd,txt1)				VALUE ("s_trz prodzboz dph",         "DO s_zbozi with 'DPH'",		"s_trz prodzboz dph")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3)		VALUE ("s_trz profit",               "DO s_profit WITH 'KAS'",		"s_trz profit","s_trz profit sumar", "s_trz profit 3")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3)		VALUE ("s_trz profit house",         "DO s_profit WITH 'HOTEL'",	"s_trz profit","s_trz profit sumar", "s_trz profit 3")
INSERT INTO sestavy (klic, cmd,txt1)				VALUE ("s_trz rozpeti uzav",         "DO rozpeti with 'UZAV'",		"s_trz rozpeti uzav")
INSERT INTO sestavy (klic, cmd,txt1,txt2)			VALUE ("s_trz rozpeti kas/man",      "DO rozpeti with 'KASMAN '",   "s_trz rozpeti kas/man", "s_trz rozpeti man/kas")
INSERT INTO sestavy (klic, cmd,txt1)				VALUE ("s_trz rozpeti dph",          "DO rozpeti with 'DPH'",		"s_trz rozpeti dph")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3)  	VALUE ("s_trz ucty",                 "DO s_ucty ",	 		        "s_trz ucty uzavierka", "s_trz ucty platba", "s_trz ucty detail")
INSERT INTO sestavy (klic, cmd,txt1)				VALUE ("s_trz 1 karta po dnech",     "DO s_1karta_po_dnech ",		"s_trz 1 karta po dnech")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3,txt4) VALUE ("s_trz trzby cisniku",        "DO mark_cis",					"s_trz trzby cisniku", "s_trz trzby cisniku sumar", "s_trz trzby cisniku 2.dil", "Objednavky")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3)		VALUE ("s_trz slevy",                "DO slevy",					"s_trz slevy", "s_trz slevy", "s_trz slevy sumar")
INSERT INTO sestavy (klic, cmd,txt1)				VALUE ("s_trz stoly",                "DO po_stolech",				"s_trz stoly")
INSERT INTO sestavy (klic, cmd,txt1)				VALUE ("s_trz po platbach/slevach",  "DO s_slev_kas",				"s_trz po platbach/slevach")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3,txt4)	VALUE ("s_trz odpocty davek",        "DO odp_davk",					"s_trz odpocty davek","s_trz odpocty davek sumar","s_trz odpocty davek druhy","s_trz odpocty davek sparty")
INSERT INTO sestavy (klic, cmd,txt1)				VALUE ("s_trz transakce",            "DO transakce",				"s_trz transakce")
INSERT INTO sestavy (klic, cmd,txt1)				VALUE ("s_trz dph/druh",             "DO dph_druh",					"s_trz dph/druh")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3,txt4)	VALUE ("s_trz rozpeti davek",        "DO rozpdavk with .t.,sestavy.dily","s_trz rozpeti davek","s_sk_trz druhy_uzavierky_druhy","sumár","sumár_druhy")
INSERT INTO sestavy (klic, cmd,txt1,txt2)			VALUE ("s_trz po hodinach",			 "DO s_hodiny",                 "s_trz po hod.","s_trz po hod.sumar")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3,txt4) VALUE ("s_trz rozpatie kas",		 "DO rozpdavk with .f.,sestavy.dily","s_trz rozpatie kas","s_sk_trz druhy_uzavierky_druhy","sumár","sumár_druhy")
INSERT INTO sestavy (klic, cmd,txt1,txt2,txt3)		VALUE ("s_trz kontrola eet",         "DO kontrola_eet",				"EET celkem", "EET neposlane", "subtotaly")



IF FILE(m.gccen_path + "narody.dbf")
	INSERT INTO sestavy (klic, cmd,txt1) VALUE ("s_trz narodnosti",           "DO mutace",	"s_trz narodnosti")
ENDIF




CREATE CURSOR zostavy (druh c(55), lbl l, dily c(5), cmd c(99), klic c(30),txt1 c(30),txt2 c(30),txt3 c(30),txt4 c(30),txt5 c(30),g1 l, g2 l, g3 l, g4 l, g5 l)
*                                                                123456789012345678901234567890
INSERT INTO zostavy (klic, cmd,txt1)						VALUE ("s_sk_trz rozp",           "DO pr_rozpe WITH 1 IN sk_stati","s_sk_trz rozp")
INSERT INTO zostavy (klic, cmd,txt1)						VALUE ("s_sk_trz rozp odpocty",   "DO pr_rozpe WITH 2 IN sk_stati","s_sk_trz rozp odpocty")
INSERT INTO zostavy (klic, cmd,txt1)						VALUE ("s_sk_trz rozp druhy",     "DO pr_rozpe WITH 3 IN sk_stati","s_sk_trz rozp druhy")
INSERT INTO zostavy (klic, cmd,txt1)						VALUE ("s_sk_trz rozp druhy kasy","DO pr_rozpe WITH 4 IN sk_stati","s_sk_trz rozp druhy kasy")
INSERT INTO zostavy (klic, cmd,txt1)						VALUE ("s_sk_trz rozp kasy",      "DO pr_rozpe WITH 5 IN sk_stati","s_sk_trz rozp kasy")
INSERT INTO zostavy (klic, cmd,txt1)						VALUE ("s_sk_trz rozp kasy many", "DO pr_rozpe WITH 6 IN sk_stati","s_sk_trz rozp kasy many")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3,txt4,txt5)	VALUE ("s_sk_trz rozp hlad kasy", "DO pr_rozpe WITH 7, zostavy.dily IN sk_stati","s_sk_trz rozp hlad kasy","s_sk_trz rozp hlad druh","s_sk_trz rozp hlad nazev","s_sk_trz rozp hlad spart","s_sk_trz rozp hlad dan")
INSERT INTO zostavy (klic, cmd,txt1)						VALUE ("s_sk_trz rozp limity",    "DO pr_rozpe WITH 8 IN sk_stati","s_sk_trz rozp limity")
INSERT INTO zostavy (klic, cmd,txt1,txt2)					VALUE ("s_sk_trz rozp ucty","DO pr_rozpe WITH 9, zostavy.dily IN sk_stati","s_sk_trz rozp ucty","s_sk_trz rozp ucty detail")
INSERT INTO zostavy (klic, cmd,txt1)						VALUE ("s_sk_trz rozp davky",     "DO pr_rozpe WITH 11 IN sk_stati","s_sk_trz rozp davky")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3)				VALUE ("s_sk_trz storna",   "DO stor_cas IN sk_stati with zostavy.dily","s_sk_trz storna","s_sk_trz storna_ucty","s_sk_trz storna_sumar")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3,txt4,txt5)	VALUE ("s_sk_trz trzby druhy",     "DO trz_plat IN sk_stati with zostavy.dily","s_sk_trz trzby druhy","s_sk_trz druhy_dan_sadzby","s_sk_trz druhy_cen_hlad","s_sk_trz druhy_minusy","s_sk_trz druhy_uzavierky")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3,txt4,txt5)	VALUE ("s_sk_trz trzby casnik",    "DO gr_trzcis IN sk_stati with zostavy.dily","s_sk_trz_jednoducha","s_sk_trz_podrobna","s_sk_trz_casn_denna","s_sk_trz_casn_tip","s_sk_trz_casn_tit")
INSERT INTO zostavy (klic, cmd,txt1,txt2)					VALUE ("s_sk_trz trzby kasy",      "DO gr_trzkas IN sk_stati with zostavy.dily","s_sk_trz trzby kasy","s_sk_trz trzby kasy_casn")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3,txt4, txt5)	VALUE ("s_sk_trz trzby many",      "DO gr_trzman IN sk_stati with zostavy.dily","s_sk_trz_jednoducha","s_sk_trz_podrobna","s_sk_trz_man_po_dnoch","s_sk_trz_man_po_dnoch","s_sk_trz_man_po_uctdnoch")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3,txt4)			VALUE ("s_sk_trz trzby hladiny",   "DO gr_trzhla IN sk_stati with zostavy.dily","s_sk_trz trzby hladiny","rep_ttl_trzhlad","rep_ttl_trzhladdan","rep_ttl_trzhladcas")
INSERT INTO zostavy (klic, cmd,txt1,txt2)					VALUE ("s_sk_trz trzby uzaver",    "DO trz_uzav IN sk_stati with zostavy.dily","s_sk_trz trzby uzaver","s_sk_trz trzby dni")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3,txt4,txt5)	VALUE ("s_sk_trz trzby casy",      "DO trz_casy IN sk_stati with zostavy.dily","s_sk_trz trzby casy","s_sk_trz_po_kalkul","s_sk_trz trzby casdruhy","s_sk_trz_casy atrib", "s_sk_trz_casy_atribpocty")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3,txt4,txt5)	VALUE ("s_sk_trz trzby skup druhy","DO s_dr_str WITH zostavy.dily IN sk_stati","s_sk_trz trzby sp druh id","s_sk_trz trzby id sp","s_sk_trz trzby skup spart","s_sk_trz trzby plat spart","s_sk_trz trzby id sp druh")
INSERT INTO zostavy (klic, cmd,txt1,txt2)					VALUE ("s_sk_trz trzby drk_plt_1", "DO m_drk_plat WITH zostavy.dily IN sk_stati","s_sk_trz trzby drk_plt_1","s_sk_trz trzby drk_plt_2")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3,txt4,txt5)	VALUE ("s_sk_trz predaj",          "DO gr_pockalk IN sk_stati with zostavy.dily","s_sk_trz_po_nazvoch","s_sk_trz_pred_ceny","s_sk_trz_mnozstva","s_sk_trz_kal_cas","s_sk_trz_predaj_uzav")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3)				VALUE ("s_sk_trz trzby meny",      "DO trz_meny IN sk_stati with zostavy.dily","s_sk_trz trzby meny uzav","s_sk_trz trzby meny kasy","s_sk_trz trzby meny meny")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3,txt4,txt5)	VALUE ("s_sk_ucty_platby_prehlad", "DO uvery IN sk_stati with zostavy.dily","s_sk_ucty_platby_prehlad","s_sk_ucty_platby_prehladsp","s_sk_ucty_platby_sumar","s_sk_ucty_platby_sumar_celk","s_sk_uvery_sparty")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3,txt4,txt5)	VALUE ("s_sk_predaj", "DO s_predaj WITH zostavy.dily IN sk_stati","s_sk_predaj kalk plat","s_sk_predaj kalk casnik","3","4","s_sk_predaj kalk cas")
INSERT INTO zostavy (klic, cmd,txt1,txt2)					VALUE ("s_sk_casplat", "DO s_casnik WITH zostavy.dily IN sk_stati","s_sk_platba casnik","s_sk_casnik kasa platba")
INSERT INTO zostavy (klic, cmd,txt1,txt2)					VALUE ("s_sk_prehlad_uctov", "DO prehluctov WITH zostavy.dily IN sk_stati","s_sk_po_platbach","s_sk_po_cenovych_hladinach")
INSERT INTO zostavy (klic, cmd,txt1,txt2)					VALUE ("s_sk_predaj_menu", "DO predajmenu WITH zostavy.dily IN sk_stati",jaz("predaj menu"),jaz("predaj menu sumar"))
INSERT INTO zostavy (klic, cmd,txt1)						VALUE ("s_sk_pohladavky1", "DO pohladavky WITH zostavy.dily IN sk_stati","s_sk_pohladavky")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3)				VALUE ("s_sk_organizacie", "DO predaj_org WITH zostavy.dily IN sk_stati","org_kalkulacie","org_druhy","org_sparty")
IF FILE(m.gcdat_path+"stravnik.dbf")
	INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3,txt4)			VALUE ("s_sk_zamestnanecka_strava", "DO zstrava WITH zostavy.dily IN sk_stati","delenie_spotreby","spotreba_stravnikov","ucty_stravnika","ucty_stravnika_sumar")
ENDIF
IF m.spotrebnadan<>0
	INSERT INTO zostavy (klic, cmd,txt1,txt2)					VALUE ("s_sk_spotrebna_dan", "DO spdanpredaj WITH zostavy.dily IN sk_stati","detail","sumar")
ENDIF
INSERT INTO zostavy (klic, cmd,txt1,txt2)					VALUE ("s_sk_trz trzby casnik2",    "DO gr_trzcis2 IN sk_stati with zostavy.dily","s_sk_trz_cas_druh","s_sk_trz_cas_ucty")
INSERT INTO zostavy (klic, cmd,txt1,txt2)					VALUE ("s_sk_trz trzby druhy2",    "DO s_dr_str2 IN sk_stati with zostavy.dily","s_sk_trz_sparty_uzav","s_sk_trz_sparty_dni")
INSERT INTO zostavy (klic, cmd,txt1,txt2)					VALUE ("s_sk_trz predajnost",    "DO gr_predajnost IN sk_stati with zostavy.dily","s_sk_trz_predajnost_druhy","s_sk_trz_predajnost_spolu")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3)				VALUE ("s_sk_trz pocty",    "DO pocty_uctov IN sk_stati with zostavy.dily","s_sk_trz_pocty_hl_sumar","s_sk_trz_pocty_hl_uzav","s_sk_trz_pocty_hl_hodiny")
INSERT INTO zostavy (klic, cmd,txt1,txt2,txt3)				VALUE ("s_sk_trz hlad vynos","DO vynosy_cen_hl IN sk_stati with zostavy.dily","s_sk_trz_pocty_hl_sumar","s_sk_trz_pocty_hl_uzav","s_sk_trz_pocty_hl_hodiny")


IF !EMPTY(m.zoznam_reportov1)
	DO CASE 
		CASE LEFT(ALLTRIM(LOWER(m.zoznam_reportov1)),4)="sada" AND INLIST(RIGHT(ALLTRIM(m.zoznam_reportov1),1),"1","2","3")
			SELECT sestavy
			REPLACE ALL dily WITH kousektextu( jaz2("s_" + ALLTRIM(sestavy.klic)), VAL(RIGHT(ALLTRIM(m.zoznam_reportov1),1)))
			SCAN
				FOR iii = 1 TO 5
					IF .NOT. BETWEEN(SUBST(sestavy.dily, 1), "1", "5")
						REPLACE dily WITH SUBSTR(dily, 2)
					ENDIF
				ENDFOR
				FOR iii = 1 TO 4
					IF .NOT. BETWEEN(SUBST(sestavy.dily, 2), "1", "5")
						REPLACE dily WITH LEFT(dily, 1) + SUBSTR(dily, 3)
					ENDIF
				ENDFOR
				FOR iii = 1 TO 3
					IF .NOT. BETWEEN(SUBST(sestavy.dily, 3), "1", "5")
						REPLACE dily WITH LEFT(dily, 2) + SUBSTR(dily, 4)
					ENDIF
				ENDFOR
				FOR iii = 1 TO 2
					IF .NOT. BETWEEN(SUBST(sestavy.dily, 4), "1", "5")
						REPLACE dily WITH LEFT(dily, 3) + SUBSTR(dily, 5)
					ENDIF
				ENDFOR
				FOR iii = 1 TO 1
					IF .NOT. BETWEEN(SUBST(sestavy.dily, 5), "1", "5")
						REPLACE dily WITH LEFT(dily, 4)
					ENDIF
				ENDFOR
			ENDSCAN
			REPLACE ALL lbl WITH ! EMPTY(dily)
			REPLACE ALL g1 WITH .F.
			REPLACE ALL g2 WITH .F.
			REPLACE ALL g3 WITH .F.
			REPLACE ALL g4 WITH .F.
			REPLACE ALL g5 WITH .F.
			REPLACE sestavy.g1 WITH .T. FOR "1"$dily .AND. !EMPTY(sestavy.txt1)
			REPLACE sestavy.g2 WITH .T. FOR "2"$dily .AND. !EMPTY(sestavy.txt2)
			REPLACE sestavy.g3 WITH .T. FOR "3"$dily .AND. !EMPTY(sestavy.txt3)
			REPLACE sestavy.g4 WITH .T. FOR "4"$dily .AND. !EMPTY(sestavy.txt4)
			REPLACE sestavy.g5 WITH .T. FOR "5"$dily .AND. !EMPTY(sestavy.txt5)
			GO TOP
		OTHERWISE 
			DO WHILE !EMPTY(m.zoznam_reportov1)
				IF AT(",",m.zoznam_reportov1)>0
					m.kusoktextu=LEFT(m.zoznam_reportov1,AT(",",m.zoznam_reportov1)-1)
					m.zoznam_reportov1=SUBSTR(m.zoznam_reportov1,AT(",",m.zoznam_reportov1)+1)
				ELSE 
					m.kusoktextu=m.zoznam_reportov1
					m.zoznam_reportov1=""
				ENDIF 
				IF AT("-",m.kusoktextu)>0
					m.riadok=VAL(LEFT(m.kusoktextu,AT("-",m.kusoktextu)-1))
					m.stlpec=VAL(SUBSTR(m.kusoktextu,AT("-",m.kusoktextu)+1))
					IF m.riadok>0 AND BETWEEN(m.stlpec,1,5)
					ELSE 
						m.riadok=0
					ENDIF 
				ELSE
					m.riadok=0
				ENDIF 
				IF m.riadok>0
					SELECT sestavy
					TRY 
						GO m.riadok
						DO CASE 
							CASE m.stlpec=1
								REPLACE g1 WITH .t., dily WITH ALLTRIM(dily)+"1"
							CASE m.stlpec=2
								REPLACE g2 WITH .t., dily WITH ALLTRIM(dily)+"2"
							CASE m.stlpec=3
								REPLACE g3 WITH .t., dily WITH ALLTRIM(dily)+"3"
							CASE m.stlpec=4
								REPLACE g4 WITH .t., dily WITH ALLTRIM(dily)+"4"
							CASE m.stlpec=5
								REPLACE g5 WITH .t., dily WITH ALLTRIM(dily)+"5"
						ENDCASE 
					ENDTRY 
				ENDIF 
			ENDDO 
			SELECT sestavy
			REPLACE ALL lbl WITH g1 OR g2 OR g3 OR g4 OR g5
	ENDCASE 
ENDIF 
IF !EMPTY(m.zoznam_reportov2)
	DO CASE 
		CASE LEFT(ALLTRIM(LOWER(m.zoznam_reportov2)),4)="sada" AND INLIST(RIGHT(ALLTRIM(m.zoznam_reportov2),1),"1","2","3")
			SELECT zostavy
			REPLACE ALL dily WITH kousektextu( jaz2("s_" + ALLTRIM(zostavy.klic)), VAL(RIGHT(ALLTRIM(m.zoznam_reportov2),1)))
			SCAN
				FOR iii = 1 TO 5
					IF .NOT. BETWEEN(SUBST(zostavy.dily, 1), "1", "5")
						REPLACE dily WITH SUBSTR(dily, 2)
					ENDIF
				ENDFOR
				FOR iii = 1 TO 4
					IF .NOT. BETWEEN(SUBST(zostavy.dily, 2), "1", "5")
						REPLACE dily WITH LEFT(dily, 1) + SUBSTR(dily, 3)
					ENDIF
				ENDFOR
				FOR iii = 1 TO 3
					IF .NOT. BETWEEN(SUBST(zostavy.dily, 3), "1", "5")
						REPLACE dily WITH LEFT(dily, 2) + SUBSTR(dily, 4)
					ENDIF
				ENDFOR
				FOR iii = 1 TO 2
					IF .NOT. BETWEEN(SUBST(zostavy.dily, 4), "1", "5")
						REPLACE dily WITH LEFT(dily, 3) + SUBSTR(dily, 5)
					ENDIF
				ENDFOR
				FOR iii = 1 TO 1
					IF .NOT. BETWEEN(SUBST(zostavy.dily, 5), "1", "5")
						REPLACE dily WITH LEFT(dily, 4)
					ENDIF
				ENDFOR
			ENDSCAN
			REPLACE ALL lbl WITH ! EMPTY(dily)
			REPLACE ALL g1 WITH .F.
			REPLACE ALL g2 WITH .F.
			REPLACE ALL g3 WITH .F.
			REPLACE ALL g4 WITH .F.
			REPLACE ALL g5 WITH .F.
			REPLACE zostavy.g1 WITH .T. FOR "1"$dily .AND. !EMPTY(zostavy.txt1)
			REPLACE zostavy.g2 WITH .T. FOR "2"$dily .AND. !EMPTY(zostavy.txt2)
			REPLACE zostavy.g3 WITH .T. FOR "3"$dily .AND. !EMPTY(zostavy.txt3)
			REPLACE zostavy.g4 WITH .T. FOR "4"$dily .AND. !EMPTY(zostavy.txt4)
			REPLACE zostavy.g5 WITH .T. FOR "5"$dily .AND. !EMPTY(zostavy.txt5)
			GO TOP
		OTHERWISE 
			DO WHILE !EMPTY(m.zoznam_reportov2)
				IF AT(",",m.zoznam_reportov2)>0
					m.kusoktextu=LEFT(m.zoznam_reportov2,AT(",",m.zoznam_reportov2)-1)
					m.zoznam_reportov2=SUBSTR(m.zoznam_reportov2,AT(",",m.zoznam_reportov2)+1)
				ELSE 
					m.kusoktextu=m.zoznam_reportov2
					m.zoznam_reportov2=""
				ENDIF 
				IF AT("-",m.kusoktextu)>0
					m.riadok=VAL(LEFT(m.kusoktextu,AT("-",m.kusoktextu)-1))
					m.stlpec=VAL(SUBSTR(m.kusoktextu,AT("-",m.kusoktextu)+1))
					IF m.riadok>0 AND BETWEEN(m.stlpec,1,5)
					ELSE 
						m.riadok=0
					ENDIF 
				ELSE
					m.riadok=0
				ENDIF 
				IF m.riadok>0
					SELECT zostavy
					TRY 
						GO m.riadok
						DO CASE 
							CASE m.stlpec=1
								REPLACE g1 WITH .t., dily WITH ALLTRIM(dily)+"1"
							CASE m.stlpec=2
								REPLACE g2 WITH .t., dily WITH ALLTRIM(dily)+"2"
							CASE m.stlpec=3
								REPLACE g3 WITH .t., dily WITH ALLTRIM(dily)+"3"
							CASE m.stlpec=4
								REPLACE g4 WITH .t., dily WITH ALLTRIM(dily)+"4"
							CASE m.stlpec=5
								REPLACE g5 WITH .t., dily WITH ALLTRIM(dily)+"5"
						ENDCASE 
					ENDTRY 
				ENDIF 
			ENDDO 
			SELECT zostavy
			REPLACE ALL lbl WITH g1 OR g2 OR g3 OR g4 OR g5
	ENDCASE 
ENDIF 
SELECT zostavy
REPLACE ALL dily WITH IIF(g1,"1","")+IIF(g2,"2","")+IIF(g3,"3","")+IIF(g4,"4","")+IIF(g5,"5","")
LOCATE FOR !EMPTY(dily)
m.pokracovat=FOUND()
SELECT sestavy
REPLACE ALL dily WITH IIF(g1,"1","")+IIF(g2,"2","")+IIF(g3,"3","")+IIF(g4,"4","")+IIF(g5,"5","")
LOCATE FOR !EMPTY(dily)
m.pokracovat=(m.pokracovat or FOUND())

IF m.pokracovat
	PRIVATE oldnull,oldsysmenu
	m.oldnull=SET("NULL")
	m.oldsysmenu=SET("SYSMENU")
	PRIVATE loSession, lcFileName
	SET PROCEDURE TO (m.gcini_path+"libs\utilityReportListener.prg") ADDITIVE
	SET CLASSLIB TO xfrxlib ADDITIVE
	losession=EVALUATE([xfrx("XFRX#INIT")])
	lnretval = losession.setparams(m.gcpri_path+LOWER(SUBSTR(SYS(2015),4))+'.xff',,,,,.T.,"XFF")
	SELECT MIN(uzaverka) as uzaverka FROM uzaverky INTO CURSOR minuz
	m.minuz=minuz.uzaverka
	SELECT MAX(uzaverka) as uzaverka FROM uzaverky  INTO CURSOR minuz
	m.maxuz=minuz.uzaverka
	USE IN minuz
	do s_trzby_new WITH .t.,m.minuz, "", m.maxuz, "", m.crd_path, m.datum_reportu1, m.datum_reportu2
	lcFileName = m.gcpri_path+DTOS(DATE())+"." +IIF(LEFT(m.typ_exportu1,1)="F",SUBSTR(m.typ_exportu1,2),m.typ_exportu1) && temporary file name
	lofinal = losession.finalize ('NOPAGEEJECT')
	IF loSession.SetParams(lcFileName,,.T.,,,,m.typ_exportu1) = 0 && the 3rd parameter says we do not want to preview the PDF
		loSession.TransformReport(lofinal)	
		IF FILE(m.lcfilename)
			DO poslimaildoalta WITH m.hotel_name+" "+m.datsk1+"-"+m.datsk2,m.hotel_name+" "+m.datsk1+"-"+m.datsk2,m.lcfilename,"","",m.mail_kam_poslat
		ENDIF 
	ENDIF 
	IF m.typ_exportu1="XLS"
		lcFileName = m.gcpri_path+DTOS(DATE())+".xlsx" && temporary file name
		IF loSession.SetParams(lcFileName,,.T.,,,,"NATIVE_PFXLSX") = 0 && the 3rd parameter says we do not want to preview the PDF
			loSession.TransformReport(lofinal)	
			IF FILE(m.lcfilename)
				DO poslimaildoalta WITH m.hotel_name+" "+m.datsk1+"-"+m.datsk2,m.hotel_name+" "+m.datsk1+"-"+m.datsk2,m.lcfilename,"","",m.mail_kam_poslat
			ENDIF 
		ENDIF 
	ENDIF 
	RELEASE CLASSLIB xfrxlib
	RELEASE PROCEDURE (m.gcini_path+"libs\utilityReportListener") 
	SET NULL &oldnull
	SET SYSMENU &oldsysmenu
ENDIF 
CLOSE DATABASES
CLOSE DATABASES
RETURN 
