	SELECT Gc.codeGcAssureur,fn_libelle_garant_rp (Gc.codeGcAssureur) AS garant,
	 B.idPolice,Po.numeroPolice,Po.libellePolice,
	 a.id,a.numeroAdherent AS numero, CONCAT (a.nom ," ",a.prenoms) AS Adherent,
	 B.id,B.numeroBeneficiaire AS numero, CONCAT (B.nomBeneficiaire," ",B.prenomsBeneficiaire) AS beneficaire,
	COUNT(A.codeGarantie) AS Quantite,SUM(IFNULL(A.montantApayer,0)) AS apresDecompte
	FROM p_prestationactes A
	INNER JOIN p_facture Bp ON (Bp.id=A.idfacture)
	INNER JOIN beneficiaire B ON ( B.id=A.idBeneficiaire )
	INNER JOIN police Po ON (Po.id=B.idPolice)
	INNER JOIN gc_assureur Gc ON  (Po.codeGcAssureur = Gc.codeGcAssureur)
	INNER JOIN adherent a ON ((Po.id=a.idPolice) AND (Po.codeSociete=a.codeSociete) AND ( a.id=B.idAdherent))
	INNER JOIN garantie G ON (A .codeGarantie=G.codeGarantie)
	INNER JOIN prestataire p  ON (A.codePrestataire=p.codePrestataire)
	WHERE (LEFT(Bp.dateSysteme,10) BETWEEN '2022-01-01' AND '2022-05-31')
	AND p.codePrestataire NOT IN ('CE0416','PR1176','CE1215','CE1232','PR1175')
	-- AND facture = "1" AND (A.fraisReel>"0")

	 AND A.codeGarantie IN ('CON') -- AND A.codeActe !='CHF'
	GROUP BY Gc.codeGcAssureur,Po.numeroPolice,B.idPolice,Po.libellePolice,B.id,B.numeroBeneficiaire,B.nomBeneficiaire,B.prenomsBeneficiaire
	,a.id,a.numeroAdherent,a.nom ,a.prenoms
	HAVING COUNT(B.id)>=10
	ORDER BY Gc.codeGcAssureur,B.idPolice,Quantite DESC;