CREATE OR REPLACE VIEW food600.ssksezodpocet
 AS
 SELECT sk__sez.uzaverka,
    sk__sez.id_kas,
    '                '::bpchar AS popis,
    sk__sez.uct_den,
    sk__sez.id_man,
    sk__sez.c_data::bigint AS c_data,
    sk__sez.c_uzaverka,
    0::smallint AS typ_pohybu
   FROM food600.sk__sez
  WHERE sk__sez.odecteno = 0 AND substr(sk__sez.lastuzav::text, 2, 1) <> '_'::text
UNION
 SELECT sk__sez.uzaverka,
    sk__sez.id_kas,
    sk__sez.lastuzav AS popis,
    sk__sez.uct_den,
    sk__sez.id_man,
    sk__sez.c_data::bigint AS c_data,
    sk__sez.c_uzaverka,
    0::smallint AS typ_pohybu
   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.uct_den,
    sk__sez.id_man,
    sk__sez.c_data::bigint AS c_data,
    sk__sez.c_uzaverka,
    nlimit_hl.typ_pohybu
   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 LEFT(sk__sez.lastuzav::text, 2) = 'L_'::text AND food600.tvor_cislo(substr(sk__sez.lastuzav::text, 3, 15)) > 0;
