PARAMETERS nezatvaraj
IF m.issql
	DO open_database
	DO FORM z_horesu
	IF USED("teraz")
		=REQUERY("teraz")
	ELSE 
		USE (m.sqlprefix+"rteraz") IN 0 ALIAS teraz
	ENDIF 
	m.vysledok=sql_exec("SELECT food600.doplnuctdendosksez("+ ALLTRIM(STR(m.cdata,2,0))+")","teraz")
	DO pozavirej WITH "teraz"
ELSE
	IF m.cts_enabled AND m.cts_act_instaled
		IF wiface("cts_transfer_view","zoznam",.f.)
			IF RECCOUNT("zoznam")>0
				haddopln = CREATEOBJECT("had", "Import spotreby z kás")
				haddopln.SHOW()
				SELECT DISTINCT uzaverka, id_kas FROM zoznam INTO CURSOR aaa WHERE !(ALLTRIM(id_kas)=="0") ORDER BY id_kas, uzaverka
				haddopln.set_max(RECCOUNT("aaa")*6+1)
				SCAN ALL 
					haddopln.INCREMENT(aaa.id_kas+" - "+aaa.uzaverka+" - FIN")
					IF wiface("cts_consumption_fin","imp_fin",.T.,aaa.uzaverka)
						haddopln.INCREMENT(aaa.id_kas+" - "+aaa.uzaverka+" -POL")
						IF wiface("cts_consumption_pol","imp_pol",.T., aaa.uzaverka)
							haddopln.INCREMENT(aaa.id_kas+" - "+aaa.uzaverka+" -PLT")
							IF wiface("cts_consumption_plt","imp_plt",.T., aaa.uzaverka)
								haddopln.INCREMENT(aaa.id_kas+" - "+aaa.uzaverka+" -TXT")
								IF wiface("cts_consumption_txt","imp_txt",.T., aaa.uzaverka)
									haddopln.INCREMENT(aaa.id_kas+" - "+aaa.uzaverka+" -SEZ")
									IF wiface("cts_consumption_sez","imp_sez",.T., aaa.uzaverka)
										haddopln.INCREMENT(aaa.id_kas+" - "+aaa.uzaverka+" -ALK")
										IF wiface("cts_consumption_alcohol","imp_alk",.T., aaa.uzaverka)
											m.pokracuj=.t.
										ELSE
											m.pokracuj=.f.
										ENDIF
									ELSE
										m.pokracuj=.f.
									ENDIF 
								ELSE 
									m.pokracuj=.f.
								ENDIF
							ELSE 
								m.pokracuj=.f.
							ENDIF 
						ELSE
							m.pokracuj=.f.
						ENDIF
					ELSE
						m.pokracuj=.f.
					ENDIF
					IF !m.pokracuj
						EXIT 
					ENDIF 
				ENDSCAN 
				IF m.pokracuj
					haddopln.INCREMENT("Pripájanie dát")
					DO pripoj_data
				ENDIF 
				RELEASE haddopln
			ENDIF 
			DO pozavirej WITH "zoznam,aaa"
		ENDIF
	ENDIF
	SELECT 0
	IF FILE(m.gccen_path + "hodiny_uzaverek.dbf")
		USE (m.gccen_path + "hodiny_uzaverek") ORDER id_kas
	ELSE
		CREATE TABLE (m.gccen_path + "hodiny_uzaverek") FREE (id_kas c(2), hodina c(2), n_hodina N(2) )
		INDEX ON id_kas TAG id_kas
	ENDIF
	REPLACE ALL n_hodina WITH VAL(hodina)

	IF !m.issql
		IF USED("hodiny_uzaverek")
			DO dopln WITH m.fn_sk_sez
			DO dopln WITH m.fn_sk_sez_a
		ENDIF 
	ENDIF
*	IF FILE(m.gccen_path+"pr_hores.dbf")
		DO FORM z_horesu
*	ENDIF
	IF !nezatvaraj
		DO clos_data
		DO clos_data
	ELSE
		DO pozavirej WITH "hodiny_uzaverek, id_kas"
	ENDIF
ENDIF

*   *   *   *   *   *   *   *   *   *   *   *   *   *   *
PROCEDURE dopln
PARAMETERS soubor
USE (m.soubor) ALIAS doplnsez IN 0 again shared 
WAIT "dopln uct_den do sk_sez " + m.soubor WINDOW NOWAIT 

SELECT DISTI id_kas WHERE EMPTY(uct_den) FROM doplnsez INTO CURSOR id_kas READWRITE 

SCAN
	SCATTER MEMVAR
	SELECT hodiny_uzaverek
	LOCATE FOR id_kas = m.id_kas
	IF .NOT. FOUND()
		INSERT INTO (m.gccen_path + "hodiny_uzaverek") (id_kas, n_hodina) VALUES (m.id_kas, 8)
	ENDIF
	SELECT id_kas
ENDSCAN
SELECT hodiny_uzaverek
LOCATE FOR EMPTY(hodina)	&& field HODINA je u nove appendovanych radku jeste prazdny
*IF FOUND()
*    BROWSE FIELDS id_kas, n_hodina:v=(BETWEEN(n_hodina, 0, 15)) FREEZE n_hodina NOAPPEND NODELETE TITLE "uzaverky pred zadanou hodinou se uctuji do vcerejsiho dne"
*ENDIF
REPLACE ALL hodina WITH TRANSFORM(n_hodina, "@L 99")

SELECT doplnsez
SET RELATION TO id_kas INTO hodiny_uzaverek
IF m.slovenskaverzia
	TRY 
		REPLACE FOR EMPTY(uct_den) uct_den WITH IIF(SUBSTR(uzaverka,10,2) < hodiny_uzaverek.hodina, ;
			DATE(VAL(SUBSTR(uzaverka, 1,4)), VAL(SUBSTR(uzaverka, 5,2)), VAL(SUBSTR(uzaverka, 7,2))) - 1, ;
			DATE(VAL(SUBSTR(uzaverka, 1,4)), VAL(SUBSTR(uzaverka, 5,2)), VAL(SUBSTR(uzaverka, 7,2))))
	CATCH
	ENDTRY 
ELSE
	TRY 
		REPLACE FOR VAL(SUBSTR(uzaverka, 3,2)) * VAL(SUBSTR(uzaverka, 5,2)) = 0 uct_den WITH {^1900-01-01} && uzaverka nema charakter datumu
	CATCH
	ENDTRY 

	SET FILTER TO LEFT(uzaverka, 1) = "O"
	TRY 
		REPLACE FOR EMPTY(uct_den) uct_den WITH IIF(SUBSTR(uzaverka,8,2) < hodiny_uzaverek.hodina, ;
			DATE(2000 + VAL(SUBSTR(uzaverka, 2,1)), VAL(SUBSTR(uzaverka, 3,2)), VAL(SUBSTR(uzaverka, 5,2))) - 1, ;
			DATE(2000 + VAL(SUBSTR(uzaverka, 2,1)), VAL(SUBSTR(uzaverka, 3,2)), VAL(SUBSTR(uzaverka, 5,2))))
	CATCH
	ENDTRY 

	SET FILTER TO LEFT(uzaverka, 1) = "9"	&& kdyby se naaahodou objevila uzaverka z minulyho stoleti
	TRY 
		REPLACE FOR EMPTY(uct_den) uct_den WITH IIF(SUBSTR(uzaverka,8,2) < hodiny_uzaverek.hodina, ;
			DATE(1900 + VAL(SUBSTR(uzaverka, 1,2)), VAL(SUBSTR(uzaverka, 3,2)), VAL(SUBSTR(uzaverka, 5,2))) - 1, ;
			DATE(1900 + VAL(SUBSTR(uzaverka, 1,2)), VAL(SUBSTR(uzaverka, 3,2)), VAL(SUBSTR(uzaverka, 5,2))))
	CATCH
	ENDTRY 

	SET FILTER TO BETWEEN(LEFT(uzaverka, 1), "0", "8")    && roky 2000 (s nulou) - 2089
	TRY 
		REPLACE FOR EMPTY(uct_den) uct_den WITH IIF(SUBSTR(uzaverka,8,2) < hodiny_uzaverek.hodina, ;
			DATE(2000 + VAL(SUBSTR(uzaverka, 1,2)), VAL(SUBSTR(uzaverka, 3,2)), VAL(SUBSTR(uzaverka, 5,2))) - 1, ;
			DATE(2000 + VAL(SUBSTR(uzaverka, 1,2)), VAL(SUBSTR(uzaverka, 3,2)), VAL(SUBSTR(uzaverka, 5,2))))
	CATCH
	ENDTRY 

	SET FILTER TO
	TRY 
		REPLACE FOR EMPTY(uct_den) uct_den WITH {^1900-01-01}
	CATCH
	ENDTRY 

ENDIF
DO pozavirej WITH "doplnsez, id_kas"
WAIT CLEAR 

*   *   *   *   *   *   *   *   *   *   *   *   *   *   *
PROCEDURE pripoj_data
TRY
	USE (m.fn_sk_fin) ALIAS sk_fin IN 0
	USE (m.fn_sk_plt) ALIAS sk_plt IN 0
	USE (m.fn_sk_pol) ALIAS sk_pol IN 0
	USE (m.fn_sk_txt) ALIAS sk_txt IN 0
	USE (m.fn_sk_sez) ALIAS sk_sez IN 0
	USE (m.fn_obr_alk) ALIAS obr_alk IN 0
	USE (m.fn_food_dat) ALIAS food_dat IN 0
CATCH
	IF FILE(m.gccen_path+"odl_fin.dbf")
		SELECT 0
		USE (m.gccen_path+"odl_fin.dbf")
		APPEND FROM DBF("imp_fin")
	ELSE
		SELECT * FROM imp_fin INTO TABLE (m.gccen_path+"odl_fin")
	ENDIF
	DO pozavirej WITH "imp_fin, odl_fin"
	IF FILE(m.gccen_path+"odl_plt.dbf")
		SELECT 0
		USE (m.gccen_path+"odl_plt.dbf")
		APPEND FROM DBF("imp_plt")
	ELSE
		SELECT * FROM imp_plt INTO TABLE (m.gccen_path+"odl_plt")
	ENDIF
	DO pozavirej WITH "imp_plt, odl_plt"
	IF FILE(m.gccen_path+"odl_pol.dbf")
		SELECT 0
		USE (m.gccen_path+"odl_pol.dbf")
		APPEND FROM DBF("imp_pol")
	ELSE
		SELECT * FROM imp_pol INTO TABLE (m.gccen_path+"odl_pol")
	ENDIF
	DO pozavirej WITH "imp_pol, odl_pol"
	IF FILE(m.gccen_path+"odl_txt.dbf")
		SELECT 0
		USE (m.gccen_path+"odl_txt.dbf")
		APPEND FROM DBF("imp_txt")
	ELSE
		SELECT * FROM imp_txt INTO TABLE (m.gccen_path+"odl_txt")
	ENDIF
	DO pozavirej WITH "imp_txt, odl_txt"
	IF FILE(m.gccen_path+"odl_sez.dbf")
		SELECT 0
		USE (m.gccen_path+"odl_sez.dbf")
		APPEND FROM DBF("imp_sez")
	ELSE
		SELECT * FROM imp_sez INTO TABLE (m.gccen_path+"odl_sez")
	ENDIF
	DO pozavirej WITH "imp_sez, odl_sez"
	IF FILE(m.gccen_path+"odl_alk.dbf")
		SELECT 0
		USE (m.gccen_path+"odl_alk.dbf")
		APPEND FROM DBF("imp_alk")
	ELSE
		SELECT * FROM imp_alk INTO TABLE (m.gccen_path+"odl_alk")
	ENDIF
	DO pozavirej WITH "imp_alk, odl_alk"
	RETURN
ENDTRY
SELECT imp_txt
IF RECCOUNT()>0
	REPLACE id_kas WITH LEFT(u_cis,2) FOR EMPTY(id_kas)
ENDIF 
SELECT * FROM sk_fin INTO CURSOR fin READWRITE WHERE .F.
SELECT * FROM sk_pol INTO CURSOR pol READWRITE WHERE .F.
SELECT * FROM sk_plt INTO CURSOR plt READWRITE WHERE .F.
SELECT * FROM sk_txt INTO CURSOR txt READWRITE WHERE .F.
SELECT * FROM sk_sez INTO CURSOR sez READWRITE WHERE .F.
SELECT * FROM obr_alk INTO CURSOR alk READWRITE WHERE .F.
SELECT alk
APPEND FROM DBF("imp_alk")
SELECT txt
APPEND FROM DBF("imp_txt")
SELECT sez
APPEND FROM DBF("imp_sez")
INSERT INTO pol (id_kas, id_man, u_cis, c_karty, nazev, prachy, dan, mnozstvi, cen_hlad, k_odpoctu, uzaverka, id_karty, id_fmenu, typpolozky, kompez) SELECT LEFT(imp_pol.u_cis,2), food_dat.ID,;
	imp_pol.u_cis, imp_pol.c_karty, imp_pol.nazev, imp_pol.prachy_puv, imp_pol.dan_sazba/100+1, imp_pol.mnozstvi, imp_pol.cen_hlad, imp_pol.k_odpoctu, imp_pol.uzaverka, imp_pol.id_karty, imp_pol.id_fmenu, imp_pol.typpolozky, imp_pol.kompez FROM imp_pol LEFT JOIN food_dat ON imp_pol.c_stredisk=food_dat.c_stredisk
REPLACE id_man WITH "" FOR ISNULL(id_man)	
INSERT INTO plt (u_cis, cena_pl, druh_pl, tip, uzaverka, mena, cena_mena, kompez) SELECT u_cis, cena_pl, druh_pl, tip, uzaverka, mena, cena_mena, kompez FROM imp_plt
INSERT INTO fin (id_kas, u_cis, AUTOR, text_sleva, text_link, uzaverka, u_cas, pocet_h, stul, cas_atrib, mutace, id_limit, lim_datum, ducis, pohladavka) SELECT ;
	LEFT(u_cis,2) AS id_kas, u_cis, AUTOR, text_sleva, text_link, uzaverka, u_cas, pocet_h, stul, cas_atrib, mutace, id_limit, lim_datum, ducis, pohladavka FROM imp_fin
SELECT uzaverka, u_cis, SUM(prachy_puv) AS cena_celk, SUM(prachy) AS cena_slev, SUM(dan) AS dph_celk FROM imp_pol INTO CURSOR aaa GROUP BY uzaverka, u_cis
UPDATE fin SET cena_celk=aaa.cena_celk, cena_slev=aaa.cena_slev, dph_celk=aaa.dph_celk, sleva_abs=aaa.cena_celk-aaa.cena_slev FROM aaa WHERE fin.uzaverka=aaa.uzaverka AND fin.u_cis=aaa.u_cis
USE IN aaa
SELECT uzaverka, u_cis, SUM(prachy) AS trzba, (dan_sazba/100+1) AS dan FROM imp_pol GROUP BY uzaverka, u_cis, dan_sazba ORDER BY uzaverka ASC, u_cis ASC, dan DESC INTO CURSOR aaa
m.uzaverka="xxxyxy"
m.u_cis="aaaa"
m.poradie=1
SCAN ALL
	IF aaa.uzaverka=m.uzaverka AND u_cis=m.u_cis
		m.poradie=m.poradie+1
	ELSE
		m.uzaverka=aaa.uzaverka
		m.u_cis=aaa.u_cis
		m.poradie=1
	ENDIF
	m.spor=ALLTRIM(STR(m.poradie,1,0))
	m.suma=aaa.trzba
	m.dan=aaa.dan
	UPDATE fin SET trzba_dph&spor=m.suma, dan&spor=m.dan WHERE uzaverka=m.uzaverka AND u_cis=m.u_cis
ENDSCAN
SELECT pol
m.pocetriadkov=i_max("idriadok sk_pol",RECCOUNT("pol"))
REPLACE ALL idriadok WITH m.pocetriadkov-RECNO()+1
SELECT plt
m.pocetriadkov=i_max("idriadok sk_plt",RECCOUNT("plt"))
REPLACE ALL idriadok WITH m.pocetriadkov-RECNO()+1
SELECT fin
m.pocetriadkov=i_max("idriadok sk_fin",RECCOUNT("fin"))
REPLACE ALL idriadok WITH m.pocetriadkov-RECNO()+1
SELECT txt
m.pocetriadkov=i_max("idriadok sk_txt",RECCOUNT("txt"))
REPLACE ALL idriadok WITH m.pocetriadkov-RECNO()+1
SELECT sez
m.pocetriadkov=i_max("idriadok sk_sez",RECCOUNT("sez"))
REPLACE ALL idriadok WITH m.pocetriadkov-RECNO()+1

DO pripoj1sk WITH "fin",.T.
DO pripoj1sk WITH "pol",.F.
DO pripoj1sk WITH "plt",.F.
DO pripoj1sk WITH "sez",.F.
DO pripoj1sk WITH "txt",.F.

SELECT id_kas, uzaverka, SUM(cena_slev) AS fin, SUM(cena_slev) AS pol, SUM(cena_slev) AS plt, 0000000 AS sez, 0000000 AS txt, 0000000 AS alk FROM sk_fin GROUP BY uzaverka, id_kas INTO CURSOR stavsk READWRITE ORDER BY uzaverka, id_kas WHERE (uzaverka+id_kas  IN (SELECT DISTINCT uzaverka+id_kas FROM fin)) 
REPLACE ALL pol WITH 0, plt WITH 0

SELECT id_kas, uzaverka, SUM(prachy) AS pol FROM sk_pol GROUP BY uzaverka, id_kas INTO CURSOR aaa WHERE !EMPTY(k_odpoctu) AND (uzaverka+id_kas  IN (SELECT DISTINCT uzaverka+id_kas FROM pol)) 
UPDATE stavsk SET pol=aaa.pol FROM aaa WHERE stavsk.uzaverka=aaa.uzaverka AND stavsk.id_kas=aaa.id_kas
INSERT INTO stavsk (id_kas, uzaverka, pol) SELECT id_kas, uzaverka, pol FROM aaa WHERE !(id_kas+uzaverka IN (SELECT DISTINCT id_kas+uzaverka FROM stavsk))

SELECT LEFT(u_cis,2) AS id_kas, uzaverka, SUM(cena_pl) AS plt FROM sk_plt GROUP BY uzaverka, id_kas INTO CURSOR aaa WHERE (uzaverka+LEFT(u_cis,2)  IN (SELECT DISTINCT uzaverka+LEFT(u_cis,2) FROM plt)) 
UPDATE stavsk SET plt=aaa.plt FROM aaa WHERE stavsk.uzaverka=aaa.uzaverka AND stavsk.id_kas=aaa.id_kas
INSERT INTO stavsk (id_kas, uzaverka, plt) SELECT id_kas, uzaverka, plt FROM aaa WHERE !(id_kas+uzaverka IN (SELECT DISTINCT id_kas+uzaverka FROM stavsk))

SELECT id_kas, uzaverka, COUNT(uzaverka) AS sez FROM sk_sez GROUP BY uzaverka, id_kas INTO CURSOR aaa WHERE (uzaverka+id_kas  IN (SELECT DISTINCT uzaverka+id_kas FROM sez)) 
UPDATE stavsk SET sez=aaa.sez FROM aaa WHERE stavsk.uzaverka=aaa.uzaverka AND stavsk.id_kas=aaa.id_kas
INSERT INTO stavsk (id_kas, uzaverka, sez) SELECT id_kas, uzaverka, sez FROM aaa WHERE !(id_kas+uzaverka IN (SELECT DISTINCT id_kas+uzaverka FROM stavsk))

SELECT id_kas, uzaverka, COUNT(uzaverka) AS txt FROM sk_txt GROUP BY uzaverka, id_kas INTO CURSOR aaa WHERE (uzaverka+id_kas  IN (SELECT DISTINCT uzaverka+id_kas FROM txt)) 
UPDATE stavsk SET txt=aaa.txt FROM aaa WHERE stavsk.uzaverka=aaa.uzaverka AND stavsk.id_kas=aaa.id_kas
INSERT INTO stavsk (id_kas, uzaverka, txt) SELECT id_kas, uzaverka, txt FROM aaa WHERE !(id_kas+uzaverka IN (SELECT DISTINCT id_kas+uzaverka FROM stavsk))

SELECT id_kas, uzaverka, COUNT(uzaverka) AS alk FROM obr_alk GROUP BY uzaverka, id_kas INTO CURSOR aaa WHERE !EMPTY(uzaverka) AND (uzaverka+id_kas  IN (SELECT DISTINCT uzaverka+id_kas FROM alk))  
UPDATE stavsk SET alk=aaa.alk FROM aaa WHERE stavsk.uzaverka=aaa.uzaverka AND stavsk.id_kas=aaa.id_kas
INSERT INTO stavsk (id_kas, uzaverka, alk) SELECT id_kas, uzaverka, alk FROM aaa WHERE !(id_kas+uzaverka IN (SELECT DISTINCT id_kas+uzaverka FROM stavsk))
SELECT id_kas AS terminal, uzaverka, fin AS sum_fin, pol AS sum_pol, plt AS sum_plt, txt AS sum_txt, sez AS sum_sez, alk AS sum_alk FROM stavsk INTO CURSOR __wwxmlcust ORDER BY uzaverka
*!*	m.request=tvorxml("check.xml",.f.)
*!*	m.stav=ACT("ctvs.sys_schema(apikey,'trans_check','"+STRTRAN(m.request,CHR(13)+CHR(10),"")+"').encode('utf_8')$$10")
IF poslixml("cts_transfer_check","check.xml",.F.)
ELSE
	ERASE (m.xml_export_path+"check.xml")
ENDIF

DO pozavirej WITH "stavsk, __wwxmlcust, fin, pol, plt, sez, alk, txt, imp_fin, imp_pol, imp_plt, imp_txt, imp_sez, imp_alk, sk_fin, sk_pol, sk_plt, sk_txt, sk_sez, obr_alk"
RETURN



PROCEDURE pripoj1sk
PARAMETERS skpripona, aj_alkohol
PRIVATE kopiruj
SELECT 0
DO CASE
	CASE skpripona="fin"
		SELECT uzaverka, SUM(cena_celk) AS cena, id_kas ;
			FROM fin INTO CURSOR sumy_i GROUP BY uzaverka,id_kas WHERE !DELETED()
		SELECT uzaverka, SUM(cena_celk) AS  cena, id_kas ;
			FROM ("sk_"+skpripona) INTO CURSOR asdf GROUP BY uzaverka,id_kas WHERE !DELETED() AND uzaverka IN (SELECT DISTINCT uzaverka FROM fin)
		INDEX ON uzaverka+id_kas TAG uzkas
	CASE skpripona="pol"
		SELECT uzaverka, SUM(prachy) AS cena, id_kas ;
			FROM pol INTO CURSOR sumy_i GROUP BY uzaverka,id_kas WHERE !DELETED()
		SELECT uzaverka, SUM(prachy) AS  cena,id_kas ;
			FROM ("sk_"+skpripona) INTO CURSOR asdf GROUP BY uzaverka,id_kas WHERE !DELETED() AND uzaverka IN (SELECT DISTINCT uzaverka FROM pol)
		INDEX ON uzaverka+id_kas TAG uzkas
	CASE skpripona="plt"
		SELECT uzaverka, SUM(cena_pl) AS cena, LEFT(u_cis,2) AS id_kas ;
			FROM plt INTO CURSOR sumy_i GROUP BY uzaverka,id_kas WHERE !DELETED()
		SELECT uzaverka,SUM(cena_pl) AS  cena, LEFT(u_cis,2) AS id_kas ;
			FROM ("sk_"+skpripona) INTO CURSOR asdf GROUP BY uzaverka,id_kas WHERE !DELETED() AND uzaverka IN (SELECT DISTINCT uzaverka FROM plt)
		INDEX ON uzaverka+id_kas TAG uzkas
	CASE skpripona="txt"
		SELECT uzaverka, COUNT(uzaverka) AS pocet, id_kas ;
			FROM txt INTO CURSOR sumy_i GROUP BY uzaverka, id_kas WHERE !DELETED()
		SELECT uzaverka, COUNT(uzaverka) AS pocet, id_kas ;
			FROM ("sk_"+skpripona) INTO CURSOR asdf GROUP BY uzaverka, id_kas WHERE !DELETED() AND uzaverka IN (SELECT DISTINCT uzaverka FROM txt)
		INDEX ON uzaverka+id_kas TAG uzkas
	CASE skpripona="sez"
		SELECT uzaverka,COUNT(uzaverka) AS pocet, id_kas ;
			FROM sez INTO CURSOR sumy_i GROUP BY uzaverka, id_kas WHERE !DELETED()
		SELECT uzaverka, COUNT(uzaverka) AS pocet, id_kas ;
			FROM ("sk_"+skpripona) INTO CURSOR asdf GROUP BY uzaverka, id_kas WHERE !DELETED() AND uzaverka IN (SELECT DISTINCT uzaverka FROM sez)
		INDEX ON uzaverka+id_kas TAG uzkas
ENDCASE
SELECT sumy_i
SCAN
	IF m.aj_alkohol
		m.sumuzaverka=sumy_i.uzaverka
		m.sumidkas=sumy_i.id_kas
		SELECT obr_alk
		COUNT TO m.pocetobralk FOR (uzaverka=m.sumuzaverka) .AND. (id_kas=m.sumidkas)
		SELECT alk
		COUNT TO m.pocetobralkn FOR (uzaverka=m.sumuzaverka) .AND. (id_kas=m.sumidkas)
		IF m.pocetobralk<>m.pocetobralkn
			SELECT obr_alk
			DELETE FOR (uzaverka=m.sumuzaverka) .AND. (id_kas=m.sumidkas)
			INSERT INTO obr_alk (c_karty, ean, c_partner, datum, pocet, zostatok, c_dokl, AUTOR, c_stredisk, operace, uzaverka, u_cis, id_kas );
				SELECT c_karty, ean, c_partner, datum, pocet, zostatok, c_dokl, AUTOR, c_stredisk, operace, uzaverka, u_cis, id_kas FROM alk WHERE uzaverka=m.sumuzaverka  .AND. id_kas=m.sumidkas
		ENDIF
		*** L.L. (11.11.2010) Doplneny prenos predaja alkoholu
	ENDIF
	m.kopiruj=.F.
	SELECT asdf 
	IF SEEK(sumy_i.uzaverka+sumy_i.id_kas,"asdf")
		IF INLIST(m.skpripona,"fin","pol","plt")
			IF asdf.cena=sumy_i.cena
				WAIT jazparam("form_uza_prenesena_preskok",sumy_i.uzaverka) WINDOW NOWAIT
			ELSE
				m.kopiruj=.T.
			ENDIF
		ELSE
			IF asdf.pocet=sumy_i.pocet
				WAIT jazparam("form_uza_prenesena_preskok",sumy_i.uzaverka) WINDOW NOWAIT
			ELSE
				m.kopiruj=.T.
			ENDIF
		ENDIF
	ELSE
		m.kopiruj=.T.
	ENDIF
	IF m.kopiruj
		SELECT sumy_i
		DO CASE
			CASE SEEK(sumy_i.uzaverka+sumy_i.id_kas,"asdf")
				WAIT jazparam("form_uza_prenesena_preskok",sumy_i.uzaverka) WINDOW NOWAIT
				SELECT ("sk_"+skpripona)
				DO CASE
					CASE m.skpripona="sez"
						DELETE FOR uzaverka=sumy_i.uzaverka .AND. EMPTY(odecteno) .AND. (id_kas=sumy_i.id_kas)
						APPEND FROM DBF("sez")+m.skpripona FOR uzaverka=sumy_i.uzaverka .AND. id_kas=sumy_i.id_kas
						SET FILTER TO uzaverka=sumy_i.uzaverka .AND. id_kas=sumy_i.id_kas
						GO TOP
						SCAN
							SCATTER MEMVAR
							REPLACE odecteno WITH m.odecteno FOR id_kas=m.id_kas .AND. ;
								uzaverka=m.uzaverka .AND. id_man=m.id_man
						ENDSCAN
						SET FILTER TO
						SELECT sumy_i
					CASE m.skpripona="plt"
						DELETE FOR (uzaverka=sumy_i.uzaverka)
						APPEND FROM DBF("plt") FOR uzaverka=sumy_i.uzaverka
					OTHERWISE
						DELETE FOR (uzaverka=sumy_i.uzaverka) .AND. (id_kas=sumy_i.id_kas)
						APPEND FROM DBF(m.skpripona) FOR uzaverka=sumy_i.uzaverka .AND. id_kas=sumy_i.id_kas
				ENDCASE
			OTHERWISE
				WAIT WINDOW jazparam("form_kopirujem_uzavierku",sumy_i.uzaverka) NOWAIT
				SELECT ("sk_"+skpripona)
				DO CASE
					CASE m.skpripona="plt"
						DELETE FOR (uzaverka=sumy_i.uzaverka)
						APPEND FROM DBF("plt") FOR uzaverka=sumy_i.uzaverka
					OTHERWISE
						DELETE FOR (uzaverka=sumy_i.uzaverka) .AND. (id_kas=sumy_i.id_kas)
						APPEND FROM DBF(m.skpripona) FOR uzaverka=sumy_i.uzaverka .AND. id_kas=sumy_i.id_kas
				ENDCASE
				SELECT sumy_i
		ENDCASE
	ENDIF
	SELECT sumy_i
ENDSCAN
USE IN asdf
USE IN sumy_i


