CREATE OR REPLACE VIEW food600.sspotrebaaktualna
 AS
 SELECT food_dat.id_zkratka AS sklad,
    sum(sk__pol.mnozstvi) AS mnozstvi,
    sum(sk__pol.prachy) AS cena,
    sk__pol.cen_hlad,
    "substring"(karty.nazev::text, 1, 27) AS nazev,
    "substring"(karty.nazev::text, 28, 3) AS mj,
    skupiny.druh,
    to_char(now(), 'YYYYMMDD HH24:MI:SS'::text)::character(17) AS uzaverka,
    sstrediska.id AS id_kas
   FROM food600.sk__pol
     JOIN food600.sstrediska ON sk__pol.c_uzaverka = sstrediska.c_stredisk
     JOIN food600.karty ON sk__pol.c_karty = karty.c_karty
     LEFT JOIN food600.skupiny ON karty.c_druhk = skupiny.c_druh
     LEFT JOIN food600.food_dat ON sk__pol.c_stredisk = food_dat.c_stredisk
  WHERE sk__pol.c_uzaverka < 0
  GROUP BY sk__pol.c_uzaverka, food_dat.id_zkratka, sk__pol.cen_hlad, karty.nazev, skupiny.druh, sstrediska.id
  ORDER BY sstrediska.id, to_char(now(), 'YYYYMMDD HH24:MI:SS'::text)::character(17);
