diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index c776e6706ce549003b9c42920a6547048c75d76c..32a1970fc0f913afbb8c2a3379daeaaeddc15b6f 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -161,27 +161,19 @@ if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->
 	}
 }
 
+// Repasse la facture en mode brouillon
 if ($_GET['action'] == 'modif' && $user->rights->facture->modifier && $conf->global->FACTURE_ENABLE_EDITDELETE)
 {
-  /*
-   *  Repasse la facture en mode brouillon
-   */
-  $fac = new Facture($db);
+	$fac = new Facture($db);
   $fac->fetch($_GET['facid']);
   
-  // On v�rifie si les lignes de factures ont �t� export�es en compta et/ou ventil�es
-  $ventilExportCompta = 0 ;
-  for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++)
-  {
-  	if ($fac->lignes[$i]->export_compta <> 0 && $fac->lignes[$i]->code_ventilation <> 0)
-  	{
-  		$ventilExportCompta++;
-  	}
-  }
-  
-  if ($ventilExportCompta == 0)
-  {
-  	$fac->reopen($user);
+	// On v�rifie si les lignes de factures ont �t� export�es en compta et/ou ventil�es
+	$ventilExportCompta = $fac->getVentilExportCompta();
+	
+	// On v�rifie si aucun paiement n'a �t� effectu�
+	if ($resteapayer == $fac->total_ttc	&& $fac->paye == 0 && $ventilExportCompta == 0)
+	{
+		$fac->reopen($user);
   }
 }
 
@@ -2111,14 +2103,7 @@ else
 				if ($fac->statut == 1)
 				{
 					// On v�rifie si les lignes de factures ont �t� export�es en compta et/ou ventil�es
-					$ventilExportCompta = 0 ;
-					for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++)
-					{
-						if ($fac->lignes[$i]->export_compta <> 0 && $fac->lignes[$i]->code_ventilation <> 0)
-						{
-							$ventilExportCompta++;
-						}
-					}
+					$ventilExportCompta = $fac->getVentilExportCompta();
 			
 					if ($conf->global->FACTURE_ENABLE_EDITDELETE && $user->rights->facture->modifier
 					&& ($resteapayer == $fac->total_ttc	&& $fac->paye == 0 && $ventilExportCompta == 0))
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index e96e48faa18227ca22cf441041d2364b1b112f3f..7523173b716f45d9e3fd5ff25639dee896e7393e 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -1835,13 +1835,41 @@ class Facture extends CommonObject
 
 
    /**
-	*   \brief      Renvoi si une facture peut etre supprim�e compl�tement
+	  *   \brief      Renvoi si les lignes de facture sont ventil�es et/ou export�es en compta
+    *   \param      user        Utilisateur cr�ant la demande
+    *   \return     int         <0 si ko, 0=non, 1=oui
+	  */
+	  function getVentilExportCompta()
+	  {
+	  	// On v�rifie si les lignes de factures ont �t� export�es en compta et/ou ventil�es
+			$ventilExportCompta = 0 ;
+			for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
+			{
+				if ($this->lignes[$i]->export_compta <> 0 && $this->lignes[$i]->code_ventilation <> 0)
+				{
+					$ventilExportCompta++;
+				}
+			}
+			
+			if ($ventilExportCompta <> 0)
+			{
+				return 1;
+			}
+			else
+			{
+				return 0;
+			}
+		}
+   
+   
+   /**
+	  *   \brief      Renvoi si une facture peut etre supprim�e compl�tement
     *				La r�gle est la suivante:
     *				Si facture derni�re, non provisoire, sans paiement et non export� en compta -> oui fin de r�gle
     *       Si facture brouillon et provisoire -> oui
     *   \param      user        Utilisateur cr�ant la demande
     *   \return     int         <0 si ko, 0=non, 1=oui
-	*/
+	  */
 	function is_erasable()
 	{
 		global $conf, $db;
@@ -1862,16 +1890,8 @@ class Facture extends CommonObject
 			{
 				$maxfacnumber = $db->fetch_row($resql);
 			}
-
-			// On v�rifie si les lignes de factures ont �t� export�es en compta et/ou ventil�es
-			$ventilExportCompta = 0 ;
-			for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
-			{
-				if ($this->lignes[$i]->export_compta <> 0 && $this->lignes[$i]->code_ventilation <> 0)
-				{
-					$ventilExportCompta++;
-				}
-			}
+			
+			$ventilExportCompta = $this->getVentilExportCompta();
 
 			// Si derniere facture et si non ventil�e, on peut supprimer
 			if ($maxfacnumber[0] == $this->ref && $ventilExportCompta == 0)
@@ -1889,10 +1909,10 @@ class Facture extends CommonObject
 	
 	
    /**
-	*   \brief      Cr�� une demande de pr�l�vement
+	  *   \brief      Cr�� une demande de pr�l�vement
     *   \param      user        Utilisateur cr�ant la demande
     *   \return     int         <0 si ko, >0 si ok
-	*/
+	  */
 	function demande_prelevement($user)
 	{
         dolibarr_syslog("Facture::demande_prelevement $this->statut $this->paye $this->mode_reglement_id");