-- MONTANT REFERENT VALIDES
SELECT 
SUM(prt.montantApayer)
FROM p_prestationactes prt JOIN p_facture B ON (B.id=prt.idfacture)
INNER JOIN  police C ON  (B.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=B.idAdherent))
INNER JOIN beneficiaire e ON (e.id=prt.idBeneficiaire)
INNER JOIN entetecontrat Ce ON (Ce.idPolice=B.idPolice)
WHERE (prt.debut BETWEEN Ce.dateEffet AND Ce.dateFin
AND Ce.exercice=2022
AND Ce.id = fn_id_entetecontrat_beneficiaire_courant(prt.idBeneficiaire))
-- AND (CASE WHEN "138" IS NULL THEN B.idPolice IS NOT NULL ELSE B.idPolice="138" END)  
AND G.id!='45' AND C.idClient!='49'   
-- AND B.codePrestataire IN ('CE0236') ;  -- 4 128 762
-- 770 482 534



SELECT * FROM prestataire WHERE libelle LIKE "%myria%"


SELECT * FROM entenete