From b4c30519a2165dfeaba46ab316dab2cfef5f1c5e Mon Sep 17 00:00:00 2001
From: Antony Le Courtes <antony.lecourtes@unicaen.fr>
Date: Fri, 20 Nov 2020 15:17:14 +0100
Subject: [PATCH] =?UTF-8?q?Refonte=20de=20l'indicateur=20320=20:=20Ne=20li?=
 =?UTF-8?q?ster=20que=20les=20intervenants=20qui=20n'ont=20pas=20encore=20?=
 =?UTF-8?q?de=20contrat=20=C3=A9dit=C3=A9.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 data/ddl/view/V_INDICATEUR_320.sql | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/data/ddl/view/V_INDICATEUR_320.sql b/data/ddl/view/V_INDICATEUR_320.sql
index 1c63987f66..70f7ca699b 100644
--- a/data/ddl/view/V_INDICATEUR_320.sql
+++ b/data/ddl/view/V_INDICATEUR_320.sql
@@ -4,16 +4,22 @@ SELECT
   t."ANNEE_ID",t."INTERVENANT_ID",t."STRUCTURE_ID"
 FROM (
 SELECT DISTINCT
-  w.annee_id,
-  w.intervenant_id,
-  w.structure_id
+	w.annee_id,
+	w.intervenant_id,
+	w.structure_id
 FROM
-  tbl_workflow w
-  LEFT JOIN tbl_contrat c ON c.INTERVENANT_ID = w.intervenant_id AND w.structure_id = c.structure_id
+	tbl_workflow w
+	JOIN intervenant i ON w.intervenant_id = i.id
+	JOIN statut_intervenant si ON si.id = i.statut_id
+	LEFT JOIN contrat c ON c.intervenant_id = w.intervenant_id
 WHERE
-  w.atteignable = 1
-  AND w.etape_code = 'CONTRAT'
-  AND w.objectif > 0
-  AND w.realisation = 0
-  AND NVL(c.EDITE,0) <> 1
+	w.atteignable = 1
+	AND w.etape_code = 'CONTRAT'
+	AND w.objectif > 0
+	AND w.realisation = 0
+	AND c.histo_destruction IS NULL
+	AND i.histo_destruction IS NULL
+	AND si.histo_destruction IS NULL
+	AND c.id IS NULL
+	AND si.peut_avoir_contrat = 1
 ) t
\ No newline at end of file
-- 
GitLab