Correction V_TBL_AGREMENT.sql / Ajout de structure_id sur agrement conseil...
Correction V_TBL_AGREMENT.sql / Ajout de structure_id sur agrement conseil restreint. / Script de migration pour remettre les structure_id manquant sur les agrements
Changes for data/ddl/package/UNICAEN_TBL/body.sql: 24 added lines, 38 removed lines.
Original line number
Diff line number
Diff line
@@ -323,7 +323,7 @@ CREATE OR REPLACE PACKAGE BODY "UNICAEN_TBL" AS
(WITH i_s AS (
SELECT
fr.intervenant_id,
ep.structure_id ep_structure_id
ep.structure_id structure_id
FROM
formule_resultat fr
JOIN type_volume_horaire tvh ON tvh.code = ''PREVU'' AND tvh.id = fr.type_volume_horaire_id
@@ -337,21 +337,21 @@ CREATE OR REPLACE PACKAGE BODY "UNICAEN_TBL" AS
),
avi AS (
SELECT
i.code code_intervenant,
i.code intervenant_code,
i.annee_id annee_id,
a.type_agrement_id type_agrement,
a.type_agrement_id type_agrement_id,
a.id agrement_id,
tas.duree_vie duree_vie,
i.annee_id+duree_vie date_validite
a.structure_id structure_id
FROM intervenant i
JOIN type_agrement_statut tas ON tas.statut_intervenant_id = i.statut_id
JOIN agrement a ON a.intervenant_id = i.id AND tas.type_agrement_id = a.type_agrement_id AND a.histo_destruction IS NULL
JOIN agrement a ON a.intervenant_id = i.id
WHERE
a.histo_destruction IS NULL
)
SELECT DISTINCT "ANNEE_ID","ANNEE_AGREMENT","TYPE_AGREMENT_ID","INTERVENANT_ID","CODE_INTERVENANT","STRUCTURE_ID","OBLIGATOIRE","AGREMENT_ID","DUREE_VIE","RANK" FROM (
SELECT DISTINCT "ANNEE_ID","ANNEE_AGREMENT","TYPE_AGREMENT_ID","INTERVENANT_ID","CODE_INTERVENANT","STRUCTURE_ID","OBLIGATOIRE","AGREMENT_ID","DUREE_VIE" FROM (
SELECT
i.annee_id annee_id,
CASE
WHEN NVL(NVL(a.id, avi.agrement_id),0) = 0
WHEN COALESCE (avi.agrement_id,0) = 0
THEN NULL
ELSE NVL(avi.annee_id, i.annee_id) END annee_agrement,
tas.type_agrement_id type_agrement_id,
@@ -359,12 +359,12 @@ CREATE OR REPLACE PACKAGE BODY "UNICAEN_TBL" AS
i.code code_intervenant,
null structure_id,
tas.obligatoire obligatoire,
NVL(a.id, avi.agrement_id) agrement_id,
avi.agrement_id agrement_id,
tas.duree_vie duree_vie,
RANK() OVER(
PARTITION BY i.code,i.annee_id ORDER BY
CASE
WHEN NVL(NVL(a.id, avi.agrement_id),0) = 0
WHEN COALESCE (avi.agrement_id,0) = 0
THEN NULL
ELSE NVL(avi.annee_id, i.annee_id) END DESC
) rank
@@ -374,20 +374,13 @@ CREATE OR REPLACE PACKAGE BODY "UNICAEN_TBL" AS
AND tas.histo_destruction IS NULL
JOIN intervenant i ON i.histo_destruction IS NULL
-- AND (tas.premier_recrutement IS NULL OR NVL(i.premier_recrutement,0) = tas.premier_recrutement)
AND i.statut_id = tas.statut_intervenant_id
JOIN i_s ON i_s.intervenant_id = i.id
LEFT JOIN agrement a ON a.type_agrement_id = ta.id
AND a.intervenant_id = i.id
AND a.histo_destruction IS NULL
LEFT JOIN avi ON i.code = avi.code_intervenant
AND tas.type_agrement_id = avi.type_agrement
AND i.annee_id < avi.date_validite
AND i.annee_id >= avi.annee_id
JOIN avi ON i.code = avi.intervenant_code
AND avi.type_agrement_id = tas.type_agrement_id
AND i.annee_id < avi.annee_id + tas.duree_vie
WHERE
ta.code = ''CONSEIL_ACADEMIQUE'')
@@ -395,24 +388,24 @@ CREATE OR REPLACE PACKAGE BODY "UNICAEN_TBL" AS
rank = 1
UNION ALL
SELECT DISTINCT "ANNEE_ID","ANNEE_AGREMENT","TYPE_AGREMENT_ID","INTERVENANT_ID","CODE_INTERVENANT","STRUCTURE_ID","OBLIGATOIRE","AGREMENT_ID","DUREE_VIE","RANK" FROM (
SELECT DISTINCT "ANNEE_ID","ANNEE_AGREMENT","TYPE_AGREMENT_ID","INTERVENANT_ID","CODE_INTERVENANT","STRUCTURE_ID","OBLIGATOIRE","AGREMENT_ID","DUREE_VIE" FROM (
SELECT
i.annee_id annee_id,
CASE
WHEN NVL(NVL(a.id, avi.agrement_id),0) = 0
WHEN COALESCE (avi.agrement_id,0) = 0
THEN NULL
ELSE NVL(avi.annee_id, i.annee_id) END annee_agrement,
tas.type_agrement_id type_agrement_id,
i.id intervenant_id,
i.code code_intervenant,
a.structure_id structure_id,
i_s.structure_id structure_id,
tas.obligatoire obligatoire,
NVL(a.id, avi.agrement_id) agrement_id,
avi.agrement_id agrement_id,
tas.duree_vie duree_vie,
RANK() OVER(
PARTITION BY i.code,i.annee_id,i_s.ep_structure_id ORDER BY
PARTITION BY i.code,i.annee_id,i_s.structure_id ORDER BY
CASE
WHEN NVL(NVL(a.id, avi.agrement_id),0) = 0
WHEN COALESCE (avi.agrement_id,0) = 0
THEN NULL
ELSE NVL(avi.annee_id, i.annee_id) END DESC
) rank
@@ -426,18 +419,11 @@ CREATE OR REPLACE PACKAGE BODY "UNICAEN_TBL" AS
JOIN i_s ON i_s.intervenant_id = i.id
LEFT JOIN agrement a ON a.type_agrement_id = ta.id
AND a.structure_id = i_s.ep_structure_id
AND a.intervenant_id = i.id
AND a.histo_destruction IS NULL
LEFT JOIN avi ON i.code = avi.code_intervenant
AND tas.type_agrement_id = avi.type_agrement
AND a.id = avi.agrement_id
AND i.annee_id < avi.date_validite
LEFT JOIN avi ON i.code = avi.intervenant_code
AND avi.type_agrement_id = tas.type_agrement_id
AND COALESCE(avi.structure_id,0) = COALESCE(i_s.structure_id,0)