diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php
index 68268db861afd03ecceaa3f3c0b258f896c45542..88d34d4f6005387417ddc4a340800ab541fbcf78 100644
--- a/htdocs/expedition/class/expedition.class.php
+++ b/htdocs/expedition/class/expedition.class.php
@@ -785,7 +785,7 @@ class Expedition extends CommonObject
 
 				$this->lignes[$i] = $line; // TODO deprecated
 				$this->lines[$i] = $line;
-				
+
 				$i++;
 			}
 			$this->db->free($resql);
@@ -875,37 +875,12 @@ class Expedition extends CommonObject
 
 		dol_syslog("Expedition::initAsSpecimen");
 
-		// Charge tableau des id de societe socids
-		$socids = array();
-
-		$sql = "SELECT rowid";
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe";
-		$sql.= " WHERE client IN (1, 3)";
-		$sql.= " AND entity = ".$conf->entity;
-		$sql.= " LIMIT 10";
-
-		$resql = $this->db->query($sql);
-		if ($resql)
-		{
-			$num_socs = $this->db->num_rows($resql);
-			$i = 0;
-			while ($i < $num_socs)
-			{
-				$i++;
-
-				$row = $this->db->fetch_row($resql);
-				$socids[$i] = $row[0];
-			}
-		}
-
 		// Charge tableau des produits prodids
 		$prodids = array();
-
 		$sql = "SELECT rowid";
 		$sql.= " FROM ".MAIN_DB_PREFIX."product";
 		$sql.= " WHERE tosell = 1";
 		$sql.= " AND entity = ".$conf->entity;
-
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
@@ -926,7 +901,6 @@ class Expedition extends CommonObject
 		$this->id=0;
 		$this->ref = 'SPECIMEN';
 		$this->specimen=1;
-		$socid = rand(1, $num_socs);
 		$this->statut               = 1;
 		if ($conf->livraison_bon->enabled)
 		{
@@ -935,11 +909,14 @@ class Expedition extends CommonObject
 		$this->date                 = time();
 		$this->entrepot_id          = 0;
 		$this->fk_delivery_address  = 0;
-		$this->socid = $socids[$socid];
+		$this->socid                = 1;
 
 		$this->commande_id          = 0;
 		$this->commande             = $order;
 
+        $this->origin_id            = 1;
+        $this->origin               = 'commande';
+
 		$nbp = 5;
 		$xnbp = 0;
 		while ($xnbp < $nbp)
diff --git a/htdocs/includes/modules/commande/pdf_einstein.modules.php b/htdocs/includes/modules/commande/pdf_einstein.modules.php
index 38cee40629b7b9240193fbac1b3661a04cb1ac92..f7bc2abaf1f9d1b2e61a3d4621e3d78f3117e2d2 100644
--- a/htdocs/includes/modules/commande/pdf_einstein.modules.php
+++ b/htdocs/includes/modules/commande/pdf_einstein.modules.php
@@ -954,8 +954,7 @@ class pdf_einstein extends ModelePDFCommandes
 
 			// Show recipient information
 			$pdf->SetFont('','',9);
-			$posy=$pdf->GetY()-9; //Auto Y coord readjust for multiline name
-			$pdf->SetXY($posx+2,$posy+6);
+			$pdf->SetXY($posx+2,$posy+8);
 			$pdf->MultiCell(86,4, $carac_client);
 		}
 	}
diff --git a/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php b/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php
index ad5a452bcdd4b6489f32039a12b19f98383d4de3..d838c4b55ba66bd13cea3bba221c9078041e6fdb 100644
--- a/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php
+++ b/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php
@@ -96,7 +96,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition
 		if ($conf->expedition->dir_output."/sending")
 		{
 			$object->fetch_thirdparty();
-			
+
 			$origin = $object->origin;
 
 			//Creation de l expediteur
@@ -335,7 +335,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition
 	function _pagehead(&$pdf, $object, $outputlangs)
 	{
 		global $conf, $langs;
-		
+
 		$origin = $object->origin;
 
 		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
@@ -432,7 +432,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition
 
 		// Sender name
 		$pdf->SetTextColor(0,0,60);
-		$pdf->SetXY($blSocX,$blSocY);
+		$pdf->SetXY($blSocX,$blSocY+3);
 		$pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->nom), 0, 'L');
 		$pdf->SetTextColor(0,0,0);
 
@@ -440,11 +440,10 @@ Class pdf_expedition_merou extends ModelePdfExpedition
 		$carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
 
 		$pdf->SetFont('','',7);
-		$pdf->SetXY($blSocX,$blSocY+3);
+		$pdf->SetXY($blSocX,$blSocY+6);
 		$pdf->MultiCell(80, 2, $carac_emetteur);
 
 
-
 		if ($object->client->code_client)
 		{
 			$Yoff+=7;
@@ -523,8 +522,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition
 		$pdf->MultiCell($blW,3, $carac_client_name, 0, 'L');
 
 		$pdf->SetFont('','',7);
-		//$posy=$pdf->GetY(); //Auto Y coord readjust for multiline name
-		$pdf->SetXY($blDestX,$pdf->GetY());
+		$pdf->SetXY($blDestX,$Yoff+4);
 		$pdf->MultiCell($blW,2, $carac_client);
 	}
 }
diff --git a/htdocs/includes/modules/facture/pdf_crabe.modules.php b/htdocs/includes/modules/facture/pdf_crabe.modules.php
index 67aeff80d15590f49ba4ab767a6e7ecc126484a8..8715b6b655578a0320a394162865626f3735d225 100644
--- a/htdocs/includes/modules/facture/pdf_crabe.modules.php
+++ b/htdocs/includes/modules/facture/pdf_crabe.modules.php
@@ -1225,8 +1225,7 @@ class pdf_crabe extends ModelePDFFactures
 
 			// Show recipient information
 			$pdf->SetFont('','',9);
-			$posy=$pdf->GetY()-9; //Auto Y coord readjust for multiline name
-			$pdf->SetXY($posx+2,$posy+6);
+			$pdf->SetXY($posx+2,$posy+8);
 			$pdf->MultiCell(86,4, $carac_client, 0, 'L');
 		}
 	}
diff --git a/htdocs/includes/modules/facture/pdf_oursin.modules.php b/htdocs/includes/modules/facture/pdf_oursin.modules.php
index b89c5b26023e2dc34f0f3992ecc35cef7fd39559..5bf31a61f9e414ceff449ea02a340f83d51153a8 100644
--- a/htdocs/includes/modules/facture/pdf_oursin.modules.php
+++ b/htdocs/includes/modules/facture/pdf_oursin.modules.php
@@ -895,7 +895,7 @@ class pdf_oursin extends ModelePDFFactures
 		$pdf->MultiCell(86,4, $carac_client_name, 0, 'L');
 
 		$pdf->SetFont('','B',9);
-		$pdf->SetXY($this->marges['g']+100,$posy+6);
+		$pdf->SetXY($this->marges['g']+100,$posy+8);
 		$pdf->MultiCell(86,4, $carac_client);
 
 		/*
diff --git a/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php b/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php
index 197437c849fe74fe170a7dd06660464886dbb15d..b8e867d46fe5a55fb04963f5b1617d67711eb510 100644
--- a/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php
+++ b/htdocs/includes/modules/livraison/pdf/pdf_typhon.modules.php
@@ -646,7 +646,7 @@ class pdf_typhon extends ModelePDFDeliveryOrder
 			$pdf->MultiCell(106,4, $carac_client_name, 0, 'L');
 
 			$pdf->SetFont('','',9);
-			$pdf->SetXY(102,$posy+7);
+			$pdf->SetXY(102,$posy+8);
 			$pdf->MultiCell(86,4, $carac_client);
 		}
 
diff --git a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php
index 8ff4d52f220b8d7b7f35b24a809316b44414945d..c0fc7be730fa7ad001b56917d9134a1590dcdd98 100644
--- a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php
+++ b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php
@@ -124,7 +124,7 @@ class pdf_propale_azur extends ModelePDFPropales
 		if ($conf->propale->dir_output)
 		{
 			$object->fetch_thirdparty();
-			
+
 			$deja_regle = "";
 
 			// Definition de $dir et $file
@@ -1011,8 +1011,7 @@ class pdf_propale_azur extends ModelePDFPropales
 
 			// Show recipient information
 			$pdf->SetFont('','',9);
-			$posy=$pdf->GetY()-9; //Auto Y coord readjust for multiline name
-			$pdf->SetXY($posx+2,$posy+6);
+			$pdf->SetXY($posx+2,$posy+8);
 			$pdf->MultiCell(86,4, $carac_client);
 		}
 	}
diff --git a/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php b/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php
index 76f92d96f83581e2c818e27b03c1d401b89d0fee..fd9f06d0c06f6fe44a449275efd4ca31a1f35321 100644
--- a/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php
+++ b/htdocs/includes/modules/propale/pdf_propale_jaune.modules.php
@@ -606,8 +606,7 @@ class pdf_propale_jaune extends ModelePDFPropales
 
 		// Show address
 		$pdf->SetFont('','',9);
-		$posy=$pdf->GetY()-9; //Auto Y coord readjust for multiline name
-		$pdf->SetXY(102,$posy+6);
+		$pdf->SetXY(102,$posy+8);
 		$pdf->MultiCell(86,4, $carac_client);
 	}
 
diff --git a/htdocs/lib/pdf.lib.php b/htdocs/lib/pdf.lib.php
index bc343020fc777d4b286ccffb43550bd3c3fac384..8c8834b31078adf9bbff67e0becc37f4da350e74 100644
--- a/htdocs/lib/pdf.lib.php
+++ b/htdocs/lib/pdf.lib.php
@@ -27,102 +27,126 @@
  */
 
 
+
 /**
- *   	\brief      Mutualize code to build address for PDF generation
- * 		\param		outputlangs		Output langs object
- *   	\param      sourcecompany	Source company object
- *   	\param      targetcompany	Target company object
- *      \param      targetcontact	Target contact object
- * 		\param		usecontact		Use contact instead of company
- * 		\return		string			Source of file
+ *      Return a formated address (part address/zip/town/state) according to country rules
+ *      @param      outputlangs     Output langs object
+ *      @param      object          A company or contact object
+ *      @return     string          Formated string
+ */
+function pdf_format_address($outputlangs,$object)
+{
+    $ret='';
+    $countriesusingstate=array('US','IN');
+
+    // Address
+    $ret .= $outputlangs->convToOutputCharset($object->address);
+    // Zip/Town/State
+    if (in_array($object->pays_code,array('US')))   // US: town, state, zip
+    {
+        $ret .= ($ret ? "\n" : '' ).$outputlangs->convToOutputCharset($object->ville);
+        if ($object->departement && in_array($object->pays_code,$countriesusingstate))
+        {
+            $ret.=", ".$outputlangs->convToOutputCharset($object->departement);
+        }
+        if ($object->cp) $ret .= ', '.$outputlangs->convToOutputCharset($object->cp);
+    }
+    else                                        // Other: zip town, state
+    {
+        $ret .= ($ret ? "\n" : '' ).$outputlangs->convToOutputCharset($object->cp);
+        $ret .= ' '.$outputlangs->convToOutputCharset($object->ville);
+        if ($object->departement && in_array($object->pays_code,$countriesusingstate))
+        {
+            $ret.=", ".$outputlangs->convToOutputCharset($object->departement);
+        }
+    }
+
+    return $ret;
+}
+
+
+/**
+ *   	Return a string with full address formated
+ * 		@param		outputlangs		Output langs object
+ *   	@param      sourcecompany	Source company object
+ *   	@param      targetcompany	Target company object
+ *      @param      targetcontact	Target contact object
+ * 		@param		usecontact		Use contact instead of company
+ * 		@return		string			Source of file
  */
 function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source')
 {
-	global $conf;
-
-	$stringaddress = '';
-
-	if ($mode == 'source' && ! is_object($sourcecompany)) return -1;
-	if ($mode == 'target' && ! is_object($targetcompany)) return -1;
-
-	if ($mode == 'source')
-	{
-		$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($sourcecompany->address);
-		$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($sourcecompany->cp).' '.$outputlangs->convToOutputCharset($sourcecompany->ville);
-		if (($sourcecompany->departement_id || $sourcecompany->departement) && in_array($sourcecompany->pays_code,array('US','IN')))
-		{
-			if ($sourcecompany->departement_id && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->departement_id);
-			$stringaddress.=" - ".$outputlangs->convToOutputCharset($sourcecompany->departement);
-		}
-		$stringaddress .= "\n";
-		// Tel
-		if ($sourcecompany->tel) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($sourcecompany->tel);
-		// Fax
-		if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->tel ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
-		// EMail
-		if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
-		// Web
-		if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
-	}
-
-	if ($mode == 'target')
-	{
-		if ($usecontact)
-		{
-			$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1));
-			// Recipient properties
-			$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcontact->address);
-			$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcontact->cp) . " " . $outputlangs->convToOutputCharset($targetcontact->ville);
-			if (($targetcompany->departement_id || $targetcompany->departement) && in_array($targetcompany->pays_code,array('US','IN')))
-			{
-				if ($targetcompany->departement_id && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->departement_id);
-				$stringaddress.=" - ".$outputlangs->convToOutputCharset($targetcompany->departement);
-			}
-			$stringaddress.="\n";
-			if ($targetcontact->pays_code && $targetcontact->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->pays_code))."\n";
-		}
-		else
-		{
-			// Recipient properties
-			$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcompany->address);
-			$stringaddress.="\n".$outputlangs->convToOutputCharset($targetcompany->cp) . " " . $outputlangs->convToOutputCharset($targetcompany->ville);
-			if (($targetcompany->departement_id || $targetcompany->departement) && in_array($targetcompany->pays_code,array('US','IN')))
-			{
-				if ($targetcompany->departement_id && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->departement_id);
-				$stringaddress.=" - ".$outputlangs->convToOutputCharset($targetcompany->departement);
-			}
-			$stringaddress.="\n";
-			if ($targetcompany->pays_code && $targetcompany->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->pays_code))."\n";
-		}
-		// Intra VAT
-		if ($targetcompany->tva_intra) $stringaddress.="\n".$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
-		if ($conf->global->MAIN_PROFID1_IN_ADDRESS)
-		{
-		    $tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->pays_code);
-		    if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
-		    $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
-		}
-		if ($conf->global->MAIN_PROFID2_IN_ADDRESS)
-		{
+    global $conf;
+
+    $stringaddress = '';
+
+    if ($mode == 'source' && ! is_object($sourcecompany)) return -1;
+    if ($mode == 'target' && ! is_object($targetcompany)) return -1;
+
+    if ($sourcecompany->departement_id && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->departement_id);
+    if ($targetcompany->departement_id && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->departement_id);
+
+    if ($mode == 'source')
+    {
+        $stringaddress .= ($stringaddress ? "\n" : '' ).pdf_format_address($outputlangs,$sourcecompany)."\n";
+
+        // Tel
+        if ($sourcecompany->tel) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($sourcecompany->tel);
+        // Fax
+        if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->tel ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
+        // EMail
+        if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
+        // Web
+        if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
+    }
+
+    if ($mode == 'target')
+    {
+        if ($usecontact)
+        {
+            $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1));
+            $stringaddress .= ($stringaddress ? "\n" : '' ).pdf_format_address($outputlangs,$targetcontact)."\n";
+            // Country
+            if ($targetcontact->pays_code && $targetcontact->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->pays_code))."\n";
+        }
+        else
+        {
+            $stringaddress .= ($stringaddress ? "\n" : '' ).pdf_format_address($outputlangs,$targetcompany)."\n";
+            // Country
+            if ($targetcompany->pays_code && $targetcompany->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->pays_code))."\n";
+        }
+
+        // Intra VAT
+        if ($targetcompany->tva_intra) $stringaddress.="\n".$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
+
+        // Professionnal Ids
+        if ($conf->global->MAIN_PROFID1_IN_ADDRESS)
+        {
+            $tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->pays_code);
+            if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
+            $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
+        }
+        if ($conf->global->MAIN_PROFID2_IN_ADDRESS)
+        {
             $tmp=$outputlangs->transcountrynoentities("ProfId2",$targetcompany->pays_code);
             if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
             $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
-		}
-		if ($conf->global->MAIN_PROFID3_IN_ADDRESS)
-		{
+        }
+        if ($conf->global->MAIN_PROFID3_IN_ADDRESS)
+        {
             $tmp=$outputlangs->transcountrynoentities("ProfId3",$targetcompany->pays_code);
             if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
             $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
-		}
-		if ($conf->global->MAIN_PROFID4_IN_ADDRESS)
-		{
+        }
+        if ($conf->global->MAIN_PROFID4_IN_ADDRESS)
+        {
             $tmp=$outputlangs->transcountrynoentities("ProfId4",$targetcompany->pays_code);
             if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
             $stringaddress.="\n".$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
-		}
-	}
+        }
+    }
 
-	return $stringaddress;
+    return $stringaddress;
 }
 
 
@@ -134,13 +158,13 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
  */
 function pdf_pagehead(&$pdf,$outputlangs,$page_height)
 {
-	global $conf;
+    global $conf;
 
-	// Add a background image on document
-	if (! empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF))
-	{
-		$pdf->Image($conf->mycompany->dir_output.'/logos/'.$conf->global->MAIN_USE_BACKGROUND_ON_PDF, 0, 0, 0, $page_height);
-	}
+    // Add a background image on document
+    if (! empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF))
+    {
+        $pdf->Image($conf->mycompany->dir_output.'/logos/'.$conf->global->MAIN_USE_BACKGROUND_ON_PDF, 0, 0, 0, $page_height);
+    }
 }
 
 
@@ -187,111 +211,111 @@ function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
  */
 function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account)
 {
-	global $mysoc;
+    global $mysoc;
 
-	$pdf->SetXY ($curx, $cury);
-	$pdf->SetFont('','B',8);
-	$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0);
-	$cury+=4;
+    $pdf->SetXY ($curx, $cury);
+    $pdf->SetFont('','B',8);
+    $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0);
+    $cury+=4;
 
-	$outputlangs->load("banks");
+    $outputlangs->load("banks");
 
-	// Get format of bank id according to country of $account
-	$usedetailedbban=$account->useDetailedBBAN();
+    // Get format of bank id according to country of $account
+    $usedetailedbban=$account->useDetailedBBAN();
 
-	if ($usedetailedbban)
-	{
+    if ($usedetailedbban)
+    {
         $savcurx=$curx;
 
-	    $pdf->SetFont('','',6);
-		$pdf->SetXY ($curx, $cury);
-		$pdf->MultiCell(90, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
-		$cury+=3;
+        $pdf->SetFont('','',6);
+        $pdf->SetXY ($curx, $cury);
+        $pdf->MultiCell(90, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
+        $cury+=3;
 
-		$pdf->line($curx+1, $cury+1, $curx+1, $cury+10 );
+        $pdf->line($curx+1, $cury+1, $curx+1, $cury+10 );
 
-		$fieldstoshow=array('bank','desk','number','key');
-		if ($account->pays_code == 'ES') $fieldstoshow=array('bank','desk','key','number');
+        $fieldstoshow=array('bank','desk','number','key');
+        if ($account->pays_code == 'ES') $fieldstoshow=array('bank','desk','key','number');
 
-		foreach ($fieldstoshow as $val)
-		{
-		    if ($val == 'bank')
-		    {
-        		// Bank code
+        foreach ($fieldstoshow as $val)
+        {
+            if ($val == 'bank')
+            {
+                // Bank code
                 $tmplength=18;
                 $pdf->SetXY ($curx, $cury+6);
                 $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->code_banque), 0, 'C', 0);
-        		$pdf->SetXY ($curx, $cury+1);
-        		$curx+=$tmplength;
-        		$pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankCode"), 0, 'C', 0);
-        		$pdf->line($curx, $cury+1, $curx, $cury+10 );
-		    }
-		    if ($val == 'desk')
-		    {
-        		// Desk
+                $pdf->SetXY ($curx, $cury+1);
+                $curx+=$tmplength;
+                $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankCode"), 0, 'C', 0);
+                $pdf->line($curx, $cury+1, $curx, $cury+10 );
+            }
+            if ($val == 'desk')
+            {
+                // Desk
                 $tmplength=18;
                 $pdf->SetXY ($curx, $cury+6);
                 $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->code_guichet), 0, 'C', 0);
                 $pdf->SetXY ($curx, $cury+1);
-        		$curx+=$tmplength;
-        		$pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("DeskCode"), 0, 'C', 0);
-        		$pdf->line($curx, $cury+1, $curx, $cury+10 );
-		    }
-		    if ($val == 'number')
-		    {
-        		// Number
+                $curx+=$tmplength;
+                $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("DeskCode"), 0, 'C', 0);
+                $pdf->line($curx, $cury+1, $curx, $cury+10 );
+            }
+            if ($val == 'number')
+            {
+                // Number
                 $tmplength=24;
                 $pdf->SetXY ($curx, $cury+6);
                 $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->number), 0, 'C', 0);
                 $pdf->SetXY ($curx, $cury+1);
-        		$curx+=$tmplength;
-        		$pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumber"), 0, 'C', 0);
-        		$pdf->line($curx, $cury+1, $curx, $cury+10 );
-		    }
-		    if ($val == 'key')
-		    {
-        		// Key
+                $curx+=$tmplength;
+                $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumber"), 0, 'C', 0);
+                $pdf->line($curx, $cury+1, $curx, $cury+10 );
+            }
+            if ($val == 'key')
+            {
+                // Key
                 $tmplength=13;
                 $pdf->SetXY ($curx, $cury+6);
                 $pdf->SetFont('','',8);$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($account->cle_rib), 0, 'C', 0);
                 $pdf->SetXY ($curx, $cury+1);
-        		$curx+=$tmplength;
-        		$pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumberKey"), 0, 'C', 0);
-        		$pdf->line($curx, $cury+1, $curx, $cury+10 );
-		    }
-		}
+                $curx+=$tmplength;
+                $pdf->SetFont('','B',6);$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities("BankAccountNumberKey"), 0, 'C', 0);
+                $pdf->line($curx, $cury+1, $curx, $cury+10 );
+            }
+        }
 
         $curx=$savcurx;
-	}
-	else
-	{
-		$pdf->SetFont('','B',6);
-		$pdf->SetXY ($curx, $cury);
-		$pdf->MultiCell(90, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
-		$cury+=3;
-
-		$pdf->SetFont('','B',6);
-		$pdf->SetXY ($curx, $cury);
-		$pdf->MultiCell(90, 3, $outputlangs->transnoentities("BankAccountNumber").': ' . $outputlangs->convToOutputCharset($account->number), 0, 'L', 0);
-		$cury-=9;
-	}
+    }
+    else
+    {
+        $pdf->SetFont('','B',6);
+        $pdf->SetXY ($curx, $cury);
+        $pdf->MultiCell(90, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
+        $cury+=3;
+
+        $pdf->SetFont('','B',6);
+        $pdf->SetXY ($curx, $cury);
+        $pdf->MultiCell(90, 3, $outputlangs->transnoentities("BankAccountNumber").': ' . $outputlangs->convToOutputCharset($account->number), 0, 'L', 0);
+        $cury-=9;
+    }
     $pdf->SetXY ($curx, $cury+1);
 
-	// Use correct name of bank id according to country
-	$ibankey="IBANNumber";
-	$bickey="BICNumber";
-	if ($account->getCountryCode() == 'IN') $ibankey="IFSC";
-	if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
-
-	$pdf->SetFont('','',6);
-	$pdf->SetXY ($curx, $cury+12);
-	$pdf->MultiCell(90, 3, $outputlangs->transnoentities("Residence").': ' . $outputlangs->convToOutputCharset($account->domiciliation), 0, 'L', 0);
-	$pdf->SetXY ($curx, $cury+22);
-	$pdf->MultiCell(90, 3, $outputlangs->transnoentities($ibankey).': ' . $outputlangs->convToOutputCharset($account->iban), 0, 'L', 0);
-	$pdf->SetXY ($curx, $cury+25);
-	$pdf->MultiCell(90, 3, $outputlangs->transnoentities($bickey).': ' . $outputlangs->convToOutputCharset($account->bic), 0, 'L', 0);
-
-	return $pdf->getY();
+    // Use correct name of bank id according to country
+    $ibankey="IBANNumber";
+    $bickey="BICNumber";
+    if ($account->getCountryCode() == 'IN') $ibankey="IFSC";
+    if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
+
+    $pdf->SetFont('','',6);
+    $pdf->SetXY ($curx, $cury+12);
+    $pdf->MultiCell(90, 3, $outputlangs->transnoentities("Residence").': ' . $outputlangs->convToOutputCharset($account->domiciliation), 0, 'L', 0);
+    $pdf->SetXY ($curx, $cury+22);
+    $pdf->MultiCell(90, 3, $outputlangs->transnoentities($ibankey).': ' . $outputlangs->convToOutputCharset($account->iban), 0, 'L', 0);
+    $pdf->SetXY ($curx, $cury+25);
+    $pdf->MultiCell(90, 3, $outputlangs->transnoentities($bickey).': ' . $outputlangs->convToOutputCharset($account->bic), 0, 'L', 0);
+
+    return $pdf->getY();
 }
 
 
@@ -308,114 +332,114 @@ function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account)
  */
 function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object)
 {
-	global $conf,$user;
+    global $conf,$user;
 
-	$outputlangs->load("dict");
-	$ligne='';
+    $outputlangs->load("dict");
+    $ligne='';
 
-	// Line of free text
-	if (! empty($conf->global->$paramfreetext))
-	{
-		// Make substitution
-		$substitutionarray=array(
+    // Line of free text
+    if (! empty($conf->global->$paramfreetext))
+    {
+        // Make substitution
+        $substitutionarray=array(
 			'__FROM_NAME__' => $fromcompany->nom,
 			'__FROM_EMAIL__' => $fromcompany->email,
 			'__TOTAL_TTC__' => $object->total_ttc,
 			'__TOTAL_HT__' => $object->total_ht,
 			'__TOTAL_VAT__' => $object->total_vat
-		);
-
-		$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs,$object);
-		$ligne.=$outputlangs->convToOutputCharset($newfreetext);
-	}
-
-	// First line of company infos
-
-	// Juridical status
-	$ligne1="";
-	if ($fromcompany->forme_juridique_code)
-	{
-		$ligne1.=($ligne1?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
-	}
-	// Capital
-	if ($fromcompany->capital)
-	{
-		$ligne1.=($ligne1?" - ":"").$outputlangs->transnoentities("CapitalOf",$fromcompany->capital)." ".$outputlangs->transnoentities("Currency".$conf->monnaie);
-	}
-	// Prof Id 1
-	if ($fromcompany->idprof1 && ($fromcompany->pays_code != 'FR' || ! $fromcompany->idprof2))
-	{
-		$field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->pays_code);
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
-		$ligne1.=($ligne1?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
-	}
-	// Prof Id 2
-	if ($fromcompany->idprof2)
-	{
-		$field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->pays_code);
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
-		$ligne1.=($ligne1?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
-	}
-
-	// Second line of company infos
-	$ligne2="";
-	// Prof Id 3
-	if ($fromcompany->idprof3)
-	{
-		$field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->pays_code);
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
-		$ligne2.=($ligne2?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
-	}
-	// Prof Id 4
-	if ($fromcompany->idprof4)
-	{
-		$field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->pays_code);
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
-		$ligne2.=($ligne2?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
-	}
-	// IntraCommunautary VAT
-	if ($fromcompany->tva_intra != '')
-	{
-		$ligne2.=($ligne2?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
-	}
-
-	$pdf->SetFont('','',7);
-	$pdf->SetDrawColor(224,224,224);
-
-	// On positionne le debut du bas de page selon nbre de lignes de ce bas de page
-	$nbofligne=dol_nboflines_bis($ligne,0,$outputlangs->charset_output);
-	//print 'nbofligne='.$nbofligne; exit;
-	//print 'e'.$ligne.'t'.dol_nboflines($ligne);exit;
-	$posy=$marge_basse + ($nbofligne*3) + ($ligne1?3:0) + ($ligne2?3:0);
-
-	if ($ligne)	// Free text
-	{
-		$pdf->SetXY($marge_gauche,-$posy);
-		$width=20000; $align='L';	// By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
-		if ($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT) { $width=200; $align='C'; }
-		$pdf->MultiCell($width, 3, $ligne, 0, $align, 0);
-		$posy-=($nbofligne*3);	// 6 of ligne + 3 of MultiCell
-	}
-
-	$pdf->SetY(-$posy);
-	$pdf->line($marge_gauche, $page_hauteur-$posy, 200, $page_hauteur-$posy);
-	$posy--;
-
-	if ($ligne1)
-	{
-		$pdf->SetXY($marge_gauche,-$posy);
-		$pdf->MultiCell(200, 2, $ligne1, 0, 'C', 0);
-	}
-
-	if ($ligne2)
-	{
-		$posy-=3;
-		$pdf->SetXY($marge_gauche,-$posy);
-		$pdf->MultiCell(200, 2, $ligne2, 0, 'C', 0);
-	}
-
-	$pdf->SetXY(-20,-$posy);
-	$pdf->MultiCell(11, 2, $pdf->PageNo().'/{nb}', 0, 'R', 0);
+        );
+
+        $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs,$object);
+        $ligne.=$outputlangs->convToOutputCharset($newfreetext);
+    }
+
+    // First line of company infos
+
+    // Juridical status
+    $ligne1="";
+    if ($fromcompany->forme_juridique_code)
+    {
+        $ligne1.=($ligne1?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
+    }
+    // Capital
+    if ($fromcompany->capital)
+    {
+        $ligne1.=($ligne1?" - ":"").$outputlangs->transnoentities("CapitalOf",$fromcompany->capital)." ".$outputlangs->transnoentities("Currency".$conf->monnaie);
+    }
+    // Prof Id 1
+    if ($fromcompany->idprof1 && ($fromcompany->pays_code != 'FR' || ! $fromcompany->idprof2))
+    {
+        $field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->pays_code);
+        if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
+        $ligne1.=($ligne1?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
+    }
+    // Prof Id 2
+    if ($fromcompany->idprof2)
+    {
+        $field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->pays_code);
+        if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
+        $ligne1.=($ligne1?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
+    }
+
+    // Second line of company infos
+    $ligne2="";
+    // Prof Id 3
+    if ($fromcompany->idprof3)
+    {
+        $field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->pays_code);
+        if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
+        $ligne2.=($ligne2?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
+    }
+    // Prof Id 4
+    if ($fromcompany->idprof4)
+    {
+        $field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->pays_code);
+        if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
+        $ligne2.=($ligne2?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
+    }
+    // IntraCommunautary VAT
+    if ($fromcompany->tva_intra != '')
+    {
+        $ligne2.=($ligne2?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
+    }
+
+    $pdf->SetFont('','',7);
+    $pdf->SetDrawColor(224,224,224);
+
+    // On positionne le debut du bas de page selon nbre de lignes de ce bas de page
+    $nbofligne=dol_nboflines_bis($ligne,0,$outputlangs->charset_output);
+    //print 'nbofligne='.$nbofligne; exit;
+    //print 'e'.$ligne.'t'.dol_nboflines($ligne);exit;
+    $posy=$marge_basse + ($nbofligne*3) + ($ligne1?3:0) + ($ligne2?3:0);
+
+    if ($ligne)	// Free text
+    {
+        $pdf->SetXY($marge_gauche,-$posy);
+        $width=20000; $align='L';	// By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
+        if ($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT) { $width=200; $align='C'; }
+        $pdf->MultiCell($width, 3, $ligne, 0, $align, 0);
+        $posy-=($nbofligne*3);	// 6 of ligne + 3 of MultiCell
+    }
+
+    $pdf->SetY(-$posy);
+    $pdf->line($marge_gauche, $page_hauteur-$posy, 200, $page_hauteur-$posy);
+    $posy--;
+
+    if ($ligne1)
+    {
+        $pdf->SetXY($marge_gauche,-$posy);
+        $pdf->MultiCell(200, 2, $ligne1, 0, 'C', 0);
+    }
+
+    if ($ligne2)
+    {
+        $posy-=3;
+        $pdf->SetXY($marge_gauche,-$posy);
+        $pdf->MultiCell(200, 2, $ligne2, 0, 'C', 0);
+    }
+
+    $pdf->SetXY(-20,-$posy);
+    $pdf->MultiCell(11, 2, $pdf->PageNo().'/{nb}', 0, 'R', 0);
 }
 
 
@@ -430,118 +454,118 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass
  */
 function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0)
 {
-	global $db, $conf, $langs;
-
-	$idprod=$object->lines[$i]->fk_product;
-	$label=$object->lines[$i]->label; if (empty($label))  $label=$object->lines[$i]->libelle;
-	$desc=$object->lines[$i]->desc; if (empty($desc))   $desc=$object->lines[$i]->description;
-	$ref_supplier=$object->lines[$i]->ref_supplier; if (empty($ref_supplier))   $ref_supplier=$object->lines[$i]->ref_fourn;	// TODO Not yeld saved for supplier invoices, only supplier orders
-	$note=$object->lines[$i]->note;
-
-	if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
-	{
-		$libelleproduitservice = $object->hooks[$object->lines[$i]->special_code]->pdf_getlinedesc($object,$i,$outputlangs);
-	}
-	else
-	{
-		if ($issupplierline) $prodser = new ProductFournisseur($db);
-		else $prodser = new Product($db);
-
-		if ($idprod)
-		{
-			$prodser->fetch($idprod);
-			// If a predefined product and multilang and on other lang, we renamed label with label translated
-			if ($conf->global->MAIN_MULTILANGS && ($outputlangs->defaultlang != $langs->defaultlang))
-			{
-				if (! empty($prodser->multilangs[$outputlangs->defaultlang]["libelle"]))     $label=$prodser->multilangs[$outputlangs->defaultlang]["libelle"];
-				if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"])) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
-				if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]))        $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
-			}
-		}
-
-		// Description short of product line
-		$libelleproduitservice=$label;
-
-		// Description long of product line
-		if ($desc && ($desc != $label))
-		{
-			if ($libelleproduitservice && !$hidedesc) $libelleproduitservice.="\n";
-
-			if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except)
-			{
-				$discount=new DiscountAbsolute($db);
-				$discount->fetch($object->lines[$i]->fk_remise_except);
-				$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
-			}
-			else
-			{
-				if ($idprod)
-				{
-					if (!$hidedesc) $libelleproduitservice.=$desc;
-				}
-				else
-				{
-					$libelleproduitservice.=$desc;
-				}
-			}
-		}
-
-		// If line linked to a product
-		if ($idprod)
-		{
-			// On ajoute la ref
-			if ($prodser->ref)
-			{
-				$prefix_prodserv = "";
-				$ref_prodserv = "";
-				if ($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)	// In standard mode, we do not show this
-				{
-					if($prodser->isservice())
-					{
-						$prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
-					}
-					else
-					{
-						$prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
-					}
-				}
-
-				if (!$hideref)
-				{
-					if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')';	// Show local ref and supplier ref
-					else $ref_prodserv = $prodser->ref;	// Show local ref only
-
-					$ref_prodserv .= " - ";
-				}
-
-				$libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
-			}
-		}
-	}
-
-	$libelleproduitservice=dol_htmlentitiesbr($libelleproduitservice,1);
-
-	if ($object->lines[$i]->date_start || $object->lines[$i]->date_end)
-	{
-		// Show duration if exists
-		if ($object->lines[$i]->date_start && $object->lines[$i]->date_end)
-		{
-			$period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs),dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
-		}
-		if ($object->lines[$i]->date_start && ! $object->lines[$i]->date_end)
-		{
-			$period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')';
-		}
-		if (! $object->lines[$i]->date_start && $object->lines[$i]->date_end)
-		{
-			$period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
-		}
-		//print '>'.$outputlangs->charset_output.','.$period;
-		$libelleproduitservice.="<br>".dol_htmlentitiesbr($period,1);
-		//print $libelleproduitservice;
-	}
-
-	return $libelleproduitservice;
+    global $db, $conf, $langs;
+
+    $idprod=$object->lines[$i]->fk_product;
+    $label=$object->lines[$i]->label; if (empty($label))  $label=$object->lines[$i]->libelle;
+    $desc=$object->lines[$i]->desc; if (empty($desc))   $desc=$object->lines[$i]->description;
+    $ref_supplier=$object->lines[$i]->ref_supplier; if (empty($ref_supplier))   $ref_supplier=$object->lines[$i]->ref_fourn;	// TODO Not yeld saved for supplier invoices, only supplier orders
+    $note=$object->lines[$i]->note;
+
+    if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
+    {
+        $libelleproduitservice = $object->hooks[$object->lines[$i]->special_code]->pdf_getlinedesc($object,$i,$outputlangs);
+    }
+    else
+    {
+        if ($issupplierline) $prodser = new ProductFournisseur($db);
+        else $prodser = new Product($db);
+
+        if ($idprod)
+        {
+            $prodser->fetch($idprod);
+            // If a predefined product and multilang and on other lang, we renamed label with label translated
+            if ($conf->global->MAIN_MULTILANGS && ($outputlangs->defaultlang != $langs->defaultlang))
+            {
+                if (! empty($prodser->multilangs[$outputlangs->defaultlang]["libelle"]))     $label=$prodser->multilangs[$outputlangs->defaultlang]["libelle"];
+                if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"])) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
+                if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]))        $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
+            }
+        }
+
+        // Description short of product line
+        $libelleproduitservice=$label;
+
+        // Description long of product line
+        if ($desc && ($desc != $label))
+        {
+            if ($libelleproduitservice && !$hidedesc) $libelleproduitservice.="\n";
+
+            if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except)
+            {
+                $discount=new DiscountAbsolute($db);
+                $discount->fetch($object->lines[$i]->fk_remise_except);
+                $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
+            }
+            else
+            {
+                if ($idprod)
+                {
+                    if (!$hidedesc) $libelleproduitservice.=$desc;
+                }
+                else
+                {
+                    $libelleproduitservice.=$desc;
+                }
+            }
+        }
+
+        // If line linked to a product
+        if ($idprod)
+        {
+            // On ajoute la ref
+            if ($prodser->ref)
+            {
+                $prefix_prodserv = "";
+                $ref_prodserv = "";
+                if ($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)	// In standard mode, we do not show this
+                {
+                    if($prodser->isservice())
+                    {
+                        $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
+                    }
+                    else
+                    {
+                        $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
+                    }
+                }
+
+                if (!$hideref)
+                {
+                    if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')';	// Show local ref and supplier ref
+                    else $ref_prodserv = $prodser->ref;	// Show local ref only
+
+                    $ref_prodserv .= " - ";
+                }
+
+                $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
+            }
+        }
+    }
+
+    $libelleproduitservice=dol_htmlentitiesbr($libelleproduitservice,1);
+
+    if ($object->lines[$i]->date_start || $object->lines[$i]->date_end)
+    {
+        // Show duration if exists
+        if ($object->lines[$i]->date_start && $object->lines[$i]->date_end)
+        {
+            $period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs),dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
+        }
+        if ($object->lines[$i]->date_start && ! $object->lines[$i]->date_end)
+        {
+            $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')';
+        }
+        if (! $object->lines[$i]->date_start && $object->lines[$i]->date_end)
+        {
+            $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
+        }
+        //print '>'.$outputlangs->charset_output.','.$period;
+        $libelleproduitservice.="<br>".dol_htmlentitiesbr($period,1);
+        //print $libelleproduitservice;
+    }
+
+    return $libelleproduitservice;
 }
 
 /**
@@ -552,14 +576,14 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl
  */
 function pdf_getlineref($object,$i,$outputlangs)
 {
-	if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
-	{
-		// TODO add hook function
-	}
-	else
-	{
-		return dol_htmlentitiesbr($object->lines[$i]->ref);
-	}
+    if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
+    {
+        // TODO add hook function
+    }
+    else
+    {
+        return dol_htmlentitiesbr($object->lines[$i]->ref);
+    }
 }
 
 /**
@@ -570,14 +594,14 @@ function pdf_getlineref($object,$i,$outputlangs)
  */
 function pdf_getlinevatrate($object,$i,$outputlangs)
 {
-	if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
-	{
-		// TODO add hook function
-	}
-	else
-	{
-		return vatrate($object->lines[$i]->tva_tx,1,$object->lines[$i]->info_bits);
-	}
+    if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
+    {
+        // TODO add hook function
+    }
+    else
+    {
+        return vatrate($object->lines[$i]->tva_tx,1,$object->lines[$i]->info_bits);
+    }
 }
 
 /**
@@ -588,14 +612,14 @@ function pdf_getlinevatrate($object,$i,$outputlangs)
  */
 function pdf_getlineupexcltax($object,$i,$outputlangs)
 {
-	if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
-	{
-		// TODO add hook function
-	}
-	else
-	{
-		return price($object->lines[$i]->subprice);
-	}
+    if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
+    {
+        // TODO add hook function
+    }
+    else
+    {
+        return price($object->lines[$i]->subprice);
+    }
 }
 
 /**
@@ -606,17 +630,17 @@ function pdf_getlineupexcltax($object,$i,$outputlangs)
  */
 function pdf_getlineqty($object,$i,$outputlangs)
 {
-	if ($object->lines[$i]->special_code != 3)
-	{
-		if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
-		{
-			// TODO add hook function
-		}
-		else
-		{
-			return $object->lines[$i]->qty;
-		}
-	}
+    if ($object->lines[$i]->special_code != 3)
+    {
+        if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
+        {
+            // TODO add hook function
+        }
+        else
+        {
+            return $object->lines[$i]->qty;
+        }
+    }
 }
 
 /**
@@ -627,17 +651,17 @@ function pdf_getlineqty($object,$i,$outputlangs)
  */
 function pdf_getlineremisepercent($object,$i,$outputlangs)
 {
-	if ($object->lines[$i]->special_code != 3)
-	{
-		if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
-		{
-			// TODO add hook function
-		}
-		else
-		{
-			return dol_print_reduction($object->lines[$i]->remise_percent,$outputlangs);
-		}
-	}
+    if ($object->lines[$i]->special_code != 3)
+    {
+        if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
+        {
+            // TODO add hook function
+        }
+        else
+        {
+            return dol_print_reduction($object->lines[$i]->remise_percent,$outputlangs);
+        }
+    }
 }
 
 /**
@@ -648,21 +672,21 @@ function pdf_getlineremisepercent($object,$i,$outputlangs)
  */
 function pdf_getlinetotalexcltax($object,$i,$outputlangs)
 {
-	if ($object->lines[$i]->special_code == 3)
-	{
-		return $outputlangs->transnoentities("Option");
-	}
-	else
-	{
-		if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
-		{
-			// TODO add hook function
-		}
-		else
-		{
-			return price($object->lines[$i]->total_ht);
-		}
-	}
+    if ($object->lines[$i]->special_code == 3)
+    {
+        return $outputlangs->transnoentities("Option");
+    }
+    else
+    {
+        if (!empty($object->hooks) && $object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code))
+        {
+            // TODO add hook function
+        }
+        else
+        {
+            return price($object->lines[$i]->total_ht);
+        }
+    }
 }
 
 ?>
\ No newline at end of file
diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php
index f83b33081ba22160b498947618155e321e2cab01..6d113735ab9f7b158101dac324597d84e22abcb0 100644
--- a/htdocs/livraison/class/livraison.class.php
+++ b/htdocs/livraison/class/livraison.class.php
@@ -697,7 +697,7 @@ class Livraison extends CommonObject
 
 				$this->lignes[$i] = $line;	// TODO deprecated
 				$this->lines[$i] = $line;
-				
+
 				$i++;
 			}
 			$this->db->free($resql);
@@ -754,37 +754,12 @@ class Livraison extends CommonObject
 	{
 		global $user,$langs,$conf;
 
-		// Charge tableau des id de societe socids
-		$socids = array();
-
-		$sql = "SELECT rowid";
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe";
-		$sql.= " WHERE client IN (1, 3)";
-		$sql.= " AND entity = ".$conf->entity;
-		$sql.= " LIMIT 10";
-
-		$resql = $this->db->query($sql);
-		if ($resql)
-		{
-			$num_socs = $this->db->num_rows($resql);
-			$i = 0;
-			while ($i < $num_socs)
-			{
-				$i++;
-
-				$row = $this->db->fetch_row($resql);
-				$socids[$i] = $row[0];
-			}
-		}
-
 		// Charge tableau des produits prodids
 		$prodids = array();
-
 		$sql = "SELECT rowid";
 		$sql.= " FROM ".MAIN_DB_PREFIX."product";
 		$sql.= " WHERE tosell = 1";
 		$sql.= " AND entity = ".$conf->entity;
-
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
@@ -802,8 +777,7 @@ class Livraison extends CommonObject
 		$this->id=0;
 		$this->ref = 'SPECIMEN';
 		$this->specimen=1;
-		$socid = rand(1, $num_socs);
-		$this->socid = $socids[$socid];
+		$this->socid = 1;
 		$this->date_delivery = time();
 		$this->note_public='SPECIMEN';