-- View: "eco.v_articles_1"

-- DROP VIEW eco.v_articles_1;

CREATE OR REPLACE VIEW eco.v_articles_1 AS 
((((((((((((((((( SELECT '-8' AS oid, 'Listes paramétrées établissement' AS texte, '' AS code, '1' AS "level", '0'::text || chr(1) AS tri
   FROM eco.t_listes_tables
  WHERE t_listes_tables.code::text = 'ART'::text AND (t_listes_tables.oid IN ( SELECT t_listes.table_id
           FROM eco.t_listes
          WHERE t_listes.is_cti::text <> 1::text AND (substr(t_listes.code::text, 1, 4) <> ALL (ARRAY['VIT_'::text, 'VED_'::text, 'HPM_'::text]))))
UNION 
 SELECT 'LI'::text || t_listes.oid::text AS oid, t_listes.texte, '' AS code, '2' AS "level", '0I'::text || t_listes.texte::text AS tri
   FROM eco.t_listes, eco.t_listes_tables
  WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text AND t_listes.is_cti::text <> 1::text AND (substr(t_listes.code::text, 1, 4) <> ALL (ARRAY['VIT_'::text, 'VED_'::text, 'HPM_'::text])))
UNION 
 SELECT 'SL'::text || t_listes.oid::text AS oid, 'Sauf '::text || t_listes.texte::text AS texte, '' AS code, '2' AS "level", '0S'::text || t_listes.texte::text AS tri
   FROM eco.t_listes, eco.t_listes_tables
  WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text AND t_listes.is_cti::text <> 1::text AND (substr(t_listes.code::text, 1, 4) <> ALL (ARRAY['VIT_'::text, 'VED_'::text, 'HPM_'::text])) AND (t_listes.show_omit::text <> '0'::text OR t_listes.show_omit::text IS NULL))
UNION 
 SELECT '-8' AS oid, 'Listes paramétrées VITALIA' AS texte, '' AS code, '1' AS "level", '1'::text || chr(1) AS tri
   FROM eco.t_listes_tables
  WHERE t_listes_tables.code::text = 'ART'::text AND (t_listes_tables.oid IN ( SELECT t_listes.table_id
           FROM eco.t_listes
          WHERE t_listes.is_cti::text <> 1::text AND substr(t_listes.code::text, 1, 4) = 'VIT_'::text)))
UNION 
 SELECT 'LI'::text || t_listes.oid::text AS oid, t_listes.texte, '' AS code, '2' AS "level", '1I'::text || t_listes.texte::text AS tri
   FROM eco.t_listes, eco.t_listes_tables
  WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code::text, 1, 4) = 'VIT_'::text)
UNION 
 SELECT 'SL'::text || t_listes.oid::text AS oid, 'Sauf '::text || t_listes.texte::text AS texte, '' AS code, '2' AS "level", '1S'::text || t_listes.texte::text AS tri
   FROM eco.t_listes, eco.t_listes_tables
  WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code::text, 1, 4) = 'VIT_'::text AND (t_listes.show_omit::text <> '0'::text OR t_listes.show_omit::text IS NULL))
UNION 
 SELECT '-8' AS oid, 'Listes paramétrées VEDICI' AS texte, '' AS code, '1' AS "level", '1'::text || chr(1) AS tri
   FROM eco.t_listes_tables
  WHERE t_listes_tables.code::text = 'ART'::text AND (t_listes_tables.oid IN ( SELECT t_listes.table_id
           FROM eco.t_listes
          WHERE t_listes.is_cti::text <> 1::text AND substr(t_listes.code::text, 1, 4) = 'VED_'::text)))
UNION 
 SELECT 'LI'::text || t_listes.oid::text AS oid, t_listes.texte, '' AS code, '2' AS "level", '1I'::text || t_listes.texte::text AS tri
   FROM eco.t_listes, eco.t_listes_tables
  WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code::text, 1, 4) = 'VED_'::text)
UNION 
 SELECT 'SL'::text || t_listes.oid::text AS oid, 'Sauf '::text || t_listes.texte::text AS texte, '' AS code, '2' AS "level", '1S'::text || t_listes.texte::text AS tri
   FROM eco.t_listes, eco.t_listes_tables
  WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code::text, 1, 4) = 'VED_'::text AND (t_listes.show_omit::text <> '0'::text OR t_listes.show_omit::text IS NULL))
UNION 
 SELECT '-8' AS oid, 'Listes paramétrées HPM' AS texte, '' AS code, '1' AS "level", '1'::text || chr(1) AS tri
   FROM eco.t_listes_tables
  WHERE t_listes_tables.code::text = 'ART'::text AND (t_listes_tables.oid IN ( SELECT t_listes.table_id
           FROM eco.t_listes
          WHERE t_listes.is_cti::text <> 1::text AND substr(t_listes.code::text, 1, 4) = 'HPM_'::text)))
UNION 
 SELECT 'LI'::text || t_listes.oid::text AS oid, t_listes.texte, '' AS code, '2' AS "level", '1I'::text || t_listes.texte::text AS tri
   FROM eco.t_listes, eco.t_listes_tables
  WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code::text, 1, 4) = 'HPM_'::text)
UNION 
 SELECT 'SL'::text || t_listes.oid::text AS oid, 'Sauf '::text || t_listes.texte::text AS texte, '' AS code, '2' AS "level", '1S'::text || t_listes.texte::text AS tri
   FROM eco.t_listes, eco.t_listes_tables
  WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text AND t_listes.is_cti::text <> 1::text AND substr(t_listes.code::text, 1, 4) = 'HPM_'::text AND (t_listes.show_omit::text <> '0'::text OR t_listes.show_omit::text IS NULL))
UNION 
 SELECT '-8' AS oid, 'Listes paramétrées CTI' AS texte, '' AS code, '1' AS "level", '3' AS tri
   FROM eco.t_listes_tables
  WHERE t_listes_tables.code::text = 'ART'::text AND (t_listes_tables.oid IN ( SELECT t_listes.table_id
           FROM eco.t_listes
          WHERE t_listes.is_cti::text = 1::text)))
UNION 
 SELECT 'LI'::text || t_listes.oid::text AS oid, t_listes.texte, '' AS code, '2' AS "level", '3I'::text || t_listes.texte::text AS tri
   FROM eco.t_listes, eco.t_listes_tables
  WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text AND t_listes.is_cti::text = 1::text)
UNION 
 SELECT 'SL'::text || t_listes.oid::text AS oid, 'Sauf '::text || t_listes.texte::text AS texte, '' AS code, '2' AS "level", '3S'::text || t_listes.texte::text AS tri
   FROM eco.t_listes, eco.t_listes_tables
  WHERE t_listes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text AND t_listes.is_cti::text = 1::text AND (t_listes.show_omit::text <> '0'::text OR t_listes.show_omit::text IS NULL))
UNION 
 SELECT ('LC'::text || lpad(t_classes."sequence"::text, 2, '0'::text)) || t_classes.oid::text AS oid, t_classes.texte, '' AS code, '1' AS "level", '5'::text || btrim(rpad(lpad(t_classes."sequence"::text, 2, '0'::text), 10, ' '::text)) AS tri
   FROM eco.t_classes, eco.t_listes_tables
  WHERE t_classes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text)
UNION ALL 
 SELECT ('LS'::text || lpad(t_classes."sequence"::text, 2, '0'::text)) || t_classes_sections.oid::text AS oid, t_classes_sections.texte, '' AS code, '2' AS "level", '5'::text || btrim(rpad(lpad(t_classes."sequence"::text, 2, '0'::text), 10, ' '::text) || t_classes_sections.code::text) AS tri
   FROM eco.t_classes, eco.t_classes_sections, eco.t_listes_tables
  WHERE t_classes.table_id = t_listes_tables.oid AND t_classes_sections.classe_id = t_classes.oid AND t_listes_tables.code::text = 'ART'::text)
UNION ALL 
 SELECT ('LS'::text || lpad(t_classes."sequence"::text, 2, '0'::text)) || '0'::text AS oid, 'Section non attribuée' AS texte, '' AS code, '2' AS "level", '5'::text || btrim(rpad(lpad(t_classes."sequence"::text, 2, '0'::text), 10, ' '::text) || chr(255)) AS tri
   FROM eco.t_classes, eco.t_listes_tables
  WHERE t_classes.table_id = t_listes_tables.oid AND t_listes_tables.code::text = 'ART'::text)


UNION 
 SELECT 'D1'::text || t_articles.oid::text AS oid, (t_articles.code::text || ' '::text) || t_articles.texte_court::text AS texte, t_articles.code, '1' AS "level", '9'::text || t_articles.code::text AS tri
   FROM eco.t_articles
  WHERE (t_articles.oid IN ( SELECT p_oids.oid
           FROM eco.p_oids
          WHERE p_oids.code_table::text = 'articles'::text))



UNION


SELECT '-8' AS oid, 'Types' AS texte, '', '1' AS "level", '81'::text || chr(1) AS tri
   
UNION

SELECT 'D1'::text || t_types_articles.oid::text AS oid, (t_types_articles.code::text || ' '::text) || t_types_articles.texte_court::text AS texte, t_types_articles.code, '2' AS "level", '81'::text || t_types_articles.code::text AS tri
   FROM eco.t_types_articles
  WHERE (t_types_articles.oid IN ( SELECT p_oids.oid
           FROM eco.p_oids
          WHERE p_oids.code_table::text = 'types_articles'::text))


UNION

SELECT '-8' AS oid, 'Familles' AS texte, '', '1' AS "level", '82'::text || chr(1) AS tri
   
UNION

SELECT 'D2'::text || t_familles_articles.oid::text AS oid, (t_familles_articles.code::text || ' '::text) || t_familles_articles.texte_court::text AS texte, t_familles_articles.code, '2' AS "level", '82'::text || t_familles_articles.code::text AS tri
   FROM eco.t_familles_articles
  WHERE (t_familles_articles.oid IN ( SELECT p_oids.oid
           FROM eco.p_oids
          WHERE p_oids.code_table::text = 'familles_articles'::text))


UNION

SELECT '-8' AS oid, 'Sous Familles' AS texte, '', '1' AS "level", '83'::text || chr(1) AS tri
   
UNION


SELECT 'D3'::text || t_sous_familles_articles.oid::text AS oid, (t_sous_familles_articles.code::text || ' '::text) || t_sous_familles_articles.texte_court::text AS texte, t_sous_familles_articles.code, '2' AS "level", '83'::text || t_sous_familles_articles.code::text AS tri
   FROM eco.t_sous_familles_articles
  WHERE (t_sous_familles_articles.oid IN ( SELECT p_oids.oid
           FROM eco.p_oids
          WHERE p_oids.code_table::text = 'sous_familles_articles'::text))



UNION

SELECT '-8' AS oid, 'Catégories' AS texte, '', '1' AS "level", '84'::text || chr(1) AS tri
   
UNION

SELECT 'D4'::text || t_categories_articles.oid::text AS oid, (t_categories_articles.code::text || ' '::text) || t_categories_articles.texte_court::text AS texte, t_categories_articles.code, '2' AS "level", '84'::text || t_categories_articles.code::text AS tri
   FROM eco.t_categories_articles
  WHERE (t_categories_articles.oid IN ( SELECT p_oids.oid
           FROM eco.p_oids
          WHERE p_oids.code_table::text = 'categories_articles'::text))


UNION

SELECT '-8' AS oid, 'Sous Catégories' AS texte, '', '1' AS "level", '85'::text || chr(1) AS tri
   
UNION


SELECT 'D5'::text || t_sous_categories_articles.oid::text AS oid, (t_sous_categories_articles.code::text || ' '::text) || t_sous_categories_articles.texte_court::text AS texte, t_sous_categories_articles.code, '2' AS "level", '85'::text || t_sous_categories_articles.code::text AS tri
   FROM eco.t_sous_categories_articles
  WHERE (t_sous_categories_articles.oid IN ( SELECT p_oids.oid
           FROM eco.p_oids
          WHERE p_oids.code_table::text = 'sous_categories_articles'::text))




UNION 
 SELECT 'DT'::text || t_articles.oid::text AS oid, (t_articles.code::text || ' '::text) || t_articles.texte_court::text AS texte, t_articles.code, '1' AS "level", '9'::text || t_articles.code::text AS tri
   FROM eco.t_articles
  WHERE (t_articles.oid IN ( SELECT p_oids.oid
           FROM eco.p_oids
          WHERE p_oids.code_table::text = 'articles'::text))
  ORDER BY 5;

ALTER TABLE eco.v_articles_1 OWNER TO postgres;
