CREATE OR REPLACE FUNCTION food600.kartysklmazaniezmazanych(
	cstredisk integer,
	cdata integer)
    RETURNS integer
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE
AS $BODY$
BEGIN
ALTER TABLE food600.sklad DISABLE TRIGGER ALL;
DELETE FROM food600.sklad WHERE sklad.c_stredisk=cstredisk AND sklad.c_data=cdata AND sklad.zustatek=0 AND c_karty NOT IN ( SELECT c_karty FROM food600.karty WHERE karty.c_data=cdata AND (NOT (karty.nazev1='xxx SMAZANO xxx')));
ALTER TABLE food600.sklad ENABLE TRIGGER ALL;
RETURN 1;
END
$BODY$;
