diff --git a/ChangeLog b/ChangeLog
index 8f822d08771f0f022ce601a3aac676bc91e87135..f83979aa8e085ce31b839c75f9bae145657b0190 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,9 @@
 English Dolibarr ChangeLog
 --------------------------------------------------------------
 
+***** ChangeLog for 3.6.4 compared to 3.6.3 *****
+- Fix: [ bug #2893 ] Dolibarr error when viewing an invoice after changing invoice mask
+
 ***** ChangeLog for 3.6.3 compared to 3.6.2 *****
 - Fix: ref_ext was not saved when recording a customer order from web service
 - Fix: amarok is a bugged theme making dolidroid failed. We switch to eldy automatically with dolidroid.
@@ -38,6 +41,11 @@ English Dolibarr ChangeLog
 - Fix: [ bug #2542 ] Contracts store localtax preferences
 - Fix: Bad permission assignments for stock movements actions
 - Fix: [ bug #2891 ] Category hooks do not work
+- Fix: [ bug #2696 ] Adding complementary attribute fails if code is numerics
+- Fix: [ bug #3074 ] Accruals accounting use payment date instead of commitment date in turnover reports for salaries
+- Fix: Not showing product supplier reference when page break
+- Fix: [ bug #3341 ] Missing translation in /compta/paiement_charge.php
+- Fix: [ bug #3342 ] Taxes dictionary page does not accept localized decimals for localtax2 rate
 
 ***** ChangeLog for 3.6.2 compared to 3.6.1 *****
 - Fix: fix ErrorBadValueForParamNotAString error message in price customer multiprice.
@@ -211,6 +219,14 @@ Fix: [ bug #2861 ] Undefined variable $res when migrating
 Fix: [ bug #2837 ] Product list table column header does not match column body
 Fix: [ bug #2835 ] Customer prices of a product shows incorrect history order
 Fix: [ bug #2814 ] JPEG photos are not displayed in Product photos page
+Fix: [ bug #2715 ] Statistics page has broken layout with long thirdparty names
+Fix: [ bug #2570 ] [Contacts] Page should not process if ID is invalid
+Fix: [ bug #3268 ] SQL error when accessing thirdparty log page without a socid parameter
+Fix: [ bug #3180 ] formObjectOptions hook when editing thirdparty card does not print result
+Fix: [ bug #1791 ] Margin menu not available if any Finance module is not enabled
+Fix: [ bug #3310 ] OrderLine::fetch, FactureLigne::fetch and PropaleLigne::fetch do not return anything
+Fix: [ bug #3206 ] PropaleLigne, OrderLine and FactureLigne given to triggers through update function does not contain all the information
+Fix: [ bug #3313 ] Error enabling module with PostgreSQL database
 
 ***** ChangeLog for 3.5.6 compared to 3.5.5 *****
 Fix: Avoid missing class error for fetch_thirdparty method #1973
diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl
index c667754d4aba747d516f1698c20d44ef47f9c9fe..9db6f3a4da391d3b2597b9d4271b8dde32648b6b 100755
--- a/build/makepack-dolibarr.pl
+++ b/build/makepack-dolibarr.pl
@@ -984,7 +984,7 @@ if ($nboftargetok) {
      		print "Remove target $FILENAMEEXEDOLIWAMP.exe...\n";
     		unlink "$NEWDESTI/$FILENAMEEXEDOLIWAMP.exe";
  
- 			print "Check that in your Wine setup, you create a Z: drive that point to your /tmp directory.\n";
+ 			print "Check that in your Wine setup, you create a Z: drive that point to your / directory.\n";
 
  			$SOURCEBACK=$SOURCE;
  			$SOURCEBACK =~ s/\//\\/g;
diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index 4a4e66e4ea5a0ec61f97aa3fe9131fe131f900d5..38f991faf52a42502c6bcb834fbccf51bc6376cc 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -516,7 +516,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
         $i=0;
         foreach ($listfieldinsert as $f => $value)
         {
-            if ($value == 'price' || preg_match('/^amount/i',$value)) {
+            if ($value == 'price' || preg_match('/^amount/i',$value) || preg_match('/^localtax/i',$value) || $value == 'taux') {
             	$_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
             }
             else if ($value == 'entity') {
@@ -564,7 +564,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
         $i = 0;
         foreach ($listfieldmodify as $field)
         {
-            if ($field == 'price' || preg_match('/^amount/i',$field)) {
+            if ($field == 'price' || preg_match('/^amount/i',$field) || preg_match('/^localtax/i',$field) || $field == 'taux') {
             	$_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
             }
             else if ($field == 'entity') {
@@ -1080,17 +1080,20 @@ if ($id)
 							  $align="center";
 							}
 							else if ($fieldlist[$field]=='localtax1') {
+                                $valuetoshow = price($valuetoshow, 0, $langs, 0, 0);
 							  if ($obj->localtax1 == 0)
 							    $valuetoshow = '';
 							  $align="right";
 							}
 							else if ($fieldlist[$field]=='localtax2') {
+                                $valuetoshow = price($valuetoshow, 0, $langs, 0, 0);
 							  if ($obj->localtax2 == 0)
 							    $valuetoshow = '';
 							  $align="right";
 							}
 							else if (in_array($fieldlist[$field],array('taux','localtax1','localtax2')))
 							{
+                                $valuetoshow = price($valuetoshow, 0, $langs, 0, 0);
 								$align="right";
 							}
 							else if (in_array($fieldlist[$field],array('recuperableonly')))
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 84b0f65d67946cafc4a0a3a22302c8dcbe5723aa..483b6ec8258a76021659df2d2d587fb3e0ab79ca 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -535,13 +535,14 @@ class Propal extends CommonObject
                 $price = $pu - $remise;
             }
 
-            // Update line
-            $this->line=new PropaleLigne($this->db);
+            //Fetch current line from the database and then clone the object and set it in $oldline property
+            $line = new PropaleLigne($this->db);
+            $line->fetch($rowid);
+
+            $staticline = clone $line;
 
-            // Stock previous line records
-            $staticline=new PropaleLigne($this->db);
-            $staticline->fetch($rowid);
-            $this->line->oldline = $staticline;
+            $line->oldline = $staticline;
+            $this->line = $line;
 
             // Reorder if fk_parent_line change
             if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
@@ -2862,10 +2863,12 @@ class PropaleLigne  extends CommonObject
             $this->date_end         = $this->db->jdate($objp->date_end);
 
 			$this->db->free($result);
+
+            return 1;
 		}
 		else
 		{
-			dol_print_error($this->db);
+			return -1;
 		}
 	}
 
@@ -2893,11 +2896,12 @@ class PropaleLigne  extends CommonObject
         if (empty($this->total_localtax2)) $this->total_localtax2=0;
         if (empty($this->rang)) $this->rang=0;
         if (empty($this->remise)) $this->remise=0;
-        if (empty($this->remise_percent)) $this->remise_percent=0;
+        if (empty($this->remise_percent) || ! is_numeric($this->remise_percent)) $this->remise_percent=0;
         if (empty($this->info_bits)) $this->info_bits=0;
         if (empty($this->special_code)) $this->special_code=0;
         if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
         if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
+		if (! is_numeric($this->qty)) $this->qty = 0;
 
         if (empty($this->pa_ht)) $this->pa_ht=0;
 
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index cac43ced7460f0295e4d1cab29c7a92a36107293..95441e5f25740723c0d8fbc3ba2be7ceee037de2 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -2403,13 +2403,14 @@ class Commande extends CommonOrder
                 $price = ($pu - $remise);
             }
 
-            // Update line
-            $this->line=new OrderLine($this->db);
+            //Fetch current line from the database and then clone the object and set it in $oldline property
+            $line = new OrderLine($this->db);
+            $line->fetch($rowid);
 
-            // Stock previous line records
-            $staticline=new OrderLine($this->db);
-            $staticline->fetch($rowid);
-            $this->line->oldline = $staticline;
+            $staticline = clone $line;
+
+            $line->oldline = $staticline;
+            $this->line = $line;
 
             // Reorder if fk_parent_line change
             if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
@@ -3218,10 +3219,12 @@ class OrderLine extends CommonOrderLine
             $this->date_end         = $this->db->jdate($objp->date_end);
 
             $this->db->free($result);
+
+            return 1;
         }
         else
         {
-            dol_print_error($this->db);
+            return -1;
         }
     }
 
diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php
index 6d1e417f4eac378efacb71f11dc3081741b43180..cecb76703dd0a463ecbdf23c3de82f17a0d86104 100644
--- a/htdocs/compta/bank/class/account.class.php
+++ b/htdocs/compta/bank/class/account.class.php
@@ -1133,7 +1133,6 @@ class AccountLine extends CommonObject
         }
         else
         {
-            dol_print_error($this->db);
             return -1;
         }
     }
diff --git a/htdocs/compta/bank/fiche.php b/htdocs/compta/bank/fiche.php
index bdb30e465282cf81070b6f3a2717cc10a902d702..428112f7289f68acaa0fe0f17439ce44dbec5c2e 100644
--- a/htdocs/compta/bank/fiche.php
+++ b/htdocs/compta/bank/fiche.php
@@ -419,7 +419,7 @@ else
 
 		// State
 		print '<tr><td>'.$langs->trans('State').'</td><td>';
-		if ($account->fk_departement > 0) print getState($account->fk_departement);
+		if ($account->state_id > 0) print getState($account->state_id);
 		print '</td></tr>';
 
 		// Conciliate
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 63cdcaeb86501b86912a6d7624fd2afdc276d536..72103f6ac5ae44c917f5d27059981ac5779c1da5 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -2173,13 +2173,24 @@ class Facture extends CommonInvoice
 			$pu_tva = $tabprice[4];
 			$pu_ttc = $tabprice[5];
 
-			// Update line into database
-			$this->line=new FactureLigne($this->db);
+			// Old properties: $price, $remise (deprecated)
+			$price = $pu;
+			$remise = 0;
+			if ($remise_percent > 0)
+			{
+				$remise = round(($pu * $remise_percent / 100),2);
+				$price = ($pu - $remise);
+			}
+			$price    = price2num($price);
+
+			//Fetch current line from the database and then clone the object and set it in $oldline property
+			$line = new FactureLigne($this->db);
+			$line->fetch($rowid);
 
-			// Stock previous line records
-			$staticline=new FactureLigne($this->db);
-			$staticline->fetch($rowid);
-			$this->line->oldline = $staticline;
+			$staticline = clone $line;
+
+			$line->oldline = $staticline;
+			$this->line = $line;
 
 			// Reorder if fk_parent_line change
 			if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
@@ -2547,15 +2558,16 @@ class Facture extends CommonInvoice
 			$numref = "";
 			$numref = $obj->getNextValue($soc,$this,$mode);
 
-			if ($numref != "")
-			{
-				return $numref;
-			}
-			else
-			{
+			/**
+			 * $numref can be empty in case we ask for the last value because if there is no invoice created with the
+			 * set up mask.
+			 */
+			if ($mode != 'last' && !$numref) {
 				dol_print_error($db,"Facture::getNextNumRef ".$obj->error);
 				return "";
 			}
+
+			return $numref;
 		}
 		else
 		{
@@ -3436,10 +3448,12 @@ class FactureLigne  extends CommonInvoiceLine
 			$this->product_desc			= $objp->product_desc;
 
 			$this->db->free($result);
+
+			return 1;
 		}
 		else
 		{
-			dol_print_error($this->db);
+			return -1;
 		}
 	}
 
@@ -3497,7 +3511,7 @@ class FactureLigne  extends CommonInvoiceLine
 				return -1;
 			}
 		}
-		
+
 		// POS or by external module, take lowest buying price
 		if (!empty($this->fk_product) && empty($this->fk_fournprice) && empty($this->pa_ht)) {
 		    include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php
index 18aeaa722dab079270be93952cee39e86db4844e..dab5631bab480e09ab3a5ea9f074e49519512f79 100644
--- a/htdocs/compta/facture/stats/index.php
+++ b/htdocs/compta/facture/stats/index.php
@@ -217,6 +217,13 @@ complete_head_from_modules($conf,$langs,null,$head,$h,$type);
 
 dol_fiche_head($head,'byyear',$langs->trans("Statistics"));
 
+$tmp_companies = $form->select_thirdparty_list($socid,'socid',$filter,1, 0, 0, array(), '', 1);
+//Array passed as an argument to Form::selectarray to build a proper select input
+$companies = array();
+
+foreach ($tmp_companies as $value) {
+	$companies[$value['value']] = $value['label'];
+}
 
 print '<div class="fichecenter"><div class="fichethirdleft">';
 
@@ -232,7 +239,7 @@ print '<div class="fichecenter"><div class="fichethirdleft">';
 	print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
 	if ($mode == 'customer') $filter='s.client in (1,2,3)';
 	if ($mode == 'supplier') $filter='s.fournisseur = 1';
-	print $form->select_company($socid,'socid',$filter,1);
+	print $form->selectarray('socid', $companies, $socid, 1, 0, 0, 'style="width: 100%"');
 	print '</td></tr>';
 	// User
 	print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>';
diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php
index 205aba9a778f5aa3f7afbbe4938860f30d6c8dde..66645f4affa19a1cf5ac52a9d157b2ad2e740c1d 100644
--- a/htdocs/compta/index.php
+++ b/htdocs/compta/index.php
@@ -1,7 +1,8 @@
 <?php
-/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2013 Laurent Destailleur  <eldy@users.sourceforge.net>
- * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
+/* Copyright (C) 2001-2005  Rodolphe Quiedeville    <rodolphe@quiedeville.org>
+ * Copyright (C) 2004-2013  Laurent Destailleur     <eldy@users.sourceforge.net>
+ * Copyright (C) 2005-2012  Regis Houssin           <regis.houssin@capnetworks.com>
+ * Copyright (C) 2015       Raphaƫl Doursenaud      <rdoursenaud@gpcsolutions.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -574,7 +575,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
 					$chargestatic->lib=$obj->libelle;
 					$chargestatic->paye=$obj->paye;
 					print '<td>'.$chargestatic->getNomUrl(1).'</td>';
-					print '<td align="center">'.dol_print_date($obj->date_ech,'day').'</td>';
+					print '<td align="center">'.dol_print_date($db->jdate($obj->date_ech),'day').'</td>';
 					print '<td align="right">'.price($obj->amount).'</td>';
 					print '<td align="right">'.price($obj->sumpaid).'</td>';
 					print '<td align="center">'.$chargestatic->getLibStatut(3).'</td>';
@@ -915,7 +916,7 @@ if ($resql)
 		$obj = $db->fetch_object($resql);
 		$var=!$var;
 
-		print "<tr ".$bc[$var]."><td>".dol_print_date($obj->da,"day")."</td>";
+		print "<tr ".$bc[$var]."><td>".dol_print_date($db->jdate($obj->da),"day")."</td>";
 		print "<td><a href=\"action/fiche.php\">$obj->libelle $obj->label</a></td></tr>";
 		$i++;
 	}
diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php
index a54a0bcd935ad36b3f5f293d4f8b2cd5da7d2871..a660259d706c86d18f0043a6a462c34cfb6ab9af 100644
--- a/htdocs/compta/paiement_charge.php
+++ b/htdocs/compta/paiement_charge.php
@@ -178,7 +178,7 @@ if ($_GET["action"] == 'create')
 
 	print '<table cellspacing="0" class="border" width="100%" cellpadding="2">';
 
-	print "<tr class=\"liste_titre\"><td colspan=\"3\">Charge</td>";
+	print "<tr class=\"liste_titre\"><td colspan=\"3\">".$langs->trans('Charge')."</td>";
 
 	print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="2"><a href="'.DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid.'">'.$chid.'</a></td></tr>';
 	print '<tr><td>'.$langs->trans("Type")."</td><td colspan=\"2\">".$charge->type_libelle."</td></tr>\n";
diff --git a/htdocs/compta/prelevement/class/rejetprelevement.class.php b/htdocs/compta/prelevement/class/rejetprelevement.class.php
index 51f9a83ed3c7bce9be5d7209a1c0946d07e605ad..61e366d0ce5e58c69cdcc8e37c10963ed52d8558 100644
--- a/htdocs/compta/prelevement/class/rejetprelevement.class.php
+++ b/htdocs/compta/prelevement/class/rejetprelevement.class.php
@@ -87,7 +87,7 @@ class RejetPrelevement
 
 		dol_syslog("RejetPrelevement::Create id $id");
 		$bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
-		$facs = $this->getListInvoices();
+		$facs = $this->getListInvoices(1);
 
 		$this->db->begin();
 
@@ -132,7 +132,7 @@ class RejetPrelevement
 		for ($i = 0; $i < $num; $i++)
 		{
 			$fac = new Facture($this->db);
-			$fac->fetch($facs[$i]);
+			$fac->fetch($facs[$i][0]);
 
 			// Make a negative payment
 			$pai = new Paiement($this->db);
@@ -144,7 +144,7 @@ class RejetPrelevement
 			 * PHP installs sends only the part integer negative
 			*/
 
-			$pai->amounts[$facs[$i]] = price2num($fac->total_ttc * -1);
+			$pai->amounts[$facs[$i][0]] = price2num($facs[$i][1] * -1);
 			$pai->datepaye = $date_rejet;
 			$pai->paiementid = 3; // type of payment: withdrawal
 			$pai->num_paiement = $fac->ref;
@@ -152,7 +152,7 @@ class RejetPrelevement
 			if ($pai->create($this->user) < 0)  // we call with no_commit
 			{
 				$error++;
-				dol_syslog("RejetPrelevement::Create Error creation payment invoice ".$facs[$i]);
+				dol_syslog("RejetPrelevement::Create Error creation payment invoice ".$facs[$i][0]);
 			}
 			else
 			{
@@ -269,22 +269,24 @@ class RejetPrelevement
 	}
 
 	/**
-	 *    Retrieve the list of invoices
+	 * Retrieve the list of invoices
+	 * @param 	int		$amounts 	If you want to get the amount of the order for each invoice
 	 *
-	 *    @return	void
+	 * @return	Array List of invoices related to the withdrawal line
+	 * @TODO	A withdrawal line is today linked to one and only one invoice. So the function should return only one object ?
 	 */
-	private function getListInvoices()
+	private function getListInvoices($amounts=0)
 	{
 		global $conf;
 
 		$arr = array();
 
 		 //Returns all invoices of a withdrawal
-		$sql = "SELECT f.rowid as facid";
+		$sql = "SELECT f.rowid as facid, pl.amount";
 		$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_facture as pf";
-		$sql.= ", ".MAIN_DB_PREFIX."facture as f";
+		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON (pf.fk_facture = f.rowid)";
+		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)";
 		$sql.= " WHERE pf.fk_prelevement_lignes = ".$this->id;
-		$sql.= " AND pf.fk_facture = f.rowid";
 		$sql.= " AND f.entity = ".$conf->entity;
 
 		$resql=$this->db->query($sql);
@@ -298,7 +300,14 @@ class RejetPrelevement
 				while ($i < $num)
 				{
 					$row = $this->db->fetch_row($resql);
-					$arr[$i] = $row[0];
+					if (!$amounts) $arr[$i] = $row[0];
+					else
+					{
+						$arr[$i] = array(
+							$row[0],
+							$row[1]
+						);
+					}
 					$i++;
 				}
 			}
diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php
index 1e09ea0a8fee304af4873064948462e330c01310..7089652d3d3b7515f06540a0f26df9fe136bca10 100644
--- a/htdocs/compta/resultat/clientfourn.php
+++ b/htdocs/compta/resultat/clientfourn.php
@@ -543,17 +543,23 @@ if ($mysoc->tva_assuj == 'franchise')	// Non assujeti
  * Salaries
  */
 
+if ($modecompta == 'CREANCES-DETTES') {
+    $column = 'p.datev';
+} else {
+    $column = 'p.datep';
+}
+
 print '<tr><td colspan="4">'.$langs->trans("Salaries").'</td></tr>';    
-$sql = "SELECT p.label as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount, u.firstname, u.lastname, p.fk_user";
+$sql = "SELECT p.label as nom, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount, u.firstname, u.lastname, p.fk_user";
 $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
 $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user";
 $sql.= " WHERE p.entity = ".$conf->entity;
 if (! empty($date_start) && ! empty($date_end))
-	$sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
+	$sql.= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
 	
 $sql.= " GROUP BY u.rowid, p.label, p.datep, p.fk_user";
 $sql.= " ORDER BY u.firstname";
-    
+
 dol_syslog("get payment salaries sql=".$sql);
 $result=$db->query($sql);
 $subtotal_ht = 0;
diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php
index fdc9b0472f04bc85244304e80f363e98fbd63ea5..32294b61beaa08d1ce53f0636dd3e574c9727b99 100644
--- a/htdocs/compta/resultat/index.php
+++ b/htdocs/compta/resultat/index.php
@@ -473,9 +473,16 @@ $reshook=$hookmanager->executeHooks('addStatisticLine',$parameters,$object,$acti
 /*
  * Salaries
  */
+
+if ($modecompta == 'CREANCES-DETTES') {
+	$column = 'p.datev';
+} else {
+	$column = 'p.datep';
+}
+
 $subtotal_ht = 0;
 $subtotal_ttc = 0;
-$sql = "SELECT p.label as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount";
+$sql = "SELECT p.label as nom, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount";
 $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
 $sql.= " WHERE p.entity = ".$conf->entity;
 $sql.= " GROUP BY p.label, dm";
diff --git a/htdocs/contact/exportimport.php b/htdocs/contact/exportimport.php
index bcb3b9c2be03385410275d1bf59f716172dc36bb..c76655f50993441f7804ce542d6719f1b25de67f 100644
--- a/htdocs/contact/exportimport.php
+++ b/htdocs/contact/exportimport.php
@@ -33,79 +33,79 @@ $id = GETPOST('id', 'int');
 if ($user->societe_id) $socid=$user->societe_id;
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 
+$contact = new Contact($db);
+
 
 /*
  *	View
  */
 
-$title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
-
-llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
-
 $form = new Form($db);
 
-$contact = new Contact($db);
-$contact->fetch($id, $user);
-
+$title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
 
-$head = contact_prepare_head($contact);
+llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
 
-dol_fiche_head($head, 'exportimport', $title, 0, 'contact');
+if ($id > 0)
+{
+	$contact->fetch($id, $user);
 
+	$head = contact_prepare_head($contact);
 
-/*
- * Fiche en mode visu
- */
-print '<table class="border" width="100%">';
+	dol_fiche_head($head, 'exportimport', $title, 0, 'contact');
 
-$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
 
-// Ref
-print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="3">';
-print $form->showrefnav($contact, 'id', $linkback);
-print '</td></tr>';
+	/*
+	 * Fiche en mode visu
+	 */
+	print '<table class="border" width="100%">';
 
-// Name
-print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$contact->lastname.'</td>';
-print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->firstname.'</td></tr>';
+	$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
 
-// Company
-if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-{
-    if ($contact->socid > 0)
-    {
-    	$objsoc = new Societe($db);
-    	$objsoc->fetch($contact->socid);
-
-    	print '<tr><td width="15%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
-    }
-    else
-    {
-    	print '<tr><td width="15%">'.$langs->trans("Company").'</td><td colspan="3">';
-    	print $langs->trans("ContactNotLinkedToCompany");
-    	print '</td></tr>';
-    }
-}
+	// Ref
+	print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="3">';
+	print $form->showrefnav($contact, 'id', $linkback);
+	print '</td></tr>';
 
-// Civility
-print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
-print $contact->getCivilityLabel();
-print '</td></tr>';
+	// Name
+	print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$contact->lastname.'</td>';
+	print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->firstname.'</td></tr>';
 
-print '</table>';
+	// Company
+	if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
+	{
+	    if ($contact->socid > 0)
+	    {
+	        $objsoc = new Societe($db);
+	        $objsoc->fetch($contact->socid);
 
-print '</div>';
+	        print '<tr><td width="15%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+	    }
+	    else
+	    {
+	        print '<tr><td width="15%">'.$langs->trans("Company").'</td><td colspan="3">';
+	        print $langs->trans("ContactNotLinkedToCompany");
+	        print '</td></tr>';
+	    }
+	}
 
-print '<br>';
+	// Civility
+	print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
+	print $contact->getCivilityLabel();
+	print '</td></tr>';
 
-print $langs->trans("ExportCardToFormat").': ';
-print '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$contact->id.'">';
-print img_picto($langs->trans("VCard"),'vcard.png').' ';
-print $langs->trans("VCard");
-print '</a>';
+	print '</table>';
 
+	print '</div>';
 
+	print '<br>';
 
+	print $langs->trans("ExportCardToFormat").': ';
+	print '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$contact->id.'">';
+	print img_picto($langs->trans("VCard"),'vcard.png').' ';
+	print $langs->trans("VCard");
+	print '</a>';
+}
 
 $db->close();
 
diff --git a/htdocs/contact/info.php b/htdocs/contact/info.php
index 51a80d8d9944f70cba4791d53696b46729d382be..5d4904faa87715f21fc82701c5bff991a2eb2d29 100644
--- a/htdocs/contact/info.php
+++ b/htdocs/contact/info.php
@@ -35,6 +35,8 @@ $contactid = GETPOST("id",'int');
 if ($user->societe_id) $socid=$user->societe_id;
 $result = restrictedArea($user, 'contact', $contactid, 'socpeople&societe');
 
+$contact = new Contact($db);
+
 
 
 /*
@@ -43,23 +45,25 @@ $result = restrictedArea($user, 'contact', $contactid, 'socpeople&societe');
 
 llxHeader('',$langs->trans("ContactsAddresses"),'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
 
+if ($contactid > 0)
+{
+	$result = $contact->fetch($contactid, $user);
 
-$contact = new Contact($db);
-$contact->fetch($contactid, $user);
-$contact->info($contactid);
+	$contact->info($contactid);
 
 
-$head = contact_prepare_head($contact);
+	$head = contact_prepare_head($contact);
 
-dol_fiche_head($head, 'info', $langs->trans("ContactsAddresses"), 0, 'contact');
+	dol_fiche_head($head, 'info', $langs->trans("ContactsAddresses"), 0, 'contact');
 
 
-print '<table width="100%"><tr><td>';
-print '</td></tr></table>';
+	print '<table width="100%"><tr><td>';
+	print '</td></tr></table>';
 
-dol_print_object_info($contact);
+	dol_print_object_info($contact);
 
-print "</div>";
+	print "</div>";
+}
 
 llxFooter();
 
diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php
index 1681324323ab47899ad54c377b0e05afdeebdccf..79e6246fc6054071a155c8552a83e81794b373f4 100644
--- a/htdocs/contact/ldap.php
+++ b/htdocs/contact/ldap.php
@@ -40,37 +40,40 @@ if ($user->societe_id) $socid=$user->societe_id;
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 
 $contact = new Contact($db);
-$contact->fetch($id, $user);
 
+if ($id > 0)
+{
+	$contact->fetch($id, $user);
 
-/*
- * Actions
- */
+	/*
+	 * Actions
+	 */
 
-if ($action == 'dolibarr2ldap')
-{
-	$message="";
+	if ($action == 'dolibarr2ldap')
+	{
+		$message="";
 
-	$db->begin();
+		$db->begin();
 
-	$ldap=new Ldap();
-	$result=$ldap->connect_bind();
+		$ldap=new Ldap();
+		$result=$ldap->connect_bind();
 
-	$info=$contact->_load_ldap_info();
-	$dn=$contact->_load_ldap_dn($info);
-	$olddn=$dn;	// We can say that old dn = dn as we force synchro
+		$info=$contact->_load_ldap_info();
+		$dn=$contact->_load_ldap_dn($info);
+		$olddn=$dn;	// We can say that old dn = dn as we force synchro
 
-	$result=$ldap->update($dn,$info,$user,$olddn);
+		$result=$ldap->update($dn,$info,$user,$olddn);
 
-	if ($result >= 0)
-	{
-		$message.='<div class="ok">'.$langs->trans("ContactSynchronized").'</div>';
-		$db->commit();
-	}
-	else
-	{
-		$message.='<div class="error">'.$ldap->error.'</div>';
-		$db->rollback();
+		if ($result >= 0)
+		{
+			$message.='<div class="ok">'.$langs->trans("ContactSynchronized").'</div>';
+			$db->commit();
+		}
+		else
+		{
+			$message.='<div class="error">'.$ldap->error.'</div>';
+			$db->rollback();
+		}
 	}
 }
 
@@ -79,135 +82,137 @@ if ($action == 'dolibarr2ldap')
  *	View
  */
 
+$form = new Form($db);
+
 $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
 
 llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
 
-$form = new Form($db);
+if ($id > 0)
+{
+	$head = contact_prepare_head($contact);
 
-$head = contact_prepare_head($contact);
+	dol_fiche_head($head, 'ldap', $title, 0, 'contact');
 
-dol_fiche_head($head, 'ldap', $title, 0, 'contact');
 
+	print '<table class="border" width="100%">';
 
-print '<table class="border" width="100%">';
+	// Ref
+	print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
+	print $form->showrefnav($contact,'id');
+	print '</td></tr>';
 
-// Ref
-print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
-print $form->showrefnav($contact,'id');
-print '</td></tr>';
+	// Name
+	print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$contact->lastname.'</td>';
+	print '<td>'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->firstname.'</td></tr>';
 
-// Name
-print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$contact->lastname.'</td>';
-print '<td>'.$langs->trans("Firstname").'</td><td width="25%">'.$contact->firstname.'</td></tr>';
+	// Company
+	if ($contact->socid > 0)
+	{
+		$objsoc = new Societe($db);
+		$objsoc->fetch($contact->socid);
 
-// Company
-if ($contact->socid > 0)
-{
-	$objsoc = new Societe($db);
-	$objsoc->fetch($contact->socid);
+		print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+	}
+	else
+	{
+		print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">';
+		print $langs->trans("ContactNotLinkedToCompany");
+		print '</td></tr>';
+	}
 
-	print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
-}
-else
-{
-	print '<tr><td width="20%">'.$langs->trans("Company").'</td><td colspan="3">';
-	print $langs->trans("ContactNotLinkedToCompany");
+	// Civility
+	print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
+	print $contact->getCivilityLabel();
 	print '</td></tr>';
-}
-
-// Civility
-print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
-print $contact->getCivilityLabel();
-print '</td></tr>';
 
-// LDAP DN
-print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_CONTACT_DN."</td></tr>\n";
+	// LDAP DN
+	print '<tr><td>LDAP '.$langs->trans("LDAPContactDn").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_CONTACT_DN."</td></tr>\n";
 
-// LDAP Cle
-print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_KEY_CONTACTS."</td></tr>\n";
+	// LDAP Cle
+	print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_KEY_CONTACTS."</td></tr>\n";
 
-// LDAP Server
-print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
-print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
-print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
+	// LDAP Server
+	print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
+	print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
+	print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur" colspan="3">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
 
-print '</table>';
+	print '</table>';
 
-print '</div>';
+	print '</div>';
 
 
-dol_htmloutput_mesg($message);
+	dol_htmloutput_mesg($message);
 
 
-/*
- * Barre d'actions
- */
+	/*
+	 * Barre d'actions
+	 */
 
-print '<div class="tabsAction">';
+	print '<div class="tabsAction">';
 
-if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr')
-{
-	print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$contact->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
-}
+	if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr')
+	{
+		print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$contact->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
+	}
 
-print "</div>\n";
+	print "</div>\n";
 
-if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "<br>\n";
+	if (! empty($conf->global->LDAP_CONTACT_ACTIVE) && $conf->global->LDAP_CONTACT_ACTIVE != 'ldap2dolibarr') print "<br>\n";
 
 
 
-// Affichage attributs LDAP
-print_titre($langs->trans("LDAPInformationsForThisContact"));
+	// Affichage attributs LDAP
+	print_titre($langs->trans("LDAPInformationsForThisContact"));
 
-print '<table width="100%" class="noborder">';
+	print '<table width="100%" class="noborder">';
 
-print '<tr class="liste_titre">';
-print '<td>'.$langs->trans("LDAPAttributes").'</td>';
-print '<td>'.$langs->trans("Value").'</td>';
-print '</tr>';
+	print '<tr class="liste_titre">';
+	print '<td>'.$langs->trans("LDAPAttributes").'</td>';
+	print '<td>'.$langs->trans("Value").'</td>';
+	print '</tr>';
 
-// Lecture LDAP
-$ldap=new Ldap();
-$result=$ldap->connect_bind();
-if ($result > 0)
-{
-	$info=$contact->_load_ldap_info();
-	$dn=$contact->_load_ldap_dn($info,1);
-	$search = "(".$contact->_load_ldap_dn($info,2).")";
-	$records=$ldap->getAttribute($dn,$search);
+	// Lecture LDAP
+	$ldap=new Ldap();
+	$result=$ldap->connect_bind();
+	if ($result > 0)
+	{
+		$info=$contact->_load_ldap_info();
+		$dn=$contact->_load_ldap_dn($info,1);
+		$search = "(".$contact->_load_ldap_dn($info,2).")";
+		$records=$ldap->getAttribute($dn,$search);
 
-	//var_dump($records);
+		//var_dump($records);
 
-	// Affichage arbre
-	if (count($records) && $records != false && (! isset($records['count']) || $records['count'] > 0))
-	{
-		if (! is_array($records))
+		// Affichage arbre
+		if (count($records) && $records != false && (! isset($records['count']) || $records['count'] > 0))
 		{
-			print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
+			if (! is_array($records))
+			{
+				print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
+			}
+			else
+			{
+				$result=show_ldap_content($records,0,$records['count'],true);
+			}
 		}
 		else
 		{
-			$result=show_ldap_content($records,0,$records['count'],true);
+			print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
 		}
+
+		$ldap->unbind();
+		$ldap->close();
 	}
 	else
 	{
-		print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
+		dol_print_error('',$ldap->error);
 	}
 
-	$ldap->unbind();
-	$ldap->close();
-}
-else
-{
-	dol_print_error('',$ldap->error);
-}
-
-
-print '</table>';
 
+	print '</table>';
 
+}
 
 
 $db->close();
diff --git a/htdocs/contact/perso.php b/htdocs/contact/perso.php
index 92ba03e9861dab3c07b36cbc7cc1294826d56d32..bd74fc75ef84abafbd127176d941e7247a4aae27 100644
--- a/htdocs/contact/perso.php
+++ b/htdocs/contact/perso.php
@@ -38,210 +38,213 @@ if ($user->societe_id) $socid=$user->societe_id;
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 $object = new Contact($db);
 
-/*
- * Action
- */
+$result = $object->fetch($id, $user);
 
-if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
+if ($id > 0)
 {
-	$ret = $object->fetch($id);
-
-	// Note: Correct date should be completed with location to have exact GM time of birth.
-	$object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]);
-	$object->birthday_alert = $_POST["birthday_alert"];
-
-	$result = $object->update_perso($id, $user);
-	if ($result > 0)
-	{
-		$object->old_name='';
-		$object->old_firstname='';
-	}
-	else
-	{
-		$error = $object->error;
-	}
-}
+    /*
+     * Action
+     */
+
+    if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
+    {
+        // Note: Correct date should be completed with location to have exact GM time of birth.
+        $object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]);
+        $object->birthday_alert = $_POST["birthday_alert"];
 
+        $result = $object->update_perso($id, $user);
+        if ($result > 0)
+        {
+            $object->old_name='';
+            $object->old_firstname='';
+        }
+        else
+        {
+            $error = $object->error;
+        }
+    }
+}
 
 /*
  *	View
  */
 
+$form = new Form($db);
+
 $now=dol_now();
 
 $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
 
 llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
 
-$form = new Form($db);
+if ($id > 0)
+{
+    $head = contact_prepare_head($object);
 
-$object->fetch($id, $user);
+    dol_fiche_head($head, 'perso', $title, 0, 'contact');
 
-$head = contact_prepare_head($object);
+    if ($action == 'edit')
+    {
+        /*
+         * Fiche en mode edition
+         */
 
-dol_fiche_head($head, 'perso', $title, 0, 'contact');
+        print '<form name="perso" method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
+        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+        print '<input type="hidden" name="action" value="update">';
+        print '<input type="hidden" name="id" value="'.$object->id.'">';
 
-if ($action == 'edit')
-{
-	/*
-	 * Fiche en mode edition
-	 */
+        print '<table class="border" width="100%">';
 
-    print '<form name="perso" method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
-    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-    print '<input type="hidden" name="action" value="update">';
-    print '<input type="hidden" name="id" value="'.$object->id.'">';
+        // Ref
+        print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
+        print $object->id;
+        print '</td></tr>';
 
-    print '<table class="border" width="100%">';
+        // Name
+        print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
+        print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td>';
 
-    // Ref
-    print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
-    print $object->id;
-    print '</td></tr>';
+        // Company
+        if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
+        {
+            if ($object->socid > 0)
+            {
+                $objsoc = new Societe($db);
+                $objsoc->fetch($object->socid);
+
+                print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td>';
+            }
+            else
+            {
+                print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
+                print $langs->trans("ContactNotLinkedToCompany");
+                print '</td></tr>';
+            }
+        }
 
-    // Name
-    print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
-    print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td>';
+        // Civility
+        print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
+        print $object->getCivilityLabel();
+        print '</td></tr>';
 
-    // Company
-    if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-    {
-        if ($object->socid > 0)
-        {
-            $objsoc = new Societe($db);
-            $objsoc->fetch($object->socid);
+        // Date To Birth
+        print '<tr><td>'.$langs->trans("DateToBirth").'</td><td>';
+        $form=new Form($db);
+        print $form->select_date($object->birthday,'birthday',0,0,1,"perso");
+        print '</td>';
 
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td>';
+        print '<td colspan="2">'.$langs->trans("Alert").': ';
+        if (! empty($object->birthday_alert))
+        {
+            print '<input type="checkbox" name="birthday_alert" checked="checked"></td>';
         }
         else
         {
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
-            print $langs->trans("ContactNotLinkedToCompany");
-            print '</td></tr>';
+            print '<input type="checkbox" name="birthday_alert"></td>';
         }
-    }
+        print '</tr>';
 
-    // Civility
-    print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
-    print $object->getCivilityLabel();
-    print '</td></tr>';
+        print "</table><br>";
 
-    // Date To Birth
-    print '<tr><td>'.$langs->trans("DateToBirth").'</td><td>';
-    $form=new Form($db);
-    print $form->select_date($object->birthday,'birthday',0,0,1,"perso");
-    print '</td>';
+        print '<center>';
+        print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
+        print ' &nbsp; ';
+        print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
+        print '</center>';
 
-    print '<td colspan="2">'.$langs->trans("Alert").': ';
-    if (! empty($object->birthday_alert))
-    {
-        print '<input type="checkbox" name="birthday_alert" checked="checked"></td>';
+        print "</form>";
     }
     else
     {
-        print '<input type="checkbox" name="birthday_alert"></td>';
-    }
-    print '</tr>';
+        /*
+         * Fiche en mode visu
+         */
+        print '<table class="border" width="100%">';
 
-    print "</table><br>";
+        $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
 
-    print '<center>';
-    print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
-    print ' &nbsp; ';
-    print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
-    print '</center>';
+        // Ref
+        print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
+        print $form->showrefnav($object, 'id', $linkback);
+        print '</td></tr>';
 
-    print "</form>";
-}
-else
-{
-    /*
-     * Fiche en mode visu
-     */
-    print '<table class="border" width="100%">';
-
-    $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
+        // Name
+        print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
+        print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td></tr>';
 
-    // Ref
-    print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
-    print $form->showrefnav($object, 'id', $linkback);
-    print '</td></tr>';
-
-    // Name
-    print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
-    print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td></tr>';
-
-    // Company
-    if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
-    {
-        if ($object->socid > 0)
+        // Company
+        if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
         {
-            $objsoc = new Societe($db);
-            $objsoc->fetch($object->socid);
-
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+            if ($object->socid > 0)
+            {
+                $objsoc = new Societe($db);
+                $objsoc->fetch($object->socid);
+
+                print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
+            }
+
+            else
+            {
+                print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
+                print $langs->trans("ContactNotLinkedToCompany");
+                print '</td></tr>';
+            }
         }
 
-        else
+        // Civility
+        print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
+        print $object->getCivilityLabel();
+        print '</td></tr>';
+
+        // Date To Birth
+        print '<tr>';
+        if (! empty($object->birthday))
         {
-            print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
-            print $langs->trans("ContactNotLinkedToCompany");
-            print '</td></tr>';
-        }
-    }
+            include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
 
-    // Civility
-    print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
-    print $object->getCivilityLabel();
-    print '</td></tr>';
+            print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.dol_print_date($object->birthday,"day");
 
-    // Date To Birth
-    print '<tr>';
-    if (! empty($object->birthday))
-    {
-        include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
+            print ' &nbsp; ';
+            //var_dump($birthdatearray);
+            $ageyear=convertSecondToTime($now-$object->birthday,'year')-1970;
+            $agemonth=convertSecondToTime($now-$object->birthday,'month')-1;
+            if ($ageyear >= 2) print '('.$ageyear.' '.$langs->trans("DurationYears").')';
+            else if ($agemonth >= 2) print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
+            else print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
 
-        print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.dol_print_date($object->birthday,"day");
 
-        print ' &nbsp; ';
-        //var_dump($birthdatearray);
-        $ageyear=convertSecondToTime($now-$object->birthday,'year')-1970;
-        $agemonth=convertSecondToTime($now-$object->birthday,'month')-1;
-        if ($ageyear >= 2) print '('.$ageyear.' '.$langs->trans("DurationYears").')';
-        else if ($agemonth >= 2) print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
-        else print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
+            print ' &nbsp; - &nbsp; ';
+            if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn");
+            else print $langs->trans("BirthdayAlertOff");
+            print '</td>';
+        }
+        else
+        {
+            print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.$langs->trans("Unknown")."</td>";
+        }
+        print "</tr>";
 
+        print "</table>";
 
-        print ' &nbsp; - &nbsp; ';
-        if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn");
-        else print $langs->trans("BirthdayAlertOff");
-        print '</td>';
     }
-    else
-    {
-        print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.$langs->trans("Unknown")."</td>";
-    }
-    print "</tr>";
 
-    print "</table>";
+    dol_fiche_end();
 
-}
-
-dol_fiche_end();
-
-if ($action != 'edit')
-{
-    // Barre d'actions
-    if ($user->societe_id == 0)
+    if ($action != 'edit')
     {
-        print '<div class="tabsAction">';
-
-        if ($user->rights->societe->contact->creer)
+        // Barre d'actions
+        if ($user->societe_id == 0)
         {
-            print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
-        }
+            print '<div class="tabsAction">';
+
+            if ($user->rights->societe->contact->creer)
+            {
+                print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
+            }
 
-        print "</div>";
+            print "</div>";
+        }
     }
 }
 
diff --git a/htdocs/contact/vcard.php b/htdocs/contact/vcard.php
index e78c298c541c446c12798b349025b0840a1b40e3..1a69eaeb80e153aa0c4722b688de704f3b72ea54 100644
--- a/htdocs/contact/vcard.php
+++ b/htdocs/contact/vcard.php
@@ -35,69 +35,73 @@ $id = GETPOST('id', 'int');
 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
 
 $contact = new Contact($db);
-$result=$contact->fetch($id);
 
-$physicalperson=1;
-
-$company = new Societe($db);
-if ($contact->socid)
+if ($id > 0)
 {
-	$result=$company->fetch($contact->socid);
-	//print "ee";
-}
+	$result=$contact->fetch($id);
 
-// We create VCard
-$v = new vCard();
-$v->setProdId('Dolibarr '.DOL_VERSION);
+	$physicalperson=1;
 
-$v->setUid('DOLIBARR-CONTACTID-'.$contact->id);
-$v->setName($contact->lastname, $contact->firstname, "", "", "");
-$v->setFormattedName($contact->getFullName($langs));
+	$company = new Societe($db);
+	if ($contact->socid)
+	{
+		$result=$company->fetch($contact->socid);
+		//print "ee";
+	}
 
-// By default, all informations are for work (except phone_perso and phone_mobile)
-$v->setPhoneNumber($contact->phone_pro, "PREF;WORK;VOICE");
-$v->setPhoneNumber($contact->phone_mobile, "CELL;VOICE");
-$v->setPhoneNumber($contact->fax, "WORK;FAX");
+	// We create VCard
+	$v = new vCard();
+	$v->setProdId('Dolibarr '.DOL_VERSION);
 
-$v->setAddress("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country_id:''), "WORK;POSTAL");
-$v->setLabel("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country_id:''), "WORK");
-$v->setEmail($contact->email,'internet,pref');
-$v->setNote($contact->note);
+	$v->setUid('DOLIBARR-CONTACTID-'.$contact->id);
+	$v->setName($contact->lastname, $contact->firstname, "", "", "");
+	$v->setFormattedName($contact->getFullName($langs));
 
-$v->setTitle($contact->poste);
+	// By default, all informations are for work (except phone_perso and phone_mobile)
+	$v->setPhoneNumber($contact->phone_pro, "PREF;WORK;VOICE");
+	$v->setPhoneNumber($contact->phone_mobile, "CELL;VOICE");
+	$v->setPhoneNumber($contact->fax, "WORK;FAX");
 
-// Data from linked company
-if ($company->id)
-{
-	$v->setURL($company->url, "WORK");
-	if (! $contact->phone_pro) $v->setPhoneNumber($company->phone, "WORK;VOICE");
-	if (! $contact->fax)       $v->setPhoneNumber($company->fax, "WORK;FAX");
-	if (! $contact->zip)        $v->setAddress("", "", $company->address, $company->town, "", $company->zip, $company->country_code, "WORK;POSTAL");
-	if ($company->email != $contact->email) $v->setEmail($company->email,'internet');
-	// Si contact lie a un tiers non de type "particulier"
-	if ($contact->typent_code != 'TE_PRIVATE') $v->setOrg($company->nom);
-}
+	$v->setAddress("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country_id:''), "WORK;POSTAL");
+	$v->setLabel("", "", $contact->address, $contact->town, "", $contact->zip, ($contact->country_code?$contact->country_id:''), "WORK");
+	$v->setEmail($contact->email,'internet,pref');
+	$v->setNote($contact->note);
 
-// Personal informations
-$v->setPhoneNumber($contact->phone_perso, "HOME;VOICE");
-if ($contact->birthday) $v->setBirthday($contact->birthday);
+	$v->setTitle($contact->poste);
 
-$db->close();
+	// Data from linked company
+	if ($company->id)
+	{
+		$v->setURL($company->url, "WORK");
+		if (! $contact->phone_pro) $v->setPhoneNumber($company->phone, "WORK;VOICE");
+		if (! $contact->fax)       $v->setPhoneNumber($company->fax, "WORK;FAX");
+		if (! $contact->zip)        $v->setAddress("", "", $company->address, $company->town, "", $company->zip, $company->country_code, "WORK;POSTAL");
+		if ($company->email != $contact->email) $v->setEmail($company->email,'internet');
+		// Si contact lie a un tiers non de type "particulier"
+		if ($contact->typent_code != 'TE_PRIVATE') $v->setOrg($company->nom);
+	}
 
+	// Personal informations
+	$v->setPhoneNumber($contact->phone_perso, "HOME;VOICE");
+	if ($contact->birthday) $v->setBirthday($contact->birthday);
 
-// Renvoi la VCard au navigateur
+	$db->close();
 
-$output = $v->getVCard();
 
-$filename =trim(urldecode($v->getFileName()));      // "Nom prenom.vcf"
-$filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
-//$filename = dol_sanitizeFileName($filename);
+	// Renvoi la VCard au navigateur
 
+	$output = $v->getVCard();
 
-header("Content-Disposition: attachment; filename=\"".$filename."\"");
-header("Content-Length: ".dol_strlen($output));
-header("Connection: close");
-header("Content-Type: text/x-vcard; name=\"".$filename."\"");
+	$filename =trim(urldecode($v->getFileName()));      // "Nom prenom.vcf"
+	$filenameurlencoded = dol_sanitizeFileName(urlencode($filename));
+	//$filename = dol_sanitizeFileName($filename);
 
-print $output;
+
+	header("Content-Disposition: attachment; filename=\"".$filename."\"");
+	header("Content-Length: ".dol_strlen($output));
+	header("Connection: close");
+	header("Content-Type: text/x-vcard; name=\"".$filename."\"");
+
+	print $output;
+}
 
diff --git a/htdocs/core/actions_extrafields.inc.php b/htdocs/core/actions_extrafields.inc.php
index 89edfcbae8ea994ee301c78085dba091c5d1928e..d547d635855bd20294bafb82b200ee794bdf84e6 100644
--- a/htdocs/core/actions_extrafields.inc.php
+++ b/htdocs/core/actions_extrafields.inc.php
@@ -118,7 +118,7 @@ if ($action == 'add')
 	    if (! $error)
 	    {
     		// attrname must be alphabetical and lower case only
-    		if (isset($_POST["attrname"]) && preg_match("/^[a-z0-9-_]+$/",$_POST['attrname']))
+    		if (isset($_POST["attrname"]) && preg_match("/^[a-z0-9-_]+$/",$_POST['attrname']) && !is_numeric($_POST["attrname"]))
     		{
     			// Construct array for parameter (value of select list)
         		$default_value = GETPOST('default_value');
diff --git a/htdocs/core/boxes/box_prospect.php b/htdocs/core/boxes/box_prospect.php
index 6d62989727be047fc00a5504e5ec8c53d8aa4a41..294178eb7b01b36d8dd0c4bfd6d7c48b789c390d 100644
--- a/htdocs/core/boxes/box_prospect.php
+++ b/htdocs/core/boxes/box_prospect.php
@@ -136,7 +136,6 @@ class box_prospect extends ModeleBoxes
 			}
 		}
 		else {
-			dol_syslog("box_prospect::loadBox not allowed de read this box content",LOG_ERR);
 			$this->info_box_contents[0][0] = array('td' => 'align="left"',
         'text' => $langs->trans("ReadPermissionNotAllowed"));
 		}
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 39639a7783ef56d08b0bc03428827a6e924bc135..902fff35bcb9df8dfc5b820618725d24584c8428 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -847,7 +847,7 @@ class Form
                         $out.= '<option value="'.$obj->rowid.'">'.$label.'</option>';
                     }
 
-                    array_push($outarray, array('key'=>$obj->rowid, 'value'=>$obj->name, 'label'=>$obj->name));
+                    array_push($outarray, array('key'=>$obj->rowid, 'value'=>$obj->rowid, 'label'=>$label));
 
                     $i++;
                     if (($i % 10) == 0) $out.="\n";
diff --git a/htdocs/core/class/vcard.class.php b/htdocs/core/class/vcard.class.php
index 512aa011d986c208990689f2ce7aacef0f1ac915..f0da8530ac2fa4099f84026c0e7111c71c5f6174 100644
--- a/htdocs/core/class/vcard.class.php
+++ b/htdocs/core/class/vcard.class.php
@@ -150,7 +150,7 @@ class vCard
     {
         $this->properties["N;CHARSET=".$this->encoding] = encode($family).";".encode($first).";".encode($additional).";".encode($prefix).";".encode($suffix);
         $this->filename = "$first%20$family.vcf";
-        if ($this->properties["FN"]=="") $this->setFormattedName(trim("$prefix $first $additional $family $suffix"));
+        if (empty($this->properties["FN"])) $this->setFormattedName(trim("$prefix $first $additional $family $suffix"));
     }
 
     /**
diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php
index 92489cd9d61aa5ce59a1391aa53e53f8bc138621..544984b9c5a2740a48d2743f755baae7ae960872 100644
--- a/htdocs/core/menus/standard/eldy.lib.php
+++ b/htdocs/core/menus/standard/eldy.lib.php
@@ -134,9 +134,11 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0)
 	}
 
 	// Financial
-	$tmpentry=array('enabled'=>(! empty($conf->comptabilite->enabled) || ! empty($conf->accounting->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->don->enabled) || ! empty($conf->tax->enabled) || ! empty($conf->salaries->enabled) || ! empty($conf->fournisseur->enabled)),
-	'perms'=>(! empty($user->rights->compta->resultat->lire) || ! empty($user->rights->accounting->plancompte->lire) || ! empty($user->rights->facture->lire) || ! empty($user->rights->don->lire) || ! empty($user->rights->tax->charges->lire) || ! empty($user->rights->salaries->read) || ! empty($user->rights->fournisseur->facture->lire)),
-	'module'=>'comptabilite|accounting|facture|don|tax|salaries');
+	$tmpentry=array(
+		'enabled' => (! empty($conf->comptabilite->enabled) || ! empty($conf->accounting->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->don->enabled) || ! empty($conf->tax->enabled) || ! empty($conf->margin->enabled) || ! empty($conf->salaries->enabled) || ! empty($conf->fournisseur->enabled)),
+		'perms' => (! empty($user->rights->compta->resultat->lire) || ! empty($user->rights->accounting->plancompte->lire) || ! empty($user->rights->facture->lire) || ! empty($user->rights->don->lire) || ! empty($user->rights->tax->charges->lire) || !empty($user->rights->margins->liretous) || ! empty($user->rights->salaries->read) || ! empty($user->rights->fournisseur->facture->lire)),
+		'module' => 'comptabilite|accounting|facture|don|tax|salaries|margin'
+	);
 	$showmode=dol_eldy_showmenu($type_user, $tmpentry, $listofmodulesforexternal);
 	if ($showmode)
 	{
diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php
index 8b636fd247f8e0cfe24eedfb3ef02c9c7a05f3b2..3504c99e1d19ea634852f9314458496fb0f1d40b 100644
--- a/htdocs/core/modules/DolibarrModules.class.php
+++ b/htdocs/core/modules/DolibarrModules.class.php
@@ -1013,7 +1013,6 @@ abstract class DolibarrModules
 
         $this->db->begin();
 
-        //var_dump($this->menu); exit;
         foreach ($this->menu as $key => $value)
         {
             $menu = new Menubase($this->db);
@@ -1022,11 +1021,9 @@ abstract class DolibarrModules
             if (! $this->menu[$key]['fk_menu'])
             {
                 $menu->fk_menu=0;
-                //print 'aaa'.$this->menu[$key]['fk_menu'];
             }
             else
             {
-                //print 'xxx'.$this->menu[$key]['fk_menu'];exit;
                 $foundparent=0;
                 $fk_parent=$this->menu[$key]['fk_menu'];
                 if (preg_match('/^r=/',$fk_parent))	// old deprecated method
diff --git a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php
index 4124d4745f636f7e4a16e95a6ade460f71f0529d..e45f45cb79bd46e6acb1707434a33e29c9e4ef47 100644
--- a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php
+++ b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php
@@ -301,7 +301,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
 						$pageposafter=$pageposbefore;
 						//print $pageposafter.'-'.$pageposbefore;exit;
 						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
-						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
+						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,1);
 						$posyafter=$pdf->GetY();
 						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
 						{
diff --git a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php
index 83d1aac952b6c1119368b9dffd8a86c08ec1e923..5376d7fcd276d27c31ee38880795d7a59d5582e4 100644
--- a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php
+++ b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php
@@ -309,7 +309,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 						$pageposafter=$pageposbefore;
 						//print $pageposafter.'-'.$pageposbefore;exit;
 						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
-						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
+						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,1);
 						$posyafter=$pdf->GetY();
 						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
 						{
diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php
index ce9885c1f1a7d5b684611dd9b1b3deb26a1e9d60..2e591bf67be34824f6552119310090ba14107d5b 100644
--- a/htdocs/expedition/class/expedition.class.php
+++ b/htdocs/expedition/class/expedition.class.php
@@ -1105,6 +1105,8 @@ class Expedition extends CommonObject
 				$obj = $this->db->fetch_object($resql);
 
                 $line->line_id          = $obj->line_id;
+                $line->rowid            = $obj->line_id;    // TODO deprecated
+                $line->id               = $obj->line_id;
 				$line->fk_origin_line 	= $obj->fk_origin_line;
 				$line->origin_line_id 	= $obj->fk_origin_line;	    // TODO deprecated
 				$line->entrepot_id    	= $obj->fk_entrepot;
diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php
index 73f3ae3e77a3c46212ebc0fb7ecc763372484261..0e23287ac31506d65b944677432a72112b3c75da 100644
--- a/htdocs/filefunc.inc.php
+++ b/htdocs/filefunc.inc.php
@@ -29,7 +29,7 @@
  *  \brief      File that include conf.php file and commons lib like functions.lib.php
  */
 
-if (! defined('DOL_VERSION')) define('DOL_VERSION','3.6.4');
+if (! defined('DOL_VERSION')) define('DOL_VERSION','3.6.5');
 if (! defined('EURO')) define('EURO',chr(128));
 
 // Define syslog constants
diff --git a/htdocs/includes/tcpdf/fonts/dejavusanscondensed.ctg.z b/htdocs/includes/tcpdf/fonts/dejavusanscondensed.ctg.z
new file mode 100755
index 0000000000000000000000000000000000000000..df25b6497f084274a55feb158bb478f237137568
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusanscondensed.ctg.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusanscondensed.z b/htdocs/includes/tcpdf/fonts/dejavusanscondensed.z
new file mode 100755
index 0000000000000000000000000000000000000000..2053dd16f031128023f839d0344a97a754285a19
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusanscondensed.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusanscondensedb.ctg.z b/htdocs/includes/tcpdf/fonts/dejavusanscondensedb.ctg.z
new file mode 100755
index 0000000000000000000000000000000000000000..71cef637e83311b26f0d4325c39b137930335918
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusanscondensedb.ctg.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusanscondensedb.z b/htdocs/includes/tcpdf/fonts/dejavusanscondensedb.z
new file mode 100755
index 0000000000000000000000000000000000000000..af54a16a09a5a4fb7fd7f4e4d44fb0f4e3f8e722
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusanscondensedb.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusanscondensedbi.ctg.z b/htdocs/includes/tcpdf/fonts/dejavusanscondensedbi.ctg.z
new file mode 100755
index 0000000000000000000000000000000000000000..23445ef2f4ba7cbb6b067515a98d6500f62a23f5
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusanscondensedbi.ctg.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusanscondensedbi.z b/htdocs/includes/tcpdf/fonts/dejavusanscondensedbi.z
new file mode 100755
index 0000000000000000000000000000000000000000..37da24ac6a9f8ff661e9aa0e3625674c3aed51ab
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusanscondensedbi.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusanscondensedi.ctg.z b/htdocs/includes/tcpdf/fonts/dejavusanscondensedi.ctg.z
new file mode 100755
index 0000000000000000000000000000000000000000..1b98d135f6843177fd449faf94308ad8f33326d4
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusanscondensedi.ctg.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusanscondensedi.z b/htdocs/includes/tcpdf/fonts/dejavusanscondensedi.z
new file mode 100755
index 0000000000000000000000000000000000000000..aa35d093a84707bad6b4314828d80cf21c62e77a
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusanscondensedi.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusansextralight.ctg.z b/htdocs/includes/tcpdf/fonts/dejavusansextralight.ctg.z
new file mode 100755
index 0000000000000000000000000000000000000000..d5fff04b70447a9468fac81266618fbb3b08d4c5
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusansextralight.ctg.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusansextralight.z b/htdocs/includes/tcpdf/fonts/dejavusansextralight.z
new file mode 100755
index 0000000000000000000000000000000000000000..a966f6de5c41357b3cae9cf88610eb77711f28db
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusansextralight.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusansmono.ctg.z b/htdocs/includes/tcpdf/fonts/dejavusansmono.ctg.z
new file mode 100755
index 0000000000000000000000000000000000000000..209e2d50b7425f6576effe463780bc5d4a5e44ea
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusansmono.ctg.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusansmono.z b/htdocs/includes/tcpdf/fonts/dejavusansmono.z
new file mode 100755
index 0000000000000000000000000000000000000000..126cc9228fe34a68006c69b7b997e79256ae46e2
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusansmono.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusansmonob.ctg.z b/htdocs/includes/tcpdf/fonts/dejavusansmonob.ctg.z
new file mode 100755
index 0000000000000000000000000000000000000000..76b78bc8f8b3c9e0a41a83366385e280a50ca0ca
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusansmonob.ctg.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusansmonob.z b/htdocs/includes/tcpdf/fonts/dejavusansmonob.z
new file mode 100755
index 0000000000000000000000000000000000000000..ef5638e2510ab23891b82dfe8fc359f7578bef53
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusansmonob.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusansmonobi.ctg.z b/htdocs/includes/tcpdf/fonts/dejavusansmonobi.ctg.z
new file mode 100755
index 0000000000000000000000000000000000000000..aa6da4149775e834c28adb6d6fdd1439b9ec4c5c
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusansmonobi.ctg.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusansmonobi.z b/htdocs/includes/tcpdf/fonts/dejavusansmonobi.z
new file mode 100755
index 0000000000000000000000000000000000000000..a866f79821ada258d10471c704595eaa9d7bcf0e
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusansmonobi.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusansmonoi.ctg.z b/htdocs/includes/tcpdf/fonts/dejavusansmonoi.ctg.z
new file mode 100755
index 0000000000000000000000000000000000000000..0fa53ab2eff7b9fa20dfe3b891351d23f21a5b81
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusansmonoi.ctg.z differ
diff --git a/htdocs/includes/tcpdf/fonts/dejavusansmonoi.z b/htdocs/includes/tcpdf/fonts/dejavusansmonoi.z
new file mode 100755
index 0000000000000000000000000000000000000000..14be5c14e57e019eb6d5f7bd2e15c33f969a5a2d
Binary files /dev/null and b/htdocs/includes/tcpdf/fonts/dejavusansmonoi.z differ
diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang
index 4f5ac8fb9ec32812d9093308855b52b33c3df9a0..e4e35c2653a50fba4d431ed917ca357973d996e1 100644
--- a/htdocs/langs/en_US/errors.lang
+++ b/htdocs/langs/en_US/errors.lang
@@ -65,7 +65,7 @@ ErrorNoValueForCheckBoxType=Please fill value for checkbox list
 ErrorNoValueForRadioType=Please fill value for radio list
 ErrorBadFormatValueList=The list value cannot have more than one come : <u>%s</u>, but need at least one: llave,valores
 ErrorFieldCanNotContainSpecialCharacters=Field <b>%s</b> must not contains special characters.
-ErrorFieldCanNotContainSpecialNorUpperCharacters=Field <b>%s</b> must not contains special characters, nor upper case characters.
+ErrorFieldCanNotContainSpecialNorUpperCharacters=Field <b>%s</b> must not contain special characters, nor upper case characters and cannot contain only numbers.
 ErrorNoAccountancyModuleLoaded=No accountancy module activated
 ErrorExportDuplicateProfil=This profile name already exists for this export set.
 ErrorLDAPSetupNotComplete=Dolibarr-LDAP matching is not complete.
diff --git a/htdocs/margin/customerMargins.php b/htdocs/margin/customerMargins.php
index 34aea94e70f518801ff88561d18b8b3d52eee184..b1328fbff66bb7768cfef0e9b02f6e0f029cf49f 100644
--- a/htdocs/margin/customerMargins.php
+++ b/htdocs/margin/customerMargins.php
@@ -50,9 +50,9 @@ $pagenext = $page + 1;
 $startdate=$enddate='';
 
 if (!empty($_POST['startdatemonth']))
-  $startdate  = dol_mktime(12, 0, 0, $_POST['startdatemonth'],  $_POST['startdateday'],  $_POST['startdateyear']);
+  $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'],  $_POST['startdateday'],  $_POST['startdateyear']);
 if (!empty($_POST['enddatemonth']))
-  $enddate  = dol_mktime(12, 0, 0, $_POST['enddatemonth'],  $_POST['enddateday'],  $_POST['enddateyear']);
+  $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'],  $_POST['enddateday'],  $_POST['enddateyear']);
 
 /*
  * View
diff --git a/htdocs/margin/productMargins.php b/htdocs/margin/productMargins.php
index b8d5f7f66ba40a7b6a359499cf251f63618e4eff..88b97df78fccd3ab0031f70bd7f8867a40296d3f 100644
--- a/htdocs/margin/productMargins.php
+++ b/htdocs/margin/productMargins.php
@@ -72,9 +72,9 @@ $pagenext = $page + 1;
 $startdate=$enddate='';
 
 if (!empty($_POST['startdatemonth']))
-  $startdate  = dol_mktime(12, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']);
+  $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']);
 if (!empty($_POST['enddatemonth']))
-  $enddate  = dol_mktime(12, 0, 0, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']);
+  $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']);
 
 
 /*
diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php
index 678660b7e6ff5999ea816e9f6309b66088a72d99..dbf8e45044a2e29b6684cf8e1d721a146970b4fc 100644
--- a/htdocs/projet/class/task.class.php
+++ b/htdocs/projet/class/task.class.php
@@ -770,7 +770,8 @@ class Task extends CommonObject
         {
             $tasktime_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_time");
             $ret = $tasktime_id;
-
+			$this->timespent_id = $ret;
+			
             if (! $notrigger)
             {
                 // Call triggers
diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php
index a22a49e35ebfc1b145fc740db8564241cf8ca3b8..6b1f1bc53f4c99cddb113a12b2801c5efe6a84e6 100644
--- a/htdocs/societe/consumption.php
+++ b/htdocs/societe/consumption.php
@@ -186,7 +186,7 @@ if ($type_element == 'order')
 	$where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid;
 	$where.= " AND d.fk_commande = c.rowid";
 	$where.= " AND c.entity = ".$conf->entity;
-	$dateprint = 'c.datef';
+	$datePrint = 'c.date_commande';
 	$doc_number='c.ref';
 	$thirdTypeSelect='customer';
 }
diff --git a/htdocs/societe/info.php b/htdocs/societe/info.php
index 0deec0419322216554294dc1eadc701a008e584a..d4c030f766495706f639e5a9b83ae7ec4a766a6d 100644
--- a/htdocs/societe/info.php
+++ b/htdocs/societe/info.php
@@ -40,6 +40,7 @@ $result = restrictedArea($user, 'societe', $socid, '&societe');
 // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
 $hookmanager->initHooks(array('infothirdparty'));
 
+$soc = new Societe($db);
 
 
 /*
@@ -59,25 +60,26 @@ $error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->e
 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
 llxHeader('',$langs->trans("ThirdParty"),$help_url);
 
-$soc = new Societe($db);
-$soc->fetch($socid);
-$soc->info($socid);
-
-/*
- * Affichage onglets
- */
-$head = societe_prepare_head($soc);
+if ($socid > 0)
+{
+	$result = $soc->fetch($socid);
 
-dol_fiche_head($head, 'info', $langs->trans("ThirdParty"),0,'company');
+	$soc->info($socid);
 
+	/*
+	 * Affichage onglets
+	 */
+	$head = societe_prepare_head($soc);
 
+	dol_fiche_head($head, 'info', $langs->trans("ThirdParty"), 0, 'company');
 
-print '<table width="100%"><tr><td>';
-dol_print_object_info($soc);
-print '</td></tr></table>';
 
-print '</div>';
+	print '<table width="100%"><tr><td>';
+	dol_print_object_info($soc);
+	print '</td></tr></table>';
 
+	dol_fiche_end();
+}
 
 llxFooter();
 
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index a6ecf470d3847467d1a9daa8593515a87b919625..df0222fbde1468ad4c233e51d57e5ebd780bc8d7 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -1025,6 +1025,7 @@ else
         // Other attributes
         $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
         $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
+        print $hookmanager->resPrint;
         if (empty($reshook) && ! empty($extrafields->attribute_label))
         {
         	print $object->showOptionals($extrafields,'edit');
@@ -1436,6 +1437,7 @@ else
             // Other attributes
             $parameters=array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
             $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
+            print $hookmanager->resPrint;
             if (empty($reshook) && ! empty($extrafields->attribute_label))
             {
             	print $object->showOptionals($extrafields,'edit');