-- 15 MONTANT CONSULATION GENERALISTE EN PRVISOIRE
SELECT   
CONCAT ('0',MONTH(LEFT(B.dateSysteme,10)),'/',YEAR(LEFT(B.dateSysteme,10))) AS DatePaiement,    
A.codePrestataire Compte,fn_libelle_prestataire(A.codePrestataire) AS Prestataire,A.codeActe,A.datePrestation,
-- DATEDIFF("2022-12-31",'2022-02-01')+1	
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,
 IFNULL(A.fraisReel,0) AS montantReclame,IFNULL(A.montantTm,0) AS montantTm,IFNULL(A.montantRedresse,0) AS montantRedresse,IFNULL(A.montantApayer,0) AS montantRembourse
FROM p_prestationactes A
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 prestataire p  ON (A.codePrestataire=p.codePrestataire)
INNER JOIN entetecontrat C ON (C.idPolice=B.idPolice)
WHERE (LEFT(B.dateSysteme,10) BETWEEN '2022-01-01' AND '2022-06-30' )
AND fn_id_entetecontrat_police(B.idPolice,CURDATE())=fn_id_entetecontrat_police_courant(B.idPolice)
AND Gc.id!='45'  AND (B.codeSociete="vitalis")  AND A.codeActe IN ('C')
AND A.montantApayer>0 -- AND A.facture="0"
AND C.id = fn_id_entetecontrat_police_courant(B.idPolice)
AND B.idPolice=156
AND p.codePrestataire  IN ("CE1376") 
ORDER BY  DatePaiement,A.codePrestataire,B.id DESC;


SELECT  A.*
FROM p_prestationactes A
INNER JOIN beneficiaire B ON ( B.id=A.idBeneficiaire ) 
WHERE (LEFT(B.dateSysteme,10) BETWEEN '2022-01-01' AND '2022-06-30' ) AND B.numeroBeneficiaire=0156241901 AND A.codeActe IN ('C')

