CREATE OR REPLACE VIEW food600.slimity_zoznam
 AS
 SELECT nlimit_hl.id_limit,
    nlimit_hl.menolimit,
    nlimit_hl.txt_kasy,
    nlimit_hl.zlava,
    nlimit_hl.typ_zlavy,
    nlimit_hl.c_mena,
    nlimit_hl.c_data,
    nlimit_hl.id_stat,
    nlimitdni.id_den,
    nlimitdni.datum,
    nlimitrov.id_rov,
    nlimitrov.uzaverka,
    nlimitrov.u_cis,
    nlimitrov.cenhlad,
    nlimitchody.chod,
    nlimitrov.poradie
   FROM food600.nlimit_hl nlimit_hl
     JOIN food600.nlimitdni ON nlimit_hl.id_limit = nlimitdni.id_limit
     JOIN food600.nlimitrov ON nlimitdni.id_limit = nlimitrov.id_limit AND nlimitdni.id_den = nlimitrov.id_den
     JOIN ( SELECT sum(nlimitrov_hladiny.hodnota * nlimitrov_hladiny.pocet) AS hodnota,
            nlimitrov_hladiny.id_rov
           FROM food600.nlimitrov_hladiny
          GROUP BY nlimitrov_hladiny.id_rov) aaa ON nlimitrov.id_rov = aaa.id_rov
     JOIN food600.nlimitchody ON nlimitrov.id_chod = nlimitchody.id_chod
  WHERE nlimit_hl.archiv = 0 AND nlimit_hl.zmazane = 0 AND nlimit_hl.is_kasy <> 0 AND nlimitdni.datum <= 'now'::text::date AND nlimitrov.u_cis = ''::bpchar AND aaa.hodnota <> 0::numeric AND nlimitrov.c_dokl = 0
  ORDER BY nlimit_hl.menolimit, nlimitdni.datum, nlimitrov.poradie;

