CREATE OR REPLACE VIEW food600.ssksezodpocitane
 AS
 SELECT sk__sez.uzaverka,
    sk__sez.id_kas,
    sk__sez.lastuzav AS popis,
    sk__sez.id_man,
    sk__sez.c_data::bigint AS c_data
   FROM food600.sk__sez
  WHERE sk__sez.odecteno <> 0 AND substr(sk__sez.lastuzav::text, 1, 2) = 'D_'::text
UNION
 SELECT sk__sez.uzaverka,
    sk__sez.id_kas,
    nlimit_hl.menolimit AS popis,
    sk__sez.id_man,
    sk__sez.c_data::bigint AS c_data
   FROM food600.sk__sez
     LEFT JOIN food600.nlimit_hl ON food600.tvor_cislo(substr(sk__sez.lastuzav::text, 3, 15)) = nlimit_hl.id_limit AND sk__sez.c_data = nlimit_hl.c_data
  WHERE sk__sez.odecteno <> 0 AND substr(sk__sez.lastuzav::text, 1, 2) = 'L_'::text AND food600.tvor_cislo(substr(sk__sez.lastuzav::text, 3, 15)) > 0;
