LOCAL m.oblast, m.stlpec, m.id_limit, m.id_den, m.id_rov, m.id_chod, m.c_kasy, m.hladina, m.cenobl, m.pocetriadkov, m.aktriadok
USE (m.gccen_path+"nlimitrov") IN 0
USE (m.gccen_path+"nlimity") IN 0
USE (m.gccen_path+"nlimitsablonypol") IN 0
USE (m.gccen_path+"karty") IN 0 ORDER c_karty
USE (m.gccen_path+"skupiny") IN 0 ORDER c_druh
USE (m.gchom_path+"food_dat") IN 0
*!*	USE ("m:\d_international\data\nlimitrov") IN 0
*!*	USE ("m:\d_international\data\nlimity") IN 0
*!*	USE ("m:\d_international\data\nlimitsablonypol") IN 0
*!*	USE ("m:\d_international\data\karty") IN 0 ORDER c_karty
*!*	USE ("m:\d_international\data\skupiny") IN 0 ORDER c_druh
*!*	USE ("m:\d_international\food_dat") IN 0
SELECT nlimity
SET RELATION TO c_karty INTO karty 
m.oblast="a"
IF DATE()>m.oblast_a
	m.oblast="a"
	IF DATE()>m.oblast_b
		m.oblast="b"
		IF DATE()>m.oblast_c
			m.oblast="c"
		ENDIF 
	ELSE
		IF DATE()>m.oblast_c
			m.oblast="c"
		ENDIF 
	ENDIF 
ELSE
	IF DATE()>m.oblast_b
		m.oblast="b"
		IF DATE()>m.oblast_c
			m.oblast="c"
		ENDIF 
	ELSE
		IF DATE()>m.oblast_c
			m.oblast="c"
		ENDIF 
	ENDIF 
ENDIF 

SELECT nlimitrov
COUNT TO pocetriadkov FOR EMPTY(uzaverka) AND EMPTY(u_cis)
had = CREATEOBJECT("had", "Limity")
had.set_max(RECCOUNT())
had.SHOW()
m.aktriadok=0
SCAN FOR EMPTY(uzaverka) AND EMPTY(u_cis)
	m.aktriadok=m.aktriadok+1
	had.INCREMENT(ALLTRIM(STR(m.aktriadok,10,0))+"/"+ALLTRIM(STR(m.pocetriadkov,10,0)))
	m.id_limit=nlimitrov.id_limit
	m.id_den=nlimitrov.id_den
	m.id_rov=nlimitrov.id_rov
	m.id_chod=nlimitrov.id_chod
	m.c_kasy=nlimitrov.c_kasy
	m.hladina=ALLTRIM(nlimitrov.hladina)
	IF m.hladina="N"
		m.cenobl=m.oblast+"1"
	ELSE
		m.cenobl=m.oblast+m.hladina
	ENDIF
	SELECT food_dat
	LOCATE FOR c_stredisk=m.c_kasy
	IF FOUND()
		m.stlpec="food_dat."+m.cenobl
	ELSE
		m.stlpec="food_dat."+m.oblast+"1" 
	ENDIF 
	m.stlpec="skupiny.dan"+EVALUATE(m.stlpec)
	SELECT nlimity
	SCAN FOR id_limit=m.id_limit AND id_den=m.id_den AND id_rov=m.id_rov AND id_chod=m.id_chod AND !EMPTY(karty.nazev)
		DO CASE 
			CASE karty.c_druhk<>0
				SELECT skupiny
				IF SEEK(karty.c_druhk)
					SELECT nlimity
					REPLACE dan WITH EVALUATE(m.stlpec)
				ENDIF 
			CASE karty.c_druh<>0
				SELECT skupiny
				IF SEEK(karty.c_druh)
					SELECT nlimity
					REPLACE dan WITH EVALUATE(m.stlpec)
				ENDIF 
			CASE karty.c_druhs<>0
				SELECT skupiny
				IF SEEK(karty.c_druhs)
					SELECT nlimity
					REPLACE dan WITH EVALUATE(m.stlpec)
				ENDIF 
		ENDCASE 
	ENDSCAN 
ENDSCAN 

SELECT nlimitsablonypol
SET RELATION TO c_karty INTO karty
SCAN FOR !EMPTY(karty.nazev)
	DO CASE 
		CASE karty.c_druhk<>0
			SELECT skupiny
			IF SEEK(karty.c_druhk)
				SELECT nlimitsablonypol
				REPLACE dan WITH skupiny.dan01
			ENDIF 
		CASE karty.c_druh<>0
			SELECT skupiny
			IF SEEK(karty.c_druh)
				SELECT nlimitsablonypol
				REPLACE dan WITH skupiny.dan01
			ENDIF 
		CASE karty.c_druhs<>0
			SELECT skupiny
			IF SEEK(karty.c_druhs)
				SELECT nlimitsablonypol
				REPLACE dan WITH skupiny.dan01
			ENDIF 
	ENDCASE 
ENDSCAN 
DO pozavirej WITH "food_dat, karty, skupiny, nlimity, nlimitrov, nlimitsablonypol"
