-- 1---


	UPDATE p_demandeententeprealablepha A
	JOIN p_prestationmedicaments_temp B ON (B.codePrestataire=A.codePrestataire)
	AND (B.numeroFeuilleMaladie=A.numeroFeuilleMaladie)
	AND (B.codeMedicament=A.codeMedicament)
	SET A.facture="1"
	WHERE (B.idPrescriptionTemp=@idPrescriptionTemp)
	AND (B.numeroFeuilleMaladie=@numeroFeuilleMaladie)
	AND (B.codePrestataire=@codePrestataire)
	AND (B.consultation!="1") AND (B.idFacture="0");

-- 2---

UPDATE p_detailprescription A
	JOIN p_prestationmedicaments_temp B ON (B.idDetailprescription=A.id)
	SET 
		A.livre = B.livre,
		A.codePrestataireLivraison = CASE WHEN B.livre="1" THEN @codePrestataire ELSE "" END
	WHERE (B.idPrescriptionTemp=@idPrescriptionTemp)
	AND (B.consultation!="1") AND (B.idFacture="0");	
	 	
	SELECT
		COUNT(*),
		SUM(IFNULL(fraisReel,"0")),
		SUM(IFNULL(prixManuel,"0")), 
		SUM(IFNULL(fraisExclu,"0")),
		SUM(IFNULL(montantArembourserTemp,"0")), 
		SUM(IFNULL(montantTmTemp,"0")), 
		SUM(IFNULL(montantArembourserTemp,"0")),
		SUM(IFNULL(deltaPrix,"0"))
	INTO
		@nbLivre,
		@fraisReel, 
		@prixManuel,
		@fraisExclu,
		@fraisRetenu, 
		@montantTm, 
		@montantArembourser,
		@deltaPrix
	FROM p_detailprescription 
	WHERE (numeroPrescription=p_numeroPrescription)
	AND (livre="1");