SELECT
		CONCAT (B.codeMois,'/',B.codeExercice) AS DatePaiement,B.codePrestataire,
		fn_codeNormalise_prestataire_rp(B.codePrestataire) AS Compte,L.libelle AS localite,fn_libelle_prestataire(B.codePrestataire) AS prestataire,
		P.codeGcAssureur,fn_libelle_garant_rp(P.codeGcAssureur) Garant,P.idClient , fn_libelle_souscripteur(P.idClient) AS Souscripteur
		,P.id AS idPolice,P.numeroPolice,P.libellePolice,
		B.idBeneficiaire AS idBeneficiaire,be.numeroBeneficiaire,CONCAT(be.nomBeneficiaire,' ',be.prenomsBeneficiaire)  Beneficiaire,
		B.numeroFeuilleMaladie AS FeuilleMaladie,  `d`.`numeroPrescription` AS `numeroPrescription`,
		`d`.`numeroBonOrdonnance` AS `numeroBonOrdonnance`, `m`.`codeForme` AS `codeForme`,`d`.`codeMedicament` AS `codeMedicament`,
		`m`.`libelle` AS `libelleMedicament`,	
		 d.valeurActeManuel AS tarifMedicament,	`d`.`quantite`  AS `quantite`,
	`d`.`fraisReel` AS `fraisReel`,`d`.`montantTm` AS `montantTm`,d.fraisExclu  AS fraisExclu,`d`.`montantArembourser`  AS `montantArembourser`
	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 `pays` AS pa ON (pa.codePays = pr.codePays)
  	INNER JOIN `ville` AS v ON (v.codeVille = pr.codeVille)
 	INNER JOIN `localite` AS L ON (L.codeLocalite = pr.codeLocalite)
 	INNER JOIN adherent a ON ((P.id=a.idPolice) AND (P.codeSociete=a.codeSociete) AND ( a.id=B.idAdherent))
 	INNER JOIN beneficiaire be ON (B.idBeneficiaire=be.id) 
 	INNER JOIN p_detailprescription d ON (B.numeroFeuilleMaladie=d.numeroFeuilleMaladie)
 	LEFT JOIN p_medicament m ON (m.codeMedicament=d.codeMedicament)
	WHERE (LEFT(B.dateSysteme,10) BETWEEN '2022-04-01' AND '2022-04-30' )	
	AND P.idClient!="49" 
	AND pr.codePrestataire='CE1465'
	-- AND L.codeLocalite  IN ('1002','0107','0103')
	-- AND (B.fraisRetenu!=0)  AND d.valeurActeManuel!=0
	-- AND B.tiersPayant ="1" AND G.id!='45'
	-- AND B.codePrestataire IN ('PR1086','PR1077','PR1383','PR1088','PR1095','PR1092','PR1093','PR0879')
	-- AND pr.codeTypePrestataire='PHA' 
	AND (B.codeSociete="vitalis")
	ORDER BY DatePaiement,Compte,P.id,idBeneficiaire,FeuilleMaladie  ASC ;
	
	-- select * from prestataire where libelle like '%COCO%'
	