CREATE OR REPLACE FUNCTION food600.vypocty_zmena()
    RETURNS trigger
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE NOT LEAKPROOF
AS $BODY$
DECLARE
ret CHARACTER VARYING;
ret_master CHARACTER VARYING;
polia CHARACTER VARYING DEFAULT '';
polia_master CHARACTER VARYING DEFAULT '';
hodnoty CHARACTER VARYING DEFAULT '';
hodnoty_master CHARACTER VARYING DEFAULT '';
pocetzmien INTEGER DEFAULT 0;
robsync SMALLINT DEFAULT 0;
mp1 CHARACTER VARYING DEFAULT '';
mp2 CHARACTER VARYING DEFAULT '';
mp3 CHARACTER VARYING DEFAULT '';
mp4 CHARACTER VARYING DEFAULT '';
mp5 CHARACTER VARYING DEFAULT '';
mp6 CHARACTER VARYING DEFAULT '';
mp1_master CHARACTER VARYING DEFAULT '';
mp2_master CHARACTER VARYING DEFAULT '';
mp3_master CHARACTER VARYING DEFAULT '';
mp4_master CHARACTER VARYING DEFAULT '';
mp5_master CHARACTER VARYING DEFAULT '';
mp6_master CHARACTER VARYING DEFAULT '';
mojeid INTEGER;
mojmaster INTEGER;
sommaster INTEGER DEFAULT 0;
posunhore INTEGER DEFAULT 0;
idnazapis_slavom INTEGER;
idnazapis_mastrovi INTEGER;
BEGIN
SELECT idriadok, id_master INTO mojeid, mojmaster  FROM food600.sync_set WHERE tosomja>0;
IF mojeid IS NULL THEN
	--- V nastavovacej tabulke sa nenachadza moj zaznam, synchronizacia sa nerobi
	mojeid:=0;
	robsync:=0;
	mojmaster:=0;
	sommaster:=0;
ELSE 
	--- V nastavovacej tabulke sa nenachadza moj zaznam, nejako je vyplneny aj mojmaster
	SELECT idriadok INTO sommaster FROM food600.sync_set WHERE tosomja=0 AND id_master=mojeid;
	--- Zistim, ci som master pre nejaky iny server
	IF sommaster IS NULL THEN
		sommaster:=0;
	END IF;
	robsync:=sommaster+mojmaster;
	--- Synchronizaciu robim ak som master, alebo mam mastera
	IF robsync > 0 THEN 
		--- Este treba overit, ci tuto tabulku vobec treba synchronizovat
		SELECT smer INTO robsync FROM food600.sync_tables WHERE LOWER(BTRIM(tabulka))=LOWER(TG_TABLE_NAME);
		IF robsync IS NULL THEN
			robsync:=0;
		END IF;
	END IF;
END IF;
IF (TG_OP = 'UPDATE') THEN
	IF robsync>0 AND new.c_druh>=0 THEN
		IF NEW.id_sync IS NULL OR NEW.id_sync=0 THEN
			--- Ak nebol vyplneny id_sync, islo o zaznam, ktory vznikol na tomto PC (z FoodManu)
			idnazapis_slavom:=mojeid;
			idnazapis_mastrovi:=mojeid;
		ELSE
			--- Ak bol id_sync vyplneny, musel zaznam prist od slave alebo od mastera. Dalsim slavom budem posuvat originalne id, aby si povodny autor zaznamu uz tuto zmenu nemusel stahovat
			idnazapis_slavom:=NEW.id_sync;
			IF mojmaster>0 THEN
				IF idnazapis_slavom IN (SELECT idriadok FROM food600.sync_set WHERE id_master=mojeid) THEN
					idnazapis_mastrovi:=mojeid;
				ELSE
					idnazapis_mastrovi:=idnazapis_slavom;
				END IF;
			END IF;
		END IF;
		--- Mastrovi sa posuvaju moje zaznamy a zaznamy mojich slavov a posuvam mu moje id (nevracaju sa nazad zaznamy, ktore prisli zhora)
		IF mojmaster>0 THEN
			IF mojeid=idnazapis_slavom THEN
				posunhore:=1;
			ELSE
				IF idnazapis_slavom IN (SELECT idriadok FROM food600.sync_set WHERE id_master=mojeid) THEN
					posunhore:=1;
				ELSE
					posunhore:=0;
				END IF;
			END IF;
		ELSE
			posunhore:=0;
		END IF;
		--- id_sync na riadok aj tak nezapisem
		NEW.id_sync:=0;
		ret:='UPDATE food600.vypocty SET ';
		ret_master:=ret;
		IF (NEW.c_druh != OLD.c_druh) THEN
			IF pocetzmien>0 THEN
				ret:=ret||',';
				ret_master:=ret_master||',';
			END IF;
			IF NEW.c_druh>0 THEN
				ret:=ret||'c_druh=%P2%';
				mp2:='getcdruhmaster('||btrim(new.c_druh::CHARACTER(20))||')';
				ret_master:=ret_master||'c_druh=%P2%';
				mp2_master:='getcdruhslave('||btrim(new.c_druh::CHARACTER(20))||')';
			ELSE
				ret:=ret||'c_druh=0';
				ret_master:=ret_master||'c_druh=0';
			END IF;
			pocetzmien:=pocetzmien+1;
		END IF; 
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.c_data::CHARACTER(20)), btrim(NEW.c_data::CHARACTER(20)), pocetzmien, ret, ret_master, 'c_data') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.druh, NEW.druh, pocetzmien, ret, ret_master, 'druh') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.typ_kalk, NEW.typ_kalk, pocetzmien, ret, ret_master, 'typ_kalk') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.spart_kas, NEW.spart_kas, pocetzmien, ret, ret_master, 'spart_kas') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.dan01::CHARACTER(20)), btrim(NEW.dan01::CHARACTER(20)), pocetzmien, ret, ret_master, 'dan01') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet01, NEW.vypocet01, pocetzmien, ret, ret_master, 'vypocet01') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet02, NEW.vypocet02, pocetzmien, ret, ret_master, 'vypocet02') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet03, NEW.vypocet03, pocetzmien, ret, ret_master, 'vypocet03') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet04, NEW.vypocet04, pocetzmien, ret, ret_master, 'vypocet04') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet05, NEW.vypocet05, pocetzmien, ret, ret_master, 'vypocet05') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet06, NEW.vypocet06, pocetzmien, ret, ret_master, 'vypocet06') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet07, NEW.vypocet07, pocetzmien, ret, ret_master, 'vypocet07') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet08, NEW.vypocet08, pocetzmien, ret, ret_master, 'vypocet08') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet09, NEW.vypocet09, pocetzmien, ret, ret_master, 'vypocet09') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet10, NEW.vypocet10, pocetzmien, ret, ret_master, 'vypocet10') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet11, NEW.vypocet11, pocetzmien, ret, ret_master, 'vypocet11') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet12, NEW.vypocet12, pocetzmien, ret, ret_master, 'vypocet12') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet13, NEW.vypocet13, pocetzmien, ret, ret_master, 'vypocet13') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet14, NEW.vypocet14, pocetzmien, ret, ret_master, 'vypocet14') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet15, NEW.vypocet15, pocetzmien, ret, ret_master, 'vypocet15') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet16, NEW.vypocet16, pocetzmien, ret, ret_master, 'vypocet16') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet17, NEW.vypocet17, pocetzmien, ret, ret_master, 'vypocet17') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet18, NEW.vypocet18, pocetzmien, ret, ret_master, 'vypocet18') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet19, NEW.vypocet19, pocetzmien, ret, ret_master, 'vypocet19') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet20, NEW.vypocet20, pocetzmien, ret, ret_master, 'vypocet20') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet21, NEW.vypocet21, pocetzmien, ret, ret_master, 'vypocet21') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet22, NEW.vypocet22, pocetzmien, ret, ret_master, 'vypocet22') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet23, NEW.vypocet23, pocetzmien, ret, ret_master, 'vypocet23') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet24, NEW.vypocet24, pocetzmien, ret, ret_master, 'vypocet24') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet25, NEW.vypocet25, pocetzmien, ret, ret_master, 'vypocet25') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet26, NEW.vypocet26, pocetzmien, ret, ret_master, 'vypocet26') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet27, NEW.vypocet27, pocetzmien, ret, ret_master, 'vypocet27') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet28, NEW.vypocet28, pocetzmien, ret, ret_master, 'vypocet28') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet29, NEW.vypocet29, pocetzmien, ret, ret_master, 'vypocet29') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet30, NEW.vypocet30, pocetzmien, ret, ret_master, 'vypocet30') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet31, NEW.vypocet31, pocetzmien, ret, ret_master, 'vypocet31') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet32, NEW.vypocet32, pocetzmien, ret, ret_master, 'vypocet32') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet33, NEW.vypocet33, pocetzmien, ret, ret_master, 'vypocet33') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet34, NEW.vypocet34, pocetzmien, ret, ret_master, 'vypocet34') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet35, NEW.vypocet35, pocetzmien, ret, ret_master, 'vypocet35') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet36, NEW.vypocet36, pocetzmien, ret, ret_master, 'vypocet36') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet37, NEW.vypocet37, pocetzmien, ret, ret_master, 'vypocet37') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet38, NEW.vypocet38, pocetzmien, ret, ret_master, 'vypocet38') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet39, NEW.vypocet39, pocetzmien, ret, ret_master, 'vypocet39') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet40, NEW.vypocet40, pocetzmien, ret, ret_master, 'vypocet40') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet41, NEW.vypocet41, pocetzmien, ret, ret_master, 'vypocet41') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet42, NEW.vypocet42, pocetzmien, ret, ret_master, 'vypocet42') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet43, NEW.vypocet43, pocetzmien, ret, ret_master, 'vypocet43') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet44, NEW.vypocet44, pocetzmien, ret, ret_master, 'vypocet44') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet45, NEW.vypocet45, pocetzmien, ret, ret_master, 'vypocet45') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet46, NEW.vypocet46, pocetzmien, ret, ret_master, 'vypocet46') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet47, NEW.vypocet47, pocetzmien, ret, ret_master, 'vypocet47') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet48, NEW.vypocet48, pocetzmien, ret, ret_master, 'vypocet48') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet49, NEW.vypocet49, pocetzmien, ret, ret_master, 'vypocet49') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet50, NEW.vypocet50, pocetzmien, ret, ret_master, 'vypocet50') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet51, NEW.vypocet51, pocetzmien, ret, ret_master, 'vypocet51') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet52, NEW.vypocet52, pocetzmien, ret, ret_master, 'vypocet52') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet53, NEW.vypocet53, pocetzmien, ret, ret_master, 'vypocet53') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet54, NEW.vypocet54, pocetzmien, ret, ret_master, 'vypocet54') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet55, NEW.vypocet55, pocetzmien, ret, ret_master, 'vypocet55') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet56, NEW.vypocet56, pocetzmien, ret, ret_master, 'vypocet56') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet57, NEW.vypocet57, pocetzmien, ret, ret_master, 'vypocet57') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet58, NEW.vypocet58, pocetzmien, ret, ret_master, 'vypocet58') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet59, NEW.vypocet59, pocetzmien, ret, ret_master, 'vypocet59') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet60, NEW.vypocet60, pocetzmien, ret, ret_master, 'vypocet60') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet61, NEW.vypocet61, pocetzmien, ret, ret_master, 'vypocet61') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet62, NEW.vypocet62, pocetzmien, ret, ret_master, 'vypocet62') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet63, NEW.vypocet63, pocetzmien, ret, ret_master, 'vypocet63') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet64, NEW.vypocet64, pocetzmien, ret, ret_master, 'vypocet64') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet65, NEW.vypocet65, pocetzmien, ret, ret_master, 'vypocet65') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet66, NEW.vypocet66, pocetzmien, ret, ret_master, 'vypocet66') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet67, NEW.vypocet67, pocetzmien, ret, ret_master, 'vypocet67') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet68, NEW.vypocet68, pocetzmien, ret, ret_master, 'vypocet68') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet69, NEW.vypocet69, pocetzmien, ret, ret_master, 'vypocet69') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet70, NEW.vypocet70, pocetzmien, ret, ret_master, 'vypocet70') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet71, NEW.vypocet71, pocetzmien, ret, ret_master, 'vypocet71') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet72, NEW.vypocet72, pocetzmien, ret, ret_master, 'vypocet72') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet73, NEW.vypocet73, pocetzmien, ret, ret_master, 'vypocet73') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet74, NEW.vypocet74, pocetzmien, ret, ret_master, 'vypocet74') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet75, NEW.vypocet75, pocetzmien, ret, ret_master, 'vypocet75') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet76, NEW.vypocet76, pocetzmien, ret, ret_master, 'vypocet76') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet77, NEW.vypocet77, pocetzmien, ret, ret_master, 'vypocet77') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet78, NEW.vypocet78, pocetzmien, ret, ret_master, 'vypocet78') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet79, NEW.vypocet79, pocetzmien, ret, ret_master, 'vypocet79') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet80, NEW.vypocet80, pocetzmien, ret, ret_master, 'vypocet80') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet81, NEW.vypocet81, pocetzmien, ret, ret_master, 'vypocet81') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet82, NEW.vypocet82, pocetzmien, ret, ret_master, 'vypocet82') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet83, NEW.vypocet83, pocetzmien, ret, ret_master, 'vypocet83') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet84, NEW.vypocet84, pocetzmien, ret, ret_master, 'vypocet84') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet85, NEW.vypocet85, pocetzmien, ret, ret_master, 'vypocet85') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet86, NEW.vypocet86, pocetzmien, ret, ret_master, 'vypocet86') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet87, NEW.vypocet87, pocetzmien, ret, ret_master, 'vypocet87') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet88, NEW.vypocet88, pocetzmien, ret, ret_master, 'vypocet88') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet89, NEW.vypocet89, pocetzmien, ret, ret_master, 'vypocet89') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet90, NEW.vypocet90, pocetzmien, ret, ret_master, 'vypocet90') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet91, NEW.vypocet91, pocetzmien, ret, ret_master, 'vypocet91') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet92, NEW.vypocet92, pocetzmien, ret, ret_master, 'vypocet92') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet93, NEW.vypocet93, pocetzmien, ret, ret_master, 'vypocet93') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet94, NEW.vypocet94, pocetzmien, ret, ret_master, 'vypocet94') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet95, NEW.vypocet95, pocetzmien, ret, ret_master, 'vypocet95') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet96, NEW.vypocet96, pocetzmien, ret, ret_master, 'vypocet96') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet97, NEW.vypocet97, pocetzmien, ret, ret_master, 'vypocet97') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet98, NEW.vypocet98, pocetzmien, ret, ret_master, 'vypocet98') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolastring(OLD.vypocet99, NEW.vypocet99, pocetzmien, ret, ret_master, 'vypocet99') INTO pocetzmien, ret, ret_master;
		IF pocetzmien>0 THEN
			IF mojmaster>0  AND posunhore>0 THEN 
				ret:=ret||', id_sync='||btrim(idnazapis_mastrovi::CHARACTER(10));
				IF OLD.idriadok_master IS NOT NULL AND OLD.idriadok_master<>0 THEN
					ret:=ret||' WHERE idriadok='||btrim(OLD.idriadok_master::CHARACTER(20))||';';
				ELSE
					ret:=ret||' WHERE idriadok=%P1%';
					mp1:='getidriadokmaster('||(OLD.idriadok::CHARACTER(20))||')';
				END IF;
				INSERT INTO food600.sync_idriadok (prikaz, tabulka, idriadok, operacia, nazev, p1, p2, p3, p4, p5, p6, id_sync, is_master) VALUES (ret, 'vypocty', OLD.idriadok, 'U', OLD.idriadok, mp1, mp2, mp3, mp4, mp5, mp6, idnazapis_mastrovi, 0);
			END IF;
			IF sommaster>0 THEN 
				ret_master:=ret_master||', id_sync='||btrim(idnazapis_slavom::CHARACTER(10));
				ret_master:=ret_master||' WHERE idriadok_master='||btrim(OLD.idriadok::CHARACTER(20))||';';
			INSERT INTO food600.sync_idriadok (prikaz, tabulka, idriadok, operacia, nazev, p1, p2, p3, p4, p5, p6, id_sync, is_master) VALUES (ret_master, 'vypocty', OLD.idriadok, 'U', OLD.idriadok, mp1_master, mp2_master, mp3_master, mp4_master, mp5_master, mp6_master, idnazapis_slavom, 1);
			END IF;
		END IF;
	END IF;
	RETURN NEW;
  ELSIF (TG_OP = 'INSERT') THEN
	IF robsync>0 AND new.c_druh>=0 THEN
		IF NEW.id_sync IS NULL OR NEW.id_sync=0 THEN
			--- Ak nebol vyplneny id_sync, islo o zaznam, ktory vznikol na tomto PC (z FoodManu)
			idnazapis_slavom:=mojeid;
			idnazapis_mastrovi:=mojeid;
		ELSE
			--- Ak bol id_sync vyplneny, musel zaznam prist od slave alebo od mastera. Dalsim slavom budem posuvat originalne id, aby si povodny autor zaznamu uz tuto zmenu nemusel stahovat
			idnazapis_slavom:=NEW.id_sync;
			IF mojmaster>0 THEN
				IF idnazapis_slavom IN (SELECT idriadok FROM food600.sync_set WHERE id_master=mojeid) THEN
					idnazapis_mastrovi:=mojeid;
				ELSE
					idnazapis_mastrovi:=idnazapis_slavom;
				END IF;
			END IF;
		END IF;
		--- Mastrovi sa posuvaju moje zaznamy a zaznamy mojich slavov a posuvam mu moje id (nevracaju sa nazad zaznamy, ktore prisli zhora)
		IF mojmaster>0 THEN
			IF mojeid=idnazapis_slavom THEN
				posunhore:=1;
			ELSE
				IF idnazapis_slavom IN (SELECT idriadok FROM food600.sync_set WHERE id_master=mojeid) THEN
					posunhore:=1;
				ELSE
					posunhore:=0;
				END IF;
			END IF;
		ELSE
			posunhore:=0;
		END IF;
		--- id_sync na riadok aj tak nezapisem
		NEW.id_sync:=0;
		ret:='INSERT INTO food600.vypocty (';
		ret_master:=ret;
		IF NEW.c_druh IS NOT NULL THEN
			IF pocetzmien>0 THEN
				polia:=polia||',';
				hodnoty:=hodnoty||',';
				polia_master:=polia_master||',';
				hodnoty_master:=hodnoty_master||',';
			END IF;
			polia:=polia||'c_druh';
			polia_master:=polia_master||'c_druh';
			IF NEW.c_druh>0 THEN
				hodnoty:=hodnoty||'%P2%';
				mp2:='getcdruhmaster('||btrim(NEW.c_druh::CHARACTER(20))||')';
				hodnoty_master:=hodnoty_master||'%P2%';
				mp2_master:='getcdruhslave('||btrim(NEW.c_druh::CHARACTER(20))||')';
			ELSE
				hodnoty:=hodnoty||'0';
				hodnoty_master:=hodnoty_master||'0';
			END IF;
			pocetzmien:=pocetzmien+1;
		END IF;
		SELECT * FROM food600.insertpolanumeric(NEW.c_data, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'c_data') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.druh, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'druh') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.spart_kas, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'spart_kas') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.typ_kalk, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'typ_kalk') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.dan01, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'dan01') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet01, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet01') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet02, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet02') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet03, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet03') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet04, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet04') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet05, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet05') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet06, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet06') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet07, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet07') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet08, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet08') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet09, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet09') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet10, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet10') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet11, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet11') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet12, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet12') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet13, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet13') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet14, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet14') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet15, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet15') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet16, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet16') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet17, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet17') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet18, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet18') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet19, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet19') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet20, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet20') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet21, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet21') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet22, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet22') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet23, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet23') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet24, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet24') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet25, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet25') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet26, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet26') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet27, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet27') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet28, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet28') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet29, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet29') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet30, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet30') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet31, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet31') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet32, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet32') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet33, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet33') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet34, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet34') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet35, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet35') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet36, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet36') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet37, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet37') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet38, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet38') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet39, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet39') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet40, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet40') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet41, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet41') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet42, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet42') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet43, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet43') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet44, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet44') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet45, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet45') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet46, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet46') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet47, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet47') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet48, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet48') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet49, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet49') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet50, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet50') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet51, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet51') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet52, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet52') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet53, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet53') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet54, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet54') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet55, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet55') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet56, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet56') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet57, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet57') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet58, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet58') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet59, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet59') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet60, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet60') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet61, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet61') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet62, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet62') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet63, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet63') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet64, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet64') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet65, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet65') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet66, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet66') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet67, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet67') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet68, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet68') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet69, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet69') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet70, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet70') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet71, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet71') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet72, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet72') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet73, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet73') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet74, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet74') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet75, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet75') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet76, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet76') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet77, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet77') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet78, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet78') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet79, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet79') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet80, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet80') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet81, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet81') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet82, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet82') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet83, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet83') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet84, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet84') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet85, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet85') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet86, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet86') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet87, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet87') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet88, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet88') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet89, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet89') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet90, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet90') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet91, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet91') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet92, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet92') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet93, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet93') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet94, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet94') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet95, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet95') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet96, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet96') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet97, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet97') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet98, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet98') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolastring(NEW.vypocet99, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'vypocet99') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		IF pocetzmien>0 THEN
			polia:=polia||',';
			hodnoty:=hodnoty||',';
			polia_master:=polia_master||',';
			hodnoty_master:=hodnoty_master||',';
			IF mojmaster>0 AND posunhore>0 THEN 
				polia:=polia||'id_sync';
				hodnoty:=hodnoty||btrim(idnazapis_mastrovi::CHARACTER(10));
				pocetzmien:=pocetzmien+1;
				ret:=ret||polia||') VALUES ('||hodnoty||') RETURNING idriadok;';
				INSERT INTO food600.sync_idriadok (prikaz, tabulka, idriadok, operacia, nazev, p1, p2, p3, p4, p5, p6, id_sync, is_master) VALUES (ret, 'vypocty', NEW.idriadok, 'I', NEW.idriadok, mp1, mp2, mp3, mp4, mp5, mp6, idnazapis_mastrovi, 0);
			END IF;
			IF sommaster>0 THEN 
				polia_master:=polia_master||'id_sync';
				hodnoty_master:=hodnoty_master||btrim(idnazapis_slavom::CHARACTER(20));
				pocetzmien:=pocetzmien+1;
				ret_master:=ret_master||polia_master||') VALUES ('||hodnoty_master||') RETURNING idriadok;';
				INSERT INTO food600.sync_idriadok (prikaz, tabulka, idriadok, operacia, nazev, p1, p2, p3, p4, p5, p6, id_sync, is_master) VALUES (ret_master, 'vypocty', NEW.idriadok, 'I', NEW.idriadok, mp1_master, mp2_master, mp3_master, mp4_master, mp5_master, mp6_master, idnazapis_slavom, 1);
			END IF;
		END IF;
	END IF;
	RETURN NEW;
ELSIF (TG_OP = 'DELETE') THEN
	IF robsync>0 THEN
		ret:='DELETE FROM food600.vypocty WHERE c_druh=';
		ret_master:='DELETE FROM food600.vypocty WHERE c_druh_master=';
		IF mojmaster>0 THEN 
			IF (OLD.idriadok_master>0) THEN
				ret:=ret||OLD.idriadok_master::CHARACTER(20);
			ELSE
				ret:=ret||'%P1%';
				mp1:='getidriadokmaster('||btrim(OLD.idriadok::CHARACTER(20))||')';
			END IF;	
			INSERT INTO food600.sync_idriadok (prikaz, tabulka, idriadok, operacia, nazev, p1, p2, p3, p4, p5, p6, id_sync, is_master) VALUES (ret, 'vypocty', OLD.idriadok, 'D', OLD.idriadok, mp1, mp2, mp3, mp4, mp5, mp6, mojeid, 0);
		END IF;
		IF sommaster>0 THEN 
			ret_master:=ret_master||OLD.idriadok::CHARACTER(20);
			INSERT INTO food600.sync_idriadok (prikaz, tabulka, idriadok, operacia, nazev, p1, p2, p3, p4, p5, p6, id_sync, is_master) VALUES (ret_master, 'vypocty', OLD.idriadok, 'D', OLD.idriadok, mp1_master, mp2_master, mp3_master, mp4_master, mp5_master, mp6_master, mojeid, 1);
		END IF;
	END IF;		
	RETURN OLD;
END IF;
END;
$BODY$;
