diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php
index 0c2a825604b277d136a09b174b5265a17e4ac24f..d935eb025dc09e3f929a81e9c98e4f8264e3ad02 100644
--- a/htdocs/accountancy/admin/account.php
+++ b/htdocs/accountancy/admin/account.php
@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2013-2014 Olivier Geffroy      <jeff@jeffinfo.com>
- * Copyright (C) 2013-2014 Alexandre Spangaro   <alexandre.spangaro@gmail.com>
+ * Copyright (C) 2013-2015 Alexandre Spangaro   <alexandre.spangaro@gmail.com>
  *
  * 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
@@ -154,7 +154,7 @@ if ($result) {
 	print_liste_field_titre($langs->trans("Accountparent"), $_SERVER["PHP_SELF"], "aa.account_parent", "", $param, "", $sortfield, $sortorder);
 	print_liste_field_titre($langs->trans("Pcgtype"), $_SERVER["PHP_SELF"], "aa.pcg_type", "", $param, "", $sortfield, $sortorder);
 	print_liste_field_titre($langs->trans("Pcgsubtype"), $_SERVER["PHP_SELF"], "aa.pcg_subtype", "", $param, "", $sortfield, $sortorder);
-	print_liste_field_titre($langs->trans("Active"), $_SERVER["PHP_SELF"], "aa.active", "", $param, "", $sortfield, $sortorder);
+	print_liste_field_titre($langs->trans("Activated"), $_SERVER["PHP_SELF"], "aa.active", "", $param, "", $sortfield, $sortorder);
 	print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"",$param,"",'width="60" align="center"',$sortfield,$sortorder);
 	print '</tr>';
 	
@@ -174,12 +174,17 @@ if ($result) {
 	
 	$var = true;
 	
+	$accountstatic=new AccountingAccount($db);
+	
 	while ( $i < min($num, $limit) ) {
 		$obj = $db->fetch_object($resql);
 		
-		$var = ! $var;
+		$accountstatic->id=$obj->rowid;
+		$accountstatic->label=$obj->label;
+		$accountstatic->account_number=$obj->account_number;
+
 		print '<tr ' . $bc[$var] . '>';
-		print '<td><a href="./card.php?id=' . $obj->rowid . '">' . $obj->account_number . '</td>';
+		print '<td>' . $accountstatic->getNomUrl(1) . '</td>';
 		print '<td>' . $obj->label . '</td>';
 		print '<td>' . $obj->account_parent . '</td>';
 		print '<td>' . $obj->pcg_type . '</td>';
@@ -210,6 +215,7 @@ if ($result) {
 		print '</td>' . "\n";
 		
 		print "</tr>\n";
+		$var=!$var;
 		$i ++;
 	}
 	
diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php
index 1161e83004c0984b2393ace631e47e1000279fb7..f3ad3e23a477156c134b3af72d2fea0ae86e093e 100644
--- a/htdocs/accountancy/class/accountingaccount.class.php
+++ b/htdocs/accountancy/class/accountingaccount.class.php
@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2013-2014 Olivier Geffroy      <jeff@jeffinfo.com>
- * Copyright (C) 2013-2014 Alexandre Spangaro   <alexandre.spangaro@gmail.com>
+ * Copyright (C) 2013-2015 Alexandre Spangaro   <alexandre.spangaro@gmail.com>
  * Copyright (C) 2013-2014 Florian Henry		<florian.henry@open-concept.pro>
  * Copyright (C) 2014 	   Juanjo Menent		<jmenent@2byte.es>
  *
@@ -66,8 +66,7 @@ class AccountingAccount extends CommonObject
 	 */
 	function fetch($rowid = null, $account_number = null)
 	{
-		if ($rowid || $account_number)
-		{
+		if ($rowid || $account_number) {
 			$sql = "SELECT rowid, datec, tms, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, fk_user_author, fk_user_modif, active";
 			$sql.= " FROM " . MAIN_DB_PREFIX . "accountingaccount WHERE";
 			if ($rowid) {
@@ -78,12 +77,10 @@ class AccountingAccount extends CommonObject
 
 			dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
 			$result = $this->db->query($sql);
-			if ($result)
-			{
+			if ($result) {
 				$obj = $this->db->fetch_object($result);
 
-				if ($obj)
-				{
+				if ($obj) {
 					$this->id = $obj->rowid;
 					$this->rowid = $obj->rowid;
 					$this->datec = $obj->datec;
@@ -99,18 +96,13 @@ class AccountingAccount extends CommonObject
 					$this->active = $obj->active;
 
 					return $this->id;
-				}
-				else
-				{
+				} else {
 					return 0;
 				}
-			}
-			else
-			{
+			} else {
 				dol_print_error($this->db);
 			}
 		}
-
 		return -1;
 	}
 
@@ -344,6 +336,31 @@ class AccountingAccount extends CommonObject
 		}
 	}
 
+	/**
+	 *	Return clicable name (with picto eventually)
+	 *
+	 *	@param		int		$withpicto		0=No picto, 1=Include picto into link, 2=Only picto
+	 *	@return		string					Chaine avec URL
+	 */
+	function getNomUrl($withpicto=0)
+	{
+		global $langs;
+
+		$result='';
+
+		$link = '<a href="'.DOL_URL_ROOT.'/accountancy/admin/card.php?id='.$this->id.'">';
+		$linkend='</a>';
+
+		$picto='billr';
+
+		$label=$langs->trans("Show").': '.$this->account_number.' - '.$this->label;
+
+		if ($withpicto) $result.=($link.img_object($label,$picto).$linkend);
+		if ($withpicto && $withpicto != 2) $result.=' ';
+		if ($withpicto != 2) $result.=$link.$this->account_number.$linkend;
+		return $result;
+	}
+
 	/**
 	 * Information on record
 	 *
diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php
index db4c1dff2096b8d4908b551d79e7d7c458854b21..53f5962f017c3a9c2fc6ac3dc91fe1abb7aa3ba8 100644
--- a/htdocs/admin/company.php
+++ b/htdocs/admin/company.php
@@ -51,216 +51,216 @@ $error=0;
 if ( ($action == 'update' && empty($_POST["cancel"]))
 || ($action == 'updateedit') )
 {
-    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
-    $tmparray=getCountry(GETPOST('country_id','int'),'all',$db,$langs,0);
-    if (! empty($tmparray['id']))
-    {
-        $mysoc->country_id   =$tmparray['id'];
-        $mysoc->country_code =$tmparray['code'];
-        $mysoc->country_label=$tmparray['label'];
-
-        $s=$mysoc->country_id.':'.$mysoc->country_code.':'.$mysoc->country_label;
-        dolibarr_set_const($db, "MAIN_INFO_SOCIETE_COUNTRY", $s,'chaine',0,'',$conf->entity);
-    }
-
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM",$_POST["nom"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ADDRESS",$_POST["address"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_TOWN",$_POST["town"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ZIP",$_POST["zipcode"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE",$_POST["state_id"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_MONNAIE",$_POST["currency"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_TEL",$_POST["tel"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_FAX",$_POST["fax"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_MAIL",$_POST["mail"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_WEB",$_POST["web"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOTE",$_POST["note"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_GENCOD",$_POST["barcode"],'chaine',0,'',$conf->entity);
-    if ($_FILES["logo"]["tmp_name"])
-    {
-        if (preg_match('/([^\\/:]+)$/i',$_FILES["logo"]["name"],$reg))
-        {
-            $original_file=$reg[1];
-
-            $isimage=image_format_supported($original_file);
-            if ($isimage >= 0)
-            {
-                dol_syslog("Move file ".$_FILES["logo"]["tmp_name"]." to ".$conf->mycompany->dir_output.'/logos/'.$original_file);
-                if (! is_dir($conf->mycompany->dir_output.'/logos/'))
-                {
-                    dol_mkdir($conf->mycompany->dir_output.'/logos/');
-                }
-                $result=dol_move_uploaded_file($_FILES["logo"]["tmp_name"],$conf->mycompany->dir_output.'/logos/'.$original_file,1,0,$_FILES['logo']['error']);
-                if ($result > 0)
-                {
-                    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO",$original_file,'chaine',0,'',$conf->entity);
-
-                    // Create thumbs of logo (Note that PDF use original file and not thumbs)
-                    if ($isimage > 0)
-                    {
-                        // Create small thumbs for company (Ratio is near 16/9)
-                        // Used on logon for example
-                        $imgThumbSmall = vignette($conf->mycompany->dir_output.'/logos/'.$original_file, $maxwidthsmall, $maxheightsmall, '_small', $quality);
-                        if (preg_match('/([^\\/:]+)$/i',$imgThumbSmall,$reg))
-                        {
-                            $imgThumbSmall = $reg[1];
-                            dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall,'chaine',0,'',$conf->entity);
-                        }
-                        else dol_syslog($imgThumbSmall);
-
-                        // Create mini thumbs for company (Ratio is near 16/9)
-                        // Used on menu or for setup page for example
-                        $imgThumbMini = vignette($conf->mycompany->dir_output.'/logos/'.$original_file, $maxwidthmini, $maxheightmini, '_mini', $quality);
-                        if (preg_match('/([^\\/:]+)$/i',$imgThumbMini,$reg))
-                        {
-                            $imgThumbMini = $reg[1];
-                            dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini,'chaine',0,'',$conf->entity);
-                        }
-                        else dol_syslog($imgThumbMini);
-                    }
-                    else dol_syslog("ErrorImageFormatNotSupported",LOG_WARNING);
-                }
-                else if (preg_match('/^ErrorFileIsInfectedWithAVirus/',$result))
-                {
-                	$error++;
-                    $langs->load("errors");
-                    $tmparray=explode(':',$result);
-                    setEventMessage($langs->trans('ErrorFileIsInfectedWithAVirus',$tmparray[1]),'errors');
-                }
-                else
-                {
-                	$error++;
-                    setEventMessage($langs->trans("ErrorFailedToSaveFile"),'errors');
-                }
-            }
-            else
+	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+	$tmparray=getCountry(GETPOST('country_id','int'),'all',$db,$langs,0);
+	if (! empty($tmparray['id']))
+	{
+		$mysoc->country_id   =$tmparray['id'];
+		$mysoc->country_code =$tmparray['code'];
+		$mysoc->country_label=$tmparray['label'];
+
+		$s=$mysoc->country_id.':'.$mysoc->country_code.':'.$mysoc->country_label;
+		dolibarr_set_const($db, "MAIN_INFO_SOCIETE_COUNTRY", $s,'chaine',0,'',$conf->entity);
+	}
+
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM",$_POST["nom"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ADDRESS",$_POST["address"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_TOWN",$_POST["town"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ZIP",$_POST["zipcode"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE",$_POST["state_id"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_MONNAIE",$_POST["currency"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_TEL",$_POST["tel"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_FAX",$_POST["fax"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_MAIL",$_POST["mail"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_WEB",$_POST["web"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOTE",$_POST["note"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_GENCOD",$_POST["barcode"],'chaine',0,'',$conf->entity);
+	if ($_FILES["logo"]["tmp_name"])
+	{
+		if (preg_match('/([^\\/:]+)$/i',$_FILES["logo"]["name"],$reg))
+		{
+			$original_file=$reg[1];
+
+			$isimage=image_format_supported($original_file);
+			if ($isimage >= 0)
+			{
+				dol_syslog("Move file ".$_FILES["logo"]["tmp_name"]." to ".$conf->mycompany->dir_output.'/logos/'.$original_file);
+				if (! is_dir($conf->mycompany->dir_output.'/logos/'))
+				{
+					dol_mkdir($conf->mycompany->dir_output.'/logos/');
+				}
+				$result=dol_move_uploaded_file($_FILES["logo"]["tmp_name"],$conf->mycompany->dir_output.'/logos/'.$original_file,1,0,$_FILES['logo']['error']);
+				if ($result > 0)
+				{
+					dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO",$original_file,'chaine',0,'',$conf->entity);
+
+					// Create thumbs of logo (Note that PDF use original file and not thumbs)
+					if ($isimage > 0)
+					{
+						// Create small thumbs for company (Ratio is near 16/9)
+						// Used on logon for example
+						$imgThumbSmall = vignette($conf->mycompany->dir_output.'/logos/'.$original_file, $maxwidthsmall, $maxheightsmall, '_small', $quality);
+						if (preg_match('/([^\\/:]+)$/i',$imgThumbSmall,$reg))
+						{
+							$imgThumbSmall = $reg[1];
+							dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall,'chaine',0,'',$conf->entity);
+						}
+						else dol_syslog($imgThumbSmall);
+
+						// Create mini thumbs for company (Ratio is near 16/9)
+						// Used on menu or for setup page for example
+						$imgThumbMini = vignette($conf->mycompany->dir_output.'/logos/'.$original_file, $maxwidthmini, $maxheightmini, '_mini', $quality);
+						if (preg_match('/([^\\/:]+)$/i',$imgThumbMini,$reg))
+						{
+							$imgThumbMini = $reg[1];
+							dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini,'chaine',0,'',$conf->entity);
+						}
+						else dol_syslog($imgThumbMini);
+					}
+					else dol_syslog("ErrorImageFormatNotSupported",LOG_WARNING);
+				}
+				else if (preg_match('/^ErrorFileIsInfectedWithAVirus/',$result))
+				{
+					$error++;
+					$langs->load("errors");
+					$tmparray=explode(':',$result);
+					setEventMessage($langs->trans('ErrorFileIsInfectedWithAVirus',$tmparray[1]),'errors');
+				}
+				else
+				{
+					$error++;
+					setEventMessage($langs->trans("ErrorFailedToSaveFile"),'errors');
+				}
+			}
+			else
 			{
-            	$error++;
+				$error++;
 				$langs->load("errors");
-            	setEventMessage($langs->trans("ErrorBadImageFormat"),'errors');
-            }
-        }
-    }
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_MANAGERS",$_POST["MAIN_INFO_SOCIETE_MANAGERS"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_CAPITAL",$_POST["capital"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SOCIETE_FORME_JURIDIQUE",$_POST["forme_juridique_code"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SIREN",$_POST["siren"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_SIRET",$_POST["siret"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_APE",$_POST["ape"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_RCS",$_POST["rcs"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_PROFID5",$_POST["MAIN_INFO_PROFID5"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "MAIN_INFO_PROFID6",$_POST["MAIN_INFO_PROFID6"],'chaine',0,'',$conf->entity);
-
-    dolibarr_set_const($db, "MAIN_INFO_TVAINTRA",$_POST["tva"],'chaine',0,'',$conf->entity);
+				setEventMessage($langs->trans("ErrorBadImageFormat"),'errors');
+			}
+		}
+	}
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_MANAGERS",$_POST["MAIN_INFO_SOCIETE_MANAGERS"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_CAPITAL",$_POST["capital"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_FORME_JURIDIQUE",$_POST["forme_juridique_code"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SIREN",$_POST["siren"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_SIRET",$_POST["siret"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_APE",$_POST["ape"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_RCS",$_POST["rcs"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_PROFID5",$_POST["MAIN_INFO_PROFID5"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "MAIN_INFO_PROFID6",$_POST["MAIN_INFO_PROFID6"],'chaine',0,'',$conf->entity);
+
+	dolibarr_set_const($db, "MAIN_INFO_TVAINTRA",$_POST["tva"],'chaine',0,'',$conf->entity);
 	dolibarr_set_const($db, "MAIN_INFO_SOCIETE_OBJECT",$_POST["object"],'chaine',0,'',$conf->entity);
 
-    dolibarr_set_const($db, "SOCIETE_FISCAL_MONTH_START",$_POST["fiscalmonthstart"],'chaine',0,'',$conf->entity);
-
-    dolibarr_set_const($db, "FACTURE_TVAOPTION",$_POST["optiontva"],'chaine',0,'',$conf->entity);
-
-    // Local taxes
-    dolibarr_set_const($db, "FACTURE_LOCAL_TAX1_OPTION",$_POST["optionlocaltax1"],'chaine',0,'',$conf->entity);
-    dolibarr_set_const($db, "FACTURE_LOCAL_TAX2_OPTION",$_POST["optionlocaltax2"],'chaine',0,'',$conf->entity);
-
-    if($_POST["optionlocaltax1"]=="localtax1on")
-    {
-    	if(!isset($_REQUEST['lt1']))
-    	{
-    		dolibarr_set_const($db, "MAIN_INFO_VALUE_LOCALTAX1", 0,'chaine',0,'',$conf->entity);
-    	}
-    	else
-    	{
-    		dolibarr_set_const($db, "MAIN_INFO_VALUE_LOCALTAX1", GETPOST('lt1'),'chaine',0,'',$conf->entity);
-    	}
-    	dolibarr_set_const($db,"MAIN_INFO_LOCALTAX_CALC1", $_POST["clt1"],'chaine',0,'',$conf->entity);
-    }
-    if($_POST["optionlocaltax2"]=="localtax2on")
-    {
-    	if(!isset($_REQUEST['lt2']))
-    	{
-    		dolibarr_set_const($db, "MAIN_INFO_VALUE_LOCALTAX2", 0,'chaine',0,'',$conf->entity);
-    	}
-    	else
-    	{
-    		dolibarr_set_const($db, "MAIN_INFO_VALUE_LOCALTAX2", GETPOST('lt2'),'chaine',0,'',$conf->entity);
-    	}
-    	dolibarr_set_const($db,"MAIN_INFO_LOCALTAX_CALC2", $_POST["clt2"],'chaine',0,'',$conf->entity);
-    }
-
-    if ($action != 'updateedit' && ! $error)
-    {
-        header("Location: ".$_SERVER["PHP_SELF"]);
-        exit;
-    }
+	dolibarr_set_const($db, "SOCIETE_FISCAL_MONTH_START",$_POST["fiscalmonthstart"],'chaine',0,'',$conf->entity);
+
+	dolibarr_set_const($db, "FACTURE_TVAOPTION",$_POST["optiontva"],'chaine',0,'',$conf->entity);
+
+	// Local taxes
+	dolibarr_set_const($db, "FACTURE_LOCAL_TAX1_OPTION",$_POST["optionlocaltax1"],'chaine',0,'',$conf->entity);
+	dolibarr_set_const($db, "FACTURE_LOCAL_TAX2_OPTION",$_POST["optionlocaltax2"],'chaine',0,'',$conf->entity);
+
+	if($_POST["optionlocaltax1"]=="localtax1on")
+	{
+		if(!isset($_REQUEST['lt1']))
+		{
+			dolibarr_set_const($db, "MAIN_INFO_VALUE_LOCALTAX1", 0,'chaine',0,'',$conf->entity);
+		}
+		else
+		{
+			dolibarr_set_const($db, "MAIN_INFO_VALUE_LOCALTAX1", GETPOST('lt1'),'chaine',0,'',$conf->entity);
+		}
+		dolibarr_set_const($db,"MAIN_INFO_LOCALTAX_CALC1", $_POST["clt1"],'chaine',0,'',$conf->entity);
+	}
+	if($_POST["optionlocaltax2"]=="localtax2on")
+	{
+		if(!isset($_REQUEST['lt2']))
+		{
+			dolibarr_set_const($db, "MAIN_INFO_VALUE_LOCALTAX2", 0,'chaine',0,'',$conf->entity);
+		}
+		else
+		{
+			dolibarr_set_const($db, "MAIN_INFO_VALUE_LOCALTAX2", GETPOST('lt2'),'chaine',0,'',$conf->entity);
+		}
+		dolibarr_set_const($db,"MAIN_INFO_LOCALTAX_CALC2", $_POST["clt2"],'chaine',0,'',$conf->entity);
+	}
+
+	if ($action != 'updateedit' && ! $error)
+	{
+		header("Location: ".$_SERVER["PHP_SELF"]);
+		exit;
+	}
 }
 
 if ($action == 'addthumb')
 {
-    if (file_exists($conf->mycompany->dir_output.'/logos/'.$_GET["file"]))
-    {
-        $isimage=image_format_supported($_GET["file"]);
-
-        // Create thumbs of logo
-        if ($isimage > 0)
-        {
-            // Create small thumbs for company (Ratio is near 16/9)
-            // Used on logon for example
-            $imgThumbSmall = vignette($conf->mycompany->dir_output.'/logos/'.$_GET["file"], $maxwidthsmall, $maxheightsmall, '_small',$quality);
-            if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i',$imgThumbSmall,$reg))
-            {
-                $imgThumbSmall = $reg[1];
-                dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall,'chaine',0,'',$conf->entity);
-            }
-            else dol_syslog($imgThumbSmall);
-
-            // Create mini thumbs for company (Ratio is near 16/9)
-            // Used on menu or for setup page for example
-            $imgThumbMini = vignette($conf->mycompany->dir_output.'/logos/'.$_GET["file"], $maxwidthmini, $maxheightmini, '_mini',$quality);
-            if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i',$imgThumbMini,$reg))
-            {
-                $imgThumbMini = $reg[1];
-                dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini,'chaine',0,'',$conf->entity);
-            }
-            else dol_syslog($imgThumbMini);
-
-            header("Location: ".$_SERVER["PHP_SELF"]);
-            exit;
-        }
-        else
-        {
-        	$error++;
-        	$langs->load("errors");
-            setEventMessage($langs->trans("ErrorBadImageFormat"),'errors');
-            dol_syslog($langs->transnoentities("ErrorBadImageFormat"),LOG_WARNING);
-        }
-    }
-    else
-    {
-    	$error++;
-    	$langs->load("errors");
-        setEventMessage($langs->trans("ErrorFileDoesNotExists",$_GET["file"]),'errors');
-        dol_syslog($langs->transnoentities("ErrorFileDoesNotExists",$_GET["file"]),LOG_WARNING);
-    }
+	if (file_exists($conf->mycompany->dir_output.'/logos/'.$_GET["file"]))
+	{
+		$isimage=image_format_supported($_GET["file"]);
+
+		// Create thumbs of logo
+		if ($isimage > 0)
+		{
+			// Create small thumbs for company (Ratio is near 16/9)
+			// Used on logon for example
+			$imgThumbSmall = vignette($conf->mycompany->dir_output.'/logos/'.$_GET["file"], $maxwidthsmall, $maxheightsmall, '_small',$quality);
+			if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i',$imgThumbSmall,$reg))
+			{
+				$imgThumbSmall = $reg[1];
+				dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall,'chaine',0,'',$conf->entity);
+			}
+			else dol_syslog($imgThumbSmall);
+
+			// Create mini thumbs for company (Ratio is near 16/9)
+			// Used on menu or for setup page for example
+			$imgThumbMini = vignette($conf->mycompany->dir_output.'/logos/'.$_GET["file"], $maxwidthmini, $maxheightmini, '_mini',$quality);
+			if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i',$imgThumbMini,$reg))
+			{
+				$imgThumbMini = $reg[1];
+				dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini,'chaine',0,'',$conf->entity);
+			}
+			else dol_syslog($imgThumbMini);
+
+			header("Location: ".$_SERVER["PHP_SELF"]);
+			exit;
+		}
+		else
+		{
+			$error++;
+			$langs->load("errors");
+			setEventMessage($langs->trans("ErrorBadImageFormat"),'errors');
+			dol_syslog($langs->transnoentities("ErrorBadImageFormat"),LOG_WARNING);
+		}
+	}
+	else
+	{
+		$error++;
+		$langs->load("errors");
+		setEventMessage($langs->trans("ErrorFileDoesNotExists",$_GET["file"]),'errors');
+		dol_syslog($langs->transnoentities("ErrorFileDoesNotExists",$_GET["file"]),LOG_WARNING);
+	}
 }
 
 if ($action == 'removelogo')
 {
-    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
-    $logofile=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
-    dol_delete_file($logofile);
-    dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO",$conf->entity);
-    $mysoc->logo='';
-
-    $logosmallfile=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
-    dol_delete_file($logosmallfile);
-    dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$conf->entity);
-    $mysoc->logo_small='';
-
-    $logominifile=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini;
-    dol_delete_file($logominifile);
-    dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$conf->entity);
-    $mysoc->logo_mini='';
+	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+	$logofile=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
+	dol_delete_file($logofile);
+	dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO",$conf->entity);
+	$mysoc->logo='';
+
+	$logosmallfile=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
+	dol_delete_file($logosmallfile);
+	dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$conf->entity);
+	$mysoc->logo_small='';
+
+	$logominifile=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini;
+	dol_delete_file($logominifile);
+	dolibarr_del_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$conf->entity);
+	$mysoc->logo_mini='';
 }
 
 
@@ -284,829 +284,821 @@ print "<br>\n";
 
 if ($action == 'edit' || $action == 'updateedit')
 {
-    /**
-     * Edition des parametres
-     */
-    print "\n".'<script type="text/javascript" language="javascript">';
-    print '$(document).ready(function () {
-              $("#selectcountry_id").change(function() {
-                document.form_index.action.value="updateedit";
-                document.form_index.submit();
-              });
-          });';
-    print '</script>'."\n";
-
-    print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'" name="form_index">';
-    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-    print '<input type="hidden" name="action" value="update">';
-    $var=true;
-
-    print '<table class="noborder" width="100%">';
-    print '<tr class="liste_titre"><th width="35%">'.$langs->trans("CompanyInfo").'</th><th>'.$langs->trans("Value").'</th></tr>'."\n";
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td class="fieldrequired"><label for="name">'.$langs->trans("CompanyName").'</label></td><td>';
-    print '<input name="nom" id="name" size="30" value="'. ($conf->global->MAIN_INFO_SOCIETE_NOM?$conf->global->MAIN_INFO_SOCIETE_NOM:$_POST["nom"]) . '" autofocus="autofocus"></td></tr>'."\n";
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td><label for="address">'.$langs->trans("CompanyAddress").'</label></td><td>';
-    print '<textarea name="address" id="address" cols="80" rows="'.ROWS_3.'">'. ($conf->global->MAIN_INFO_SOCIETE_ADDRESS?$conf->global->MAIN_INFO_SOCIETE_ADDRESS:$_POST["address"]) . '</textarea></td></tr>'."\n";
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td><label for="zipcode">'.$langs->trans("CompanyZip").'</label></td><td>';
-    print '<input name="zipcode" id="zipcode" value="'. ($conf->global->MAIN_INFO_SOCIETE_ZIP?$conf->global->MAIN_INFO_SOCIETE_ZIP:$_POST["zipcode"]) . '" size="10"></td></tr>'."\n";
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td><label for="town">'.$langs->trans("CompanyTown").'</label></td><td>';
-    print '<input name="town" id="town" size="30" value="'. ($conf->global->MAIN_INFO_SOCIETE_TOWN?$conf->global->MAIN_INFO_SOCIETE_TOWN:$_POST["town"]) . '"></td></tr>'."\n";
-
-    // Country
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td class="fieldrequired"><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td class="maxwidthonsmartphone">';
-    //if (empty($country_selected)) $country_selected=substr($langs->defaultlang,-2);    // By default, country of localization
-    print $form->select_country($mysoc->country_id,'country_id');
-    if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
-    print '</td></tr>'."\n";
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td><label for="state_id">'.$langs->trans("State").'</label></td><td class="maxwidthonsmartphone">';
-    $formcompany->select_departement($conf->global->MAIN_INFO_SOCIETE_STATE,$mysoc->country_code,'state_id');
-    print '</td></tr>'."\n";
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td><label for="currency">'.$langs->trans("CompanyCurrency").'</label></td><td>';
-    print $form->selectCurrency($conf->currency,"currency");
-    print '</td></tr>'."\n";
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td><label for="phone">'.$langs->trans("Phone").'</label></td><td>';
-    print '<input name="tel" id="phone" value="'. $conf->global->MAIN_INFO_SOCIETE_TEL . '"></td></tr>';
-    print '</td></tr>'."\n";
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td><label for="fax">'.$langs->trans("Fax").'</label></td><td>';
-    print '<input name="fax" id="fax" value="'. $conf->global->MAIN_INFO_SOCIETE_FAX . '"></td></tr>';
-    print '</td></tr>'."\n";
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td><label for="email">'.$langs->trans("EMail").'</label></td><td>';
-    print '<input name="mail" id="email" size="60" value="'. $conf->global->MAIN_INFO_SOCIETE_MAIL . '"></td></tr>';
-    print '</td></tr>'."\n";
-
-    // Web
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td><label for="web">'.$langs->trans("Web").'</label></td><td>';
-    print '<input name="web" id="web" size="60" value="'. $conf->global->MAIN_INFO_SOCIETE_WEB . '"></td></tr>';
-    print '</td></tr>'."\n";
-
-    // Barcode
-    if (! empty($conf->barcode->enabled))
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td><label for="barcode">'.$langs->trans("Gencod").'</label></td><td>';
-        print '<input name="barcode" id="barcode" size="40" value="'. $conf->global->MAIN_INFO_SOCIETE_GENCOD . '"></td></tr>';
-        print '</td></tr>';
-    }
-
-    // Logo
-    $var=!$var;
-    print '<tr'.dol_bc($var,'hideonsmartphone').'><td><label for="logo">'.$langs->trans("Logo").' (png,jpg)</label></td><td>';
-    print '<table width="100%" class="nobordernopadding"><tr class="nocellnopadd"><td valign="middle" class="nocellnopadd">';
-    print '<input type="file" class="flat" name="logo" id="logo" size="50">';
-    print '</td><td class="nocellnopadd" valign="middle" align="right">';
-    if (! empty($mysoc->logo_mini))
-    {
-        print '<a href="'.$_SERVER["PHP_SELF"].'?action=removelogo">'.img_delete($langs->trans("Delete")).'</a>';
-        if (file_exists($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini))
-        {
-            print ' &nbsp; ';
-            print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&amp;file='.urlencode('/thumbs/'.$mysoc->logo_mini).'">';
-        }
-    }
-    else
-    {
-        print '<img height="30" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.jpg">';
-    }
-    print '</td></tr></table>';
-    print '</td></tr>';
-
-    // Note
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td valign="top"><label for="note">'.$langs->trans("Note").'</label></td><td>';
-    print '<textarea class="flat" name="note" id="note" cols="80" rows="'.ROWS_5.'">'.(! empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ? $conf->global->MAIN_INFO_SOCIETE_NOTE : '').'</textarea></td></tr>';
-    print '</td></tr>';
-
-    print '</table>';
-
-    print '<br>';
-
-    // Identifiants de la societe (country-specific)
-    print '<table class="noborder" width="100%">';
-    print '<tr class="liste_titre"><td>'.$langs->trans("CompanyIds").'</td><td>'.$langs->trans("Value").'</td></tr>';
-    $var=true;
-
-    $langs->load("companies");
-
-    // Managing Director(s)
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%"><label for="director">'.$langs->trans("ManagingDirectors").'</label></td><td>';
-    print '<input name="MAIN_INFO_SOCIETE_MANAGERS" id="director" size="80" value="' . $conf->global->MAIN_INFO_SOCIETE_MANAGERS . '"></td></tr>';
-
-    // Capital
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%"><label for="capital">'.$langs->trans("Capital").'</label></td><td>';
-    print '<input name="capital" id="capital" size="20" value="' . $conf->global->MAIN_INFO_CAPITAL . '"></td></tr>';
-
-    // Forme juridique
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td><label for="legal_form">'.$langs->trans("JuridicalStatus").'</label></td><td>';
-    if ($mysoc->country_code)
-    {
-        print $formcompany->select_juridicalstatus($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE, $mysoc->country_code, '', 'legal_form');
-    }
-    else
-    {
-        print $countrynotdefined;
-    }
-    print '</td></tr>';
-
-    // ProfID1
-    if ($langs->transcountry("ProfId1",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%"><label for="profid1">'.$langs->transcountry("ProfId1",$mysoc->country_code).'</label></td><td>';
-        if (! empty($mysoc->country_code))
-        {
-            print '<input name="siren" id="profid1" size="20" value="' . (! empty($conf->global->MAIN_INFO_SIREN) ? $conf->global->MAIN_INFO_SIREN : '') . '">';
-        }
-        else
-        {
-            print $countrynotdefined;
-        }
-        print '</td></tr>';
-    }
-
-    // ProfId2
-    if ($langs->transcountry("ProfId2",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%"><label for="profid2">'.$langs->transcountry("ProfId2",$mysoc->country_code).'</label></td><td>';
-        if (! empty($mysoc->country_code))
-        {
-            print '<input name="siret" id="profid2" size="20" value="' . (! empty($conf->global->MAIN_INFO_SIRET) ? $conf->global->MAIN_INFO_SIRET : '' ) . '">';
-        }
-        else
-        {
-            print $countrynotdefined;
-        }
-        print '</td></tr>';
-    }
-
-    // ProfId3
-    if ($langs->transcountry("ProfId3",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%"><label for="profid3">'.$langs->transcountry("ProfId3",$mysoc->country_code).'</label></td><td>';
-        if (! empty($mysoc->country_code))
-        {
-            print '<input name="ape" id="profid3" size="20" value="' . (! empty($conf->global->MAIN_INFO_APE) ? $conf->global->MAIN_INFO_APE : '') . '">';
-        }
-        else
-        {
-            print $countrynotdefined;
-        }
-        print '</td></tr>';
-    }
-
-    // ProfId4
-    if ($langs->transcountry("ProfId4",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%"><label for="profid4">'.$langs->transcountry("ProfId4",$mysoc->country_code).'</label></td><td>';
-        if (! empty($mysoc->country_code))
-        {
-            print '<input name="rcs" id="profid4" size="20" value="' . (! empty($conf->global->MAIN_INFO_RCS) ? $conf->global->MAIN_INFO_RCS : '') . '">';
-        }
-        else
-        {
-            print $countrynotdefined;
-        }
-        print '</td></tr>';
-    }
-
-    // ProfId5
-    if ($langs->transcountry("ProfId5",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%"><label for="profid5">'.$langs->transcountry("ProfId5",$mysoc->country_code).'</label></td><td>';
-        if (! empty($mysoc->country_code))
-        {
-            print '<input name="MAIN_INFO_PROFID5" id="profid5" size="20" value="' . (! empty($conf->global->MAIN_INFO_PROFID5) ? $conf->global->MAIN_INFO_PROFID5 : '') . '">';
-        }
-        else
-        {
-            print $countrynotdefined;
-        }
-        print '</td></tr>';
-    }
-
-    // ProfId6
-    if ($langs->transcountry("ProfId6",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%"><label for="profid6">'.$langs->transcountry("ProfId6",$mysoc->country_code).'</label></td><td>';
-        if (! empty($mysoc->country_code))
-        {
-            print '<input name="MAIN_INFO_PROFID6" id="profid6" size="20" value="' . (! empty($conf->global->MAIN_INFO_PROFID6) ? $conf->global->MAIN_INFO_PROFID6 : '') . '">';
-        }
-        else
-        {
-            print $countrynotdefined;
-        }
-        print '</td></tr>';
-    }
-
-    // TVA Intra
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%"><label for="intra_vat">'.$langs->trans("VATIntra").'</label></td><td>';
-    print '<input name="tva" id="intra_vat" size="20" value="' . (! empty($conf->global->MAIN_INFO_TVAINTRA) ? $conf->global->MAIN_INFO_TVAINTRA : '') . '">';
-    print '</td></tr>';
+	/**
+	 * Edition des parametres
+	 */
+	print "\n".'<script type="text/javascript" language="javascript">';
+	print '$(document).ready(function () {
+			  $("#selectcountry_id").change(function() {
+				document.form_index.action.value="updateedit";
+				document.form_index.submit();
+			  });
+		  });';
+	print '</script>'."\n";
+
+	print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'" name="form_index">';
+	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+	print '<input type="hidden" name="action" value="update">';
+	$var=true;
+
+	print '<table class="noborder" width="100%">';
+	print '<tr class="liste_titre"><th width="35%">'.$langs->trans("CompanyInfo").'</th><th>'.$langs->trans("Value").'</th></tr>'."\n";
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td class="fieldrequired"><label for="name">'.$langs->trans("CompanyName").'</label></td><td>';
+	print '<input name="nom" id="name" size="30" value="'. ($conf->global->MAIN_INFO_SOCIETE_NOM?$conf->global->MAIN_INFO_SOCIETE_NOM:$_POST["nom"]) . '" autofocus="autofocus"></td></tr>'."\n";
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td><label for="address">'.$langs->trans("CompanyAddress").'</label></td><td>';
+	print '<textarea name="address" id="address" cols="80" rows="'.ROWS_3.'">'. ($conf->global->MAIN_INFO_SOCIETE_ADDRESS?$conf->global->MAIN_INFO_SOCIETE_ADDRESS:$_POST["address"]) . '</textarea></td></tr>'."\n";
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td><label for="zipcode">'.$langs->trans("CompanyZip").'</label></td><td>';
+	print '<input name="zipcode" id="zipcode" value="'. ($conf->global->MAIN_INFO_SOCIETE_ZIP?$conf->global->MAIN_INFO_SOCIETE_ZIP:$_POST["zipcode"]) . '" size="10"></td></tr>'."\n";
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td><label for="town">'.$langs->trans("CompanyTown").'</label></td><td>';
+	print '<input name="town" id="town" size="30" value="'. ($conf->global->MAIN_INFO_SOCIETE_TOWN?$conf->global->MAIN_INFO_SOCIETE_TOWN:$_POST["town"]) . '"></td></tr>'."\n";
+
+	// Country
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td class="fieldrequired"><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td class="maxwidthonsmartphone">';
+	//if (empty($country_selected)) $country_selected=substr($langs->defaultlang,-2);    // By default, country of localization
+	print $form->select_country($mysoc->country_id,'country_id');
+	if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
+	print '</td></tr>'."\n";
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td><label for="state_id">'.$langs->trans("State").'</label></td><td class="maxwidthonsmartphone">';
+	$formcompany->select_departement($conf->global->MAIN_INFO_SOCIETE_STATE,$mysoc->country_code,'state_id');
+	print '</td></tr>'."\n";
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td><label for="currency">'.$langs->trans("CompanyCurrency").'</label></td><td>';
+	print $form->selectCurrency($conf->currency,"currency");
+	print '</td></tr>'."\n";
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td><label for="phone">'.$langs->trans("Phone").'</label></td><td>';
+	print '<input name="tel" id="phone" value="'. $conf->global->MAIN_INFO_SOCIETE_TEL . '"></td></tr>';
+	print '</td></tr>'."\n";
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td><label for="fax">'.$langs->trans("Fax").'</label></td><td>';
+	print '<input name="fax" id="fax" value="'. $conf->global->MAIN_INFO_SOCIETE_FAX . '"></td></tr>';
+	print '</td></tr>'."\n";
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td><label for="email">'.$langs->trans("EMail").'</label></td><td>';
+	print '<input name="mail" id="email" size="60" value="'. $conf->global->MAIN_INFO_SOCIETE_MAIL . '"></td></tr>';
+	print '</td></tr>'."\n";
+
+	// Web
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td><label for="web">'.$langs->trans("Web").'</label></td><td>';
+	print '<input name="web" id="web" size="60" value="'. $conf->global->MAIN_INFO_SOCIETE_WEB . '"></td></tr>';
+	print '</td></tr>'."\n";
+
+	// Barcode
+	if (! empty($conf->barcode->enabled)) {
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td><label for="barcode">'.$langs->trans("Gencod").'</label></td><td>';
+		print '<input name="barcode" id="barcode" size="40" value="'. $conf->global->MAIN_INFO_SOCIETE_GENCOD . '"></td></tr>';
+		print '</td></tr>';
+	}
+
+	// Logo
+	$var=!$var;
+	print '<tr'.dol_bc($var,'hideonsmartphone').'><td><label for="logo">'.$langs->trans("Logo").' (png,jpg)</label></td><td>';
+	print '<table width="100%" class="nobordernopadding"><tr class="nocellnopadd"><td valign="middle" class="nocellnopadd">';
+	print '<input type="file" class="flat" name="logo" id="logo" size="50">';
+	print '</td><td class="nocellnopadd" valign="middle" align="right">';
+	if (! empty($mysoc->logo_mini)) {
+		print '<a href="'.$_SERVER["PHP_SELF"].'?action=removelogo">'.img_delete($langs->trans("Delete")).'</a>';
+		if (file_exists($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini)) {
+			print ' &nbsp; ';
+			print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&amp;file='.urlencode('/thumbs/'.$mysoc->logo_mini).'">';
+		}
+	} else {
+		print '<img height="30" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.jpg">';
+	}
+	print '</td></tr></table>';
+	print '</td></tr>';
+
+	// Note
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td valign="top"><label for="note">'.$langs->trans("Note").'</label></td><td>';
+	print '<textarea class="flat" name="note" id="note" cols="80" rows="'.ROWS_5.'">'.(! empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ? $conf->global->MAIN_INFO_SOCIETE_NOTE : '').'</textarea></td></tr>';
+	print '</td></tr>';
+
+	print '</table>';
+
+	print '<br>';
+
+	// Identifiants de la societe (country-specific)
+	print '<table class="noborder" width="100%">';
+	print '<tr class="liste_titre"><td>'.$langs->trans("CompanyIds").'</td><td>'.$langs->trans("Value").'</td></tr>';
+	$var=true;
+
+	$langs->load("companies");
+
+	// Managing Director(s)
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%"><label for="director">'.$langs->trans("ManagingDirectors").'</label></td><td>';
+	print '<input name="MAIN_INFO_SOCIETE_MANAGERS" id="director" size="80" value="' . $conf->global->MAIN_INFO_SOCIETE_MANAGERS . '"></td></tr>';
+
+	// Capital
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%"><label for="capital">'.$langs->trans("Capital").'</label></td><td>';
+	print '<input name="capital" id="capital" size="20" value="' . $conf->global->MAIN_INFO_CAPITAL . '"></td></tr>';
+
+	// Forme juridique
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td><label for="legal_form">'.$langs->trans("JuridicalStatus").'</label></td><td>';
+	if ($mysoc->country_code) {
+		print $formcompany->select_juridicalstatus($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE, $mysoc->country_code, '', 'legal_form');
+	} else {
+		print $countrynotdefined;
+	}
+	print '</td></tr>';
+
+	// ProfID1
+	if ($langs->transcountry("ProfId1",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%"><label for="profid1">'.$langs->transcountry("ProfId1",$mysoc->country_code).'</label></td><td>';
+		if (! empty($mysoc->country_code))
+		{
+			print '<input name="siren" id="profid1" size="20" value="' . (! empty($conf->global->MAIN_INFO_SIREN) ? $conf->global->MAIN_INFO_SIREN : '') . '">';
+		}
+		else
+		{
+			print $countrynotdefined;
+		}
+		print '</td></tr>';
+	}
+
+	// ProfId2
+	if ($langs->transcountry("ProfId2",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%"><label for="profid2">'.$langs->transcountry("ProfId2",$mysoc->country_code).'</label></td><td>';
+		if (! empty($mysoc->country_code))
+		{
+			print '<input name="siret" id="profid2" size="20" value="' . (! empty($conf->global->MAIN_INFO_SIRET) ? $conf->global->MAIN_INFO_SIRET : '' ) . '">';
+		}
+		else
+		{
+			print $countrynotdefined;
+		}
+		print '</td></tr>';
+	}
+
+	// ProfId3
+	if ($langs->transcountry("ProfId3",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%"><label for="profid3">'.$langs->transcountry("ProfId3",$mysoc->country_code).'</label></td><td>';
+		if (! empty($mysoc->country_code))
+		{
+			print '<input name="ape" id="profid3" size="20" value="' . (! empty($conf->global->MAIN_INFO_APE) ? $conf->global->MAIN_INFO_APE : '') . '">';
+		}
+		else
+		{
+			print $countrynotdefined;
+		}
+		print '</td></tr>';
+	}
+
+	// ProfId4
+	if ($langs->transcountry("ProfId4",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%"><label for="profid4">'.$langs->transcountry("ProfId4",$mysoc->country_code).'</label></td><td>';
+		if (! empty($mysoc->country_code))
+		{
+			print '<input name="rcs" id="profid4" size="20" value="' . (! empty($conf->global->MAIN_INFO_RCS) ? $conf->global->MAIN_INFO_RCS : '') . '">';
+		}
+		else
+		{
+			print $countrynotdefined;
+		}
+		print '</td></tr>';
+	}
+
+	// ProfId5
+	if ($langs->transcountry("ProfId5",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%"><label for="profid5">'.$langs->transcountry("ProfId5",$mysoc->country_code).'</label></td><td>';
+		if (! empty($mysoc->country_code))
+		{
+			print '<input name="MAIN_INFO_PROFID5" id="profid5" size="20" value="' . (! empty($conf->global->MAIN_INFO_PROFID5) ? $conf->global->MAIN_INFO_PROFID5 : '') . '">';
+		}
+		else
+		{
+			print $countrynotdefined;
+		}
+		print '</td></tr>';
+	}
+
+	// ProfId6
+	if ($langs->transcountry("ProfId6",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%"><label for="profid6">'.$langs->transcountry("ProfId6",$mysoc->country_code).'</label></td><td>';
+		if (! empty($mysoc->country_code))
+		{
+			print '<input name="MAIN_INFO_PROFID6" id="profid6" size="20" value="' . (! empty($conf->global->MAIN_INFO_PROFID6) ? $conf->global->MAIN_INFO_PROFID6 : '') . '">';
+		}
+		else
+		{
+			print $countrynotdefined;
+		}
+		print '</td></tr>';
+	}
+
+	// TVA Intra
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%"><label for="intra_vat">'.$langs->trans("VATIntra").'</label></td><td>';
+	print '<input name="tva" id="intra_vat" size="20" value="' . (! empty($conf->global->MAIN_INFO_TVAINTRA) ? $conf->global->MAIN_INFO_TVAINTRA : '') . '">';
+	print '</td></tr>';
 	
 	// Object of the company
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%"><label for="object">'.$langs->trans("CompanyObject").'</label></td><td>';
-    print '<textarea class="flat" name="object" id="object" cols="80" rows="'.ROWS_5.'">'.(! empty($conf->global->MAIN_INFO_SOCIETE_OBJECT) ? $conf->global->MAIN_INFO_SOCIETE_OBJECT : '').'</textarea></td></tr>';
-    print '</td></tr>';
-
-    print '</table>';
-
-
-    // Fiscal year start
-    print '<br>';
-    print '<table class="noborder" width="100%">';
-    print '<tr class="liste_titre">';
-    print '<td>'.$langs->trans("FiscalYearInformation").'</td><td>'.$langs->trans("Value").'</td>';
-    print "</tr>\n";
-    $var=true;
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%"><label for="fiscalmonthstart">'.$langs->trans("FiscalMonthStart").'</label></td><td>';
-    print $formother->select_month($conf->global->SOCIETE_FISCAL_MONTH_START,'fiscalmonthstart',0,1) . '</td></tr>';
-
-    print "</table>";
-
-
-    // Fiscal options
-    print '<br>';
-    print '<table class="noborder" width="100%">';
-    print '<tr class="liste_titre">';
-    print '<td>'.$langs->trans("VATManagement").'</td><td>'.$langs->trans("Description").'</td>';
-    print '<td align="right">&nbsp;</td>';
-    print "</tr>\n";
-    $var=true;
-
-    $var=!$var;
-    print "<tr ".$bc[$var]."><td width=\"140\"><label><input type=\"radio\" name=\"optiontva\" id=\"use_vat\" value=\"1\"".(empty($conf->global->FACTURE_TVAOPTION)?"":" checked")."> ".$langs->trans("VATIsUsed")."</label></td>";
-    print '<td colspan="2">';
-    print "<table>";
-    print "<tr><td><label for=\"use_vat\">".$langs->trans("VATIsUsedDesc")."</label></td></tr>";
-    print "<tr><td><i>".$langs->trans("Example").': '.$langs->trans("VATIsUsedExampleFR")."</i></td></tr>\n";
-    print "</table>";
-    print "</td></tr>\n";
-
-    $var=!$var;
-    print "<tr ".$bc[$var]."><td width=\"140\"><label><input type=\"radio\" name=\"optiontva\" id=\"no_vat\" value=\"0\"".(empty($conf->global->FACTURE_TVAOPTION)?" checked":"")."> ".$langs->trans("VATIsNotUsed")."</label></td>";
-    print '<td colspan="2">';
-    print "<table>";
-    print "<tr><td><label for=\"no_vat\">".$langs->trans("VATIsNotUsedDesc")."</label></td></tr>";
-    print "<tr><td><i>".$langs->trans("Example").': '.$langs->trans("VATIsNotUsedExampleFR")."</i></td></tr>\n";
-    print "</table>";
-    print "</td></tr>\n";
-
-    print "</table>";
-
-    /*
-     *  Local Taxes
-     */
-    if ($mysoc->useLocalTax(1))
-    {
-        // Local Tax 1
-        print '<br>';
-        print '<table class="noborder" width="100%">';
-        print '<tr class="liste_titre">';
-        print '<td>'.$langs->transcountry("LocalTax1Management",$mysoc->country_code).'</td><td>'.$langs->trans("Description").'</td>';
-        print '<td align="right">&nbsp;</td>';
-        print "</tr>\n";
-        $var=true;
-        $var=!$var;
-        // Note: When option is not set, it must not appears as set on on, because there is no default value for this option
-        print "<tr ".$bc[$var]."><td width=\"140\"><input type=\"radio\" name=\"optionlocaltax1\" id=\"lt1\" value=\"localtax1on\"".(($conf->global->FACTURE_LOCAL_TAX1_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION == "localtax1on")?" checked":"")."> ".$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code)."</td>";
-        print '<td colspan="2">';
-        print "<table>";
-        print "<tr><td><label for=\"lt1\">".$langs->transcountry("LocalTax1IsUsedDesc",$mysoc->country_code)."</label></td></tr>";
-        $example=$langs->transcountry("LocalTax1IsUsedExample",$mysoc->country_code);
-        print ($example!="LocalTax1IsUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax1IsUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
-        if(! isOnlyOneLocalTax(1))
-        {
-	        print '<tr><td align="left"><label for="lt1">'.$langs->trans("LTRate").'</label>: ';
-    	    $formcompany->select_localtax(1,$conf->global->MAIN_INFO_VALUE_LOCALTAX1, "lt1");
-        }
-        print '</td></tr>';
-
-        $opcions=array($langs->trans("CalcLocaltax1").' '.$langs->trans("CalcLocaltax1Desc"),$langs->trans("CalcLocaltax2").' - '.$langs->trans("CalcLocaltax2Desc"),$langs->trans("CalcLocaltax3").' - '.$langs->trans("CalcLocaltax3Desc"));
-
-        print '<tr><td align="left"></label for="clt1">'.$langs->trans("CalcLocaltax").'</label>: ';
-        print $form->selectarray("clt1", $opcions, $conf->global->MAIN_INFO_LOCALTAX_CALC1);
-        print '</td></tr>';
-        print "</table>";
-        print "</td></tr>\n";
-
-        $var=!$var;
-        print "<tr ".$bc[$var]."><td width=\"140\"><input type=\"radio\" name=\"optionlocaltax1\" id=\"nolt1\" value=\"localtax1off\"".($conf->global->FACTURE_LOCAL_TAX1_OPTION == "localtax1off"?" checked":"")."> ".$langs->transcountry("LocalTax1IsNotUsed",$mysoc->country_code)."</td>";
-        print '<td colspan="2">';
-        print "<table>";
-        print "<tr><td><label for=\"nolt1\">".$langs->transcountry("LocalTax1IsNotUsedDesc",$mysoc->country_code)."</label></td></tr>";
-        $example=$langs->transcountry("LocalTax1IsNotUsedExample",$mysoc->country_code);
-        print ($example!="LocalTax1IsNotUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax1IsNotUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
-        print "</table>";
-        print "</td></tr>\n";
-        print "</table>";
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%"><label for="object">'.$langs->trans("CompanyObject").'</label></td><td>';
+	print '<textarea class="flat" name="object" id="object" cols="80" rows="'.ROWS_5.'">'.(! empty($conf->global->MAIN_INFO_SOCIETE_OBJECT) ? $conf->global->MAIN_INFO_SOCIETE_OBJECT : '').'</textarea></td></tr>';
+	print '</td></tr>';
+
+	print '</table>';
+
+
+	// Fiscal year start
+	print '<br>';
+	print '<table class="noborder" width="100%">';
+	print '<tr class="liste_titre">';
+	print '<td>'.$langs->trans("FiscalYearInformation").'</td><td>'.$langs->trans("Value").'</td>';
+	print "</tr>\n";
+	$var=true;
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%"><label for="fiscalmonthstart">'.$langs->trans("FiscalMonthStart").'</label></td><td>';
+	print $formother->select_month($conf->global->SOCIETE_FISCAL_MONTH_START,'fiscalmonthstart',0,1) . '</td></tr>';
+
+	print "</table>";
+
+
+	// Fiscal options
+	print '<br>';
+	print '<table class="noborder" width="100%">';
+	print '<tr class="liste_titre">';
+	print '<td>'.$langs->trans("VATManagement").'</td><td>'.$langs->trans("Description").'</td>';
+	print '<td align="right">&nbsp;</td>';
+	print "</tr>\n";
+	$var=true;
+
+	$var=!$var;
+	print "<tr ".$bc[$var]."><td width=\"140\"><label><input type=\"radio\" name=\"optiontva\" id=\"use_vat\" value=\"1\"".(empty($conf->global->FACTURE_TVAOPTION)?"":" checked")."> ".$langs->trans("VATIsUsed")."</label></td>";
+	print '<td colspan="2">';
+	print "<table>";
+	print "<tr><td><label for=\"use_vat\">".$langs->trans("VATIsUsedDesc")."</label></td></tr>";
+	print "<tr><td><i>".$langs->trans("Example").': '.$langs->trans("VATIsUsedExampleFR")."</i></td></tr>\n";
+	print "</table>";
+	print "</td></tr>\n";
+
+	$var=!$var;
+	print "<tr ".$bc[$var]."><td width=\"140\"><label><input type=\"radio\" name=\"optiontva\" id=\"no_vat\" value=\"0\"".(empty($conf->global->FACTURE_TVAOPTION)?" checked":"")."> ".$langs->trans("VATIsNotUsed")."</label></td>";
+	print '<td colspan="2">';
+	print "<table>";
+	print "<tr><td><label for=\"no_vat\">".$langs->trans("VATIsNotUsedDesc")."</label></td></tr>";
+	print "<tr><td><i>".$langs->trans("Example").': '.$langs->trans("VATIsNotUsedExampleFR")."</i></td></tr>\n";
+	print "</table>";
+	print "</td></tr>\n";
+
+	print "</table>";
+
+	/*
+	 *  Local Taxes
+	 */
+	if ($mysoc->useLocalTax(1))
+	{
+		// Local Tax 1
+		print '<br>';
+		print '<table class="noborder" width="100%">';
+		print '<tr class="liste_titre">';
+		print '<td>'.$langs->transcountry("LocalTax1Management",$mysoc->country_code).'</td><td>'.$langs->trans("Description").'</td>';
+		print '<td align="right">&nbsp;</td>';
+		print "</tr>\n";
+		$var=true;
+		$var=!$var;
+		// Note: When option is not set, it must not appears as set on on, because there is no default value for this option
+		print "<tr ".$bc[$var]."><td width=\"140\"><input type=\"radio\" name=\"optionlocaltax1\" id=\"lt1\" value=\"localtax1on\"".(($conf->global->FACTURE_LOCAL_TAX1_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION == "localtax1on")?" checked":"")."> ".$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code)."</td>";
+		print '<td colspan="2">';
+		print "<table>";
+		print "<tr><td><label for=\"lt1\">".$langs->transcountry("LocalTax1IsUsedDesc",$mysoc->country_code)."</label></td></tr>";
+		$example=$langs->transcountry("LocalTax1IsUsedExample",$mysoc->country_code);
+		print ($example!="LocalTax1IsUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax1IsUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
+		if(! isOnlyOneLocalTax(1))
+		{
+			print '<tr><td align="left"><label for="lt1">'.$langs->trans("LTRate").'</label>: ';
+			$formcompany->select_localtax(1,$conf->global->MAIN_INFO_VALUE_LOCALTAX1, "lt1");
+		}
+		print '</td></tr>';
+
+		$opcions=array($langs->trans("CalcLocaltax1").' '.$langs->trans("CalcLocaltax1Desc"),$langs->trans("CalcLocaltax2").' - '.$langs->trans("CalcLocaltax2Desc"),$langs->trans("CalcLocaltax3").' - '.$langs->trans("CalcLocaltax3Desc"));
+
+		print '<tr><td align="left"></label for="clt1">'.$langs->trans("CalcLocaltax").'</label>: ';
+		print $form->selectarray("clt1", $opcions, $conf->global->MAIN_INFO_LOCALTAX_CALC1);
+		print '</td></tr>';
+		print "</table>";
+		print "</td></tr>\n";
+
+		$var=!$var;
+		print "<tr ".$bc[$var]."><td width=\"140\"><input type=\"radio\" name=\"optionlocaltax1\" id=\"nolt1\" value=\"localtax1off\"".($conf->global->FACTURE_LOCAL_TAX1_OPTION == "localtax1off"?" checked":"")."> ".$langs->transcountry("LocalTax1IsNotUsed",$mysoc->country_code)."</td>";
+		print '<td colspan="2">';
+		print "<table>";
+		print "<tr><td><label for=\"nolt1\">".$langs->transcountry("LocalTax1IsNotUsedDesc",$mysoc->country_code)."</label></td></tr>";
+		$example=$langs->transcountry("LocalTax1IsNotUsedExample",$mysoc->country_code);
+		print ($example!="LocalTax1IsNotUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax1IsNotUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
+		print "</table>";
+		print "</td></tr>\n";
+		print "</table>";
+	}
+	if ($mysoc->useLocalTax(2))
+	{
+		// Local Tax 2
+		print '<br>';
+		print '<table class="noborder" width="100%">';
+		print '<tr class="liste_titre">';
+		print '<td>'.$langs->transcountry("LocalTax2Management",$mysoc->country_code).'</td><td>'.$langs->trans("Description").'</td>';
+		print '<td align="right">&nbsp;</td>';
+		print "</tr>\n";
+		$var=true;
+
+		$var=!$var;
+		// Note: When option is not set, it must not appears as set on on, because there is no default value for this option
+		print "<tr ".$bc[$var]."><td width=\"140\"><input type=\"radio\" name=\"optionlocaltax2\" id=\"lt2\" value=\"localtax2on\"".(($conf->global->FACTURE_LOCAL_TAX2_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION == "localtax2on")?" checked":"")."> ".$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code)."</td>";
+		print '<td colspan="2">';
+		print "<table>";
+		print "<tr><td><label for=\"lt2\">".$langs->transcountry("LocalTax2IsUsedDesc",$mysoc->country_code)."</label></td></tr>";
+		$example=$langs->transcountry("LocalTax2IsUsedExample",$mysoc->country_code);
+		print ($example!="LocalTax2IsUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax2IsUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
+		print '<tr><td align="left"><label for="lt2">'.$langs->trans("LTRate").'</label>: ';
+		if(! isOnlyOneLocalTax(2))
+		{
+			$formcompany->select_localtax(2,$conf->global->MAIN_INFO_VALUE_LOCALTAX2, "lt2");
+			print '</td></tr>';
+		}
+		print '<tr><td align="left"><label for="clt2">'.$langs->trans("CalcLocaltax").'</label>: ';
+		print $form->selectarray("clt2", $opcions, $conf->global->MAIN_INFO_LOCALTAX_CALC2);
+		print '</td></tr>';
+		print "</table>";
+		print "</td></tr>\n";
+
+		$var=!$var;
+		print "<tr ".$bc[$var]."><td width=\"140\"><input type=\"radio\" name=\"optionlocaltax2\" id=\"nolt2\" value=\"localtax2off\"".($conf->global->FACTURE_LOCAL_TAX2_OPTION == "localtax2off"?" checked":"")."> ".$langs->transcountry("LocalTax2IsNotUsed",$mysoc->country_code)."</td>";
+		print '<td colspan="2">';
+		print "<table>";
+		print "<tr><td><label for=\"nolt2\">".$langs->transcountry("LocalTax2IsNotUsedDesc",$mysoc->country_code)."</label></td></tr>";
+		$example=$langs->transcountry("LocalTax2IsNotUsedExample",$mysoc->country_code);
+		print ($example!="LocalTax2IsNotUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax2IsNotUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
+		print "</table>";
+		print "</td></tr>\n";
+		print "</table>";
 	}
-    if ($mysoc->useLocalTax(2))
-    {
-        // Local Tax 2
-        print '<br>';
-        print '<table class="noborder" width="100%">';
-        print '<tr class="liste_titre">';
-        print '<td>'.$langs->transcountry("LocalTax2Management",$mysoc->country_code).'</td><td>'.$langs->trans("Description").'</td>';
-        print '<td align="right">&nbsp;</td>';
-        print "</tr>\n";
-        $var=true;
-
-        $var=!$var;
-        // Note: When option is not set, it must not appears as set on on, because there is no default value for this option
-        print "<tr ".$bc[$var]."><td width=\"140\"><input type=\"radio\" name=\"optionlocaltax2\" id=\"lt2\" value=\"localtax2on\"".(($conf->global->FACTURE_LOCAL_TAX2_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION == "localtax2on")?" checked":"")."> ".$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code)."</td>";
-        print '<td colspan="2">';
-        print "<table>";
-        print "<tr><td><label for=\"lt2\">".$langs->transcountry("LocalTax2IsUsedDesc",$mysoc->country_code)."</label></td></tr>";
-        $example=$langs->transcountry("LocalTax2IsUsedExample",$mysoc->country_code);
-        print ($example!="LocalTax2IsUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax2IsUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
-        print '<tr><td align="left"><label for="lt2">'.$langs->trans("LTRate").'</label>: ';
-        if(! isOnlyOneLocalTax(2))
-        {
-	        $formcompany->select_localtax(2,$conf->global->MAIN_INFO_VALUE_LOCALTAX2, "lt2");
-	        print '</td></tr>';
-        }
-        print '<tr><td align="left"><label for="clt2">'.$langs->trans("CalcLocaltax").'</label>: ';
-        print $form->selectarray("clt2", $opcions, $conf->global->MAIN_INFO_LOCALTAX_CALC2);
-        print '</td></tr>';
-        print "</table>";
-        print "</td></tr>\n";
-
-        $var=!$var;
-        print "<tr ".$bc[$var]."><td width=\"140\"><input type=\"radio\" name=\"optionlocaltax2\" id=\"nolt2\" value=\"localtax2off\"".($conf->global->FACTURE_LOCAL_TAX2_OPTION == "localtax2off"?" checked":"")."> ".$langs->transcountry("LocalTax2IsNotUsed",$mysoc->country_code)."</td>";
-        print '<td colspan="2">';
-        print "<table>";
-        print "<tr><td><label for=\"nolt2\">".$langs->transcountry("LocalTax2IsNotUsedDesc",$mysoc->country_code)."</label></td></tr>";
-        $example=$langs->transcountry("LocalTax2IsNotUsedExample",$mysoc->country_code);
-        print ($example!="LocalTax2IsNotUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax2IsNotUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
-        print "</table>";
-        print "</td></tr>\n";
-        print "</table>";
-    }
-
-
-    print '<br><div class="center">';
-    print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
-    print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
-    print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
-    print '</div>';
-    print '<br>';
-
-    print '</form>';
+
+
+	print '<br><div class="center">';
+	print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
+	print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
+	print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
+	print '</div>';
+	print '<br>';
+
+	print '</form>';
 }
 else
 {
-    /*
-     * Show parameters
-     */
-
-    // Actions buttons
-    //print '<div class="tabsAction">';
-    //print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
-    //print '</div><br>';
-
-    print '<table class="noborder" width="100%">';
-    print '<tr class="liste_titre"><td>'.$langs->trans("CompanyInfo").'</td><td>'.$langs->trans("Value").'</td></tr>';
-    $var=true;
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("CompanyName").'</td><td>';
-    if (! empty($conf->global->MAIN_INFO_SOCIETE_NOM)) print $conf->global->MAIN_INFO_SOCIETE_NOM;
-    else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyName")).'</font>';
-    print '</td></tr>';
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("CompanyAddress").'</td><td>' . nl2br(empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS) . '</td></tr>';
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("CompanyZip").'</td><td>' . (empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP) . '</td></tr>';
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("CompanyTown").'</td><td>' . (empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN) . '</td></tr>';
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td>'.$langs->trans("CompanyCountry").'</td><td>';
-    if ($mysoc->country_code)
-    {
-        $img=picto_from_langcode($mysoc->country_code);
-        print $img?$img.' ':'';
-        print getCountry($mysoc->country_code,1);
-    }
-    else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
-    print '</td></tr>';
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td>'.$langs->trans("State").'</td><td>';
-    if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) print getState($conf->global->MAIN_INFO_SOCIETE_STATE);
-    else print '&nbsp;';
-    print '</td></tr>';
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("CompanyCurrency").'</td><td>';
-    print currency_name($conf->currency,1);
-    print ' ('.$langs->getCurrencySymbol($conf->currency).')';
-    print '</td></tr>';
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Phone").'</td><td>' . dol_print_phone($conf->global->MAIN_INFO_SOCIETE_TEL,$mysoc->country_code) . '</td></tr>';
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Fax").'</td><td>' . dol_print_phone($conf->global->MAIN_INFO_SOCIETE_FAX,$mysoc->country_code) . '</td></tr>';
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Mail").'</td><td>' . dol_print_email($conf->global->MAIN_INFO_SOCIETE_MAIL,0,0,0,80) . '</td></tr>';
-
-    // Web
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Web").'</td><td>' . dol_print_url($conf->global->MAIN_INFO_SOCIETE_WEB,'_blank',80) . '</td></tr>';
-
-    // Barcode
-    if (! empty($conf->barcode->enabled))
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Gencod").'</td><td>' . $conf->global->MAIN_INFO_SOCIETE_GENCOD . '</td></tr>';
-    }
-
-    // Logo
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Logo").'</td><td>';
-
-    print '<table width="100%" class="nobordernopadding"><tr class="nocellnopadd"><td valign="middle" class="nocellnopadd">';
-    print $mysoc->logo;
-    print '</td><td class="nocellnopadd" valign="center" align="right">';
-
-    // On propose la generation de la vignette si elle n'existe pas
-    if (!is_file($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini) && preg_match('/(\.jpg|\.jpeg|\.png)$/i',$mysoc->logo))
-    {
-        print '<a href="'.$_SERVER["PHP_SELF"].'?action=addthumb&amp;file='.urlencode($mysoc->logo).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').'&nbsp;&nbsp;</a>';
-    }
-    else if ($mysoc->logo_mini && is_file($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini))
-    {
-        print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&amp;file='.urlencode('/thumbs/'.$mysoc->logo_mini).'">';
-    }
-    else
-    {
-        print '<img height="30" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.jpg">';
-    }
-    print '</td></tr></table>';
-
-    print '</td></tr>';
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%" valign="top">'.$langs->trans("Note").'</td><td>' . (! empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ? nl2br($conf->global->MAIN_INFO_SOCIETE_NOTE) : '') . '</td></tr>';
-
-    print '</table>';
-
-
-    print '<br>';
-
-
-    // Identifiants de la societe (country-specific)
-    print '<form name="formsoc" method="post">';
-    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-    print '<table class="noborder" width="100%">';
-    print '<tr class="liste_titre"><td>'.$langs->trans("CompanyIds").'</td><td>'.$langs->trans("Value").'</td></tr>';
-    $var=true;
-
-    // Managing Director(s)
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("ManagingDirectors").'</td><td>';
-    print $conf->global->MAIN_INFO_SOCIETE_MANAGERS . '</td></tr>';
-
-    // Capital
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Capital").'</td><td>';
-    print $conf->global->MAIN_INFO_CAPITAL . '</td></tr>';
-
-    // Forme juridique
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("JuridicalStatus").'</td><td>';
-    print getFormeJuridiqueLabel($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE);
-    print '</td></tr>';
-
-    // ProfId1
-    if ($langs->transcountry("ProfId1",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId1",$mysoc->country_code).'</td><td>';
-        if (! empty($conf->global->MAIN_INFO_SIREN))
-        {
-            print $conf->global->MAIN_INFO_SIREN;
-            if ($mysoc->country_code == 'FR') print ' &nbsp; <a href="http://avis-situation-sirene.insee.fr/avisitu/jsp/avis.jsp" target="_blank">'.$langs->trans("Check").'</a>';
-        } else {
-        	print '&nbsp;';
-        }
-        print '</td></tr>';
-    }
-
-    // ProfId2
-    if ($langs->transcountry("ProfId2",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId2",$mysoc->country_code).'</td><td>';
-        if (! empty($conf->global->MAIN_INFO_SIRET))
-        {
-            print $conf->global->MAIN_INFO_SIRET;
-        } else {
-        	print '&nbsp;';
-        }
-        print '</td></tr>';
-    }
-
-    // ProfId3
-    if ($langs->transcountry("ProfId3",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId3",$mysoc->country_code).'</td><td>';
-        if (! empty($conf->global->MAIN_INFO_APE))
-        {
-            print $conf->global->MAIN_INFO_APE;
-        } else {
-        	print '&nbsp;';
-        }
-        print '</td></tr>';
-    }
-
-    // ProfId4
-    if ($langs->transcountry("ProfId4",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId4",$mysoc->country_code).'</td><td>';
-        if (! empty($conf->global->MAIN_INFO_RCS))
-        {
-            print $conf->global->MAIN_INFO_RCS;
-        } else {
-        	print '&nbsp;';
-        }
-        print '</td></tr>';
-    }
-
-    // ProfId5
-    if ($langs->transcountry("ProfId5",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId5",$mysoc->country_code).'</td><td>';
-        if (! empty($conf->global->MAIN_INFO_PROFID5))
-        {
-            print $conf->global->MAIN_INFO_PROFID5;
-        } else {
-        	print '&nbsp;';
-        }
-        print '</td></tr>';
-    }
-
-    // ProfId6
-    if ($langs->transcountry("ProfId6",$mysoc->country_code) != '-')
-    {
-        $var=!$var;
-        print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId6",$mysoc->country_code).'</td><td>';
-        if (! empty($conf->global->MAIN_INFO_PROFID6))
-        {
-            print $conf->global->MAIN_INFO_PROFID6;
-        } else {
-        	print '&nbsp;';
-        }
-        print '</td></tr>';
-    }
-
-    // TVA
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td>'.$langs->trans("VATIntra").'</td>';
-    print '<td>';
-    if (! empty($conf->global->MAIN_INFO_TVAINTRA))
-    {
-        $s='';
-        $s.=$conf->global->MAIN_INFO_TVAINTRA;
-        $s.='<input type="hidden" name="tva_intra" size="12" maxlength="20" value="'.$conf->global->MAIN_INFO_TVAINTRA.'">';
-        if (empty($conf->global->MAIN_DISABLEVATCHECK))
-        {
-            $s.=' &nbsp; ';
-            if (! empty($conf->use_javascript_ajax))
-            {
-                print "\n";
-                print '<script language="JavaScript" type="text/javascript">';
-                print "function CheckVAT(a) {\n";
-                print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,285);\n";
-                print "}\n";
-                print '</script>';
-                print "\n";
-                $s.='<a href="#" onClick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
-                $s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
-            }
-            else
-            {
-                $s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$soc->id_country).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
-            }
-        }
-        print $s;
-    }
-    else
-    {
-        print '&nbsp;';
-    }
-    print '</td>';
-    print '</tr>';
+	/*
+	 * Show parameters
+	 */
+
+	// Actions buttons
+	//print '<div class="tabsAction">';
+	//print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
+	//print '</div><br>';
+
+	print '<table class="noborder" width="100%">';
+	print '<tr class="liste_titre"><td>'.$langs->trans("CompanyInfo").'</td><td>'.$langs->trans("Value").'</td></tr>';
+	$var=true;
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("CompanyName").'</td><td>';
+	if (! empty($conf->global->MAIN_INFO_SOCIETE_NOM)) print $conf->global->MAIN_INFO_SOCIETE_NOM;
+	else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyName")).'</font>';
+	print '</td></tr>';
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("CompanyAddress").'</td><td>' . nl2br(empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS) . '</td></tr>';
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("CompanyZip").'</td><td>' . (empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP) . '</td></tr>';
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("CompanyTown").'</td><td>' . (empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN) . '</td></tr>';
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td>'.$langs->trans("CompanyCountry").'</td><td>';
+	if ($mysoc->country_code)
+	{
+		$img=picto_from_langcode($mysoc->country_code);
+		print $img?$img.' ':'';
+		print getCountry($mysoc->country_code,1);
+	}
+	else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
+	print '</td></tr>';
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td>'.$langs->trans("State").'</td><td>';
+	if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) print getState($conf->global->MAIN_INFO_SOCIETE_STATE);
+	else print '&nbsp;';
+	print '</td></tr>';
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("CompanyCurrency").'</td><td>';
+	print currency_name($conf->currency,1);
+	print ' ('.$langs->getCurrencySymbol($conf->currency).')';
+	print '</td></tr>';
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Phone").'</td><td>' . dol_print_phone($conf->global->MAIN_INFO_SOCIETE_TEL,$mysoc->country_code) . '</td></tr>';
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Fax").'</td><td>' . dol_print_phone($conf->global->MAIN_INFO_SOCIETE_FAX,$mysoc->country_code) . '</td></tr>';
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Mail").'</td><td>' . dol_print_email($conf->global->MAIN_INFO_SOCIETE_MAIL,0,0,0,80) . '</td></tr>';
+
+	// Web
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Web").'</td><td>' . dol_print_url($conf->global->MAIN_INFO_SOCIETE_WEB,'_blank',80) . '</td></tr>';
+
+	// Barcode
+	if (! empty($conf->barcode->enabled))
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Gencod").'</td><td>' . $conf->global->MAIN_INFO_SOCIETE_GENCOD . '</td></tr>';
+	}
+
+	// Logo
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Logo").'</td><td>';
+
+	print '<table width="100%" class="nobordernopadding"><tr class="nocellnopadd"><td valign="middle" class="nocellnopadd">';
+	print $mysoc->logo;
+	print '</td><td class="nocellnopadd" valign="center" align="right">';
+
+	// On propose la generation de la vignette si elle n'existe pas
+	if (!is_file($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini) && preg_match('/(\.jpg|\.jpeg|\.png)$/i',$mysoc->logo))
+	{
+		print '<a href="'.$_SERVER["PHP_SELF"].'?action=addthumb&amp;file='.urlencode($mysoc->logo).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').'&nbsp;&nbsp;</a>';
+	}
+	else if ($mysoc->logo_mini && is_file($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_mini))
+	{
+		print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=companylogo&amp;file='.urlencode('/thumbs/'.$mysoc->logo_mini).'">';
+	}
+	else
+	{
+		print '<img height="30" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.jpg">';
+	}
+	print '</td></tr></table>';
+
+	print '</td></tr>';
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%" valign="top">'.$langs->trans("Note").'</td><td>' . (! empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ? nl2br($conf->global->MAIN_INFO_SOCIETE_NOTE) : '') . '</td></tr>';
+
+	print '</table>';
+
+
+	print '<br>';
+
+
+	// Identifiants de la societe (country-specific)
+	print '<form name="formsoc" method="post">';
+	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+	print '<table class="noborder" width="100%">';
+	print '<tr class="liste_titre"><td>'.$langs->trans("CompanyIds").'</td><td>'.$langs->trans("Value").'</td></tr>';
+	$var=true;
+
+	// Managing Director(s)
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("ManagingDirectors").'</td><td>';
+	print $conf->global->MAIN_INFO_SOCIETE_MANAGERS . '</td></tr>';
+
+	// Capital
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("Capital").'</td><td>';
+	print $conf->global->MAIN_INFO_CAPITAL . '</td></tr>';
+
+	// Forme juridique
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("JuridicalStatus").'</td><td>';
+	print getFormeJuridiqueLabel($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE);
+	print '</td></tr>';
+
+	// ProfId1
+	if ($langs->transcountry("ProfId1",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId1",$mysoc->country_code).'</td><td>';
+		if (! empty($conf->global->MAIN_INFO_SIREN))
+		{
+			print $conf->global->MAIN_INFO_SIREN;
+			if ($mysoc->country_code == 'FR') print ' &nbsp; <a href="http://avis-situation-sirene.insee.fr/avisitu/jsp/avis.jsp" target="_blank">'.$langs->trans("Check").'</a>';
+		} else {
+			print '&nbsp;';
+		}
+		print '</td></tr>';
+	}
+
+	// ProfId2
+	if ($langs->transcountry("ProfId2",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId2",$mysoc->country_code).'</td><td>';
+		if (! empty($conf->global->MAIN_INFO_SIRET))
+		{
+			print $conf->global->MAIN_INFO_SIRET;
+		} else {
+			print '&nbsp;';
+		}
+		print '</td></tr>';
+	}
+
+	// ProfId3
+	if ($langs->transcountry("ProfId3",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId3",$mysoc->country_code).'</td><td>';
+		if (! empty($conf->global->MAIN_INFO_APE))
+		{
+			print $conf->global->MAIN_INFO_APE;
+		} else {
+			print '&nbsp;';
+		}
+		print '</td></tr>';
+	}
+
+	// ProfId4
+	if ($langs->transcountry("ProfId4",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId4",$mysoc->country_code).'</td><td>';
+		if (! empty($conf->global->MAIN_INFO_RCS))
+		{
+			print $conf->global->MAIN_INFO_RCS;
+		} else {
+			print '&nbsp;';
+		}
+		print '</td></tr>';
+	}
+
+	// ProfId5
+	if ($langs->transcountry("ProfId5",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId5",$mysoc->country_code).'</td><td>';
+		if (! empty($conf->global->MAIN_INFO_PROFID5))
+		{
+			print $conf->global->MAIN_INFO_PROFID5;
+		} else {
+			print '&nbsp;';
+		}
+		print '</td></tr>';
+	}
+
+	// ProfId6
+	if ($langs->transcountry("ProfId6",$mysoc->country_code) != '-')
+	{
+		$var=!$var;
+		print '<tr '.$bc[$var].'><td width="35%">'.$langs->transcountry("ProfId6",$mysoc->country_code).'</td><td>';
+		if (! empty($conf->global->MAIN_INFO_PROFID6))
+		{
+			print $conf->global->MAIN_INFO_PROFID6;
+		} else {
+			print '&nbsp;';
+		}
+		print '</td></tr>';
+	}
+
+	// TVA
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td>'.$langs->trans("VATIntra").'</td>';
+	print '<td>';
+	if (! empty($conf->global->MAIN_INFO_TVAINTRA))
+	{
+		$s='';
+		$s.=$conf->global->MAIN_INFO_TVAINTRA;
+		$s.='<input type="hidden" name="tva_intra" size="12" maxlength="20" value="'.$conf->global->MAIN_INFO_TVAINTRA.'">';
+		if (empty($conf->global->MAIN_DISABLEVATCHECK))
+		{
+			$s.=' &nbsp; ';
+			if (! empty($conf->use_javascript_ajax))
+			{
+				print "\n";
+				print '<script language="JavaScript" type="text/javascript">';
+				print "function CheckVAT(a) {\n";
+				print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,285);\n";
+				print "}\n";
+				print '</script>';
+				print "\n";
+				$s.='<a href="#" onClick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
+				$s = $form->textwithpicto($s,$langs->trans("VATIntraCheckDesc",$langs->trans("VATIntraCheck")),1);
+			}
+			else
+			{
+				$s.='<a href="'.$langs->transcountry("VATIntraCheckURL",$soc->id_country).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"),'help').'</a>';
+			}
+		}
+		print $s;
+	}
+	else
+	{
+		print '&nbsp;';
+	}
+	print '</td>';
+	print '</tr>';
 	
 	$var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%" valign="top">'.$langs->trans("CompanyObject").'</td><td>' . (! empty($conf->global->MAIN_INFO_SOCIETE_OBJECT) ? nl2br($conf->global->MAIN_INFO_SOCIETE_OBJECT) : '') . '</td></tr>';
-
-    print '</table>';
-    print '</form>';
-
-    /*
-     *  Debut d'annee fiscale
-     */
-    print '<br>';
-    print '<table class="noborder" width="100%">';
-    print '<tr class="liste_titre">';
-    print '<td>'.$langs->trans("FiscalYearInformation").'</td><td>'.$langs->trans("Value").'</td>';
-    print "</tr>\n";
-    $var=true;
-
-    $var=!$var;
-    print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("FiscalMonthStart").'</td><td>';
-    $monthstart=(! empty($conf->global->SOCIETE_FISCAL_MONTH_START)) ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1;
-    print dol_print_date(dol_mktime(12,0,0,$monthstart,1,2000,1),'%B','gm') . '</td></tr>';
-
-    print "</table>";
-
-    /*
-     *  Options fiscale
-     */
-    print '<br>';
-    print '<table class="noborder" width="100%">';
-    print '<tr class="liste_titre">';
-    print '<td>'.$langs->trans("VATManagement").'</td><td>'.$langs->trans("Description").'</td>';
-    print '<td align="right">&nbsp;</td>';
-    print "</tr>\n";
-    $var=true;
-
-    $var=!$var;
-    print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optiontva\" id=\"use_vat\" disabled value=\"1\"".(empty($conf->global->FACTURE_TVAOPTION)?"":" checked")."> ".$langs->trans("VATIsUsed")."</td>";
-    print '<td colspan="2">';
-    print "<table>";
-    print "<tr><td><label for=\"use_vat\">".$langs->trans("VATIsUsedDesc")."</label></td></tr>";
-    print "<tr><td><i>".$langs->trans("Example").': '.$langs->trans("VATIsUsedExampleFR")."</i></td></tr>\n";
-    print "</table>";
-    print "</td></tr>\n";
-
-    $var=!$var;
-    print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optiontva\" id=\"no_vat\" disabled value=\"0\"".(empty($conf->global->FACTURE_TVAOPTION)?" checked":"")."> ".$langs->trans("VATIsNotUsed")."</td>";
-    print '<td colspan="2">';
-    print "<table>";
-    print "<tr><td><label=\"no_vat\">".$langs->trans("VATIsNotUsedDesc")."</label></td></tr>";
-    print "<tr><td><i>".$langs->trans("Example").': '.$langs->trans("VATIsNotUsedExampleFR")."</i></td></tr>\n";
-    print "</table>";
-    print "</td></tr>\n";
-
-    print "</table>";
-
-
-    /*
-     *  Local Taxes
-     */
-    if ($mysoc->useLocalTax(1))
-    {
-        // Local Tax 1
-        print '<br>';
-        print '<table class="noborder" width="100%">';
-        print '<tr class="liste_titre">';
-        print '<td>'.$langs->transcountry("LocalTax1Management",$mysoc->country_code).'</td><td>'.$langs->trans("Description").'</td>';
-        print '<td align="right">&nbsp;</td>';
-        print "</tr>\n";
-        $var=true;
-
-        $var=!$var;
-        print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optionlocaltax1\" id=\"lt1\" disabled value=\"localtax1on\"".(($conf->global->FACTURE_LOCAL_TAX1_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION == "localtax1on")?" checked":"")."> ".$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code)."</td>";
-        print '<td colspan="2">';
-        print "<table>";
-        print "<tr><td></label for=\"lt1\">".$langs->transcountry("LocalTax1IsUsedDesc",$mysoc->country_code)."</label></td></tr>";
-        $example=$langs->transcountry("LocalTax1IsUsedExample",$mysoc->country_code);
-        print ($example!="LocalTax1IsUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax1IsUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
-        if($conf->global->MAIN_INFO_VALUE_LOCALTAX1!=0)
-        {
-	        print '<tr><td>'.$langs->trans("LTRate").': '. $conf->global->MAIN_INFO_VALUE_LOCALTAX1 .'</td></tr>';
-	    }
-        print '<tr><td align="left">'.$langs->trans("CalcLocaltax").': ';
-        if($conf->global->MAIN_INFO_LOCALTAX_CALC1==0)
-        {
-        	print $langs->transcountry("CalcLocaltax1",$mysoc->country_code);
-        }
-        else if($conf->global->MAIN_INFO_LOCALTAX_CALC1==1)
-        {
-        	print $langs->transcountry("CalcLocaltax2",$mysoc->country_code);
-        }
-        else if($conf->global->MAIN_INFO_LOCALTAX_CALC1==2){
-        	print $langs->transcountry("CalcLocaltax3",$mysoc->country_code);
-        }
-
-        print '</td></tr>';
-        print "</table>";
-        print "</td></tr>\n";
-
-        $var=!$var;
-        print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optionlocaltax1\" id=\"nolt1\" disabled value=\"localtax1off\"".($conf->global->FACTURE_LOCAL_TAX1_OPTION == "localtax1off"?" checked":"")."> ".$langs->transcountry("LocalTax1IsNotUsed",$mysoc->country_code)."</td>";
-        print '<td colspan="2">';
-        print "<table>";
-        print "<tr><td><label for=\"no_lt1\">".$langs->transcountry("LocalTax1IsNotUsedDesc",$mysoc->country_code)."</label></td></tr>";
-        $example=$langs->transcountry("LocalTax1IsNotUsedExample",$mysoc->country_code);
-        print ($example!="LocalTax1IsNotUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax1IsNotUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
-        print "</table>";
-        print "</td></tr>\n";
-
-        print "</table>";
+	print '<tr '.$bc[$var].'><td width="35%" valign="top">'.$langs->trans("CompanyObject").'</td><td>' . (! empty($conf->global->MAIN_INFO_SOCIETE_OBJECT) ? nl2br($conf->global->MAIN_INFO_SOCIETE_OBJECT) : '') . '</td></tr>';
+
+	print '</table>';
+	print '</form>';
+
+	/*
+	 *  Debut d'annee fiscale
+	 */
+	print '<br>';
+	print '<table class="noborder" width="100%">';
+	print '<tr class="liste_titre">';
+	print '<td>'.$langs->trans("FiscalYearInformation").'</td><td>'.$langs->trans("Value").'</td>';
+	print "</tr>\n";
+	$var=true;
+
+	$var=!$var;
+	print '<tr '.$bc[$var].'><td width="35%">'.$langs->trans("FiscalMonthStart").'</td><td>';
+	$monthstart=(! empty($conf->global->SOCIETE_FISCAL_MONTH_START)) ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1;
+	print dol_print_date(dol_mktime(12,0,0,$monthstart,1,2000,1),'%B','gm') . '</td></tr>';
+
+	print "</table>";
+
+	/*
+	 *  Options fiscale
+	 */
+	print '<br>';
+	print '<table class="noborder" width="100%">';
+	print '<tr class="liste_titre">';
+	print '<td>'.$langs->trans("VATManagement").'</td><td>'.$langs->trans("Description").'</td>';
+	print '<td align="right">&nbsp;</td>';
+	print "</tr>\n";
+	$var=true;
+
+	$var=!$var;
+	print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optiontva\" id=\"use_vat\" disabled value=\"1\"".(empty($conf->global->FACTURE_TVAOPTION)?"":" checked")."> ".$langs->trans("VATIsUsed")."</td>";
+	print '<td colspan="2">';
+	print "<table>";
+	print "<tr><td><label for=\"use_vat\">".$langs->trans("VATIsUsedDesc")."</label></td></tr>";
+	print "<tr><td><i>".$langs->trans("Example").': '.$langs->trans("VATIsUsedExampleFR")."</i></td></tr>\n";
+	print "</table>";
+	print "</td></tr>\n";
+
+	$var=!$var;
+	print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optiontva\" id=\"no_vat\" disabled value=\"0\"".(empty($conf->global->FACTURE_TVAOPTION)?" checked":"")."> ".$langs->trans("VATIsNotUsed")."</td>";
+	print '<td colspan="2">';
+	print "<table>";
+	print "<tr><td><label=\"no_vat\">".$langs->trans("VATIsNotUsedDesc")."</label></td></tr>";
+	print "<tr><td><i>".$langs->trans("Example").': '.$langs->trans("VATIsNotUsedExampleFR")."</i></td></tr>\n";
+	print "</table>";
+	print "</td></tr>\n";
+
+	print "</table>";
+
+
+	/*
+	 *  Local Taxes
+	 */
+	if ($mysoc->useLocalTax(1))
+	{
+		// Local Tax 1
+		print '<br>';
+		print '<table class="noborder" width="100%">';
+		print '<tr class="liste_titre">';
+		print '<td>'.$langs->transcountry("LocalTax1Management",$mysoc->country_code).'</td><td>'.$langs->trans("Description").'</td>';
+		print '<td align="right">&nbsp;</td>';
+		print "</tr>\n";
+		$var=true;
+
+		$var=!$var;
+		print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optionlocaltax1\" id=\"lt1\" disabled value=\"localtax1on\"".(($conf->global->FACTURE_LOCAL_TAX1_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION == "localtax1on")?" checked":"")."> ".$langs->transcountry("LocalTax1IsUsed",$mysoc->country_code)."</td>";
+		print '<td colspan="2">';
+		print "<table>";
+		print "<tr><td></label for=\"lt1\">".$langs->transcountry("LocalTax1IsUsedDesc",$mysoc->country_code)."</label></td></tr>";
+		$example=$langs->transcountry("LocalTax1IsUsedExample",$mysoc->country_code);
+		print ($example!="LocalTax1IsUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax1IsUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
+		if($conf->global->MAIN_INFO_VALUE_LOCALTAX1!=0)
+		{
+			print '<tr><td>'.$langs->trans("LTRate").': '. $conf->global->MAIN_INFO_VALUE_LOCALTAX1 .'</td></tr>';
+		}
+		print '<tr><td align="left">'.$langs->trans("CalcLocaltax").': ';
+		if($conf->global->MAIN_INFO_LOCALTAX_CALC1==0)
+		{
+			print $langs->transcountry("CalcLocaltax1",$mysoc->country_code);
+		}
+		else if($conf->global->MAIN_INFO_LOCALTAX_CALC1==1)
+		{
+			print $langs->transcountry("CalcLocaltax2",$mysoc->country_code);
+		}
+		else if($conf->global->MAIN_INFO_LOCALTAX_CALC1==2){
+			print $langs->transcountry("CalcLocaltax3",$mysoc->country_code);
+		}
+
+		print '</td></tr>';
+		print "</table>";
+		print "</td></tr>\n";
+
+		$var=!$var;
+		print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optionlocaltax1\" id=\"nolt1\" disabled value=\"localtax1off\"".($conf->global->FACTURE_LOCAL_TAX1_OPTION == "localtax1off"?" checked":"")."> ".$langs->transcountry("LocalTax1IsNotUsed",$mysoc->country_code)."</td>";
+		print '<td colspan="2">';
+		print "<table>";
+		print "<tr><td><label for=\"no_lt1\">".$langs->transcountry("LocalTax1IsNotUsedDesc",$mysoc->country_code)."</label></td></tr>";
+		$example=$langs->transcountry("LocalTax1IsNotUsedExample",$mysoc->country_code);
+		print ($example!="LocalTax1IsNotUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax1IsNotUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
+		print "</table>";
+		print "</td></tr>\n";
+
+		print "</table>";
+	}
+	if ($mysoc->useLocalTax(2))
+	{
+		// Local Tax 2
+		print '<br>';
+		print '<table class="noborder" width="100%">';
+		print '<tr class="liste_titre">';
+		print '<td>'.$langs->transcountry("LocalTax2Management",$mysoc->country_code).'</td><td>'.$langs->trans("Description").'</td>';
+		print '<td align="right">&nbsp;</td>';
+		print "</tr>\n";
+		$var=true;
+
+		$var=!$var;
+		print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optionlocaltax2\" id=\"lt2\" disabled value=\"localtax2on\"".(($conf->global->FACTURE_LOCAL_TAX2_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION == "localtax2on")?" checked":"")."> ".$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code)."</td>";
+		print '<td colspan="2">';
+		print "<table>";
+		print "<tr><td><label for=\"lt2\">".$langs->transcountry("LocalTax2IsUsedDesc",$mysoc->country_code)."</label></td></tr>";
+		$example=$langs->transcountry("LocalTax2IsUsedExample",$mysoc->country_code);
+		print ($example!="LocalTax2IsUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax2IsUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
+		if($conf->global->MAIN_INFO_VALUE_LOCALTAX2!=0)
+		{
+			print '<tr><td>'.$langs->trans("LTRate").': '. $conf->global->MAIN_INFO_VALUE_LOCALTAX2 .'</td></tr>';
+		}
+		print '<tr><td align="left">'.$langs->trans("CalcLocaltax").': ';
+		if($conf->global->MAIN_INFO_LOCALTAX_CALC2==0)
+		{
+			print $langs->trans("CalcLocaltax1").' - '.$langs->trans("CalcLocaltax1Desc");
+		}
+		else if($conf->global->MAIN_INFO_LOCALTAX_CALC2==1)
+		{
+			print $langs->trans("CalcLocaltax2").' - '.$langs->trans("CalcLocaltax2Desc");
+		}
+		else if($conf->global->MAIN_INFO_LOCALTAX_CALC2==2)
+		{
+			print $langs->trans("CalcLocaltax3").' - '.$langs->trans("CalcLocaltax3Desc");
+		}
+
+		print '</td></tr>';
+		print "</table>";
+		print "</td></tr>\n";
+
+		$var=!$var;
+		print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optionlocaltax2\" id=\"nolt2\" disabled value=\"localtax2off\"".($conf->global->FACTURE_LOCAL_TAX2_OPTION == "localtax2off"?" checked":"")."> ".$langs->transcountry("LocalTax2IsNotUsed",$mysoc->country_code)."</td>";
+		print '<td colspan="2">';
+		print "<table>";
+		print "<tr><td><label for=\"nolt2\">".$langs->transcountry("LocalTax2IsNotUsedDesc",$mysoc->country_code)."</label></td></tr>";
+		$example=$langs->transcountry("LocalTax2IsNotUsedExample",$mysoc->country_code);
+		print ($example!="LocalTax2IsNotUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax2IsNotUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
+		print "</table>";
+		print "</td></tr>\n";
+
+		print "</table>";
 	}
-    if ($mysoc->useLocalTax(2))
-    {
-        // Local Tax 2
-        print '<br>';
-        print '<table class="noborder" width="100%">';
-        print '<tr class="liste_titre">';
-        print '<td>'.$langs->transcountry("LocalTax2Management",$mysoc->country_code).'</td><td>'.$langs->trans("Description").'</td>';
-        print '<td align="right">&nbsp;</td>';
-        print "</tr>\n";
-        $var=true;
-
-        $var=!$var;
-        print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optionlocaltax2\" id=\"lt2\" disabled value=\"localtax2on\"".(($conf->global->FACTURE_LOCAL_TAX2_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION == "localtax2on")?" checked":"")."> ".$langs->transcountry("LocalTax2IsUsed",$mysoc->country_code)."</td>";
-        print '<td colspan="2">';
-        print "<table>";
-        print "<tr><td><label for=\"lt2\">".$langs->transcountry("LocalTax2IsUsedDesc",$mysoc->country_code)."</label></td></tr>";
-        $example=$langs->transcountry("LocalTax2IsUsedExample",$mysoc->country_code);
-        print ($example!="LocalTax2IsUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax2IsUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
-        if($conf->global->MAIN_INFO_VALUE_LOCALTAX2!=0)
-        {
-	        print '<tr><td>'.$langs->trans("LTRate").': '. $conf->global->MAIN_INFO_VALUE_LOCALTAX2 .'</td></tr>';
-	    }
-        print '<tr><td align="left">'.$langs->trans("CalcLocaltax").': ';
-        if($conf->global->MAIN_INFO_LOCALTAX_CALC2==0)
-        {
-        	print $langs->trans("CalcLocaltax1").' - '.$langs->trans("CalcLocaltax1Desc");
-        }
-        else if($conf->global->MAIN_INFO_LOCALTAX_CALC2==1)
-        {
-        	print $langs->trans("CalcLocaltax2").' - '.$langs->trans("CalcLocaltax2Desc");
-        }
-        else if($conf->global->MAIN_INFO_LOCALTAX_CALC2==2)
-        {
-        	print $langs->trans("CalcLocaltax3").' - '.$langs->trans("CalcLocaltax3Desc");
-        }
-
-        print '</td></tr>';
-        print "</table>";
-        print "</td></tr>\n";
-
-        $var=!$var;
-        print "<tr ".$bc[$var]."><td width=\"140\"><input ".$bc[$var]." type=\"radio\" name=\"optionlocaltax2\" id=\"nolt2\" disabled value=\"localtax2off\"".($conf->global->FACTURE_LOCAL_TAX2_OPTION == "localtax2off"?" checked":"")."> ".$langs->transcountry("LocalTax2IsNotUsed",$mysoc->country_code)."</td>";
-        print '<td colspan="2">';
-        print "<table>";
-        print "<tr><td><label for=\"nolt2\">".$langs->transcountry("LocalTax2IsNotUsedDesc",$mysoc->country_code)."</label></td></tr>";
-        $example=$langs->transcountry("LocalTax2IsNotUsedExample",$mysoc->country_code);
-        print ($example!="LocalTax2IsNotUsedExample"?"<tr><td><i>".$langs->trans("Example").': '.$langs->transcountry("LocalTax2IsNotUsedExample",$mysoc->country_code)."</i></td></tr>\n":"");
-        print "</table>";
-        print "</td></tr>\n";
-
-        print "</table>";
-    }
-
-
-    // Actions buttons
-    print '<div class="tabsAction">';
-    print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a></div>';
-    print '</div>';
-
-    print '<br>';
+
+
+	// Actions buttons
+	print '<div class="tabsAction">';
+	print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a></div>';
+	print '</div>';
+
+	print '<br>';
 }
 
 
diff --git a/htdocs/compta/hrm.php b/htdocs/compta/hrm.php
index f253193b1a9af051f40864d205447552d47373d0..584077509b30e1316deec46e0cf664d988b1aba1 100644
--- a/htdocs/compta/hrm.php
+++ b/htdocs/compta/hrm.php
@@ -203,7 +203,7 @@ if (! empty($conf->deplacement->enabled) && $user->rights->deplacement->lire)
 
 if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire)
 {
-	$sql = "SELECT u.rowid as uid, u.lastname, u.firstname, x.rowid, x.date_debut as date, x.tms as dm, x.total_ttc, x.fk_statut as status";
+	$sql = "SELECT u.rowid as uid, u.lastname, u.firstname, x.rowid, x.ref, x.date_debut as date, x.tms as dm, x.total_ttc, x.fk_statut as status";
 	$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as x, ".MAIN_DB_PREFIX."user as u";
 	if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 	$sql.= " WHERE u.rowid = x.fk_user_author";
@@ -238,8 +238,8 @@ if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire
 			while ($i < $num && $i < $max)
 			{
 				$obj = $db->fetch_object($result);
-				$expensereportstatic->ref=$obj->rowid;
 				$expensereportstatic->id=$obj->rowid;
+				$expensereportstatic->ref=$obj->ref;
 				$userstatic->id=$obj->uid;
 				$userstatic->lastname=$obj->lastname;
 				$userstatic->firstname=$obj->firstname;
diff --git a/htdocs/compta/tva/clients.php b/htdocs/compta/tva/clients.php
index 5d8dce0fd738e44ea8e5712a65e94e7301ad1c66..857523673342d169dc6ee6a7ee7a2d42ff76f3ed 100644
--- a/htdocs/compta/tva/clients.php
+++ b/htdocs/compta/tva/clients.php
@@ -21,7 +21,7 @@
 
 /**
  *	    \file       htdocs/compta/tva/clients.php
- *      \ingroup    tax
+ *	  \ingroup    tax
  *		\brief      Page des societes
  */
 
@@ -30,6 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php';
 
 $langs->load("bills");
 $langs->load("compta");
@@ -39,8 +40,7 @@ $langs->load("other");
 
 // Date range
 $year=GETPOST("year");
-if (empty($year))
-{
+if (empty($year)) {
 	$year_current = strftime("%Y",dol_now());
 	$year_start = $year_current;
 } else {
@@ -50,38 +50,55 @@ if (empty($year))
 $date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]);
 $date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);
 // Quarter
-if (empty($date_start) || empty($date_end)) // We define date_start and date_end
-{
-    $q=GETPOST("q");
-    if (empty($q))
-	{
-		if (isset($_REQUEST["month"])) { $date_start=dol_get_first_day($year_start,$_REQUEST["month"],false); $date_end=dol_get_last_day($year_start,$_REQUEST["month"],false); }
-		else
-		{
-		    $month_current = strftime("%m",dol_now());
-		    if ($month_current >= 10) $q=4;
-            elseif ($month_current >= 7) $q=3;
-            elseif ($month_current >= 4) $q=2;
-            else $q=1;
+if (empty($date_start) || empty($date_end)) {// We define date_start and date_end
+	$q=GETPOST("q");
+	if (empty($q)) {
+		if (isset($_REQUEST["month"])) {
+			$date_start=dol_get_first_day($year_start,$_REQUEST["month"],false);
+			$date_end=dol_get_last_day($year_start,$_REQUEST["month"],false);
+		} else {
+			$month_current = strftime("%m",dol_now());
+			if ($month_current >= 10) $q=4;
+			elseif ($month_current >= 7) $q=3;
+			elseif ($month_current >= 4) $q=2;
+			else $q=1;
 		}
 	}
-	if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); }
-	if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); }
-	if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); }
-	if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); }
+	if ($q==1) {
+		$date_start=dol_get_first_day($year_start,1,false);
+		$date_end=dol_get_last_day($year_start,3,false);
+	}
+	if ($q==2) {
+		$date_start=dol_get_first_day($year_start,4,false);
+		$date_end=dol_get_last_day($year_start,6,false);
+	}
+	if ($q==3) {
+		$date_start=dol_get_first_day($year_start,7,false);
+		$date_end=dol_get_last_day($year_start,9,false);
+	}
+	if ($q==4) {
+		$date_start=dol_get_first_day($year_start,10,false);
+		$date_end=dol_get_last_day($year_start,12,false);
+	}
 }
 
 $min = GETPOST("min");
-if (empty($min)) $min = 0;
+if (empty($min)) {
+	$min = 0;
+}
 
 // Define modetax (0 or 1)
 // 0=normal, 1=option vat for services is on debit
 $modetax = $conf->global->TAX_MODE;
-if (isset($_REQUEST["modetax"])) $modetax=$_REQUEST["modetax"];
+if (isset($_REQUEST["modetax"])) {
+	$modetax=$_REQUEST["modetax"];
+}
 
 // Security check
 $socid = GETPOST('socid','int');
-if ($user->societe_id) $socid=$user->societe_id;
+if ($user->societe_id) {
+	$socid=$user->societe_id;
+}
 $result = restrictedArea($user, 'tax', '', '', 'charges');
 
 
@@ -95,9 +112,15 @@ $company_static=new Societe($db);
 
 $morequerystring='';
 $listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
-foreach($listofparams as $param)
-{
-	if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
+foreach($listofparams as $param) {
+	if (GETPOST($param)!='') {
+		$morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
+	}
+}
+
+$special_report = false;
+if (isset($_REQUEST['extra_report']) && $_REQUEST['extra_report'] == 1) {
+	$special_report = true;
 }
 
 llxHeader('','','','',0,0,'','',$morequerystring);
@@ -109,62 +132,92 @@ $fsearch.='  '.$langs->trans("SalesTurnoverMinimum").': ';
 $fsearch.='  <input type="text" name="min" id="min" value="'.$min.'" size="6">';
 
 // Affiche en-tete du rapport
-if ($modetax==1)	// Calculate on invoice for goods and services
-{
-    $name=$langs->trans("VATReportByCustomersInDueDebtMode");
+if ($modetax==1) {	// Calculate on invoice for goods and services
+	$name=$langs->trans("VATReportByCustomersInDueDebtMode");
 	$calcmode=$langs->trans("CalcModeVATDebt");
-    $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
-    //$name.='<br>('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=0">','</a>').')';
-    $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
-    //$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
-    $description=$langs->trans("RulesVATDueServices");
-    $description.='<br>';
-    $description.=$langs->trans("RulesVATDueProducts");
-    //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
-    //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
-    if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.='<br>'.$langs->trans("DepositsAreNotIncluded");
-	else  $description.='<br>'.$langs->trans("DepositsAreIncluded");
+	$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
+	//$name.='<br>('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=0">','</a>').')';
+	$period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
+	//$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
+	$description=$langs->trans("RulesVATDueServices");
+	$description.='<br>';
+	$description.=$langs->trans("RulesVATDueProducts");
+	//if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
+	//if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
+	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
+		$description.='<br>'.$langs->trans("DepositsAreNotIncluded");
+	} else {
+		$description.='<br>'.$langs->trans("DepositsAreIncluded");
+	}
 	$description.=$fsearch;
+	$description.='<br>'
+		. '<input type="radio" name="extra_report" value="0" '.($special_report?'':'checked="checked"').'> '
+		. $langs->trans('SimpleReport')
+		. '</input>'
+		. '<br>'
+		. '<input type="radio" name="extra_report" value="1" '.($special_report?'checked="checked"':'').'> '
+		. $langs->trans('AddExtraReport')
+		. '</input>'
+		. '<br>';
 	$builddate=time();
-    //$exportlink=$langs->trans("NotYetAvailable");
+	//$exportlink=$langs->trans("NotYetAvailable");
 
 	$elementcust=$langs->trans("CustomersInvoices");
 	$productcust=$langs->trans("Description");
 	$amountcust=$langs->trans("AmountHT");
-	if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
+	if ($mysoc->tva_assuj) {
+		$vatcust.=' ('.$langs->trans("ToPay").')';
+	}
 	$elementsup=$langs->trans("SuppliersInvoices");
 	$productsup=$langs->trans("Description");
 	$amountsup=$langs->trans("AmountHT");
-	if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
+	if ($mysoc->tva_assuj) {
+		$vatsup.=' ('.$langs->trans("ToGetBack").')';
+	}
 }
-if ($modetax==0) 	// Invoice for goods, payment for services
-{
-    $name=$langs->trans("VATReportByCustomersInInputOutputMode");
-    $calcmode=$langs->trans("CalcModeVATEngagement");
-    $calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
-    //$name.='<br>('.$langs->trans("SeeVATReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=1">','</a>').')';
-    $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
-    //$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
-    $description=$langs->trans("RulesVATInServices");
-    $description.=' '.$langs->trans("DepositsAreIncluded");
-    $description.='<br>';
-    $description.=$langs->trans("RulesVATInProducts");
-    if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.=' '.$langs->trans("DepositsAreNotIncluded");
-	else  $description.=' '.$langs->trans("DepositsAreIncluded");
-    //if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
-    //if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
-    $description.=$fsearch;
-    $builddate=time();
-    //$exportlink=$langs->trans("NotYetAvailable");
+if ($modetax==0) {	// Invoice for goods, payment for services
+	$name=$langs->trans("VATReportByCustomersInInputOutputMode");
+	$calcmode=$langs->trans("CalcModeVATEngagement");
+	$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
+	//$name.='<br>('.$langs->trans("SeeVATReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=1">','</a>').')';
+	$period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
+	//$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
+	$description=$langs->trans("RulesVATInServices");
+	$description.=' '.$langs->trans("DepositsAreIncluded");
+	$description.='<br>';
+	$description.=$langs->trans("RulesVATInProducts");
+	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
+		$description .= ' ' . $langs->trans("DepositsAreNotIncluded");
+	} else {
+		$description .= ' ' . $langs->trans("DepositsAreIncluded");
+	}
+	//if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
+	//if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
+	$description.=$fsearch;
+	$description.='<br>'
+		. '<input type="radio" name="extra_report" value="0" '.($special_report?'':'checked="checked"').'> '
+		. $langs->trans('SimpleReport')
+		. '</input>'
+		. '<br>'
+		. '<input type="radio" name="extra_report" value="1" '.($special_report?'checked="checked"':'').'> '
+		. $langs->trans('AddExtraReport')
+		. '</input>'
+		. '<br>';
+	$builddate=time();
+	//$exportlink=$langs->trans("NotYetAvailable");
 
 	$elementcust=$langs->trans("CustomersInvoices");
 	$productcust=$langs->trans("Description");
 	$amountcust=$langs->trans("AmountHT");
-	if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
+	if ($mysoc->tva_assuj) {
+		$vatcust.=' ('.$langs->trans("ToPay").')';
+	}
 	$elementsup=$langs->trans("SuppliersInvoices");
 	$productsup=$langs->trans("Description");
 	$amountsup=$langs->trans("AmountHT");
-	if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
+	if ($mysoc->tva_assuj) {
+		$vatsup.=' ('.$langs->trans("ToGetBack").')';
+	}
 }
 report_header($name,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
 
@@ -198,25 +251,18 @@ $parameters["direction"] = 'sell';
 $hookmanager->initHooks(array('externalbalance'));
 $reshook=$hookmanager->executeHooks('addStatisticLine',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
 
-if (is_array($coll_list))
-{
+if (is_array($coll_list)) {
 	$var=true;
 	$total = 0;  $totalamount = 0;
 	$i = 1;
-	foreach($coll_list as $coll)
-	{
-		if($min == 0 or ($min > 0 && $coll->amount > $min))
-		{
+	foreach ($coll_list as $coll) {
+		if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
 			$var=!$var;
 			$intra = str_replace($find,$replace,$coll->tva_intra);
-			if(empty($intra))
-			{
-				if($coll->assuj == '1')
-				{
+			if(empty($intra)) {
+				if($coll->assuj == '1') {
 					$intra = $langs->trans('Unknown');
-				}
-				else
-				{
+				} else {
 					//$intra = $langs->trans('NotRegistered');
 					$intra = '';
 				}
@@ -232,28 +278,27 @@ if (is_array($coll_list))
 			print '<td class="nowrap">'.$intra."</td>";
 			print "<td class=\"nowrap\" align=\"right\">".price($coll->amount)."</td>";
 			print "<td class=\"nowrap\" align=\"right\">".price($coll->tva)."</td>";
-            $totalamount = $totalamount + $coll->amount;
+			$totalamount = $totalamount + $coll->amount;
 			$total = $total + $coll->tva;
 			print "</tr>\n";
 			$i++;
 		}
 	}
-    $x_coll_sum = $total;
+	$x_coll_sum = $total;
 
 	print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
-    print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
+	print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
 	print '<td class="nowrap" align="right">'.price($total).'</td>';
 	print '</tr>';
-}
-else
-{
+} else {
 	$langs->load("errors");
-	if ($coll_list == -1)
-		print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
-	else if ($coll_list == -2)
-		print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
-	else
-		print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
+	if ($coll_list == -1) {
+		print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
+	} else if ($coll_list == -2) {
+		print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
+	} else {
+		print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
+	}
 }
 
 //print '</table>';
@@ -279,25 +324,18 @@ $coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'buy');
 
 $parameters["direction"] = 'buy';
 $reshook=$hookmanager->executeHooks('addStatisticLine',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
-if (is_array($coll_list))
-{
+if (is_array($coll_list)) {
 	$var=true;
 	$total = 0;  $totalamount = 0;
 	$i = 1;
-	foreach($coll_list as $coll)
-	{
-		if($min == 0 or ($min > 0 && $coll->amount > $min))
-		{
+	foreach ($coll_list as $coll) {
+		if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
 			$var=!$var;
 			$intra = str_replace($find,$replace,$coll->tva_intra);
-			if(empty($intra))
-			{
-				if($coll->assuj == '1')
-				{
+			if (empty($intra)) {
+				if ($coll->assuj == '1') {
 					$intra = $langs->trans('Unknown');
-				}
-				else
-				{
+				} else {
 					//$intra = $langs->trans('NotRegistered');
 					$intra = '';
 				}
@@ -313,44 +351,197 @@ if (is_array($coll_list))
 			print '<td class="nowrap">'.$intra."</td>";
 			print "<td class=\"nowrap\" align=\"right\">".price($coll->amount)."</td>";
 			print "<td class=\"nowrap\" align=\"right\">".price($coll->tva)."</td>";
-            $totalamount = $totalamount + $coll->amount;
+			$totalamount = $totalamount + $coll->amount;
 			$total = $total + $coll->tva;
 			print "</tr>\n";
 			$i++;
 		}
 	}
-    $x_paye_sum = $total;
+	$x_paye_sum = $total;
 
 	print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
-    print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
+	print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
 	print '<td class="nowrap" align="right">'.price($total).'</td>';
 	print '</tr>';
 
 	print '</table>';
 
-    // Total to pay
-    print '<br><br>';
-    print '<table class="noborder" width="100%">';
-    $diff = $x_coll_sum - $x_paye_sum;
-    print '<tr class="liste_total">';
-    print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
-    print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
-    print "</tr>\n";
+	// Total to pay
+	print '<br><br>';
+	print '<table class="noborder" width="100%">';
+	$diff = $x_coll_sum - $x_paye_sum;
+	print '<tr class="liste_total">';
+	print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
+	print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
+	print "</tr>\n";
 
-}
-else
-{
+} else {
 	$langs->load("errors");
-	if ($coll_list == -1)
-		print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
-	else if ($coll_list == -2)
-		print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
-	else
-		print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
+	if ($coll_list == -1) {
+		print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
+	} else if ($coll_list == -2) {
+		print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
+	} else {
+		print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
+	}
 }
 
 print '</table>';
 
+if ($special_report) {
+	// Get country 2-letters code
+	global $mysoc;
+	$country_id = $mysoc->country_id;
+	$country = new Ccountry($db);
+	$country->fetch($country_id);
+
+	// Print listing of other-country customers as additional report
+	// This matches tax requirements to list all same-country customers (only)
+	print '<h3>'.$langs->trans('OtherCountriesCustomersReport').'</h3>';
+	print $langs->trans('BasedOnTwoFirstLettersOfVATNumberBeingDifferentFromYourCompanyCountry');
+	$coll_list = vat_by_thirdparty($db, 0, $date_start, $date_end, $modetax, 'sell');
+
+	print "<table class=\"noborder\" width=\"100%\">";
+	print "<tr class=\"liste_titre\">";
+	print '<td align="left">' . $langs->trans("Num") . "</td>";
+	print '<td align="left">' . $langs->trans("Customer") . "</td>";
+	print "<td>" . $langs->trans("VATIntra") . "</td>";
+	print "<td align=\"right\">" . $langs->trans("AmountHTVATRealReceived") . "</td>";
+	print "<td align=\"right\">" . $vatcust . "</td>";
+	print "</tr>\n";
+
+	if (is_array($coll_list)) {
+		$var = true;
+		$total = 0;
+		$totalamount = 0;
+		$i = 1;
+		foreach ($coll_list as $coll) {
+			if (substr($coll->tva_intra, 0, 2) == $country->code) {
+				// Only use different-country VAT codes
+				continue;
+			}
+			if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
+				$var = !$var;
+				$intra = str_replace($find, $replace, $coll->tva_intra);
+				if (empty($intra)) {
+					if ($coll->assuj == '1') {
+						$intra = $langs->trans('Unknown');
+					} else {
+						//$intra = $langs->trans('NotRegistered');
+						$intra = '';
+					}
+				}
+				print "<tr " . $bc[$var] . ">";
+				print '<td class="nowrap">' . $i . "</td>";
+				$company_static->id = $coll->socid;
+				$company_static->name = $coll->name;
+				$company_static->client = 1;
+				print '<td class="nowrap">' . $company_static->getNomUrl(1,
+						'customer') . '</td>';
+				$find = array(' ', '.');
+				$replace = array('', '');
+				print '<td class="nowrap">' . $intra . "</td>";
+				print "<td class=\"nowrap\" align=\"right\">" . price($coll->amount) . "</td>";
+				print "<td class=\"nowrap\" align=\"right\">" . price($coll->tva) . "</td>";
+				$totalamount = $totalamount + $coll->amount;
+				$total = $total + $coll->tva;
+				print "</tr>\n";
+				$i++;
+			}
+		}
+		$x_coll_sum = $total;
+
+		print '<tr class="liste_total"><td align="right" colspan="3">' . $langs->trans("Total") . ':</td>';
+		print '<td class="nowrap" align="right">' . price($totalamount) . '</td>';
+		print '<td class="nowrap" align="right">' . price($total) . '</td>';
+		print '</tr>';
+	} else {
+		$langs->load("errors");
+		if ($coll_list == -1) {
+			print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
+		} else {
+			if ($coll_list == -2) {
+				print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
+			} else {
+				print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
+			}
+		}
+	}
+	print '</table>';
+
+	// Print listing of same-country customers as additional report
+	// This matches tax requirements to list all same-country customers (only)
+	print '<h3>'.$langs->trans('SameCountryCustomersWithVAT').'</h3>';
+	print $langs->trans('BasedOnTwoFirstLettersOfVATNumberBeingTheSameAsYourCompanyCountry');
+	$coll_list = vat_by_thirdparty($db, 0, $date_start, $date_end, $modetax, 'sell');
+
+	print "<table class=\"noborder\" width=\"100%\">";
+	print "<tr class=\"liste_titre\">";
+	print '<td align="left">' . $langs->trans("Num") . "</td>";
+	print '<td align="left">' . $langs->trans("Customer") . "</td>";
+	print "<td>" . $langs->trans("VATIntra") . "</td>";
+	print "<td align=\"right\">" . $langs->trans("AmountHTVATRealReceived") . "</td>";
+	print "<td align=\"right\">" . $vatcust . "</td>";
+	print "</tr>\n";
+
+	if (is_array($coll_list)) {
+		$var = true;
+		$total = 0;
+		$totalamount = 0;
+		$i = 1;
+		foreach ($coll_list as $coll) {
+			if (substr($coll->tva_intra, 0, 2) != $country->code) {
+				// Only use same-country VAT codes
+				continue;
+			}
+			if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
+				$var = !$var;
+				$intra = str_replace($find, $replace, $coll->tva_intra);
+				if (empty($intra)) {
+					if ($coll->assuj == '1') {
+						$intra = $langs->trans('Unknown');
+					} else {
+						//$intra = $langs->trans('NotRegistered');
+						$intra = '';
+					}
+				}
+				print "<tr " . $bc[$var] . ">";
+				print '<td class="nowrap">' . $i . "</td>";
+				$company_static->id = $coll->socid;
+				$company_static->name = $coll->name;
+				$company_static->client = 1;
+				print '<td class="nowrap">' . $company_static->getNomUrl(1, 'customer') . '</td>';
+				$find = array(' ', '.');
+				$replace = array('', '');
+				print '<td class="nowrap">' . $intra . "</td>";
+				print "<td class=\"nowrap\" align=\"right\">" . price($coll->amount) . "</td>";
+				print "<td class=\"nowrap\" align=\"right\">" . price($coll->tva) . "</td>";
+				$totalamount = $totalamount + $coll->amount;
+				$total = $total + $coll->tva;
+				print "</tr>\n";
+				$i++;
+			}
+		}
+		$x_coll_sum = $total;
+
+		print '<tr class="liste_total"><td align="right" colspan="3">' . $langs->trans("Total") . ':</td>';
+		print '<td class="nowrap" align="right">' . price($totalamount) . '</td>';
+		print '<td class="nowrap" align="right">' . price($total) . '</td>';
+		print '</tr>';
+	} else {
+		$langs->load("errors");
+		if ($coll_list == -1) {
+			print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
+		} else {
+			if ($coll_list == -2) {
+				print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
+			} else {
+				print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
+			}
+		}
+	}
+	print '</table>';
+}
 
 llxFooter();
 
diff --git a/htdocs/compta/tva/quadri.php b/htdocs/compta/tva/quadri.php
index 4b399d65248307c67b012ae903be9944da1827ca..3918b56c3bffddbd00c6034b93cb86b6d869fcef 100644
--- a/htdocs/compta/tva/quadri.php
+++ b/htdocs/compta/tva/quadri.php
@@ -72,8 +72,8 @@ function tva_coll($db,$y,$q)
         $sql.= " AND f.fk_statut in (1,2)";
         $sql.= " AND f.rowid = d.fk_facture ";
         $sql.= " AND date_format(f.datef,'%Y') = '".$y."'";
-        $sql.= " AND (round(date_format(f.datef,'%m') > ".(($q-1)*3);
-        $sql.= " AND round(date_format(f.datef,'%m')) <= ".($q*3).")";
+        $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3);
+        $sql.= " AND date_format(f.datef,'%m') <= ".($q*3).")";
         $sql.= " ORDER BY rate, facid";
 
     }
@@ -131,7 +131,7 @@ function tva_paye($db, $y,$q)
     if ($conf->global->ACCOUNTING_MODE == "CREANCES-DETTES")
     {
         // Si on paye la tva sur les factures dues (non brouillon)
-        $sql = "SELECT d.fk_facture_fourn as facid, f.facnumber as facnum, d.tva_tx as rate, d.total_ht as totalht, d.tva as amount";
+        $sql = "SELECT d.fk_facture_fourn as facid, f.ref_supplier as facnum, d.tva_tx as rate, d.total_ht as totalht, d.tva as amount";
         $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
         $sql.= ", ".MAIN_DB_PREFIX."facture_fourn_det as d" ;
         $sql.= ", ".MAIN_DB_PREFIX."societe as s";
@@ -222,8 +222,7 @@ if ($conf->global->ACCOUNTING_MODE == "CREANCES-DETTES")
 	$subtot_coll_vat = 0;
 	$subtot_paye_total = 0;
 	$subtot_paye_vat = 0;
-	for ($q = 1 ; $q <= 4 ; $q++)
-	{
+	for ($q = 1 ; $q <= 4 ; $q++) {
 		print "<tr class=\"liste_titre\"><td colspan=\"8\">".$langs->trans("Quadri")." $q (".dol_print_date(dol_mktime(0,0,0,(($q-1)*3)+1,1,$y),"%b %Y").' - '.dol_print_date(dol_mktime(0,0,0,($q*3),1,$y),"%b %Y").")</td></tr>";
 		$var=true;
 
diff --git a/htdocs/compta/tva/quarter_report.php b/htdocs/compta/tva/quarter_report.php
new file mode 100644
index 0000000000000000000000000000000000000000..5861dcdaff45022ad23301f4d86e7bc6ba32d782
--- /dev/null
+++ b/htdocs/compta/tva/quarter_report.php
@@ -0,0 +1,713 @@
+<?php
+/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
+ * Copyright (C) 2004      Eric Seigne          <eric.seigne@ryxeo.com>
+ * Copyright (C) 2004-2013 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2006-2007, 2015 Yannick Warnier      <ywarnier@beeznest.org>
+ * Copyright (C) 2014	   Ferran Marcet        <fmarcet@2byte.es>
+ *
+ * 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
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ *		\file       htdocs/compta/tva/quadri_detail.php
+ *		\ingroup    tax
+ *		\brief      Trimestrial page - detailed version
+ *		TODO 		Deal with recurrent invoices as well
+ */
+
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
+require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
+require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
+require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
+
+$langs->load("main");
+$langs->load("bills");
+$langs->load("compta");
+$langs->load("companies");
+$langs->load("products");
+$langs->load("other");
+
+// Date range
+$year=GETPOST('year', 'int');
+if (empty($year)) {
+	$year_current = strftime("%Y",dol_now());
+	$year_start = $year_current;
+} else {
+	$year_current = $year;
+	$year_start = $year;
+}
+$date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]);
+$date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);
+// Quarter
+if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
+	$q=GETPOST('q', 'int');
+	if (empty($q)) {
+		if (isset($_REQUEST["month"])) {
+			$date_start=dol_get_first_day($year_start,$_REQUEST["month"],false);
+			$date_end=dol_get_last_day($year_start,$_REQUEST["month"],false);
+		} else {
+			$month_current = strftime("%m",dol_now());
+			if ($month_current >= 10) $q=4;
+			elseif ($month_current >= 7) $q=3;
+			elseif ($month_current >= 4) $q=2;
+			else $q=1;
+		}
+	}
+	if ($q==1) {
+		$date_start=dol_get_first_day($year_start,1,false);
+		$date_end=dol_get_last_day($year_start,3,false);
+	}
+	if ($q==2) {
+		$date_start=dol_get_first_day($year_start,4,false);
+		$date_end=dol_get_last_day($year_start,6,false);
+	}
+	if ($q==3) {
+		$date_start=dol_get_first_day($year_start,7,false);
+		$date_end=dol_get_last_day($year_start,9,false);
+	}
+	if ($q==4) {
+		$date_start=dol_get_first_day($year_start,10,false);
+		$date_end=dol_get_last_day($year_start,12,false);
+	}
+}
+
+$min = GETPOST("min");
+if (empty($min)) {
+	$min = 0;
+}
+
+// Define modetax (0 or 1)
+// 0=normal, 1=option vat for services is on debit
+$modetax = $conf->global->TAX_MODE;
+if (isset($_REQUEST["modetax"])) {
+	$modetax=$_REQUEST["modetax"];
+}
+if (empty($modetax)) {
+	$modetax=0;
+}
+
+// Security check
+$socid = GETPOST('socid','int');
+if ($user->societe_id) {
+	$socid=$user->societe_id;
+}
+$result = restrictedArea($user, 'tax', '', '', 'charges');
+
+
+
+/*
+ * View
+ */
+
+$morequerystring='';
+$listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
+foreach ($listofparams as $param) {
+	if (GETPOST($param)!='') {
+		$morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
+	}
+}
+
+llxHeader('','','','',0,0,'','',$morequerystring);
+
+$form=new Form($db);
+
+$company_static=new Societe($db);
+$invoice_customer=new Facture($db);
+$invoice_supplier=new FactureFournisseur($db);
+$product_static=new Product($db);
+$payment_static=new Paiement($db);
+$paymentfourn_static=new PaiementFourn($db);
+
+//print_fiche_titre($langs->trans("VAT"),"");
+
+//$fsearch.='<br>';
+$fsearch.='  <input type="hidden" name="year" value="'.$year.'">';
+$fsearch.='  <input type="hidden" name="modetax" value="'.$modetax.'">';
+//$fsearch.='  '.$langs->trans("SalesTurnoverMinimum").': ';
+//$fsearch.='  <input type="text" name="min" value="'.$min.'">';
+
+
+// Affiche en-tete du rapport
+if ($modetax==1) { // Calculate on invoice for goods and services
+	$nom=$langs->trans("VATReportByQuartersInDueDebtMode");
+	$calcmode=$langs->trans("CalcModeVATDebt");
+	$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
+	$period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
+	$prevyear=$year_start; $prevquarter=$q;
+	if ($prevquarter > 1) {
+		$prevquarter--;
+	} else {
+		$prevquarter=4; $prevyear--;
+	}
+	$nextyear=$year_start; $nextquarter=$q;
+	if ($nextquarter < 4) {
+		$nextquarter++;
+	} else {
+		$nextquarter=1; $nextyear++;
+	}
+	//$periodlink=($prevyear?"<a href='".$_SERVER["PHP_SELF"]."?year=".$prevyear."&q=".$prevquarter."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".$nextyear."&q=".$nextquarter."&modetax=".$modetax."'>".img_next()."</a>":"");
+	$description=$langs->trans("RulesVATDueServices");
+	$description.='<br>';
+	$description.=$langs->trans("RulesVATDueProducts");
+	//if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
+	//if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
+	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
+		$description.='<br>'.$langs->trans("DepositsAreNotIncluded");
+	} else {
+		$description.='<br>'.$langs->trans("DepositsAreIncluded");
+	}
+	$description.=$fsearch;
+	$builddate=time();
+	//$exportlink=$langs->trans("NotYetAvailable");
+
+	$elementcust=$langs->trans("CustomersInvoices");
+	$productcust=$langs->trans("ProductOrService");
+	$amountcust=$langs->trans("AmountHT");
+	$vatcust=$langs->trans("VATReceived");
+	$namecust=$langs->trans("Name");
+	if ($mysoc->tva_assuj) {
+		$vatcust.=' ('.$langs->trans("ToPay").')';
+	}
+	$elementsup=$langs->trans("SuppliersInvoices");
+	$productsup=$langs->trans("ProductOrService");
+	$amountsup=$langs->trans("AmountHT");
+	$vatsup=$langs->trans("VATPaid");
+	$namesup=$namecust;
+	if ($mysoc->tva_assuj) {
+		$vatsup.=' ('.$langs->trans("ToGetBack").')';
+	}
+}
+if ($modetax==0) {	// Invoice for goods, payment for services
+	$nom=$langs->trans("VATReportByQuartersInInputOutputMode");
+	$calcmode=$langs->trans("CalcModeVATEngagement");
+	$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
+	$period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
+	$prevyear=$year_start; $prevquarter=$q;
+	if ($prevquarter > 1) {
+		$prevquarter--;
+	} else {
+		$prevquarter=4; $prevyear--;
+	}
+	$nextyear=$year_start; $nextquarter=$q;
+	if ($nextquarter < 4) {
+		$nextquarter++;
+	} else {
+		$nextquarter=1; $nextyear++;
+	}
+	//$periodlink=($prevyear?"<a href='".$_SERVER["PHP_SELF"]."?year=".$prevyear."&q=".$prevquarter."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".$nextyear."&q=".$nextquarter."&modetax=".$modetax."'>".img_next()."</a>":"");
+	$description=$langs->trans("RulesVATInServices");
+	$description.=' '.$langs->trans("DepositsAreIncluded");
+	$description.='<br>';
+	$description.=$langs->trans("RulesVATInProducts");
+	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
+		$description.=' '.$langs->trans("DepositsAreNotIncluded");
+	} else {
+		$description.=' '.$langs->trans("DepositsAreIncluded");
+	}
+	//if ($conf->global->MAIN_MODULE_COMPTABILITE || $conf->global->MAIN_MODULE_ACCOUNTING) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
+	//if (! empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description.='<br>'.$langs->trans("WarningDepositsNotIncluded");
+	$description.=$fsearch;
+	$builddate=time();
+	//$exportlink=$langs->trans("NotYetAvailable");
+
+	$elementcust=$langs->trans("CustomersInvoices");
+	$productcust=$langs->trans("ProductOrService");
+	$amountcust=$langs->trans("AmountHT");
+	$vatcust=$langs->trans("VATReceived");
+	$namecust=$langs->trans("Name");
+	if ($mysoc->tva_assuj) {
+		$vatcust.=' ('.$langs->trans("ToPay").')';
+	}
+	$elementsup=$langs->trans("SuppliersInvoices");
+	$productsup=$productcust;
+	$amountsup=$amountcust;
+	$vatsup=$langs->trans("VATPaid");
+	$namesup=$namecust;
+	if ($mysoc->tva_assuj) {
+		$vatsup.=' ('.$langs->trans("ToGetBack").')';
+	}
+}
+report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
+
+$vatcust=$langs->trans("VATReceived");
+$vatsup=$langs->trans("VATPaid");
+
+
+// VAT Received and paid
+
+echo '<table class="noborder" width="100%">';
+
+$y = $year_current;
+$total = 0;
+$i=0;
+$columns = 6;
+
+// Load arrays of datas
+$x_coll = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'sell');
+$x_paye = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'buy');
+
+if (!is_array($x_coll) || !is_array($x_paye)) {
+	$langs->load("errors");
+	if ($x_coll == -1) {
+		print '<tr><td colspan="' . $columns . '">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
+	} else if ($x_coll == -2) {
+		print '<tr><td colspan="' . $columns . '">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
+	} else {
+		print '<tr><td colspan="' . $columns . '">' . $langs->trans("Error") . '</td></tr>';
+	}
+} else {
+	$x_both = array();
+	//now, from these two arrays, get another array with one rate per line
+	foreach(array_keys($x_coll) as $my_coll_rate) {
+		$x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
+		$x_both[$my_coll_rate]['coll']['vat']	 = $x_coll[$my_coll_rate]['vat'];
+		$x_both[$my_coll_rate]['paye']['totalht'] = 0;
+		$x_both[$my_coll_rate]['paye']['vat'] = 0;
+		$x_both[$my_coll_rate]['coll']['links'] = '';
+		$x_both[$my_coll_rate]['coll']['detail'] = array();
+		foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) {
+			$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
+			$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
+			$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
+			$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$id]);
+			$x_both[$my_coll_rate]['coll']['detail'][] = array(
+				'id'        =>$x_coll[$my_coll_rate]['facid'][$id],
+				'descr'     =>$x_coll[$my_coll_rate]['descr'][$id],
+				'pid'       =>$x_coll[$my_coll_rate]['pid'][$id],
+				'pref'      =>$x_coll[$my_coll_rate]['pref'][$id],
+				'ptype'     =>$x_coll[$my_coll_rate]['ptype'][$id],
+				'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
+				'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
+				'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
+				'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
+				'dtype'     =>$x_coll[$my_coll_rate]['dtype'][$id],
+				'datef'     =>$x_coll[$my_coll_rate]['datef'][$id],
+				'company_link'=>$company_static->getNomUrl(1,'',20),
+				'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
+				'ddate_end'  =>$x_coll[$my_coll_rate]['ddate_end'][$id],
+				'totalht'   =>$x_coll[$my_coll_rate]['totalht_list'][$id],
+				'vat'       =>$x_coll[$my_coll_rate]['vat_list'][$id],
+				'link'      =>$invoice_customer->getNomUrl(1,'',12)
+			);
+		}
+	}
+	// tva paid
+	foreach (array_keys($x_paye) as $my_paye_rate) {
+		$x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
+		$x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
+		if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
+			$x_both[$my_paye_rate]['coll']['totalht'] = 0;
+			$x_both[$my_paye_rate]['coll']['vat'] = 0;
+		}
+		$x_both[$my_paye_rate]['paye']['links'] = '';
+		$x_both[$my_paye_rate]['paye']['detail'] = array();
+
+		foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy) {
+			$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
+			$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
+			$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
+			$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$id]);
+			$x_both[$my_paye_rate]['paye']['detail'][] = array(
+				'id'        =>$x_paye[$my_paye_rate]['facid'][$id],
+				'descr'     =>$x_paye[$my_paye_rate]['descr'][$id],
+				'pid'       =>$x_paye[$my_paye_rate]['pid'][$id],
+				'pref'      =>$x_paye[$my_paye_rate]['pref'][$id],
+				'ptype'     =>$x_paye[$my_paye_rate]['ptype'][$id],
+				'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
+				'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
+				'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
+				'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
+				'dtype'     =>$x_paye[$my_paye_rate]['dtype'][$id],
+				'datef'     =>$x_paye[$my_paye_rate]['datef'][$id],
+				'company_link'=>$company_static->getNomUrl(1,'',20),
+				'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
+				'ddate_end'  =>$x_paye[$my_paye_rate]['ddate_end'][$id],
+				'totalht'   =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
+				'vat'       =>$x_paye[$my_paye_rate]['vat_list'][$id],
+				'link'      =>$invoice_supplier->getNomUrl(1,'',12)
+			);
+		}
+	}
+	//now we have an array (x_both) indexed by rates for coll and paye
+
+
+	//print table headers for this quadri - incomes first
+
+	$x_coll_sum = 0;
+	$x_coll_ht = 0;
+	$x_paye_sum = 0;
+	$x_paye_ht = 0;
+
+	$span=$columns-3;
+	if ($modetax == 0) $span+=2;
+
+	//print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
+
+	// Customers invoices
+	print '<tr class="liste_titre">';
+	print '<td align="left">'.$elementcust.'</td>';
+	print '<td align="left">'.$langs->trans("Date").'</td>';
+	print '<td align="left">'.$namecust.'</td>';
+	print '<td align="left">'.$productcust.'</td>';
+	if ($modetax == 0) {
+		print '<td align="right">'.$amountcust.'</td>';
+		print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
+	}
+	print '<td align="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
+	print '<td align="right">'.$vatcust.'</td>';
+	print '</tr>';
+	
+	$action = "tvadetail";
+	$parameters["mode"] = $modetax;
+	$parameters["start"] = $date_start;
+	$parameters["end"] = $date_end;
+	$object = array(&$x_coll, &$x_paye, &$x_both);
+	// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
+	$hookmanager->initHooks(array('externalbalance'));
+	$reshook=$hookmanager->executeHooks('addStatisticLine',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
+	
+	foreach (array_keys($x_coll) as $rate) {
+		$subtot_coll_total_ht = 0;
+		$subtot_coll_vat = 0;
+
+		if (is_array($x_both[$rate]['coll']['detail'])) {
+			// VAT Rate
+			$var=true;
+			print "<tr>";
+			print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
+			print '</tr>'."\n";
+
+			foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
+				// Define type
+				$type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
+				// Try to enhance type detection using date_start and date_end for free lines where type
+				// was not saved.
+				if (!empty($fields['ddate_start'])) {
+					$type=1;
+				}
+				if (!empty($fields['ddate_end'])) {
+					$type=1;
+				}
+
+				$var=!$var;
+				print '<tr '.$bc[$var].'>';
+
+				// Ref
+				print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
+
+				// Invoice date
+				print '<td align="left">' . $fields['datef'] . '</td>';
+				// Company name
+				print '<td align="left">' . $fields['company_link'] . '</td>';
+
+				// Description
+				print '<td align="left">';
+				if ($fields['pid']) {
+					$product_static->id=$fields['pid'];
+					$product_static->ref=$fields['pref'];
+					$product_static->type=$fields['ptype'];
+					print $product_static->getNomUrl(1);
+					if (dol_string_nohtmltag($fields['descr'])) {
+						print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
+					}
+				} else {
+					if ($type) {
+						$text = img_object($langs->trans('Service'),'service');
+					} else {
+						$text = img_object($langs->trans('Product'),'product');
+					}
+					if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg)) {
+						if ($reg[1]=='DEPOSIT') {
+							$fields['descr']=$langs->transnoentitiesnoconv('Deposit');
+						} elseif ($reg[1]=='CREDIT_NOTE') {
+							$fields['descr']=$langs->transnoentitiesnoconv('CreditNote');
+						} else {
+							$fields['descr']=$langs->transnoentitiesnoconv($reg[1]);
+						}
+					}
+					print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
+
+					// Show range
+					print_date_range($fields['ddate_start'],$fields['ddate_end']);
+				}
+				print '</td>';
+
+				// Total HT
+				if ($modetax == 0) {
+					print '<td class="nowrap" align="right">';
+					print price($fields['totalht']);
+					if (price2num($fields['ftotal_ttc'])) {
+						//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
+						$ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
+						//print ' ('.round($ratiolineinvoice*100,2).'%)';
+					}
+					print '</td>';
+				}
+
+				// Payment
+				$ratiopaymentinvoice=1;
+				if ($modetax == 0) {
+					if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
+						$ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
+					}
+					print '<td class="nowrap" align="right">';
+					//print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
+					if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
+						$payment_static->id=$fields['payment_id'];
+						print $payment_static->getNomUrl(2);
+					}
+					if ($type == 0) {
+						print $langs->trans("NotUsedForGoods");
+					} else {
+						print $fields['payment_amount'];
+						if (isset($fields['payment_amount'])) {
+							print ' ('.round($ratiopaymentinvoice*100,2).'%)';
+						}
+					}
+					print '</td>';
+				}
+
+				// Total collected
+				print '<td class="nowrap" align="right">';
+				$temp_ht=$fields['totalht'];
+				if ($type == 1) {
+					$temp_ht=$fields['totalht']*$ratiopaymentinvoice;
+				}
+				print price(price2num($temp_ht,'MT'),1);
+				print '</td>';
+
+				// VAT
+				print '<td class="nowrap" align="right">';
+				$temp_vat=$fields['vat'];
+				if ($type == 1) {
+					$temp_vat=$fields['vat']*$ratiopaymentinvoice;
+				}
+				print price(price2num($temp_vat,'MT'),1);
+				//print price($fields['vat']);
+				print '</td>';
+				print '</tr>';
+
+				$subtot_coll_total_ht += $temp_ht;
+				$subtot_coll_vat      += $temp_vat;
+				$x_coll_sum           += $temp_vat;
+			}
+		}
+		// Total customers for this vat rate
+		print '<tr class="liste_total">';
+		print '<td colspan="'.$span.'"></td>';
+		print '<td align="right">'.$langs->trans("Total").':</td>';
+		if ($modetax == 0) {
+			print '<td class="nowrap" align="right">&nbsp;</td>';
+			print '<td align="right">&nbsp;</td>';
+		}
+		print '<td align="right">'.price(price2num($subtot_coll_total_ht,'MT')).'</td>';
+		print '<td class="nowrap" align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
+		print '</tr>';
+	}
+
+	if (count($x_coll) == 0) {  // Show a total ine if nothing shown
+		print '<tr class="liste_total">';
+		print '<td colspan="'.$span.'"></td>';
+		print '<td align="right">'.$langs->trans("Total").':</td>';
+		if ($modetax == 0) {
+			print '<td class="nowrap" align="right">&nbsp;</td>';
+			print '<td align="right">&nbsp;</td>';
+		}
+		print '<td align="right">'.price(price2num(0,'MT')).'</td>';
+		print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
+		print '</tr>';
+	}
+
+	// Blank line
+	print '<tr><td colspan="'.($span+1).'">&nbsp;</td></tr>';
+
+	//print table headers for this quadri - expenses now
+	//imprime les en-tete de tables pour ce quadri - maintenant les d�penses
+	print '<tr class="liste_titre">';
+	print '<td align="left">'.$elementsup.'</td>';
+	print '<td align="left">'.$langs->trans("Date").'</td>';
+	print '<td align="left">'.$namesup.'</td>';
+	print '<td align="left">'.$productsup.'</td>';
+	if ($modetax == 0) {
+		print '<td align="right">'.$amountsup.'</td>';
+		print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
+	}
+	print '<td align="right">'.$langs->trans("AmountHTVATRealPaid").'</td>';
+	print '<td align="right">'.$vatsup.'</td>';
+	print '</tr>'."\n";
+
+	foreach (array_keys($x_paye) as $rate) {
+		$subtot_paye_total_ht = 0;
+		$subtot_paye_vat = 0;
+
+		if (is_array($x_both[$rate]['paye']['detail'])) {
+			$var=true;
+			print "<tr>";
+			print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
+			print '</tr>'."\n";
+
+			foreach ($x_both[$rate]['paye']['detail'] as $index=>$fields) {
+				// Define type
+				$type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
+				// Try to enhance type detection using date_start and date_end for free lines where type
+				// was not saved.
+				if (!empty($fields['ddate_start'])) {
+					$type=1;
+				}
+				if (!empty($fields['ddate_end'])) {
+					$type=1;
+				}
+
+				$var=!$var;
+				print '<tr '.$bc[$var].'>';
+
+				// Ref
+				print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
+				// Invoice date
+				print '<td align="left">' . $fields['datef'] . '</td>';
+				// Company name
+				print '<td align="left">' . $fields['company_link'] . '</td>';
+
+				// Description
+				print '<td align="left">';
+				if ($fields['pid']) {
+					$product_static->id=$fields['pid'];
+					$product_static->ref=$fields['pref'];
+					$product_static->type=$fields['ptype'];
+					print $product_static->getNomUrl(1);
+					if (dol_string_nohtmltag($fields['descr'])) {
+						print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
+					}
+				} else {
+					if ($type) {
+						$text = img_object($langs->trans('Service'),'service');
+					} else {
+						$text = img_object($langs->trans('Product'),'product');
+					}
+					print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
+
+					// Show range
+					print_date_range($fields['ddate_start'],$fields['ddate_end']);
+				}
+				print '</td>';
+
+				// Total HT
+				if ($modetax == 0) {
+					print '<td class="nowrap" align="right">';
+					print price($fields['totalht']);
+					if (price2num($fields['ftotal_ttc'])) {
+						//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
+						$ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
+						//print ' ('.round($ratiolineinvoice*100,2).'%)';
+					}
+					print '</td>';
+				}
+
+				// Payment
+				$ratiopaymentinvoice=1;
+				if ($modetax == 0) {
+					if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
+						$ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
+					}
+					print '<td class="nowrap" align="right">';
+					if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
+						$paymentfourn_static->id=$fields['payment_id'];
+						print $paymentfourn_static->getNomUrl(2);
+					}
+					if ($type == 0) {
+						print $langs->trans("NotUsedForGoods");
+					} else {
+						print $fields['payment_amount'];
+						if (isset($fields['payment_amount'])) {
+							print ' ('.round($ratiopaymentinvoice*100,2).'%)';
+						}
+					}
+					print '</td>';
+				}
+
+				// VAT paid
+				print '<td class="nowrap" align="right">';
+				$temp_ht=$fields['totalht'];
+				if ($type == 1) {
+					$temp_ht=$fields['totalht']*$ratiopaymentinvoice;
+				}
+				print price(price2num($temp_ht,'MT'),1);
+				print '</td>';
+
+				// VAT
+				print '<td class="nowrap" align="right">';
+				$temp_vat=$fields['vat'];
+				if ($type == 1) {
+					$temp_vat=$fields['vat']*$ratiopaymentinvoice;
+				}
+				print price(price2num($temp_vat,'MT'),1);
+				//print price($fields['vat']);
+				print '</td>';
+				print '</tr>';
+
+				$subtot_paye_total_ht += $temp_ht;
+				$subtot_paye_vat	  += $temp_vat;
+				$x_paye_sum		   += $temp_vat;
+			}
+		}
+		// Total suppliers for this vat rate
+		print '<tr class="liste_total">';
+		print '<td colspan="'.$span.'"></td>';
+		print '<td align="right">'.$langs->trans("Total").':</td>';
+		if ($modetax == 0) {
+			print '<td class="nowrap" align="right">&nbsp;</td>';
+			print '<td align="right">&nbsp;</td>';
+		}
+		print '<td align="right">'.price(price2num($subtot_paye_total_ht,'MT')).'</td>';
+		print '<td class="nowrap" align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
+		print '</tr>';
+	}
+
+	if (count($x_paye) == 0) {  // Show a total ine if nothing shown
+		print '<tr class="liste_total">';
+		print '<td colspan="'.$span.'"></td>';
+		print '<td align="right">'.$langs->trans("Total").':</td>';
+		if ($modetax == 0) {
+			print '<td class="nowrap" align="right">&nbsp;</td>';
+			print '<td align="right">&nbsp;</td>';
+		}
+		print '<td align="right">'.price(price2num(0,'MT')).'</td>';
+		print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
+		print '</tr>';
+	}
+
+	print '</table>';
+
+	// Total to pay
+	print '<br><br>';
+	print '<table class="noborder" width="100%">';
+	$diff = $x_coll_sum - $x_paye_sum;
+	print '<tr class="liste_total">';
+	print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
+	print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
+	print "</tr>\n";
+
+	$i++;
+}
+echo '</table>';
+
+$db->close();
+
+llxFooter();
diff --git a/htdocs/core/lib/report.lib.php b/htdocs/core/lib/report.lib.php
index 681f6e7a913c70aacb2e4bb82fbac01ddb1a11bc..79ab5fe0eadd1f2d642a19d4b36bcd099af8c439 100644
--- a/htdocs/core/lib/report.lib.php
+++ b/htdocs/core/lib/report.lib.php
@@ -24,18 +24,18 @@
 
 
 /**
-*    Show header of a VAT report
+*	Show header of a VAT report
 *
-*    @param		string				$nom            Name of report
-*    @param 	string				$variante       Link for alternate report
-*    @param 	string				$period         Period of report
-*    @param 	string				$periodlink     Link to switch period
-*    @param 	string				$description    Description
-*    @param 	timestamp|integer	$builddate      Date generation
-*    @param 	string				$exportlink     Link for export or ''
-*    @param		array				$moreparam		Array with list of params to add into form
-*    @param		string				$calcmode		Calculation mode
-*    @return	void
+*	@param		string				$nom            Name of report
+*	@param 	string				$variante       Link for alternate report
+*	@param 	string				$period         Period of report
+*	@param 	string				$periodlink     Link to switch period
+*	@param 	string				$description    Description
+*	@param 	timestamp|integer	$builddate      Date generation
+*	@param 	string				$exportlink     Link for export or ''
+*	@param		array				$moreparam		Array with list of params to add into form
+*	@param		string				$calcmode		Calculation mode
+*	@return	void
 */
 function report_header($nom,$variante,$period,$periodlink,$description,$builddate,$exportlink='',$moreparam=array(),$calcmode='')
 {
@@ -55,7 +55,7 @@ function report_header($nom,$variante,$period,$periodlink,$description,$builddat
 	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
 	foreach($moreparam as $key => $value)
 	{
-	     print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
+		 print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
 	}
 	print '<table width="100%" class="border">';
 
diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php
index a163047e61b4a401ca26f8c3c134165684bb9f12..7d9ee545dea4cd874740a2f5a36c39c40aeac110 100644
--- a/htdocs/core/lib/tax.lib.php
+++ b/htdocs/core/lib/tax.lib.php
@@ -280,10 +280,11 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
             $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
             $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
             $sql.= " d.date_start as date_start, d.date_end as date_end,";
-            $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc,";
+            $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
             $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
             $sql.= " 0 as payment_id, 0 as payment_amount";
             $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
+            $sql.= " ".MAIN_DB_PREFIX."societe as s,";
             $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
             $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
             $sql.= " WHERE f.entity = " . $conf->entity;
@@ -291,6 +292,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
             if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
 			else $sql.= " AND f.type IN (0,1,2,3,5)";
             $sql.= " AND f.rowid = d.".$fk_facture;
+            $sql.= " AND s.rowid = f.fk_soc";
             if ($y && $m)
             {
                 $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
@@ -325,10 +327,11 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
             $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
             $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
             $sql.= " d.date_start as date_start, d.date_end as date_end,";
-            $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc,";
+            $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef as date_f, s.nom as company_name, s.rowid as company_id,";
             $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
             $sql.= " 0 as payment_id, 0 as payment_amount";
             $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
+            $sql.= " ".MAIN_DB_PREFIX."societe as s,";
             $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
             $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
             $sql.= " WHERE f.entity = " . $conf->entity;
@@ -336,6 +339,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
         	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
 			else $sql.= " AND f.type IN (0,1,2,3,5)";
             $sql.= " AND f.rowid = d.".$fk_facture;
+            $sql.= " AND s.rowid = f.fk_soc";
             if ($y && $m)
             {
                 $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
@@ -384,6 +388,9 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
                 }
                 $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
                 $list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
+                $list[$assoc['rate']]['datef'][] = $assoc['datef'];
+                $list[$assoc['rate']]['company_name'][] = $assoc['company_name'];
+                $list[$assoc['rate']]['company_id'][] = $assoc['company_id'];
                 $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']);
                 $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']);
 
@@ -438,10 +445,11 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
             $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
             $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
             $sql.= " d.date_start as date_start, d.date_end as date_end,";
-            $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc,";
+            $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
             $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
             $sql.= " 0 as payment_id, 0 as payment_amount";
             $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
+            $sql.= " ".MAIN_DB_PREFIX."societe as s,";
             $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
             $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
             $sql.= " WHERE f.entity = " . $conf->entity;
@@ -449,6 +457,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
         	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
 			else $sql.= " AND f.type IN (0,1,2,3,5)";
             $sql.= " AND f.rowid = d.".$fk_facture;
+            $sql.= " AND s.rowid = f.fk_soc";
             if ($y && $m)
             {
                 $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
@@ -484,12 +493,13 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
             $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
             $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
             $sql.= " d.date_start as date_start, d.date_end as date_end,";
-            $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc,";
+            $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
             $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
             $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount";
             $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
             $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
             $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
+            $sql.= " ".MAIN_DB_PREFIX."societe as s,";
             $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
             $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
             $sql.= " WHERE f.entity = " . $conf->entity;
@@ -497,6 +507,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
         	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
 			else $sql.= " AND f.type IN (0,1,2,3,5)";
             $sql.= " AND f.rowid = d.".$fk_facture;
+            $sql.= " AND s.rowid = f.fk_soc";
             $sql.= " AND pf.".$fk_facture2." = f.rowid";
             $sql.= " AND pa.rowid = pf.".$fk_payment;
             if ($y && $m)
@@ -548,6 +559,9 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
                 }
                 $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
                 $list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
+                $list[$assoc['rate']]['datef'][] = $assoc['datef'];
+                $list[$assoc['rate']]['company_name'][] = $assoc['company_name'];
+                $list[$assoc['rate']]['company_id'][] = $assoc['company_id'];
                 $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']);
                 $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']);
 
diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php
index 659590e8bdc09086feb7c47b6d2b237352f6328a..e36040743ad31916540f0bbbf4003ea398ad1364 100644
--- a/htdocs/expensereport/class/expensereport.class.php
+++ b/htdocs/expensereport/class/expensereport.class.php
@@ -29,1421 +29,1440 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
  */
 class ExpenseReport extends CommonObject
 {
-	var $db;
-	var $error;
-	var $element='expensereport';
-	var $table_element='expensereport';
-	var $table_element_line = 'expensereport_det';
-	var $fk_element = 'fk_expensereport';
-
-	var $id;
-	var $ref;
-	var $lignes=array();
-	var $total_ht;
-	var $total_tva;
-	var $total_ttc;
-	var $note_public;
-	var $note_private;
-	var $date_debut;
-	var $date_fin;
-
-	var $fk_user_validator;
-	var $status;
-	var $fk_statut;		// -- 1=draft, 2=validated (attente approb), 4=canceled, 5=approved, 6=payed, 99=denied
-	var $fk_c_paiement;
-	var $paid;
-
-	var $user_author_infos;
-	var $user_validator_infos;
+    var $db;
+    var $error;
+    var $element='expensereport';
+    var $table_element='expensereport';
+    var $table_element_line = 'expensereport_det';
+    var $fk_element = 'fk_expensereport';
+
+    var $id;
+    var $ref;
+    var $lignes=array();
+    var $total_ht;
+    var $total_tva;
+    var $total_ttc;
+    var $note_public;
+    var $note_private;
+    var $date_debut;
+    var $date_fin;
+
+    var $fk_user_validator;
+    var $status;
+    var $fk_statut;     // -- 1=draft, 2=validated (attente approb), 4=canceled, 5=approved, 6=payed, 99=denied
+    var $fk_c_paiement;
+    var $paid;
+
+    var $user_author_infos;
+    var $user_validator_infos;
 
     var $modepayment;
     var $modepaymentid;
-	var $code_paiement;
-	var $code_statut;
-
-	/*
-		ACTIONS
-	*/
-
-	// Enregistrement
-	var $date_create;
-	var $fk_user_author;
-
-	// Refus
-	var $date_refuse;
-	var $detail_refuse;
-	var $fk_user_refuse;
-
-	// Annulation
-	var $date_cancel;
-	var $detail_cancel;
-	var $fk_user_cancel;
-
-	// Validation
-	var $date_valid;
-	var	$fk_user_valid;
-	var $user_valid_infos;
-
-	// Approve
-	var $date_approve;
-	var	$fk_user_approve;
-
-	// Paiement
-	var $user_paid_infos;
-
-	/*
-		END ACTIONS
-	*/
-
-
-	/**
-	 *  Constructor
-	 *
-	 *  @param  DoliDB	$db		Handler acces base de donnees
-	 */
-	function __construct($db)
-	{
-		$this->db = $db;
-		$this->total_ht = 0;
-		$this->total_ttc = 0;
-		$this->total_tva = 0;
-		$this->modepaymentid = 0;
-
-		// List of language codes for status
+    var $code_paiement;
+    var $code_statut;
+
+    /*
+        ACTIONS
+    */
+
+    // Enregistrement
+    var $date_create;
+    var $fk_user_author;
+
+    // Refus
+    var $date_refuse;
+    var $detail_refuse;
+    var $fk_user_refuse;
+
+    // Annulation
+    var $date_cancel;
+    var $detail_cancel;
+    var $fk_user_cancel;
+
+    // Validation
+    var $date_valid;
+    var $fk_user_valid;
+    var $user_valid_infos;
+
+    // Approve
+    var $date_approve;
+    var $fk_user_approve;
+
+    // Paiement
+    var $user_paid_infos;
+
+    /*
+        END ACTIONS
+    */
+
+
+    /**
+     *  Constructor
+     *
+     *  @param  DoliDB  $db     Handler acces base de donnees
+     */
+    function __construct($db)
+    {
+        $this->db = $db;
+        $this->total_ht = 0;
+        $this->total_ttc = 0;
+        $this->total_tva = 0;
+        $this->modepaymentid = 0;
+
+        // List of language codes for status
         $this->statuts_short = array(0 => 'Draft', 2 => 'Validated', 4 => 'Canceled', 5 => 'Approved', 6 => 'Paid', 99 => 'Refused');
         $this->statuts = array(0 => 'Draft', 2 => 'ValidatedWaitingApproval', 4 => 'Canceled', 5 => 'Approved', 6 => 'Paid', 99 => 'Refused');
         $this->statuts_logo = array(0 => 'statut0', 2 => 'statut1', 4 => 'statut5', 5 => 'statut3', 6 => 'statut6', 99 => 'statut8');
 
-		return 1;
-	}
-
-	/**
-	 * Create object in database
-	 *
-	 * @param 	User	$user	User that create
-	 * @return 	int				<0 if KO, >0 if OK
-	 */
-	function create($user)
-	{
-		global $conf;
-
-		$now = dol_now();
-
-		$this->db->begin();
-
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." (";
-		$sql.= "ref";
-		$sql.= ",total_ht";
-		$sql.= ",total_ttc";
-		$sql.= ",total_tva";
-		$sql.= ",date_debut";
-		$sql.= ",date_fin";
-		$sql.= ",date_create";
-		$sql.= ",fk_user_author";
-		$sql.= ",fk_user_validator";
-		$sql.= ",fk_statut";
-		$sql.= ",fk_c_paiement";
-		$sql.= ",paid";
-		$sql.= ",note_public";
-		$sql.= ",note_private";
-		$sql.= ") VALUES(";
-		$sql.= "'(PROV)'";
-		$sql.= ", ".$this->total_ht;
-		$sql.= ", ".$this->total_ttc;
-		$sql.= ", ".$this->total_tva;
-		$sql.= ", '".$this->db->idate($this->date_debut)."'";
-		$sql.= ", '".$this->db->idate($this->date_fin)."'";
-		$sql.= ", '".$this->db->idate($now)."'";
-		$sql.= ", ".($user->id > 0 ? $user->id:"null");
-		$sql.= ", ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null");
-		$sql.= ", ".($this->fk_statut > 1 ? $this->fk_statut:0);
-		$sql.= ", ".($this->modepaymentid?$this->modepaymentid:"null");
-		$sql.= ", 0";
-		$sql.= ", ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null");
-		$sql.= ", ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null");
-		$sql.= ")";
-
-		dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
-		$result = $this->db->query($sql);
-		if ($result)
-		{
-			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
-			$this->ref='(PROV'.$this->id.')';
-
-			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET ref='".$this->ref."' WHERE rowid=".$this->id;
-			dol_syslog(get_class($this)."::create sql=".$sql);
-			$resql=$this->db->query($sql);
-			if (!$resql) $error++;
-
-			foreach ($this->lignes as $i => $val)
-			{
-				$newndfline=new ExpenseReportLine($this->db);
-				$newndfline=$this->lignes[$i];
-				$newndfline->fk_expensereport=$this->id;
-				if ($result >= 0)
-				{
-					$result=$newndfline->insert();
-				}
-				if ($result < 0)
-				{
-					$error++;
-					break;
-				}
-			}
-
-			if (! $error)
-			{
-				$result=$this->update_price();
-				if ($result > 0)
-				{
-					$this->db->commit();
-					return $this->id;
-				}
-				else
-				{
-					$this->db->rollback();
-					return -3;
-				}
-			}
-			else
-			{
-				dol_syslog(get_class($this)."::create error ".$this->error, LOG_ERR);
-				$this->db->rollback();
-				return -2;
-			}
-		}
-		else
-		{
-			$this->error=$this->db->error()." sql=".$sql;
-			$this->db->rollback();
-			return -1;
-		}
-
-	}
-
-	/**
-	 * update
-	 *
-	 * @param 	User	$user		User making change
-	 * @return 	int					<0 if KO, >0 if OK
-	 */
-	function update($user)
-	{
-		global $langs;
-
-		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
-		$sql.= " total_ht = ".$this->total_ht;
-		$sql.= " , total_ttc = ".$this->total_ttc;
-		$sql.= " , total_tva = ".$this->total_tva;
-		$sql.= " , date_debut = '".$this->db->idate($this->date_debut)."'";
-		$sql.= " , date_fin = '".$this->db->idate($this->date_fin)."'";
-		$sql.= " , fk_user_author = ".($user->id > 0 ? "'".$user->id."'":"null");
-		$sql.= " , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null");
-		$sql.= " , fk_user_valid = ".($this->fk_user_valid > 0 ? $this->fk_user_valid:"null");
-		$sql.= " , fk_statut = ".($this->fk_statut >= 0 ? $this->fk_statut:'0');
-		$sql.= " , fk_c_paiement = ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:"null");
-		$sql.= " , note_public = ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"''");
-		$sql.= " , note_private = ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"''");
-		$sql.= " , detail_refuse = ".(!empty($this->detail_refuse)?"'".$this->db->escape($this->detail_refuse)."'":"''");
-		$sql.= " WHERE rowid = ".$this->id;
-
-		dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
-		$result = $this->db->query($sql);
-		if ($result)
-		{
-			return 1;
-		}
-		else
-		{
-			$this->error=$this->db->error();
-			return -1;
-		}
-	}
-
-	/**
-	 *	Load an object from database
-	 *
-	 *	@param	int		$id		Id
-	 *	@param	string	$ref	Ref
-	 *	@return	int				<0 if KO, >0 if OK
-	 */
-	function fetch($id, $ref='')
-	{
-		global $conf;
-
-		$sql = "SELECT d.rowid, d.ref, d.note_public, d.note_private,";									// DEFAULT
-		$sql.= " d.detail_refuse, d.detail_cancel, d.fk_user_refuse, d.fk_user_cancel,"; 				// ACTIONS
-		$sql.= " d.date_refuse, d.date_cancel,";														// ACTIONS
-		$sql.= " d.total_ht, d.total_ttc, d.total_tva,"; 												// TOTAUX (int)
-		$sql.= " d.date_debut, d.date_fin, d.date_create, d.date_valid, d.date_approve,"; 			// DATES (datetime)
-		$sql.= " d.fk_user_author, d.fk_user_validator, d.fk_statut as status, d.fk_c_paiement,";
-		$sql.= " d.fk_user_valid, d.fk_user_approve,";
-		$sql.= " dp.libelle as libelle_paiement, dp.code as code_paiement";								// INNER JOIN paiement
-		$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as dp ON d.fk_c_paiement = dp.id";
-		if ($ref) $sql.= " WHERE d.ref = '".$this->db->escape($ref)."'";
-		else $sql.= " WHERE d.rowid = ".$id;
-		$sql.= $restrict;
-
-		dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
-		$resql = $this->db->query($sql) ;
-		if ($resql)
-		{
-			$obj = $this->db->fetch_object($resql);
-			if ($obj)
-			{
-				$this->id       	= $obj->rowid;
-				$this->ref          = $obj->ref;
-				$this->total_ht 	= $obj->total_ht;
-				$this->total_tva 	= $obj->total_tva;
-				$this->total_ttc 	= $obj->total_ttc;
-				$this->note_public	= $obj->note_public;
-				$this->note_private	= $obj->note_private;
-				$this->detail_refuse = $obj->detail_refuse;
-				$this->detail_cancel = $obj->detail_cancel;
-
-				$this->date_debut		= $this->db->jdate($obj->date_debut);
-				$this->date_fin			= $this->db->jdate($obj->date_fin);
-				$this->date_valid		= $this->db->jdate($obj->date_valid);
-				$this->date_approve		= $this->db->jdate($obj->date_approve);
-				$this->date_create		= $this->db->jdate($obj->date_create);
-				$this->date_refuse		= $this->db->jdate($obj->date_refuse);
-				$this->date_cancel		= $this->db->jdate($obj->date_cancel);
-
-				$this->fk_user_author			= $obj->fk_user_author;
-				$this->fk_user_validator		= $obj->fk_user_validator;
-				$this->fk_user_valid			= $obj->fk_user_valid;
-				$this->fk_user_refuse			= $obj->fk_user_refuse;
-				$this->fk_user_cancel			= $obj->fk_user_cancel;
-				$this->fk_user_approve			= $obj->fk_user_approve;
-
-				$user_author = new User($this->db);
-				if ($this->fk_user_author > 0) $user_author->fetch($this->fk_user_author);
-
-				$this->user_author_infos = dolGetFirstLastname($user_author->firstname, $user_author->lastname);
-
-				$user_approver = new User($this->db);
-				if ($this->fk_user_validator > 0) $user_approver->fetch($this->fk_user_validator);
-				$this->user_validator_infos = dolGetFirstLastname($user_approver->firstname, $user_approver->lastname);
-
-				$this->fk_statut 				= $obj->status;
-				$this->status                   = $obj->status;
-				$this->fk_c_paiement			= $obj->fk_c_paiement;
-				$this->paid						= $obj->paid;
-
-				if ($this->fk_statut==5 || $this->fk_statut==6)
-				{
-					$user_valid = new User($this->db);
-					if ($this->fk_user_valid > 0) $user_valid->fetch($this->fk_user_valid);
-					$this->user_valid_infos = dolGetFirstLastname($user_valid->firstname, $user_valid->lastname);
-				}
-
-				$this->libelle_statut 	= $obj->libelle_statut;
-				$this->libelle_paiement = $obj->libelle_paiement;
-				$this->code_statut 		= $obj->code_statut;
-				$this->code_paiement 	= $obj->code_paiement;
-
-				$this->lignes = array();	// deprecated
-				$this->lines = array();
-
-				$result=$this->fetch_lines();
-
-				return $result;
-			}
-			else
-			{
-				return 0;
-			}
-		}
-		else
-		{
-			$this->error=$this->db->lasterror();
-			return -1;
-		}
-	}
+        return 1;
+    }
+
+    /**
+     * Create object in database
+     *
+     * @param   User    $user   User that create
+     * @return  int             <0 if KO, >0 if OK
+     */
+    function create($user)
+    {
+        global $conf;
+
+        $now = dol_now();
+
+        $this->db->begin();
+
+        $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." (";
+        $sql.= "ref";
+        $sql.= ",total_ht";
+        $sql.= ",total_ttc";
+        $sql.= ",total_tva";
+        $sql.= ",date_debut";
+        $sql.= ",date_fin";
+        $sql.= ",date_create";
+        $sql.= ",fk_user_author";
+        $sql.= ",fk_user_validator";
+        $sql.= ",fk_statut";
+        $sql.= ",fk_c_paiement";
+        $sql.= ",paid";
+        $sql.= ",note_public";
+        $sql.= ",note_private";
+        $sql.= ") VALUES(";
+        $sql.= "'(PROV)'";
+        $sql.= ", ".$this->total_ht;
+        $sql.= ", ".$this->total_ttc;
+        $sql.= ", ".$this->total_tva;
+        $sql.= ", '".$this->db->idate($this->date_debut)."'";
+        $sql.= ", '".$this->db->idate($this->date_fin)."'";
+        $sql.= ", '".$this->db->idate($now)."'";
+        $sql.= ", ".($user->id > 0 ? $user->id:"null");
+        $sql.= ", ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null");
+        $sql.= ", ".($this->fk_statut > 1 ? $this->fk_statut:0);
+        $sql.= ", ".($this->modepaymentid?$this->modepaymentid:"null");
+        $sql.= ", 0";
+        $sql.= ", ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null");
+        $sql.= ", ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null");
+        $sql.= ")";
+
+        dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
+        $result = $this->db->query($sql);
+        if ($result)
+        {
+            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
+            $this->ref='(PROV'.$this->id.')';
+
+            $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET ref='".$this->ref."' WHERE rowid=".$this->id;
+            dol_syslog(get_class($this)."::create sql=".$sql);
+            $resql=$this->db->query($sql);
+            if (!$resql) $error++;
+
+            foreach ($this->lignes as $i => $val)
+            {
+                $newndfline=new ExpenseReportLine($this->db);
+                $newndfline=$this->lignes[$i];
+                $newndfline->fk_expensereport=$this->id;
+                if ($result >= 0)
+                {
+                    $result=$newndfline->insert();
+                }
+                if ($result < 0)
+                {
+                    $error++;
+                    break;
+                }
+            }
+
+            if (! $error)
+            {
+                $result=$this->update_price();
+                if ($result > 0)
+                {
+                    $this->db->commit();
+                    return $this->id;
+                }
+                else
+                {
+                    $this->db->rollback();
+                    return -3;
+                }
+            }
+            else
+            {
+                dol_syslog(get_class($this)."::create error ".$this->error, LOG_ERR);
+                $this->db->rollback();
+                return -2;
+            }
+        }
+        else
+        {
+            $this->error=$this->db->error()." sql=".$sql;
+            $this->db->rollback();
+            return -1;
+        }
+
+    }
+
+    /**
+     * update
+     *
+     * @param   User    $user       User making change
+     * @return  int                 <0 if KO, >0 if OK
+     */
+    function update($user)
+    {
+        global $langs;
+
+        $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
+        $sql.= " total_ht = ".$this->total_ht;
+        $sql.= " , total_ttc = ".$this->total_ttc;
+        $sql.= " , total_tva = ".$this->total_tva;
+        $sql.= " , date_debut = '".$this->db->idate($this->date_debut)."'";
+        $sql.= " , date_fin = '".$this->db->idate($this->date_fin)."'";
+        $sql.= " , fk_user_author = ".($user->id > 0 ? "'".$user->id."'":"null");
+        $sql.= " , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null");
+        $sql.= " , fk_user_valid = ".($this->fk_user_valid > 0 ? $this->fk_user_valid:"null");
+        $sql.= " , fk_statut = ".($this->fk_statut >= 0 ? $this->fk_statut:'0');
+        $sql.= " , fk_c_paiement = ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:"null");
+        $sql.= " , note_public = ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"''");
+        $sql.= " , note_private = ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"''");
+        $sql.= " , detail_refuse = ".(!empty($this->detail_refuse)?"'".$this->db->escape($this->detail_refuse)."'":"''");
+        $sql.= " WHERE rowid = ".$this->id;
+
+        dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
+        $result = $this->db->query($sql);
+        if ($result)
+        {
+            return 1;
+        }
+        else
+        {
+            $this->error=$this->db->error();
+            return -1;
+        }
+    }
+
+    /**
+     *  Load an object from database
+     *
+     *  @param  int     $id     Id
+     *  @param  string  $ref    Ref
+     *  @return int             <0 if KO, >0 if OK
+     */
+    function fetch($id, $ref='')
+    {
+        global $conf;
+
+        $sql = "SELECT d.rowid, d.ref, d.note_public, d.note_private,";                                 // DEFAULT
+        $sql.= " d.detail_refuse, d.detail_cancel, d.fk_user_refuse, d.fk_user_cancel,";                // ACTIONS
+        $sql.= " d.date_refuse, d.date_cancel,";                                                        // ACTIONS
+        $sql.= " d.total_ht, d.total_ttc, d.total_tva,";                                                // TOTAUX (int)
+        $sql.= " d.date_debut, d.date_fin, d.date_create, d.date_valid, d.date_approve,";           // DATES (datetime)
+        $sql.= " d.fk_user_author, d.fk_user_validator, d.fk_statut as status, d.fk_c_paiement,";
+        $sql.= " d.fk_user_valid, d.fk_user_approve,";
+        $sql.= " dp.libelle as libelle_paiement, dp.code as code_paiement";                             // INNER JOIN paiement
+        $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as dp ON d.fk_c_paiement = dp.id";
+        if ($ref) $sql.= " WHERE d.ref = '".$this->db->escape($ref)."'";
+        else $sql.= " WHERE d.rowid = ".$id;
+        $sql.= $restrict;
+
+        dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
+        $resql = $this->db->query($sql) ;
+        if ($resql)
+        {
+            $obj = $this->db->fetch_object($resql);
+            if ($obj)
+            {
+                $this->id           = $obj->rowid;
+                $this->ref          = $obj->ref;
+                $this->total_ht     = $obj->total_ht;
+                $this->total_tva    = $obj->total_tva;
+                $this->total_ttc    = $obj->total_ttc;
+                $this->note_public  = $obj->note_public;
+                $this->note_private = $obj->note_private;
+                $this->detail_refuse = $obj->detail_refuse;
+                $this->detail_cancel = $obj->detail_cancel;
+
+                $this->date_debut       = $this->db->jdate($obj->date_debut);
+                $this->date_fin         = $this->db->jdate($obj->date_fin);
+                $this->date_valid       = $this->db->jdate($obj->date_valid);
+                $this->date_approve     = $this->db->jdate($obj->date_approve);
+                $this->date_create      = $this->db->jdate($obj->date_create);
+                $this->date_refuse      = $this->db->jdate($obj->date_refuse);
+                $this->date_cancel      = $this->db->jdate($obj->date_cancel);
+
+                $this->fk_user_author           = $obj->fk_user_author;
+                $this->fk_user_validator        = $obj->fk_user_validator;
+                $this->fk_user_valid            = $obj->fk_user_valid;
+                $this->fk_user_refuse           = $obj->fk_user_refuse;
+                $this->fk_user_cancel           = $obj->fk_user_cancel;
+                $this->fk_user_approve          = $obj->fk_user_approve;
+
+                $user_author = new User($this->db);
+                if ($this->fk_user_author > 0) $user_author->fetch($this->fk_user_author);
+
+                $this->user_author_infos = dolGetFirstLastname($user_author->firstname, $user_author->lastname);
+
+                $user_approver = new User($this->db);
+                if ($this->fk_user_validator > 0) $user_approver->fetch($this->fk_user_validator);
+                $this->user_validator_infos = dolGetFirstLastname($user_approver->firstname, $user_approver->lastname);
+
+                $this->fk_statut                = $obj->status;
+                $this->status                   = $obj->status;
+                $this->fk_c_paiement            = $obj->fk_c_paiement;
+                $this->paid                     = $obj->paid;
+
+                if ($this->fk_statut==5 || $this->fk_statut==6)
+                {
+                    $user_valid = new User($this->db);
+                    if ($this->fk_user_valid > 0) $user_valid->fetch($this->fk_user_valid);
+                    $this->user_valid_infos = dolGetFirstLastname($user_valid->firstname, $user_valid->lastname);
+                }
+
+                $this->libelle_statut   = $obj->libelle_statut;
+                $this->libelle_paiement = $obj->libelle_paiement;
+                $this->code_statut      = $obj->code_statut;
+                $this->code_paiement    = $obj->code_paiement;
+
+                $this->lignes = array();    // deprecated
+                $this->lines = array();
+
+                $result=$this->fetch_lines();
+
+                return $result;
+            }
+            else
+            {
+                return 0;
+            }
+        }
+        else
+        {
+            $this->error=$this->db->lasterror();
+            return -1;
+        }
+    }
+
+    /**
+     *    Classify the expense report as paid
+     *
+     *    @param    int     $id                 Id of expense report
+     *    @param    user    $fuser              User making change
+     *    @return   int                         <0 if KO, >0 if OK
+     */
+    function set_paid($id, $fuser)
+    {
+        $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport";
+        $sql.= " SET fk_statut = 6";
+        $sql.= " WHERE rowid = ".$id." AND fk_statut = 5";
+
+        dol_syslog(get_class($this)."::set_paid sql=".$sql, LOG_DEBUG);
+        $resql=$this->db->query($sql);
+        if ($resql)
+        {
+            if ($this->db->affected_rows($resql))
+            {
+                return 1;
+            }
+            else
+            {
+                return 0;
+            }
+        }
+        else
+        {
+            dol_print_error($this->db);
+            return -1;
+        }
+    }
+
+    /**
+     *  Returns the label status
+     *
+     *  @param      int     $mode       0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
+     *  @return     string              Label
+     */
+    function getLibStatut($mode=0)
+    {
+        return $this->LibStatut($this->status,$mode);
+    }
+
+    /**
+     *  Returns the label of a statut
+     *
+     *  @param      int     $status     id statut
+     *  @param      int     $mode       0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
+     *  @return     string              Label
+     */
+    function LibStatut($status,$mode=0)
+    {
+        global $langs;
+
+        if ($mode == 0)
+            return $langs->trans($this->statuts[$status]);
+
+        if ($mode == 1)
+            return $langs->trans($this->statuts_short[$status]);
+
+        if ($mode == 2)
+            return img_picto($langs->trans($this->statuts_short[$status]), $this->statuts_logo[$status]).' '.$langs->trans($this->statuts_short[$status]);
+
+        if ($mode == 3)
+            return img_picto($langs->trans($this->statuts_short[$status]), $this->statuts_logo[$status]);
+
+        if ($mode == 4)
+            return img_picto($langs->trans($this->statuts_short[$status]),$this->statuts_logo[$status]).' '.$langs->trans($this->statuts[$status]);
+
+        if ($mode == 5)
+            return '<span class="hideonsmartphone">'.$langs->trans($this->statuts_short[$status]).' </span>'.img_picto($langs->trans($this->statuts_short[$status]),$this->statuts_logo[$status]);
+
+    }
+
+
+    /**
+     *  Load information on object
+     *
+     *  @param  int     $id      Id of object
+     *  @return void
+     */
+    function info($id)
+    {
+        global $conf;
+
+        $sql = "SELECT f.rowid,";
+        $sql.= " f.date_create as datec,";
+        $sql.= " f.tms as date_modification,";
+        $sql.= " f.date_valid as datev,";
+        $sql.= " f.date_approve as datea,";
+        $sql.= " f.fk_user_author as fk_user_creation,";
+        $sql.= " f.fk_user_modif as fk_user_modification,";
+        $sql.= " f.fk_user_valid,";
+        $sql.= " f.fk_user_approve";
+        $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as f";
+        $sql.= " WHERE f.rowid = ".$id;
+        $sql.= " AND f.entity = ".$conf->entity;
+
+        $resql = $this->db->query($sql);
+        if ($resql)
+        {
+            if ($this->db->num_rows($resql))
+            {
+                $obj = $this->db->fetch_object($resql);
+
+                $this->id                = $obj->rowid;
+
+                $this->date_creation     = $this->db->jdate($obj->datec);
+                $this->date_modification = $this->db->jdate($obj->date_modification);
+                $this->date_validation   = $this->db->jdate($obj->datev);
+                $this->date_approbation  = $this->db->jdate($obj->datea);
+
+                $cuser = new User($this->db);
+                $cuser->fetch($obj->fk_user_author);
+                $this->user_creation     = $cuser;
+
+                if ($obj->fk_user_creation)
+                {
+                    $cuser = new User($this->db);
+                    $cuser->fetch($obj->fk_user_creation);
+                    $this->user_creation     = $cuser;
+                }
+                if ($obj->fk_user_valid)
+                {
+                    $vuser = new User($this->db);
+                    $vuser->fetch($obj->fk_user_valid);
+                    $this->user_validation     = $vuser;
+                }
+                if ($obj->fk_user_modification)
+                {
+                    $muser = new User($this->db);
+                    $muser->fetch($obj->fk_user_modification);
+                    $this->user_modification   = $muser;
+                }
+
+            }
+            $this->db->free($resql);
+        }
+        else
+        {
+            dol_print_error($this->db);
+        }
+    }
+
+
+
+    /**
+     *  Initialise an instance with random values.
+     *  Used to build previews or test instances.
+     *  id must be 0 if object instance is a specimen.
+     *
+     *  @return void
+     */
+    function initAsSpecimen()
+    {
+        global $user,$langs,$conf;
+
+        $now=dol_now();
+
+        // Initialise parametres
+        $this->id=0;
+        $this->ref = 'SPECIMEN';
+        $this->specimen=1;
+        $this->date_create = $now;
+        $this->date_debut = $now;
+        $this->date_fin = $now;
+        $this->date_approve = $now;
+
+        $this->status = 5;
+        $this->fk_statut = 5;
+
+        $this->fk_user_author = $user->id;
+        $this->fk_user_valid = $user->id;
+        $this->fk_user_approve = $user->id;
+        $this->fk_user_validator = $user->id;
+
+        $this->note_private='Private note';
+        $this->note_public='SPECIMEN';
+        $nbp = 5;
+        $xnbp = 0;
+        while ($xnbp < $nbp)
+        {
+            $line=new ExpenseReportLine($this->db);
+            $line->comments=$langs->trans("Comment")." ".$xnbp;
+            $line->date=($now-3600*(1+$xnbp));
+            $line->total_ht=100;
+            $line->total_tva=20;
+            $line->total_ttc=120;
+            $line->qty=1;
+            $line->vatrate=20;
+            $line->value_unit=120;
+            $line->fk_expensereport=0;
+            $line->type_fees_code='TRA';
+
+            $line->projet_ref = 'ABC';
+
+            $this->lines[$xnbp]=$line;
+            $xnbp++;
+
+            $this->total_ht+=$line->total_ht;
+            $this->total_tva+=$line->total_tva;
+            $this->total_ttc+=$line->total_ttc;
+        }
+    }
+
+    /**
+     * fetch_line_by_project
+     *
+     * @param   int     $projectid      Project id
+     * @param   User    $user           User
+     * @return  int                     <0 if KO, >0 if OK
+     */
+    function fetch_line_by_project($projectid,$user='')
+    {
+        global $conf,$db,$langs;
+
+        $langs->load('trips');
+
+        if($user->rights->expensereport->lire) {
+
+            $sql = "SELECT de.fk_expensereport, de.date, de.comments, de.total_ht, de.total_ttc";
+            $sql.= " FROM ".MAIN_DB_PREFIX."expensereport_det as de";
+            $sql.= " WHERE de.fk_projet = ".$projectid;
+
+            dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
+            $result = $db->query($sql) ;
+            if ($result)
+            {
+                $num = $db->num_rows($result);
+                $i = 0;
+                $total_HT = 0;
+                $total_TTC = 0;
+
+                while ($i < $num)
+                {
+
+                    $objp = $db->fetch_object($result);
+
+                    $sql2 = "SELECT d.rowid, d.fk_user_author, d.ref, d.fk_statut";
+                    $sql2.= " FROM ".MAIN_DB_PREFIX."expensereport as d";
+                    $sql2.= " WHERE d.rowid = '".$objp->fk_expensereport."'";
+
+                    $result2 = $db->query($sql2);
+                    $obj = $db->fetch_object($result2);
+
+                    $objp->fk_user_author = $obj->fk_user_author;
+                    $objp->ref = $obj->ref;
+                    $objp->fk_c_expensereport_status = $obj->fk_statut;
+                    $objp->rowid = $obj->rowid;
+
+                    $total_HT = $total_HT + $objp->total_ht;
+                    $total_TTC = $total_TTC + $objp->total_ttc;
+                    $author = new User($db);
+                    $author->fetch($objp->fk_user_author);
+
+                    print '<tr>';
+                    print '<td><a href="'.DOL_URL_ROOT.'/expensereport/card.php?id='.$objp->rowid.'">'.$objp->ref_num.'</a></td>';
+                    print '<td align="center">'.dol_print_date($objp->date,'day').'</td>';
+                    print '<td>'.$author->getNomUrl().'</td>';
+                    print '<td>'.$objp->comments.'</td>';
+                    print '<td align="right">'.price($objp->total_ht).'</td>';
+                    print '<td align="right">'.price($objp->total_ttc).'</td>';
+                    print '<td align="right">';
+
+                    switch($objp->fk_c_expensereport_status) {
+                        case 4:
+                            print img_picto($langs->trans('StatusOrderCanceled'),'statut5');
+                            break;
+                        case 1:
+                            print $langs->trans('Draft').' '.img_picto($langs->trans('Draft'),'statut0');
+                            break;
+                        case 2:
+                            print $langs->trans('TripForValid').' '.img_picto($langs->trans('TripForValid'),'statut3');
+                            break;
+                        case 5:
+                            print $langs->trans('TripForPaid').' '.img_picto($langs->trans('TripForPaid'),'statut3');
+                            break;
+                        case 6:
+                            print $langs->trans('TripPaid').' '.img_picto($langs->trans('TripPaid'),'statut4');
+                            break;
+                    }
+                    /*
+                     if ($status==4) return img_picto($langs->trans('StatusOrderCanceled'),'statut5');
+                    if ($status==1) return img_picto($langs->trans('StatusOrderDraft'),'statut0');
+                    if ($status==2) return img_picto($langs->trans('StatusOrderValidated'),'statut1');
+                    if ($status==2) return img_picto($langs->trans('StatusOrderOnProcess'),'statut3');
+                    if ($status==5) return img_picto($langs->trans('StatusOrderToBill'),'statut4');
+                    if ($status==6) return img_picto($langs->trans('StatusOrderOnProcess'),'statut6');
+                    */
+                    print '</td>';
+                    print '</tr>';
+
+                    $i++;
+                }
+
+                print '<tr class="liste_total"><td colspan="4">'.$langs->trans("Number").': '.$i.'</td>';
+                print '<td align="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_HT).'</td>';
+                print '<td align="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_TTC).'</td>';
+                print '<td>&nbsp;</td>';
+                print '</tr>';
+
+            }
+            else
+            {
+                $this->error=$db->error();
+                return -1;
+            }
+        }
+
+    }
+
+    /**
+     * recalculer
+     * TODO Replace this with call to update_price if not already done
+     *
+     * @param   int         $id     Id of expense report
+     * @return  int                 <0 if KO, >0 if OK
+     */
+    function recalculer($id)
+    {
+        $sql = 'SELECT tt.total_ht, tt.total_ttc, tt.total_tva';
+        $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as tt';
+        $sql.= ' WHERE tt.'.$this->fk_element.' = '.$id;
+
+        $total_ht = 0; $total_tva = 0; $total_ttc = 0;
+
+        dol_syslog('ExpenseReport::recalculer sql='.$sql,LOG_DEBUG);
+
+        $result = $this->db->query($sql);
+        if($result)
+        {
+            $num = $this->db->num_rows($result);
+            $i = 0;
+            while ($i < $num):
+            $objp = $this->db->fetch_object($result);
+            $total_ht+=$objp->total_ht;
+            $total_tva+=$objp->total_tva;
+            $i++;
+            endwhile;
+
+            $total_ttc = $total_ht + $total_tva;
+            $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
+            $sql.= " total_ht = ".$total_ht;
+            $sql.= " , total_ttc = ".$total_ttc;
+            $sql.= " , total_tva = ".$total_tva;
+            $sql.= " WHERE rowid = ".$id;
+            $result = $this->db->query($sql);
+            if($result):
+            $this->db->free($result);
+            return 1;
+            else:
+            $this->error=$this->db->error();
+            dol_syslog('ExpenseReport::recalculer: Error '.$this->error,LOG_ERR);
+            return -3;
+            endif;
+        }
+        else
+        {
+            $this->error=$this->db->error();
+            dol_syslog('ExpenseReport::recalculer: Error '.$this->error,LOG_ERR);
+            return -3;
+        }
+    }
+
+    /**
+     * fetch_lines
+     *
+     * @return  int     <0 if OK, >0 if KO
+     */
+    function fetch_lines()
+    {
+        $this->lines=array();
+
+        $sql = ' SELECT de.rowid, de.comments, de.qty, de.value_unit, de.date,';
+        $sql.= ' de.'.$this->fk_element.', de.fk_c_type_fees, de.fk_projet, de.tva_tx as vatrate,';
+        $sql.= ' de.total_ht, de.total_tva, de.total_ttc,';
+        $sql.= ' ctf.code as code_type_fees, ctf.label as libelle_type_fees,';
+        $sql.= ' p.ref as ref_projet, p.title as title_projet';
+        $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as de';
+        $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id';
+        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as p ON de.fk_projet = p.rowid';
+        $sql.= ' WHERE de.'.$this->fk_element.' = '.$this->id;
+
+        dol_syslog('ExpenseReport::fetch_lines sql='.$sql, LOG_DEBUG);
+        $resql = $this->db->query($sql);
+        if ($resql)
+        {
+            $num = $this->db->num_rows($resql);
+            $i = 0;
+            while ($i < $num)
+            {
+                $objp = $this->db->fetch_object($resql);
+
+                $deplig = new ExpenseReportLine($this->db);
+
+                $deplig->rowid          = $objp->rowid;
+                $deplig->comments       = $objp->comments;
+                $deplig->qty            = $objp->qty;
+                $deplig->value_unit     = $objp->value_unit;
+                $deplig->date           = $objp->date;
+
+                $deplig->fk_expensereport = $objp->fk_expensereport;
+                $deplig->fk_c_type_fees = $objp->fk_c_type_fees;
+                $deplig->fk_projet      = $objp->fk_projet;
+
+                $deplig->total_ht       = $objp->total_ht;
+                $deplig->total_tva      = $objp->total_tva;
+                $deplig->total_ttc      = $objp->total_ttc;
+
+                $deplig->type_fees_code     = $objp->code_type_fees;
+                $deplig->type_fees_libelle  = $objp->libelle_type_fees;
+                $deplig->vatrate            = $objp->vatrate;
+                $deplig->projet_ref         = $objp->ref_projet;
+                $deplig->projet_title       = $objp->title_projet;
+
+                $this->lignes[$i] = $deplig;
+                $this->lines[$i] = $deplig;
+
+                $i++;
+            }
+            $this->db->free($resql);
+            return 1;
+        }
+        else
+        {
+            $this->error=$this->db->lasterror();
+            dol_syslog('ExpenseReport::fetch_lines: Error '.$this->error, LOG_ERR);
+            return -3;
+        }
+    }
+
+
+    /**
+     * delete
+     *
+     * @param   int     $rowid      Id to delete (optional)
+     * @param   User    $fuser      User that delete
+     * @return  int                 <0 if KO, >0 if OK
+     */
+    function delete($rowid=0, User $fuser=null)
+    {
+        global $user,$langs,$conf;
+
+        if (! $rowid) $rowid=$this->id;
+
+        $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line.' WHERE '.$this->fk_element.' = '.$rowid;
+        if ($this->db->query($sql))
+        {
+            $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid = '.$rowid;
+            $resql=$this->db->query($sql);
+            if ($resql)
+            {
+                $this->db->commit();
+                return 1;
+            }
+            else
+            {
+                $this->error=$this->db->error()." sql=".$sql;
+                dol_syslog("ExpenseReport.class::delete ".$this->error, LOG_ERR);
+                $this->db->rollback();
+                return -6;
+            }
+        }
+        else
+        {
+            $this->error=$this->db->error()." sql=".$sql;
+            dol_syslog("ExpenseReport.class::delete ".$this->error, LOG_ERR);
+            $this->db->rollback();
+            return -4;
+        }
+    }
+
+    /**
+     * Set to status validate
+     *
+     * @param   User    $fuser      User
+     * @return  int                 <0 if KO, >0 if OK
+     */
+    function setValidate($fuser)
+    {
+        global $conf,$langs;
+
+        $expld_car = (empty($conf->global->NDF_EXPLODE_CHAR))?"-":$conf->global->NDF_EXPLODE_CHAR;
+
+        // Sélection du numéro de ref suivant
+        $ref_next = $this->getNextNumRef();
+        $ref_number_int = ($this->ref+1)-1;
+
+        // Sélection de la date de début de la NDF
+        $sql = 'SELECT date_debut';
+        $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
+        $sql.= ' WHERE rowid = '.$this->id;
+        $result = $this->db->query($sql);
+        $objp = $this->db->fetch_object($result);
+        $this->date_debut = $this->db->jdate($objp->date_debut);
+
+        // Création du ref_number suivant
+        if($ref_next)
+        {
+            $prefix="ER";
+            if (! empty($conf->global->EXPENSE_REPORT_PREFIX)) $prefix=$conf->global->EXPENSE_REPORT_PREFIX;
+            $this->ref = strtoupper($fuser->login).$expld_car.$prefix.$this->ref.$expld_car.dol_print_date($this->date_debut,'%y%m%d');
+        }
+
+        if ($this->fk_statut != 2)
+        {
+            $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+            $sql.= " SET ref = '".$this->ref."', fk_statut = 2, fk_user_valid = ".$fuser->id.",";
+            $sql.= " ref_number_int = ".$ref_number_int;
+            $sql.= ' WHERE rowid = '.$this->id;
+
+            dol_syslog(get_class($this)."::set_save sql=".$sql, LOG_DEBUG);
+
+            if ($this->db->query($sql))
+            {
+                return 1;
+            }
+            else
+            {
+                $this->error=$this->db->error();
+                return -1;
+            }
+        }
+        else
+        {
+            dol_syslog(get_class($this)."::set_save expensereport already with save status", LOG_WARNING);
+        }
+    }
+
+    /**
+     * set_save_from_refuse
+     *
+     * @param   User    $fuser      User
+     * @return  int                 <0 if KO, >0 if OK
+     */
+    function set_save_from_refuse($fuser)
+    {
+        global $conf,$langs;
+
+        // Sélection de la date de début de la NDF
+        $sql = 'SELECT date_debut';
+        $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
+        $sql.= ' WHERE rowid = '.$this->id;
+
+        $result = $this->db->query($sql);
+
+        $objp = $this->db->fetch_object($result);
+
+        $this->date_debut = $this->db->jdate($objp->date_debut);
+
+        if ($this->fk_statut != 2)
+        {
+            $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+            $sql.= " SET fk_statut = 2";
+            $sql.= ' WHERE rowid = '.$this->id;
+
+            dol_syslog(get_class($this)."::set_save_from_refuse sql=".$sql, LOG_DEBUG);
+
+            if ($this->db->query($sql))
+            {
+                return 1;
+            }
+            else
+            {
+                $this->error=$this->db->lasterror();
+                return -1;
+            }
+        }
+        else
+        {
+            dol_syslog(get_class($this)."::set_save_from_refuse expensereport already with save status", LOG_WARNING);
+        }
+    }
+
+    /**
+     * Set status to approved
+     *
+     * @param   User    $fuser      User
+     * @return  int                 <0 if KO, >0 if OK
+     */
+    function setApproved($fuser)
+    {
+        $now=dol_now();
+
+        // date approval
+        $this->date_approve = $this->db->idate($now);
+        if ($this->fk_statut != 5)
+        {
+            $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+            $sql.= " SET ref = '".$this->ref."', fk_statut = 5, fk_user_approve = ".$fuser->id.",";
+            $sql.= " date_approve='".$this->date_approve."'";
+            $sql.= ' WHERE rowid = '.$this->id;
+            if ($this->db->query($sql))
+            {
+                return 1;
+            }
+            else
+            {
+                $this->error=$this->db->lasterror();
+                return -1;
+            }
+        }
+        else
+        {
+            dol_syslog(get_class($this)."::set_valide expensereport already with valide status", LOG_WARNING);
+        }
+    }
+
+    /**
+     * setDeny
+     *
+     * @param User      $fuser      User
+     * @param Details   $details    Details
+     */
+    function setDeny($fuser,$details)
+    {
+        $now = dol_now();
+
+        // date de refus
+        if ($this->fk_statut != 99)
+        {
+            $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+            $sql.= " SET ref = '".$this->ref."', fk_statut = 99, fk_user_refuse = ".$fuser->id.",";
+            $sql.= " date_refuse='".$this->db->idate($now)."',";
+            $sql.= " detail_refuse='".$this->db->escape($details)."'";
+            $sql.= " fk_user_approve=NULL,";
+            $sql.= ' WHERE rowid = '.$this->id;
+            if ($this->db->query($sql))
+            {
+                $this->fk_statut = 99;
+                $this->fk_user_refuse = $fuser->id;
+                $this->detail_refuse = $details;
+                $this->date_refuse = $now;
+                return 1;
+            }
+            else
+            {
+                $this->error=$this->db->lasterror();
+                return -1;
+            }
+        }
+        else
+        {
+            dol_syslog(get_class($this)."::setDeny expensereport already with refuse status", LOG_WARNING);
+        }
+    }
 
     /**
-     *    Classify the expense report as paid
+     * set_unpaid
      *
-     *    @param	int		$id           	    Id of expense report
-     *    @param	user	$fuser				User making change
-	 *    @return   int      					<0 if KO, >0 if OK
+     * @param   User    $fuser      User
+     * @return  int                 <0 if KO, >0 if OK
      */
-    function set_paid($id, $fuser)
+    function set_unpaid($fuser)
     {
-        $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport";
-		$sql.= " SET fk_statut = 6";
-        $sql.= " WHERE rowid = ".$id." AND fk_statut = 5";
+        if ($this->fk_c_deplacement_statuts != 5)
+        {
+            $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+            $sql.= " SET fk_statut = 5";
+            $sql.= ' WHERE rowid = '.$this->id;
 
-		dol_syslog(get_class($this)."::set_paid sql=".$sql, LOG_DEBUG);
-        $resql=$this->db->query($sql);
-        if ($resql)
+            dol_syslog(get_class($this)."::set_unpaid sql=".$sql, LOG_DEBUG);
+
+            if ($this->db->query($sql)):
+            return 1;
+            else:
+            $this->error=$this->db->error();
+            return -1;
+            endif;
+        }
+        else
         {
-            if ($this->db->affected_rows($resql))
+            dol_syslog(get_class($this)."::set_unpaid expensereport already with unpaid status", LOG_WARNING);
+        }
+    }
+
+    /**
+     * set_cancel
+     *
+     * @param   User    $fuser      User
+     * @param   string  $detail     Detail
+     * @return  int                 <0 if KO, >0 if OK
+     */
+    function set_cancel($fuser,$detail)
+    {
+        $this->date_cancel = $this->db->idate(gmmktime());
+        if ($this->fk_statut != 4)
+        {
+            $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+            $sql.= " SET fk_statut = 4, fk_user_cancel = ".$fuser->id;
+            $sql.= ", date_cancel='".$this->date_cancel."'";
+            $sql.= " ,detail_cancel='".$this->db->escape($detail)."'";
+            $sql.= ' WHERE rowid = '.$this->id;
+
+            dol_syslog(get_class($this)."::set_cancel sql=".$sql, LOG_DEBUG);
+
+            if ($this->db->query($sql))
+            {
+                return 1;
+            }
+            else
+            {
+                $this->error=$this->db->error();
+                return -1;
+            }
+        }
+        else
+        {
+            dol_syslog(get_class($this)."::set_cancel expensereport already with cancel status", LOG_WARNING);
+        }
+    }
+
+    /**
+     * Return next reference of expense report not already used
+     *
+     * @return    string            free ref
+     */
+    function getNextNumRef()
+    {
+        global $conf;
+
+        $expld_car = (empty($conf->global->NDF_EXPLODE_CHAR))?"-":$conf->global->NDF_EXPLODE_CHAR;
+        $num_car = (empty($conf->global->NDF_NUM_CAR_REF))?"5":$conf->global->NDF_NUM_CAR_REF;
+
+        $sql = 'SELECT de.ref_number_int';
+        $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' de';
+        $sql.= ' ORDER BY de.ref_number_int DESC';
+
+        $result = $this->db->query($sql);
+
+        if($this->db->num_rows($result) > 0):
+        $objp = $this->db->fetch_object($result);
+        $this->ref = $objp->ref_number_int;
+        $this->ref++;
+        while(strlen($this->ref) < $num_car):
+        $this->ref = "0".$this->ref;
+        endwhile;
+        else:
+        $this->ref = 1;
+        while(strlen($this->ref) < $num_car):
+        $this->ref = "0".$this->ref;
+        endwhile;
+        endif;
+
+        if ($result):
+        return 1;
+        else:
+        $this->error=$this->db->error();
+        return -1;
+        endif;
+    }
+
+    /**
+     *  Return clicable name (with picto eventually)
+     *
+     *  @param      int     $withpicto      0=No picto, 1=Include picto into link, 2=Only picto
+     *  @return     string                  String with URL
+     */
+    function getNomUrl($withpicto=0)
+    {
+        global $langs;
+
+        $result='';
+
+        $link = '<a href="'.DOL_URL_ROOT.'/expensereport/card.php?id='.$this->id.'">';
+        $linkend='</a>';
+
+        $picto='trip';
+
+        $label=$langs->trans("Show").': '.$this->ref;
+
+        if ($withpicto) $result.=($link.img_object($label,$picto).$linkend);
+        if ($withpicto && $withpicto != 2) $result.=' ';
+        if ($withpicto != 2) $result.=$link.$this->ref.$linkend;
+        return $result;
+    }
+
+    /**
+     *  Update total of an expense report when you add a line.
+     *
+     *  @param    string    $ligne_total_ht    Amount without taxes
+     *  @param    string    $ligne_total_tva    Amount of all taxes
+     *  @return    void
+     */
+    function update_totaux_add($ligne_total_ht,$ligne_total_tva)
+    {
+        $this->total_ht = $this->total_ht + $ligne_total_ht;
+        $this->total_tva = $this->total_tva + $ligne_total_tva;
+        $this->total_ttc = $this->total_ht + $this->total_tva;
+
+        $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
+        $sql.= " total_ht = ".$this->total_ht;
+        $sql.= " , total_ttc = ".$this->total_ttc;
+        $sql.= " , total_tva = ".$this->total_tva;
+        $sql.= " WHERE rowid = ".$this->id;
+
+        $result = $this->db->query($sql);
+        if ($result):
+        return 1;
+        else:
+        $this->error=$this->db->error();
+        return -1;
+        endif;
+    }
+
+    /**
+     *  Update total of an expense report when you delete a line.
+     *
+     *  @param    string    $ligne_total_ht    Amount without taxes
+     *  @param    string    $ligne_total_tva    Amount of all taxes
+     *  @return    void
+     */
+    function update_totaux_del($ligne_total_ht,$ligne_total_tva)
+    {
+        $this->total_ht = $this->total_ht - $ligne_total_ht;
+        $this->total_tva = $this->total_tva - $ligne_total_tva;
+        $this->total_ttc = $this->total_ht + $this->total_tva;
+
+        $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
+        $sql.= " total_ht = ".$this->total_ht;
+        $sql.= " , total_ttc = ".$this->total_ttc;
+        $sql.= " , total_tva = ".$this->total_tva;
+        $sql.= " WHERE rowid = ".$this->id;
+
+        $result = $this->db->query($sql);
+        if ($result):
+        return 1;
+        else:
+        $this->error=$this->db->error();
+        return -1;
+        endif;
+    }
+
+
+    /**
+     * updateline
+     *
+     * @param   int         $rowid                  Line to edit
+     * @param   int         $type_fees_id           Type payment
+     * @param   int         $projet_id              Project id
+     * @param   double      $vatrate                Vat rate
+     * @param   string      $comments               Description
+     * @param   real        $qty                    Qty
+     * @param   double      $value_unit             Value init
+     * @param   int         $date                   Date
+     * @param   int         $expensereport_id       Expense report id
+     * @return  int                                 <0 if KO, >0 if OK
+     */
+    function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id)
+    {
+        global $user;
+
+        if ($this->fk_statut==0 || $this->fk_statut==99)
+        {
+            $this->db->begin();
+
+            // calcul de tous les totaux de la ligne
+            $total_ttc  = price2num($qty*$value_unit, 'MT');
+
+            $tx_tva = $vatrate / 100;
+            $tx_tva = $tx_tva + 1;
+            $total_ht   = price2num($total_ttc/$tx_tva, 'MT');
+
+            $total_tva = price2num($total_ttc - $total_ht, 'MT');
+            // fin calculs
+
+            $ligne = new ExpenseReportLine($this->db);
+            $ligne->comments        = $comments;
+            $ligne->qty             = $qty;
+            $ligne->value_unit      = $value_unit;
+            $ligne->date            = $date;
+
+            $ligne->fk_expensereport= $expensereport_id;
+            $ligne->fk_c_type_fees  = $type_fees_id;
+            $ligne->fk_projet       = $projet_id;
+
+            $ligne->total_ht        = $total_ht;
+            $ligne->total_tva       = $total_tva;
+            $ligne->total_ttc       = $total_ttc;
+            $ligne->vatrate         = price2num($vatrate);
+            $ligne->rowid           = $rowid;
+
+            // Select des infos sur le type fees
+            $sql = "SELECT c.code as code_type_fees, c.label as libelle_type_fees";
+            $sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees as c";
+            $sql.= " WHERE c.id = ".$type_fees_id;
+            $result = $this->db->query($sql);
+            $objp_fees = $this->db->fetch_object($result);
+            $ligne->type_fees_code      = $objp_fees->code_type_fees;
+            $ligne->type_fees_libelle   = $objp_fees->libelle_type_fees;
+
+            // Select des informations du projet
+            $sql = "SELECT p.ref as ref_projet, p.title as title_projet";
+            $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
+            $sql.= " WHERE p.rowid = ".$projet_id;
+            $result = $this->db->query($sql);
+            $objp_projet = $this->db->fetch_object($result);
+            $ligne->projet_ref          = $objp_projet->ref_projet;
+            $ligne->projet_title        = $objp_projet->title_projet;
+
+            $result = $ligne->update($user);
+            if ($result > 0)
             {
+                $this->db->commit();
                 return 1;
             }
             else
+            {
+                $this->error=$ligne->error;
+                $this->errors=$ligne->errors;
+                $this->db->rollback();
+                return -2;
+            }
+        }
+    }
+
+    /**
+     * deleteline
+     *
+     * @param   int     $rowid      Row id
+     * @param   User    $fuser      User
+     * @return  int                 <0 if KO, >0 if OK
+     */
+    function deleteline($rowid, $fuser='')
+    {
+        $this->db->begin();
+
+        $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line;
+        $sql.= ' WHERE rowid = '.$rowid;
+
+        dol_syslog(get_class($this)."::deleteline sql=".$sql);
+        $result = $this->db->query($sql);
+        if (!$result)
+        {
+            $this->error=$this->db->error();
+            dol_syslog(get_class($this)."::deleteline  Error ".$this->error, LOG_ERR);
+            $this->db->rollback();
+            return -1;
+        }
+
+        $this->db->commit();
+
+        return 1;
+    }
+
+    /**
+     * periode_existe
+     *
+     * @param   User    $fuser          User
+     * @param   Date    $date_debut     Start date
+     * @param   Date    $date_fin       End date
+     * @return  int                     <0 if KO, >0 if OK
+     */
+    function periode_existe($fuser, $date_debut, $date_fin)
+    {
+        $sql = "SELECT rowid, date_debut, date_fin";
+        $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
+        $sql.= " WHERE fk_user_author = '{$fuser->id}'";
+
+        dol_syslog(get_class($this)."::periode_existe sql=".$sql);
+        $result = $this->db->query($sql);
+        if($result)
+        {
+            $num_lignes = $this->db->num_rows($result); $i = 0;
+
+            if ($num_lignes>0)
+            {
+                $date_d_form = $date_debut;
+                $date_f_form = $date_fin;
+
+                $existe = false;
+
+                while ($i < $num_lignes)
+                {
+                    $objp = $this->db->fetch_object($result);
+
+                    $date_d_req = $this->db->jdate($objp->date_debut); // 3
+                    $date_f_req = $this->db->jdate($objp->date_fin);      // 4
+
+                    if (!($date_f_form < $date_d_req || $date_d_form > $date_f_req)) $existe = true;
+
+                    $i++;
+                }
+
+                if($existe) return 1;
+                else return 0;
+            }
+            else
             {
                 return 0;
             }
         }
         else
         {
-            dol_print_error($this->db);
+            $this->error=$this->db->lasterror();
+            dol_syslog(get_class($this)."::periode_existe  Error ".$this->error, LOG_ERR);
+            return -1;
+        }
+    }
+
+
+    /**
+     * Return list of people with permission to validate trips and expenses
+     *
+     * @return  array       Array of user ids
+     */
+    function fetch_users_approver_expensereport()
+    {
+        $users_validator=array();
+
+        $sql = "SELECT fk_user";
+        $sql.= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd";
+        $sql.= " WHERE ur.fk_id = rd.id and module = 'expensereport' AND perms = 'approve'";                    // Permission 'Approve';
+
+        dol_syslog(get_class($this)."::fetch_users_approver_expensereport sql=".$sql);
+        $result = $this->db->query($sql);
+        if($result)
+        {
+            $num_lignes = $this->db->num_rows($result); $i = 0;
+            while ($i < $num_lignes)
+            {
+                $objp = $this->db->fetch_object($result);
+                array_push($users_validator,$objp->fk_user);
+                $i++;
+            }
+            return $users_validator;
+        }
+        else
+        {
+            $this->error=$this->db->lasterror();
+            dol_syslog(get_class($this)."::fetch_users_approver_expensereport  Error ".$this->error, LOG_ERR);
             return -1;
         }
     }
 
-	/**
-	 *	Returns the label status
-	 *
-	 *	@param      int		$mode       0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
-	 *	@return     string      		Label
-	 */
-	function getLibStatut($mode=0)
-	{
-		return $this->LibStatut($this->status,$mode);
-	}
-
-	/**
-	 *	Returns the label of a statut
-	 *
-	 *	@param      int		$status     id statut
-	 *	@param      int		$mode       0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
-	 *	@return     string      		Label
-	 */
-	function LibStatut($status,$mode=0)
-	{
-		global $langs;
-
-		if ($mode == 0)
-			return $langs->trans($this->statuts[$status]);
-
-		if ($mode == 1)
-			return $langs->trans($this->statuts_short[$status]);
-
-		if ($mode == 2)
-			return img_picto($langs->trans($this->statuts_short[$status]), $this->statuts_logo[$status]).' '.$langs->trans($this->statuts_short[$status]);
-
-		if ($mode == 3)
-			return img_picto($langs->trans($this->statuts_short[$status]), $this->statuts_logo[$status]);
-
-		if ($mode == 4)
-			return img_picto($langs->trans($this->statuts_short[$status]),$this->statuts_logo[$status]).' '.$langs->trans($this->statuts[$status]);
-
-		if ($mode == 5)
-			return '<span class="hideonsmartphone">'.$langs->trans($this->statuts_short[$status]).' </span>'.img_picto($langs->trans($this->statuts_short[$status]),$this->statuts_logo[$status]);
-
-	}
-
-
-	/**
-	 * 	Load information on object
-	 *
-	 *	@param	int		$id      Id of object
-	 *	@return	void
-	 */
-	function info($id)
-	{
-		global $conf;
-
-		$sql = "SELECT f.rowid,";
-		$sql.= " f.date_create as datec,";
-		$sql.= " f.tms as date_modification,";
-		$sql.= " f.date_valid as datev,";
-		$sql.= " f.date_approve as datea,";
-		$sql.= " f.fk_user_author as fk_user_creation,";
-		$sql.= " f.fk_user_modif as fk_user_modification,";
-		$sql.= " f.fk_user_valid,";
-		$sql.= " f.fk_user_approve";
-		$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as f";
-		$sql.= " WHERE f.rowid = ".$id;
-		$sql.= " AND f.entity = ".$conf->entity;
-
-		$resql = $this->db->query($sql);
-		if ($resql)
-		{
-			if ($this->db->num_rows($resql))
-			{
-				$obj = $this->db->fetch_object($resql);
-
-				$this->id                = $obj->rowid;
-
-				$this->date_creation     = $this->db->jdate($obj->datec);
-				$this->date_modification = $this->db->jdate($obj->date_modification);
-				$this->date_validation   = $this->db->jdate($obj->datev);
-				$this->date_approbation  = $this->db->jdate($obj->datea);
-
-				$cuser = new User($this->db);
-				$cuser->fetch($obj->fk_user_author);
-				$this->user_creation     = $cuser;
-
-				if ($obj->fk_user_creation)
-				{
-					$cuser = new User($this->db);
-					$cuser->fetch($obj->fk_user_creation);
-					$this->user_creation     = $cuser;
-				}
-				if ($obj->fk_user_valid)
-				{
-					$vuser = new User($this->db);
-					$vuser->fetch($obj->fk_user_valid);
-					$this->user_validation     = $vuser;
-				}
-				if ($obj->fk_user_modification)
-				{
-					$muser = new User($this->db);
-					$muser->fetch($obj->fk_user_modification);
-					$this->user_modification   = $muser;
-				}
-
-			}
-			$this->db->free($resql);
-		}
-		else
-		{
-			dol_print_error($this->db);
-		}
-	}
-
-
-
-	/**
-	 *  Initialise an instance with random values.
-	 *  Used to build previews or test instances.
-	 *	id must be 0 if object instance is a specimen.
-	 *
-	 *  @return	void
-	 */
-	function initAsSpecimen()
-	{
-		global $user,$langs,$conf;
-
-		$now=dol_now();
-
-		// Initialise parametres
-		$this->id=0;
-		$this->ref = 'SPECIMEN';
-		$this->specimen=1;
-		$this->date_create = $now;
-		$this->date_debut = $now;
-		$this->date_fin = $now;
-		$this->date_approve = $now;
-
-		$this->status = 5;
-		$this->fk_statut = 5;
-
-		$this->fk_user_author = $user->id;
-		$this->fk_user_valid = $user->id;
-		$this->fk_user_approve = $user->id;
-		$this->fk_user_validator = $user->id;
-
-		$this->note_private='Private note';
-		$this->note_public='SPECIMEN';
-		$nbp = 5;
-		$xnbp = 0;
-		while ($xnbp < $nbp)
-		{
-			$line=new ExpenseReportLine($this->db);
-			$line->comments=$langs->trans("Comment")." ".$xnbp;
-			$line->date=($now-3600*(1+$xnbp));
-			$line->total_ht=100;
-			$line->total_tva=20;
-			$line->total_ttc=120;
-			$line->qty=1;
-			$line->vatrate=20;
-			$line->value_unit=120;
-			$line->fk_expensereport=0;
-			$line->type_fees_code='TRA';
-
-			$line->projet_ref = 'ABC';
-
-			$this->lines[$xnbp]=$line;
-			$xnbp++;
-
-			$this->total_ht+=$line->total_ht;
-			$this->total_tva+=$line->total_tva;
-			$this->total_ttc+=$line->total_ttc;
-		}
-	}
-
-	/**
-	 * fetch_line_by_project
-	 *
-	 * @param 	int		$projectid		Project id
-	 * @param 	User	$user			User
-	 * @return	int						<0 if KO, >0 if OK
-	 */
-	function fetch_line_by_project($projectid,$user='')
-	{
-		global $conf,$db,$langs;
-
-		$langs->load('trips');
-
-		if($user->rights->expensereport->lire) {
-
-			$sql = "SELECT de.fk_expensereport, de.date, de.comments, de.total_ht, de.total_ttc";
-			$sql.= " FROM ".MAIN_DB_PREFIX."expensereport_det as de";
-			$sql.= " WHERE de.fk_projet = ".$projectid;
-
-			dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
-			$result = $db->query($sql) ;
-			if ($result)
-			{
-				$num = $db->num_rows($result);
-				$i = 0;
-				$total_HT = 0;
-				$total_TTC = 0;
-
-				while ($i < $num)
-				{
-
-					$objp = $db->fetch_object($result);
-
-					$sql2 = "SELECT d.rowid, d.fk_user_author, d.ref, d.fk_statut";
-					$sql2.= " FROM ".MAIN_DB_PREFIX."expensereport as d";
-					$sql2.= " WHERE d.rowid = '".$objp->fk_expensereport."'";
-
-					$result2 = $db->query($sql2);
-					$obj = $db->fetch_object($result2);
-
-					$objp->fk_user_author = $obj->fk_user_author;
-					$objp->ref = $obj->ref;
-					$objp->fk_c_expensereport_status = $obj->fk_statut;
-					$objp->rowid = $obj->rowid;
-
-					$total_HT = $total_HT + $objp->total_ht;
-					$total_TTC = $total_TTC + $objp->total_ttc;
-					$author = new User($db);
-					$author->fetch($objp->fk_user_author);
-
-					print '<tr>';
-					print '<td><a href="'.DOL_URL_ROOT.'/expensereport/card.php?id='.$objp->rowid.'">'.$objp->ref_num.'</a></td>';
-					print '<td align="center">'.dol_print_date($objp->date,'day').'</td>';
-					print '<td>'.$author->getNomUrl().'</td>';
-					print '<td>'.$objp->comments.'</td>';
-					print '<td align="right">'.price($objp->total_ht).'</td>';
-					print '<td align="right">'.price($objp->total_ttc).'</td>';
-					print '<td align="right">';
-
-					switch($objp->fk_c_expensereport_status) {
-						case 4:
-							print img_picto($langs->trans('StatusOrderCanceled'),'statut5');
-							break;
-						case 1:
-							print $langs->trans('Draft').' '.img_picto($langs->trans('Draft'),'statut0');
-							break;
-						case 2:
-							print $langs->trans('TripForValid').' '.img_picto($langs->trans('TripForValid'),'statut3');
-							break;
-						case 5:
-							print $langs->trans('TripForPaid').' '.img_picto($langs->trans('TripForPaid'),'statut3');
-							break;
-						case 6:
-							print $langs->trans('TripPaid').' '.img_picto($langs->trans('TripPaid'),'statut4');
-							break;
-					}
-					/*
-					 if ($status==4) return img_picto($langs->trans('StatusOrderCanceled'),'statut5');
-					if ($status==1) return img_picto($langs->trans('StatusOrderDraft'),'statut0');
-					if ($status==2) return img_picto($langs->trans('StatusOrderValidated'),'statut1');
-					if ($status==2) return img_picto($langs->trans('StatusOrderOnProcess'),'statut3');
-					if ($status==5) return img_picto($langs->trans('StatusOrderToBill'),'statut4');
-					if ($status==6) return img_picto($langs->trans('StatusOrderOnProcess'),'statut6');
-					*/
-					print '</td>';
-					print '</tr>';
-
-					$i++;
-				}
-
-				print '<tr class="liste_total"><td colspan="4">'.$langs->trans("Number").': '.$i.'</td>';
-				print '<td align="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_HT).'</td>';
-				print '<td align="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_TTC).'</td>';
-				print '<td>&nbsp;</td>';
-				print '</tr>';
-
-			}
-			else
-			{
-				$this->error=$db->error();
-				return -1;
-			}
-		}
-
-	}
-
-	/**
-	 * recalculer
-	 * TODO Replace this with call to update_price if not already done
-	 *
-	 * @param 	int			$id		Id of expense report
-	 * @return 	int					<0 if KO, >0 if OK
-	 */
-	function recalculer($id)
-	{
-		$sql = 'SELECT tt.total_ht, tt.total_ttc, tt.total_tva';
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as tt';
-		$sql.= ' WHERE tt.'.$this->fk_element.' = '.$id;
-
-		$total_ht = 0; $total_tva = 0; $total_ttc = 0;
-
-		dol_syslog('ExpenseReport::recalculer sql='.$sql,LOG_DEBUG);
-
-		$result = $this->db->query($sql);
-		if($result)
-		{
-			$num = $this->db->num_rows($result);
-			$i = 0;
-			while ($i < $num):
-			$objp = $this->db->fetch_object($result);
-			$total_ht+=$objp->total_ht;
-			$total_tva+=$objp->total_tva;
-			$i++;
-			endwhile;
-
-			$total_ttc = $total_ht + $total_tva;
-			$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
-			$sql.= " total_ht = ".$total_ht;
-			$sql.= " , total_ttc = ".$total_ttc;
-			$sql.= " , total_tva = ".$total_tva;
-			$sql.= " WHERE rowid = ".$id;
-			$result = $this->db->query($sql);
-			if($result):
-			$this->db->free($result);
-			return 1;
-			else:
-			$this->error=$this->db->error();
-			dol_syslog('ExpenseReport::recalculer: Error '.$this->error,LOG_ERR);
-			return -3;
-			endif;
-		}
-		else
-		{
-			$this->error=$this->db->error();
-			dol_syslog('ExpenseReport::recalculer: Error '.$this->error,LOG_ERR);
-			return -3;
-		}
-	}
-
-	/**
-	 * fetch_lines
-	 *
-	 * @return	int		<0 if OK, >0 if KO
-	 */
-	function fetch_lines()
-	{
-		$this->lines=array();
-
-		$sql = ' SELECT de.rowid, de.comments, de.qty, de.value_unit, de.date,';
-		$sql.= ' de.'.$this->fk_element.', de.fk_c_type_fees, de.fk_projet, de.tva_tx as vatrate,';
-		$sql.= ' de.total_ht, de.total_tva, de.total_ttc,';
-		$sql.= ' ctf.code as code_type_fees, ctf.label as libelle_type_fees,';
-		$sql.= ' p.ref as ref_projet, p.title as title_projet';
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as de';
-		$sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id';
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as p ON de.fk_projet = p.rowid';
-		$sql.= ' WHERE de.'.$this->fk_element.' = '.$this->id;
-
-		dol_syslog('ExpenseReport::fetch_lines sql='.$sql, LOG_DEBUG);
-		$resql = $this->db->query($sql);
-		if ($resql)
-		{
-			$num = $this->db->num_rows($resql);
-			$i = 0;
-			while ($i < $num)
-			{
-				$objp = $this->db->fetch_object($resql);
-
-				$deplig = new ExpenseReportLine($this->db);
-
-				$deplig->rowid	    	= $objp->rowid;
-				$deplig->comments		= $objp->comments;
-				$deplig->qty			= $objp->qty;
-				$deplig->value_unit 	= $objp->value_unit;
-				$deplig->date			= $objp->date;
-
-				$deplig->fk_expensereport = $objp->fk_expensereport;
-				$deplig->fk_c_type_fees = $objp->fk_c_type_fees;
-				$deplig->fk_projet		= $objp->fk_projet;
-
-				$deplig->total_ht		= $objp->total_ht;
-				$deplig->total_tva		= $objp->total_tva;
-				$deplig->total_ttc		= $objp->total_ttc;
-
-				$deplig->type_fees_code 	= $objp->code_type_fees;
-				$deplig->type_fees_libelle 	= $objp->libelle_type_fees;
-				$deplig->vatrate			= $objp->vatrate;
-				$deplig->projet_ref			= $objp->ref_projet;
-				$deplig->projet_title		= $objp->title_projet;
-
-				$this->lignes[$i] = $deplig;
-				$this->lines[$i] = $deplig;
-
-				$i++;
-			}
-			$this->db->free($resql);
-			return 1;
-		}
-		else
-		{
-			$this->error=$this->db->lasterror();
-			dol_syslog('ExpenseReport::fetch_lines: Error '.$this->error, LOG_ERR);
-			return -3;
-		}
-	}
-
-
-	/**
-	 * delete
-	 *
-	 * @param 	int		$rowid		Id to delete (optional)
-	 * @param	User	$fuser		User that delete
-	 * @return	int					<0 if KO, >0 if OK
-	 */
-	function delete($rowid=0, User $fuser=null)
-	{
-		global $user,$langs,$conf;
-
-		if (! $rowid) $rowid=$this->id;
-
-		$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line.' WHERE '.$this->fk_element.' = '.$rowid;
-		if ($this->db->query($sql))
-		{
-			$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid = '.$rowid;
-			$resql=$this->db->query($sql);
-			if ($resql)
-			{
-				$this->db->commit();
-				return 1;
-			}
-			else
-			{
-				$this->error=$this->db->error()." sql=".$sql;
-				dol_syslog("ExpenseReport.class::delete ".$this->error, LOG_ERR);
-				$this->db->rollback();
-				return -6;
-			}
-		}
-		else
-		{
-			$this->error=$this->db->error()." sql=".$sql;
-			dol_syslog("ExpenseReport.class::delete ".$this->error, LOG_ERR);
-			$this->db->rollback();
-			return -4;
-		}
-	}
-
-	/**
-	 * Set to status validate
-	 *
-	 * @param 	User	$fuser		User
-	 * @return	int					<0 if KO, >0 if OK
-	 */
-	function setValidate($fuser)
-	{
-		global $conf,$langs;
-
-		$expld_car = (empty($conf->global->NDF_EXPLODE_CHAR))?"-":$conf->global->NDF_EXPLODE_CHAR;
-
-		// Sélection du numéro de ref suivant
-		$ref_next = $this->getNextNumRef();
-		$ref_number_int = ($this->ref+1)-1;
-
-		// Sélection de la date de début de la NDF
-		$sql = 'SELECT date_debut';
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
-		$sql.= ' WHERE rowid = '.$this->id;
-		$result = $this->db->query($sql);
-		$objp = $this->db->fetch_object($result);
-		$this->date_debut = $this->db->jdate($objp->date_debut);
-
-		// Création du ref_number suivant
-		if($ref_next)
-		{
-			$prefix="ER";
-			if (! empty($conf->global->EXPENSE_REPORT_PREFIX)) $prefix=$conf->global->EXPENSE_REPORT_PREFIX;
-			$this->ref = strtoupper($fuser->login).$expld_car.$prefix.$this->ref.$expld_car.dol_print_date($this->date_debut,'%y%m%d');
-		}
-
-		if ($this->fk_statut != 2)
-		{
-			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
-			$sql.= " SET ref = '".$this->ref."', fk_statut = 2, fk_user_valid = ".$fuser->id.",";
-			$sql.= " ref_number_int = ".$ref_number_int;
-			$sql.= ' WHERE rowid = '.$this->id;
-
-			dol_syslog(get_class($this)."::set_save sql=".$sql, LOG_DEBUG);
-
-			if ($this->db->query($sql))
-			{
-				return 1;
-			}
-			else
-			{
-				$this->error=$this->db->error();
-				return -1;
-			}
-		}
-		else
-		{
-			dol_syslog(get_class($this)."::set_save expensereport already with save status", LOG_WARNING);
-		}
-	}
-
-	/**
-	 * set_save_from_refuse
-	 *
-	 * @param 	User	$fuser		User
-	 * @return	int					<0 if KO, >0 if OK
-	 */
-	function set_save_from_refuse($fuser)
-	{
-		global $conf,$langs;
-
-		// Sélection de la date de début de la NDF
-		$sql = 'SELECT date_debut';
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
-		$sql.= ' WHERE rowid = '.$this->id;
-
-		$result = $this->db->query($sql);
-
-		$objp = $this->db->fetch_object($result);
-
-		$this->date_debut = $this->db->jdate($objp->date_debut);
-
-		if ($this->fk_statut != 2)
-		{
-			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
-			$sql.= " SET fk_statut = 2";
-			$sql.= ' WHERE rowid = '.$this->id;
-
-			dol_syslog(get_class($this)."::set_save_from_refuse sql=".$sql, LOG_DEBUG);
-
-			if ($this->db->query($sql))
-			{
-				return 1;
-			}
-			else
-			{
-				$this->error=$this->db->lasterror();
-				return -1;
-			}
-		}
-		else
-		{
-			dol_syslog(get_class($this)."::set_save_from_refuse expensereport already with save status", LOG_WARNING);
-		}
-	}
-
-	/**
-	 * Set status to approved
-	 *
-	 * @param 	User	$fuser		User
-	 * @return	int					<0 if KO, >0 if OK
-	 */
-	function setApproved($fuser)
-	{
-		$now=dol_now();
-
-		// date approval
-		$this->date_approve = $this->db->idate($now);
-		if ($this->fk_statut != 5)
-		{
-			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
-			$sql.= " SET ref = '".$this->ref."', fk_statut = 5, fk_user_approve = ".$fuser->id.",";
-			$sql.= " date_approve='".$this->date_approve."'";
-			$sql.= ' WHERE rowid = '.$this->id;
-			if ($this->db->query($sql))
-			{
-				return 1;
-			}
-			else
-			{
-				$this->error=$this->db->lasterror();
-				return -1;
-			}
-		}
-		else
-		{
-			dol_syslog(get_class($this)."::set_valide expensereport already with valide status", LOG_WARNING);
-		}
-	}
-
-	/**
-	 * setDeny
-	 *
-	 * @param User		$fuser		User
-	 * @param Details	$details	Details
-	 */
-	function setDeny($fuser,$details)
-	{
-		$now = dol_now();
-
-		// date de refus
-		if ($this->fk_statut != 99)
-		{
-			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
-			$sql.= " SET ref = '".$this->ref."', fk_statut = 99, fk_user_refuse = ".$fuser->id.",";
-			$sql.= " date_refuse='".$this->db->idate($now)."',";
-			$sql.= " detail_refuse='".$this->db->escape($details)."'";
-			$sql.= " fk_user_approve=NULL,";
-			$sql.= ' WHERE rowid = '.$this->id;
-			if ($this->db->query($sql))
-			{
-				$this->fk_statut = 99;
-				$this->fk_user_refuse = $fuser->id;
-				$this->detail_refuse = $details;
-				$this->date_refuse = $now;
-				return 1;
-			}
-			else
-			{
-				$this->error=$this->db->lasterror();
-				return -1;
-			}
-		}
-		else
-		{
-			dol_syslog(get_class($this)."::setDeny expensereport already with refuse status", LOG_WARNING);
-		}
-	}
-
-	/**
-	 * set_unpaid
-	 *
-	 * @param 	User	$fuser		User
-	 * @return	int					<0 if KO, >0 if OK
-	 */
-	function set_unpaid($fuser)
-	{
-		if ($this->fk_c_deplacement_statuts != 5)
-		{
-			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
-			$sql.= " SET fk_statut = 5";
-			$sql.= ' WHERE rowid = '.$this->id;
-
-			dol_syslog(get_class($this)."::set_unpaid sql=".$sql, LOG_DEBUG);
-
-			if ($this->db->query($sql)):
-			return 1;
-			else:
-			$this->error=$this->db->error();
-			return -1;
-			endif;
-		}
-		else
-		{
-			dol_syslog(get_class($this)."::set_unpaid expensereport already with unpaid status", LOG_WARNING);
-		}
-	}
-
-	/**
-	 * set_cancel
-	 *
-	 * @param 	User	$fuser		User
-	 * @param	string	$detail		Detail
-	 * @return	int					<0 if KO, >0 if OK
-	 */
-	function set_cancel($fuser,$detail)
-	{
-		$this->date_cancel = $this->db->idate(gmmktime());
-		if ($this->fk_statut != 4)
-		{
-			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
-			$sql.= " SET fk_statut = 4, fk_user_cancel = ".$fuser->id;
-			$sql.= ", date_cancel='".$this->date_cancel."'";
-			$sql.= " ,detail_cancel='".$this->db->escape($detail)."'";
-			$sql.= ' WHERE rowid = '.$this->id;
-
-			dol_syslog(get_class($this)."::set_cancel sql=".$sql, LOG_DEBUG);
-
-			if ($this->db->query($sql))
-			{
-				return 1;
-			}
-			else
-			{
-				$this->error=$this->db->error();
-				return -1;
-			}
-		}
-		else
-		{
-			dol_syslog(get_class($this)."::set_cancel expensereport already with cancel status", LOG_WARNING);
-		}
-	}
-
-	function getNextNumRef()
-	{
-		global $conf;
-
-		$expld_car = (empty($conf->global->NDF_EXPLODE_CHAR))?"-":$conf->global->NDF_EXPLODE_CHAR;
-		$num_car = (empty($conf->global->NDF_NUM_CAR_REF))?"5":$conf->global->NDF_NUM_CAR_REF;
-
-		$sql = 'SELECT de.ref_number_int';
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' de';
-		$sql.= ' ORDER BY de.ref_number_int DESC';
-
-		$result = $this->db->query($sql);
-
-		if($this->db->num_rows($result) > 0):
-		$objp = $this->db->fetch_object($result);
-		$this->ref = $objp->ref_number_int;
-		$this->ref++;
-		while(strlen($this->ref) < $num_car):
-		$this->ref = "0".$this->ref;
-		endwhile;
-		else:
-		$this->ref = 1;
-		while(strlen($this->ref) < $num_car):
-		$this->ref = "0".$this->ref;
-		endwhile;
-		endif;
-
-		if ($result):
-		return 1;
-		else:
-		$this->error=$this->db->error();
-		return -1;
-		endif;
-	}
-
-
-	/**
-	 *	Return clicable name (with picto eventually)
-	 *
-	 *	@param		int		$withpicto		0=No picto, 1=Include picto into link, 2=Only picto
-	 *	@return		string					Chaine avec URL
-	 */
-	function getNomUrl($withpicto=0)
-	{
-		global $langs;
-
-		$result='';
-
-		$link = '<a href="'.DOL_URL_ROOT.'/expensereport/card.php?id='.$this->id.'">';
-		$linkend='</a>';
-
-		$picto='trip';
-
-		$label=$langs->trans("Show").': '.$this->ref;
-
-		if ($withpicto) $result.=($link.img_object($label,$picto).$linkend);
-		if ($withpicto && $withpicto != 2) $result.=' ';
-		if ($withpicto != 2) $result.=$link.$this->ref.$linkend;
-		return $result;
-	}
-
-
-	function update_totaux_add($ligne_total_ht,$ligne_total_tva){
-		$this->total_ht = $this->total_ht + $ligne_total_ht;
-		$this->total_tva = $this->total_tva + $ligne_total_tva;
-		$this->total_ttc = $this->total_ht + $this->total_tva;
-
-		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
-		$sql.= " total_ht = ".$this->total_ht;
-		$sql.= " , total_ttc = ".$this->total_ttc;
-		$sql.= " , total_tva = ".$this->total_tva;
-		$sql.= " WHERE rowid = ".$this->id;
-
-		$result = $this->db->query($sql);
-		if ($result):
-		return 1;
-		else:
-		$this->error=$this->db->error();
-		return -1;
-		endif;
-	}
-
-	function update_totaux_del($ligne_total_ht,$ligne_total_tva){
-		$this->total_ht = $this->total_ht - $ligne_total_ht;
-		$this->total_tva = $this->total_tva - $ligne_total_tva;
-		$this->total_ttc = $this->total_ht + $this->total_tva;
-
-		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
-		$sql.= " total_ht = ".$this->total_ht;
-		$sql.= " , total_ttc = ".$this->total_ttc;
-		$sql.= " , total_tva = ".$this->total_tva;
-		$sql.= " WHERE rowid = ".$this->id;
-
-		$result = $this->db->query($sql);
-		if ($result):
-		return 1;
-		else:
-		$this->error=$this->db->error();
-		return -1;
-		endif;
-	}
-
-
-	/**
-	 * updateline
-	 *
-	 * @param 	int			$rowid					Line to edit
-	 * @param 	int			$type_fees_id			Type payment
-	 * @param 	int			$projet_id				Project id
-	 * @param 	double		$vatrate				Vat rate
-	 * @param 	string		$comments				Description
-	 * @param 	real		$qty					Qty
-	 * @param 	double		$value_unit				Value init
-	 * @param 	int			$date					Date
-	 * @param 	int			$expensereport_id		Expense report id
-	 * @return	int									<0 if KO, >0 if OK
-	 */
-	function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id)
-	{
-		global $user;
-
-		if ($this->fk_statut==0 || $this->fk_statut==99)
-		{
-			$this->db->begin();
-
-			// calcul de tous les totaux de la ligne
-			$total_ttc	= price2num($qty*$value_unit, 'MT');
-
-			$tx_tva = $vatrate / 100;
-			$tx_tva	= $tx_tva + 1;
-			$total_ht 	= price2num($total_ttc/$tx_tva, 'MT');
-
-			$total_tva = price2num($total_ttc - $total_ht, 'MT');
-			// fin calculs
-
-			$ligne = new ExpenseReportLine($this->db);
-			$ligne->comments		= $comments;
-			$ligne->qty				= $qty;
-			$ligne->value_unit 		= $value_unit;
-			$ligne->date			= $date;
-
-			$ligne->fk_expensereport= $expensereport_id;
-			$ligne->fk_c_type_fees 	= $type_fees_id;
-			$ligne->fk_projet		= $projet_id;
-
-			$ligne->total_ht		= $total_ht;
-			$ligne->total_tva		= $total_tva;
-			$ligne->total_ttc		= $total_ttc;
-			$ligne->vatrate			= price2num($vatrate);
-			$ligne->rowid			= $rowid;
-
-			// Select des infos sur le type fees
-			$sql = "SELECT c.code as code_type_fees, c.label as libelle_type_fees";
-			$sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees as c";
-			$sql.= " WHERE c.id = ".$type_fees_id;
-			$result = $this->db->query($sql);
-			$objp_fees = $this->db->fetch_object($result);
-			$ligne->type_fees_code 		= $objp_fees->code_type_fees;
-			$ligne->type_fees_libelle 	= $objp_fees->libelle_type_fees;
-
-			// Select des informations du projet
-			$sql = "SELECT p.ref as ref_projet, p.title as title_projet";
-			$sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
-			$sql.= " WHERE p.rowid = ".$projet_id;
-			$result = $this->db->query($sql);
-			$objp_projet = $this->db->fetch_object($result);
-			$ligne->projet_ref			= $objp_projet->ref_projet;
-			$ligne->projet_title		= $objp_projet->title_projet;
-
-			$result = $ligne->update($user);
-			if ($result > 0)
-			{
-				$this->db->commit();
-				return 1;
-			}
-			else
-			{
-				$this->error=$ligne->error;
-				$this->errors=$ligne->errors;
-				$this->db->rollback();
-				return -2;
-			}
-		}
-	}
-
-	/**
-	 * deleteline
-	 *
-	 * @param 	int		$rowid		Row id
-	 * @param 	User	$fuser		User
-	 * @return 	int					<0 if KO, >0 if OK
-	 */
-	function deleteline($rowid, $fuser='')
-	{
-		$this->db->begin();
-
-		$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line;
-		$sql.= ' WHERE rowid = '.$rowid;
-
-		dol_syslog(get_class($this)."::deleteline sql=".$sql);
-		$result = $this->db->query($sql);
-		if (!$result)
-		{
-			$this->error=$this->db->error();
-			dol_syslog(get_class($this)."::deleteline  Error ".$this->error, LOG_ERR);
-			$this->db->rollback();
-			return -1;
-		}
-
-		$this->db->commit();
-
-		return 1;
-	}
-
-	/**
-	 * periode_existe
-	 *
-	 * @param 	User	$fuser			User
-	 * @param 	Date	$date_debut		Start date
-	 * @param 	Date	$date_fin		End date
-	 * @return	int						<0 if KO, >0 if OK
-	 */
-	function periode_existe($fuser, $date_debut, $date_fin)
-	{
-		$sql = "SELECT rowid, date_debut, date_fin";
-		$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
-		$sql.= " WHERE fk_user_author = '{$fuser->id}'";
-
-		dol_syslog(get_class($this)."::periode_existe sql=".$sql);
-		$result = $this->db->query($sql);
-		if($result)
-		{
-			$num_lignes = $this->db->num_rows($result); $i = 0;
-
-			if ($num_lignes>0)
-			{
-				$date_d_form = $date_debut;
-				$date_f_form = $date_fin;
-
-				$existe = false;
-
-				while ($i < $num_lignes)
-				{
-					$objp = $this->db->fetch_object($result);
-
-					$date_d_req = $this->db->jdate($objp->date_debut); // 3
-					$date_f_req = $this->db->jdate($objp->date_fin);	  // 4
-
-					if (!($date_f_form < $date_d_req || $date_d_form > $date_f_req)) $existe = true;
-
-					$i++;
-				}
-
-				if($existe) return 1;
-				else return 0;
-			}
-			else
-			{
-				return 0;
-			}
-		}
-		else
-		{
-			$this->error=$this->db->lasterror();
-			dol_syslog(get_class($this)."::periode_existe  Error ".$this->error, LOG_ERR);
-			return -1;
-		}
-	}
-
-
-	/**
-	 * Return list of people with permission to validate trips and expenses
-	 *
-	 * @return	array		Array of user ids
-	 */
-	function fetch_users_approver_expensereport()
-	{
-		$users_validator=array();
-
-		$sql = "SELECT fk_user";
-		$sql.= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd";
-		$sql.= " WHERE ur.fk_id = rd.id and module = 'expensereport' AND perms = 'approve'";					// Permission 'Approve';
-
-		dol_syslog(get_class($this)."::fetch_users_approver_expensereport sql=".$sql);
-		$result = $this->db->query($sql);
-		if($result)
-		{
-			$num_lignes = $this->db->num_rows($result); $i = 0;
-			while ($i < $num_lignes)
-			{
-				$objp = $this->db->fetch_object($result);
-				array_push($users_validator,$objp->fk_user);
-				$i++;
-			}
-			return $users_validator;
-		}
-		else
-		{
-			$this->error=$this->db->lasterror();
-			dol_syslog(get_class($this)."::fetch_users_approver_expensereport  Error ".$this->error, LOG_ERR);
-			return -1;
-		}
-	}
-
-	/**
-	 *  Create a document onto disk accordign to template module.
-	 *
-	 *  @param	    string		$modele			Force le mnodele a utiliser ('' to not force)
-	 *  @param		Translate	$outputlangs	objet lang a utiliser pour traduction
-	 *  @param      int			$hidedetails    Hide details of lines
-	 *  @param      int			$hidedesc       Hide description
-	 *  @param      int			$hideref        Hide ref
-	 *  @return     int         				0 if KO, 1 if OK
-	 */
-	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
-	{
-		global $conf,$langs;
-
-		$langs->load("trips");
-
-		// Positionne le modele sur le nom du modele a utiliser
-		if (! dol_strlen($modele))
-		{
-			if (! empty($conf->global->EXPENSEREPORT_ADDON_PDF))
-			{
-				$modele = $conf->global->EXPENSEREPORT_ADDON_PDF;
-			}
-			else
-			{
-				$modele = 'standard';
-			}
-		}
-
-		$modelpath = "core/modules/expensereport/doc/";
-
-		return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
-	}
-
-	/**
-	 * List of types
-	 *
-	 * @param	int		$active		Active or not
-	 * @return	array
-	 */
-	function listOfTypes($active=1)
-	{
-		global $langs;
-		$ret=array();
-		$sql = "SELECT id, code, label";
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees";
-		$sql.= " WHERE active = ".$active;
-		dol_syslog(get_class($this)."::listOfTypes", LOG_DEBUG);
-		$result = $this->db->query($sql);
-		if ( $result )
-		{
-			$num = $this->db->num_rows($result);
-			$i=0;
-			while ($i < $num)
-			{
-				$obj = $this->db->fetch_object($result);
-				$ret[$obj->code]=(($langs->trans($obj->code)!=$obj->code)?$langs->trans($obj->code):$obj->label);
-				$i++;
-			}
-		}
-		else
-		{
-			dol_print_error($this->db);
-		}
-		return $ret;
-	}
+    /**
+     *  Create a document onto disk accordign to template module.
+     *
+     *  @param      string      $modele         Force le mnodele a utiliser ('' to not force)
+     *  @param      Translate   $outputlangs    objet lang a utiliser pour traduction
+     *  @param      int         $hidedetails    Hide details of lines
+     *  @param      int         $hidedesc       Hide description
+     *  @param      int         $hideref        Hide ref
+     *  @return     int                         0 if KO, 1 if OK
+     */
+    public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+    {
+        global $conf,$langs;
+
+        $langs->load("trips");
+
+        // Positionne le modele sur le nom du modele a utiliser
+        if (! dol_strlen($modele))
+        {
+            if (! empty($conf->global->EXPENSEREPORT_ADDON_PDF))
+            {
+                $modele = $conf->global->EXPENSEREPORT_ADDON_PDF;
+            }
+            else
+            {
+                $modele = 'standard';
+            }
+        }
+
+        $modelpath = "core/modules/expensereport/doc/";
+
+        return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
+    }
+
+    /**
+     * List of types
+     *
+     * @param   int     $active     Active or not
+     * @return  array
+     */
+    function listOfTypes($active=1)
+    {
+        global $langs;
+        $ret=array();
+        $sql = "SELECT id, code, label";
+        $sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees";
+        $sql.= " WHERE active = ".$active;
+        dol_syslog(get_class($this)."::listOfTypes", LOG_DEBUG);
+        $result = $this->db->query($sql);
+        if ( $result )
+        {
+            $num = $this->db->num_rows($result);
+            $i=0;
+            while ($i < $num)
+            {
+                $obj = $this->db->fetch_object($result);
+                $ret[$obj->code]=(($langs->trans($obj->code)!=$obj->code)?$langs->trans($obj->code):$obj->label);
+                $i++;
+            }
+        }
+        else
+        {
+            dol_print_error($this->db);
+        }
+        return $ret;
+    }
 
 }
 
@@ -1453,233 +1472,235 @@ class ExpenseReport extends CommonObject
  */
 class ExpenseReportLine
 {
-	var $db;
-	var $error;
-
-	var $rowid;
-	var $comments;
-	var $qty;
-	var $value_unit;
-	var $date;
-
-	var $fk_c_type_fees;
-	var $fk_projet;
-	var $fk_expensereport;
-
-	var $type_fees_code;
-	var $type_fees_libelle;
-
-	var $projet_ref;
-	var $projet_title;
-
-	var $vatrate;
-	var $total_ht;
-	var $total_tva;
-	var $total_ttc;
-
-	/**
-	 * Constructor
-	 *
-	 * @param DoliDB	$db		Handlet database
-	 */
-	function ExpenseReportLine($db)
-	{
-		$this->db= $db;
-	}
-
-	/**
-	 * fetch record
-	 *
-	 * @param	int		$rowid		Row id to fetch
-	 * @return	int					<0 if KO, >0 if OK
-	 */
-	function fetch($rowid)
-	{
-		$sql = 'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_projet, fde.date,';
-		$sql.= ' fde.tva_tx as vatrate, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc,';
-		$sql.= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,';
-		$sql.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref';
-		$sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde';
-		$sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON fde.fk_c_type_fees=ctf.id';
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pjt ON fde.fk_projet=pjt.rowid';
-		$sql.= ' WHERE fde.rowid = '.$rowid;
-
-		$result = $this->db->query($sql);
-
-		if($result)
-		{
-			$objp = $this->db->fetch_object($result);
-
-			$this->rowid = $objp->rowid;
-			$this->fk_expensereport = $objp->fk_expensereport;
-			$this->comments = $objp->comments;
-			$this->qty = $objp->qty;
-			$this->date = $objp->date;
-			$this->value_unit = $objp->value_unit;
-			$this->fk_c_type_fees = $objp->fk_c_type_fees;
-			$this->fk_projet = $objp->fk_projet;
-			$this->type_fees_code = $objp->type_fees_code;
-			$this->type_fees_libelle = $objp->type_fees_libelle;
-			$this->projet_ref = $objp->projet_ref;
-			$this->projet_title = $objp->projet_title;
-			$this->vatrate = $objp->vatrate;
-			$this->total_ht = $objp->total_ht;
-			$this->total_tva = $objp->total_tva;
-			$this->total_ttc = $objp->total_ttc;
-
-			$this->db->free($result);
-		} else {
-			dol_print_error($this->db);
-		}
-	}
-
-	/**
-	 * insert
-	 *
-	 * @param 	int		$notrigger		1=No trigger
-	 * @return 	int						<0 if KO, >0 if OK
-	 */
-	function insert($notrigger=0)
-	{
-		global $langs,$user,$conf;
-
-		$error=0;
-
-		dol_syslog("ExpenseReportLine::Insert rang=".$this->rang, LOG_DEBUG);
-
-		// Clean parameters
-		$this->comments=trim($this->comments);
-		if (!$this->value_unit_HT) $this->value_unit_HT=0;
-		$this->qty = price2num($this->qty);
-		$this->vatrate = price2num($this->vatrate);
-
-		$this->db->begin();
-
-		$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'expensereport_det';
-		$sql.= ' (fk_expensereport, fk_c_type_fees, fk_projet,';
-		$sql.= ' tva_tx, comments, qty, value_unit, total_ht, total_tva, total_ttc, date)';
-		$sql.= " VALUES (".$this->fk_expensereport.",";
-		$sql.= " ".$this->fk_c_type_fees.",";
-		$sql.= " ".($this->fk_projet>0?$this->fk_projet:'null').",";
-		$sql.= " ".$this->vatrate.",";
-		$sql.= " '".$this->db->escape($this->comments)."',";
-		$sql.= " ".$this->qty.",";
-		$sql.= " ".$this->value_unit.",";
-		$sql.= " ".$this->total_ht.",";
-		$sql.= " ".$this->total_tva.",";
-		$sql.= " ".$this->total_ttc.",";
-		$sql.= "'".$this->db->idate($this->date)."'";
-		$sql.= ")";
-
-		dol_syslog("ExpenseReportLine::insert sql=".$sql);
-
-		$resql=$this->db->query($sql);
-		if ($resql)
-		{
-			$this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'expensereport_det');
-
-			$tmpparent=new ExpenseReport($this->db);
-			$tmpparent->fetch($this->fk_expensereport);
-			$result = $tmpparent->update_price();
-			if ($result < 0)
-			{
-				$error++;
-				$this->error = $tmpparent->error;
-				$this->errors = $tmpparent->errors;
-			}
-		}
-
-		if (! $error)
-		{
-			$this->db->commit();
-			return $this->rowid;
-		}
-		else
-		{
-			$this->error=$this->db->lasterror();
-			dol_syslog("ExpenseReportLine::insert Error ".$this->error, LOG_ERR);
-			$this->db->rollback();
-			return -2;
-		}
-	}
-
-	/**
-	 * update
-	 *
-	 * @param	User	$fuser		User
-	 * @return 	int					<0 if KO, >0 if OK
-	 */
-	function update($fuser)
-	{
-		global $fuser,$langs,$conf;
-
-		$error=0;
-
-		// Clean parameters
-		$this->comments=trim($this->comments);
-		$this->vatrate = price2num($this->vatrate);
-
-		$this->db->begin();
-
-		// Mise a jour ligne en base
-		$sql = "UPDATE ".MAIN_DB_PREFIX."expensereport_det SET";
-		$sql.= " comments='".$this->db->escape($this->comments)."'";
-		$sql.= ",value_unit=".$this->value_unit."";
-		$sql.= ",qty=".$this->qty."";
-		$sql.= ",date='".$this->db->idate($this->date)."'";
-		$sql.= ",total_ht=".$this->total_ht."";
-		$sql.= ",total_tva=".$this->total_tva."";
-		$sql.= ",total_ttc=".$this->total_ttc."";
-		$sql.= ",tva_tx=".$this->vatrate;
-		if ($this->fk_c_type_fees) $sql.= ",fk_c_type_fees=".$this->fk_c_type_fees;
-		else $sql.= ",fk_c_type_fees=null";
-		if ($this->fk_projet) $sql.= ",fk_projet=".$this->fk_projet;
-		else $sql.= ",fk_projet=null";
-		$sql.= " WHERE rowid = ".$this->rowid;
-
-		dol_syslog("ExpenseReportLine::update sql=".$sql);
-
-		$resql=$this->db->query($sql);
-		if ($resql)
-		{
-			$tmpparent=new ExpenseReport($this->db);
-			$result = $tmpparent->fetch($this->fk_expensereport);
-			if ($result > 0)
-			{
-				$result = $tmpparent->update_price();
-				if ($result < 0)
-				{
-					$error++;
-					$this->error = $tmpparent->error;
-					$this->errors = $tmpparent->errors;
-				}
-			}
-			else
-			{
-				$error++;
-				$this->error = $tmpparent->error;
-				$this->errors = $tmpparent->errors;
-			}
-		}
-		else
-		{
-			$error++;
-			dol_print_error($this->db);
-		}
-
-		if (! $error)
-		{
-			$this->db->commit();
-			return 1;
-		}
-		else
-		{
-			$this->error=$this->db->lasterror();
-			dol_syslog("ExpenseReportLine::update Error ".$this->error, LOG_ERR);
-			$this->db->rollback();
-			return -2;
-		}
-	}
+    var $db;
+    var $error;
+
+    var $rowid;
+    var $comments;
+    var $qty;
+    var $value_unit;
+    var $date;
+
+    var $fk_c_type_fees;
+    var $fk_projet;
+    var $fk_expensereport;
+
+    var $type_fees_code;
+    var $type_fees_libelle;
+
+    var $projet_ref;
+    var $projet_title;
+
+    var $vatrate;
+    var $total_ht;
+    var $total_tva;
+    var $total_ttc;
+
+    /**
+     * Constructor
+     *
+     * @param DoliDB    $db     Handlet database
+     */
+    function ExpenseReportLine($db)
+    {
+        $this->db= $db;
+    }
+
+    /**
+     * fetch record
+     *
+     * @param   int     $rowid      Id of object to load
+     * @return  int                 <0 if KO, >0 if OK
+     */
+    function fetch($rowid)
+    {
+        $sql = 'SELECT fde.rowid, fde.ref, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_projet, fde.date,';
+        $sql.= ' fde.tva_tx as vatrate, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc,';
+        $sql.= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,';
+        $sql.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref';
+        $sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde';
+        $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON fde.fk_c_type_fees=ctf.id';
+        $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pjt ON fde.fk_projet=pjt.rowid';
+        $sql.= ' WHERE fde.rowid = '.$rowid;
+
+        $result = $this->db->query($sql);
+
+        if($result)
+        {
+            $objp = $this->db->fetch_object($result);
+
+            $this->rowid = $objp->rowid;
+            $this->id = $obj->rowid;
+            $this->ref = $obj->ref;
+            $this->fk_expensereport = $objp->fk_expensereport;
+            $this->comments = $objp->comments;
+            $this->qty = $objp->qty;
+            $this->date = $objp->date;
+            $this->value_unit = $objp->value_unit;
+            $this->fk_c_type_fees = $objp->fk_c_type_fees;
+            $this->fk_projet = $objp->fk_projet;
+            $this->type_fees_code = $objp->type_fees_code;
+            $this->type_fees_libelle = $objp->type_fees_libelle;
+            $this->projet_ref = $objp->projet_ref;
+            $this->projet_title = $objp->projet_title;
+            $this->vatrate = $objp->vatrate;
+            $this->total_ht = $objp->total_ht;
+            $this->total_tva = $objp->total_tva;
+            $this->total_ttc = $objp->total_ttc;
+
+            $this->db->free($result);
+        } else {
+            dol_print_error($this->db);
+        }
+    }
+
+    /**
+     * insert
+     *
+     * @param   int     $notrigger      1=No trigger
+     * @return  int                     <0 if KO, >0 if OK
+     */
+    function insert($notrigger=0)
+    {
+        global $langs,$user,$conf;
+
+        $error=0;
+
+        dol_syslog("ExpenseReportLine::Insert rang=".$this->rang, LOG_DEBUG);
+
+        // Clean parameters
+        $this->comments=trim($this->comments);
+        if (!$this->value_unit_HT) $this->value_unit_HT=0;
+        $this->qty = price2num($this->qty);
+        $this->vatrate = price2num($this->vatrate);
+
+        $this->db->begin();
+
+        $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'expensereport_det';
+        $sql.= ' (fk_expensereport, fk_c_type_fees, fk_projet,';
+        $sql.= ' tva_tx, comments, qty, value_unit, total_ht, total_tva, total_ttc, date)';
+        $sql.= " VALUES (".$this->fk_expensereport.",";
+        $sql.= " ".$this->fk_c_type_fees.",";
+        $sql.= " ".($this->fk_projet>0?$this->fk_projet:'null').",";
+        $sql.= " ".$this->vatrate.",";
+        $sql.= " '".$this->db->escape($this->comments)."',";
+        $sql.= " ".$this->qty.",";
+        $sql.= " ".$this->value_unit.",";
+        $sql.= " ".$this->total_ht.",";
+        $sql.= " ".$this->total_tva.",";
+        $sql.= " ".$this->total_ttc.",";
+        $sql.= "'".$this->db->idate($this->date)."'";
+        $sql.= ")";
+
+        dol_syslog("ExpenseReportLine::insert sql=".$sql);
+
+        $resql=$this->db->query($sql);
+        if ($resql)
+        {
+            $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'expensereport_det');
+
+            $tmpparent=new ExpenseReport($this->db);
+            $tmpparent->fetch($this->fk_expensereport);
+            $result = $tmpparent->update_price();
+            if ($result < 0)
+            {
+                $error++;
+                $this->error = $tmpparent->error;
+                $this->errors = $tmpparent->errors;
+            }
+        }
+
+        if (! $error)
+        {
+            $this->db->commit();
+            return $this->rowid;
+        }
+        else
+        {
+            $this->error=$this->db->lasterror();
+            dol_syslog("ExpenseReportLine::insert Error ".$this->error, LOG_ERR);
+            $this->db->rollback();
+            return -2;
+        }
+    }
+
+    /**
+     * update
+     *
+     * @param   User    $fuser      User
+     * @return  int                 <0 if KO, >0 if OK
+     */
+    function update($fuser)
+    {
+        global $fuser,$langs,$conf;
+
+        $error=0;
+
+        // Clean parameters
+        $this->comments=trim($this->comments);
+        $this->vatrate = price2num($this->vatrate);
+
+        $this->db->begin();
+
+        // Mise a jour ligne en base
+        $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport_det SET";
+        $sql.= " comments='".$this->db->escape($this->comments)."'";
+        $sql.= ",value_unit=".$this->value_unit."";
+        $sql.= ",qty=".$this->qty."";
+        $sql.= ",date='".$this->db->idate($this->date)."'";
+        $sql.= ",total_ht=".$this->total_ht."";
+        $sql.= ",total_tva=".$this->total_tva."";
+        $sql.= ",total_ttc=".$this->total_ttc."";
+        $sql.= ",tva_tx=".$this->vatrate;
+        if ($this->fk_c_type_fees) $sql.= ",fk_c_type_fees=".$this->fk_c_type_fees;
+        else $sql.= ",fk_c_type_fees=null";
+        if ($this->fk_projet) $sql.= ",fk_projet=".$this->fk_projet;
+        else $sql.= ",fk_projet=null";
+        $sql.= " WHERE rowid = ".$this->rowid;
+
+        dol_syslog("ExpenseReportLine::update sql=".$sql);
+
+        $resql=$this->db->query($sql);
+        if ($resql)
+        {
+            $tmpparent=new ExpenseReport($this->db);
+            $result = $tmpparent->fetch($this->fk_expensereport);
+            if ($result > 0)
+            {
+                $result = $tmpparent->update_price();
+                if ($result < 0)
+                {
+                    $error++;
+                    $this->error = $tmpparent->error;
+                    $this->errors = $tmpparent->errors;
+                }
+            }
+            else
+            {
+                $error++;
+                $this->error = $tmpparent->error;
+                $this->errors = $tmpparent->errors;
+            }
+        }
+        else
+        {
+            $error++;
+            dol_print_error($this->db);
+        }
+
+        if (! $error)
+        {
+            $this->db->commit();
+            return 1;
+        }
+        else
+        {
+            $this->error=$this->db->lasterror();
+            dol_syslog("ExpenseReportLine::update Error ".$this->error, LOG_ERR);
+            $this->db->rollback();
+            return -2;
+        }
+    }
 }
 
 
@@ -1687,74 +1708,74 @@ class ExpenseReportLine
  *    Retourne la liste deroulante des differents etats d'une note de frais.
  *    Les valeurs de la liste sont les id de la table c_expensereport_statuts
  *
- *    @param    int		$selected    	preselect status
- *    @param	string	$htmlname		Name of HTML select
- *    @param	int		$useempty		1=Add empty line
- *    @return	string					HTML select with status
+ *    @param    int     $selected       preselect status
+ *    @param    string  $htmlname       Name of HTML select
+ *    @param    int     $useempty       1=Add empty line
+ *    @return   string                  HTML select with status
  */
 function select_expensereport_statut($selected='',$htmlname='fk_statut',$useempty=1)
 {
-	global $db;
-
-	$tmpep=new ExpenseReport($db);
-
-	print '<select class="flat" name="'.$htmlname.'">';
-	if ($useempty) print '<option value="-1">&nbsp;</option>';
-	foreach ($tmpep->statuts as $key => $val)
-	{
-		if ($selected != '' && $selected == $key)
-		{
-			print '<option value="'.$key.'" selected>';
-		}
-		else
-		{
-			print '<option value="'.$key.'">';
-		}
-		print $val;
-		print '</option>';
-	}
-	print '</select>';
+    global $db;
+
+    $tmpep=new ExpenseReport($db);
+
+    print '<select class="flat" name="'.$htmlname.'">';
+    if ($useempty) print '<option value="-1">&nbsp;</option>';
+    foreach ($tmpep->statuts as $key => $val)
+    {
+        if ($selected != '' && $selected == $key)
+        {
+            print '<option value="'.$key.'" selected>';
+        }
+        else
+        {
+            print '<option value="'.$key.'">';
+        }
+        print $val;
+        print '</option>';
+    }
+    print '</select>';
 }
 
 /**
- *	Return list of types of notes with select value = id
+ *  Return list of types of notes with select value = id
  *
- *	@param      int		$selected       Preselected type
- *	@param      string	$htmlname       Name of field in form
- * 	@param		int		$showempty		Add an empty field
- *  @return		string					Select html
+ *  @param      int     $selected       Preselected type
+ *  @param      string  $htmlname       Name of field in form
+ *  @param      int     $showempty      Add an empty field
+ *  @return     string                  Select html
  */
 function select_type_fees_id($selected='',$htmlname='type',$showempty=0)
 {
-	global $db,$langs,$user;
-	$langs->load("trips");
-
-	print '<select class="flat" name="'.$htmlname.'">';
-	if ($showempty)
-	{
-		print '<option value="-1"';
-		if ($selected == -1) print ' selected';
-		print '>&nbsp;</option>';
-	}
-
-	$sql = "SELECT c.id, c.code, c.label as type FROM ".MAIN_DB_PREFIX."c_type_fees as c";
-	$sql.= " ORDER BY c.label ASC";
-	$resql=$db->query($sql);
-	if ($resql)
-	{
-		$num = $db->num_rows($resql);
-		$i = 0;
-
-		while ($i < $num)
-		{
-			$obj = $db->fetch_object($resql);
-			print '<option value="'.$obj->id.'"';
-			if ($obj->code == $selected || $obj->id == $selected) print ' selected';
-			print '>';
-			if ($obj->code != $langs->trans($obj->code)) print $langs->trans($obj->code);
-			else print $langs->trans($obj->type);
-			$i++;
-		}
-	}
-	print '</select>';
+    global $db,$langs,$user;
+    $langs->load("trips");
+
+    print '<select class="flat" name="'.$htmlname.'">';
+    if ($showempty)
+    {
+        print '<option value="-1"';
+        if ($selected == -1) print ' selected';
+        print '>&nbsp;</option>';
+    }
+
+    $sql = "SELECT c.id, c.code, c.label as type FROM ".MAIN_DB_PREFIX."c_type_fees as c";
+    $sql.= " ORDER BY c.label ASC";
+    $resql=$db->query($sql);
+    if ($resql)
+    {
+        $num = $db->num_rows($resql);
+        $i = 0;
+
+        while ($i < $num)
+        {
+            $obj = $db->fetch_object($resql);
+            print '<option value="'.$obj->id.'"';
+            if ($obj->code == $selected || $obj->id == $selected) print ' selected';
+            print '>';
+            if ($obj->code != $langs->trans($obj->code)) print $langs->trans($obj->code);
+            else print $langs->trans($obj->type);
+            $i++;
+        }
+    }
+    print '</select>';
 }
diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php
index ef7b8d5311aa90506c75000649cd24be99f7543e..8b83f69ee12bd43f0038c23e6fefb4010caee165 100644
--- a/htdocs/expensereport/list.php
+++ b/htdocs/expensereport/list.php
@@ -245,16 +245,21 @@ if ($resql)
 	$total_total_ht = 0;
 	$total_total_ttc = 0;
 	$total_total_tva = 0;
+	
+	$expensereportstatic=new ExpenseReport($db);
 
 	if($num > 0)
 	{
 		while ($i < min($num,$limit))
 		{
 			$objp = $db->fetch_object($resql);
+			
+			$expensereportstatic->id=$objp->rowid;
+			$expensereportstatic->ref=$objp->ref;
 
 			$var=!$var;
 			print "<tr ".$bc[$var].">";
-			print '<td><a href="card.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowTrip"),"trip").' '.$objp->ref.'</a></td>';
+			print '<td>'.$expensereportstatic->getNomUrl(1).'</td>';
 			print '<td align="center">'.($objp->date_debut > 0 ? dol_print_date($objp->date_debut, 'day') : '').'</td>';
 			print '<td align="center">'.($objp->date_fin > 0 ? dol_print_date($objp->date_fin, 'day') : '').'</td>';
 			print '<td align="left"><a href="'.DOL_URL_ROOT.'/user/card.php?id='.$objp->id_user.'">'.img_object($langs->trans("ShowUser"),"user").' '.dolGetFirstLastname($objp->firstname, $objp->lastname).'</a></td>';
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index 155ac2288e660b0bbdf2e6e089173a8cb73ed3d6..c3bbced76bd461183dc41b97afa2b0c8b6292fe6 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -2313,6 +2313,11 @@ else
 
             print '<div class="tabsAction">';
 
+		$parameters = array();
+		$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
+		                                                                                          // modified by hook
+		if (empty($reshook)) {
+
 		    // Modify a validated invoice with no payments
 			if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $action != 'edit' && $object->getSommePaiement() == 0 && $user->rights->fournisseur->facture->creer)
 			{
@@ -2432,6 +2437,7 @@ else
 				print '</div></div></div>';
                 //print '</td></tr></table>';
             }
+		}
         }
         /*
          * Show mail form
diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php
index a13a3923eabb60c8c3b416978561a2eac361b272..26d1c05721915f05901f45fe0ab58dddafdb0b19 100644
--- a/htdocs/includes/odtphp/odf.php
+++ b/htdocs/includes/odtphp/odf.php
@@ -489,11 +489,11 @@ IMG;
 		$name=preg_replace('/\.odt/i', '', $name);
 		if (!empty($conf->global->MAIN_DOL_SCRIPTS_ROOT))
 		{
-			$command = $conf->global->MAIN_DOL_SCRIPTS_ROOT.'/scripts/odt2pdf/odt2pdf.sh '.$name.' '.(is_numeric($conf->global->MAIN_ODT_AS_PDF)?'jodconverter':$conf->global->MAIN_ODT_AS_PDF);
+			$command = $conf->global->MAIN_DOL_SCRIPTS_ROOT.'/scripts/odt2pdf/odt2pdf.sh '.escapeshellcmd($name).' '.(is_numeric($conf->global->MAIN_ODT_AS_PDF)?'jodconverter':$conf->global->MAIN_ODT_AS_PDF);
 		}
 		else
 		{
-			$command = '../../scripts/odt2pdf/odt2pdf.sh '.$name.' '.(is_numeric($conf->global->MAIN_ODT_AS_PDF)?'jodconverter':$conf->global->MAIN_ODT_AS_PDF);
+			$command = '../../scripts/odt2pdf/odt2pdf.sh '.escapeshellcmd($name).' '.(is_numeric($conf->global->MAIN_ODT_AS_PDF)?'jodconverter':$conf->global->MAIN_ODT_AS_PDF);
 		}
 
 
diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang
index 09858bc092f52b21449401bb06b35b277bde2261..9e801939dccd69ac96566d2e65a4a92ffade7034 100644
--- a/htdocs/langs/en_US/compta.lang
+++ b/htdocs/langs/en_US/compta.lang
@@ -205,3 +205,9 @@ ACCOUNTING_ACCOUNT_SUPPLIER=Accountancy code by default for supplier thirdpartie
 CloneTax=Clone a social/fiscal tax
 ConfirmCloneTax=Confirm the clone of a social/fiscal tax payment
 CloneTaxForNextMonth=Clone it for next month
+SimpleReport=Simple report
+AddExtraReport=Extra reports
+OtherCountriesCustomersReport=Foreign customers report
+BasedOnTwoFirstLettersOfVATNumberBeingDifferentFromYourCompanyCountry=Based on the two first letters of the VAT number being different from your own company's country code
+SameCountryCustomersWithVAT=National customers report
+BasedOnTwoFirstLettersOfVATNumberBeingTheSameAsYourCompanyCountry=Based on the two first letters of the VAT number being the same as your own company's country code
\ No newline at end of file
diff --git a/htdocs/langs/en_US/trips.lang b/htdocs/langs/en_US/trips.lang
index 969ceaa01d6f2382b6efa1e408893dbc6b2d882b..cc14a66aea538b261c028e0e56431126a4ecfa84 100644
--- a/htdocs/langs/en_US/trips.lang
+++ b/htdocs/langs/en_US/trips.lang
@@ -9,6 +9,7 @@ TripCard=Expense report card
 AddTrip=Create expense report
 ListOfTrips=List of expense reports
 ListOfFees=List of fees
+ShowTrip=Show expense report
 NewTrip=New expense report
 CompanyVisited=Company/foundation visited
 Kilometers=Kilometers