CREATE OR REPLACE FUNCTION food600.dopremenujkartu(
	mcdata integer,
	stara integer,
	nova integer)
    RETURNS smallint
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE
AS $BODY$
BEGIN
UPDATE food600.obraty SET c_karty=stara WHERE c_karty = nova AND c_data=mcdata;
UPDATE food600.dluhy SET c_karty=stara WHERE c_karty = nova AND c_data=mcdata;
UPDATE food600.davky SET c_karty=stara WHERE c_karty = nova AND c_data=mcdata;
UPDATE food600.eany SET c_karty=stara WHERE c_karty = nova AND c_data=mcdata;
UPDATE food600.obr_alk SET c_karty=stara WHERE c_karty = nova AND c_data=mcdata;
UPDATE food600.nlimity SET c_karty=stara WHERE c_karty = nova AND c_data=mcdata;
UPDATE food600.nlimitsablonypol SET c_karty=stara WHERE c_karty = nova AND c_data=mcdata;
UPDATE food600.polozky SET c_karty=stara WHERE c_karty = nova AND c_data=mcdata;
UPDATE food600.polozky SET c_poloz=stara WHERE c_poloz = nova AND c_data=mcdata;
UPDATE food600.klapky SET c_karty=stara WHERE c_karty = nova AND c_data=mcdata;
UPDATE food600.klapky SET caption=karty.nazev, caption1=karty.nazev, caption2=karty.nazev, caption3=karty.nazev, caption4=karty.nazev FROM food600.karty WHERE klapky.c_karty=karty.c_karty and klapky.c_data=karty.c_data AND c_karty=stara AND c_data=mcdata;
UPDATE food600.kl_don SET c_karty=stara WHERE c_karty = nova AND c_data=mcdata;
UPDATE food600.kl_don SET caption=karty.nazev, caption1=karty.nazev, caption2=karty.nazev, caption3=karty.nazev, caption4=karty.nazev FROM food600.karty WHERE klapky.c_karty=karty.c_karty and klapky.c_data=karty.c_data AND c_karty=stara AND c_data=mcdata;
UPDATE food600.buffer SET c_karty=stara WHERE c_karty = nova AND c_data=mcdata;
DELETE FROM food600.sklad WHERE c_karty = nova AND c_data=mcdata;
DELETE FROM food600.bourak WHERE c_karty = nova AND c_data=mcdata;
DELETE FROM food600.bourak WHERE c_karty2 = nova AND c_data=mcdata;
RETURN 1;
END
$BODY$;
