CREATE OR REPLACE FUNCTION food600.skupinyrozpatia_zmena()
    RETURNS trigger
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE NOT LEAKPROOF
AS $BODY$
DECLARE mcdruhk INTEGER;
	mrozp NUMERIC(8,2) DEFAULT 0;
	mhladina SMALLINT;
	nakup NUMERIC(12,4);
	predaj NUMERIC(12,4);
	cdata SMALLINT;
	newrozp NUMERIC(12,2);
	oldrozp NUMERIC(12,2);
	mcdruh INTEGER;
	mckarty INTEGER;
	newdan NUMERIC(5,2);
	mdone SMALLINT;
	typ SMALLINT DEFAULT 0;
	midriadok INTEGER;
	zoznamkariet CURSOR FOR SELECT c_karty FROM food600.karty WHERE c_druhk=mcdruh AND c_data=cdata;
BEGIN

IF (TG_OP = 'DELETE')THEN
	DELETE FROM food600.rozpatia WHERE c_data=OLD.c_data AND c_karty IN (SELECT c_karty FROM food600.karty WHERE c_druhk=OLD.c_druh AND c_data=OLD.c_data);
	RETURN OLD;
ELSE
	IF NEW.c_druh>0 THEN
		cdata:=NEW.c_data;
		mcdruh:=NEW.c_druh;
		IF cdata=0 OR cdata IS NULL THEN
			cdata:=1;
		END IF;
		mhladina:=0;
		WHILE mhladina<90 LOOP
			mhladina:=mhladina+1;
			CASE mhladina
				WHEN 1 THEN 
					SELECT dan01 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp01;
					END IF;
					newrozp:=NEW.rozp01;
				WHEN 2 THEN 
					SELECT dan02 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp02;
					END IF;
					newrozp:=NEW.rozp02;
				WHEN 3 THEN 
					SELECT dan03 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp03;
					END IF;
					newrozp:=NEW.rozp03;
				WHEN 4 THEN 
					SELECT dan04 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp04;
					END IF;
					newrozp:=NEW.rozp04;
				WHEN 5 THEN 
					SELECT dan05 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp05;
					END IF;
					newrozp:=NEW.rozp05;
				WHEN 6 THEN
					SELECT dan06 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp06;
					END IF;
					newrozp:=NEW.rozp06;
				WHEN 7 THEN 
					SELECT dan07 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp07;
					END IF;
					newrozp:=NEW.rozp07;
				WHEN 8 THEN
					SELECT dan08 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp08;
					END IF;
					newrozp:=NEW.rozp08;
				WHEN 9 THEN
					SELECT dan09 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp09;
					END IF;
					newrozp:=NEW.rozp09;
				WHEN 10 THEN
					SELECT dan10 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp10;
					END IF;
					newrozp:=NEW.rozp10;
				WHEN 11 THEN
					SELECT dan11 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp11;
					END IF;
					newrozp:=NEW.rozp11;
				WHEN 12 THEN
					SELECT dan12 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp12;
					END IF;
					newrozp:=NEW.rozp12;
				WHEN 13 THEN
					SELECT dan13 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp13;
					END IF;
					newrozp:=NEW.rozp13;
				WHEN 14 THEN
					SELECT dan14 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp14;
					END IF;
					newrozp:=NEW.rozp14;
				WHEN 15 THEN 
					SELECT dan15 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp15;
					END IF;
					newrozp:=NEW.rozp15;
				WHEN 16 THEN
					SELECT dan16 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp16;
					END IF;
					newrozp:=NEW.rozp16;
				WHEN 17 THEN
					SELECT dan17 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp17;
					END IF;
					newrozp:=NEW.rozp17;
				WHEN 18 THEN
					SELECT dan18 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp18;
					END IF;
					newrozp:=NEW.rozp18;
				WHEN 19 THEN
					SELECT dan19 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp19;
					END IF;
					newrozp:=NEW.rozp19;
				WHEN 20 THEN
					SELECT dan20 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp20;
					END IF;
					newrozp:=NEW.rozp20;
				WHEN 21 THEN
					SELECT dan21 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp21;
					END IF;
					newrozp:=NEW.rozp21;
				WHEN 22 THEN
					SELECT dan22 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp22;
					END IF;
					newrozp:=NEW.rozp22;
				WHEN 23 THEN
					SELECT dan23 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp23;
					END IF;
					newrozp:=NEW.rozp23;
				WHEN 24 THEN
					SELECT dan24 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp24;
					END IF;
					newrozp:=NEW.rozp24;
				WHEN 25 THEN
					SELECT dan25 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp25;
					END IF;
					newrozp:=NEW.rozp25;
				WHEN 26 THEN
					SELECT dan26 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp26;
					END IF;
					newrozp:=NEW.rozp26;
				WHEN 27 THEN
					SELECT dan27 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp27;
					END IF;
					newrozp:=NEW.rozp27;
				WHEN 28 THEN
					SELECT dan28 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp28;
					END IF;
					newrozp:=NEW.rozp28;
				WHEN 29 THEN
					SELECT dan29 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp29;
					END IF;
					newrozp:=NEW.rozp29;
				WHEN 30 THEN
					SELECT dan30 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp30;
					END IF;
					newrozp:=NEW.rozp30;
				WHEN 31 THEN
					SELECT dan31 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp31;
					END IF;
					newrozp:=NEW.rozp31;
				WHEN 32 THEN
					SELECT dan32 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp32;
					END IF;
					newrozp:=NEW.rozp32;
				WHEN 33 THEN
					SELECT dan33 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp33;
					END IF;
					newrozp:=NEW.rozp33;
				WHEN 34 THEN
					SELECT dan34 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp34;
					END IF;
					newrozp:=NEW.rozp34;
				WHEN 35 THEN
					SELECT dan35 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp35;
					END IF;
					newrozp:=NEW.rozp35;
				WHEN 36 THEN
					SELECT dan36 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp36;
					END IF;
					newrozp:=NEW.rozp36;
				WHEN 37 THEN
					SELECT dan37 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp37;
					END IF;
					newrozp:=NEW.rozp37;
				WHEN 38 THEN
					SELECT dan38 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp38;
					END IF;
					newrozp:=NEW.rozp38;
				WHEN 39 THEN
					SELECT dan39 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp39;
					END IF;
					newrozp:=NEW.rozp39;
				WHEN 40 THEN
					SELECT dan40 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozp40;
					END IF;
					newrozp:=NEW.rozp40;
				WHEN 41 THEN
					SELECT dana0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpa0;
					END IF;
					newrozp:=NEW.rozpa0;
				WHEN 42 THEN
					SELECT dana1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpa1;
					END IF;
					newrozp:=NEW.rozpa1;
				WHEN 43 THEN
					SELECT dana2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpa2;
					END IF;
					newrozp:=NEW.rozpa2;
				WHEN 44 THEN
					SELECT dana3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpa3;
					END IF;
					newrozp:=NEW.rozpa3;
				WHEN 45 THEN
					SELECT dana4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpa4;
					END IF;
					newrozp:=NEW.rozpa4;
				WHEN 46 THEN
					SELECT dana5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpa5;
					END IF;
					newrozp:=NEW.rozpa5;
				WHEN 47 THEN
					SELECT dana6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpa6;
					END IF;
					newrozp:=NEW.rozpa6;
				WHEN 48 THEN
					SELECT dana7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpa7;
					END IF;
					newrozp:=NEW.rozpa7;
				WHEN 49 THEN
					SELECT dana8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpa8;
					END IF;
					newrozp:=NEW.rozpa8;
				WHEN 50 THEN
					SELECT dana9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpa9;
					END IF;
					newrozp:=NEW.rozpa9;
				WHEN 51 THEN
					SELECT danb0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpb0;
					END IF;
					newrozp:=NEW.rozpb0;
				WHEN 52 THEN
					SELECT danb1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpb1;
					END IF;
					newrozp:=NEW.rozpb1;
				WHEN 53 THEN
					SELECT danb2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpb2;
					END IF;
					newrozp:=NEW.rozpb2;
				WHEN 54 THEN
					SELECT danb3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpb3;
					END IF;
					newrozp:=NEW.rozpb3;
				WHEN 55 THEN
					SELECT danb4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpb4;
					END IF;
					newrozp:=NEW.rozpb4;
				WHEN 56 THEN
					SELECT danb5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpb5;
					END IF;
					newrozp:=NEW.rozpb5;
				WHEN 57 THEN
					SELECT danb6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpb6;
					END IF;
					newrozp:=NEW.rozpb6;
				WHEN 58 THEN
					SELECT danb7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpb7;
					END IF;
					newrozp:=NEW.rozpb7;
				WHEN 59 THEN
					SELECT danb8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpb8;
					END IF;
					newrozp:=NEW.rozpb8;
				WHEN 60 THEN
					SELECT danb9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpb9;
					END IF;
					newrozp:=NEW.rozpb9;
				WHEN 61 THEN
					SELECT danc0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpc0;
					END IF;
					newrozp:=NEW.rozpc0;
				WHEN 62 THEN
					SELECT danc1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpc1;
					END IF;
					newrozp:=NEW.rozpc1;
				WHEN 63 THEN
					SELECT danc2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpc2;
					END IF;
					newrozp:=NEW.rozpc2;
				WHEN 64 THEN
					SELECT danc3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpc3;
					END IF;
					newrozp:=NEW.rozpc3;
				WHEN 65 THEN
					SELECT danc4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpc4;
					END IF;
					newrozp:=NEW.rozpc4;
				WHEN 66 THEN
					SELECT danc5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpc5;
					END IF;
					newrozp:=NEW.rozpc5;
				WHEN 67 THEN
					SELECT danc6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpc6;
					END IF;
					newrozp:=NEW.rozpc6;
				WHEN 68 THEN
					SELECT danc7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpc7;
					END IF;
					newrozp:=NEW.rozpc7;
				WHEN 69 THEN
					SELECT danc8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpc8;
					END IF;
					newrozp:=NEW.rozpc8;
				WHEN 70 THEN
					SELECT danc9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpc9;
					END IF;
					newrozp:=NEW.rozpc9;
				WHEN 71 THEN
					SELECT dand0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpd0;
					END IF;
					newrozp:=NEW.rozpd0;
				WHEN 72 THEN
					SELECT dand1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpd1;
					END IF;
					newrozp:=NEW.rozpd1;
				WHEN 73 THEN
					SELECT dand2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpd2;
					END IF;
					newrozp:=NEW.rozpd2;
				WHEN 74 THEN
					SELECT dand3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpd3;
					END IF;
					newrozp:=NEW.rozpd3;
				WHEN 75 THEN
					SELECT dand4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpd4;
					END IF;
					newrozp:=NEW.rozpd4;
				WHEN 76 THEN
					SELECT dand5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpd5;
					END IF;
					newrozp:=NEW.rozpd5;
				WHEN 77 THEN
					SELECT dand6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpd6;
					END IF;
					newrozp:=NEW.rozpd6;
				WHEN 78 THEN
					SELECT dand7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpd7;
					END IF;
					newrozp:=NEW.rozpd7;
				WHEN 79 THEN
					SELECT dand8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpd8;
					END IF;
					newrozp:=NEW.rozpd8;
				WHEN 80 THEN
					SELECT dand9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpd9;
					END IF;
					newrozp:=NEW.rozpd9;
				WHEN 81 THEN
					SELECT dane0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpe0;
					END IF;
					newrozp:=NEW.rozpe0;
				WHEN 82 THEN
					SELECT dane1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpe1;
					END IF;
					newrozp:=NEW.rozpe1;
				WHEN 83 THEN
					SELECT dane2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpe2;
					END IF;
					newrozp:=NEW.rozpe2;
				WHEN 84 THEN
					SELECT dane3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpe3;
					END IF;
					newrozp:=NEW.rozpe3;
				WHEN 85 THEN
					SELECT dane4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpe4;
					END IF;
					newrozp:=NEW.rozpe4;
				WHEN 86 THEN
					SELECT dane5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpe5;
					END IF;
					newrozp:=NEW.rozpe5;
				WHEN 87 THEN 
					SELECT dane6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpe6;
					END IF;
					newrozp:=NEW.rozpe6;
				WHEN 88 THEN
					SELECT dane7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpe7;
					END IF;
					newrozp:=NEW.rozpe7;
				WHEN 89 THEN
					SELECT dane8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpe8;
					END IF;
					newrozp:=NEW.rozpe9;
				WHEN 90 THEN
					SELECT dane9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpe9;
					END IF;
					newrozp:=NEW.rozpe9;
				WHEN 91 THEN
					SELECT danf0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpf0;
					END IF;
					newrozp:=NEW.rozpf0;
				WHEN 92 THEN
					SELECT danf1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpf1;
					END IF;
					newrozp:=NEW.rozpf1;
				WHEN 93 THEN
					SELECT danf2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpf2;
					END IF;
					newrozp:=NEW.rozpf2;
				WHEN 94 THEN
					SELECT danf3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpf3;
					END IF;
					newrozp:=NEW.rozpf3;
				WHEN 95 THEN
					SELECT danf4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpf4;
					END IF;
					newrozp:=NEW.rozpf4;
				WHEN 96 THEN
					SELECT danf5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpf5;
					END IF;
					newrozp:=NEW.rozpf5;
				WHEN 97 THEN 
					SELECT danf6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpf6;
					END IF;
					newrozp:=NEW.rozpf6;
				WHEN 98 THEN
					SELECT danf7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpf7;
					END IF;
					newrozp:=NEW.rozpf7;
				WHEN 99 THEN
					SELECT danf8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpf8;
					END IF;
					newrozp:=NEW.rozpf9;
				WHEN 100 THEN
					SELECT danf9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpf9;
					END IF;
					newrozp:=NEW.rozpf9;
				WHEN 101 THEN
					SELECT dang0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpg0;
					END IF;
					newrozp:=NEW.rozpg0;
				WHEN 102 THEN
					SELECT dang1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpg1;
					END IF;
					newrozp:=NEW.rozpg1;
				WHEN 103 THEN
					SELECT dang2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpg2;
					END IF;
					newrozp:=NEW.rozpg2;
				WHEN 104 THEN
					SELECT dang3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpg3;
					END IF;
					newrozp:=NEW.rozpg3;
				WHEN 105 THEN
					SELECT dang4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpg4;
					END IF;
					newrozp:=NEW.rozpg4;
				WHEN 106 THEN
					SELECT dang5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpg5;
					END IF;
					newrozp:=NEW.rozpg5;
				WHEN 107 THEN 
					SELECT dang6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpg6;
					END IF;
					newrozp:=NEW.rozpg6;
				WHEN 108 THEN
					SELECT dang7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpg7;
					END IF;
					newrozp:=NEW.rozpg7;
				WHEN 109 THEN
					SELECT dang8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpg8;
					END IF;
					newrozp:=NEW.rozpg9;
				WHEN 110 THEN
					SELECT dang9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpg9;
					END IF;
					newrozp:=NEW.rozpg9;
				WHEN 111 THEN
					SELECT danh0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozph0;
					END IF;
					newrozp:=NEW.rozph0;
				WHEN 112 THEN
					SELECT danh1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozph1;
					END IF;
					newrozp:=NEW.rozph1;
				WHEN 113 THEN
					SELECT danh2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozph2;
					END IF;
					newrozp:=NEW.rozph2;
				WHEN 114 THEN
					SELECT danh3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozph3;
					END IF;
					newrozp:=NEW.rozph3;
				WHEN 115 THEN
					SELECT danh4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozph4;
					END IF;
					newrozp:=NEW.rozph4;
				WHEN 116 THEN
					SELECT danh5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozph5;
					END IF;
					newrozp:=NEW.rozph5;
				WHEN 117 THEN 
					SELECT danh6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozph6;
					END IF;
					newrozp:=NEW.rozph6;
				WHEN 118 THEN
					SELECT danh7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozph7;
					END IF;
					newrozp:=NEW.rozph7;
				WHEN 119 THEN
					SELECT danh8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozph8;
					END IF;
					newrozp:=NEW.rozph9;
				WHEN 120 THEN
					SELECT danh9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozph9;
					END IF;
					newrozp:=NEW.rozph9;
				WHEN 121 THEN
					SELECT dani0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpi0;
					END IF;
					newrozp:=NEW.rozpi0;
				WHEN 122 THEN
					SELECT dani1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpi1;
					END IF;
					newrozp:=NEW.rozpi1;
				WHEN 123 THEN
					SELECT dani2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpi2;
					END IF;
					newrozp:=NEW.rozpi2;
				WHEN 124 THEN
					SELECT dani3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpi3;
					END IF;
					newrozp:=NEW.rozpi3;
				WHEN 125 THEN
					SELECT dani4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpi4;
					END IF;
					newrozp:=NEW.rozpi4;
				WHEN 126 THEN
					SELECT dani5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpi5;
					END IF;
					newrozp:=NEW.rozpi5;
				WHEN 127 THEN 
					SELECT dani6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpi6;
					END IF;
					newrozp:=NEW.rozpi6;
				WHEN 128 THEN
					SELECT dani7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpi7;
					END IF;
					newrozp:=NEW.rozpi7;
				WHEN 129 THEN
					SELECT dani8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpi8;
					END IF;
					newrozp:=NEW.rozpi9;
				WHEN 130 THEN
					SELECT dani9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpi9;
					END IF;
					newrozp:=NEW.rozpi9;
				WHEN 131 THEN
					SELECT danj0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpj0;
					END IF;
					newrozp:=NEW.rozpj0;
				WHEN 132 THEN
					SELECT danj1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpj1;
					END IF;
					newrozp:=NEW.rozpj1;
				WHEN 133 THEN
					SELECT danj2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpj2;
					END IF;
					newrozp:=NEW.rozpj2;
				WHEN 134 THEN
					SELECT danj3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpj3;
					END IF;
					newrozp:=NEW.rozpj3;
				WHEN 135 THEN
					SELECT danj4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpj4;
					END IF;
					newrozp:=NEW.rozpj4;
				WHEN 136 THEN
					SELECT danj5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpj5;
					END IF;
					newrozp:=NEW.rozpj5;
				WHEN 137 THEN 
					SELECT danj6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpj6;
					END IF;
					newrozp:=NEW.rozpj6;
				WHEN 138 THEN
					SELECT danj7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpj7;
					END IF;
					newrozp:=NEW.rozpj7;
				WHEN 139 THEN
					SELECT danj8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpj8;
					END IF;
					newrozp:=NEW.rozpj9;
				WHEN 140 THEN
					SELECT danj9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpj9;
					END IF;
					newrozp:=NEW.rozpj9;
				WHEN 141 THEN
					SELECT dank0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpk0;
					END IF;
					newrozp:=NEW.rozpk0;
				WHEN 142 THEN
					SELECT dank1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpk1;
					END IF;
					newrozp:=NEW.rozpk1;
				WHEN 143 THEN
					SELECT dank2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpk2;
					END IF;
					newrozp:=NEW.rozpk2;
				WHEN 144 THEN
					SELECT dank3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpk3;
					END IF;
					newrozp:=NEW.rozpk3;
				WHEN 145 THEN
					SELECT dank4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpk4;
					END IF;
					newrozp:=NEW.rozpk4;
				WHEN 146 THEN
					SELECT dank5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpk5;
					END IF;
					newrozp:=NEW.rozpk5;
				WHEN 147 THEN 
					SELECT dank6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpk6;
					END IF;
					newrozp:=NEW.rozpk6;
				WHEN 148 THEN
					SELECT dank7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpk7;
					END IF;
					newrozp:=NEW.rozpk7;
				WHEN 149 THEN
					SELECT dank8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpk8;
					END IF;
					newrozp:=NEW.rozpk9;
				WHEN 150 THEN
					SELECT dank9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpk9;
					END IF;
					newrozp:=NEW.rozpk9;
				WHEN 151 THEN
					SELECT danl0 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpl0;
					END IF;
					newrozp:=NEW.rozpl0;
				WHEN 152 THEN
					SELECT danl1 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpl1;
					END IF;
					newrozp:=NEW.rozpl1;
				WHEN 153 THEN
					SELECT danl2 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpl2;
					END IF;
					newrozp:=NEW.rozpl2;
				WHEN 154 THEN
					SELECT danl3 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpl3;
					END IF;
					newrozp:=NEW.rozpl3;
				WHEN 155 THEN
					SELECT danl4 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpl4;
					END IF;
					newrozp:=NEW.rozpl4;
				WHEN 156 THEN
					SELECT danl5 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpl5;
					END IF;
					newrozp:=NEW.rozpl5;
				WHEN 157 THEN 
					SELECT danl6 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpl6;
					END IF;
					newrozp:=NEW.rozpl6;
				WHEN 158 THEN
					SELECT danl7 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpl7;
					END IF;
					newrozp:=NEW.rozpl7;
				WHEN 159 THEN
					SELECT danl8 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpl8;
					END IF;
					newrozp:=NEW.rozpl9;
				WHEN 160 THEN
					SELECT danl9 INTO newdan FROM food600.skupiny WHERE c_data=cdata AND c_druh=mcdruh;
					IF (TG_OP = 'INSERT')THEN
						oldrozp:=0;
					ELSE
						oldrozp:=OLD.rozpl9;
					END IF;
					newrozp:=NEW.rozpl9;
			END CASE;
			IF newrozp=0 THEN
				DELETE FROM food600.rozpatia WHERE hladina=mhladina AND c_data=cdata AND c_karty IN (SELECT c_karty FROM food600.karty WHERE c_druhk=mcdruh AND c_data=cdata);				
			ELSE
				IF oldrozp<>newrozp THEN 
					OPEN zoznamkariet;
					mdone:=1;
					WHILE mdone>0 LOOP
						FETCH zoznamkariet INTO mckarty;
						IF mckarty ISNULL THEN
							mdone:=0;
						END IF;
						IF mhladina<=40 THEN
							SELECT cena_prum, CASE mhladina WHEN 1 THEN cena01
								WHEN 2 THEN cena02
								WHEN 3 THEN cena03
								WHEN 4 THEN cena04
								WHEN 5 THEN cena05
								WHEN 6 THEN cena06
								WHEN 7 THEN cena07
								WHEN 8 THEN cena08
								WHEN 9 THEN cena09
								WHEN 10 THEN cena10
								WHEN 11 THEN cena11
								WHEN 12 THEN cena12
								WHEN 13 THEN cena13
								WHEN 14 THEN cena14
								WHEN 15 THEN cena15
								WHEN 16 THEN cena16
								WHEN 17 THEN cena17
								WHEN 18 THEN cena18
								WHEN 19 THEN cena19
								WHEN 20 THEN cena20
								WHEN 21 THEN cena21
								WHEN 22 THEN cena22
								WHEN 23 THEN cena23
								WHEN 24 THEN cena24
								WHEN 25 THEN cena25
								WHEN 26 THEN cena26
								WHEN 27 THEN cena27
								WHEN 28 THEN cena28
								WHEN 29 THEN cena29
								WHEN 30 THEN cena30
								WHEN 31 THEN cena31
								WHEN 32 THEN cena32
								WHEN 33 THEN cena33
								WHEN 34 THEN cena34
								WHEN 35 THEN cena35
								WHEN 36 THEN cena36
								WHEN 37 THEN cena37
								WHEN 38 THEN cena38
								WHEN 39 THEN cena39
								WHEN 40 THEN cena40
								END
								INTO nakup, predaj FROM food600.karty WHERE c_karty=mckarty AND c_data=cdata;
						ELSE
							SELECT cena_prum INTO nakup FROM food600.karty WHERE c_karty=mckarty AND c_data=cdata;
							SELECT CASE mhladina WHEN 41 THEN cenaa0
								WHEN 42 THEN cenaa1
								WHEN 43 THEN cenaa2
								WHEN 44 THEN cenaa3
								WHEN 45 THEN cenaa4
								WHEN 46 THEN cenaa5
								WHEN 47 THEN cenaa6
								WHEN 48 THEN cenaa7
								WHEN 49 THEN cenaa8
								WHEN 50 THEN cenaa9
								WHEN 51 THEN cenab0
								WHEN 52 THEN cenab1
								WHEN 53 THEN cenab2
								WHEN 54 THEN cenab3
								WHEN 55 THEN cenab4
								WHEN 56 THEN cenab5
								WHEN 57 THEN cenab6
								WHEN 58 THEN cenab7
								WHEN 59 THEN cenab8
								WHEN 60 THEN cenab9
								WHEN 61 THEN cenac0
								WHEN 62 THEN cenac1
								WHEN 63 THEN cenac2
								WHEN 64 THEN cenac3
								WHEN 65 THEN cenac4
								WHEN 66 THEN cenac5
								WHEN 67 THEN cenac6
								WHEN 68 THEN cenac7
								WHEN 69 THEN cenac8
								WHEN 70 THEN cenac9
								WHEN 71 THEN cenad0
								WHEN 72 THEN cenad1
								WHEN 73 THEN cenad2
								WHEN 74 THEN cenad3
								WHEN 75 THEN cenad4
								WHEN 76 THEN cenad5
								WHEN 77 THEN cenad6
								WHEN 78 THEN cenad7
								WHEN 79 THEN cenad8
								WHEN 80 THEN cenad9
								WHEN 81 THEN cenae0
								WHEN 82 THEN cenae1
								WHEN 83 THEN cenae2
								WHEN 84 THEN cenae3
								WHEN 85 THEN cenae4
								WHEN 86 THEN cenae5
								WHEN 87 THEN cenae6
								WHEN 88 THEN cenae7
								WHEN 89 THEN cenae8
								WHEN 90 THEN cenae9
								WHEN 91 THEN cenaf0
								WHEN 92 THEN cenaf1
								WHEN 93 THEN cenaf2
								WHEN 94 THEN cenaf3
								WHEN 95 THEN cenaf4
								WHEN 96 THEN cenaf5
								WHEN 97 THEN cenaf6
								WHEN 98 THEN cenaf7
								WHEN 99 THEN cenaf8
								WHEN 100 THEN cenaf9
								WHEN 101 THEN cenag0
								WHEN 102 THEN cenag1
								WHEN 103 THEN cenag2
								WHEN 104 THEN cenag3
								WHEN 105 THEN cenag4
								WHEN 106 THEN cenag5
								WHEN 107 THEN cenag6
								WHEN 108 THEN cenag7
								WHEN 109 THEN cenag8
								WHEN 110 THEN cenag9
								WHEN 111 THEN cenah0
								WHEN 112 THEN cenah1
								WHEN 113 THEN cenah2
								WHEN 114 THEN cenah3
								WHEN 115 THEN cenah4
								WHEN 116 THEN cenah5
								WHEN 117 THEN cenah6
								WHEN 118 THEN cenah7
								WHEN 119 THEN cenah8
								WHEN 120 THEN cenah9
								WHEN 121 THEN cenai0
								WHEN 122 THEN cenai1
								WHEN 123 THEN cenai2
								WHEN 124 THEN cenai3
								WHEN 125 THEN cenai4
								WHEN 126 THEN cenai5
								WHEN 127 THEN cenai6
								WHEN 128 THEN cenai7
								WHEN 129 THEN cenai8
								WHEN 130 THEN cenai9
								WHEN 131 THEN cenaj0
								WHEN 132 THEN cenaj1
								WHEN 133 THEN cenaj2
								WHEN 134 THEN cenaj3
								WHEN 135 THEN cenaj4
								WHEN 136 THEN cenaj5
								WHEN 137 THEN cenaj6
								WHEN 138 THEN cenaj7
								WHEN 139 THEN cenaj8
								WHEN 140 THEN cenaj9
								WHEN 141 THEN cenak0
								WHEN 142 THEN cenak1
								WHEN 143 THEN cenak2
								WHEN 144 THEN cenak3
								WHEN 145 THEN cenak4
								WHEN 146 THEN cenak5
								WHEN 147 THEN cenak6
								WHEN 148 THEN cenak7
								WHEN 149 THEN cenak8
								WHEN 150 THEN cenak9
								WHEN 151 THEN cenal0
								WHEN 152 THEN cenal1
								WHEN 153 THEN cenal2
								WHEN 154 THEN cenal3
								WHEN 155 THEN cenal4
								WHEN 156 THEN cenal5
								WHEN 157 THEN cenal6
								WHEN 158 THEN cenal7
								WHEN 159 THEN cenal8
								WHEN 160 THEN cenal9
							END
								INTO predaj FROM food600.kceny WHERE c_karty=mckarty AND c_data=cdata;
						END IF;
						IF newdan=0 THEN
							newdan:=1;
						END IF;
						IF predaj<>0 AND nakup<>0 THEN
							IF typ=0 THEN
								IF food600.dajvarnamelogical('FOOD_SET','','is_spanne')=1 THEN
									typ:=3;
								ELSE
									IF food600.dajvarnamelogical('FOOD_SET','','isfoodcost')=1 THEN
										typ:=2;
									ELSE							
										typ:=1;
									END IF;
								END IF;
							END IF;
							mrozp:=food600.spocitajrozpatie(predaj, newdan, nakup, typ);
							IF newrozp>0 AND mrozp<newrozp THEN 
								SELECT idriadok INTO midriadok FROM food600.rozpatia WHERE c_karty=mckarty AND hladina=mhladina AND c_data=cdata;
								IF midriadok  IS NULL THEN
									INSERT INTO food600.rozpatia (c_karty, hladina, rozp, rozp_ciel, c_data) VALUES (mckarty, mhladina, mrozp, newrozp, cdata);
								ELSE
									UPDATE food600.rozpatia SET rozp=mrozp, rozp_ciel=newrozp WHERE rozpatia.c_karty=mckarty AND rozpatia.hladina=mhladina AND rozpatia.c_data=cdata;
								END IF;
							ELSE
								DELETE FROM food600.rozpatia WHERE c_karty=mckarty AND hladina=mhladina AND c_data=cdata;				
							END IF;
						ELSE
							DELETE FROM food600.rozpatia WHERE c_karty=mckarty AND hladina=mhladina AND c_data=cdata;
						END IF;
					END LOOP;
					CLOSE zoznamkariet;
				END IF;
			END IF;
		END LOOP;
	END IF;
	RETURN NEW;
END IF;
RETURN NEW;
END
$BODY$;
