-- CE1479 : LABORATOIRE CENTRE MEDICAL MAIRIE DE KOUMASSI

-- CE1287 : CME MAIRIE DE KOUMASSI

-- 1 --RECHERCHE DANS FEUILLES MALADIES
SELECT  -- f.codePrestataire CodeFeuille,p.codePrestataire CodePrestation,
c.* ,numeroLotDecompte,numeroDecompte
FROM `p_feuillemaladie` f
INNER JOIN p_prestationactes p ON (f.numeroFeuilleMaladie=p.numeroFeuilleMaladie)
INNER JOIN p_facture c ON (c.id=p.idFacture)
WHERE f.codePrestataire IN ("CE1479") AND p.datePrestation>="2022-01-01"
AND p.codeTypePrestation="EXAM"
AND c.dateSysteme  BETWEEN "2022-01-01" AND "2022-01-31" 
ORDER BY p.datePrestation



SELECT * FROM `p_prestationactes` WHERE codePrestataire IN("CE1377") AND codeTypePrestation="EXAM"

SELECT * FROM `p_prestationactes` WHERE codePrestataire IN("CE1479") AND codeTypePrestation="EXAM" AND datePrestation>="2022-01-01"


SELECT * FROM p_feuillemaladie  WHERE numeroFeuilleMaladie="25788"



UPDATE  p_facture
SET montantArembourser=(fraisReel-montantTm),fraisRetenu=fraisReel
,montantApayerCalc=montantArembourser,montantApayer=montantArembourser
WHERE numeroFeuilleMaladie IN (18370,18466,18502,18520)
AND codePrestataire IN ("CE1479")

SELECT * FROM p_facture  WHERE numeroFeuilleMaladie IN (18370,18466,18502,18520)
AND codePrestataire IN ("CE1479")


- 1 --RECHERCHE DANS FEUILLES MALADIES
SELECT  
c.*
FROM `p_feuillemaladie` f
INNER JOIN p_prestationactes p ON (f.numeroFeuilleMaladie=p.numeroFeuilleMaladie)
INNER JOIN p_detailexamen d ON ((d.numeroFeuilleMaladie=p.numeroFeuilleMaladie))
INNER JOIN p_facture c ON (c.id=p.idFacture)
WHERE f.codePrestataire IN ("CE1479") AND p.datePrestation>="2022-01-01"
AND p.codeTypePrestation="EXAM" -- and p.montantApayer=0
AND f.numeroBonOrdonnance IN (19112,18962,19094,19058)
AND c.dateSysteme  BETWEEN "2022-01-01" AND "2022-03-31"
 ORDER BY p.datePrestation


-- 2-- mise à jour decompte

UPDATE `p_feuillemaladie` f
INNER JOIN p_prestationactes p ON (f.numeroFeuilleMaladie=p.numeroFeuilleMaladie)
INNER JOIN p_facture c ON (c.id=p.idFacture)
INNER JOIN p_detailexamen d ON (d.numeroFeuilleMaladie=p.numeroFeuilleMaladie)
SET d.codePrestataireLivraison="CE1479" 
-- SET c.numeroLotDecompte="202202L001348",c.numeroDecompte="2790",c.montantApayer=f.montantArembourser
WHERE f.codePrestataire IN ("CE1287") AND p.datePrestation>="2022-01-01"
AND p.codeTypePrestation="EXAM"
AND c.dateSysteme  BETWEEN "2022-01-01" AND "2022-02-28" 

SELECT * FROM `p_detailexamen`