PRIVATE xxxx
CLOS DATA
posledniverze = "1111-11-11"
IF m.issql
	rv("verzia","ps_rverzia")
	SELECT ps_rverzia
	IF RECCOUNT() > 0
        GO TOP 
		posledniverze = ps_rverzia.data
	ENDIF
	USE IN ps_rverzia
ELSE
	IF FILE(m.gchom_path + "errors.dbf")
		USE (m.gchom_path + "errors")
	ENDIF
	IF USED("errors")
		SELECT LEFT(line_txt,10) AS line_txt FROM errors WHERE "V*E*R*Z*E" $ line_txt INTO CURSOR posledneverzie
		IF !prazdna()
			GO BOTTOM
			posledniverze = line_txt
		ENDIF
		USE IN posledneverzie
	ENDIF
ENDIF
IF m.posledniverze < LEFT(m.gcverze_dat, 10)
	WAIT "update verze >" + m.posledniverze + "< na >" + m.gcverze_dat + "<" WINDOW TIMEOUT 3
	IF ! EMPTY(n_checkall("POHYBY_"))
		IF !m.issql
			SELECT 0
			USE (m.gchom_path + "semafory600")
			SET FILTER TO "POHYBY_" $ semafor
			seznam_stanic = ""
			SCAN
				seznam_stanic = seznam_stanic + CHR(13) + SPACE(20) + semafor_id
			ENDSCAN
			USE
		ELSE
			m.seznam_stanic=""
		ENDIF
		MESSAGEBOX(jaz("ted nelze, zkuste pozdeji") + ";" + jaz("pracuji stanice:") + m.seznam_stanic, 0+16+256, jaz("m_ost stru_upda"))
		RETURN
	ENDIF
	IF n_slock("POHYBY_EXCL_")
		vysledokupd=.T.
		chybyupd=""
		DO stru_update_2
		DO n_sunlock WITH "POHYBY_EXCL_"
		IF !m.vysledokupd
			IF !EMPTY(m.chybyupd)
				IF MESSAGEBOX(jaz("form_nie_struktury_pokracovat")+CHR(13)+m.chybyupd,4+32+256,jaz("m_ost stru_upda"))<>6
					CLOSE DATABASES
					QUIT
				ENDIF 
			ELSE 
				MESSAGEBOX(jaz("form_nie_struktury_nepokrac"),16,jaz("m_ost stru_upda"))
				CLOSE DATABASES
				QUIT
			ENDIF 
		ELSE
			IF !EMPTY(m.chybyupd)
				MESSAGEBOX(jaz("form_neupgradovane_tabulky")+CHR(13)+CHR(10) + m.chybyupd,64,jaz("m_ost stru_upda"))
			ENDIF 
		ENDIF
		RELEASE m.chybyupd
	ELSE
		MESSAGEBOX(jaz("ted nelze, zkuste pozdeji"),1+16,"upgrade databazi")
	ENDIF
	IF m.slovenskaverzia
		v_thr=DATE()-89
		DO skusvthr IN s_o_lic
		DO CASE
			CASE m.v_thr=EVALUATE("{^2000-01-01}") .AND. m.posledniverze="1111-11-11"
* prazdne l2 aj errors
* bud nova instalacia, alebo niekto zmazal errors a aj porusenie licencie
* nastavim lic do konca mesiaca
* prerobim to na tri mesiace od datumu instalovanej verzie a zapisem do errors, aby nova instalacia nerobila problemy
				m.gcverzex=EVALUATE("{^" + m.gcverze + "}")
				DO app_log WITH LEFT(m.gcverze_dat, 10) + "     (" + LEFT(m.gcverze, 10) + ")   V*E*R*Z*E instalovana, predtim byla " + m.posledniverze + "     " + REPLICATE("*", 111)
			CASE v_thr=EVALUATE("{^2000-01-01}")
* prazdne l2, ale v errors je zaznam o instalacii novej verzie
* doslo k poruseniu licencie
* nastavim lic na 99 dni odo dna poslednej verzie
* nezapisem do errors aktualizaciu verzie, aby sa mi nestratil datum tej poslednej
				m.gcverzex=EVALUATE("{^"+m.posledniverze+"}")
			OTHERWISE
* neprazdne m.l2, teda je znamy datum, po ktory bola pridelena licencia
				m.gcverzex=m.v_thr
				IF m.v_thr>DATE()
* licencia je neporusena, moze sa zapisat najnovsia aktualizacia
					DO app_log WITH LEFT(m.gcverze_dat, 10) + "     (" + LEFT(m.gcverze, 10) + ")   V*E*R*Z*E instalovana, predtim byla " + m.posledniverze + "     " + REPLICATE("*", 111)
				ENDIF
		ENDCASE
		m.gcverzex=TRANS(YEAR(m.gcverzex), "9999") + "-" + TRANSFORM(MONTH(m.gcverzex), "@L 99") + "-" + TRANSFORM(DAY(m.gcverzex), "@L 99")
	ELSE
		m.gcverzex=m.gcverze
		DO app_log WITH LEFT(m.gcverze, 10) + "     (" + LEFT(m.gcverze, 10) + ")   V*E*R*Z*E instalovana, predtim byla " + m.posledniverze + "     " + REPLICATE("*", 111)
	ENDIF
ELSE
	IF m.slovenskaverzia
		v_thr=DATE()-89
		DO skusvthr IN s_o_lic
		DO CASE
			CASE m.v_thr=EVALUATE("{^2000-01-01}") .AND. m.posledniverze="1111-11-11"
* prazdne l2 aj errors
* bud nova instalacia, alebo niekto zmazal errors a aj porusenie licencie
* nastavim lic do konca mesiaca
* prerobim to na tri mesiace od datumu instalovanej verzie a zapisem do errors, aby nova instalacia nerobila problemy
*				m.gcverzex=DATE()-68
				gcverzex=EVALUATE("{^" + m.gcverze + "}")
				DO app_log WITH LEFT(m.gcverze_dat, 10) + "     (" + LEFT(m.gcverze, 10) + ")   V*E*R*Z*E instalovana, predtim byla " + m.posledniverze + "     " + REPLICATE("*", 111)
			CASE v_thr=EVALUATE("{^2000-01-01}")
* prazdne l2, ale v errors je zaznam o instalacii novej verzie
* doslo k poruseniu licencie
* nastavim lic na 99 dni odo dna poslednej verzie
				gcverzex=EVALUATE("{^"+m.posledniverze+"}")
			OTHERWISE
* neprazdne m.l2, teda je znamy datum, po ktory bola pridelena licencia
				gcverzex=m.v_thr
		ENDCASE
		gcverzex=TRANS(YEAR(m.gcverzex), "9999") + "-" + TRANSFORM(MONTH(m.gcverzex), "@L 99") + "-" + TRANSFORM(DAY(m.gcverzex), "@L 99")
	ELSE
		gcverzex=m.gcverze
	ENDIF
ENDIF

************************************************************
PROCEDURE stru_update_rucne
PARAMETERS updatovat_vzdy
IF ! EMPTY(n_checkall("POHYBY_"))
	IF !m.issql
		SELECT 0
		USE (m.gchom_path + "semafory")
		SET FILTER TO "POHYBY_" $ semafor
		seznam_stanic = ""
		SCAN
			seznam_stanic = seznam_stanic + CHR(13) + SPACE(20) + semafor_id
		ENDSCAN
		USE
	ELSE
		seznam_stanic = ""
	ENDIF
	MESSAGEBOX(jaz("ted nelze, zkuste pozdeji") + ";" + jaz("pracuji stanice:") + m.seznam_stanic, 0+16+256, "manualni upgrade databazi")
	RETURN
ENDIF
IF n_slock("POHYBY_EXCL_")
	vysledokupd=.T.
	chybyupd=""
	DO stru_update_2
	DO app_log WITH LEFT(m.gcverze_dat, 10) + "     (" + LEFT(m.gcverze, 10) + ")   V*E*R*Z*E instalovana manualne    " + REPLICATE("*", 111)
	DO n_sunlock WITH "POHYBY_EXCL_"
	IF !m.vysledokupd
		IF !EMPTY(m.chybyupd)
			IF MESSAGEBOX(jaz("form_nie_struktury_pokracovat")+CHR(13)+m.chybyupd,4+32+256,"upgrade databazi")<>6
				CLOSE DATABASES
				QUIT
			ENDIF 
		ELSE 
			MESSAGEBOX(jaz("form_nie_struktury_nepokrac"),16,"upgrade databazi")
			CLOSE DATABASES
			QUIT
		ENDIF 
	ELSE
		IF !EMPTY(m.chybyupd)
            MESSAGEBOX("Nasledujici databaze se nepodarilo upgradovat:"+CHR(13)+CHR(10) + m.chybyupd,64,"upgrade databazi")
		ENDIF 
	ENDIF
	RELEASE m.chybyupd
ELSE
	= MESSAGEBOX(jaz("ted nelze, zkuste pozdeji"))
ENDIF

************************************************************
PROCEDURE stru_update_2
PRIVATE prerob_limity
*!*	PRIVATE m.chybyupd
*!*	m.chybyupd=""
IF m.issql
*	DO FORM verzia WITH m.gcverze_dat
ELSE
	prerob_limity=.F.

**********    kontrola mista na disku     ********** zacatek
	STORE 0 TO celkova_velikost, nejvetsi_velikost
	pocet = ADIR(qqq, m.gcdat_path + "*.*")
	FOR iii = 1 TO pocet
		celkova_velikost = celkova_velikost + qqq(iii, 2)
		IF qqq(iii, 2) > m.nejvetsi_velikost
			nejvetsi_velikost = qqq(iii, 2)
		ENDIF
	ENDFOR
	IF m.nejvetsi_velikost > DISKSPACE()/2
		IF MESSAGEBOX("na disku je pouze " + ALLTRIM(STR(DISKSPACE()/1048576)) + "MB mista" + CHR(13) ;
				+ "datovy adresar zabira " + ALLTRIM(STR(m.celkova_velikost/1048576)) + "MB" + CHR(13) ;
				+ "nejvetsi soubor ma " + ALLTRIM(STR(m.nejvetsi_velikost/1048576)) + "MB" + CHR(13) ;
				+ CHR(13) + "CHCETE OPRAVDU UPDATOVAT STRUKTURY DAT?" + CHR(13) ;
				+ "(lepsi by bylo udelat misto, vysypat kos a teprve pak pokracovat)" ;
				,3+48+256,"Na disku je malo mista") # 6
			QUIT    &&   RETURN
		ENDIF
	ENDIF
**********    kontrola mista na disku     ********** konec


	had = CREATEOBJECT("had", "Update struktur" )
	had.SHOW()
	had.set_max(20)
    DO clos_data

    small_log("UPDATE STRUKTUR DBF  " + LEFT(m.gcverze_dat, 10), "update_struktur")
    DO clos_data
	zaloha_dir = LEFT(m.gchom_path, RAT("\", m.gchom_path, 2)) + "zaloha\" + DTOS(DATE()) + "-" + STRTR(SUBST(TTOC(DATETIME()), 12, 5), ":", "") + "\"
	DO mk_dir WITH m.zaloha_dir
	IF .NOT. DIRECTORY(m.zaloha_dir)
		zaloha_dir = "c:\zaloha\" + DTOS(DATE()) + "-" + STRTR(SUBST(TTOC(DATETIME()), 12, 5), ":", "") + "\"
		DO mk_dir WITH m.zaloha_dir
		IF .NOT. DIRECTORY(m.zaloha_dir)
			zaloha_dir = m.pri_path + DTOS(DATE()) + "-" + STRTR(SUBST(TTOC(DATETIME()), 12, 5), ":", "") + "\"
		ENDIF
	ENDIF
    small_log("UPDATE STRUKTUR DBF  " + LEFT(m.gcverze_dat, 10) + ", zaloha v " + m.zaloha_dir, "update_struktur")

	DO zalohovac WITH .T., m.zaloha_dir
    DO stru_update_1 WITH m.fn_vypocty
	had.INCREMENT("skupiny, karty")
	DO stru_update_skupiny

	DO vypln_kod_v_sk_pol

	DO stru_update_1 WITH m.fn_skupiny
	TRY
		USE (m.fn_skupiny) EXCLUSIVE
		INDEX ON druh TAG druh
		USE
	CATCH
	ENDTRY
	SELECT 0
	USE (m.fn_skupiny) ALIAS skupiny
	SELECT COUNT(c_druh) AS nulove FROM skupiny WHERE EMPTY(c_druh) INTO CURSOR nulove
	IF nulove.nulove>0
		SELECT skupiny
		REPLACE c_druh WITH i_max("c_druh") FOR EMPTY(c_druh)
	ENDIF
	USE IN nulove
	USE IN skupiny

	DO stru_update_1 WITH m.fn_kkarty
	DO stru_update_1 WITH m.fn_kceny
	DO stru_update_1 WITH m.fn_ktexty
	DO stru_update_1 WITH m.fn_krest
	DO stru_update_1 WITH m.fn_ktried
	DO stru_update_1 WITH m.fn_tried
	DO stru_update_1 WITH m.fn_uzav_pohyby

    DO stru_update_1 WITH m.gcdat_path + "vahinv"

	DO stru_update_1 WITH m.fn_karty
	IF !test_mena(m.fn_karty)
		SELECT 0
		USE (m.fn_karty) ALIAS testsubor
		IF m.giakt_mena<>1
			IF MESSAGEBOX(jaz("form_pred_ceny_su_v_mene")+" "+en__meny(2,3)+"?",4+32+256,"FoodMan")=6
				REPLACE c_mena WITH 2 FOR EMPTY(c_mena)
			ELSE
				REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
			ENDIF
		ELSE
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
		ENDIF
		USE
	ENDIF

	IF !test_mena(m.fn_karty,.T.)
		REPLACE c_mena_n WITH m.giakt_mena FOR EMPTY(c_mena_n)
	ENDIF
	USE (m.fn_skupiny) ALIAS skupiny ORDER druh
	SELECT 0
	USE (m.fn_karty) ALIAS karty

	SET RELATION TO druh INTO skupiny
	REPLACE c_druh WITH skupiny.c_druh FOR !EMPTY(karty.druh)

	SET RELATION TO druh_skl INTO skupiny
	REPLACE c_druhs WITH skupiny.c_druh FOR !EMPTY(karty.druh_skl)

	SET RELATION TO druh_kalk INTO skupiny
	REPLACE c_druhk WITH skupiny.c_druh FOR !EMPTY(karty.druh_kalk)

	USE IN skupiny
	SELECT karty
	USE
	TRY
		USE (m.fn_karty) ALIAS karty EXCLUSIVE
		DO indexuj IN indexy
		USE
	CATCH
	ENDTRY
	USE (m.fn_karty) ALIAS karty SHARED
	SELECT MAX(c_karty) as c_karty FROM karty INTO CURSOR aakarty
	IF RECCOUNT("aakarty")>0
		SELECT aakarty
		GO TOP 
		IF ISNULL(aakarty.c_karty)
			m.max_karty=0
		ELSE 
			m.max_karty=aakarty.c_karty
		ENDIF 
	ELSE
		m.max_karty=0
	ENDIF 
	DO pozavirej WITH "aakarty"
	STORE .f. TO reindexovat, reindexovat_sk

	had.INCREMENT("food_dat, food_set, semafory, errors, maxima, prn_def")

    DO stru_update_1 WITH (m.gchom_path + "food_dat")
    DO clos_data
    USE (m.gchom_path + "food_dat") IN 0 ALIAS food_dat
    REPLACE FOR c_stredisk=0 c_stredisk WITH -9999 + RECNO()
    ERASE (m.gcpri_path + "food_dat.dbf")
    COPY ALL TO (m.gcpri_path + "food_dat") WITH CDX 
    DO clos_data 

	DO stru_update_1 WITH (m.gchom_path+"z_horca")
	DO stru_update_1 WITH (m.gchom_path+"typypohybov")
	DO stru_update_1 WITH (m.gccen_path+"sortiment_dodavatelu")
	DO stru_update_1 WITH m.gchom_path + "food_set"
	DO stru_update_1 WITH m.gchom_path + "semafory"
	DO stru_update_1 WITH m.gchom_path + "errors"
	DO stru_update_1 WITH fn_users
	DO stru_update_1 WITH m.gchom_path + "maxima"
	DO stru_update_1 WITH m.gchom_path + "prn_def"
	DO stru_update_1 WITH m.gcdat_path + "inventur"
	DO stru_update_1 WITH m.gcdat_path + "inv_uloz"
	DO stru_update_1 WITH m.gchom_path + "prevadzkarne"
	IF FILE(m.gchom_path+"baz_izby.dbf")
		DO stru_update_1 WITH (m.gchom_path+"baz_izby.dbf")
	ENDIF 

	IF FILE(m.gchom_path+"baz_kalkulacie.dbf")
		DO stru_update_1 WITH (m.gchom_path+"baz_kalkulacie.dbf")
	ENDIF 
	IF FILE(m.gchom_path+"baz_kalkzony.dbf")
		DO stru_update_1 WITH (m.gchom_path+"baz_kalkzony.dbf")
	ENDIF 
	IF FILE(m.gchom_path+"baz_prechody.dbf")
		DO stru_update_1 WITH (m.gchom_path+"baz_prechody.dbf")
	ENDIF 
	IF FILE(m.gchom_path+"baz_pristupy.dbf")
		DO stru_update_1 WITH (m.gchom_path+"baz_pristupy.dbf")
	ENDIF 
	IF FILE(m.gchom_path+"baz_pohyby.dbf")
		DO stru_update_1 WITH (m.gchom_path+"baz_pohyby.dbf")
	ENDIF 
	IF FILE(m.gchom_path+"baz_zamky.dbf")
		DO stru_update_1 WITH (m.gchom_path+"baz_zamky.dbf")
	ENDIF 
	IF FILE(m.gchom_path+"baz_zony.dbf")
		DO stru_update_1 WITH (m.gchom_path+"baz_zony.dbf")
	ENDIF 

	had.INCREMENT("polozky, bourak, umisteni")

	IF FILE(m.gcdat_path+"exp_faktura.dbf")
		DO stru_update_1 WITH (m.gcdat_path+"exp_faktura.dbf")
	ENDIF 
	DO stru_update_1 WITH m.fn_polozky
*DO testidr WITH m.fn_polozky,"polozky"
	DO stru_update_1 WITH m.fn_cas_hlav
	DO stru_update_1 WITH m.fn_cas_pol
	DO stru_update_1 WITH m.fn_hh_hlav
	DO stru_update_1 WITH m.fn_hh_druhy
	DO stru_update_1 WITH m.fn_umdruhy
	DO stru_update_1 WITH m.fn_eany
	DO stru_update_1 WITH m.fn_spotrebnadan
	DO stru_update_1 WITH m.fn_buff_r
	DO stru_update_1 WITH m.fn_buff_d
	DO stru_update_1 WITH m.fn_bourak
	DO stru_update_1 WITH m.fn_umisteni
	DO stru_update_1 WITH m.fn_partneri
	DO stru_update_1 WITH m.fn_sklad
	IF FILE(m.gccen_path+"pr_hores.dbf")
		DO stru_update_1 WITH (m.gccen_path+"pr_hores.dbf")
	ENDIF
	IF !test_mena(m.fn_sklad)
		SELECT 0
		USE (m.fn_sklad)
		IF m.giakt_mena<>1
			IF MESSAGEBOX(jaz("form_ceny_v_skladoch_su_v_mene")+" "+en__meny(2,3)+"?",4+32+256,"FoodMan")=6
				REPLACE c_mena WITH 2 FOR EMPTY(c_mena)
			ELSE
				REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
			ENDIF
		ELSE
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
		ENDIF
		USE
	ENDIF

	DO stru_update_1 WITH m.fn_davky
	IF !test_mena(m.gcdat_path + "davky")
		SELECT 0
		USE (m.gcdat_path + "davky") ALIAS testsubor
		IF m.giakt_mena<>1
			IF MESSAGEBOX(jaz("form_ceny_v_davkach_su_v_mene")+" "+en__meny(2,3)+"?",4+32+256,"FoodMan")=6
				REPLACE c_mena WITH 2 FOR EMPTY(c_mena)
			ELSE
				REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
			ENDIF
		ELSE
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
		ENDIF
		USE
	ENDIF
	DO stru_update_1 WITH m.gcdat_path + "davk_hl"
	IF !test_mena(m.gcdat_path + "davk_hl")
		SELECT 0
		USE (m.gcdat_path + "davk_hl") ALIAS testsubor
		IF m.giakt_mena<>1
			IF MESSAGEBOX("Ceny v rautoch sú v "+en__meny(2,3)+"?",4+32+256,"FoodMan")=6
				REPLACE c_mena WITH 2 FOR EMPTY(c_mena)
			ELSE
				REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
			ENDIF
		ELSE
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
		ENDIF
		USE
	ENDIF

	DO stru_update_1 WITH m.fn_dluhy
	DO stru_update_1 WITH m.fn_limity
	DO stru_update_1 WITH m.fn_limit_hl
	DO stru_update_1 WITH m.fn_limitdni
	DO stru_update_1 WITH m.fn_limitrov
	DO stru_update_1 WITH m.fn_limitchody
	DO stru_update_1 WITH m.fn_limithladiny
	DO stru_update_1 WITH m.fn_limitrovhladiny
	DO stru_update_1 WITH m.fn_limittypy
	DO stru_update_1 WITH m.fn_limittypchody
	DO stru_update_1 WITH m.fn_limitsablhl
	DO stru_update_1 WITH m.fn_limitsablpol
	DO stru_update_1 WITH m.fn_limitsabldni

	DO stru_update_1 WITH m.gcdat_path + "limity_a"
	DO stru_update_1 WITH m.gcdat_path + "limhl_a"
	DO stru_update_1 WITH m.gcdat_path + "limdni_a"
	DO stru_update_1 WITH m.gcdat_path + "limity"
	DO stru_update_1 WITH m.gcdat_path + "limit_hl"
	IF !test_mena(m.gcdat_path + "limit_hl")
		SELECT 0
		USE (m.gcdat_path + "limit_hl") ALIAS testsubor
		IF m.giakt_mena<>1
			IF MESSAGEBOX(jaz("form_ceny_v_limitoch_su_v_mene")+" "+en__meny(2,3)+"?",4+32+256,"FoodMan")=6
				REPLACE c_mena WITH 2 FOR EMPTY(c_mena)
			ELSE
				REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
			ENDIF
		ELSE
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
		ENDIF
		USE
	ENDIF

	DO stru_update_1 WITH m.gcdat_path + "limitdni"
	IF !test_mena(m.gcdat_path + "limitdni")
		SELECT 0
		USE (m.gcdat_path + "limitdni") ALIAS testsubor
		IF m.giakt_mena<>1
			IF MESSAGEBOX("Limity v limitoch sú v "+en__meny(2,3)+"?",4+32+256,"FoodMan")=6
				REPLACE c_mena WITH 2 FOR EMPTY(c_mena)
			ELSE
				REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
			ENDIF
		ELSE
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
		ENDIF
		USE
	ENDIF

	DO stru_update_1 WITH m.gchom_path + "druhy_pl"
	IF FILE(m.gcucto_path+"u_ex_obr.dbf")
		DO stru_update_1 WITH (m.gcucto_path+"u_ex_obr")
	ENDIF
	IF FILE(m.gcucto_path+"u_ex_pol.dbf")
		DO stru_update_1 WITH (m.gcucto_path+"u_ex_pol")
	ENDIF
	IF FILE(m.gcucto_path+"u_ex_plt.dbf")
		DO stru_update_1 WITH (m.gcucto_path+"u_ex_plt")
	ENDIF
	IF m.slovenskaverzia
		IF FILE(m.gcucto_path+"u_ex.dbf")
			DO stru_update_1 WITH (m.gcucto_path+"u_ex")
		ENDIF
	ENDIF
	IF FILE(m.gchom_path+"z_hores10.dbf")
		DO stru_update_1 WITH (m.gchom_path+"z_hores10")
	ENDIF
	IF FILE(m.gccen_path+"pr_hores10.dbf")
		DO stru_update_1 WITH (m.gccen_path+"pr_hores10")
	ENDIF
	IF FILE(m.gccen_path+"pr_hores10_uzav.dbf")
		DO stru_update_1 WITH (m.gccen_path+"pr_hores10_uzav")
	ENDIF

	IF .NOT. FILE(m.gccen_path + "parovaky.dbf")
		DO creafile WITH m.gccen_path + "parovaky"
	ENDIF

	DO stru_update_1 WITH m.gcdat_path + "vahinv"

	had.INCREMENT("doklady, obraty")
	DO stru_update_1 WITH m.fn_obr_alk
	DO stru_update_1 WITH m.fn_doklady
	DO stru_update_1 WITH m.fn_obraty
	DO stru_update_1 WITH m.fn_dokl_a
	DO stru_update_1 WITH m.fn_obra_a
	DO stru_update_1 WITH m.fn_dokl_sto
	DO stru_update_1 WITH m.fn_obra_sto
	IF FILE(m.gcdat_path+"dokl_buf.dbf")
		DO stru_update_1 WITH (m.gcdat_path+"dokl_buf")
	ENDIF
	IF FILE(m.gcdat_path+"obra_buf.dbf")
		DO stru_update_1 WITH (m.gcdat_path+"obra_buf")
	ENDIF
	IF FILE(m.gccen_path+"edi_hlav.dbf")
		DO stru_update_1 WITH (m.gccen_path+"edi_hlav")
	ENDIF
	IF FILE(m.gccen_path+"edi_pol.dbf")
		DO stru_update_1 WITH (m.gccen_path+"edi_pol")
	ENDIF
	IF FILE(m.gchom_path+"edi_prev.dbf")
		DO stru_update_1 WITH (m.gchom_path+"edi_prev")
	ENDIF
	IF FILE(m.gccen_path+"edi_part.dbf")
		DO stru_update_1 WITH (m.gccen_path+"edi_part")
	ENDIF
	DO stru_update_1 WITH m.fn_uzav
	PRIVATE minmesiac,m.minuzav,riadok
	m.minmesiac=en__meny(1,4)
	IF m.slovenskaverzia
		m.minuzav=m.minmesiac+"31 23:59:59"
	ELSE
		m.minuzav="991231 23:59"
	ENDIF 
	IF !test_mena(m.fn_uzav)
		SELECT 0
		USE (m.fn_doklady) ALIAS doklady
		SELECT 0
		USE (m.fn_dokl_a) ALIAS dokl_a
		SELECT 0
		USE (m.fn_dokl_sto) ALIAS dokl_sto
		IF FILE(m.gcdat_path+"dokl_buf.dbf")
			SELECT 0
			USE (m.gcdat_path+"dokl_buf.dbf") ALIAS dokl_buf
		ENDIF

		SELECT 0
		USE (m.fn_uzav) ALIAS uzaverka
		IF m.giakt_mena<>1
			SCAN FOR EMPTY(c_mena)
				FOR m.riadok=1 TO ALEN(en_meny,1)
					IF (rok+mesiac)<=en__meny(m.riadok,4)
						REPLACE c_mena WITH m.riadok
						EXIT
					ENDIF
				ENDFOR
				SELECT doklady
				REPLACE c_mena WITH uzaverka.c_mena FOR c_stredisk=uzaverka.c_stredisk .AND. c_dokl<=uzaverka.c_dokldo .AND. c_dokl>=uzaverka.c_doklod
				SELECT dokl_a
				REPLACE c_mena WITH uzaverka.c_mena FOR c_stredisk=uzaverka.c_stredisk .AND. c_dokl<=uzaverka.c_dokldo .AND. c_dokl>=uzaverka.c_doklod
				SELECT dokl_sto
				REPLACE c_mena WITH uzaverka.c_mena FOR c_stredisk=uzaverka.c_stredisk .AND. c_dokl<=uzaverka.c_dokldo .AND. c_dokl>=uzaverka.c_doklod
				IF USED("dokl_buf")
					SELECT dokl_buf
					REPLACE c_mena WITH uzaverka.c_mena FOR c_stredisk=uzaverka.c_stredisk .AND. c_dokl<=uzaverka.c_dokldo .AND. c_dokl>=uzaverka.c_doklod
				ENDIF
				SELECT uzaverka
			ENDSCAN
		ELSE
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
			SELECT doklady
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
			SELECT dokl_a
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
			SELECT dokl_sto
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
			IF USED("dokl_buf")
				SELECT dokl_buf
				REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
			ENDIF
		ENDIF
		USE IN uzaverka
		USE IN doklady
		USE IN dokl_a
		USE IN dokl_sto
		IF USED("dokl_buf")
			USE IN dokl_buf
		ENDIF
	ENDIF
	IF !test_mena(m.fn_doklady)
		SELECT 0
		USE (m.fn_doklady) ALIAS doklady
		SCAN FOR EMPTY(c_mena)
			FOR m.riadok=1 TO ALEN(en_meny,1)
				IF LEFT(DTOS(datum_dokl),6)<=en__meny(m.riadok,4)
					REPLACE c_mena WITH m.riadok
					EXIT
				ENDIF
			ENDFOR
		ENDSCAN
		REPLACE FOR EMPTY(c_mena) c_mena WITH 1
		USE
	ENDIF
	IF !test_mena(m.fn_dokl_a)
		SELECT 0
		USE (m.fn_dokl_a) ALIAS doklady
		SCAN FOR EMPTY(c_mena)
			FOR m.riadok=1 TO ALEN(en_meny,1)
				IF LEFT(DTOS(datum_dokl),6)<=en__meny(m.riadok,4)
					REPLACE c_mena WITH m.riadok
					EXIT
				ENDIF
			ENDFOR
		ENDSCAN
		USE
	ENDIF
	IF !test_mena(m.fn_dokl_sto)
		SELECT 0
		USE (m.fn_dokl_sto) ALIAS doklady
		SCAN FOR EMPTY(c_mena)
			FOR m.riadok=1 TO ALEN(en_meny,1)
				IF LEFT(DTOS(datum_dokl),6)<=en__meny(m.riadok,4)
					REPLACE c_mena WITH m.riadok
					EXIT
				ENDIF
			ENDFOR
		ENDSCAN
		USE
	ENDIF
	IF FILE(m.gcdat_path+"dokl_buf.dbf")
		IF !test_mena(m.gcdat_path+"dokl_buf.dbf")
			SELECT 0
			USE (m.gcdat_path+"dokl_buf.dbf") ALIAS doklady
			SCAN FOR EMPTY(c_mena)
				FOR m.riadok=1 TO ALEN(en_meny,1)
					IF LEFT(DTOS(datum_dokl),6)<=en__meny(m.riadok,4)
						REPLACE c_mena WITH m.riadok
						EXIT
					ENDIF
				ENDFOR
			ENDSCAN
			USE
		ENDIF
	ENDIF
	IF FILE(m.gcdat_path+"listovanie.dbf")
		DO stru_update_1 WITH (m.gcdat_path+"listovanie")
	ENDIF
	IF FILE(m.gccen_path+"uexarchobraty.dbf")
		DO stru_update_1 WITH (m.gccen_path+"uexarchobraty")
	ENDIF
	IF FILE(m.gccen_path+"uexarchpolozky.dbf")
		DO stru_update_1 WITH (m.gccen_path+"uexarchpolozky")
	ENDIF
	IF FILE(m.gccen_path+"uexarchplatby.dbf")
		DO stru_update_1 WITH (m.gccen_path+"uexarchplatby")
	ENDIF
	had.INCREMENT("sk")
	DO stru_update_1 WITH m.fn_sk_fin
	DO testidr WITH m.fn_sk_fin,"sk_fin"
	DO stru_update_1 WITH m.fn_sk_plt
	DO testidr WITH m.fn_sk_plt,"sk_plt"
	DO stru_update_1 WITH m.fn_sk_pol
	DO testidr WITH m.fn_sk_pol,"sk_pol"
	IF m.slovenskaverzia
		DO stru_update_1 WITH m.fn_sk_fis
		DO testidr WITH m.fn_sk_fin,"sk_fis"
		TRY 
			SELECT 0
			USE (m.fn_sk_fis) ALIAS sk_fis 
			GO BOTTOM 
			IF LEN(ALLTRIM(uzaverka))=12
				USE (m.fn_sk_fin) IN 0 ALIAS sk_fin
				SELECT sk_fis
				UPDATE sk_fis SET uzaverka=sk_fin.uzaverka from sk_fin WHERE sk_fis.u_cis=sk_fin.u_cis AND ALLTRIM(sk_fis.uzaverka)=LEFT(sk_fin.uzaverka,12)
				USE IN sk_fin
			ENDIF 
			USE IN sk_fis
		CATCH
		ENDTRY
		DO pozavirej WITH "sk_fin, sk_fis"
		DO stru_update_1 WITH m.fn_sk_vklvy
		DO testidr WITH m.fn_sk_fin,"sk_vklvy"
		TRY 
			SELECT 0
			USE (m.fn_sk_vklvy) ALIAS sk_vklvy 
			GO BOTTOM 
			IF LEN(ALLTRIM(uzaverka))=12
				USE (m.fn_sk_sez) IN 0 ALIAS sk_sez
				SELECT sk_vklvy
				UPDATE sk_vklvy SET uzaverka=sk_sez.uzaverka from sk_sez WHERE ALLTRIM(sk_vklvy.uzaverka)=LEFT(sk_sez.uzaverka,12)
				USE IN sk_sez
			ENDIF 
			USE IN sk_vklvy
		CATCH
		ENDTRY
		DO pozavirej WITH "sk_sez, sk_vklvy"
	ENDIF 
	DO stru_update_1 WITH m.fn_sk_sez
	DO testidr WITH m.fn_sk_sez,"sk_sez"
	IF !test_mena(m.fn_sk_sez)
		SELECT 0
		USE (m.fn_sk_sez) ALIAS sk_sez
		IF m.giakt_mena<>1
			LOCATE FOR c_mena=1
			IF FOUND()
				m.minmesiac="Koniec "+SUBSTR(m.minmesiac,5,2)+"/"+LEFT(m.minmesiac,4)
				LOCATE FOR ALLTRIM(sk_sez.lastuzav)=m.minmesiac
				IF !FOUND()
					DO WHILE .T.
						=MESSAGEBOX(jaz("form_oznacte_posled_uz_v")+" "+en__meny(1,3),48,"FoodMan")
						DO FORM koniecsk
						SELECT sk_sez
						LOCATE FOR ALLTRIM(sk_sez.lastuzav)=m.minmesiac
						IF FOUND()
							m.minuzav=sk_sez.uzaverka
							EXIT
						ENDIF
					ENDDO
				ELSE
					m.minuzav=sk_sez.uzaverka
				ENDIF
				SCAN FOR EMPTY(c_mena)
					IF uzaverka<=m.minuzav
						REPLACE c_mena WITH 1
					ELSE
						REPLACE c_mena WITH 2
					ENDIF
				ENDSCAN
			ELSE
				REPLACE c_mena WITH m.giakt_mena FOR EMPTY(c_mena)
			ENDIF
		ELSE
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
		ENDIF
		USE IN sk_sez
	ENDIF

	DO stru_update_1 WITH m.fn_sk_txt

	had.INCREMENT("sk_a")
	DO stru_update_1 WITH m.fn_sk_fin_a
	DO stru_update_1 WITH m.fn_sk_plt_a
	DO stru_update_1 WITH m.fn_sk_pol_a
	DO stru_update_1 WITH m.fn_sk_sez_a
	DO stru_update_1 WITH m.fn_sk_fis_a
	DO stru_update_1 WITH m.fn_sk_vklvy_a
	IF !test_mena(m.fn_sk_sez_a)
		SELECT 0
		USE (m.fn_sk_sez_a) ALIAS sk_sez
		IF m.giakt_mena<>1
			SCAN FOR EMPTY(c_mena)
				IF uzaverka<=m.minuzav
					REPLACE c_mena WITH 1
				ELSE
					REPLACE c_mena WITH 2
				ENDIF
			ENDSCAN
		ELSE
			REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
		ENDIF
		USE IN sk_sez
	ENDIF
	RELEASE m.minmesiac,m.minuzav

	DO stru_update_1 WITH m.fn_sk_txt_a

	DO stru_update_1 WITH m.gccen_path + "TMSKFIN"

	DO stru_update_1 WITH m.gccen_path + "_TMSKFIN"
	DO stru_update_1 WITH m.gccen_path + "_TMSKPLT"
	DO stru_update_1 WITH m.gccen_path + "_TMSKPOL"
	DO stru_update_1 WITH m.gccen_path + "_TMSKTXT"


	DO stru_update_1 WITH fn_objednan
	DO stru_update_1 WITH (gchom_path + "kursy")
	DO stru_update_1 WITH (gchom_path + "hores_d")
***Koniec: L.L Zmena strukruty doplnene aj ostane subory (asi nie vsetky) aby to nerobilo chyby pri provom spusteni a updatovalo co najviac databaz***

	RELEASE had
	IF m.reindexovat
		DO indexy
	ENDIF
	IF m.reindexovat_sk
		DO index_sk WITH ""   IN indexy
		DO index_sk WITH "_a" IN indexy
	ENDIF
	DO clos_data
	IF FILE("\foodw32\food_set.dbf")
		USE \foodw32\food_set
		LOCATE FOR var_name = "lic_id"
		IF .NOT. FOUND()
			INSERT INTO \foodw32\food_set (var_name, var_value, var_typ, COMMENT) VALUES ("lic_id", '""', "C", "licencni cislo")
		ENDIF

		LOCATE FOR var_name = "lic_kod"
		IF .NOT. FOUND()
			INSERT INTO \foodw32\food_set (var_name, var_value, var_typ, COMMENT) VALUES ("lic_kod", '""', "C", "licencni kod")
		ENDIF

	ENDIF
	DO clos_data
	err_h_info = ""

	DO upgrade_setup_files

ENDIF
IF !m.slovenskaverzia
	TRY
		DO poslimaildoalta WITH " update verze " + m.hotel_name, "update na verzi " + m.gcverze + " v " + m.machine  + "-" + m.gchom_path, (m.gchom_path + "food_set.dbf"), (m.gchom_path + "food_dat.dbf"),(m.gchom_path + "food_dat.cdx"), "evzen@altopraha.cz"
	CATCH
	ENDTRY
ENDIF


************************************************************
PROCEDURE vypln_kod_v_sk_pol
RETURN       &&&& kasy uz c_karty vyplnuji, tak neni potreba
IF m.issql
	IF !USED("teraz")
		USE (m.sqlprefix+"rteraz") IN 0 ALIAS teraz
	ELSE
		=REQUERY("teraz")
	ENDIF 
	m.vysledok=sql_exec("SELECT food600.vyplnkodvskpol("+ ALLTRIM(STR(m.cdata,2,0))+")","teraz")
	DO pozavirej WITH "teraz"
ELSE
	USE (m.fn_karty) ALIAS karty ORDER nazev IN 0
	CREATE TABLE (m.gcpri_path + "nazvy") FREE (nazev c(30), druh_kalk c(10), c_karty i, nazev1 c(30), idriadok i)
	SELECT 0
	USE (m.fn_sk_pol)   ALIAS sk_pol
	DO vypln_kod_v_sk_pol_2
	SELECT sk_pol
	USE (m.fn_sk_pol_a) ALIAS sk_pol
	DO vypln_kod_v_sk_pol_2
	SELECT nazvy
    IF RECCOUNT() > 0
    	REPLACE ALL c_karty WITH genc_kar(), druh_kalk WITH "SK-sirotek", nazev1 WITH m.smazana_karta
    	SELECT karty
    	APPEND FROM (m.gcpri_path + "nazvy")
    	SELECT sk_pol
    	USE (m.fn_sk_pol)   ALIAS sk_pol
    	DO vypln_kod_v_sk_pol_2
    	SELECT sk_pol
    	USE (m.fn_sk_pol_a) ALIAS sk_pol
    	DO vypln_kod_v_sk_pol_2
    ENDIF 
	DO pozavirej WITH "sk_pol, sk_pol_a, karty, nazvy1, nazvy"
ENDIF


************************************************************
PROCEDURE vypln_kod_v_sk_pol_2

SELECT sk_pol
IF FSIZE("NAZEV") > 0
	WAIT "doplneni c_karty do " + DBF() WINDOW NOWAIT AT 22,22
	SELECT sk_pol
	SET RELATION TO nazev INTO karty
	REPLACE FOR EMPTY(c_karty) c_karty WITH karty.c_karty
	SELECT DISTI nazev WHERE EMPTY(c_karty) FROM sk_pol INTO TABLE (m.gcpri_path + "nazvy1")
	SELECT nazvy
	APPEND FROM (m.gcpri_path + "nazvy1.dbf")
	WAIT CLEAR
ENDIF


************************************************************
PROCEDURE stru_update_skupiny
DO clos_data

USE (m.fn_skupiny)
IF   .f.  &&&  !FILE(m.fn_vypocty)
	DO creafile WITH (m.fn_vypocty)
	IF FSIZE("vypocet","skupiny")>0
		INSERT INTO vypocty (c_druh, druh, spart_kas, typ_kalk, dan01, vypocet01, vypocet02, vypocet03, vypocet04, vypocet05, vypocet06, vypocet07, vypocet08, vypocet09, vypocet10, ;
			vypocet11, vypocet12, vypocet13, vypocet14, vypocet15, vypocet16, vypocet17, vypocet18, vypocet19, vypocet20, ;
			vypocet21, vypocet22, vypocet23, vypocet24, vypocet25, vypocet26, vypocet27, vypocet28, vypocet29, vypocet30,;
			vypocet31, vypocet32, vypocet33, vypocet34, vypocet35, vypocet36, vypocet37, vypocet38, vypocet39, vypocet40,;
			vypocet41, vypocet42, vypocet43, vypocet44, vypocet45, vypocet46, vypocet47, vypocet48, vypocet49, vypocet50,;
			vypocet51, vypocet52, vypocet53, vypocet54, vypocet55, vypocet56, vypocet57, vypocet58, vypocet59, vypocet60,;
			vypocet61, vypocet62, vypocet63, vypocet64, vypocet65, vypocet66, vypocet67, vypocet68, vypocet69, vypocet70,;
			vypocet71, vypocet72, vypocet73, vypocet74, vypocet75, vypocet76, vypocet77, vypocet78, vypocet79, vypocet80,;
			vypocet81, vypocet82, vypocet83, vypocet84, vypocet85, vypocet86, vypocet87, vypocet88, vypocet89, vypocet90);
			SELECT c_druh, druh, spart_kas, typ_kalk, dan01, vypocet01, vypocet02, vypocet03, vypocet04, vypocet05, vypocet06, vypocet07, vypocet08, vypocet09, vypocet10, ;
			vypocet11, vypocet12, vypocet13, vypocet14, vypocet15, vypocet16, vypocet17, vypocet18, vypocet19, vypocet20, ;
			vypocet21, vypocet22, vypocet23, vypocet24, vypocet25, vypocet26, vypocet27, vypocet28, vypocet29, vypocet30,;
			vypocet31, vypocet32, vypocet33, vypocet34, vypocet35, vypocet36, vypocet37, vypocet38, vypocet39, vypocet40,;
			vypocet41, vypocet42, vypocet43, vypocet44, vypocet45, vypocet46, vypocet47, vypocet48, vypocet49, vypocet50,;
			vypocet51, vypocet52, vypocet53, vypocet54, vypocet55, vypocet56, vypocet57, vypocet58, vypocet59, vypocet60,;
			vypocet61, vypocet62, vypocet63, vypocet64, vypocet65, vypocet66, vypocet67, vypocet68, vypocet69, vypocet70,;
			vypocet71, vypocet72, vypocet73, vypocet74, vypocet75, vypocet76, vypocet77, vypocet78, vypocet79, vypocet80,;
			vypocet81, vypocet82, vypocet83, vypocet84, vypocet85, vypocet86, vypocet87, vypocet88, vypocet89, vypocet90 FROM skupiny
	ELSE
		INSERT INTO vypocty (c_druh, druh, spart_kas, typ_kalk, dan01, vypocet01, vypocet02, vypocet03, vypocet04, vypocet05, vypocet06, vypocet07, vypocet08, vypocet09, vypocet10);
			SELECT c_druh, druh, spart_kas, typ_kalk, dan01, vypocet01, vypocet02, vypocet03, vypocet04, vypocet05, vypocet06, vypocet07, vypocet08, vypocet09, vypocet10 FROM skupiny
	ENDIF 
	DO pozavirej WITH "vypocty"
ENDIF 
SELECT skupiny
policka = ""
FOR ii = 1 TO 99
	policka = m.policka + UPPER(FIELD (m.ii))
ENDFOR
IF ("TYP_KALK" $ m.policka) .AND. ("TYP_SKL" $ m.policka)
	DO clos_data
	RETURN 
ENDIF

DO creafile WITH m.gcpri_path + "skupiny",.t.
DO clos_data
IF stru_diff(m.fn_skupiny, m.gcpri_path + "skupiny")
	reindexovat = .T.

	pozice = AT("\", m.fn_skupiny)
	zaloha = LEFT(m.fn_skupiny, pozice) + "zaloha\" + DTOS(DATE()) + STRTR(SUBST(TTOC(DATETIME()), 12, 5), ":", "") + "\" + SUBSTR(m.fn_skupiny, m.pozice+1)
	DO mk_dir WITH JUSTPATH(m.zaloha)

	USE
	RENAME (m.fn_skupiny + ".*") TO (m.zaloha + ".*")
	DO creafile WITH m.fn_skupiny
	USE (m.fn_skupiny) ALIAS skupiny EXCL
	APPE FROM (m.zaloha) FOR typ_skup = "K"
	REPLACE ALL typ_kalk WITH typ_skup, typ_skup WITH ""

	SELECT * WHERE BETWEEN(typ_skup, "a", "z") FROM (m.zaloha) INTO TABLE (m.gcpri_path + "skup")
	SCAN
		SCATTER MEMVA
		SELECT skupiny
		LOCATE FOR druh = m.druh
		IF FOUND()
			GATHER FIELD typ_skup MEMVAR
		ELSE
			INSERT INTO (m.fn_skupiny) FROM MEMVAR
		ENDIF
	ENDSCAN

	SELECT *, typ_skup AS typ_skl WHERE BETWEEN(typ_skup, "0", "9") FROM (m.zaloha) INTO TABLE (m.gcpri_path + "skup")
	REPLACE ALL typ_skup WITH ""
	SCAN
		SCATTER MEMVA
		SELECT skupiny
		LOCATE FOR druh = m.druh
		IF FOUND()
			GATHER FIELD typ_skl MEMVAR
		ELSE
			INSERT INTO (m.fn_skupiny) FROM MEMVAR
		ENDIF
	ENDSCAN
	SELECT skupiny
	DO app_log WITH UPPER(m.fn_skupiny) + " : struct updated"
ENDIF
DO clos_data

************************************************************
PROCEDURE stru_update_1
PARAMETERS soubor, nevadi
DO clos_data
err_h_info = m.soubor
IF .NOT. FILE(JUSTPATH(m.soubor) + "\" + JUSTSTEM(m.soubor) + ".dbf")    && L.L Ak neexistoval subor (napr. pri 1.starte tak to hadzalo chybu)
	DO creafile WITH m.soubor
	USE
ELSE
	IF !INLIST(RIGHT(LOWER(soubor),6),"sk_fin","sk_pol","sk_plt","sk_txt","sk_sez") .AND. !INLIST(RIGHT(LOWER(soubor),5),"users") .AND. !INLIST(RIGHT(LOWER(soubor),8),"_tmskfin","_tmskpol","_tmskplt","_tmsktxt")
		m.vysledokupd=m.vysledokupd AND setautoincr(m.soubor)
	ENDIF
ENDIF

TRY
    ERASE (m.gcpri_path + JUSTSTEM(m.soubor) + ".dbf")
CATCH
ENDTRY 
DO creafile WITH m.gcpri_path + JUSTSTEM(m.soubor)
DO clos_data

IF VARTYPE(updatovat_vzdy) = "U"
      updatovat_vzdy = .F.
ENDIF 

IF m.updatovat_vzdy .OR. stru_diff(m.soubor, m.gcpri_path + JUSTSTEM(m.soubor))

	IF ("SK_" $ UPPER(m.soubor)) .OR. ("TMSK" $ UPPER(m.soubor))
		reindexovat_sk = .T.
	ELSE
		reindexovat = .T.
	ENDIF

	pozice = AT("\", m.soubor)
	zaloha = zaloha_dir  + SUBSTR(m.soubor, m.pozice+1)
	DO mk_dir WITH JUSTPATH(m.zaloha)

	USE
	IF FILE(m.zaloha+".dbf")
		ERASE (m.zaloha+".dbf")
	ENDIF
	IF FILE(m.zaloha+".cdx")
		ERASE (m.zaloha+".cdx")
	ENDIF
	IF FILE(m.zaloha+".fpt")
		ERASE (m.zaloha+".fpt")
	ENDIF

	TRY
		RENAME (m.soubor + ".*") TO (m.zaloha + ".*")
		DO creafile WITH m.soubor

		DO CASE 
			CASE "nlimit_hl"$LOWER(m.soubor) OR "nlimitsablonyhl"$LOWER(m.soubor)
				ALTER TABLE (m.soubor) ALTER COLUMN id_limit INTEGER
				APPEND FROM (m.zaloha)
				SELECT MAX(id_limit) as idl FROM (m.soubor) INTO CURSOR aaa
				IF RECCOUNT("aaa")>0 AND !ISNULL(aaa.idl)
					m.maximum=aaa.idl+1
				ELSE
					m.maximum=1
				ENDIF 
				USE IN aaa
				ALTER TABLE (m.soubor) ALTER COLUMN id_limit INTEGER AUTOINC NEXTVALUE m.maximum
			CASE "nlimitdni"$LOWER(m.soubor) OR "nlimitsablonydni"$LOWER(m.soubor)
				ALTER TABLE (m.soubor) ALTER COLUMN id_den INTEGER
				APPEND FROM (m.zaloha)
				SELECT MAX(id_den) as idl FROM (m.soubor) INTO CURSOR aaa
				IF RECCOUNT("aaa")>0 AND !ISNULL(aaa.idl)
					m.maximum=aaa.idl+1
				ELSE
					m.maximum=1
				ENDIF 
				USE IN aaa
				ALTER TABLE (m.soubor) ALTER COLUMN id_den INTEGER AUTOINC NEXTVALUE m.maximum
			CASE "nlimitchody"$LOWER(m.soubor)
				ALTER TABLE (m.soubor) ALTER COLUMN id_chod INTEGER
				APPEND FROM (m.zaloha)
				SELECT MAX(id_chod) as idl FROM (m.soubor) INTO CURSOR aaa
				IF RECCOUNT("aaa")>0 AND !ISNULL(aaa.idl)
					m.maximum=aaa.idl+1
				ELSE
					m.maximum=1
				ENDIF 
				USE IN aaa
				ALTER TABLE (m.soubor) ALTER COLUMN id_chod INTEGER AUTOINC NEXTVALUE m.maximum
			CASE "nlimit_hladiny"$LOWER(m.soubor)
				ALTER TABLE (m.soubor) ALTER COLUMN idriadok INTEGER
				APPEND FROM (m.zaloha)
				SELECT MAX(idriadok) as idl FROM (m.soubor) INTO CURSOR aaa
				IF RECCOUNT("aaa")>0 AND !ISNULL(aaa.idl)
					m.maximum=aaa.idl+1
				ELSE
					m.maximum=1
				ENDIF 
				USE IN aaa
				ALTER TABLE (m.soubor) ALTER COLUMN idriadok INTEGER AUTOINC NEXTVALUE m.maximum
			CASE "nlimitrov_hladiny"$LOWER(m.soubor)
				ALTER TABLE (m.soubor) ALTER COLUMN idriadok INTEGER
				APPEND FROM (m.zaloha)
				SELECT MAX(idriadok) as idl FROM (m.soubor) INTO CURSOR aaa
				IF RECCOUNT("aaa")>0 AND !ISNULL(aaa.idl)
					m.maximum=aaa.idl+1
				ELSE
					m.maximum=1
				ENDIF 
				USE IN aaa
				ALTER TABLE (m.soubor) ALTER COLUMN idriadok INTEGER AUTOINC NEXTVALUE m.maximum
			CASE "nlimitrov"$LOWER(m.soubor)
				ALTER TABLE (m.soubor) ALTER COLUMN id_rov INTEGER
				APPEND FROM (m.zaloha)
				SELECT MAX(id_rov) as idl FROM (m.soubor) INTO CURSOR aaa
				IF RECCOUNT("aaa")>0 AND !ISNULL(aaa.idl)
					m.maximum=aaa.idl+1
				ELSE
					m.maximum=1
				ENDIF 
				USE IN aaa
				ALTER TABLE (m.soubor) ALTER COLUMN id_rov INTEGER AUTOINC NEXTVALUE m.maximum
			CASE "nlimittypy"$LOWER(m.soubor)
				ALTER TABLE (m.soubor) ALTER COLUMN id_typ INTEGER
				APPEND FROM (m.zaloha)
				SELECT MAX(id_typ) as idl FROM (m.soubor) INTO CURSOR aaa
				IF RECCOUNT("aaa")>0 AND !ISNULL(aaa.idl)
					m.maximum=aaa.idl+1
				ELSE
					m.maximum=1
				ENDIF 
				USE IN aaa
				ALTER TABLE (m.soubor) ALTER COLUMN id_typ INTEGER AUTOINC NEXTVALUE m.maximum
			CASE "skupiny"$LOWER(m.soubor)
				ALTER TABLE (m.soubor) ALTER COLUMN c_druh INTEGER
				APPEND FROM (m.zaloha)
				SELECT MAX(c_druh) as idl FROM (m.soubor) INTO CURSOR aaa
				IF RECCOUNT("aaa")>0 AND !ISNULL(aaa.idl)
					m.maximum=aaa.idl+1
				ELSE
					m.maximum=1
				ENDIF 
				USE IN aaa
				ALTER TABLE (m.soubor) ALTER COLUMN c_druh INTEGER AUTOINC NEXTVALUE m.maximum
			CASE "cas_hlav"$LOWER(m.soubor) OR "hh_hlav"$LOWER(m.soubor) OR "prevadzkarne"$LOWER(m.soubor) OR "hores_d"$LOWER(m.soubor) OR "listovanie"$LOWER(m.soubor) OR "edi_prev"$LOWER(m.soubor) OR "edi_part"$LOWER(m.soubor)
				ALTER TABLE (m.soubor) ALTER COLUMN idriadok INTEGER
				APPEND FROM (m.zaloha)
				SELECT MAX(idriadok) as idl FROM (m.soubor) INTO CURSOR aaa
				IF RECCOUNT("aaa")>0 AND !ISNULL(aaa.idl)
					m.maximum=aaa.idl+1
				ELSE
					m.maximum=1
				ENDIF 
				USE IN aaa
				ALTER TABLE (m.soubor) ALTER COLUMN idriadok INTEGER AUTOINC NEXTVALUE m.maximum

            CASE "food_dat" $ LOWER(m.soubor)
                APPEND FROM (m.zaloha)
                COPY ALL TO (m.gcpri_path + "food_dat") WITH CDX 

			OTHERWISE 
				APPEND FROM (m.zaloha)
		ENDCASE 
		DO app_log WITH UPPER(m.soubor) + " : struct updated"
	CATCH
		DO app_log WITH UPPER(m.soubor) + " : update neuspesne"
		m.chybyupd = m.chybyupd + m.soubor + CHR(13) + CHR(10)
	ENDTRY
ENDIF
DO clos_data
ERASE (m.gcpri_path + JUSTSTEM(m.soubor) + ".dbf")
ERASE (m.gcpri_path + JUSTSTEM(m.soubor) + ".fpt")
ERASE (m.gcpri_path + JUSTSTEM(m.soubor) + ".cdx")


*!************************************************************************************
PROCEDURE stru_diff
PARAMETERS o_filename, n_filename
old_filename = strtr(m.o_filename, ".dbf", "")
new_filename = strtr(m.n_filename, ".dbf", "")

IF FILE(m.old_filename + ".dbf") .and. FILE(m.new_filename + ".dbf")
	USE (m.new_filename)
	COPY STRU EXTENDED TO (m.gcpri_path + "new_stru")
	USE (m.gcpri_path + "new_stru") exclu
	INDEX ON LEFT(field_name, 33) TAG field_name
	SELECT 0
	USE (m.old_filename)
	old_codepage = CPDBF()
	COPY STRU EXTENDED TO (m.gcpri_path + "o_str")
	USE
	SELECT LEFT(field_name, 15) AS o_name, SPACE(15) AS field_name, ;
		field_type + " "     AS o_type, SPACE(2)  AS field_type, ;
		field_len            AS o_len,        000 AS field_len,  ;
		field_dec            AS o_dec,        000 AS field_dec,  ;
		field_step           AS o_step,   0000000 AS field_step  ;
		FROM (m.gcpri_path + "o_str") INTO TABLE (m.gcpri_path + "old_stru")
	SET RELATION TO LEFT(o_name, 33) INTO new_stru
	SCAN
		IF o_type = new_stru.field_type .AND. o_len = new_stru.field_len .AND. o_dec = new_stru.field_dec .AND. o_step = new_stru.field_step
			REPLACE new_stru.field_name WITH ""
			REPLACE field_name WITH "", o_name WITH ""
		ELSE
			REPLACE new_stru.field_name WITH ""
			REPLACE field_type WITH new_stru.field_type, field_len WITH new_stru.field_len, field_dec WITH new_stru.field_dec, field_step WITH new_stru.field_step
			REPLACE field_name WITH IIF(field_len>0, o_name, "")
		ENDIF
	ENDSCAN
	SET RELATION OFF INTO new_stru
	APPEND FROM (m.gcpri_path + "new_stru") FOR ! EMPTY(field_name)
	DELETE FOR EMPTY(o_name + field_name)
	REPLACE FOR EMPTY(o_name) o_name WITH field_name
	retval = (! prazdna())
	IF old_codepage # m.def_cp
		retval = .T.
	ENDIF 
	IF m.retval
		REPLACE FOR field_step # 0 field_type WITH ALLTRIM(field_type) + "A"
		REPLACE FOR o_step     # 0 o_type     WITH ALLTRIM(o_type)     + "A"
        oo_fn = "2#$%^&"
		SCAN 
            IF old_filename # m.oo_fn
                oo_fn = old_filename
                small_log(LOWER(old_filename), "update_struktur")
            ENDIF 

            txt_to_log = ALLTRIM(o_type)     + "(" + ALLTRIM(STR(o_len)) + "," + ALLTRIM(STR(o_dec)) + ") -> " + ;
                         ALLTRIM(field_type) + "(" + ALLTRIM(STR(field_len)) + "," + ALLTRIM(STR(field_dec)) + ")"
            txt_to_log = STRTRAN( m.txt_to_log, ",0)", ")"   )
            txt_to_log = STRTRAN( m.txt_to_log, "(0)", "   " )

            txt_to_log = STRTRAN( m.txt_to_log, "I(4)" , "Int" )
            txt_to_log = STRTRAN( m.txt_to_log, "IA(4)", "Autoinc" )
            txt_to_log = STRTRAN( m.txt_to_log, "M(4)" , "Memo" )
            txt_to_log = STRTRAN( m.txt_to_log, "L(1)" , "Logical" )

            small_log(SPACE(33) + o_name + m.txt_to_log, "update_struktur")

		ENDSCAN
		IF ALLTRIM(STR(m.old_codepage)) # ALLTRIM(STR(CPCURRENT()))
            small_log(right(allt(old_filename), 14) + ": puvodni codepage " + ALLTRIM(STR(m.old_codepage)) + ", CPCURRENT: " + ALLTRIM(STR(CPCURRENT())), "update_struktur")
		ENDIF 
	ENDIF
	DO pozavirej with "old_stru, o_str, new_stru"
	RETURN m.retval
ELSE
	WAIT "stru_diff: " + m.old_filename + " nebo " + m.new_filename + " neexistuje" wind time 1 at 22,22
	RETURN .f.
ENDIF


******************************************************************
PROCEDURE testidr
PARAMETERS subor, menosub
RETURN
PRIVATE oldsel, imax
oldsel = SELECT()
SELECT 0
USE (m.subor) ALIAS subor
SELECT COUNT(idriadok) AS nulove FROM subor WHERE EMPTY(idriadok) INTO CURSOR nulove
IF nulove.nulove>0
	IF nulove.nulove=RECCOUNT("subor")
		imax=i_max("idriadok "+m.menosub,nulove.nulove)
		SELECT subor
		REPLACE ALL idriadok WITH m.imax-RECNO()+1
	ELSE
		imax=i_max("idriadok "+m.menosub,nulove.nulove)
		SELECT subor
		SCAN FOR EMPTY(idriadok)
			REPLACE idriadok WITH m.imax
			imax=m.imax-1
		ENDSCAN
	ENDIF
ENDIF
USE IN nulove
USE IN subor
SELECT(m.oldsel)


******************************************************************
FUNCTION test_mena
PARAMETERS subor,mena_n
PRIVATE oldsel,m.ret
m.oldsel=SELECT()
SELECT 0
USE (m.subor) ALIAS subor
IF EMPTY(m.mena_n)
	SELECT COUNT(c_mena) AS nulove FROM subor WHERE EMPTY(c_mena) INTO CURSOR nulove
ELSE
	SELECT COUNT(c_mena_n) AS nulove FROM subor WHERE EMPTY(c_mena) INTO CURSOR nulove
ENDIF
IF nulove.nulove>0
	ret=.F.
ELSE
	ret=.T.
ENDIF
USE IN nulove
USE IN subor
SELECT(m.oldsel)
RETURN m.ret



******************************************************************
PROCEDURE upgrade_setup_files
pocet = ADIR(qqq, m.gchom_path + "s_???_*.dbf")
FOR iii = 1 TO m.pocet
	IF .NOT. ("s_kas_" $ LOWER(qqq(iii, 1)))
		TRY
			ALTER TABLE (m.gchom_path + qqq(iii, 1)) ALTER COLUMN var_name c(20)
			ALTER TABLE (m.gchom_path + qqq(iii, 1)) ALTER COLUMN var_value c(111)
			USE
		CATCH
		ENDTRY
	ENDIF
ENDFOR

******************************************************************
FUNCTION setautoincr
PARAMETERS ssubor
PRIVATE uspech, maxcdruh
uspech=.T.
TRY
	USE (m.ssubor) ALIAS ssoubor EXCLUSIVE
	COPY STRUCTURE EXTENDED TO (m.gcpri_path+"struext")
	SELECT 0
	USE (m.gcpri_path+"struext")
	IF "skupiny"$ssubor
		LOCATE FOR LOWER(ALLTRIM(field_name))="c_druh"
		IF FOUND() AND field_step=0
			SELECT ssoubor
			SELECT MAX(c_druh) AS c_druh FROM ssoubor INTO CURSOR aaa
			IF RECCOUNT()>0
				m.maxcdruh=aaa.c_druh+1
			ELSE
				m.maxcdruh=1
			ENDIF
			USE IN aaa
*			REPLACE ALL idriadok WITH RECNO()
			ALTER TABLE ssoubor ALTER COLUMN c_druh i AUTOINC NEXTVALUE m.maxcdruh
		ENDIF
	ELSE
		LOCATE FOR LOWER(ALLTRIM(field_name))="idriadok"
		IF FOUND() AND field_step=0
			SELECT ssoubor
			REPLACE ALL idriadok WITH RECNO()
			ALTER TABLE ssoubor ALTER COLUMN idriadok i AUTOINC NEXTVALUE RECCOUNT()+1
		ENDIF
	ENDIF
	USE IN struext
	USE IN ssoubor
CATCH
	uspech=.F.
	chybyupd=m.chybyupd+m.soubor+CHR(13)+CHR(10)
ENDTRY
RETURN m.uspech
