	SELECT
		G.codeGcAssureur,fn_libelle_garant_rp (G.codeGcAssureur) AS garant,
		C.id,C.numeroPolice,C.libellePolice,
		a.id,a.numeroAdherent,CONCAT(a.nom,' ',a.prenoms)  adherent,
		SUM(IFNULL(prt.montantApayer,0)) AS montantRembourse	
	FROM p_prestationactes prt JOIN p_facture B ON (B.id=prt.idfacture)
	JOIN police C ON  (B.idPolice = C.id)
	JOIN gc_assureur G ON  (C.codeGcAssureur = G.codeGcAssureur)
	INNER JOIN adherent a ON ((C.id=a.idPolice) AND (C.codeSociete=a.codeSociete) AND ( a.id=B.idAdherent))
	WHERE (LEFT(B.dateSysteme,10) BETWEEN '2022-01-01' AND '2022-05-31')

	AND G.id!='45' AND C.idClient!='49' AND (B.codeSociete="vitalis")
	AND B.codePrestataire NOT IN ('CE0416','PR1176','CE1215','CE1232','PR1175')
	GROUP BY  a.id,a.numeroAdherent,a.nom,a.prenoms ,C.id,C.libellePolice,C.numeroPolice 
	HAVING 	 SUM(IFNULL(prt.montantApayer,0)) >= 500000

	ORDER BY G.codeGcAssureur,C.id,montantRembourse DESC,C.id,adherent;