CREATE OR REPLACE FUNCTION food600.doplnodectenodosksez(
	mcstredisk integer)
    RETURNS integer
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE
AS $BODY$
BEGIN
UPDATE food600.sk__sez SET odecteno=1 FROM food600.doklady WHERE sk__sez.odecteno=0 AND sk__sez.c_stredisk=doklady.c_stredisk AND doklady.c_stredisk=mcstredisk AND doklady.operace='VK' AND (substr(sk__sez.uzaverka,3,12)||'/'||sk__sez.id_kas)=doklady.pz2;
UPDATE food600.sk_sez SET odecteno='ano' WHERE uzaverka||id_man IN (SELECT uzaverka||id_man FROM food600.sk__sez WHERE odecteno=1);
UPDATE food600.sk_sez SET odecteno='' WHERE uzaverka||id_man IN (SELECT uzaverka||id_man FROM food600.sk__sez WHERE odecteno=0);
RETURN 1;
END
$BODY$;
