CREATE OR REPLACE FUNCTION food600.vyplnkodvskpol(
	cdata integer)
    RETURNS integer
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE
AS $BODY$
--DECLARE chyby CURSOR FOR SELECT DISTINCT nazev FROM food600.sk_pol WHERE c_data=cdata AND (c_karty=0 OR c_karty IS NULL);
--	chyby1 CURSOR FOR SELECT DISTINCT nazev FROM food600.sk_pol_a WHERE c_data=cdata AND (c_karty=0 OR c_karty IS NULL);
--	mdone SMALLINT DEFAULT 1;
--	mnazev CHARACTER(30);
BEGIN
--SELECT COUNT(c_karty) INTO mdone FROM food600.sk_pol WHERE sk_pol.c_karty=0 AND c_data=cdata;
--IF mdone>0 THEN 
--	UPDATE food600.sk_pol SET c_karty=karty.c_karty FROM food600.karty WHERE (sk_pol.c_karty=0 OR  sk_pol.c_karty IS NULL) AND sk_pol.c_data=cdata AND sk_pol.nazev=karty.nazev AND sk_pol.c_data=karty.c_data;
--	OPEN chyby;
--	WHILE (mdone>0) LOOP
--		FETCH chyby INTO mnazev;
--		IF mnazev ISNULL THEN
--			mdone:=0;
--		ELSE
--			INSERT INTO food600.karty (c_karty, nazev, nazev1,c_mena, c_mena_n, pocet, c_data) VALUES (food600.m_max(1,'karty'),mnazev,'xxx SMAZANO xxx',1,1,1, cdata);
--		END IF;
--	END LOOP;
--	CLOSE chyby;
--	UPDATE food600.sk_pol SET c_karty=karty.c_karty FROM food600.karty WHERE (sk_pol.c_karty=0 OR  sk_pol.c_karty IS NULL) AND sk_pol.c_data=cdata AND sk_pol.nazev=karty.nazev AND sk_pol.c_data=karty.c_data;
--END IF;
--
--SELECT COUNT(c_karty) INTO mdone FROM food600.sk_pol WHERE sk_pol.c_karty=0 AND c_data=cdata;
--IF mdone>0 THEN 
--	UPDATE food600.sk_pol_a SET c_karty=karty.c_karty FROM food600.karty WHERE (sk_pol_a.c_karty=0 OR  sk_pol_a.c_karty IS NULL) AND sk_pol_a.c_data=cdata AND sk_pol_a.nazev=karty.nazev AND sk_pol_a.c_data=karty.c_data;
--	OPEN chyby1;
--	WHILE (mdone>0) LOOP
--		FETCH chyby1 INTO mnazev;
--		IF mnazev ISNULL THEN
--			mdone:=0;
--		ELSE
--			INSERT INTO food600.karty (c_karty, nazev, nazev1,c_mena, c_mena_n, pocet, c_data) VALUES (food600.m_max(1,'karty'),mnazev,'xxx SMAZANO xxx',1,1,1, cdata);
--		END IF;
--	END LOOP;
--	CLOSE chyby1;
--	UPDATE food600.sk_pol_a SET c_karty=karty.c_karty FROM food600.karty WHERE (sk_pol_a.c_karty=0 OR  sk_pol_a.c_karty IS NULL) AND sk_pol_a.c_data=cdata AND sk_pol_a.nazev=karty.nazev AND sk_pol_a.c_data=karty.c_data;
--END IF;
RETURN 1;
END
$BODY$;
