Commit 437aa0af authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Modification de l'état de sortie imputation budgétaire SIHAM pour faire une...

Modification de l'état de sortie imputation budgétaire SIHAM pour faire une répartition par pourcentage par matricule et code indémnité.
parent e1afe8dc
Loading
Loading
Loading
Loading
+25 −26
Original line number Diff line number Diff line
CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE_SIHAM AS
CREATE
OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE_SIHAM AS
SELECT 'P'                                                                                type,
       NULL                                                                               uo,
       intervenant_matricule                                                              matricule,
       date_debut                                                                         date_debut,
       date_fin                                                                           date_fin,
       CASE
           WHEN rem_fc_d714 > 0 THEN '1542'
           ELSE
               CASE WHEN type_intervenant_code = 'P' THEN '0204' ELSE '2251' END
           END                                                                            code_indemnite,
       code_indemnite                                                                     code_indemnite,
       eotp_code                                                                          operation,
       centre_cout_code                                                                   centre_cout,
       domaine_fonctionnel_code                                                           destination,
@@ -17,11 +14,11 @@ SELECT 'P'
       to_char((CASE
                    WHEN pourc_ecart >= 0 THEN
                        CASE
                            WHEN rank() OVER (PARTITION BY periode_id, intervenant_id, etat ORDER BY CASE WHEN (pourc_ecart >= 0 AND pourc_diff >= 0) OR (pourc_ecart < 0 AND pourc_diff < 0) THEN pourc_diff ELSE -1 END DESC) <= (ABS(pourc_ecart) / 0.001) THEN hetd_pourc + (pourc_ecart / abs(pourc_ecart) * 0.001)
                            WHEN rank() OVER (PARTITION BY periode_id, intervenant_id, code_indemnite, etat   ORDER BY CASE WHEN (pourc_ecart >= 0 AND pourc_diff >= 0) OR (pourc_ecart < 0 AND pourc_diff < 0) THEN pourc_diff ELSE -1 END DESC) <= (ABS(pourc_ecart) / 0.001) THEN hetd_pourc + (pourc_ecart / abs(pourc_ecart) * 0.001)
                            ELSE hetd_pourc END
                    ELSE
                        CASE
                            WHEN rank() OVER (PARTITION BY periode_id, intervenant_id, etat ORDER BY CASE WHEN (pourc_ecart >= 0 AND pourc_diff >= 0) OR (pourc_ecart < 0 AND pourc_diff < 0) THEN pourc_diff ELSE -1 END) <= (ABS(pourc_ecart) / 0.001) THEN hetd_pourc + (pourc_ecart / abs(pourc_ecart) * 0.001)
                            WHEN rank() OVER (PARTITION BY periode_id, intervenant_id,code_indemnite, etat   ORDER BY CASE WHEN (pourc_ecart >= 0 AND pourc_diff >= 0) OR (pourc_ecart < 0 AND pourc_diff < 0) THEN pourc_diff ELSE -1 END) <= (ABS(pourc_ecart) / 0.001) THEN hetd_pourc + (pourc_ecart / abs(pourc_ecart) * 0.001)
                            ELSE hetd_pourc END
           END)) * 100                                                                    pourcentage,
--       pourc_ecart,
@@ -42,13 +39,11 @@ SELECT 'P'
       hetd_montant,
       rem_fc_d714,
       type_intervenant_id
FROM (
         SELECT dep3.*,
                1 - CASE WHEN hetd > 0 THEN SUM(hetd_pourc) OVER ( PARTITION BY periode_id, intervenant_id, etat) ELSE 0 END pourc_ecart
FROM (SELECT dep3.*,
             1 - CASE WHEN hetd > 0 THEN SUM(hetd_pourc) OVER ( PARTITION BY periode_id, intervenant_id, etat, code_indemnite) ELSE 0 END pourc_ecart


         FROM (
                  SELECT periode_id,
      FROM (SELECT periode_id,
                   type_intervenant_id,
                   type_intervenant_code,
                   intervenant_id,
@@ -71,7 +66,8 @@ FROM (
                   domaine_fonctionnel_code,
                   domaine_fonctionnel_libelle,
                   hetd,
                         round(CASE WHEN hetd > 0 THEN hetd / SUM(hetd) OVER( PARTITION BY periode_id, intervenant_id, etat) ELSE 0 END, 3) hetd_pourc,
                   code_indemnite                                                                                                                      code_indemnite,
                   round(CASE WHEN hetd > 0 THEN hetd / SUM(hetd) OVER( PARTITION BY periode_id, intervenant_id,  code_indemnite, etat) ELSE 0 END, 3) hetd_pourc,
                   round(hetd * taux_horaire, 2)                                                                                                       hetd_montant,
                   round(fc_majorees * taux_horaire, 2)                                                                                                rem_fc_d714,
                   exercice_aa,
@@ -80,12 +76,10 @@ FROM (
                   round(exercice_ac * taux_horaire, 2)                                                                                                exercice_ac_montant,


                         (CASE WHEN hetd > 0 THEN hetd / SUM(hetd) OVER( PARTITION BY periode_id, intervenant_id, etat) ELSE 0 END)
                   (CASE WHEN hetd > 0 THEN hetd / SUM(hetd) OVER( PARTITION BY periode_id, intervenant_id, etat, code_indemnite) ELSE 0 END)
                       -
                         round(CASE WHEN hetd > 0 THEN hetd / SUM(hetd) OVER( PARTITION BY periode_id, intervenant_id, etat) ELSE 0 END, 3) pourc_diff

                  FROM (
                           WITH dep AS ( -- détails par état de paiement
                   round(CASE WHEN hetd > 0 THEN hetd / SUM(hetd) OVER( PARTITION BY periode_id, intervenant_id, etat, code_indemnite) ELSE 0 END, 3)  pourc_diff
            FROM (WITH dep AS ( -- détails par état de paiement
                SELECT CASE WHEN th.code = 'fc_majorees' THEN 1 ELSE 0 END                        is_fc_majoree,
                       p.id                                                                       periode_id,
                       i.id                                                                       intervenant_id,
@@ -108,6 +102,13 @@ FROM (
                       i.code_rh                                                                  intervenant_matricule,
                       i.nom_usuel || ' ' || i.prenom                                             intervenant_nom,
                       i.numero_insee                                                             intervenant_numero_insee,
                       CASE
                           WHEN round(CASE WHEN th.code = 'fc_majorees' THEN mep.heures ELSE 0 END *
                                      ose_formule.get_taux_horaire_hetd(nvl(mep.date_mise_en_paiement, sysdate)), 2) > 0
                               THEN '1542'
                           ELSE
                               CASE WHEN ti.code = 'P' THEN '204' ELSE '2251' END
                           END                                                                    code_indemnite,
                       CASE
                           WHEN cc.parent_id IS NULL THEN cc.source_code
                           ELSE cc2.source_code END                                               centre_cout_code,
@@ -135,7 +136,7 @@ FROM (
                         LEFT JOIN validation v ON v.id = mep.validation_id AND v.histo_destruction IS NULL
                         LEFT JOIN domaine_fonctionnel df ON df.id = mis.domaine_fonctionnel_id
                         LEFT JOIN periode p ON p.id = mep.periode_paiement_id
                           )
                WHERE mep.date_mise_en_paiement IS NOT NULL)
                  SELECT periode_id,
                         type_intervenant_id,
                         MAX(type_intervenant_code) type_intervenant_code,
@@ -162,7 +163,8 @@ FROM (
                         SUM(fc_majorees)           fc_majorees,
                         SUM(exercice_aa)           exercice_aa,
                         SUM(exercice_ac)           exercice_ac,
                                  taux_horaire
                         taux_horaire,
                         code_indemnite
                  FROM dep
                  GROUP BY periode_id,
                           type_intervenant_id,
@@ -186,11 +188,8 @@ FROM (
                           domaine_fonctionnel_code,
                           domaine_fonctionnel_libelle,
                           taux_horaire,
                                    is_fc_majoree
                       ) dep2
              ) dep3
     ) dep4

                           is_fc_majoree,
                           code_indemnite) dep2) dep3) dep4
ORDER BY annee_id,
         type_intervenant_id,
         periode_id,