Commit 955dc04c authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Imputation SIHAM

parent 12066f24
CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE_SIHAM AS
SELECT
'P' Type,
null uo,
......@@ -14,10 +14,12 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
NULL fonds,
NULL poste_reservation_credit,
to_char((CASE WHEN pourc_ecart >= 0 THEN
CASE WHEN RANK() OVER (PARTITION BY periode_id, intervenant_id, etat, structure_id 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
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) ELSE hetd_pourc END
ELSE
CASE WHEN RANK() OVER (PARTITION BY periode_id, intervenant_id, etat, structure_id 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
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) ELSE hetd_pourc END
END)) * 100 pourcentage,
-- pourc_ecart,
-- pourc_diff,
NULL nombres_heures,
NULL FLMODI,
NULL NUMORD,
......@@ -28,7 +30,6 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
centre_cout_id,
domaine_fonctionnel_id,
etat,
composante,
date_mise_en_paiement,
domaine_fonctionnel_code,
hetd,
......@@ -40,14 +41,13 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
(
SELECT
dep3.*,
1-CASE WHEN hetd > 0 THEN SUM( hetd_pourc ) OVER ( PARTITION BY periode_id, intervenant_id, etat, structure_id) ELSE 0 END pourc_ecart
1-CASE WHEN hetd > 0 THEN SUM( hetd_pourc ) OVER ( PARTITION BY periode_id, intervenant_id, etat) ELSE 0 END pourc_ecart
FROM (
SELECT
periode_id,
structure_id,
type_intervenant_id,
type_intervenant_code,
intervenant_id,
......@@ -55,7 +55,6 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
centre_cout_id,
domaine_fonctionnel_id,
etat,
composante,
date_mise_en_paiement,
date_debut,
date_fin,
......@@ -71,7 +70,7 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
domaine_fonctionnel_code,
domaine_fonctionnel_libelle,
hetd,
ROUND( CASE WHEN hetd > 0 THEN hetd / SUM( hetd ) OVER( PARTITION BY periode_id, intervenant_id, etat, structure_id) ELSE 0 END, 3 ) hetd_pourc,
ROUND( CASE WHEN hetd > 0 THEN hetd / SUM( hetd ) OVER( PARTITION BY periode_id, intervenant_id, 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,16 +79,15 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
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, structure_id) ELSE 0 END)
(CASE WHEN hetd > 0 THEN hetd / SUM( hetd ) OVER( PARTITION BY periode_id, intervenant_id, etat) ELSE 0 END)
-
ROUND( CASE WHEN hetd > 0 THEN hetd / SUM( hetd ) OVER( PARTITION BY periode_id, intervenant_id, etat, structure_id) ELSE 0 END, 3 ) pourc_diff
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
SELECT
CASE WHEN th.code = 'fc_majorees' THEN 1 ELSE 0 END is_fc_majoree,
p.id periode_id,
s.id structure_id,
i.id intervenant_id,
i.annee_id annee_id,
cc.id centre_cout_id,
......@@ -104,7 +102,6 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
TRIM(to_char( add_months( a.date_debut, p.ecart_mois ), 'dd/mm/yyyy' )) date_debut,
TRIM(to_char( last_day(add_months( a.date_debut, p.ecart_mois )), 'dd/mm/yyyy' )) date_fin,
mep.date_mise_en_paiement date_mise_en_paiement,
s.libelle_court composante,
ti.libelle statut,
i.source_code intervenant_code,
i.code_rh intervenant_matricule,
......@@ -131,14 +128,12 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
JOIN annee a ON a.id = i.annee_id
JOIN statut_intervenant si ON si.id = i.statut_id
JOIN type_intervenant ti ON ti.id = si.type_intervenant_id
JOIN structure s ON s.id = mis.structure_id
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
)
SELECT
periode_id,
structure_id,
type_intervenant_id,
MAX(type_intervenant_code) type_intervenant_code,
intervenant_id,
......@@ -148,7 +143,6 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
etat,
date_debut,
date_fin,
composante,
date_mise_en_paiement,
statut,
intervenant_code,
......@@ -170,7 +164,6 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
dep
GROUP BY
periode_id,
structure_id,
type_intervenant_id,
intervenant_id,
annee_id,
......@@ -179,7 +172,6 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
etat,
date_debut,
date_fin,
composante,
date_mise_en_paiement,
statut,
intervenant_code,
......@@ -201,11 +193,9 @@ CREATE OR REPLACE FORCE VIEW V_IMPUTATION_BUDGETAIRE AS
)
dep4
ORDER BY
ORDER BY
annee_id,
type_intervenant_id,
structure_id,
periode_id,
intervenant_nom
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment