src: |
  SELECT p_stock.provider_id,
      p_stock.fournisseur_id,
      p_stock.oid AS mouvement_article_id,
      p_stock.date_debut,
      p_stock.date_fin,
      p_stock.site_id,
      t_sites.code AS site_code,
      t_sites.texte_court AS site_texte,
      t_sites.section_id AS site_section_id,
      t_sites.section_code AS site_section_code,
      t_sites.section_texte AS site_section_texte,
      p_stock.lieu_id,
      t_lieux.code AS lieu_code,
      t_lieux.texte_court AS lieu_texte,
      t_lieux.section_id AS lieu_section_id,
      t_lieux.section_code AS lieu_section_code,
      t_lieux.section_texte AS lieu_section_texte,
      p_stock.article_id,
      t_articles.code AS article_code,
      t_articles.texte AS article_texte,
          CASE
              WHEN t_articles.ref_fournisseur_id[1] IS NOT NULL THEN t_articles.ref_fournisseur_texte[1]::character varying
              ELSE t_articles.texte
          END AS article_texte_fournisseur,
      t_articles.section_id AS article_section_id,
      t_articles.section_code AS article_section_code,
      t_articles.section_texte AS article_section_texte,
      p_stock.compte_id AS compte_article_id,
      t_compte.code AS compte_article_code,
      t_compte.texte AS compte_article_texte,
      t_compte.section_id AS compte_article_section_id,
      t_compte.section_code AS compte_article_section_code,
      t_compte.section_texte AS compte_article_section_texte,
      t_articles.type_id AS type_article_id,
      t_articles.type_code AS type_article_code,
      t_articles.type_texte AS type_article_texte,
      t_articles.type_section_id AS type_article_section_id,
      t_articles.type_section_code AS type_article_section_code,
      t_articles.type_section_texte AS type_article_section_texte,
      t_articles.article_reference_cacic_id,
      t_articles.article_reference_cacic_code,
      t_articles.article_reference_cacic_texte,
      t_articles.article_reference_cacic_section_id,
      t_articles.article_reference_cacic_section_code,
      t_articles.article_reference_cacic_section_texte,
      t_articles.article_reference_cti_id,
      t_articles.article_reference_cti_code,
      t_articles.article_reference_cti_texte,
      t_articles.article_reference_cti_section_id,
      t_articles.article_reference_cti_section_code,
      t_articles.article_reference_cti_section_texte,
      t_articles.classification_atc_id,
      t_articles.classification_atc_code,
      t_articles.classification_atc_texte,
      t_articles.classification_atc_1_id,
      t_articles.classification_atc_1_code,
      t_articles.classification_atc_1_texte,
      t_articles.classification_atc_2_id,
      t_articles.classification_atc_2_code,
      t_articles.classification_atc_2_texte,
      t_articles.classification_atc_3_id,
      t_articles.classification_atc_3_code,
      t_articles.classification_atc_3_texte,
      t_articles.classification_atc_4_id,
      t_articles.classification_atc_4_code,
      t_articles.classification_atc_4_texte,
      t_articles.classification_atc_section_id,
      t_articles.classification_atc_section_code,
      t_articles.classification_atc_section_texte,
      t_articles.famille_id AS famille_article_id,
      t_articles.famille_code AS famille_article_code,
      t_articles.famille_texte AS famille_article_texte,
      t_articles.famille_section_id AS famille_article_section_id,
      t_articles.famille_section_code AS famille_article_section_code,
      t_articles.famille_section_texte AS famille_article_section_texte,
      t_articles.sous_famille_id AS sous_famille_article_id,
      t_articles.sous_famille_code AS sous_famille_article_code,
      t_articles.sous_famille_texte AS sous_famille_article_texte,
      t_articles.sous_famille_section_id AS sous_famille_article_section_id,
      t_articles.sous_famille_section_code AS sous_famille_article_section_code,
      t_articles.sous_famille_section_texte AS sous_famille_article_section_texte,
      t_articles.categorie_id AS categorie_article_id,
      t_articles.categorie_code AS categorie_article_code,
      t_articles.categorie_texte AS categorie_article_texte,
      t_articles.categorie_section_id AS categorie_article_section_id,
      t_articles.categorie_section_code AS categorie_article_section_code,
      t_articles.categorie_section_texte AS categorie_article_section_texte,
      t_articles.sous_categorie_id AS sous_categorie_article_id,
      t_articles.sous_categorie_code AS sous_categorie_article_code,
      t_articles.sous_categorie_texte AS sous_categorie_article_texte,
      t_articles.sous_categorie_section_id AS sous_categorie_article_section_id,
      t_articles.sous_categorie_section_code AS sous_categorie_article_section_code,
      t_articles.sous_categorie_section_texte AS sous_categorie_article_section_texte,
      t_articles.unite_stockage_id AS unite_stockage_article_id,
      t_articles.unite_stockage_code AS unite_stockage_article_code,
      t_articles.unite_stockage_texte AS unite_stockage_article_texte,
      t_articles.unite_stockage_section_id AS unite_stockage_article_section_id,
      t_articles.unite_stockage_section_code AS unite_stockage_article_section_code,
      t_articles.unite_stockage_section_texte AS unite_stockage_article_section_texte,
      t_articles.unite_distribution_id AS unite_distribution_article_id,
      t_articles.unite_distribution_code AS unite_distribution_article_code,
      t_articles.unite_distribution_texte AS unite_distribution_article_texte,
      t_articles.unite_distribution_section_id AS unite_distribution_article_section_id,
      t_articles.unite_distribution_section_code AS unite_distribution_article_section_code,
      t_articles.unite_distribution_section_texte AS unite_distribution_article_section_texte,
      p_stock.ucd_id,
      t_ucd_c.code AS ucd_code,
      t_ucd_c.texte AS ucd_texte,
      t_ucd_c.section_id AS ucd_section_id,
      t_ucd_c.section_code AS ucd_section_code,
      t_ucd_c.section_texte AS ucd_section_texte,
      p_stock.lpp_id,
      t_lpp_c.code AS lpp_code,
      t_lpp_c.texte AS lpp_texte,
      t_lpp_c.section_id AS lpp_section_id,
      t_lpp_c.section_code AS lpp_section_code,
      t_lpp_c.section_texte AS lpp_section_texte,
      p_stock.stock_quantite_debut,
      p_stock.stock_valeur_debut,
      p_stock.entree_quantite,
      p_stock.entree_montant,
      p_stock.sortie_quantite,
      p_stock.sortie_montant,
      p_stock.stock_quantite_fin,
      p_stock.stock_valeur_fin,
      p_stock.pump
     FROM eco.p_stock
       JOIN eco.t_sites ON p_stock.site_id = t_sites.oid
       JOIN eco.t_lieux ON p_stock.lieu_id = t_lieux.oid
       JOIN eco.t_articles ON p_stock.article_id = t_articles.oid AND t_articles.gere_en_stock IS DISTINCT FROM '0'::bpchar
       JOIN eco.t_compte ON p_stock.compte_id = t_compte.oid
       JOIN eco.t_ucd_c ON p_stock.ucd_id = t_ucd_c.oid
       JOIN eco.t_lpp_c ON p_stock.lpp_id = t_lpp_c.oid;