diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index 0c6458f37ee8dd23daa4f5b2d508bc8d493b3783..6e1a58dafe9a26250cbbdd619c19842fb6365a08 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -1923,7 +1923,7 @@ class Facture extends CommonObject
 		$idarray=array();
 
 		$sql = 'SELECT rowid';
-		$sql.= ' FROM '.MAIN_DB_PREFIX.'facture';
+		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
 		$sql.= ' WHERE fk_facture_source = '.$this->id;
 		$sql.= ' AND type = 2';
 		$resql=$this->db->query($sql);
@@ -1953,7 +1953,7 @@ class Facture extends CommonObject
 	function getIdReplacingInvoice($option='')
 	{
 		$sql = 'SELECT rowid';
-		$sql.= ' FROM '.MAIN_DB_PREFIX.'facture';
+		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
 		$sql.= ' WHERE fk_facture_source = '.$this->id;
 		$sql.= ' AND type < 2';
 		if ($option == 'validated') $sql.= ' AND fk_statut = 1';
diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php
index 216f590c466bb9b13d997a75b2750cf1cf6a8920..8ed19d42c45573cbe3716bbc413ac2da1b4b8b96 100644
--- a/htdocs/fourn/facture/fiche.php
+++ b/htdocs/fourn/facture/fiche.php
@@ -515,6 +515,7 @@ else
 			print '<td width="50%" valign="top">'.$langs->trans('NotePublic').'</td>';
 			print '</tr>';
 
+			// Ref
 			print '<tr><td valign="top">'.$langs->trans('Ref').'</td><td valign="top">';
 			print $fac->ref.'</td>';
 
@@ -594,7 +595,7 @@ else
 		else
 		{
 			/*
-			 *
+			 *	View card
 			 */
 			$head = facturefourn_prepare_head($fac);
 			$titre=$langs->trans('SupplierInvoice');
diff --git a/htdocs/fourn/fournisseur.facture.class.php b/htdocs/fourn/fournisseur.facture.class.php
index a76b56793dd212138da7865075c50e7147bfd471..eceb7550eecfac1cc322f5e8a0b4ed6fd4c159fb 100644
--- a/htdocs/fourn/fournisseur.facture.class.php
+++ b/htdocs/fourn/fournisseur.facture.class.php
@@ -47,6 +47,8 @@ class FactureFournisseur extends Facture
 	var $ref;
 	var $ref_supplier;
 	var $socid;
+	//! 0=Standard invoice, 1=Replacement invoice, 2=Credit note invoice, 3=Deposit invoice, 4=Proformat invoice
+	var $type;
 	//! 0=draft,
 	//! 1=validated,
 	//! TODO Ce statut doit etre 2 et non 1 classee payee partiellement (close_code='discount_vat','badcustomer') ou completement (close_code=null),
@@ -231,6 +233,8 @@ class FactureFournisseur extends Facture
 				$this->ref           = $this->id;
 				$this->ref_supplier  = $obj->facnumber;
 
+				$this->type          = 0;
+
 				$this->datep         = $obj->df;
 				$this->date          = $obj->df;
 				$this->date_echeance = $obj->de;
@@ -268,9 +272,9 @@ class FactureFournisseur extends Facture
 			}
 			else
 			{
-				dol_syslog('FactureFournisseur::Fetch rowid='.$rowid.' numrows=0 sql='.$sql);
 				$this->error='Bill with id '.$rowid.' not found sql='.$sql;
-				dol_print_error($this->db);
+				dol_syslog('FactureFournisseur::Fetch rowid='.$rowid.' numrows=0 sql='.$sql);
+				dol_print_error('',$sql);
 				return -2;
 			}
 		}
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index 05bb19abc2c40ba4783b466bbb5e064254f94b95..3bc2e0b6385e40caaf69794b0316f63b3efa6348 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -451,13 +451,14 @@ class Form
 	 *		\param      htmlname        Name of field in form
 	 *    	\param      filter          Optionnal filters criteras
 	 *		\param		showempty		Add an empty field
+	 * 		\param		showtype		Show if third party is customer, prospect or supplier
 	 */
-	function select_societes($selected='',$htmlname='socid',$filter='',$showempty=0)
+	function select_societes($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0)
 	{
-		global $conf,$user;
+		global $conf,$user,$langs;
 
 		// On recherche les societes
-		$sql = "SELECT s.rowid, s.nom, s.code_client, s.code_fournisseur";
+		$sql = "SELECT s.rowid, s.nom, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
 		$sql.= " FROM ".MAIN_DB_PREFIX ."societe as s";
 		if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 		$sql.= " WHERE s.entity = ".$conf->entity;
@@ -507,13 +508,22 @@ class Form
 					while ($i < $num)
 					{
 						$obj = $this->db->fetch_object($resql);
+						$label=$obj->nom;
+						if ($showtype)
+						{
+							if ($obj->client || $obj->fournisseur) $label.=' (';
+							if ($obj->client == 1) $label.=$langs->trans("Customer");
+							if ($obj->client == 2) $label.=$langs->trans("Prospect");
+							if ($obj->fournisseur) $label.=($obj->client?', ':'').$langs->trans("Supplier");
+							if ($obj->client || $obj->fournisseur) $label.=')';
+						}
 						if ($selected > 0 && $selected == $obj->rowid)
 						{
-							print '<option value="'.$obj->rowid.'" selected="true">'.$obj->nom.'</option>';
+							print '<option value="'.$obj->rowid.'" selected="true">'.$label.'</option>';
 						}
 						else
 						{
-							print '<option value="'.$obj->rowid.'">'.$obj->nom.'</option>';
+							print '<option value="'.$obj->rowid.'">'.$label.'</option>';
 						}
 						$i++;
 					}
diff --git a/htdocs/lib/project.lib.php b/htdocs/lib/project.lib.php
index b417fd5059075563e14e8ec32fcebff4f7606f50..5cc8d16e06017365641bd25ccd00b25d952bdf32 100644
--- a/htdocs/lib/project.lib.php
+++ b/htdocs/lib/project.lib.php
@@ -97,11 +97,11 @@ function task_prepare_head($object)
  */
 function select_projects($socid, $selected='', $htmlname='projectid')
 {
-	global $db;
+	global $db,$langs;
 
 	// On recherche les projets
-	$sql = 'SELECT p.rowid, p.ref, p.title FROM ';
-	$sql.= MAIN_DB_PREFIX .'projet as p';
+	$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc';
+	$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
 	$sql.= " WHERE (fk_soc='".$socid."' or fk_soc IS NULL)";
 	$sql.= " ORDER BY p.title ASC";
 
@@ -118,13 +118,15 @@ function select_projects($socid, $selected='', $htmlname='projectid')
 			while ($i < $num)
 			{
 				$obj = $db->fetch_object($resql);
+				$labeltoshow=dol_trunc($obj->ref,12).' - '.dol_trunc($obj->title,12);
+				if (empty($obj->fk_soc)) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
 				if (!empty($selected) && $selected == $obj->rowid)
 				{
-					print '<option value="'.$obj->rowid.'" selected="true">'.dol_trunc($obj->ref,12).' - '.dol_trunc($obj->title,12).'</option>';
+					print '<option value="'.$obj->rowid.'" selected="true">'.$labeltoshow.'</option>';
 				}
 				else
 				{
-					print '<option value="'.$obj->rowid.'">'.dol_trunc($obj->ref,12).' - '.dol_trunc($obj->title,12).'</option>';
+					print '<option value="'.$obj->rowid.'">'.$labeltoshow.'</option>';
 				}
 				$i++;
 			}
diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php
index da7db1e8a75cec100561d6a880dd791c354735db..fcf7702c5b79e623141cd64e3b5129ee74c34257 100644
--- a/htdocs/projet/fiche.php
+++ b/htdocs/projet/fiche.php
@@ -166,7 +166,7 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer)
 	// Client
 	print '<tr><td>'.$langs->trans("Company").'</td><td>';
 	//print $_REQUEST["socid"];
-	print $html->select_societes($_REQUEST["socid"],'socid','',1);
+	print $html->select_societes($_REQUEST["socid"],'socid','',1,1);
 	print '</td></tr>';
 
 	// Responsable du projet
@@ -232,7 +232,7 @@ else
 
 		// Client
 		print '<tr><td>'.$langs->trans("Company").'</td><td>';
-		print $html->select_societes($projet->societe->id,'socid','',1);
+		print $html->select_societes($projet->societe->id,'socid','',1,1);
 		print '</td></tr>';
 
 		// Responsable du projet
diff --git a/mysql/migration/2.6.0-2.7.0.sql b/mysql/migration/2.6.0-2.7.0.sql
index 4d2d91b55b4d2132caec0bb101dd59f495545446..d6b7dfb7971438b7619fe97886e3832e1abb325f 100644
--- a/mysql/migration/2.6.0-2.7.0.sql
+++ b/mysql/migration/2.6.0-2.7.0.sql
@@ -72,6 +72,8 @@ ALTER TABLE llx_adherent ADD UNIQUE INDEX uk_adherent_fk_soc (fk_soc);
 
 alter table llx_facture add column  tms timestamp after date_valid;
 alter table llx_facture_fourn add column  tms timestamp after datef;
+alter table llx_facture_fourn add column  fk_facture_source   integer after fk_user_valid;
+  
 update llx_facture set tms = datec where tms <= 0;
 update llx_facture_fourn set tms = datec where tms <= 0;
 
diff --git a/mysql/tables/llx_facture_fourn.sql b/mysql/tables/llx_facture_fourn.sql
index 93a4ce35babd48173360f25eacd13bc2d29e897d..c7ddcd98a7e52b3e0b09925a33132e8e6775bdc7 100644
--- a/mysql/tables/llx_facture_fourn.sql
+++ b/mysql/tables/llx_facture_fourn.sql
@@ -46,6 +46,7 @@ create table llx_facture_fourn
   fk_user_author      integer,                       -- createur de la facture
   fk_user_valid       integer,                       -- valideur de la facture
 
+  fk_facture_source   integer,                       -- facture origine si facture avoir
   fk_projet           integer,                       -- projet auquel est associ�e la facture
 
   fk_cond_reglement   integer  DEFAULT 1 NOT NULL,   -- condition de reglement (30 jours, fin de mois ...)