From d0d2cd7d02be0687555cef790d5e6075ed27a78e Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Sun, 16 Jul 2006 12:46:07 +0000
Subject: [PATCH] =?UTF-8?q?Am=E9lioration=20s=E9curit=E9=20sur=20l'=E9diti?=
 =?UTF-8?q?on=20d'un=20facture=20valid=E9e?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 htdocs/compta/facture.php | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 32a1970fc0f..e75a6c80232 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -167,6 +167,25 @@ if ($_GET['action'] == 'modif' && $user->rights->facture->modifier && $conf->glo
 	$fac = new Facture($db);
   $fac->fetch($_GET['facid']);
   
+  // On v�rifie si la facture a des paiements
+  $sql = 'SELECT pf.amount,';
+	$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
+	$sql.= ' WHERE pf.fk_facture = '.$fac->id;
+
+	$result = $db->query($sql);
+	
+	if ($result)
+	{
+		while ($i < $num)
+		{
+			$objp = $db->fetch_object($result);
+			$totalpaye += $objp->amount;
+		  $i++;
+		}
+	}
+			
+  $resteapayer = $fac->total_ttc - $totalpaye;
+  
 	// On v�rifie si les lignes de factures ont �t� export�es en compta et/ou ventil�es
 	$ventilExportCompta = $fac->getVentilExportCompta();
 	
-- 
GitLab