diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php
index 8f31b40bc54fee586a0fcd350d9888584cf547df..c5f2e9d8696b3f6042f5565b1b5400ad4b4f2688 100644
--- a/htdocs/accountancy/class/bookkeeping.class.php
+++ b/htdocs/accountancy/class/bookkeeping.class.php
@@ -53,19 +53,19 @@ class BookKeeping extends CommonObject
 	 *
 	 * @var string Name of table without prefix where object is stored
 	 */
-	public $table_element = 'accounting_bookkeeping';  
-	
-	
+	public $table_element = 'accounting_bookkeeping';
+
+
 	public $entity = 1;
-	
-	
+
+
 	/**
 	 *
 	 * @var BookKeepingLine[] Lines
 	 */
 	public $lines = array ();
-	
-	
+
+
 	/**
 	 *
 	 * @var int ID
@@ -89,10 +89,10 @@ class BookKeeping extends CommonObject
 	public $import_key;
 	public $code_journal;
 	public $piece_num;
-	
+
 	/**
 	 */
-	
+
 	/**
 	 * Constructor
 	 *
@@ -101,7 +101,7 @@ class BookKeeping extends CommonObject
 	public function __construct(DoliDB $db) {
 		$this->db = $db;
 	}
-	
+
 	/**
 	 * Create object into database
 	 *
@@ -111,11 +111,11 @@ class BookKeeping extends CommonObject
 	 */
 	public function create(User $user, $notrigger = false) {
 	    global $conf, $langs;
-	    
+
 		dol_syslog(__METHOD__, LOG_DEBUG);
-		
+
 		$error = 0;
-		
+
 		// Clean parameters
 		if (isset($this->doc_type)) {
 			$this->doc_type = trim($this->doc_type);
@@ -164,7 +164,7 @@ class BookKeeping extends CommonObject
 		}
 		if (empty($this->debit)) $this->debit = 0;
 		if (empty($this->credit)) $this->credit = 0;
-		
+
 		// Check parameters
 		if (empty($this->numero_compte) || $this->numero_compte == '-1')
 		{
@@ -175,40 +175,40 @@ class BookKeeping extends CommonObject
             }
             else
             {
-                $this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForInvoiceLine', $this->fk_doc,  $this->doc_type);		    
+                $this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForInvoiceLine', $this->fk_doc,  $this->doc_type);
             }
-		    
+
 		    return -1;
 		}
-		
-		
+
+
 		$this->db->begin();
-		
+
 		$this->piece_num = 0;
-		
+
 		// First check if line not yet already in bookkeeping
 		$sql = "SELECT count(*) as nb";
 		$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
 		$sql .= " WHERE doc_type = '" . $this->doc_type . "'";
 		$sql .= " AND fk_doc = " . $this->fk_doc;
-		$sql .= " AND fk_docdet = " . $this->fk_docdet;                   // This field can be 0 is record is for several lines 
+		$sql .= " AND fk_docdet = " . $this->fk_docdet;                   // This field can be 0 is record is for several lines
 		$sql .= " AND numero_compte = '" . $this->numero_compte . "'";
 	    $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
-		
+
 		$resql = $this->db->query($sql);
-		
+
 		if ($resql) {
 			$row = $this->db->fetch_object($resql);
-			if ($row->nb == 0) 
+			if ($row->nb == 0)
 			{
 				// Determine piece_num
 				$sqlnum = "SELECT piece_num";
 				$sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
-				$sqlnum .= " WHERE doc_type = '" . $this->doc_type . "'";		// For example doc_type = 'bank' 
+				$sqlnum .= " WHERE doc_type = '" . $this->doc_type . "'";		// For example doc_type = 'bank'
 				$sqlnum .= " AND fk_docdet = '" . $this->fk_docdet . "'";		// fk_docdet is rowid into llx_bank or llx_facturedet or llx_facturefourndet, or ...
 				$sqlnum .= " AND doc_ref = '" . $this->doc_ref . "'";			// ref of source object
 			    $sqlnum .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
-				
+
 				dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG);
 				$resqlnum = $this->db->query($sqlnum);
 				if ($resqlnum) {
@@ -220,7 +220,7 @@ class BookKeeping extends CommonObject
 					$sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum";
 					$sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
 				    $sqlnum .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
-						
+
 					dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG);
 					$resqlnum = $this->db->query($sqlnum);
 					if ($resqlnum) {
@@ -232,12 +232,12 @@ class BookKeeping extends CommonObject
 				if (empty($this->piece_num)) {
 					$this->piece_num = 1;
 				}
-				
+
 				$now = dol_now();
 				if (empty($this->date_create)) {
 					$this->date_create = $now;
 				}
-				
+
 				$sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " (";
 				$sql .= "doc_date";
 				$sql .= ", doc_type";
@@ -255,7 +255,7 @@ class BookKeeping extends CommonObject
 				$sql .= ", import_key";
 				$sql .= ", code_journal";
 				$sql .= ", piece_num";
-				$sql .= ', entity';				
+				$sql .= ', entity';
 				$sql .= ") VALUES (";
 				$sql .= "'" . $this->db->idate($this->doc_date) . "'";
 				$sql .= ",'" . $this->doc_type . "'";
@@ -275,12 +275,12 @@ class BookKeeping extends CommonObject
 				$sql .= "," . $this->piece_num;
 				$sql .= ", " . (! isset($this->entity) ? '1' : $this->entity);
 				$sql .= ")";
-				
+
 				dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG);
 				$resql = $this->db->query($sql);
 				if ($resql) {
 					$id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
-					
+
 					if ($id > 0) {
 						$this->id = $id;
 						$result = 0;
@@ -308,20 +308,20 @@ class BookKeeping extends CommonObject
 			$this->errors[] = 'Error ' . $this->db->lasterror();
 			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
 		}
-		
+
 		if (! $error) {
-			
+
 			if (! $notrigger) {
 				// Uncomment this and change MYOBJECT to your own tag if you
 				// want this action to call a trigger.
-				
+
 				// // Call triggers
 				// $result=$this->call_trigger('MYOBJECT_CREATE',$user);
 				// if ($result < 0) $error++;
 				// // End call triggers
 			}
 		}
-		
+
 		// Commit or rollback
 		if ($error) {
 			$this->db->rollback();
@@ -331,7 +331,7 @@ class BookKeeping extends CommonObject
 			return $result;
 		}
 	}
-	
+
 	/**
 	 * Create object into database
 	 *
@@ -341,11 +341,11 @@ class BookKeeping extends CommonObject
 	 */
 	public function createStd(User $user, $notrigger = false) {
 		dol_syslog(__METHOD__, LOG_DEBUG);
-		
+
 		$error = 0;
-		
+
 		// Clean parameters
-		
+
 		if (isset($this->doc_type)) {
 			$this->doc_type = trim($this->doc_type);
 		}
@@ -393,10 +393,10 @@ class BookKeeping extends CommonObject
 		}
 		if (empty($this->debit)) $this->debit = 0;
 		if (empty($this->credit)) $this->credit = 0;
-		
+
 		// Check parameters
 		// Put here code to add control on parameters values
-		
+
 		// Insert request
 		$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
 		$sql .= 'doc_date,';
@@ -435,55 +435,55 @@ class BookKeeping extends CommonObject
 		$sql .= ' ' . (empty($this->piece_num) ? 'NULL' : $this->piece_num).',';
 		$sql .= ' ' . (! isset($this->entity) ? '1' : $this->entity);
 		$sql .= ')';
-		
+
 		$this->db->begin();
-		
+
 		$resql = $this->db->query($sql);
 		if (! $resql) {
 			$error ++;
 			$this->errors[] = 'Error ' . $this->db->lasterror();
 			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
 		}
-		
+
 		if (! $error) {
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
-			
+
 			if (! $notrigger) {
 				// Uncomment this and change MYOBJECT to your own tag if you
 				// want this action to call a trigger.
-				
+
 				// // Call triggers
 				// $result=$this->call_trigger('MYOBJECT_CREATE',$user);
 				// if ($result < 0) $error++;
 				// // End call triggers
 			}
 		}
-		
+
 		// Commit or rollback
 		if ($error) {
 			$this->db->rollback();
-			
+
 			return - 1 * $error;
 		} else {
 			$this->db->commit();
-			
+
 			return $this->id;
 		}
 	}
-	
+
 	/**
 	 * Load object in memory from the database
 	 *
 	 * @param int $id Id object
 	 * @param string $ref Ref
-	 * 
+	 *
 	 * @return int <0 if KO, 0 if not found, >0 if OK
 	 */
 	public function fetch($id, $ref = null) {
 		global $conf;
-		
+
 	    dol_syslog(__METHOD__, LOG_DEBUG);
-		
+
 		$sql = 'SELECT';
 		$sql .= ' t.rowid,';
 		$sql .= " t.doc_date,";
@@ -510,15 +510,15 @@ class BookKeeping extends CommonObject
 		} else {
 			$sql .= ' AND t.rowid = ' . $id;
 		}
-		
+
 		$resql = $this->db->query($sql);
 		if ($resql) {
 			$numrows = $this->db->num_rows($resql);
 			if ($numrows) {
 				$obj = $this->db->fetch_object($resql);
-				
+
 				$this->id = $obj->rowid;
-				
+
 				$this->doc_date = $this->db->jdate($obj->doc_date);
 				$this->doc_type = $obj->doc_type;
 				$this->doc_ref = $obj->doc_ref;
@@ -537,7 +537,7 @@ class BookKeeping extends CommonObject
 				$this->piece_num = $obj->piece_num;
 			}
 			$this->db->free($resql);
-			
+
 			if ($numrows) {
 				return 1;
 			} else {
@@ -546,11 +546,11 @@ class BookKeeping extends CommonObject
 		} else {
 			$this->errors[] = 'Error ' . $this->db->lasterror();
 			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
-			
+
 			return - 1;
 		}
 	}
-  
+
   /**
 	 * Load object in memory from the database
 	 *
@@ -560,14 +560,14 @@ class BookKeeping extends CommonObject
 	 * @param int $offset offset limit
 	 * @param array $filter filter array
 	 * @param string $filtermode filter mode (AND or OR)
-	 *       
+	 *
 	 * @return int <0 if KO, >0 if OK
 	 */
 	public function fetchAllByAccount($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') {
 		global $conf;
-		
+
 	    dol_syslog(__METHOD__, LOG_DEBUG);
-		
+
 		$sql = 'SELECT';
 		$sql .= ' t.rowid,';
 		$sql .= " t.doc_date,";
@@ -620,18 +620,18 @@ class BookKeeping extends CommonObject
 		}
 		if (! empty($limit)) {
 			$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
-		} 
+		}
 		$this->lines = array ();
-		
+
 		$resql = $this->db->query($sql);
 		if ($resql) {
 			$num = $this->db->num_rows($resql);
-			
+
 			while ( $obj = $this->db->fetch_object($resql) ) {
 				$line = new BookKeepingLine();
-				
+
 				$line->id = $obj->rowid;
-				
+
 				$line->doc_date = $this->db->jdate($obj->doc_date);
 				$line->doc_type = $obj->doc_type;
 				$line->doc_ref = $obj->doc_ref;
@@ -648,21 +648,21 @@ class BookKeeping extends CommonObject
 				$line->import_key = $obj->import_key;
 				$line->code_journal = $obj->code_journal;
 				$line->piece_num = $obj->piece_num;
-				
+
 				$this->lines[] = $line;
 			}
 			$this->db->free($resql);
-			
+
 			return $num;
 		} else {
 			$this->errors[] = 'Error ' . $this->db->lasterror();
 			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
-			
+
 			return - 1;
 		}
 	}
-  
-	
+
+
 	/**
 	 * Load object in memory from the database
 	 *
@@ -672,14 +672,14 @@ class BookKeeping extends CommonObject
 	 * @param int $offset offset limit
 	 * @param array $filter filter array
 	 * @param string $filtermode filter mode (AND or OR)
-	 *       
+	 *
 	 * @return int <0 if KO, >0 if OK
 	 */
 	public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') {
 		global $conf;
-		
+
 	    dol_syslog(__METHOD__, LOG_DEBUG);
-		
+
 		$sql = 'SELECT';
 		$sql .= ' t.rowid,';
 		$sql .= " t.doc_date,";
@@ -723,7 +723,7 @@ class BookKeeping extends CommonObject
 		if (count($sqlwhere) > 0) {
 			$sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere);
 		}
-		
+
 		if (! empty($sortfield)) {
 			$sql .= $this->db->order($sortfield, $sortorder);
 		}
@@ -731,16 +731,16 @@ class BookKeeping extends CommonObject
 			$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
 		}
 		$this->lines = array ();
-		
+
 		$resql = $this->db->query($sql);
 		if ($resql) {
 			$num = $this->db->num_rows($resql);
-			
+
 			while ( $obj = $this->db->fetch_object($resql) ) {
 				$line = new BookKeepingLine();
-				
+
 				$line->id = $obj->rowid;
-				
+
 				$line->doc_date = $this->db->jdate($obj->doc_date);
 				$line->doc_type = $obj->doc_type;
 				$line->doc_ref = $obj->doc_ref;
@@ -757,20 +757,20 @@ class BookKeeping extends CommonObject
 				$line->import_key = $obj->import_key;
 				$line->code_journal = $obj->code_journal;
 				$line->piece_num = $obj->piece_num;
-				
+
 				$this->lines[] = $line;
 			}
 			$this->db->free($resql);
-			
+
 			return $num;
 		} else {
 			$this->errors[] = 'Error ' . $this->db->lasterror();
 			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
-			
+
 			return - 1;
 		}
 	}
-	
+
 	/**
 	 * Load object in memory from the database
 	 *
@@ -785,9 +785,9 @@ class BookKeeping extends CommonObject
 	 */
 	public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') {
 		global $conf;
-		
+
 	    dol_syslog(__METHOD__, LOG_DEBUG);
-	
+
 		$sql = 'SELECT';
 		$sql .= " t.numero_compte,";
 		$sql .= " SUM(t.debit) as debit,";
@@ -817,55 +817,55 @@ class BookKeeping extends CommonObject
 		if (count($sqlwhere) > 0) {
 			$sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere);
 		}
-		
+
 		$sql .= ' GROUP BY t.numero_compte';
-	
+
 		if (! empty($sortfield)) {
-			$sql .= $this->db->order($sortfield, $sortorder); 
+			$sql .= $this->db->order($sortfield, $sortorder);
 		}
 		if (! empty($limit)) {
 			$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
 		}
 		$this->lines = array ();
-	
+
 		$resql = $this->db->query($sql);
 		if ($resql) {
 			$num = $this->db->num_rows($resql);
-	
+
 			while ( $obj = $this->db->fetch_object($resql) ) {
 				$line = new BookKeepingLine();
-				
+
 				$line->numero_compte = $obj->numero_compte;
 				$line->debit = $obj->debit;
 				$line->credit = $obj->credit;
 				$this->lines[] = $line;
 			}
 			$this->db->free($resql);
-	
+
 			return $num;
 		} else {
 			$this->errors[] = 'Error ' . $this->db->lasterror();
 			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
-	
+
 			return - 1;
 		}
 	}
-	
+
 	/**
 	 * Update object into database
 	 *
 	 * @param User $user User that modifies
 	 * @param bool $notrigger false=launch triggers after, true=disable triggers
-	 *       
+	 *
 	 * @return int <0 if KO, >0 if OK
 	 */
 	public function update(User $user, $notrigger = false) {
 		$error = 0;
-		
+
 		dol_syslog(__METHOD__, LOG_DEBUG);
-		
+
 		// Clean parameters
-		
+
 		if (isset($this->doc_type)) {
 			$this->doc_type = trim($this->doc_type);
 		}
@@ -911,10 +911,10 @@ class BookKeeping extends CommonObject
 		if (isset($this->piece_num)) {
 			$this->piece_num = trim($this->piece_num);
 		}
-		
+
 		// Check parameters
 		// Put here code to add a control on parameters values
-		
+
 		// Update request
 		$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
 		$sql .= ' doc_date = ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) != 0 ? "'" . $this->db->idate($this->doc_date) . "'" : 'null') . ',';
@@ -934,69 +934,69 @@ class BookKeeping extends CommonObject
 		$sql .= ' code_journal = ' . (isset($this->code_journal) ? "'" . $this->db->escape($this->code_journal) . "'" : "null") . ',';
 		$sql .= ' piece_num = ' . (isset($this->piece_num) ? $this->piece_num : "null");
 		$sql .= ' WHERE rowid=' . $this->id;
-		
+
 		$this->db->begin();
-		
+
 		$resql = $this->db->query($sql);
 		if (! $resql) {
 			$error ++;
 			$this->errors[] = 'Error ' . $this->db->lasterror();
 			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
 		}
-		
+
 		if (! $error && ! $notrigger) {
 			// Uncomment this and change MYOBJECT to your own tag if you
 			// want this action calls a trigger.
-			
+
 			// // Call triggers
 			// $result=$this->call_trigger('MYOBJECT_MODIFY',$user);
 			// if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
 			// // End call triggers
 		}
-		
+
 		// Commit or rollback
 		if ($error) {
 			$this->db->rollback();
-			
+
 			return - 1 * $error;
 		} else {
 			$this->db->commit();
-			
+
 			return 1;
 		}
 	}
-	
+
 	/**
 	 * Delete object in database
 	 *
 	 * @param User $user User that deletes
 	 * @param bool $notrigger false=launch triggers after, true=disable triggers
-	 *       
+	 *
 	 * @return int <0 if KO, >0 if OK
 	 */
 	public function delete(User $user, $notrigger = false) {
 		dol_syslog(__METHOD__, LOG_DEBUG);
-		
+
 		$error = 0;
-		
+
 		$this->db->begin();
-		
+
 		if (! $error) {
 			if (! $notrigger) {
 				// Uncomment this and change MYOBJECT to your own tag if you
 				// want this action calls a trigger.
-				
+
 				// // Call triggers
 				// $result=$this->call_trigger('MYOBJECT_DELETE',$user);
 				// if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
 				// // End call triggers
 			}
 		}
-		
+
 		if (! $error) {
 			$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
 			$sql .= ' WHERE rowid=' . $this->id;
-			
+
 			$resql = $this->db->query($sql);
 			if (! $resql) {
 				$error ++;
@@ -1004,19 +1004,19 @@ class BookKeeping extends CommonObject
 				dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
 			}
 		}
-		
+
 		// Commit or rollback
 		if ($error) {
 			$this->db->rollback();
-			
+
 			return - 1 * $error;
 		} else {
 			$this->db->commit();
-			
+
 			return 1;
 		}
 	}
-	
+
 	/**
 	 * Delete bookkepping by importkey
 	 *
@@ -1025,25 +1025,25 @@ class BookKeeping extends CommonObject
 	 */
 	function deleteByImportkey($importkey) {
 		$this->db->begin();
-		
+
 		// first check if line not yet in bookkeeping
 		$sql = "DELETE";
 		$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
 		$sql .= " WHERE import_key = '" . $importkey . "'";
-		
+
 		$resql = $this->db->query($sql);
-		
+
 		if (! $resql) {
 			$this->errors[] = "Error " . $this->db->lasterror();
 			dol_syslog(get_class($this)."::delete Error " . $this->db->lasterror(), LOG_ERR);
 			$this->db->rollback();
 			return - 1;
 		}
-		
+
 		$this->db->commit();
 		return 1;
 	}
-	
+
 	/**
 	 * Delete bookkepping by year
 	 *
@@ -1053,14 +1053,14 @@ class BookKeeping extends CommonObject
 	 */
 	function deleteByYearAndJournal($delyear='', $journal='') {
 	    global $conf;
-	    
-	    if (empty($delyear) && empty($journal)) 
+
+	    if (empty($delyear) && empty($journal))
 	    {
 	        return -1;
 	    }
-	    
+
 		$this->db->begin();
-		
+
 		// first check if line not yet in bookkeeping
 		$sql = "DELETE";
 		$sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element;
@@ -1069,7 +1069,7 @@ class BookKeeping extends CommonObject
 		if (! empty($journal)) $sql.= " AND code_journal = '".$journal."'";
 	    $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
 		$resql = $this->db->query($sql);
-		
+
 		if (! $resql) {
 			$this->errors[] = "Error " . $this->db->lasterror();
 			foreach ( $this->errors as $errmsg ) {
@@ -1079,11 +1079,11 @@ class BookKeeping extends CommonObject
 			$this->db->rollback();
 			return -1;
 		}
-		
+
 		$this->db->commit();
 		return 1;
 	}
-	
+
 	/**
 	 * Delete bookkepping by piece number
 	 *
@@ -1092,17 +1092,17 @@ class BookKeeping extends CommonObject
 	 */
 	function deleteMvtNum($piecenum) {
 	    global $conf;
-	    
+
 		$this->db->begin();
-		
+
 		// first check if line not yet in bookkeeping
 		$sql = "DELETE";
 		$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
 		$sql .= " WHERE piece_num = " . $piecenum;
 	    $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
-		
+
 		$resql = $this->db->query($sql);
-		
+
 		if (! $resql) {
 			$this->errors[] = "Error " . $this->db->lasterror();
 			foreach ( $this->errors as $errmsg ) {
@@ -1112,57 +1112,57 @@ class BookKeeping extends CommonObject
 			$this->db->rollback();
 			return - 1;
 		}
-		
+
 		$this->db->commit();
 		return 1;
 	}
-	
+
 	/**
 	 * Load an object from its id and create a new one in database
 	 *
 	 * @param int $fromid Id of object to clone
-	 *       
+	 *
 	 * @return int New id of clone
 	 */
 	public function createFromClone($fromid) {
 		dol_syslog(__METHOD__, LOG_DEBUG);
-		
+
 		global $user;
 		$error = 0;
-		$object = new Accountingbookkeeping($this->db);
-		
+		$object = new BookKeeping($this->db);
+
 		$this->db->begin();
-		
+
 		// Load source object
 		$object->fetch($fromid);
 		// Reset object
 		$object->id = 0;
-		
+
 		// Clear fields
 		// ...
-		
+
 		// Create clone
 		$result = $object->create($user);
-		
+
 		// Other options
 		if ($result < 0) {
 			$error ++;
 			$this->errors = $object->errors;
 			dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
 		}
-		
+
 		// End
 		if (! $error) {
 			$this->db->commit();
-			
+
 			return $object->id;
 		} else {
 			$this->db->rollback();
-			
+
 			return - 1;
 		}
 	}
-	
+
 	/**
 	 * Initialise object with example values
 	 * Id must be 0 if object instance is a specimen
@@ -1171,9 +1171,9 @@ class BookKeeping extends CommonObject
 	 */
 	public function initAsSpecimen() {
 		global $user;
-		
+
 		$now=dol_now();
-		
+
 		$this->id = 0;
 		$this->doc_date = $now;
 		$this->doc_type = '';
@@ -1192,7 +1192,7 @@ class BookKeeping extends CommonObject
 		$this->code_journal = '';
 		$this->piece_num = '';
 	}
-	
+
 	/**
 	 * Load an accounting document into memory from database
 	 *
@@ -1201,17 +1201,17 @@ class BookKeeping extends CommonObject
 	 */
 	public function fetchPerMvt($piecenum) {
 		global $conf;
-		
+
 	    $sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type";
 		$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
 		$sql .= " WHERE piece_num = " . $piecenum;
 	    $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
-		
+
 		dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
 		$result = $this->db->query($sql);
 		if ($result) {
 			$obj = $this->db->fetch_object($result);
-			
+
 			$this->piece_num = $obj->piece_num;
 			$this->code_journal = $obj->code_journal;
 			$this->doc_date = $this->db->jdate($obj->doc_date);
@@ -1222,22 +1222,22 @@ class BookKeeping extends CommonObject
 			dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR);
 			return - 1;
 		}
-		
+
 		return 1;
 	}
-	
+
 	/**
 	 * Return next number movement
 	 *
 	 * @return string      Next numero to use
 	 */
-	public function getNextNumMvt() 
+	public function getNextNumMvt()
 	{
 	    global $conf;
-	    
+
 		$sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element;
 	    $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
-		
+
 		dol_syslog(get_class($this) . "getNextNumMvt sql=" . $sql, LOG_DEBUG);
 		$result = $this->db->query($sql);
 
@@ -1252,7 +1252,7 @@ class BookKeeping extends CommonObject
 			return - 1;
 		}
 	}
-	
+
 	/**
 	 * Load all informations of accountancy document
 	 *
@@ -1261,7 +1261,7 @@ class BookKeeping extends CommonObject
 	 */
 	function fetch_all_per_mvt($piecenum) {
 	    global $conf;
-	    
+
 		$sql = "SELECT rowid, doc_date, doc_type,";
 		$sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,";
 		$sql .= " numero_compte, label_compte, debit, credit,";
@@ -1269,17 +1269,17 @@ class BookKeeping extends CommonObject
 		$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
 		$sql .= " WHERE piece_num = " . $piecenum;
 	    $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")";
-		
+
 		dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
 		$result = $this->db->query($sql);
 		if ($result) {
-			
+
 			while ( $obj = $this->db->fetch_object($result) ) {
-				
+
 				$line = new BookKeepingLine();
-				
+
 				$line->id = $obj->rowid;
-				
+
 				$line->doc_date = $this->db->jdate($obj->doc_date);
 				$line->doc_type = $obj->doc_type;
 				$line->doc_ref = $obj->doc_ref;
@@ -1294,7 +1294,7 @@ class BookKeeping extends CommonObject
 				$line->sens = $obj->sens;
 				$line->code_journal = $obj->code_journal;
 				$line->piece_num = $obj->piece_num;
-				
+
 				$this->linesmvt[] = $line;
 			}
 		} else {
@@ -1302,10 +1302,10 @@ class BookKeeping extends CommonObject
 			dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR);
 			return - 1;
 		}
-		
+
 		return 1;
 	}
-	
+
 	/**
 	 * Export bookkeping
 	 *
@@ -1314,27 +1314,27 @@ class BookKeeping extends CommonObject
 	 */
 	function export_bookkeping($model = 'ebp') {
 	    global $conf;
-	    
+
 		$sql = "SELECT rowid, doc_date, doc_type,";
 		$sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,";
 		$sql .= " numero_compte, label_compte, debit, credit,";
 		$sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num";
 		$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
 	    $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
-		
+
 		dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG);
-		
+
 		$resql = $this->db->query($sql);
-		
+
 		if ($resql) {
 			$this->linesexport = array ();
-			
+
 			$num = $this->db->num_rows($resql);
 			while ( $obj = $this->db->fetch_object($resql) ) {
 				$line = new BookKeepingLine();
-				
+
 				$line->id = $obj->rowid;
-				
+
 				$line->doc_date = $this->db->jdate($obj->doc_date);
 				$line->doc_type = $obj->doc_type;
 				$line->doc_ref = $obj->doc_ref;
@@ -1349,11 +1349,11 @@ class BookKeeping extends CommonObject
 				$line->sens = $obj->sens;
 				$line->code_journal = $obj->code_journal;
 				$line->piece_num = $obj->piece_num;
-				
+
 				$this->linesexport[] = $line;
 			}
 			$this->db->free($resql);
-			
+
 			return $num;
 		} else {
 			$this->error = "Error " . $this->db->lasterror();
@@ -1361,9 +1361,9 @@ class BookKeeping extends CommonObject
 			return - 1;
 		}
 	}
-  
-  
-  
+
+
+
     /**
     * Return list of accounts with label by chart of accounts
     *
@@ -1378,11 +1378,11 @@ class BookKeeping extends CommonObject
     */
     function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '') {
         global $conf;
-        
+
         require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
-        
+
         $pcgver = $conf->global->CHARTOFACCOUNTS;
-        
+
         $sql = "SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
         $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab";
         $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = ab.numero_compte";
@@ -1391,82 +1391,82 @@ class BookKeeping extends CommonObject
         $sql .= " AND asy.rowid = " . $pcgver;
 	    $sql .= " AND ab.entity IN (" . getEntity("accountancy", 1) . ")";
         $sql .= " ORDER BY account_number ASC";
-        
+
         dol_syslog(get_class($this) . "::select_account", LOG_DEBUG);
         $resql = $this->db->query($sql);
-        
+
         if (! $resql) {
             $this->error = "Error " . $this->db->lasterror();
             dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR);
             return - 1;
         }
-        
+
         $out = ajax_combobox($htmlname, $event);
-        
+
         $options = array();
         $selected = null;
-        
+
         while ($obj = $this->db->fetch_object($resql)) {
             $label = length_accountg($obj->account_number) . ' - ' . $obj->label;
-            
+
             $select_value_in = $obj->rowid;
             $select_value_out = $obj->rowid;
-            
+
             if ($select_in == 1) {
                 $select_value_in = $obj->account_number;
             }
             if ($select_out == 1) {
                 $select_value_out = $obj->account_number;
             }
-            
+
             // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number
             // Because same account_number can be share between different accounting_system and do have the same meaning
             if (($selectid != '') && $selectid == $select_value_in) {
                 $selected = $select_value_out;
             }
-            
+
             $options[$select_value_out] = $label;
         }
-        
+
         $out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', 'maxwidth300');
         $this->db->free($resql);
         return $out;
     }
 
-  
-	
+
+
 	/**
-	* Description of a root accounting account 
+	* Description of a root accounting account
 	*
 	* @param 	string 	$account	Accounting account
 	* @return 	string 	            Root account
 	*/
 	function get_compte_racine($account = null)
-	{	
+	{
 		global $conf;
 		$pcgver = $conf->global->CHARTOFACCOUNTS;
-        
+
         $sql  = "SELECT root.account_number, root.label as label";
         $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
         $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
         $sql .= " AND asy.rowid = " . $pcgver;
         $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as parent ON aa.account_parent = parent.rowid";
         $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as root ON parent.account_parent = root.rowid";
-        $sql .= " WHERE aa.account_number = '" . $account . "'";  
+        $sql .= " WHERE aa.account_number = '" . $account . "'";
         $sql .= " AND parent.active = 1";
         $sql .= " AND root.active = 1";
         $sql .= " AND aa.entity IN (" . getEntity("accountancy", 1) . ")";
-        
+
 		dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG);
 		$resql = $this->db->query($sql);
 		if ($resql) {
 			$obj = '';
 			if ($this->db->num_rows($resql)) {
-				$obj = $this->db->fetch_object($resql);	
+				$obj = $this->db->fetch_object($resql);
 			}
-							
+
 			return $obj->label;
-			
+
 		} else {
 			$this->error = "Error " . $this->db->lasterror();
 			dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR);
@@ -1474,8 +1474,8 @@ class BookKeeping extends CommonObject
 			return -1;
 		}
 	}
-  
-  
+
+
   /**
 	* Description of accounting account
 	*
@@ -1483,9 +1483,9 @@ class BookKeeping extends CommonObject
 	* @return 	string 	            Account desc
 	*/
 	function get_compte_desc($account = null)
-	{	
+	{
 		global $conf;
-		
+
 		$pcgver = $conf->global->CHARTOFACCOUNTS;
 		$sql  = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
 		$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa ";
@@ -1495,20 +1495,20 @@ class BookKeeping extends CommonObject
 		$sql .= " AND aa.active = 1";
 		$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
 	    $sql .= " WHERE aa.entity IN (" . getEntity("accountancy", 1) . ")";
-		
+
 		dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG);
 		$resql = $this->db->query($sql);
 		if ($resql) {
 			$obj = '';
 			if ($this->db->num_rows($resql)) {
-				$obj = $this->db->fetch_object($resql);	
+				$obj = $this->db->fetch_object($resql);
 			}
-			
-			if(empty($obj->category)){				
+
+			if(empty($obj->category)){
 				return $obj->label;
 			}else{
 				return $obj->label.' ('.$obj->category.')';
-				
+
 			}
 		} else {
 			$this->error = "Error " . $this->db->lasterror();
@@ -1516,7 +1516,7 @@ class BookKeeping extends CommonObject
 			return -1;
 		}
 	}
-	
+
 }
 
 
diff --git a/htdocs/compta/paiement/class/cpaiement.class.php b/htdocs/compta/paiement/class/cpaiement.class.php
index 5428f4abdbf81a72ea8a380dfd341bf00ade70a8..c91b7276633c55ce4bc0b84ee3bdd4f7b628b155 100644
--- a/htdocs/compta/paiement/class/cpaiement.class.php
+++ b/htdocs/compta/paiement/class/cpaiement.class.php
@@ -46,7 +46,7 @@ class Cpaiement
 
 	/**
 	 */
-	
+
 	public $code;
 	public $libelle;
 	public $type;
@@ -56,7 +56,7 @@ class Cpaiement
 
 	/**
 	 */
-	
+
 
 	/**
 	 * Constructor
@@ -83,7 +83,7 @@ class Cpaiement
 		$error = 0;
 
 		// Clean parameters
-		
+
 		if (isset($this->code)) {
 			 $this->code = trim($this->code);
 		}
@@ -103,14 +103,14 @@ class Cpaiement
 			 $this->module = trim($this->module);
 		}
 
-		
+
 
 		// Check parameters
 		// Put here code to add control on parameters values
 
 		// Insert request
 		$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
-		
+
 		$sql.= 'id,';
 		$sql.= 'code,';
 		$sql.= 'libelle,';
@@ -119,9 +119,9 @@ class Cpaiement
 		$sql.= 'accountancy_code,';
 		$sql.= 'module';
 
-		
+
 		$sql .= ') VALUES (';
-		
+
 		$sql .= ' '.(! isset($this->id)?'NULL':$this->id).',';
 		$sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").',';
 		$sql .= ' '.(! isset($this->libelle)?'NULL':"'".$this->db->escape($this->libelle)."'").',';
@@ -130,7 +130,7 @@ class Cpaiement
 		$sql .= ' '.(! isset($this->accountancy_code)?'NULL':"'".$this->db->escape($this->accountancy_code)."'").',';
 		$sql .= ' '.(! isset($this->module)?'NULL':"'".$this->db->escape($this->module)."'");
 
-		
+
 		$sql .= ')';
 
 		$this->db->begin();
@@ -202,7 +202,7 @@ class Cpaiement
 				$obj = $this->db->fetch_object($resql);
 
 				$this->id = $obj->id;
-				
+
 				$this->code = $obj->code;
 				$this->libelle = $obj->libelle;
 				$this->type = $obj->type;
@@ -210,7 +210,7 @@ class Cpaiement
 				$this->accountancy_code = $obj->accountancy_code;
 				$this->module = $obj->module;
 
-				
+
 			}
 			$this->db->free($resql);
 
@@ -252,7 +252,7 @@ class Cpaiement
 		$sql .= " t.accountancy_code,";
 		$sql .= " t.module";
 
-		
+
 		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
 
 		// Manage filter
@@ -265,7 +265,7 @@ class Cpaiement
 		if (count($sqlwhere) > 0) {
 			$sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
 		}
-		
+
 		if (!empty($sortfield)) {
 			$sql .= $this->db->order($sortfield,$sortorder);
 		}
@@ -279,10 +279,10 @@ class Cpaiement
 			$num = $this->db->num_rows($resql);
 
 			while ($obj = $this->db->fetch_object($resql)) {
-				$line = new CpaiementLine();
+				$line = new Cpaiement();
 
 				$line->id = $obj->id;
-				
+
 				$line->code = $obj->code;
 				$line->libelle = $obj->libelle;
 				$line->type = $obj->type;
@@ -290,7 +290,7 @@ class Cpaiement
 				$line->accountancy_code = $obj->accountancy_code;
 				$line->module = $obj->module;
 
-				
+
 
 				$this->lines[$line->id] = $line;
 			}
@@ -320,7 +320,7 @@ class Cpaiement
 		dol_syslog(__METHOD__, LOG_DEBUG);
 
 		// Clean parameters
-		
+
 		if (isset($this->code)) {
 			 $this->code = trim($this->code);
 		}
@@ -340,7 +340,7 @@ class Cpaiement
 			 $this->module = trim($this->module);
 		}
 
-		
+
 
 		// Check parameters
 		// Put here code to add a control on parameters values
@@ -438,8 +438,8 @@ class Cpaiement
 			return 1;
 		}
 	}
-	
-	
+
+
 	/**
 	 * Initialise object with example values
 	 * Id must be 0 if object instance is a specimen
@@ -449,7 +449,7 @@ class Cpaiement
 	public function initAsSpecimen()
 	{
 		$this->id = 0;
-		
+
 		$this->code = '';
 		$this->libelle = '';
 		$this->type = '';
@@ -457,7 +457,7 @@ class Cpaiement
 		$this->accountancy_code = '';
 		$this->module = '';
 
-		
+
 	}
 
 }