src: |
  SELECT p_repartitions_analytiques_shs.mois_comptable,
      p_repartitions_analytiques_shs.etape_id,
      p_repartitions_analytiques_shs.code_prevision_realisation,
      p_repartitions_analytiques_shs.compte_id,
      t_comptes_c.numero AS compte_numero,
      t_comptes_c.texte AS compte_texte,
      t_comptes_c.section1_id AS compte_section1_id,
      t_comptes_c.section1_code AS compte_section1_code,
      t_comptes_c.section1_texte AS compte_section1_texte,
      t_comptes_c.section2_id AS compte_section2_id,
      t_comptes_c.section2_code AS compte_section2_code,
      t_comptes_c.section2_texte AS compte_section2_texte,
      t_comptes_c.section3_id AS compte_section3_id,
      t_comptes_c.section3_code AS compte_section3_code,
      t_comptes_c.section3_texte AS compte_section3_texte,
      t_comptes_c.classe_1_id,
      t_comptes_c.classe_1_code,
      t_comptes_c.classe_1_texte,
      t_comptes_c.classe_2_id,
      t_comptes_c.classe_2_code,
      t_comptes_c.classe_2_texte,
      t_comptes_c.classe_3_id,
      t_comptes_c.classe_3_code,
      t_comptes_c.classe_3_texte,
      t_comptes_c.classe_4_id,
      t_comptes_c.classe_4_code,
      t_comptes_c.classe_4_texte,
      t_comptes_c.classe_5_id,
      t_comptes_c.classe_5_code,
      t_comptes_c.classe_5_texte,
      t_comptes_c.classe_6_id,
      t_comptes_c.classe_6_code,
      t_comptes_c.classe_6_texte,
      t_comptes_c.arbre_classe_1_id,
      t_comptes_c.arbre_classe_1_code,
      t_comptes_c.arbre_classe_1_texte,
      t_comptes_c.arbre_classe_2_id,
      t_comptes_c.arbre_classe_2_code,
      t_comptes_c.arbre_classe_2_texte,
      t_comptes_c.arbre_classe_3_id,
      t_comptes_c.arbre_classe_3_code,
      t_comptes_c.arbre_classe_3_texte,
      t_comptes_c.arbre_classe_4_id,
      t_comptes_c.arbre_classe_4_code,
      t_comptes_c.arbre_classe_4_texte,
      t_comptes_c.arbre_classe_5_id,
      t_comptes_c.arbre_classe_5_code,
      t_comptes_c.arbre_classe_5_texte,
      t_comptes_c.arbre_classe_6_id,
      t_comptes_c.arbre_classe_6_code,
      t_comptes_c.arbre_classe_6_texte,
      t_comptes_c.arbre_classe_7_id,
      t_comptes_c.arbre_classe_7_code,
      t_comptes_c.arbre_classe_7_texte,
      t_comptes_c.type_compta_id,
      t_comptes_c.type_compta_code,
      t_comptes_c.type_compta_texte,
      p_repartitions_analytiques_shs.section_analytique_id,
      t_sections_analytiques.code AS section_analytique_code,
      t_sections_analytiques.texte AS section_analytique_texte,
      t_sections_analytiques.section1_id AS section_analytique_section1_id,
      t_sections_analytiques.section1_code AS section_analytique_section1_code,
      t_sections_analytiques.section1_texte AS section_analytique_section1_texte,
      t_sections_analytiques.section2_id AS section_analytique_section2_id,
      t_sections_analytiques.section2_code AS section_analytique_section2_code,
      t_sections_analytiques.section2_texte AS section_analytique_section2_texte,
      t_sections_analytiques.section3_id AS section_analytique_section3_id,
      t_sections_analytiques.section3_code AS section_analytique_section3_code,
      t_sections_analytiques.section3_texte AS section_analytique_section3_texte,
      t_sections_analytiques.section4_id AS section_analytique_section4_id,
      t_sections_analytiques.section4_code AS section_analytique_section4_code,
      t_sections_analytiques.section4_texte AS section_analytique_section4_texte,
      t_sections_analytiques.section5_id AS section_analytique_section5_id,
      t_sections_analytiques.section5_code AS section_analytique_section5_code,
      t_sections_analytiques.section5_texte AS section_analytique_section5_texte,
      t_sections_analytiques.section6_id AS section_analytique_section6_id,
      t_sections_analytiques.section6_code AS section_analytique_section6_code,
      t_sections_analytiques.section6_texte AS section_analytique_section6_texte,
      t_sections_analytiques.section7_id AS section_analytique_section7_id,
      t_sections_analytiques.section7_code AS section_analytique_section7_code,
      t_sections_analytiques.section7_texte AS section_analytique_section7_texte,
      t_sections_analytiques.section8_id AS section_analytique_section8_id,
      t_sections_analytiques.section8_code AS section_analytique_section8_code,
      t_sections_analytiques.section8_texte AS section_analytique_section8_texte,
      t_sections_analytiques.section9_id AS section_analytique_section9_id,
      t_sections_analytiques.section9_code AS section_analytique_section9_code,
      t_sections_analytiques.section9_texte AS section_analytique_section9_texte,
      p_repartitions_analytiques_shs.section_analytique_origine_id,
      t_sections_analytiques_origine.code AS section_analytique_origine_code,
      t_sections_analytiques_origine.texte AS section_analytique_origine_texte,
      t_sections_analytiques_origine.section1_id AS section_analytique_origine_section1_id,
      t_sections_analytiques_origine.section1_code AS section_analytique_origine_section1_code,
      t_sections_analytiques_origine.section1_texte AS section_analytique_origine_section1_texte,
      t_sections_analytiques_origine.section2_id AS section_analytique_origine_section2_id,
      t_sections_analytiques_origine.section2_code AS section_analytique_origine_section2_code,
      t_sections_analytiques_origine.section2_texte AS section_analytique_origine_section2_texte,
      t_sections_analytiques_origine.section3_id AS section_analytique_origine_section3_id,
      t_sections_analytiques_origine.section3_code AS section_analytique_origine_section3_code,
      t_sections_analytiques_origine.section3_texte AS section_analytique_origine_section3_texte,
      t_sections_analytiques_origine.section4_id AS section_analytique_origine_section4_id,
      t_sections_analytiques_origine.section4_code AS section_analytique_origine_section4_code,
      t_sections_analytiques_origine.section4_texte AS section_analytique_origine_section4_texte,
      t_sections_analytiques_origine.section5_id AS section_analytique_origine_section5_id,
      t_sections_analytiques_origine.section5_code AS section_analytique_origine_section5_code,
      t_sections_analytiques_origine.section5_texte AS section_analytique_origine_section5_texte,
      t_sections_analytiques_origine.section6_id AS section_analytique_origine_section6_id,
      t_sections_analytiques_origine.section6_code AS section_analytique_origine_section6_code,
      t_sections_analytiques_origine.section6_texte AS section_analytique_origine_section6_texte,
      t_sections_analytiques_origine.section7_id AS section_analytique_origine_section7_id,
      t_sections_analytiques_origine.section7_code AS section_analytique_origine_section7_code,
      t_sections_analytiques_origine.section7_texte AS section_analytique_origine_section7_texte,
      t_sections_analytiques_origine.section8_id AS section_analytique_origine_section8_id,
      t_sections_analytiques_origine.section8_code AS section_analytique_origine_section8_code,
      t_sections_analytiques_origine.section8_texte AS section_analytique_origine_section8_texte,
      t_sections_analytiques_origine.section9_id AS section_analytique_origine_section9_id,
      t_sections_analytiques_origine.section9_code AS section_analytique_origine_section9_code,
      t_sections_analytiques_origine.section9_texte AS section_analytique_origine_section9_texte,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'R'::bpchar AND p_repartitions_analytiques_shs.etape_id = 0 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_realisation_avant_repartition,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'R'::bpchar AND p_repartitions_analytiques_shs.etape_id = 1 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_realisation_1,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'R'::bpchar AND p_repartitions_analytiques_shs.etape_id = 2 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_realisation_2,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'R'::bpchar AND p_repartitions_analytiques_shs.etape_id = 3 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_realisation_3,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'R'::bpchar AND p_repartitions_analytiques_shs.etape_id = 4 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_realisation_4,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'R'::bpchar AND p_repartitions_analytiques_shs.etape_id = 5 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_realisation_5,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'R'::bpchar AND p_repartitions_analytiques_shs.etape_id = 6 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_realisation_6,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'R'::bpchar AND p_repartitions_analytiques_shs.etape_id = 7 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_realisation_7,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'R'::bpchar AND p_repartitions_analytiques_shs.etape_id = 8 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_realisation_8,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'R'::bpchar AND p_repartitions_analytiques_shs.etape_id = 9 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_realisation_9,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'R'::bpchar AND t_etapes_analytiques.est_derniere_etape = '1'::bpchar THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_realisation_apres_repartition,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'P'::bpchar AND p_repartitions_analytiques_shs.etape_id = 0 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_prevision_avant_repartition,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'P'::bpchar AND p_repartitions_analytiques_shs.etape_id = 1 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_prevision_1,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'P'::bpchar AND p_repartitions_analytiques_shs.etape_id = 2 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_prevision_2,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'P'::bpchar AND p_repartitions_analytiques_shs.etape_id = 3 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_prevision_3,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'P'::bpchar AND p_repartitions_analytiques_shs.etape_id = 4 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_prevision_4,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'P'::bpchar AND p_repartitions_analytiques_shs.etape_id = 5 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_prevision_5,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'P'::bpchar AND p_repartitions_analytiques_shs.etape_id = 6 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_prevision_6,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'P'::bpchar AND p_repartitions_analytiques_shs.etape_id = 7 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_prevision_7,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'P'::bpchar AND p_repartitions_analytiques_shs.etape_id = 8 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_prevision_8,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'P'::bpchar AND p_repartitions_analytiques_shs.etape_id = 9 THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_prevision_9,
          CASE
              WHEN p_repartitions_analytiques_shs.code_prevision_realisation = 'P'::bpchar AND t_etapes_analytiques.est_derniere_etape = '1'::bpchar THEN p_repartitions_analytiques_shs.montant
              ELSE 0::numeric
          END AS montant_prevision_apres_repartition,
      0 AS no_oid,
      ''::text AS no_code,
      ''::text AS no_texte,
      t_comptes_c.section_id AS compte_section_id,
      t_comptes_c.section_code AS compte_section_code,
      t_comptes_c.section_texte AS compte_section_texte,
      t_sections_analytiques.section_id AS section_analytique_section_id,
      t_sections_analytiques.section_code AS section_analytique_section_code,
      t_sections_analytiques.section_texte AS section_analytique_section_texte,
      t_sections_analytiques_origine.section_id AS section_analytique_origine_section_id,
      t_sections_analytiques_origine.section_code AS section_analytique_origine_section_code,
      t_sections_analytiques_origine.section_texte AS section_analytique_origine_section_texte
     FROM compta.p_repartitions_analytiques_shs,
      compta.t_comptes_c,
      compta.t_sections_analytiques,
      compta.t_sections_analytiques t_sections_analytiques_origine,
      compta.t_etapes_analytiques
    WHERE p_repartitions_analytiques_shs.compte_id = t_comptes_c.oid AND p_repartitions_analytiques_shs.section_analytique_id = t_sections_analytiques.oid AND p_repartitions_analytiques_shs.section_analytique_origine_id = t_sections_analytiques_origine.oid AND p_repartitions_analytiques_shs.etape_id = t_etapes_analytiques.oid;