SELECT
			C.codeGcAssureur,C.id,C.numeroPolice,C.libellePolice,
		FROM p_prestationactes prt 
		INNER JOIN beneficiaire e ON (e.id=prt.idBeneficiaire)
		-- JOIN p_facture B ON (B.id=prt.idfacture)
		INNER JOIN  police C ON  (e.idPolice = C.id)
		INNER 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=e.idAdherent))
		-- INNER JOIN entetecontrat T ON (T.idPolice=e.idPolice)		
		WHERE (LEFT(prt.dateSysteme,10) BETWEEN '' AND @dateFin)
		AND G.id!='45' AND C.idClient!='49' 
		-- AND T.id=fn_id_entetecontrat_police_courant(e.idPolice) AND (e.dateEffet<=@dateFin) 
		AND prt.codePrestataire NOT IN ('CE0416','PR1176','CE1215','CE1232','CE1287','PR1175','CE1276')
		GROUP BY prt.dateSysteme,C.codeGcAssureur,C.id,C.numeroPolice,C.libellePolice
		
		
		
		
		
SELECT 
	 P.codeGcAssureur,P.id,P.numeroPolice,P.libellePolice,COUNT(A.codeActe) nbrActe
FROM p_prestationactes A
JOIN beneficiaire B ON (B.id=A.idBeneficiaire)
JOIN entetecontrat C ON (C.idPolice=B.idPolice)
INNER JOIN  police P ON  (B.idPolice = P.id)
WHERE A.ententePrealable NOT IN ('2','9')
AND A.debut BETWEEN C.dateEffet AND C.dateFin
-- AND C.id=fn_id_entetecontrat_police_courant(P.id) AND (B.dateEffet<='2022-10-31') 
AND (LEFT(A.dateSysteme,10) BETWEEN '2022-01-01' AND '2022-10-31')
GROUP BY   P.codeGcAssureur,P.id,P.numeroPolice,P.libellePolice
ORDER BY nbrActe DESC;