*!*****************************************************************************
PRIVATE pokr
had = CREATEOBJECT("had", jaz("prg_reindexace") )
had.SHOW()
had.set_max(33)
STORE 0 TO max_c_dokl, max_c_karty, max_c_partner, max_c_druh
DO clos_data
had.INCREMENT("skupiny")

IF f_acc_ex(m.fn_skupiny)
	DO indexuj
ENDIF
m.pokr=.t.
TRY 
	USE (m.fn_skupiny) ALIAS skupiny
CATCH 
	m.pokr=.f.
ENDTRY 
IF m.pokr
	REPLACE FOR EMPTY(druh1) druh1 WITH druh
	REPLACE FOR EMPTY(druh2) druh2 WITH druh
	REPLACE FOR EMPTY(druh3) druh3 WITH druh
	REPLACE FOR EMPTY(druh4) druh4 WITH druh
	REPLACE FOR EMPTY(druh5) druh5 WITH druh

    FOR iii = 1 TO 159       &&& nevyplnene sazby DPH se nahradi predchozim sloupcem
        odkud = cislohladiny(m.iii)
        kam   = cislohladiny(m.iii+1)
        cmd = "REPLACE FOR EMPTY(dan" + m.kam + ") dan" + m.kam + " WITH dan" + m.odkud
        &cmd
    ENDFOR

	SET ORDE TO c_druh
	GO BOTTOM 
	IF ! EOF()
		max_c_druh = skupiny.c_druh
	ENDIF
ENDIF 

*******************************************
had.INCREMENT("karty")
SELE skupiny
SET ORDER TO druh
SELE 0
IF f_acc_ex(m.fn_karty)
	DO indexuj
ENDIF

USE (m.fn_karty) ALIAS karty
REPLACE FOR EMPTY(nazev1) nazev1 WITH petra(nazev)
REPLACE FOR EMPTY(nazev2) nazev2 WITH petra(nazev)
REPLACE FOR EMPTY(nazev3) nazev3 WITH petra(nazev)
REPLACE FOR EMPTY(nazev4) nazev4 WITH petra(nazev)
REPLACE FOR EMPTY(nazev5) nazev5 WITH petra(nazev)

REPLACE FOR EMPTY(naz1) naz1 WITH petra(nazev)
REPLACE FOR EMPTY(naz2) naz2 WITH petra(nazev)
REPLACE FOR EMPTY(naz3) naz3 WITH petra(nazev)
REPLACE FOR EMPTY(naz4) naz4 WITH petra(nazev)
REPLACE FOR EMPTY(naz5) naz5 WITH petra(nazev)
FOR i=1 TO 40
	si = TRANSFORM(m.i,"@L 99")
	REPLACE cena&si WITH en__meny(c_mena,m.giakt_mena)*cena&si FOR EMPTY(c_druhk) .AND. c_mena<>m.giakt_mena .AND. cena&si<>0
ENDFOR
REPLACE c_mena WITH m.giakt_mena FOR EMPTY(c_druhk) .AND. c_mena<>m.giakt_mena

REPLACE ALL kod WITH PADL( ALLT ( kod ), 13 )

REPLACE FOR EMPTY(pocet) pocet WITH 1
REPLACE FOR EMPTY(obal_obsah) obal_obsah WITH 1

SET RELATION TO druh_kalk INTO skupiny
REPLACE ALL dph           WITH skupiny.dan01
SET RELATION TO druh      INTO skupiny
REPLACE FOR EMPTY(dph) dph WITH skupiny.dan01
SET RELATION TO druh_skl  INTO skupiny
REPLACE FOR EMPTY(dph) dph WITH skupiny.dan01
*use in skupiny
REPLACE FOR EMPTY(dph) dph WITH 1
REPLACE FOR EMPTY(c_mena) c_mena WITH m.giakt_mena
REPLACE FOR nazev1 = m.smazana_karta kod WITH "", bar_kod1 WITH "", bar_kod2 WITH ""

SET ORDE TO c_karty
GO BOTTOM 
IF ! EOF()
	max_c_karty = karty.c_karty
ENDIF

DO vypln_ean_pro_mtz


had.INCREMENT("kkarty")
SELE 0
IF f_acc_ex(m.fn_kkarty)
	DO indexuj
ENDIF

had.INCREMENT("kceny")
SELE 0
IF f_acc_ex(m.fn_kceny)
	DO indexuj
ENDIF

had.INCREMENT("ktexty")
SELE 0
IF f_acc_ex(m.fn_ktexty)
	DO indexuj
ENDIF
had.INCREMENT("krest")
SELECT 0
IF f_acc_ex(m.fn_krest)
	DO indexuj
ENDIF
had.INCREMENT("ktried")
SELECT 0
IF f_acc_ex(m.fn_ktried)
	DO indexuj
ENDIF
had.INCREMENT("tried")
SELECT 0
IF f_acc_ex(m.fn_tried)
	DO indexuj
ENDIF

*******************************************
had.INCREMENT("bourak")
IF f_acc_ex(m.fn_bourak)
	DELETE TAG ALL

	SET RELATION TO c_karty INTO karty
	DELETE FOR EMPTY(karty.c_karty)
	SET RELATION TO c_karty2 INTO karty
	DELETE FOR EMPTY(karty.c_karty)
	REPLACE ALL nazev WITH karty.nazev
	SET RELATION TO
	DO indexuj
ENDIF

*******************************************
had.INCREMENT("uzaver")
IF f_acc_ex(m.fn_uzav)
	DELETE TAG ALL
	DO indexuj
ENDIF
IF f_acc_ex(m.fn_uzav_pohyby)
	DELETE TAG ALL
	DO indexuj
ENDIF

had.INCREMENT("sortiment_dodavatelu")
IF f_acc_ex(m.gccen_path+"sortiment_dodavatelu")
	DELETE TAG ALL
	DO indexuj
ENDIF

had.INCREMENT("limity")
IF f_acc_ex(m.gcdat_path + "limity")
	DELETE TAG ALL
	DO indexuj
ENDIF
IF f_acc_ex(m.gcdat_path + "nlimity")
	DELETE TAG ALL
	DO indexuj
ENDIF
IF f_acc_ex(m.gcdat_path + "limit_hl")
	DELETE TAG ALL
	DO indexuj
ENDIF
IF f_acc_ex(m.gcdat_path + "limitdni")
	DELETE TAG ALL
	DO indexuj
ENDIF
IF FILE(m.gcdat_path + "limity_a.dbf")
	IF f_acc_ex(m.gcdat_path + "limity_a")
		DELETE TAG ALL
		DO indexuj
	ENDIF
ENDIF 
IF FILE(m.gcdat_path + "limhl_a.dbf")
	IF f_acc_ex(m.gcdat_path + "limhl_a")
		DELETE TAG ALL
		DO indexuj
	ENDIF
ENDIF 
IF FILE(m.gcdat_path + "limdni_a.dbf")
	IF f_acc_ex(m.gcdat_path + "limdni_a")
		DELETE TAG ALL
		DO indexuj
	ENDIF
ENDIF 

*******************************************
had.INCREMENT("davky")
IF f_acc_ex(m.fn_davky)
	DELETE TAG ALL

	SET RELATION TO c_karty INTO karty
	DELETE FOR EMPTY(karty.c_karty)
	SET RELATION TO
	DO indexuj
ENDIF

IF FILE(m.gcdat_path + "davk_hl.dbf")
    had.INCREMENT("davk_hl")
    IF f_acc_ex(m.gcdat_path + "davk_hl")
        DO indexuj
    ENDIF
ENDIF

*******************************************
had.INCREMENT("dokl_a")
IF f_acc_ex(m.fn_dokl_a)
	DO indexuj
ENDIF

IF FILE(m.gccen_path+"dokl_buf.dbf")
	had.INCREMENT("dokl_buf")
	IF f_acc_ex(m.gccen_path+"dokl_buf.dbf")
		DO indexuj
	ENDIF
	DO pozavirej WITH "dokl_buf"
ENDIF

had.INCREMENT("obr_alk")
IF f_acc_ex(m.fn_obr_alk)
	DELETE TAG ALL
	DO indexuj
ENDIF

*******************************************
had.INCREMENT("doklady")
IF !("_buf"$LOWER(m.fn_doklady))
	IF f_acc_ex(m.fn_doklady)
		DO indexuj
		SET ORDER TO c_dokl
		GO BOTTOM 
		IF ! EOF()
			max_c_dokl = doklady.c_dokl
		ENDIF
		SET FILTER TO kdy < DATE() - 99
		GO BOTTOM 
		IF EOF()
			dluh_c_dokl = 0
		ELSE
			dluh_c_dokl = doklady.c_dokl
		ENDIF
	ELSE
		m.dluh_c_dokl=0
	ENDIF
ELSE
	m.dluh_c_dokl=0
ENDIF 
*******************************************
SELECT 0
IF !("_buf"$LOWER(m.fn_obraty))
	had.INCREMENT("obraty")
	IF f_acc_ex(m.fn_obraty)
	    DELETE TAG ALL
	    REPLACE ALL serial_no WITH LOWER(serial_no)
	    DO indexuj
	ENDIF

	*** Doplnenie chybajucich riadkov v DOKLADY.DBF ***
	IF !USED("obraty")
		USE (m.fn_obraty) ALIAS obraty IN 0
	ENDIF
	IF !USED("doklady")
		SELECT 0
		USE (m.fn_doklady) ALIAS doklady ORDER c_dokl
	ELSE
		SELECT doklady
		SET ORDER TO c_dokl
	ENDIF

	* Test na viacnasobny vyskyt operacie "PR" na jednom stredisku a karte
	SELECT DISTINCT c_karty,c_stredisk, COUNT(c_dokl) AS pocet FROM obraty GROUP BY c_karty,c_stredisk WHERE operace="PR" HAVING pocet>1 INTO CURSOR viacpr
	IF RECCOUNT()>0
		SCAN
			m.viacprck=viacpr.c_karty
			m.viacprcs=viacpr.c_stredisk
			SELECT MIN(c_dokl) AS c_dokl FROM obraty WHERE c_stredisk=m.viacprcs .AND. c_karty=m.viacprck .AND. operace="PR" INTO CURSOR viacprcd
			IF RECCOUNT()>0
				m.viacprcd=viacprcd.c_dokl
				SELECT obraty
				DELETE FOR c_dokl<>m.viacprcd .AND. c_stredisk=m.viacprcs .AND. c_karty=m.viacprck .AND. operace="PR"
			ENDIF
			USE IN viacprcd
			SELECT viacpr
		ENDSCAN
	ENDIF
	USE IN viacpr
	* Test na viacnasobny vyskyt operacie "PR" na jednom stredisku a karte

	SELECT doklady
	IF m.slovenskaverzia
		REPLACE pz2 WITH "" FOR operace = "VV" .AND. pz2=m.semafor_id
        IF BITAND(VAL(OS(10)), 16) # 0
			REPLACE pz2 WITH "" FOR operace = "VV" .AND. ! EMPTY(pz2) .AND. VAL(pz2) = 0 .AND. LEFT(pz2,2) # "--" .AND. (kdy + 24*3600*4) < DATETIME()
		ENDIF
		SELECT 0
		USE (m.fn_uzav) ALIAS uzav
		SELECT DISTINCT c_dokl, operace,c_stredisk FROM obraty INTO CURSOR aaa READWRITE WHERE !(c_dokl IN (SELECT c_dokl FROM doklady))

		IF RECCOUNT()>0
			SCAN ALL
				m.cs=aaa.c_stredisk
				m.cd=aaa.c_dokl
				m.qq=m.giakt_mena
				SELECT uzav
				LOCATE FOR c_stredisk=m.cs .AND. c_doklod<=m.cd .AND. c_dokldo>=m.cd
				IF FOUND()
					FOR m.xx=1 TO ALEN(en_meny,1)
						IF (uzav.rok+uzav.mesiac)<=en__meny(m.xx,4)
							m.qq=m.xx
							EXIT
						ENDIF
					ENDFOR
				ENDIF
				INSERT INTO doklady (c_stredisk, operace, c_dokl,c_mena) VALUES (aaa.c_stredisk, aaa.operace,aaa.c_dokl,m.qq)
				SELECT aaa
			ENDSCAN
			*			ENDIF
		ENDIF
		DO pozavirej WITH "doklady, obraty, uzav, aaa"
	ELSE
		REPLACE pz2 WITH "" FOR operace = "VV" .AND. pz2=m.semafor_id
        IF BITAND(VAL(OS(10)), 16) # 0
			REPLACE pz2 WITH "" FOR operace = "VV" .AND. ! EMPTY(pz2) .AND. VAL(pz2) = 0 .AND. LEFT(pz2,2) # "--" .AND. (kdy + 24*3600*4) < DATETIME()
		ENDIF
		SELECT DISTINCT c_dokl, operace,c_stredisk FROM (m.fn_obraty) ;
			WHERE c_dokl NOT IN (SELECT c_dokl FROM (m.fn_doklady)) ;
			INTO TABLE (m.gcpri_path + "obr_parchanti")
		INSERT INTO doklady (c_stredisk, operace, c_dokl,c_mena) ;
			SELECT c_stredisk, operace, c_dokl, m.giakt_mena FROM (m.gcpri_path + "obr_parchanti")
		SELECT doklady
		REPLACE c_mena WITH 1 FOR EMPTY(c_mena)
		DO pozavirej WITH "doklady, obraty, obr_parchanti"

	ENDIF
ENDIF 

SELECT 0
USE (m.fn_sk_sez) ALIAS sez
REPLACE c_mena WITH m.giakt_mena FOR EMPTY(c_mena)
USE


*******************************************
had.INCREMENT("obra_a")
IF f_acc_ex(m.fn_obra_a)
    INDEX ON idriadok TAG idriadok
	SELECT operace, idriadok FROM obra_a INTO CURSOR minoperace WHERE c_dokl IN (SELECT MIN(c_dokl) AS c_dokl FROM obra_a GROUP BY c_karty, c_stredisk WHERE INLIST(operace,"PR","_P"))
    had.INCREMENT("obra_a - scan")
	SCAN FOR operace="_P"
		SCATTER MEMVAR FIELDS idriadok
*        WAIT STR(idriadok, 12) WINDOW AT 22,22 NOWAIT 
		SELECT obra_a
		REPLACE operace WITH "PR" FOR idriadok=m.idriadok
		SELECT minoperace
	ENDSCAN 
    WAIT CLEAR 
	USE IN minoperace
	SELECT obra_a
	DO indexuj
ENDIF

IF FILE(m.gccen_path+"obra_buf.dbf")
	had.INCREMENT("obra_buf")
	IF f_acc_ex(m.gccen_path+"obra_buf.dbf")
		DO indexuj
	ENDIF
	DO pozavirej WITH "obra_buf"
ENDIF

*******************************************
had.INCREMENT("dluhy")
IF f_acc_ex(m.fn_dluhy)
	DELETE TAG ALL
	SET RELATION TO c_karty INTO karty
	DELETE FOR EMPTY(karty.c_karty)
	SET RELATION TO
	DELETE FOR c_dokl < dluh_c_dokl
	DO indexuj
ENDIF

*******************************************
had.INCREMENT("partneri")
IF f_acc_ex(m.fn_partneri)

	SELE 0
	USE (m.gcpri_path + "strediska") ORDER ID
	SCAN
        SCATT FIELD c_stredisk, id_zkratka, stredskup, zadan_prn, a1 MEMVAR
        SELE partneri
        LOCATE FOR c_partner = m.c_stredisk
        IF FOUND()
             REPLACE partner WITH m.id_zkratka
        ELSE
             INSERT INTO (m.fn_partneri) (c_partner, partner, ico, dic, cen_hlad) VALUES (m.c_stredisk, m.id_zkratka, m.stredskup, m.zadan_prn, m.a1)
        ENDIF
        SELECT strediska
	ENDSCAN
	SELE partneri
	DO indexuj
	SET ORDER TO c_partner
	GO BOTTOM 
	IF ! EOF()
		max_c_partner = partneri.c_partner
	ENDIF
ENDIF

*******************************************
had.INCREMENT("polozky")
IF f_acc_ex(m.fn_polozky)
	DELETE TAG ALL
	DELETE FOR hruba = 0 .OR. c_poloz = c_karty
	SET RELATION TO c_poloz INTO karty
	DELETE FOR EMPTY(karty.c_karty)

	SET RELATION TO c_karty INTO karty
	DELETE FOR EMPTY(karty.c_karty) .or. EMPTY(karty.c_druhk)
	REPLACE ALL pocet WITH karty.pocet
	SET RELATION TO
	DO indexuj
ENDIF

*******************************************
had.INCREMENT("sklad")
IF !("_buf"$LOWER(m.fn_obraty))
	IF f_acc_ex(m.fn_sklad)
		DELETE TAG ALL
		SET RELATION TO c_karty INTO karty
		DELETE FOR EMPTY(karty.c_karty)
		DELETE FOR karty.nazev1 = m.smazana_karta .AND. zustatek = 0
		REPLACE FOR zustatek = 0 cena_prum WITH karty.cena_prum
		SET RELATION TO
		REPLACE FOR EMPTY(c_mena) c_mena WITH m.giakt_mena
		DO indexuj
	ENDIF
ENDIF 

*******************************************
had.INCREMENT("umisteni")
IF f_acc_ex(m.fn_umisteni)
	DELETE TAG ALL
	SET RELATION TO c_karty INTO karty
	DELETE FOR EMPTY(karty.c_karty)
	DELETE FOR karty.nazev1 = m.smazana_karta
	REPLACE ALL nazev WITH karty.nazev
	SET RELATION TO
	DO indexuj
ENDIF

*******************************************
had.INCREMENT("users")
IF f_acc_ex(m.fn_users)
	DELETE TAG ALL
	DO indexuj
        SET ORDER TO user_id
	o_user_id = "!@#"
	SCAN
		IF user_id = m.o_user_id
			DELE
		ENDIF
		o_user_id = user_id
	ENDSCAN
	PACK
	LOCATE FOR user_id = "SUP"
	IF ! FOUND()
		INSERT INTO (m.fn_users) (heslo, username, user_id, jazyk) VALUE ("gm}ughSP*NaV", "ALTO Supervisor", "SUP", "0")
	ENDIF
	LOCATE FOR user_id = "ADM"
	IF ! FOUND()
		INSERT INTO (m.fn_users) (heslo, username, user_id, jazyk) VALUE ("xxxxxxxxxxxx",  "ADMINISTRATOR",   "ADM", "0")
	ENDIF
ENDIF

had.INCREMENT("umdruhy")
IF f_acc_ex(m.fn_umdruhy)
	DELETE TAG ALL
	SELECT skupiny
	SET ORDER TO druh
	SELECT  umdruhy
	SET RELATION TO druh INTO skupiny
	DELETE FOR EMPTY(skupiny.druh)
	SET RELATION OFF INTO skupiny
	DO indexuj
	USE IN umdruhy
	USE IN skupiny
ENDIF

had.INCREMENT("spdan")
IF f_acc_ex(m.fn_spotrebnadan)
	DELETE TAG ALL
	DO indexuj
	USE IN spdan
ENDIF

had.INCREMENT("eany")
IF f_acc_ex(m.fn_eany)
	DELETE TAG ALL
	DELETE FROM eany WHERE !(c_karty IN (SELECT c_karty FROM karty))
	DELETE FROM eany WHERE c_karty IN (SELECT c_karty FROM karty WHERE karty.nazev1==m.smazana_karta)
*!*		SET RELATION TO c_karty INTO karty
*!*		DELETE FOR EMPTY(karty.c_karty)
*!*		DELETE FOR karty.nazev1 = m.smazana_karta
*!*		SET RELATION TO
	DO indexuj
ENDIF

had.INCREMENT("edi_pol")
IF f_acc_ex(m.fn_edipol)
	DO indexuj
ENDIF
had.INCREMENT("edi_hlav")
IF f_acc_ex(m.fn_edihlav)
	DO indexuj
ENDIF
had.INCREMENT("cas_hlav")
IF f_acc_ex(m.fn_cas_hlav)
	DO indexuj
ENDIF
had.INCREMENT("cas_pol")
IF f_acc_ex(m.fn_cas_pol)
	DO indexuj
ENDIF
had.INCREMENT("hh_hlav")
IF f_acc_ex(m.fn_hh_hlav)
	DO indexuj
ENDIF
had.INCREMENT("hh_druh")
IF f_acc_ex(m.fn_hh_druhy)
	DO indexuj
ENDIF
had.INCREMENT("hh_kalk")
IF f_acc_ex(m.fn_hh_kalky)
	DO indexuj
ENDIF
had.INCREMENT("buff_d")
IF f_acc_ex(m.fn_buff_d)
	DELETE FOR EMPTY(odlozene)
	PACK 
	SELECT DISTINCT menobuf FROM buff_d INTO CURSOR menabuf
	IF USED("menabuf") 
		IF RECCOUNT("menabuf")>0
			INDEX on menobuf TAG menobuf
		ELSE
			USE IN menabuf
		ENDIF 
	ENDIF 
	SELECT buff_d
	DO indexuj
ENDIF
had.INCREMENT("buff_r")
IF f_acc_ex(m.fn_buff_r)
	IF USED("menabuf")
		SET RELATION TO menobuf INTO menabuf
		DELETE for EMPTY(menabuf.menobuf)
		SET RELATION OFF INTO menabuf
		USE IN menabuf
	ENDIF 
	PACK 
	DO indexuj
ENDIF

IF USED("skupiny")
	USE IN skupiny
ENDIF

*******************************************
IF f_acc_ex(m.gchom_path + "maxima")

	IF m.max_c_karty > 0
		LOCATE FOR soubor = "karty"
		IF FOUND()
			IF m.max_c_karty> maxima.i_max
				REPLACE i_max WITH max_c_karty + 1
			ENDIF 
		ELSE
			INSERT INTO (m.gchom_path + "maxima") (soubor, i_max) VALUES ("karty", max_c_karty + 1)
		ENDIF
	ENDIF

	IF m.max_c_druh > 0
		LOCATE FOR soubor = "c_druh"
		IF FOUND()
			IF m.max_c_druh> maxima.i_max
				REPLACE i_max WITH max_c_druh + 1
			ENDIF 
		ELSE
			INSERT INTO (m.gchom_path + "maxima") (soubor, i_max) VALUES ("c_druh", max_c_druh + 1)
		ENDIF
	ENDIF

	IF m.max_c_partner > 0
		LOCATE FOR soubor = "c_partner"
		IF FOUND()
			IF m.max_c_partner> maxima.i_max
				REPLACE i_max WITH max_c_partner + 1
			ENDIF 
		ELSE
			INSERT INTO (m.gchom_path + "maxima") (soubor, i_max) VALUES ("c_partner", max_c_partner + 1)
		ENDIF
	ENDIF

	IF m.max_c_dokl > 0
		LOCATE FOR soubor = "c_dokl"
		IF FOUND()
			IF m.max_c_dokl >= maxima.i_max
				REPLACE i_max WITH m.max_c_dokl + 10
			ENDIF

			IF m.max_c_dokl < maxima.i_max - 50
				DO zurnal_log WITH "OPERA", "INDEXY-MAXIMA", "maxima:" + ALLTRIM(STR(maxima.i_max)) + ", doklady:" + ALLTRIM(STR(m.max_c_dokl))
			ENDIF

		ELSE
			INSERT INTO (m.gchom_path + "maxima") (soubor, i_max) VALUES ("c_dokl", max_c_dokl + 1)
		ENDIF
	ENDIF

ENDIF

*******************************************
had.INCREMENT("doklady+obraty")
DO clos_data
IF "_buf"$LOWER(m.fn_obraty)
	IF f_acc(m.fn_obraty) .AND. f_acc(m.fn_doklady)
		SELECT obra_buf
		SET ORDE TO c_dokl
		SELECT dokl_buf
		SET FILTER TO operace = "VV" .AND. EMPTY(pz2)
		SET RELATION TO c_dokl INTO obra_buf
		REPLACE FOR EMPTY(obra_buf.c_dokl) pz2 WITH "--neprijimat--"
		DO clos_data
	ENDIF
ELSE
	IF f_acc(m.fn_obraty) .AND. f_acc(m.fn_doklady)
		SELECT obraty
		SET ORDE TO c_dokl
		SELECT doklady
		SET FILTER TO operace = "VV" .AND. EMPTY(pz2)
		SET RELATION TO c_dokl INTO obraty
		REPLACE FOR EMPTY(obraty.c_dokl) pz2 WITH "--neprijimat--"
		DO clos_data
	ENDIF
ENDIF 
*******************************************
had.INCREMENT("errors")
IF f_acc_ex(m.gchom_path + "errors")
	GO TOP
	IF cas < DATE() - 266
		DELETE FOR cas < DATE() - 222
		PACK
	ENDIF
ENDIF

*******************************************
had.INCREMENT("err_log")
IF FILE(m.gchom_path + "err_log.dbf")
	IF f_acc_ex(m.gchom_path + "err_log")
		COUNT ALL TO pocet_radku
		GO TOP
		DELETE NEXT (m.pocet_radku - 999)
		PACK
	ENDIF
ENDIF

*******************************************
had.INCREMENT("food_log")
IF FILE(m.gchom_path + "food_log.dbf")
	IF f_acc_ex(m.gchom_path + "food_log")
		DELETE FOR BETWEEN(cas, "20000000", DTOS(DATE()-222))
		PACK
	ENDIF
ENDIF

*******************************************
had.INCREMENT("inv_uloz")
IF FILE(m.gcdat_path + "inv_uloz.dbf")
	IF f_acc_ex(m.gcdat_path + "inv_uloz.dbf")
		DELETE FOR (kdy < DATE() - 222) .OR. ;
			((kdy < DATE() - 111) .AND. mnozstvi = na_sklade)
		PACK
	ENDIF
ENDIF


*******************************************
had.INCREMENT("vahinv")
IF FILE(m.gcdat_path + "vahinv.dbf")
    IF f_acc_ex(m.gcdat_path + "vahinv.dbf")
        DELETE FOR (uzaverka < SUBSTR(TTOC(DATE() - 222, 1), 3, 6))      && odmaze stare vazene inventury
        PACK
    ENDIF
ENDIF


*******************************************
had.INCREMENT("kursy")
IF FILE(m.gchom_path + "kursy.dbf")
	IF f_acc_ex(m.gchom_path + "kursy")
		DO indexuj
	ENDIF
ENDIF

*******************************************
had.INCREMENT("uvery")
IF FILE(m.gccen_path + "uvery.dbf")
	IF f_acc_ex(m.gccen_path + "uvery")
		DO indexuj
	ENDIF
ENDIF

*******************************************
IF FILE(m.gchom_path+"z_horca.dbf")
	had.INCREMENT("z_horca")
	IF f_acc_ex(m.gchom_path+"z_horca.dbf")
		DELETE TAG ALL
		DO indexuj
	ENDIF
ENDIF 

*******************************************
IF FILE(m.gcdat_path + "archivace_zaloha.dbf")
    had.INCREMENT("archivace_zaloha")
    IF f_acc_ex(m.gcdat_path + "archivace_zaloha")
        DELETE FOR provedeno < (DATE() - 333)
        PACK
    ENDIF
ENDIF

DO clos_data
SET COLLATE TO m.gccollate
RELEASE had



*******************************************
*******************************************
PROCEDURE max_maxima
IF m.issql
	m.vysledok=sql_exec("SELECT food600.max_maxima()")
ELSE 
	DO clos_data

	IF f_acc_ex(m.gchom_path + "maxima")
		TRY 
			SELECT MAX(c_karty) AS i_max FROM (m.fn_karty) INTO CURSOR max_c
			SCATTER FIELD i_max MEMVAR
			SELECT maxima
			LOCATE FOR soubor = "karty"
			IF FOUND()
				IF m.i_max >= maxima.i_max
					REPLACE i_max WITH m.i_max + 1
				ENDIF
			ENDIF
		CATCH
		ENDTRY 
		DO pozavirej WITH "karty, max_c"
		TRY 
			SELECT MAX(c_partner) AS i_max FROM (m.fn_partneri) INTO CURSOR max_c
			SCATTER FIELD i_max MEMVAR
			SELECT maxima
			LOCATE FOR soubor = "c_partner"
			IF FOUND()
				IF m.i_max >= maxima.i_max
					REPLACE i_max WITH m.i_max + 1
				ENDIF
			ENDIF
		CATCH
		ENDTRY 
		DO pozavirej WITH "partneri, max_c"
		TRY 
			SELECT MAX(c_dokl) AS i_max FROM (m.fn_doklady) INTO CURSOR max_c
			SCATTER FIELD i_max MEMVAR
			SELECT maxima
			LOCATE FOR soubor = "c_dokl"

			IF FOUND()
				IF m.i_max >= maxima.i_max
					REPLACE i_max WITH m.i_max + 10
				ENDIF
				IF m.i_max < maxima.i_max - 50
					DO zurnal_log WITH "OPERA", "INDEXY-MAX-MAXIMA", "maxima:" + ALLTRIM(STR(maxima.i_max)) + ", doklady:" + ALLTRIM(STR(m.i_max))
				ENDIF
			ENDIF
		CATCH
		ENDTRY 
		DO pozavirej WITH "doklady,c_max"
	ENDIF
	DO clos_data
ENDIF 

*******************************************
*******************************************
PROCEDURE index_sk
PARAMETERS pripona
had = CREATEOBJECT("had", jaz("prg_reindexace") + " SK" )
had.SHOW()
had.set_max(20)
DO clos_data

SET COLLATE TO "machine"

IF f_acc_ex(m.gccen_path + "sk_sez" + pripona)
	had.INCREMENT(DBF())
	DO indexuj
ENDIF



IF f_acc_ex(m.fn_karty)
    SET ORDER TO nazev
ENDIF 

SELECT 0
IF f_acc_ex(m.gccen_path + "sk_pol" + pripona)
	had.INCREMENT(DBF())

    IF FSIZE("nazev") # 0 AND USED("karty")
        SET RELATION TO nazev INTO karty
        REPLACE FOR EMPTY(c_karty) c_karty WITH karty.c_karty
        USE IN karty
    ENDIF 

	DO indexuj
ENDIF

IF !m.slovenskaverzia
	IF FILE(m.gccen_path + "_tmskpol.dbf")
		IF f_acc_ex(m.gccen_path + "_tmskpol")
			had.INCREMENT(DBF())
			DO indexuj
		ENDIF
	ENDIF
ENDIF

IF f_acc_ex(m.gccen_path + "sk_plt" + pripona)
	had.INCREMENT(DBF())
	DO indexuj
ENDIF
IF !m.slovenskaverzia
	IF FILE(m.gccen_path + "_tmskplt.dbf")
		IF f_acc_ex(m.gccen_path + "_tmskplt")
			had.INCREMENT(DBF())
			DO indexuj
		ENDIF
	ENDIF
ENDIF

IF f_acc_ex(m.gccen_path + "sk_fin" + pripona)
	had.INCREMENT(DBF())
	DO indexuj
ENDIF
IF !m.slovenskaverzia
	IF FILE(m.gccen_path + "_tmskfin.dbf")
		IF f_acc_ex(m.gccen_path + "_tmskfin")
			had.INCREMENT(DBF())
			DO indexuj
		ENDIF
	ENDIF
ELSE
	IF f_acc_ex(m.gccen_path + "sk_fis" + pripona)
		had.INCREMENT(DBF())
		DO indexuj
	ENDIF
	IF f_acc_ex(m.gccen_path + "sk_vklvy" + pripona)
		had.INCREMENT(DBF())
		DO indexuj
	ENDIF
ENDIF

IF f_acc_ex(m.gccen_path + "sk_txt" + pripona)
	had.INCREMENT(DBF())
	DO indexuj
ENDIF
IF !m.slovenskaverzia
	IF FILE(m.gccen_path + "_tmsktxt.dbf")
		IF f_acc_ex(m.gccen_path + "_tmsktxt")
			had.INCREMENT(DBF())
			DO indexuj
		ENDIF
	ENDIF
ENDIF

RELEASE had
DO clos_data

*******************************************
*******************************************
PROC indexuj
WAIT jaz("prg_indexy_prg_indexing")+" " + DBF() WINDOW AT 22, 22 TIME .2
WAIT jaz("prg_indexy_prg_indexing")+" " + DBF() WINDOW AT 22, 22 NOWA
indexovano = .T.
DO CASE
	CASE "uexarchobraty" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok

	CASE "uexarchpolozky" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok

	CASE "uexarchplatby" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok

	CASE "skupiny" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO "machine"
		INDEX ON spart     TAG spart
		INDEX ON druh      TAG druh
		INDEX ON typ_skup  TAG typ_skup
		INDEX ON typ_kalk  TAG typ_kalk
		INDEX ON typ_skl   TAG typ_skl
		INDEX ON c_druh TAG c_druh

	CASE "vypocty" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO "machine"
		INDEX ON c_druh TAG c_druh
		INDEX ON idriadok TAG idriadok

	CASE "uvery" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON hjmeno TAG hjmeno

	CASE "z_horca" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON kod TAG kod

	CASE "uzaver" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON rok+mesiac     TAG kedy
		INDEX ON idriadok TAG idriadok

	CASE "limit_hl" $ LOWER( DBF() ) .or. "limhl_a"$ LOWER( DBF() ) 
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON limit TAG limit
		INDEX ON id_limit TAG id_limit
		INDEX ON idriadok TAG idriadok

        CASE "nlimity" $ LOWER( DBF() )
	      	DELETE TAG ALL
	        PACK
        	SET COLLATE TO m.gccollate
	        INDEX ON id_limit TAG id_limit
        	INDEX ON idriadok TAG idriadok

	CASE "limity" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON poradie TAG poradie
		INDEX ON idriadok TAG idriadok

	CASE "limitdni" $ LOWER( DBF() ) .or. "limdni_a"$ LOWER( DBF() ) 
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON datum TAG datum
		INDEX ON idriadok TAG idriadok

	CASE "bourak" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON nazev    TAG nazev
		INDEX ON c_karty  TAG c_karty
		INDEX ON c_karty2 TAG c_karty2
		INDEX ON idriadok TAG idriadok

	CASE "davky" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		REPLACE FOR EMPTY(c_mena) c_mena WITH m.giakt_mena
		SET COLLATE TO m.gccollate
		INDEX ON c_stredisk TAG c_stredisk
		INDEX ON davka      TAG davka
		INDEX ON idriadok TAG idriadok

    CASE "davk_hl" $ LOWER( DBF() )
        DELETE TAG ALL
        DELETE FOR EMPTY(davka)
        PACK
        SET COLLATE TO m.gccollate
        INDEX ON c_stredisk TAG c_stredisk
        INDEX ON davka      TAG davka
        INDEX ON idriadok TAG idriadok

	CASE "dluhy" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON c_stredisk TAG c_stredisk
		INDEX ON c_dokl     TAG c_dokl
		INDEX ON idriadok TAG idriadok

	CASE "dokl" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON c_dokl TAG c_dokl
		INDEX ON idriadok TAG idriadok
		REPLACE FOR datum_dokl < {^1990-01-01} datum_dokl WITH TTOD(kdy)
		REPLACE FOR datum_dokl < {^1990-01-01} datum_dokl WITH {^1990-01-01}
		REPLACE FOR pz2 = "__REZERVOVANO__" .AND. datum_dokl > DATE() - 99  pz2 WITH ""
		REPLACE pz2 WITH "" FOR operace = "VV" .AND. ! EMPTY(pz2) .AND. VAL(pz2) = 0 .AND. LEFT(pz2,2) # "--"

	CASE "obra" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON c_karty           TAG c_karty
		INDEX ON c_dokl            TAG c_dokl
		INDEX ON c_stredisk        TAG c_stredisk
		INDEX ON STR(c_dokl, 12) + STR(poradi, 12) + STR(SIGN(mnozstvi)+3, 1) TAG dok_por_mn
		INDEX ON idriadok TAG idriadok

	CASE "polozky" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON c_poloz TAG c_poloz
		INDEX ON c_karty TAG c_karty
		INDEX ON idriadok TAG idriadok

	CASE "sklad" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON c_karty    TAG c_karty
		INDEX ON c_stredisk TAG c_stredisk
		INDEX ON idriadok TAG idriadok
*		INDEX ON STR(c_stredisk,12)+STR(c_karty,12) TAG cstrck

	CASE "umisteni" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON c_karty   TAG c_karty
		INDEX ON nazev     TAG nazev
		INDEX ON id_kas    TAG id_kas
		INDEX ON druh_kalk TAG druh_kalk
		INDEX ON idriadok TAG idriadok

	CASE "umdruhy" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON id_kas	TAG id_kas
		INDEX ON druh	TAG druh
		INDEX ON idriadok TAG idriadok

	CASE "spdan" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON c_karty TAG c_karty
		INDEX ON idriadok TAG idriadok

	CASE "eany" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON c_karty			TAG c_karty
		INDEX ON ALLTRIM(ean)	TAG ean
		INDEX ON idriadok TAG idriadok

	CASE "sortiment_dodavatelu" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON ALLTRIM(ean)	TAG ean
		INDEX ON idriadok TAG idriadok

	CASE "partneri" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO m.gccollate
		INDEX ON partner   TAG partner
		SET COLLATE TO "machine"
		INDEX ON c_partner TAG c_partner
		INDEX ON idriadok TAG idriadok

	CASE "kkarty" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO "machine"
		INDEX ON kod       TAG kod
		INDEX ON c_karty   TAG c_karty
		SET COLLATE TO m.gccollate
		INDEX ON c_druhk   TAG c_druhk
		INDEX ON c_druh    TAG c_druh
		INDEX ON c_druhs   TAG c_druhs
		INDEX ON nazev     TAG nazev
		INDEX ON idriadok  TAG idriadok

	CASE "kceny" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON c_karty   TAG c_karty
		INDEX ON idriadok  TAG idriadok

	CASE "ktexty" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON c_karty   TAG c_karty
		INDEX ON idriadok  TAG idriadok

        SELECT c_karty FROM (m.fn_karty) WHERE c_karty NOT IN (SELECT c_karty FROM (m.fn_ktexty)) INTO CURSOR kkkk
        INSERT INTO ktexty (c_karty) SELECT c_karty FROM kkkk
        SET ORDER TO C_KARTY IN karty
        SELECT ktexty
        SET RELATION TO c_karty INTO karty
        REPLACE FOR EMPTY(meno1) meno1 WITH karty.nazev
        REPLACE FOR EMPTY(meno2) meno2 WITH karty.nazev

	CASE "krest" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON c_karty   TAG c_karty
		INDEX ON idriadok  TAG idriadok

        SELECT c_karty FROM (m.fn_karty) WHERE c_karty NOT IN (SELECT c_karty FROM (m.fn_krest)) INTO CURSOR kkkk
        INSERT INTO krest (c_karty) SELECT c_karty FROM kkkk

	CASE "ktried" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON c_karty   TAG c_karty
		INDEX ON idriadok  TAG idriadok

	CASE "tried" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON c_tr   TAG c_tr
		INDEX ON idriadok  TAG idriadok

	CASE "karty" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO "machine"
*		INDEX ON kod       TAG kod
		INDEX ON c_karty   TAG c_karty
		SET COLLATE TO m.gccollate
		INDEX ON druh_kalk TAG druh_kalk
*		INDEX ON druh      TAG druh
*		INDEX ON druh_skl  TAG druh_skl
*		INDEX ON c_druhk   TAG c_druhk
*		INDEX ON c_druh    TAG c_druh
*		INDEX ON c_druhs   TAG c_druhs
		INDEX ON nazev     TAG nazev
		INDEX ON nazev1    TAG nazev1
		INDEX ON idriadok  TAG idriadok

	CASE "sk_txt" $ LOWER( DBF() ) .OR. "tmsktxt" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON u_cis + TRAN(poradi, "@L 99") TAG u_cispor
		INDEX ON u_cis TAG u_cis
		INDEX ON uzaverka TAG uzaverka
		*** L.L Doplnene indexy, kvoli stornam starych uctov
		INDEX ON u_cis+uzaverka TAG uzuc
		INDEX ON uzaverka+u_cis+STR(poradi,2,0) TAG uzcispor
		INDEX ON idriadok TAG idriadok

	CASE "sk_fin" $ LOWER( DBF() ) .OR. "tmskfin" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON id_kas TAG id_kas
		INDEX ON u_cis TAG u_cis
        TRY
		INDEX ON AUTOR + uzcis TAG uzcis
        CATCH
        ENDTRY
		INDEX ON uzaverka TAG uzaverka
		*** L.L Doplnene indexy, kvoli stornam starych uctov
		INDEX ON u_cis+uzaverka TAG uzuc
		INDEX ON idriadok TAG idriadok

	CASE "sk_plt" $ LOWER( DBF() ) .OR. "tmskplt" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON u_cis TAG u_cis
		INDEX ON uzaverka TAG uzaverka
		*** L.L Doplnene indexy, kvoli stornam starych uctov
		INDEX ON u_cis+uzaverka TAG uzuc
		INDEX ON idriadok TAG idriadok

	CASE "sk_pol" $ LOWER( DBF() ) .OR. "tmskpol" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		REPLACE FOR dan = 0 dan WITH 1
        TRY
		    INDEX ON nazev TAG nazev
        CATCH
        ENDTRY
		INDEX ON id_man TAG id_man
		INDEX ON id_kas TAG id_kas
		INDEX ON uzaverka TAG uzaverka
		INDEX ON u_cis TAG u_cis
		*** L.L Doplnene indexy, kvoli stornam starych uctov
		INDEX ON u_cis+uzaverka TAG uzuc
		INDEX ON idriadok TAG idriadok

	CASE "sk_sez" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON uzaverka TAG uzaverka
		INDEX ON idriadok TAG idriadok

	CASE "klapky" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON vazba                                                TAG vazba
		INDEX ON nazev                                                TAG nazev
		INDEX ON TRANSFORM(strana,"@l 999")+TRANSFORM(pozice,"@l 99") TAG strpoz
		INDEX ON pozice                                               TAG PAGE

	CASE "hras_set" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON druh TAG druh

	CASE "uc_pol" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON STR(stul,6,1)                                           TAG u_cisstul
		INDEX ON STR(stul,6,1)+STR(delitel,1,0)+nazev+cena+id_man+cisnik TAG stul_na_de
		INDEX ON kolik                                                   TAG kolik

	CASE "uc_subt" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON u_cis TAG u_cis

	CASE "food_dat" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO "machine"
		INDEX ON ID TAG ID

	CASE "users" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO "machine"
		INDEX ON user_id TAG user_id
		INDEX ON idriadok TAG idriadok

	CASE "kursy" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		SET COLLATE TO "machine"
		INDEX ON mena TAG mena
	CASE "cas_hlav" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
		INDEX ON id_hlav TAG id_hlav
	CASE "cas_pol" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
		INDEX ON id_hlav TAG id_hlav
	CASE "hh_hlav" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
	CASE "hh_druhy" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
		INDEX ON id_hh_hlav TAG id_hlav
	CASE "hh_kalky" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
		INDEX ON id_hh_hlav TAG id_hlav
	CASE "obr_alk" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
		INDEX ON c_karty TAG c_karty
	CASE "buff_d" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		ALTER table buff_d alter COLUMN idriadok INTEGER 
		REPLACE ALL idriadok WITH RECNO()
		ALTER table buff_d alter COLUMN idriadok INTEGER AUTOINC NEXTVALUE RECCOUNT("buff_d")+1
		INDEX ON idriadok TAG idriadok
		INDEX ON menobuf TAG menobuf
	CASE "buff_r" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		ALTER table buff_r alter COLUMN idriadok INTEGER 
		REPLACE ALL idriadok WITH RECNO()
		ALTER table buff_r alter COLUMN idriadok INTEGER AUTOINC NEXTVALUE RECCOUNT("buff_r")+1
		INDEX ON idriadok TAG idriadok
		INDEX ON menobuf TAG menobuf
	CASE "sk_vklvy" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
	CASE "sk_fis" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON id_kas TAG id_kas
		INDEX ON u_cis TAG u_cis
		INDEX ON uzaverka TAG uzaverka
		INDEX ON u_cis+uzaverka TAG uzuc
		INDEX ON idriadok TAG idriadok
	CASE "edi_pol" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
	CASE "edi_hlav" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
	CASE "listovanie" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
	CASE "tried" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
	CASE "ktried" $ LOWER( DBF() )
		DELETE TAG ALL
		PACK
		INDEX ON idriadok TAG idriadok
	OTHERWISE 
		*PACK
		WAIT jaz("prg_indexy_prg_neviem_index")+" " + DBF() WINDOW AT 22, 22 TIME 1
		indexovano = .F.
ENDCASE

SET COLLATE TO m.gccollate
WAIT CLEAR
RETURN indexovano



*******************************************
PROCEDURE vypln_ean_pro_mtz
LOCAL m.hladajprefix, m.hladajprefixlen, m.ax_ean
IF  VARTYPE(auto_kodymtz)="L" AND m.auto_kodymtz

    m.hladajprefix   =     m.prefix_kodymtz
    m.hladajprefixlen= LEN(m.prefix_kodymtz)

    SELECT MAX(kod) as max_ean ;
           WHERE LEFT(kod, m.hladajprefixlen+1) = " " + m.hladajprefix ;
           FROM karty INTO CURSOR max_ean_kod READWRITE 
    IF RECCOUNT()>0
        m.max_ean=VAL(SUBSTR(max_ean_kod.max_ean, m.hladajprefixlen+1))
    ELSE 
        m.max_ean=0
    ENDIF 
	USE IN max_ean_kod
    SELECT karty
    SCAN FOR EMPTY(kod) .and. nazev1 # m.smazana_karta .and. EMPTY(c_druhk)
        max_ean = m.max_ean + 1
        REPLACE kod WITH " " + m.hladajprefix + PADL(ALLTRIM(STR(m.max_ean,12,0)), 12-m.hladajprefixlen,"0")
    ENDSCAN 
ENDIF 
