*!*****************************************************************************
*!      Procedure: ODP_VYROBA
*!*****************************************************************************
PARAMETERS hladajdavku, hladajdatumod, plan
PRIVATE cdokldo, hladajcstredisk, menobuffera, lic_dokl, hladajcdokl, natlac, ret
PRIVATE tlacpopis, hladajdatumod, hladajdatumdo
LOCAL uroven
ret=.T.
menobuffera=LOWER(SUBSTR(SYS(2015),4))
hladajcstredisk=m.gic_stredisk
natlac=""

SELECT SPACE(30) AS zostava, .F. AS lbl, 00 AS riadok  FROM buf_dav INTO CURSOR selzost READWRITE WHERE .F.
IF !m.plan
	*	INSERT INTO selzost (zostava, riadok) VALUES (jaz("Výroba podľa poradia")         , 1)
	INSERT INTO selzost (zostava, riadok) VALUES (jaz("Výroba podľa zadania")         , 2)
	INSERT INTO selzost (zostava, riadok) VALUES (jaz("Potreba surovín po druhoch")   , 3)
	INSERT INTO selzost (zostava, riadok) VALUES (jaz("Potreba surovín abecedne")     , 4)
	INSERT INTO selzost (zostava, riadok) VALUES (jaz("D4 podľa poradia")             , 5)
	INSERT INTO selzost (zostava, riadok) VALUES (jaz("D4 podľa zadania")             , 6)
	IF .NOT. m.slovenskaverzia
		INSERT INTO selzost (zostava, riadok) VALUES ("D4 pizza"                      , 7)
		INSERT INTO selzost (zostava, riadok) VALUES ("Vyr.postupy"                   , 8)
	ENDIF
ENDIF
INSERT INTO selzost (zostava, riadok) VALUES (jaz("Zostava pre kuchára")              ,10)
INSERT INTO selzost (zostava, riadok) VALUES (jaz("Zostava pre kuchára podľa poradia"),11)
INSERT INTO selzost (zostava, riadok) VALUES (jaz("Zostava pre skladníka")            ,12)
INSERT INTO selzost (zostava, riadok) VALUES (jaz("Vyroba+potreba surovin")           ,13)
DO FORM selpartn WITH "selzost","zostava"

SELECT selzost
SCAN FOR !EMPTY(lbl)
	natlac = m.natlac + TRANSFORM(riadok, "@L 99") + ","
ENDSCAN
USE IN selzost
SET ASSERTS ON
ASSERT .f.
IF !EMPTY(m.natlac)
	IF "01,"$m.natlac .OR. "02,"$m.natlac .OR. "03,"$m.natlac .OR. "04,"$m.natlac .OR. "05,"$m.natlac .OR. "06,"$m.natlac .OR. "07,"$m.natlac .OR. "08,"$m.natlac .OR. "13,"$m.natlac
		IF m.issql
			DO odp_vyr_sql
		ELSE
			IF "01,"$m.natlac .OR. "02,"$m.natlac .OR. "03,"$m.natlac .OR. "04," $ m.natlac .OR. "08," $ m.natlac .OR. "13,"$m.natlac .OR. (VARTYPE(m.prava_na_druhy)=="L" AND m.prava_na_druhy AND !m.glis_admin)
				odpocet_vyroba()
				IF "01,"$m.natlac AND m.ret
					INDEX ON STR(poradi,10,0)+nazev TAG pornaz
					DO pr_report WITH "vyroba1"
				ENDIF

				IF "02,"$m.natlac AND m.ret
					INDEX ON naz_rec + nazev TAG naznaz
					DO pr_report WITH "vyroba1"
				ENDIF

				IF "03,"$m.natlac AND m.ret     && po druzich
					SELECT c_karty, druh AS naz_rec, nazev, SUM(mnozstvi) AS mnozstvi, SUM(cista) AS cista, cena, 0 AS cis_rec, 0 AS mnoz_rec, 00 AS hloubka ;
						GROUP BY c_karty FROM buf2 INTO CURSOR bbbb ORDER BY druh, nazev WHERE !kalk
					DO pr_report WITH "vyroba1"
				ENDIF
				IF "13,"$m.natlac AND m.ret     && po druzich
					SELECT c_karty, naz_rec, nazev, mnozstvi, poradi FROM buf2 INTO CURSOR buf3 ORDER BY poradi, nazev READWRITE 
					INSERT INTO buf3 (c_karty, naz_rec, nazev, mnozstvi, poradi) SELECT c_karty, druh AS naz_rec, nazev, SUM(mnozstvi) AS mnozstvi, 0 as poradi FROM buf2 GROUP BY c_karty, druh, nazev ORDER BY druh, nazev
					
					DO pr_report WITH "vyroba2"
					DO pozavirej WITH "buf3"
				ENDIF

				IF "04,"$m.natlac AND m.ret
					SELECT c_karty, druh, nazev, SUM(mnozstvi) AS mnozstvi, SUM(cista) AS cista, cena, 0 AS cis_rec, " " AS naz_rec, 0 AS mnoz_rec, 00 AS hloubka ;
						GROUP BY c_karty FROM buf2 INTO CURSOR bbbb WHERE !kalk
					DO pr_report WITH "vyroba1"
				ENDIF

				IF "08," $ m.natlac AND m.ret
					ALTER TABLE (m.gcpri_path + "davka") ALTER vyr_postup m
					SELECT davka
					SET RELATION TO c_karty INTO karty
					REPLACE ALL nazev WITH karty.nazev, vyr_postup WITH karty.vyr_postup
					SET RELATION TO
					SET FILTER TO .NOT. EMPTY(vyr_postup)
					DO pr_report WITH "jak_varit_postupy"
				ENDIF
			ENDIF

			IF "05,"$m.natlac .OR. "06,"$m.natlac .OR. "07,"$m.natlac
				SELECT polozky.c_karty, polozky.c_poloz, polozky.hruba / polozky.pocet AS hruba,polozky.cista / polozky.pocet AS cista, polozky.poznamka, karty.nazev ;
					FROM polozky LEFT JOIN karty ON karty.c_karty==polozky.c_karty ;
					INTO CURSOR poc1

				SELECT poc1.nazev + SPACE(10) AS nazev, poc1.c_karty, poc1.c_poloz, poc1.hruba, poc1.cista, karty.nazev + poc1.poznamka AS poloz;
					FROM poc1 LEFT JOIN karty ON karty.c_karty==poc1.c_poloz ;
					INTO CURSOR mkapoc
				INDEX ON nazev TAG nazev

				SELECT nazev, c_karty, SUM(mnozstvi) + $0 AS mnozstvi, c_karty AS c_dokl, poradi ;
					GROUP BY c_karty FROM buf_dav INTO CURSOR davka567
				INDEX ON c_karty TAG c_karty

				SELECT $0 AS mnozstvi, mnozstvi AS hruba,mnozstvi AS cista, poradi, ;
					nazev + SPACE(10) AS poloz, SPACE(30) AS nazev, " " AS FLAG, 00 AS hloubka ;
					FROM davka567 INTO CURSOR debil4 READWRITE WHERE mnozstvi>0
				FOR hloubka = 1 TO 8
					UPDATE debil4 SET FLAG="S" FROM mkapoc WHERE EMPTY(debil4.FLAG)
					UPDATE debil4 SET FLAG="" FROM mkapoc WHERE debil4.FLAG="S" AND LEFT(debil4.poloz,30)=LEFT(mkapoc.nazev,30)
					SELECT debil4.poloz AS nazev, mkapoc.poloz, debil4.hruba AS mnozstvi, ;
						SUM(debil4.hruba * mkapoc.hruba) AS hruba,SUM(debil4.cista * mkapoc.cista) AS cista, m.hloubka AS hloubka ,debil4.poradi AS poradi;
						FROM debil4, mkapoc GROUP BY debil4.poloz, mkapoc.poloz;
						WHERE EMPTY(FLAG) AND LEFT(debil4.poloz,30)==LEFT(mkapoc.nazev,30) INTO CURSOR debil44
					rcc = RECCOUNT()
					SELECT debil4
					REPLACE FOR EMPTY(FLAG) FLAG WITH "K"
					INSERT INTO debil4 (nazev, poloz, mnozstvi, hruba, cista, hloubka, poradi) SELECT nazev, poloz, mnozstvi, ;
						hruba, cista, hloubka , poradi	FROM debil44
					USE IN debil44
					IF EMPTY(m.rcc)
						EXIT
					ENDIF
				ENDFOR

				SELECT nazev+"|"+poloz AS qwe,poradi, nazev, poloz, SUM(mnozstvi) AS mnozstvi, SUM(hruba) AS hruba, SUM(cista) AS cista, FLAG, hloubka ;
					GROUP BY 1 FROM debil4 INTO TABLE (m.gcpri_path + "debil444")
				REPLACE poradi WITH 9999 FOR hloubka>1
				REPLACE FOR FLAG # "K" FLAG WITH ""

				ALTER TABLE (m.gcpri_path + "debil444") ADD vyr_postup m        && doplneni vyrobniho postupu
				SET ORDER TO nazev IN karty
				SELECT debil444
				SET RELATION TO nazev INTO karty
				REPLACE ALL vyr_postup WITH karty.vyr_postup
				SET RELATION TO

				IF "05,"$m.natlac AND m.ret
					INDEX ON STR(hloubka,1,0)+STR(poradi,10,0) TAG por_pol
					DO pr_report WITH "jak_varit"
				ENDIF

				IF "06,"$m.natlac AND m.ret
					INDEX ON hloubka TAG naz_pol
					DO pr_report WITH "jak_varit"
				ENDIF

				IF "07,"$m.natlac AND m.ret    && pizza felix
					SELECT debil4
					SELECT PADR(FLAG + STR(hloubka,1), 33) AS nazev, poloz, poloz AS qwe, poradi, hloubka, 0 AS mnozstvi, SUM(hruba) AS hruba, SUM(cista) AS cista, " " AS FLAG ;
						GROUP BY 1,2 FROM debil4 INTO CURSOR debil444pizza READWRITE
					*						GROUP BY 1,2 FROM (m.gcpri_path + "debil4") INTO TABLE (m.gcpri_path + "debil444")
					REPLACE FOR nazev = "K0" nazev WITH "VYROBKY"
					REPLACE FOR nazev = "K1" nazev WITH "POLOTOVARY"
					REPLACE FOR nazev = "K2" nazev WITH "POLOTOVARY V POLOTOVARECH"
					REPLACE FOR nazev = "S1" nazev WITH "SUROVINY PRO VYROBKY"
					REPLACE FOR nazev = "S2" nazev WITH "SUROVINY PRO POLOTOVARY"
					REPLACE FOR nazev = "S3" nazev WITH "SUR. PRO POLOTOVARY V POLOTOVARECH"
					DO pr_report WITH "jak_varit"
				ENDIF

				DO pozavirej WITH "debil4, debil444, mkapoc, poc1, davka, davka567"
			ENDIF
		ENDIF
	ENDIF
	IF "10,"$m.natlac .OR. "11,"$m.natlac .OR. "12,"$m.natlac
		DO kusokzlimitov
	ENDIF
ENDIF


*!*****************************************************************************
PROCEDURE odpocet_vyroba
had = CREATEOBJECT("had", jaz("prg_odpocet_davky")+" " + m.hladajdavku )
had.SHOW()

IF SELECT("buf_dav") = 0
	SELECT * FROM davky WHERE .F. INTO CURSOR buf_dav
ENDIF

SELECT 000000000000 AS cis_rec, SPACE(30) AS naz_rec, $0 AS mnoz_rec, 000000000000 AS c_karty, SPACE(30) AS nazev, SPACE(m.sirkastlpcadruh) AS druh,000000000000 AS c_druh,;
	$0 AS mnozstvi, $0 AS cista, 000000000000 AS poradi, $0 AS cena, 00 AS hloubka,.F. AS kalk FROM buf_dav INTO CURSOR buf2 READWRITE WHERE .F.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SET ORDER TO c_karty IN karty
SELECT polozky
SET RELATION TO c_karty INTO karty
REPLACE ALL pocet WITH karty.pocet
SET RELATION TO

IF !USED("obraty")
	USE (m.fn_obraty) ALIAS obraty IN 0
ENDIF

USE vodpoctyaskl ALIAS a_skl1 IN 0
SELECT nazev, c_karty, c_druh, c_druhk, c_druhs, c_druh AS c_druhstr, 999999999.99 AS k_odpoctu, cena_prum, c_mena_n AS c_mena, 999999999.99 AS zustatek," " AS vycisleni, .F. AS prepocet, m.gic_stredisk AS c_stredisk ;
	FROM karty WHERE nazev1<>m.smazana_karta INTO CURSOR a_skl READWRITE
UPDATE a_skl SET cena_prum=a_skl1.cena_prum, c_mena=a_skl1.c_mena, vycisleni=a_skl1.vycisleni FROM a_skl1 WHERE a_skl.c_karty=a_skl1.c_karty
INDEX ON c_karty TAG c_karty
USE IN a_skl1

SELECT c_karty, SUM(mnozstvi) + $0 AS mnozstvi, c_karty AS c_dokl, poradi, 01 AS hloubka, " " AS vyr_postup, SPACE(30) AS nazev ;
	GROUP BY c_karty FROM buf_dav INTO TABLE (m.gcpri_path + "davka")
INDEX ON c_karty TAG c_karty
SCAN FOR mnozstvi<>0
	cis_rec      = davka.c_karty
	mnozstvi_rec = davka.mnozstvi
	hlx=davka.hloubka
	IF m.hlx<10
		SELECT m.cis_rec AS c_karty, m.mnozstvi_rec AS mnozstvi, m.mnozstvi_rec AS mnoz_pov, $0 AS odecteno, m.mnozstvi_rec AS cista, m.mnozstvi_rec AS hruba ;
			WHERE c_karty = m.cis_rec AND hloubka=m.hlx FROM davka INTO CURSOR sk1 READWRITE
		SELECT 000000000000 AS c_karty,$0 AS hruba, $0 AS cista FROM sk1 INTO CURSOR  kalk READWRITE  WHERE .F.
		SELECT sk1
		GO TOP
		IF RECCOUNT()>0
			SET RELATION TO c_karty INTO a_skl
			SELECT sk1
			IF sk1.mnozstvi > 0
				IF EMPTY(a_skl.vycisleni)
					SCATTER FIELD c_karty, mnozstvi MEMVAR
					SELECT polozky
					LOCATE FOR c_karty = m.c_karty .AND. ! EMPT(c_poloz) .AND. ! EMPT(hruba)
					IF FOUND()
						SCAN FOR c_karty = m.c_karty .AND. ! EMPT(c_poloz) .AND. ! EMPT(hruba)
							INSERT INTO kalk (c_karty, hruba, cista) ;
								VALUE (polozky.c_poloz, ROUND(m.mnozstvi * polozky.hruba / polozky.pocet, 4), ROUND(m.mnozstvi * polozky.cista / polozky.pocet, 4))
						ENDSCAN
						SELECT sk1
						REPLACE mnozstvi WITH 0
					ELSE
						SELECT sk1
						REPLACE odecteno WITH mnozstvi
						REPLACE mnozstvi WITH 0
					ENDIF
				ELSE
					SELECT sk1
					REPLACE odecteno WITH mnozstvi
					REPLACE mnozstvi WITH 0
				ENDIF
				SELECT sk1
				INSERT INTO buf2 (c_karty, mnozstvi, cista, mnoz_rec, cis_rec, hloubka) SELECT c_karty, SUM(hruba) AS mnozstvi, SUM(cista) AS cista, m.mnozstvi_rec AS mnoz_rec, m.cis_rec AS cis_rec, m.hlx AS hloubka ;
					GROUP BY c_karty WHERE sk1.mnozstvi # 0 .OR. odecteno#0 FROM sk1
				hl = m.hlx + 1
				SELECT c_karty, SUM(hruba) AS mnozstvi, SUM(cista) AS cista, .F. AS kalk FROM kalk INTO CURSOR qqq  GROUP BY c_karty READWRITE
				IF RECCOUNT() > 0
					SELECT kalk
					DELETE ALL
					SELECT davka
					m.pozice=RECNO()
					SELECT qqq
					SCAN ALL
						SELECT polozky
						LOCATE FOR c_karty=qqq.c_karty
						IF FOUND()
							SELECT qqq
							REPLACE kalk WITH .T.
							INSERT INTO davka (c_karty, mnozstvi, hloubka, c_dokl, poradi) VALUES (qqq.c_karty, qqq.mnozstvi, m.hl, qqq.c_karty,99999)
						ENDIF
						SELECT qqq
					ENDSCAN
					INSERT INTO buf2 (c_karty, mnozstvi, cista, mnoz_rec, cis_rec, hloubka, kalk) SELECT c_karty, mnozstvi, cista, m.mnozstvi_rec AS mnoz_rec, m.cis_rec AS cis_rec, m.hlx AS hloubka, kalk FROM qqq
					USE IN qqq
					SELECT davka
					GOTO (m.pozice)
				ENDIF
				USE IN sk1
			ENDIF
		ENDIF
		USE IN kalk
		SELECT davka
	ELSE
		MESSAGEBOX(jaz("form_pozor_rekurzie"),64,"FoodMan")
	ENDIF
ENDSCAN

DO pozavirej WITH "sk1, qqq, kalk, a_skl"

SET ORDER TO c_karty IN karty
SELECT sklad
SET FILTER TO c_stredisk = gic_stredisk
SET ORDER TO c_karty

SELECT buf2
SET RELATION TO c_karty INTO sklad
REPLACE ALL cena WITH sklad.cena_prum
SET RELATION TO c_karty INTO karty
REPLACE FOR mnozstvi=0 .AND. cena=0 cena WITH karty.cena_prum
REPLACE c_druh WITH karty.c_druh ALL
REPLACE c_druh WITH karty.c_druhk FOR EMPTY(buf2.c_druh)
REPLACE ALL nazev WITH karty.nazev
UPDATE buf2 SET druh=skupiny.druh FROM skupiny WHERE buf2.c_druh=skupiny.c_druh
SET RELATION TO cis_rec INTO karty
REPLACE ALL naz_rec WITH karty.nazev
SET RELATION OFF INTO karty
IF VARTYPE(m.prava_na_druhy)=="L" AND m.prava_na_druhy AND !m.glis_admin
	SELECT c_druh FROM buf2 WHERE !EMPTY(c_druh) AND !(c_druh IN (SELECT c_druh FROM uzivat)) INTO CURSOR vysledok
	IF RECCOUNT("vysledok")>0
		ret=.F.
	ENDIF
	USE IN vysledok
	IF !m.ret
		MESSAGEBOX(jaz("form_nepravo_davka")+CHR(10)+jaz("form_neda_sa_pokracovat"),64,"FoodMan")
	ELSE
		SET RELATION TO cis_rec INTO davka
		REPLACE ALL poradi WITH davka.poradi
		SET RELATION OFF INTO davka
	ENDIF
ENDIF
RELEASE had
WAIT CLEAR

*!*****************************************************************************
PROCEDURE odp_vyr_sql
had = CREATEOBJECT("had", jaz("prg_odpocet_davky")+" " + m.hladajdavku )
had.SHOW()
m.vysledok=sql_exec("SELECT food600.odpocet_vyroba('"+m.menobuffera+"',"+ALLTRIM(STR(m.cdata,2,0))+","+ALLTRIM(STR(m.gic_stredisk,10,0))+","+ALLTRIM(STR(m.giakt_mena,2,0))+",'"+m.hladajdavku+"')","buf_dav")
RELEASE had
WAIT CLEAR
USE (m.sqlprefix+"rbufferuzky") ALIAS BUFFER NODATA IN 0

IF "01,"$m.natlac .OR. "02,"$m.natlac .OR. "03,"$m.natlac .OR. "04,"$m.natlac .OR. "13,"$m.natlac .OR. (VARTYPE(m.prava_na_druhy)=="L" AND m.prava_na_druhy AND !m.glis_admin)
	SELECT 0
	USE (m.sqlprefix+"rdavkavyroba1") ALIAS buf2

	IF VARTYPE(m.prava_na_druhy)=="L" AND m.prava_na_druhy AND !m.glis_admin
		SELECT cdruh FROM buf2 WHERE !EMPTY(cdruh) AND !(cdruh IN (SELECT c_druh FROM uzivat)) INTO CURSOR vysledok
		IF RECCOUNT("vysledok")>0
			ret=.F.
		ENDIF
		USE IN vysledok
		IF m.ret
			SELECT cdruhs FROM buf2 WHERE !EMPTY(cdruhs) AND  !(cdruhs IN (SELECT c_druh FROM uzivat)) INTO CURSOR vysledok
			IF RECCOUNT("vysledok")>0
				ret=.F.
			ENDIF
			USE IN vysledok
			IF m.ret
				SELECT cdruhk FROM buf2 WHERE !EMPTY(cdruhk) AND  !(cdruhk IN (SELECT c_druh FROM uzivat)) INTO CURSOR vysledok
				IF RECCOUNT("vysledok")>0
					ret=.F.
				ENDIF
				USE IN vysledok
			ENDIF
		ENDIF
		IF !m.ret
			=MESSAGEBOX(jaz("form_nepravo_davka")+CHR(10)+jaz("form_neda_sa_pokracovat"),64,"FoodMan")
		ENDIF
	ENDIF

	SELECT buf2
	REPLACE c_druh WITH cdruh  FOR EMPTY(c_druh)
	REPLACE c_druh WITH cdruhk FOR EMPTY(c_druh)
	REPLACE c_druh WITH cdruhs FOR EMPTY(c_druh)
	UPDATE buf2 SET druh=rskupiny.druh FROM rskupiny WHERE buf2.c_druh=rskupiny.c_druh
	UPDATE buf2 SET poradi=buf_dav.poradi FROM buf_dav WHERE buf2.cis_rec=buf_dav.c_karty AND buf2.hloubka=1
	UPDATE buf2 SET poradi=999 FROM buf_dav WHERE buf2.cis_rec=buf_dav.c_karty AND buf2.hloubka>1

ENDIF
IF "01,"$m.natlac AND m.ret
	INDEX ON STR(poradi,10,0)+nazev TAG pornaz
	DO pr_report WITH "vyroba1"
ENDIF
IF "02,"$m.natlac AND m.ret
	INDEX ON naz_rec + nazev TAG naznaz
	DO pr_report WITH "vyroba1"
ENDIF

IF "03,"$m.natlac AND m.ret     && po druzich
	SELECT c_karty, druh AS naz_rec, nazev, SUM(mnozstvi) AS mnozstvi, SUM(cista) AS cista, cena, 0 AS cis_rec, 0 AS mnoz_rec, 00 AS hloubka ;
		GROUP BY c_karty FROM buf2 INTO CURSOR bbbb ORDER BY druh, nazev
	DO pr_report WITH "vyroba1"
ENDIF
IF "13,"$m.natlac AND m.ret     && po druzich
	SELECT c_karty, naz_rec, nazev, mnozstvi, poradi FROM buf2 INTO CURSOR buf3 READWRITE ORDER BY poradi, nazev
	INSERT INTO buf3 (c_karty, naz_rec, nazev, mnozstvi, poradi) SELECT c_karty, druh AS naz_rec, nazev, SUM(mnozstvi) AS mnozstvi, 0 as poradi FROM buf2 GROUP BY c_karty, druh, nazev ORDER BY druh, nazev
	
	DO pr_report WITH "vyroba2"
	DO pozavirej WITH "buf3"
ENDIF

IF "04,"$m.natlac AND m.ret
	SELECT c_karty, druh, nazev, SUM(mnozstvi) AS mnozstvi, SUM(cista) AS cista, cena, 0 AS cis_rec, " " AS naz_rec, 0 AS mnoz_rec, 00 AS hloubka ;
		GROUP BY 1 FROM buf2 INTO CURSOR bbbb
	DO pr_report WITH "vyroba1"
ENDIF
DO pozavirej WITH "buf2,bbbb"
IF "05,"$m.natlac .OR. "06,"$m.natlac .OR. "07,"$m.natlac
	DO pozavirej WITH "debil44, debil444"
	SELECT 0
	USE (m.sqlprefix+"rdavkavyroba2") ALIAS debil44
	SELECT * FROM debil44 INTO TABLE (m.gcpri_path + "debil444") READWRITE
	ALTER TABLE (m.gcpri_path + "debil444") ADD vyr_postup m        && doplneni vyrobniho postupu
	UPDATE debil444 SET poradi=buf_dav.poradi FROM buf_dav WHERE debil444.o_c_karty=buf_dav.c_karty
	UPDATE debil444 SET o_c_karty=0, nazev="" WHERE hloubka=0
ENDIF
IF "05,"$m.natlac AND m.ret
	INDEX ON STR(hloubka,1,0)+STR(poradi,10,0) TAG por_pol
	DO pr_report WITH "jak_varit"
ENDIF

IF "06,"$m.natlac AND m.ret
	INDEX ON hloubka TAG naz_pol
	DO pr_report WITH "jak_varit"
ENDIF

IF "07,"$m.natlac AND m.ret    && pizza felix
	SELECT debil44
	SELECT PADR(FLAG + STR(hloubka,1), 33) AS nazev, poloz, poloz AS qwe, poradi, hloubka, 0 AS mnozstvi, SUM(hruba) AS hruba, SUM(cista) AS cista, " " AS FLAG ;
		GROUP BY 1,2 FROM debil44 INTO CURSOR debil444pizza READWRITE
	REPLACE FOR nazev = "K0" nazev WITH "VYROBKY"
	REPLACE FOR nazev = "K1" nazev WITH "POLOTOVARY"
	REPLACE FOR nazev = "K2" nazev WITH "POLOTOVARY V POLOTOVARECH"
	REPLACE FOR nazev = "S1" nazev WITH "SUROVINY PRO VYROBKY"
	REPLACE FOR nazev = "S2" nazev WITH "SUROVINY PRO POLOTOVARY"
	REPLACE FOR nazev = "S3" nazev WITH "SUR. PRO POLOTOVARY V POLOTOVARECH"
	DO pr_report WITH "jak_varit"
ENDIF

DO vymaz_buffer WITH m.menobuffera
DO pozavirej WITH "debil444, buffer"


*!*****************************************************************************
PROCEDURE kusokzlimitov
PRIVATE m.hladajidlimit, m.hladajidden, m.datum, m.kk1, m.kk2, m.hladina1, m.hladina2, sfilt, m.den_mena, m.lim_mena, m.hladajdatumdo
PRIVATE m.chod, m.por1, m.ajdatum, m.ajnakup, m.typskupina, m.prirazka, m.pokracovat, m.menolimitu, m.hladajckarty, m.hladajnazev, m.opakovanie, m.vaha
PRIVATE m.ret
ret=.T.
menolimitu=m.hladajdavku
* milan *
SELECT "" AS dieta, "" AS vaha, .T. AS novinka, 000 AS riadok, m.menolimitu AS menolimit, 0 AS id_limit, .T. AS LABEL, SPACE(m.sirkastlpcadruh) AS druhy, SPACE(10) AS poznamka, SPACE(13) AS kod, SPACE(m.sirkastlpcadruh) AS druh, SPACE(3) AS spart, DATE() AS datum, "" AS chod, 0 AS por1, c_karty, nazev, c_druhk AS c_druh, c_druh AS c_druhstr, c_druhs, c_druhk, SUM(mnozstvi) AS mnozstvi, cena AS nc, poradi AS poradie, c_mena, c_stredisk FROM buf_dav INTO CURSOR llist8 READWRITE GROUP BY nazev WHERE mnozstvi<>0
SELECT llist8
REPLACE c_druh WITH c_druhstr FOR EMPTY(c_druh)
REPLACE c_druh WITH c_druhs FOR EMPTY(c_druh)
UPDATE llist8 SET druh=rskupiny.druh, spart=rskupiny.spart FROM rskupiny WHERE llist8.c_druh=rskupiny.c_druh
REPLACE nc WITH 0 FOR ISNULL(nc)
REPLACE nc WITH MTON(nc)*en__meny(c_mena, m.giakt_mena) FOR c_mena<>m.giakt_mena
REPLACE c_mena WITH m.giakt_mena FOR c_mena<>m.giakt_mena
IF !USED("llist8")
	=MESSAGEBOX(jaz("form_nic_nevybrane"),64,"FoodMan")
	DO pozavirej WITH "llist8"
	RETURN
ELSE
	SELECT llist8
	REPLACE ALL LABEL WITH .T.
	REPLACE ALL riadok WITH -RECNO()
	COUNT TO m.pokracovat FOR !EMPTY(LABEL)
	IF m.pokracovat=0
		=MESSAGEBOX(jaz("form_nic_nevybrane"),64,"FoodMan")
		DO pozavirej WITH "llist8"
		RETURN
	ENDIF
ENDIF
m.uroven=0
SELECT m.uroven AS uroven, dieta, poznamka AS pozn_hl, riadok,.F. AS LABEL, SPACE(30) AS nazev2, menolimit, id_limit, datum, chod, por1, poradie, nazev, druhy, druh, spart, poznamka, kod, mnozstvi, c_stredisk, c_karty AS c_poloz, nazev AS polozka, mnozstvi AS hruba, mnozstvi AS cista, 00001 AS pocet, c_druhstr, c_druhs, c_druhk, druhy AS pdruhy, druh AS pdruh, spart AS pspart, nc, c_mena, vaha FROM llist8 WHERE c_druhk=0 AND novinka INTO CURSOR lllist8 READWRITE
REPLACE ALL pozn_hl WITH ""
SELECT lllist8
SELECT DISTINCT c_karty, nazev, vaha FROM llist8 INTO CURSOR aaa WHERE llist8.c_druhk<>0 AND llist8.novinka
DO pozavirej WITH "lllist8x"
m.uroven=1
SCAN ALL
	m.hladajckarty=aaa.c_karty
	m.hladajnazev=aaa.nazev
	m.vaha=aaa.vaha
	IF USED("limkalkuluj")
		=REQUERY("limkalkuluj")
	ELSE
		IF m.issql
			USE (m.sqlprefix+"rlimkalkuluj") ALIAS limkalkuluj IN 0
		ELSE
			USE vlimkalkuluj ALIAS limkalkuluj IN 0
		ENDIF
	ENDIF
	SELECT c_poloz, SUM(hruba) AS hruba, SUM(cista) AS cista, pozn, nazev, cena_prum, c_druh, c_druhs, c_druhk, c_karty, c_mena_n, vaha, pocet FROM limkalkuluj INTO CURSOR limkalk1 GROUP BY c_poloz, pozn
	IF USED("lllist8x")
		IF RECCOUNT("limkalk1")=0
			INSERT INTO lllist8x (dieta, c_karty, vaha, vahax,pozn_hl, riadok, menolimit, id_limit, datum, chod, por1, poradie, nazev, druhy, druh, spart, poznamka, kod, mnozstvi, c_stredisk, c_poloz, polozka, hruba, cista, pocet, c_druhstr, c_druhs, c_druhk, pdruhy, pdruh, pspart, nc, c_mena);
				SELECT llist8.dieta,m.hladajckarty AS c_karty, m.vaha AS vaha, m.vaha AS vahax, llist8.poznamka AS pozn_hl, llist8.riadok, llist8.menolimit, llist8.id_limit, llist8.datum, llist8.chod, llist8.por1, llist8.poradie, llist8.nazev, llist8.druhy, llist8.druh, llist8.spart,;
				llist8.poznamka, llist8.kod, llist8.mnozstvi, llist8.c_stredisk, llist8.c_karty AS c_poloz, llist8.nazev AS polozka, llist8.mnozstvi AS hruba, llist8.mnozstvi AS cista, 00001 AS pocet,;
				IIF(llist8.c_druhstr=0, llist8.c_druhk, llist8.c_druhstr) AS c_druhstr, llist8.c_druhs, 00000 AS c_druhk, SPACE(m.sirkastlpcadruh) AS pdruhy, SPACE(m.sirkastlpcadruh) AS pdruh, SPACE(3) AS pspart, nc, c_mena FROM llist8 WHERE llist8.c_karty=m.hladajckarty AND llist8.novinka
		ELSE
			INSERT INTO lllist8x (dieta, c_karty, vaha, vahax, pozn_hl, riadok, menolimit, id_limit, datum, chod, por1, poradie, nazev, druhy, druh, spart, poznamka, kod, mnozstvi, c_stredisk, c_poloz, polozka, hruba, cista, pocet, c_druhstr, c_druhs, c_druhk, pdruhy, pdruh, pspart, nc, c_mena);
				SELECT llist8.dieta, m.hladajckarty AS c_karty, m.vaha AS vaha, limkalk1.vaha AS vahax, llist8.poznamka AS pozn_hl, llist8.riadok, llist8.menolimit, llist8.id_limit, llist8.datum, llist8.chod, llist8.por1, llist8.poradie, llist8.nazev, llist8.druhy, llist8.druh,;
				llist8.spart, limkalk1.pozn AS poznamka, llist8.kod, llist8.mnozstvi, llist8.c_stredisk, limkalk1.c_poloz, limkalk1.nazev AS polozka, llist8.mnozstvi*limkalk1.hruba AS hruba,;
				llist8.mnozstvi*limkalk1.cista AS cista, limkalk1.pocet AS pocet, limkalk1.c_druh AS c_druhstr, limkalk1.c_druhs, limkalk1.c_druhk, SPACE(m.sirkastlpcadruh) AS pdruhy, SPACE(m.sirkastlpcadruh) AS pdruh, SPACE(3) AS pspart, limkalk1.cena_prum AS nc, limkalk1.c_mena_n AS c_mena FROM llist8 inner JOIN limkalk1 ON llist8.c_karty=limkalk1.c_karty WHERE llist8.c_karty=m.hladajckarty AND llist8.novinka
		ENDIF
	ELSE
		IF RECCOUNT("limkalk1")=0
			SELECT llist8.dieta, m.hladajckarty AS c_karty, m.vaha AS vaha, m.vaha AS vahax, llist8.poznamka AS pozn_hl,llist8.riadok, llist8.menolimit, llist8.id_limit, llist8.datum, llist8.chod, llist8.por1, llist8.poradie, llist8.nazev, llist8.druhy, llist8.druh,;
				llist8.spart, llist8.poznamka, llist8.kod, llist8.mnozstvi, llist8.c_stredisk, llist8.c_karty AS c_poloz, llist8.nazev AS polozka, llist8.mnozstvi AS hruba, llist8.mnozstvi AS cista,;
				00001 AS pocet, IIF(llist8.c_druhstr=0, llist8.c_druhk, llist8.c_druhstr) AS c_druhstr, llist8.c_druhs, 00000 AS c_druhk, SPACE(m.sirkastlpcadruh) AS pdruhy, SPACE(m.sirkastlpcadruh) AS pdruh, SPACE(3) AS pspart, llist8.nc, llist8.c_mena;
				FROM llist8 WHERE llist8.c_karty=m.hladajckarty AND llist8.novinka INTO CURSOR lllist8x READWRITE
		ELSE
			SELECT llist8.dieta, m.hladajckarty AS c_karty, m.vaha AS vaha, limkalk1.vaha AS vahax, llist8.poznamka AS pozn_hl, llist8.riadok, llist8.menolimit, llist8.id_limit, llist8.datum, llist8.chod, llist8.por1, llist8.poradie, llist8.nazev, llist8.druhy, llist8.druh,;
				llist8.spart, limkalk1.pozn AS poznamka, llist8.kod, llist8.mnozstvi, llist8.c_stredisk, limkalk1.c_poloz, limkalk1.nazev AS polozka, llist8.mnozstvi*limkalk1.hruba AS hruba,;
				llist8.mnozstvi*limkalk1.cista AS cista, limkalk1.pocet AS pocet, limkalk1.c_druh AS c_druhstr, limkalk1.c_druhs, limkalk1.c_druhk, SPACE(m.sirkastlpcadruh) AS pdruhy, SPACE(m.sirkastlpcadruh) AS pdruh, SPACE(3) AS pspart, limkalk1.cena_prum AS nc, limkalk1.c_mena_n AS c_mena;
				FROM llist8 inner JOIN limkalk1 ON llist8.c_karty=limkalk1.c_karty WHERE llist8.c_karty=m.hladajckarty AND llist8.novinka INTO CURSOR lllist8x READWRITE
		ENDIF
	ENDIF
	USE IN limkalk1
	SELECT aaa
ENDSCAN
IF USED("lllist8x")
	SELECT lllist8x
	REPLACE pocet WITH 1 FOR pocet=0 OR ISNULL(pocet)
	REPLACE hruba WITH hruba/pocet, cista WITH cista/pocet FOR pocet<>1
	REPLACE c_druhstr WITH c_druhs FOR EMPTY(c_druhstr)
	REPLACE c_druhstr WITH c_druhk FOR EMPTY(c_druhstr)
	UPDATE lllist8x SET pdruh=rskupiny.druh, pspart=rskupiny.spart FROM rskupiny WHERE lllist8x.c_druhstr=rskupiny.c_druh
	REPLACE nc WITH 0 FOR ISNULL(nc)
	REPLACE nc WITH MTON(nc)*en__meny(c_mena, m.giakt_mena) FOR c_mena<>m.giakt_mena
	REPLACE c_mena WITH m.giakt_mena FOR c_mena<>m.giakt_mena
	IF USED("lllist8")
		INSERT INTO lllist8 (uroven, dieta, vaha, pozn_hl, riadok, menolimit, id_limit, datum, chod, por1, poradie, nazev, druhy, druh, spart, poznamka, kod, mnozstvi, c_stredisk, c_poloz, polozka, hruba, cista, pocet, c_druhstr, c_druhs, c_druhk, pdruhy, pdruh, pspart, nc, c_mena)	;
			SELECT m.uroven, dieta, vaha, pozn_hl, riadok, menolimit, id_limit, datum, chod, por1, poradie, nazev, druhy, druh, spart, poznamka, kod, mnozstvi, c_stredisk, c_poloz, polozka, hruba, cista, pocet, c_druhstr, c_druhs, c_druhk, pdruhy, pdruh, pspart, nc, c_mena FROM lllist8x
	ELSE
		SELECT m.uroven AS uroven, dieta, vaha, pozn_hl, .F. AS LABEL, riadok, SPACE(30) AS nazev2, menolimit, id_limit, datum, chod, por1, poradie, nazev, druhy, druh, spart, poznamka, kod, mnozstvi, c_stredisk, c_poloz, polozka, hruba, cista, pocet, c_druhstr, c_druhs, c_druhk, pdruhy, pdruh, pspart, nc, c_mena FROM lllist8x INTO CURSOR lllist8 READWRITE
	ENDIF
	SELECT lllist8x
	m.opakovanie=0
	DO WHILE .T.
		m.uroven=m.uroven+1
		m.opakovanie=m.opakovanie+1
		IF m.opakovanie>7
			EXIT
		ENDIF
		IF !USED("lllist8x")
			EXIT
		ENDIF
		SELECT * FROM lllist8x INTO CURSOR aaa WHERE c_druhk<>0
		IF RECCOUNT("aaa")=0
			EXIT
		ENDIF
		SELECT DISTINCT c_poloz, vahax FROM aaa INTO CURSOR bbb
		DO pozavirej WITH "lllist8x"
		SCAN ALL
			m.hladajckarty=bbb.c_poloz
			m.vaha=bbb.vahax
			IF USED("limkalkuluj")
				=REQUERY("limkalkuluj")
			ELSE
				IF m.issql
					USE (m.sqlprefix+"rlimkalkuluj") ALIAS limkalkuluj IN 0
				ELSE
					USE vlimkalkuluj ALIAS limkalkuluj IN 0
				ENDIF
			ENDIF
			SELECT c_poloz, SUM(hruba) AS hruba, SUM(cista) AS cista, pozn, nazev, cena_prum, c_druh, c_druhs, c_druhk, c_karty, c_mena_n, vaha, pocet FROM limkalkuluj INTO CURSOR limkalk1 GROUP BY c_poloz, pozn
			IF USED("lllist8x")
				IF RECCOUNT("limkalk1")=0
					INSERT INTO lllist8x (dieta, vaha, vahax, riadok, nazev2, menolimit, id_limit, datum, chod, por1, poradie, nazev, druhy, druh, spart, poznamka, kod, mnozstvi, c_stredisk, c_karty, c_poloz, polozka, hruba, cista, pocet, c_druhstr, c_druhs, c_druhk, pdruhy, pdruh, pspart, nc, c_mena);
						SELECT aaa.dieta, m.vaha AS vaha, m.vaha AS vahax, aaa.riadok, aaa.nazev AS nazev2, aaa.menolimit, aaa.id_limit, aaa.datum, aaa.chod, aaa.por1, aaa.poradie, aaa.nazev, aaa.druhy, aaa.druh, aaa.spart, aaa.poznamka,;
						aaa.kod, aaa.mnozstvi, aaa.c_stredisk, aaa.c_karty, aaa.c_karty AS c_poloz, aaa.nazev AS polozka, aaa.hruba AS hruba, aaa.hruba AS cista, 00001 AS pocet, IIF(aaa.c_druhstr=0, aaa.c_druhk, aaa.c_druhstr) AS c_druhstr,;
						aaa.c_druhs, 00000 AS c_druhk, SPACE(m.sirkastlpcadruh) AS pdruhy, SPACE(m.sirkastlpcadruh) AS pdruh, SPACE(3) AS pspart, aaa.nc, aaa.c_mena FROM aaa WHERE c_poloz=m.hladajckarty
				ELSE
					INSERT INTO lllist8x (dieta, vaha, vahax, riadok, nazev2, menolimit, id_limit, datum, chod, por1, poradie, nazev, druhy, druh, spart, poznamka, kod, mnozstvi, c_stredisk, c_karty, c_poloz, polozka, hruba, cista, pocet, c_druhstr, c_druhs, c_druhk, pdruhy, pdruh, pspart, nc, c_mena);
						SELECT aaa.dieta, m.vaha AS vaha, limkalk1.vaha AS vahax, aaa.riadok, aaa.nazev AS nazev2, aaa.menolimit, aaa.id_limit, aaa.datum, aaa.chod, aaa.por1, aaa.poradie, aaa.polozka AS nazev, aaa.pdruhy AS druhy, aaa.pdruh AS druh, aaa.pspart AS spart,;
						limkalk1.pozn AS poznamka, aaa.kod, aaa.hruba AS mnozstvi, aaa.c_stredisk, limkalk1.c_poloz AS c_karty, limkalk1.c_poloz, limkalk1.nazev AS polozka, aaa.hruba*limkalk1.hruba AS hruba, aaa.hruba*limkalk1.cista AS cista,;
						limkalk1.pocet AS pocet, limkalk1.c_druh AS c_druhstr, limkalk1.c_druhs, limkalk1.c_druhk, SPACE(m.sirkastlpcadruh) AS pdruhy, SPACE(m.sirkastlpcadruh) AS pdruh, SPACE(3) AS pspart, limkalk1.cena_prum AS nc, limkalk1.c_mena_n AS c_mena FROM aaa inner JOIN limkalk1 ON aaa.c_poloz=limkalk1.c_karty WHERE aaa.c_poloz=m.hladajckarty
				ENDIF
			ELSE
				IF RECCOUNT("limkalk1")=0
					SELECT aaa.dieta, m.vaha AS vaha, m.vaha AS vahax, aaa.riadok, aaa.nazev AS nazev2, aaa.menolimit, aaa.id_limit, aaa.datum, aaa.chod, aaa.por1, aaa.poradie, aaa.polozka AS nazev, aaa.pdruhy AS druhy, aaa.pdruh AS druh, aaa.pspart AS spart,;
						aaa.poznamka, aaa.kod, aaa.hruba AS mnozstvi, aaa.c_stredisk, aaa.c_karty, aaa.c_karty AS c_poloz, aaa.polozka, aaa.hruba, aaa.hruba AS cista, 00001 AS pocet, IIF(aaa.c_druhstr=0, aaa.c_druhk, aaa.c_druhstr) AS c_druhstr, aaa.c_druhs,;
						00000 AS c_druhk, SPACE(m.sirkastlpcadruh) AS pdruhy, SPACE(m.sirkastlpcadruh) AS pdruh, SPACE(3) AS pspart, aaa.nc, aaa.c_mena FROM aaa WHERE aaa.c_poloz=m.hladajckarty INTO CURSOR lllist8x READWRITE
				ELSE
					SELECT aaa.dieta, m.vaha AS vaha, limkalk1.vaha AS vahax, aaa.riadok, aaa.nazev AS nazev2, aaa.menolimit, aaa.id_limit, aaa.datum, aaa.chod, aaa.por1, aaa.poradie, aaa.polozka AS nazev, aaa.pdruhy AS druhy, aaa.pdruh AS druh, aaa.pspart AS spart,;
						limkalk1.pozn AS poznamka, aaa.kod, aaa.hruba AS mnozstvi, aaa.c_stredisk, limkalk1.c_poloz AS c_karty, limkalk1.c_poloz, limkalk1.nazev AS polozka, aaa.hruba*limkalk1.hruba AS hruba, aaa.hruba*limkalk1.cista AS cista,;
						limkalk1.pocet AS pocet, limkalk1.c_druh AS c_druhstr, limkalk1.c_druhs, limkalk1.c_druhk, SPACE(m.sirkastlpcadruh) AS pdruhy, SPACE(m.sirkastlpcadruh) AS pdruh, SPACE(3) AS pspart, limkalk1.cena_prum AS nc, limkalk1.c_mena_n AS c_mena FROM aaa inner JOIN limkalk1 ON aaa.c_poloz=limkalk1.c_karty WHERE aaa.c_poloz=m.hladajckarty INTO CURSOR lllist8x READWRITE
				ENDIF
			ENDIF
			USE IN limkalk1
			SELECT bbb
		ENDSCAN
		DO pozavirej WITH "aaa,bbb"
		IF USED("lllist8x")
			SELECT lllist8x
			REPLACE pocet WITH 1 FOR pocet=0 OR ISNULL(pocet)
			REPLACE hruba WITH hruba/pocet, cista WITH cista/pocet FOR pocet<>1
			SELECT lllist8x
			TRY
				REPLACE c_druhstr WITH c_druhs FOR EMPTY(c_druhstr)
			CATCH
			ENDTRY
			TRY
				REPLACE c_druhstr WITH c_druhk FOR EMPTY(c_druhstr)
			CATCH
			ENDTRY
			UPDATE lllist8x SET pdruh=rskupiny.druh, pspart=rskupiny.spart FROM rskupiny WHERE lllist8x.c_druhstr=rskupiny.c_druh
			REPLACE nc WITH 0 FOR ISNULL(nc)
			REPLACE nc WITH MTON(nc)*en__meny(c_mena, m.giakt_mena) FOR c_mena<>m.giakt_mena
			REPLACE c_mena WITH m.giakt_mena FOR c_mena<>m.giakt_mena
			IF USED("lllist8")
				INSERT INTO lllist8 (uroven, dieta, vaha, riadok, nazev2, menolimit, id_limit, datum, chod, por1, poradie, nazev, druhy, druh, spart, poznamka, kod, mnozstvi, c_stredisk, c_poloz, polozka, hruba, cista, pocet, c_druhstr, c_druhs, c_druhk, pdruhy, pdruh, pspart, nc, c_mena)	;
					SELECT m.uroven, dieta, vaha, riadok, nazev2, menolimit, id_limit, datum, chod, por1, poradie, nazev, druhy, druh, spart, poznamka, kod, mnozstvi, c_stredisk, c_poloz, polozka, hruba, cista, pocet, c_druhstr, c_druhs, c_druhk, pdruhy, pdruh, pspart, nc, c_mena FROM lllist8x
			ELSE
				SELECT m.uroven AS uroven, dieta, "" AS vaha, "" AS pozn_hl, riadok, nazev2, .F. AS LABEL, menolimit, id_limit, datum, chod, por1, poradie, nazev, druhy, druh, spart, poznamka, kod, mnozstvi, c_stredisk, c_poloz, polozka, hruba, cista, pocet, c_druhstr, c_druhs, c_druhk, pdruhy, pdruh, pspart, nc, c_mena FROM lllist8x INTO CURSOR lllist8 READWRITE
			ENDIF
		ENDIF
	ENDDO
ENDIF
DO pozavirej WITH "limkalkuluj,lllist8x"
IF USED("lllist8")
	IF VARTYPE(m.prava_na_druhy)=="L" AND m.prava_na_druhy AND !m.glis_admin
		SELECT c_druhstr FROM lllist8 WHERE !EMPTY(c_druhstr) AND !(c_druhstr IN (SELECT c_druh FROM uzivat)) INTO CURSOR vysledok
		IF RECCOUNT("vysledok")>0
			m.ret=.F.
		ENDIF
		USE IN vysledok
		IF m.ret
			SELECT c_druhs FROM lllist8 WHERE !EMPTY(c_druhs) AND  !(c_druhs IN (SELECT c_druh FROM uzivat)) INTO CURSOR vysledok
			IF RECCOUNT("vysledok")>0
				m.ret=.F.
			ENDIF
			USE IN vysledok
			IF m.ret
				SELECT c_druhk FROM lllist8 WHERE !EMPTY(c_druhk) AND  !(c_druhk IN (SELECT c_druh FROM uzivat)) INTO CURSOR vysledok
				IF RECCOUNT("vysledok")>0
					m.ret=.F.
				ENDIF
				USE IN vysledok
			ENDIF
		ENDIF
		IF !m.ret
			=MESSAGEBOX(jaz("form_nepravo_davka")+CHR(10)+jaz("form_neda_sa_pokracovat"),64,"FoodMan")
		ENDIF
	ENDIF
	SELECT lllist8
	REPLACE ALL druhy WITH ""
	REPLACE ALL LABEL WITH .T.
	IF m.uroven>1
		LOCAL vybrane
		SELECT DISTINCT ALLTRIM(STR(uroven,2,0)) AS uroven,(ALLTRIM(STR(uroven,2,0))+"."+LOWER(jaz("rep_uroven"))) AS popis  FROM lllist8 INTO CURSOR seluroven READWRITE
		IF RECCOUNT("seluroven")>1
			IF MESSAGEBOX(jaz("form_mate_x_urovni_podkalkula")+CHR(10)+jaz("form_chcete_spocitat_podkalkulacie"),4+32+256,"FoodMan")=6
				m.vybrane=""
				DO FORM dajdruh WITH "","seluroven","uroven",70,"popis",200 TO vybrane
				IF !EMPTY(m.vybrane)
					SELECT lllist8
					REPLACE nazev2 WITH "" FOR uroven>=VAL(m.vybrane)
				ENDIF
			ENDIF
		ENDIF
		USE IN seluroven
	ENDIF
	SELECT menolimit, dieta, c_stredisk, chod, por1, nazev, nazev2, SUM(mnozstvi) AS mnozstvi, pozn_hl, poznamka, polozka, SUM(hruba) AS hruba, SUM(cista) AS cista, druhy, nc, vaha, poradie, 1 as polka FROM lllist8 GROUP BY c_stredisk, dieta, menolimit, chod, nazev, pozn_hl, nazev2, polozka, poznamka INTO CURSOR list8out READWRITE WHERE LABEL
	lim_mena=m.giakt_mena
	tlacpopis=""
	hladajdatumdo = m.hladajdatumod
	IF "10,"$m.natlac AND m.ret
		SELECT list8out
		INDEX ON STR(c_stredisk,5,0) + dieta+ menolimit + STR(por1,5,0) + druhy + nazev + pozn_hl + nazev2 TAG aaa
		DO pr_report WITH "nlimitkuch"
	ENDIF
	IF "11,"$m.natlac AND m.ret
		SELECT list8out
		INDEX ON STR(c_stredisk,5,0) + dieta+ menolimit + STR(por1,5,0) + druhy + STR(poradie,5,0)+ nazev + pozn_hl + nazev2 TAG aaa
		DO pr_report WITH "nlimitkuch"
	ENDIF
	IF "12,"$m.natlac AND m.ret
		m.hladajdatumdo=m.hladajdatumod
		SELECT menolimit, c_stredisk, c_poloz, polozka, poznamka, SUM(hruba) AS hruba, SUM(cista) AS cista, pdruhy, nc FROM lllist8 GROUP BY c_stredisk, menolimit, c_poloz, poznamka INTO CURSOR list7out WHERE LABEL AND (EMPTY(c_druhk) OR nazev=polozka) READWRITE
		INDEX ON STR(c_stredisk,5,0)+menolimit+ pdruhy + polozka TAG aaa
		SELECT list7out
		DO pr_report WITH "nlimitskladnc"
	ENDIF
	DO pozavirej WITH "list8out,lllist8,list7out"
ENDIF
