CREATE OR REPLACE FUNCTION food600.dorobprecenenie(
	mmeno character varying,
	mmena integer,
	maxcdokl integer,
	mcdata integer,
	mcstredisk integer)
    RETURNS integer
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE
AS $BODY$
BEGIN
PERFORM food600.prep1po(mmeno,mcdata,mmena,maxcdokl,mcstredisk);
UPDATE food600.buffer SET mnozstvi=-zustatek WHERE c_data=mcdata AND menobuf=mmeno;
DELETE FROM food600.buffer WHERE c_data=mcdata AND menobuf=mmeno AND round(cast(cena as numeric),4)=round(cast(cena_part as numeric),4);
INSERT INTO food600.buffer (c_karty, mnozstvi, cena, poradi, menobuf, c_stredisk, c_data, serial_no, operace) SELECT c_karty, -mnozstvi as mnozstvi, cena_part as cena, poradi, menobuf, c_stredisk, c_data, serial_no, operace FROM food600.buffer WHERE menobuf=mmeno and c_data=mcdata;
RETURN 1;
END
$BODY$;
