	SELECT
	  pr.codePrestataire AS codeP,pr.libelle AS Prestataire,l.codeLocalite AS CODE ,l.libelle AS localite,
	pr.adresseGeo,pr.telephoneFixe,pr.telephonePortable, 
	
		SUM(IFNULL(prt.fraisRetenu,0)) AS montantFacture,
		SUM(IFNULL(prt.montantApayer,0)) AS apresDecompte
		
	FROM p_prestationactes prt INNER JOIN p_facture B ON (B.id=prt.idfacture)  
	INNER JOIN police P ON  (B.idPolice = P.id)
	INNER JOIN gc_assureur G ON  (P.codeGcAssureur = G.codeGcAssureur)
	INNER JOIN prestataire pr ON (B.codePrestataire=pr.codePrestataire)
	INNER JOIN adherent a ON ((P.id=a.idPolice) AND (P.codeSociete=a.codeSociete) AND ( a.id=B.idAdherent))
	INNER JOIN typeprestataire t ON (t.codeTypePrestataire=pr.codeTypePrestataire)
	INNER JOIN localite_ci l ON (l.codeLocalite=pr.codeLocalite)
	WHERE (LEFT(B.dateSysteme,10) BETWEEN '2022-01-01' AND '2022-12-31' )
	AND pr.codeTypePrestataire='PHA'  
	
	-- and pr.codePrestataire IN ('PR0638','PR0648','PR0274','PR0423')
	 AND prt.CodeGarantie='PHA' 
	AND B.idPolice NOT IN ( SELECT id FROM police WHERE `idClient` = "49")
	AND G.id!='45' AND P.idClient!='49' AND (B.codeSociete="vitalis") AND prt.montantApayer!=0
	AND B.codePrestataire NOT IN ('CE0416','PR1176','CE1215','CE1232','PR1175')
	GROUP BY pr.codePrestataire,pr.libelle,l.codeLocalite ,l.libelle,
	pr.adresseGeo,pr.telephoneFixe,pr.telephonePortable 
	ORDER BY localite, apresDecompte DESC