diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index ac138636b08f8ba06ce6265425d65b9575e9f5fc..06d5a64a8c8b78e64c116a9555a6f23f360c0118 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -155,7 +155,7 @@ class FactureFournisseur extends CommonInvoice
         $sql.= ", ".$this->socid;
         $sql.= ", '".$this->db->idate($now)."'";
         $sql.= ", '".$this->db->idate($this->date)."'";
-		$sql.= ", ".$this->fk_project;
+		$sql.= ", ".(isset($this->fk_project)?$this->fk_project:"null");
         $sql.= ", '".$this->db->escape($this->note_private)."'";
         $sql.= ", '".$this->db->escape($this->note_public)."'";
         $sql.= ", ".$user->id.",";
@@ -167,14 +167,14 @@ class FactureFournisseur extends CommonInvoice
         if ($resql)
         {
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn');
-
-            // Update ref with new one
-            $this->ref='(PROV'.$this->id.')';
-            $sql = 'UPDATE '.MAIN_DB_PREFIX."facture_fourn SET ref='".$this->ref."' WHERE rowid=".$this->id;
-
-            dol_syslog(get_class($this)."::create sql=".$sql);
-            $resql=$this->db->query($sql);
-            if (! $resql) $error++;
+
+            // Update ref with new one
+            $this->ref='(PROV'.$this->id.')';
+            $sql = 'UPDATE '.MAIN_DB_PREFIX."facture_fourn SET ref='".$this->ref."' WHERE rowid=".$this->id;
+
+            dol_syslog(get_class($this)."::create sql=".$sql);
+            $resql=$this->db->query($sql);
+            if (! $resql) $error++;
 
             // Add object linked
             if (! $error && $this->id && ! empty($this->origin) && ! empty($this->origin_id))
@@ -1350,8 +1350,8 @@ class FactureFournisseur extends CommonInvoice
         global $db, $langs, $conf;
         $langs->load("orders");
 
-        // Clean parameters (if not defined or using deprecated value)
-        if (empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER)) $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER='mod_facture_fournisseur_cactus';
+        // Clean parameters (if not defined or using deprecated value)
+        if (empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER)) $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER='mod_facture_fournisseur_cactus';
 
         $mybool=false;
 
@@ -1365,25 +1365,25 @@ class FactureFournisseur extends CommonInvoice
             $mybool|=@include_once $dir.$file;
         }
 
-        if (! $mybool)
-        {
-        	dol_print_error('',"Failed to include file ".$file);
-        	return '';
+        if (! $mybool)
+        {
+        	dol_print_error('',"Failed to include file ".$file);
+        	return '';
         }
 
-        $obj = new $classname();
-
-        $numref = "";
-        $numref = $obj->getNumRef($soc,$this,$mode);
-
-        if ( $numref != "")
-        {
-        	return $numref;
-        }
-        else
-       {
-        	//dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error);
-        	return false;
+        $obj = new $classname();
+
+        $numref = "";
+        $numref = $obj->getNumRef($soc,$this,$mode);
+
+        if ( $numref != "")
+        {
+        	return $numref;
+        }
+        else
+       {
+        	//dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error);
+        	return false;
         }
     }
 
diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php
index f7ade7b3d62ddab9f7fa2db5e9e6272ecffe5e7d..d4010f6c4954c6eb92f9be0bd54463f544da4408 100644
--- a/htdocs/fourn/facture/fiche.php
+++ b/htdocs/fourn/facture/fiche.php
@@ -270,16 +270,18 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
     {
         $db->begin();
 
+        $tmpproject = GETPOST('projectid', 'int');
+
         // Creation facture
         $object->ref           = $_POST['ref'];
 		$object->ref_supplier  = $_POST['ref_supplier'];
-		$object->fk_project    = GETPOST('projectid');
         $object->socid         = $_POST['socid'];
         $object->libelle       = $_POST['libelle'];
         $object->date          = $datefacture;
         $object->date_echeance = $datedue;
         $object->note_public   = GETPOST('note_public');
         $object->note_private  = GETPOST('note_private');
+        $object->fk_project    = ($tmpproject > 0) ? $tmpproject : null;
 
         // If creation from another object of another module
         if ($_POST['origin'] && $_POST['originid'])