SELECT * FROM p_prestationactes
WHERE idBeneficiaire=18610
-- numeroBeneficiaire="0185019701" -- "0185019701"
-- WHERE id IN (55955,76318,45363)


CALL recherchecolonne ('codeActe')


SELECT * FROM p_acte WHERE  codeActe='AC0000419'

SELECT   fn_garantie_acte('AC0000419');

SELECT * FROM p_prestationactes
WHERE codeGarantie=""


SELECT * FROM beneficiaire WHERE nomBeneficiaire="FOFANA" AND prenomsBeneficiaire="DRAMANE"


SELECT * FROM p_prestationactes
WHERE codeActe IN ( SELECT codeActe FROM p_acte WHERE codeGarantie="MAT")
AND codeGarantie!="MAT"
AND YEAR(LEFT(dateSysteme,10))=2022
AND MONTH(LEFT(dateSysteme,10))>=9


-- PRESTATION / FACTURE
UPDATE p_prestationactes p
INNER JOIN p_facture f ON (f.id=p.idfacture)
SET p.codeGarantie="MAT",f.codeGarantie="MAT"
WHERE p.codeActe IN ( SELECT codeActe FROM p_acte WHERE codeGarantie="MAT")
AND p.codeGarantie!="MAT"
AND YEAR(LEFT(p.dateSysteme,10))=2022
AND MONTH(LEFT(p.dateSysteme,10))>=1

-- PRESTATION

UPDATE p_prestationactes p
-- INNER JOIN p_facture f ON (f.id=p.idfacture)
SET p.codeGarantie="MAT" -- ,f.codeGarantie="MAT"
WHERE p.codeActe IN ( SELECT codeActe FROM p_acte WHERE codeGarantie="MAT")
AND p.codeGarantie!="MAT"
AND YEAR(LEFT(p.dateSysteme,10))=2022


UPDATE  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)
LEFT JOIN p_feuillemaladie f ON (f.numeroFeuilleMaladie =B.numeroFeuilleMaladie )

SET prt.codeGarantie=fn_garantie_acte_tout(codeActe,f.numeroFeuilleMaladie)

WHERE (LEFT(B.dateSysteme,10)  BETWEEN "2022-08-01" AND "2022-08-31" )
AND (prt.codeGarantie="HOS") AND B.montantApayer>0  
AND (CASE WHEN 168 IS NULL THEN B.idPolice IS NOT NULL ELSE B.idPolice=168 END)  
AND G.id!='45' AND C.idClient!='49' 