CREATE OR REPLACE FUNCTION food600.kceny_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;
mojtyp 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 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.kceny SET ';
		ret_master:=ret;
		IF (NEW.c_karty != OLD.c_karty) THEN
			IF pocetzmien>0 THEN
				ret:=ret||',';
				ret_master:=ret_master||',';
			END IF;
			ret:=ret||'c_karty=%P2%';
			mp2:='getckartymaster('||btrim(NEW.c_karty::CHARACTER(20))||')';
			ret_master:=ret_master||'c_karty=%P2%';
			mp2_master:='getckartyslave('||btrim(NEW.c_karty::CHARACTER(20))||')';
			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.updatepolanumeric(btrim(OLD.cenaa0::CHARACTER(20)), btrim(NEW.cenaa0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaa0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaa1::CHARACTER(20)), btrim(NEW.cenaa1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaa1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaa2::CHARACTER(20)), btrim(NEW.cenaa2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaa2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaa3::CHARACTER(20)), btrim(NEW.cenaa3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaa3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaa4::CHARACTER(20)), btrim(NEW.cenaa4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaa4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaa5::CHARACTER(20)), btrim(NEW.cenaa5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaa5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaa6::CHARACTER(20)), btrim(NEW.cenaa6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaa6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaa7::CHARACTER(20)), btrim(NEW.cenaa7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaa7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaa8::CHARACTER(20)), btrim(NEW.cenaa8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaa8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaa9::CHARACTER(20)), btrim(NEW.cenaa9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaa9') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenab0::CHARACTER(20)), btrim(NEW.cenab0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenab0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenab1::CHARACTER(20)), btrim(NEW.cenab1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenab1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenab2::CHARACTER(20)), btrim(NEW.cenab2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenab2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenab3::CHARACTER(20)), btrim(NEW.cenab3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenab3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenab4::CHARACTER(20)), btrim(NEW.cenab4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenab4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenab5::CHARACTER(20)), btrim(NEW.cenab5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenab5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenab6::CHARACTER(20)), btrim(NEW.cenab6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenab6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenab7::CHARACTER(20)), btrim(NEW.cenab7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenab7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenab8::CHARACTER(20)), btrim(NEW.cenab8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenab8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenab9::CHARACTER(20)), btrim(NEW.cenab9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenab9') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenac0::CHARACTER(20)), btrim(NEW.cenac0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenac0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenac1::CHARACTER(20)), btrim(NEW.cenac1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenac1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenac2::CHARACTER(20)), btrim(NEW.cenac2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenac2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenac3::CHARACTER(20)), btrim(NEW.cenac3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenac3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenac4::CHARACTER(20)), btrim(NEW.cenac4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenac4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenac5::CHARACTER(20)), btrim(NEW.cenac5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenac5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenac6::CHARACTER(20)), btrim(NEW.cenac6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenac6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenac7::CHARACTER(20)), btrim(NEW.cenac7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenac7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenac8::CHARACTER(20)), btrim(NEW.cenac8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenac8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenac9::CHARACTER(20)), btrim(NEW.cenac9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenac9') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenad0::CHARACTER(20)), btrim(NEW.cenad0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenad0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenad1::CHARACTER(20)), btrim(NEW.cenad1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenad1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenad2::CHARACTER(20)), btrim(NEW.cenad2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenad2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenad3::CHARACTER(20)), btrim(NEW.cenad3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenad3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenad4::CHARACTER(20)), btrim(NEW.cenad4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenad4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenad5::CHARACTER(20)), btrim(NEW.cenad5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenad5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenad6::CHARACTER(20)), btrim(NEW.cenad6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenad6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenad7::CHARACTER(20)), btrim(NEW.cenad7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenad7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenad8::CHARACTER(20)), btrim(NEW.cenad8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenad8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenad9::CHARACTER(20)), btrim(NEW.cenad9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenad9') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenae0::CHARACTER(20)), btrim(NEW.cenae0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenae0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenae1::CHARACTER(20)), btrim(NEW.cenae1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenae1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenae2::CHARACTER(20)), btrim(NEW.cenae2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenae2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenae3::CHARACTER(20)), btrim(NEW.cenae3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenae3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenae4::CHARACTER(20)), btrim(NEW.cenae4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenae4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenae5::CHARACTER(20)), btrim(NEW.cenae5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenae5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenae6::CHARACTER(20)), btrim(NEW.cenae6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenae6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenae7::CHARACTER(20)), btrim(NEW.cenae7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenae7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenae8::CHARACTER(20)), btrim(NEW.cenae8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenae8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenae9::CHARACTER(20)), btrim(NEW.cenae9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenae9') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaf0::CHARACTER(20)), btrim(NEW.cenaf0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaf0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaf1::CHARACTER(20)), btrim(NEW.cenaf1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaf1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaf2::CHARACTER(20)), btrim(NEW.cenaf2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaf2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaf3::CHARACTER(20)), btrim(NEW.cenaf3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaf3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaf4::CHARACTER(20)), btrim(NEW.cenaf4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaf4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaf5::CHARACTER(20)), btrim(NEW.cenaf5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaf5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaf6::CHARACTER(20)), btrim(NEW.cenaf6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaf6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaf7::CHARACTER(20)), btrim(NEW.cenaf7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaf7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaf8::CHARACTER(20)), btrim(NEW.cenaf8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaf8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaf9::CHARACTER(20)), btrim(NEW.cenaf9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaf9') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenag0::CHARACTER(20)), btrim(NEW.cenag0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenag0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenag1::CHARACTER(20)), btrim(NEW.cenag1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenag1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenag2::CHARACTER(20)), btrim(NEW.cenag2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenag2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenag3::CHARACTER(20)), btrim(NEW.cenag3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenag3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenag4::CHARACTER(20)), btrim(NEW.cenag4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenag4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenag5::CHARACTER(20)), btrim(NEW.cenag5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenag5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenag6::CHARACTER(20)), btrim(NEW.cenag6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenag6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenag7::CHARACTER(20)), btrim(NEW.cenag7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenag7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenag8::CHARACTER(20)), btrim(NEW.cenag8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenag8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenag9::CHARACTER(20)), btrim(NEW.cenag9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenag9') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenah0::CHARACTER(20)), btrim(NEW.cenah0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenah0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenah1::CHARACTER(20)), btrim(NEW.cenah1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenah1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenah2::CHARACTER(20)), btrim(NEW.cenah2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenah2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenah3::CHARACTER(20)), btrim(NEW.cenah3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenah3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenah4::CHARACTER(20)), btrim(NEW.cenah4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenah4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenah5::CHARACTER(20)), btrim(NEW.cenah5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenah5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenah6::CHARACTER(20)), btrim(NEW.cenah6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenah6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenah7::CHARACTER(20)), btrim(NEW.cenah7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenah7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenah8::CHARACTER(20)), btrim(NEW.cenah8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenah8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenah9::CHARACTER(20)), btrim(NEW.cenah9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenah9') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenai0::CHARACTER(20)), btrim(NEW.cenai0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenai0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenai1::CHARACTER(20)), btrim(NEW.cenai1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenai1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenai2::CHARACTER(20)), btrim(NEW.cenai2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenai2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenai3::CHARACTER(20)), btrim(NEW.cenai3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenai3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenai4::CHARACTER(20)), btrim(NEW.cenai4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenai4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenai5::CHARACTER(20)), btrim(NEW.cenai5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenai5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenai6::CHARACTER(20)), btrim(NEW.cenai6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenai6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenai7::CHARACTER(20)), btrim(NEW.cenai7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenai7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenai8::CHARACTER(20)), btrim(NEW.cenai8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenai8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenai9::CHARACTER(20)), btrim(NEW.cenai9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenai9') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaj0::CHARACTER(20)), btrim(NEW.cenaj0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaj0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaj1::CHARACTER(20)), btrim(NEW.cenaj1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaj1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaj2::CHARACTER(20)), btrim(NEW.cenaj2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaj2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaj3::CHARACTER(20)), btrim(NEW.cenaj3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaj3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaj4::CHARACTER(20)), btrim(NEW.cenaj4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaj4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaj5::CHARACTER(20)), btrim(NEW.cenaj5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaj5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaj6::CHARACTER(20)), btrim(NEW.cenaj6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaj6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaj7::CHARACTER(20)), btrim(NEW.cenaj7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaj7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaj8::CHARACTER(20)), btrim(NEW.cenaj8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaj8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenaj9::CHARACTER(20)), btrim(NEW.cenaj9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenaj9') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenak0::CHARACTER(20)), btrim(NEW.cenak0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenak0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenak1::CHARACTER(20)), btrim(NEW.cenak1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenak1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenak2::CHARACTER(20)), btrim(NEW.cenak2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenak2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenak3::CHARACTER(20)), btrim(NEW.cenak3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenak3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenak4::CHARACTER(20)), btrim(NEW.cenak4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenak4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenak5::CHARACTER(20)), btrim(NEW.cenak5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenak5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenak6::CHARACTER(20)), btrim(NEW.cenak6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenak6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenak7::CHARACTER(20)), btrim(NEW.cenak7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenak7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenak8::CHARACTER(20)), btrim(NEW.cenak8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenak8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenak9::CHARACTER(20)), btrim(NEW.cenak9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenak9') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenal0::CHARACTER(20)), btrim(NEW.cenal0::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenal0') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenal1::CHARACTER(20)), btrim(NEW.cenal1::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenal1') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenal2::CHARACTER(20)), btrim(NEW.cenal2::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenal2') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenal3::CHARACTER(20)), btrim(NEW.cenal3::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenal3') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenal4::CHARACTER(20)), btrim(NEW.cenal4::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenal4') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenal5::CHARACTER(20)), btrim(NEW.cenal5::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenal5') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenal6::CHARACTER(20)), btrim(NEW.cenal6::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenal6') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenal7::CHARACTER(20)), btrim(NEW.cenal7::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenal7') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenal8::CHARACTER(20)), btrim(NEW.cenal8::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenal8') INTO pocetzmien, ret, ret_master;
		SELECT * FROM food600.updatepolanumeric(btrim(OLD.cenal9::CHARACTER(20)), btrim(NEW.cenal9::CHARACTER(20)), pocetzmien, ret, ret_master, 'cenal9') INTO pocetzmien, ret, ret_master;
		IF pocetzmien>0 THEN
			IF mojmaster>0 AND posunhore>0 THEN 
				ret:=ret||', id_sync='||btrim(idnazapis_mastrovi::CHARACTER(20));
				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))||',''kceny'')';
				END IF;
				INSERT INTO food600.sync_idriadok (prikaz, tabulka, idriadok, operacia, nazev, p1, p2, p3, p4, p5, p6, id_sync, is_master) VALUES (ret, 'kceny', OLD.idriadok, 'U', '', 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(20));
				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, 'kceny', OLD.idriadok, 'U', '', 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  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.kceny (';
		ret_master:=ret;
		IF NEW.c_karty 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_karty';
			hodnoty:=hodnoty||'%P2%';
			mp2:='getckartymaster('||btrim(NEW.c_karty::CHARACTER(20))||')';
			polia_master:=polia_master||'c_karty';
			hodnoty_master:=hodnoty_master||'%P2%';
			mp2_master:='getckartyslave('||btrim(NEW.c_karty::CHARACTER(20))||')';
			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.insertpolanumeric(NEW.cenaa0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaa0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaa1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaa1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaa2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaa2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaa3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaa3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaa4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaa4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaa5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaa5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaa6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaa6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaa7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaa7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaa8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaa8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaa9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaa9') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenab0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenab0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenab1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenab1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenab2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenab2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenab3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenab3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenab4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenab4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenab5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenab5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenab6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenab6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenab7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenab7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenab8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenab8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenab9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenab9') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenac0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenac0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenac1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenac1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenac2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenac2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenac3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenac3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenac4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenac4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenac5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenac5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenac6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenac6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenac7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenac7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenac8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenac8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenac9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenac9') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenad0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenad0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenad1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenad1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenad2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenad2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenad3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenad3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenad4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenad4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenad5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenad5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenad6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenad6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenad7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenad7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenad8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenad8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenad9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenad9') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenae0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenae0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenae1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenae1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenae2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenae2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenae3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenae3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenae4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenae4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenae5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenae5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenae6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenae6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenae7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenae7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenae8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenae8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenae9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenae9') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaf0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaf0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaf1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaf1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaf2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaf2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaf3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaf3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaf4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaf4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaf5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaf5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaf6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaf6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaf7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaf7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaf8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaf8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaf9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaf9') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenag0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenag0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenag1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenag1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenag2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenag2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenag3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenag3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenag4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenag4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenag5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenag5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenag6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenag6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenag7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenag7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenag8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenag8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenag9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenag9') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenah0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenah0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenah1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenah1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenah2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenah2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenah3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenah3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenah4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenah4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenah5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenah5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenah6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenah6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenah7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenah7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenah8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenah8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenah9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenah9') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenai0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenai0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenai1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenai1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenai2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenai2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenai3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenai3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenai4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenai4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenai5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenai5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenai6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenai6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenai7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenai7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenai8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenai8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenai9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenai9') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaj0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaj0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaj1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaj1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaj2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaj2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaj3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaj3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaj4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaj4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaj5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaj5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaj6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaj6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaj7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaj7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaj8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaj8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenaj9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenaj9') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenak0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenak0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenak1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenak1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenak2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenak2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenak3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenak3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenak4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenak4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenak5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenak5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenak6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenak6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenak7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenak7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenak8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenak8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenak9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenak9') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenal0, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenal0') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenal1, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenal1') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenal2, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenal2') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenal3, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenal3') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenal4, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenal4') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenal5, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenal5') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenal6, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenal6') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenal7, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenal7') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenal8, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenal8') INTO pocetzmien, hodnoty, polia, hodnoty_master, polia_master;
		SELECT * FROM food600.insertpolanumeric(NEW.cenal9, pocetzmien, hodnoty, polia, hodnoty_master, polia_master, 'cenal9') 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(20));
				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,'kceny', NEW.idriadok, 'I', '', 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, 'kceny', NEW.idriadok, 'I', '', 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.kceny WHERE idriadok=';
		ret_master:='DELETE FROM food600.kceny WHERE idriadok_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))||',''kceny'')';
			END IF;	
			INSERT INTO food600.sync_idriadok (prikaz, tabulka, idriadok, operacia, nazev, p1, p2, p3, p4, p5, p6, id_sync, is_master) VALUES (ret, 'kceny', OLD.idriadok, 'D', '', 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, 'kceny', OLD.idriadok, 'D', '', '', '', '', '', '', '', mojeid, 1);
		END IF;
	END IF;
	RETURN OLD;
END IF;
        
END;
$BODY$;
