From cbec43e098ff8c0e0e02fe8cf0e7b54eaf11dcd1 Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Wed, 9 Nov 2011 06:10:31 +0800
Subject: [PATCH] Fix: change 'editfieldkey' and 'editfieldval' for
 compatibility with external module and hook system. Fix: uniform code

---
 htdocs/comm/fiche.php                         | 230 +++++++-------
 htdocs/comm/mailing/fiche.php                 |  12 +-
 htdocs/compta/deplacement/fiche.php           |  20 +-
 htdocs/compta/paiement/fiche.php              |  12 +-
 htdocs/core/ajax/loadinplace.php              |  14 +-
 htdocs/core/class/html.form.class.php         |  50 +--
 htdocs/core/js/editinplace.js                 |  98 +++---
 htdocs/core/lib/functions.lib.php             |   8 -
 htdocs/expedition/fiche.php                   |  20 +-
 htdocs/fichinter/fiche.php                    |  12 +-
 htdocs/fourn/facture/fiche.php                | 300 +++++++++---------
 htdocs/fourn/fiche.php                        | 108 +++----
 htdocs/fourn/paiement/fiche.php               |  92 +++---
 .../product/actions_card_product.class.php    |   8 +-
 .../service/actions_card_service.class.php    |   8 +-
 htdocs/product/fiche.php                      |   8 +-
 htdocs/product/stock/product.php              |   4 +-
 17 files changed, 506 insertions(+), 498 deletions(-)

diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php
index 9355bb0d491..6bbd07771b2 100644
--- a/htdocs/comm/fiche.php
+++ b/htdocs/comm/fiche.php
@@ -49,12 +49,13 @@ if ($conf->notification->enabled) $langs->load("mails");
 if (!empty($conf->global->MAIN_MODULE_CHRONODOCS)) $langs->load("chronodocs");
 
 // Security check
-$socid = isset($_GET["socid"])?$_GET["socid"]:'';
-if ($user->societe_id > 0) $socid=$user->societe_id;
-$result = restrictedArea($user,'societe',$socid,'');
+$id = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id'));
+if ($user->societe_id > 0) $id=$user->societe_id;
+$result = restrictedArea($user,'societe',$id,'');
 
-$mode=GETPOST("mode");
-$modesearch=GETPOST("mode_search");
+$action		= GETPOST('action');
+$mode		= GETPOST("mode");
+$modesearch	= GETPOST("mode_search");
 
 $sortfield = GETPOST("sortfield",'alpha');
 $sortorder = GETPOST("sortorder",'alpha');
@@ -66,61 +67,61 @@ $pagenext = $page + 1;
 if (! $sortorder) $sortorder="ASC";
 if (! $sortfield) $sortfield="nom";
 
+$object = new Societe($db);
 
 /*
  * Actions
  */
 
-if ($_POST['action'] == 'setcustomeraccountancycode')
+if ($action == 'setcustomeraccountancycode')
 {
-	$societe = new Societe($db);
-	$result=$societe->fetch($_POST['socid']);
-	$societe->code_compta=$_POST["customeraccountancycode"];
-	$result=$societe->update($societe->id,$user,1,1,0);
+	$result=$object->fetch($id);
+	$object->code_compta=$_POST["customeraccountancycode"];
+	$result=$object->update($object->id,$user,1,1,0);
 	if ($result < 0)
 	{
-		$mesg=join(',',$societe->errors);
+		$mesg=join(',',$object->errors);
 	}
-	$POST["action"]="";
-	$socid=$_POST["socid"];
+	$action="";
 }
 
-if ($_GET["action"] == 'attribute_prefix' && $user->rights->societe->creer)
+if ($action == 'attribute_prefix' && $user->rights->societe->creer)
 {
-	$societe = new Societe($db);
-	$societe->fetch($_GET["socid"]);
-	$societe->attribute_prefix($db, $_GET["socid"]);
+	$object->fetch($id);
+	$object->attribute_prefix($db, $id);
 }
 // conditions de reglement
-if ($_POST["action"] == 'setconditions' && $user->rights->societe->creer)
+if ($action == 'setconditions' && $user->rights->societe->creer)
 {
-
-	$societe = new Societe($db);
-	$societe->fetch($_GET["socid"]);
-	$societe->cond_reglement=$_POST['cond_reglement_id'];
+	$object->fetch($id);
+	$object->cond_reglement=$_POST['cond_reglement_id'];
+	
+	// TODO move to DAO class
 	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET cond_reglement='".$_POST['cond_reglement_id'];
-	$sql.= "' WHERE rowid='".$_GET["socid"]."'";
+	$sql.= "' WHERE rowid='".$id."'";
 	$result = $db->query($sql);
 	if (! $result) dol_print_error($result);
 }
 // mode de reglement
-if ($_POST["action"] == 'setmode' && $user->rights->societe->creer)
+if ($action == 'setmode' && $user->rights->societe->creer)
 {
-	$societe = new Societe($db);
-	$societe->fetch($_GET["socid"]);
-	$societe->mode_reglement=$_POST['mode_reglement_id'];
+	$obejct->fetch($id);
+	$object->mode_reglement=$_POST['mode_reglement_id'];
+	
+	// TODO move to DAO class
 	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET mode_reglement='".$_POST['mode_reglement_id'];
-	$sql.= "' WHERE rowid='".$_GET["socid"]."'";
+	$sql.= "' WHERE rowid='".$id."'";
 	$result = $db->query($sql);
 	if (! $result) dol_print_error($result);
 }
 // assujetissement a la TVA
-if ($_POST["action"] == 'setassujtva' && $user->rights->societe->creer)
+if ($action == 'setassujtva' && $user->rights->societe->creer)
 {
-	$societe = new Societe($db);
-	$societe->fetch($_GET["socid"]);
-	$societe->tva_assuj=$_POST['assujtva_value'];
-	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET tva_assuj='".$_POST['assujtva_value']."' WHERE rowid='".$socid."'";
+	$object->fetch($id);
+	$object->tva_assuj=$_POST['assujtva_value'];
+	
+	// TODO move to DAO class
+	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET tva_assuj='".$_POST['assujtva_value']."' WHERE rowid='".$id."'";
 	$result = $db->query($sql);
 	if (! $result) dol_print_error($result);
 }
@@ -143,12 +144,13 @@ if ($mode == 'search')
 {
 	if ($modesearch == 'soc')
 	{
+		// TODO move to DAO class
 		$sql = "SELECT s.rowid";
-		if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
+		if (!$user->rights->societe->client->voir && !$id) $sql .= ", sc.fk_soc, sc.fk_user ";
 		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
-		if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+		if (!$user->rights->societe->client->voir && !$id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 		$sql .= " WHERE lower(s.nom) like '%".strtolower($socname)."%'";
-		if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+		if (!$user->rights->societe->client->voir && !$id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
 	}
 
 	$resql=$db->query($sql);
@@ -157,22 +159,20 @@ if ($mode == 'search')
 		if ( $db->num_rows($resql) == 1)
 		{
 			$obj = $db->fetch_object($resql);
-			$socid = $obj->rowid;
+			$id = $obj->rowid;
 		}
 		$db->free($resql);
 	}
 }
 
 
-if ($socid > 0)
+if ($id > 0)
 {
 	// Load data of third party
-	$objsoc = new Societe($db);
-	$objsoc->id=$socid;
-	$objsoc->fetch($socid,$to);
-	if ($objsoc->id <= 0)
+	$object->fetch($id);
+	if ($object->id <= 0)
 	{
-		dol_print_error($db,$objsoc->error);
+		dol_print_error($db,$object->error);
 	}
 
 	if ($errmesg)
@@ -184,7 +184,7 @@ if ($socid > 0)
 	 * Affichage onglets
 	 */
 
-	$head = societe_prepare_head($objsoc);
+	$head = societe_prepare_head($object);
 
 	dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"),0,'company');
 
@@ -195,69 +195,70 @@ if ($socid > 0)
 	print '<table class="border" width="100%">';
 
 	print '<tr><td width="30%">'.$langs->trans("ThirdPartyName").'</td><td width="70%" colspan="3">';
-	$objsoc->next_prev_filter="te.client in (1,3)";
-	print $form->showrefnav($objsoc,'socid','',($user->societe_id?0:1),'rowid','nom','','');
+	$object->next_prev_filter="te.client in (1,3)";
+	print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','','');
 	print '</td></tr>';
 
 	// Prefix
     if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
     {
         print '<tr><td>'.$langs->trans("Prefix").'</td><td colspan="3">';
-	   print ($objsoc->prefix_comm?$objsoc->prefix_comm:'&nbsp;');
+	   print ($object->prefix_comm?$object->prefix_comm:'&nbsp;');
 	   print '</td></tr>';
     }
 
-	if ($objsoc->client)
+	if ($object->client)
 	{
         $langs->load("compta");
 
 		print '<tr><td nowrap>';
 		print $langs->trans('CustomerCode').'</td><td colspan="3">';
-		print $objsoc->code_client;
-		if ($objsoc->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
+		print $object->code_client;
+		if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
 		print '</td></tr>';
 
 		print '<tr>';
 		print '<td>';
-		print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$objsoc->code_compta,'socid',$objsoc->id,$user->rights->societe->creer);
+		print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
 		print '</td><td colspan="3">';
-		print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$objsoc->code_compta,'socid',$objsoc->id,$user->rights->societe->creer);
+		print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
 		print '</td>';
 		print '</tr>';
 	}
 
 	// Address
 	print '<tr><td valign="top">'.$langs->trans('Address').'</td><td colspan="3">';
-	dol_print_address($objsoc->address,'gmap','thirdparty',$objsoc->id);
+	dol_print_address($object->address,'gmap','thirdparty',$object->id);
 	print "</td></tr>";
 
 	// Zip / Town
-	print '<tr><td nowrap="nowrap">'.$langs->trans('Zip').' / '.$langs->trans('Town').'</td><td colspan="3">'.$objsoc->cp.(($objsoc->cp && $objsoc->ville)?' / ':'').$objsoc->ville."</td>";
+	print '<tr><td nowrap="nowrap">'.$langs->trans('Zip').' / '.$langs->trans('Town').'</td>';
+	print '<td colspan="3">'.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town."</td>";
 	print '</tr>';
 
 	// Country
 	print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
-	$img=picto_from_langcode($objsoc->pays_code);
-	if ($objsoc->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$objsoc->pays,$langs->trans("CountryIsInEEC"),1,0);
-	else print ($img?$img.' ':'').$objsoc->pays;
+	$img=picto_from_langcode($object->country_code);
+	if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0);
+	else print ($img?$img.' ':'').$object->country;
 	print '</td></tr>';
 
 	// Phone
-	print '<tr><td>'.$langs->trans('Phone').'</td><td style="min-width: 25%;">'.dol_print_phone($objsoc->tel,$objsoc->pays_code,0,$objsoc->id,'AC_TEL').'</td>';
+	print '<tr><td>'.$langs->trans('Phone').'</td><td style="min-width: 25%;">'.dol_print_phone($object->tel,$object->country_code,0,$object->id,'AC_TEL').'</td>';
 
 	// Fax
-	print '<td>'.$langs->trans('Fax').'</td><td style="min-width: 25%;">'.dol_print_phone($objsoc->fax,$objsoc->pays_code,0,$objsoc->id,'AC_FAX').'</td></tr>';
+	print '<td>'.$langs->trans('Fax').'</td><td style="min-width: 25%;">'.dol_print_phone($object->fax,$object->country_code,0,$object->id,'AC_FAX').'</td></tr>';
 
 	// EMail
-	print '<td>'.$langs->trans('EMail').'</td><td colspan="3">'.dol_print_email($objsoc->email,0,$objsoc->id,'AC_EMAIL').'</td></tr>';
+	print '<td>'.$langs->trans('EMail').'</td><td colspan="3">'.dol_print_email($object->email,0,$object->id,'AC_EMAIL').'</td></tr>';
 
 	// Web
-	print '<tr><td>'.$langs->trans("Web").'</td><td colspan="3">'.dol_print_url($objsoc->url,'_blank').'</td></tr>';
+	print '<tr><td>'.$langs->trans("Web").'</td><td colspan="3">'.dol_print_url($object->url,'_blank').'</td></tr>';
 
 	// Assujeti a TVA ou pas
 	print '<tr>';
 	print '<td nowrap="nowrap">'.$langs->trans('VATIsUsed').'</td><td colspan="3">';
-	print yn($objsoc->tva_assuj);
+	print yn($object->tva_assuj);
 	print '</td>';
 	print '</tr>';
 
@@ -267,29 +268,29 @@ if ($socid > 0)
 		if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
 		{
 			print '<tr><td nowrap="nowrap">'.$langs->trans('LocalTax1IsUsedES').'</td><td colspan="3">';
-			print yn($objsoc->localtax1_assuj);
+			print yn($object->localtax1_assuj);
 			print '</td></tr>';
 			print '<tr><td nowrap="nowrap">'.$langs->trans('LocalTax2IsUsedES').'</td><td colspan="3">';
-			print yn($objsoc->localtax2_assuj);
+			print yn($object->localtax2_assuj);
 			print '</td></tr>';
 		}
 		elseif($mysoc->localtax1_assuj=="1")
 		{
 			print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">';
-			print yn($objsoc->localtax1_assuj);
+			print yn($object->localtax1_assuj);
 			print '</td></tr>';
 		}
 		elseif($mysoc->localtax2_assuj=="1")
 		{
 			print '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">';
-			print yn($objsoc->localtax2_assuj);
+			print yn($object->localtax2_assuj);
 			print '</td></tr>';
 		}
 	}
 
 	// TVA Intra
 	print '<tr><td nowrap>'.$langs->trans('VATIntraVeryShort').'</td><td colspan="3">';
-	print $objsoc->tva_intra;
+	print $object->tva_intra;
 	print '</td></tr>';
 
 	// Conditions de reglement par defaut
@@ -299,16 +300,16 @@ if ($socid > 0)
 	print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
 	print $langs->trans('PaymentConditions');
 	print '<td>';
-	if (($_GET['action'] != 'editconditions') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;socid='.$objsoc->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
+	if (($action != 'editconditions') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
 	print '</tr></table>';
 	print '</td><td colspan="3">';
-	if ($_GET['action'] == 'editconditions')
+	if ($action == 'editconditions')
 	{
-		$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$objsoc->id,$objsoc->cond_reglement,'cond_reglement_id',-1,1);
+		$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement,'cond_reglement_id',-1,1);
 	}
 	else
 	{
-		$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$objsoc->id,$objsoc->cond_reglement,'none');
+		$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement,'none');
 	}
 	print "</td>";
 	print '</tr>';
@@ -318,16 +319,16 @@ if ($socid > 0)
 	print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
 	print $langs->trans('PaymentMode');
 	print '<td>';
-	if (($_GET['action'] != 'editmode') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;socid='.$objsoc->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
+	if (($action != 'editmode') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
 	print '</tr></table>';
 	print '</td><td colspan="3">';
-	if ($_GET['action'] == 'editmode')
+	if ($action == 'editmode')
 	{
-		$form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$objsoc->id,$objsoc->mode_reglement,'mode_reglement_id');
+		$form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement,'mode_reglement_id');
 	}
 	else
 	{
-		$form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$objsoc->id,$objsoc->mode_reglement,'none');
+		$form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement,'none');
 	}
 	print "</td>";
 	print '</tr>';
@@ -339,10 +340,10 @@ if ($socid > 0)
 	print '<td><td align="right">';
 	if ($user->rights->societe->creer && !$user->societe_id > 0)
 	{
-		print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$objsoc->id.'">'.img_edit($langs->trans("Modify")).'</a>';
+		print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
 	}
 	print '</td></tr></table>';
-	print '</td><td colspan="3">'.($objsoc->remise_client?'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$objsoc->id.'">'.$objsoc->remise_client.'%</a>':$langs->trans("DiscountNone")).'</td>';
+	print '</td><td colspan="3">'.($object->remise_client?'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_client.'%</a>':$langs->trans("DiscountNone")).'</td>';
 	print '</tr>';
 
 	// Absolute discounts (Discounts-Drawbacks-Rebates)
@@ -353,14 +354,14 @@ if ($socid > 0)
 	print '<td><td align="right">';
 	if ($user->rights->societe->creer && !$user->societe_id > 0)
 	{
-		print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$objsoc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$objsoc->id).'">'.img_edit($langs->trans("Modify")).'</a>';
+		print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.img_edit($langs->trans("Modify")).'</a>';
 	}
 	print '</td></tr></table>';
 	print '</td>';
 	print '<td colspan="3">';
-	$amount_discount=$objsoc->getAvailableDiscounts();
-	if ($amount_discount < 0) dol_print_error($db,$societe->error);
-	if ($amount_discount > 0) print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$objsoc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$objsoc->id).'">'.price($amount_discount).'</a>&nbsp;'.$langs->trans("Currency".$conf->monnaie);
+	$amount_discount=$object->getAvailableDiscounts();
+	if ($amount_discount < 0) dol_print_error($db,$object->error);
+	if ($amount_discount > 0) print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.price($amount_discount).'</a>&nbsp;'.$langs->trans("Currency".$conf->monnaie);
 	else print $langs->trans("DiscountNone");
 	print '</td>';
 	print '</tr>';
@@ -374,10 +375,10 @@ if ($socid > 0)
 		print '<td><td align="right">';
 		if ($user->rights->societe->creer)
 		{
-			print '<a href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$objsoc->id.'">'.img_edit($langs->trans("Modify")).'</a>';
+			print '<a href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
 		}
 		print '</td></tr></table>';
-		print '</td><td colspan="3">'.$objsoc->price_level."</td>";
+		print '</td><td colspan="3">'.$object->price_level."</td>";
 		print '</tr>';
 	}
 
@@ -391,14 +392,15 @@ if ($socid > 0)
 		print '<td><td align="right">';
 		if ($user->rights->societe->creer)
 		{
-			print '<a href="'.DOL_URL_ROOT.'/comm/address.php?socid='.$objsoc->id.'">'.img_edit($langs->trans("Modify")).'</a>';
+			print '<a href="'.DOL_URL_ROOT.'/comm/address.php?socid='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
 		}
 		print '</td></tr></table>';
 		print '</td><td colspan="3">';
-
+		
+		// TODO move to DAO class
 		$sql = "SELECT count(rowid) as nb";
 		$sql.= " FROM ".MAIN_DB_PREFIX."societe_address";
-		$sql.= " WHERE fk_soc =".$objsoc->id;
+		$sql.= " WHERE fk_soc =".$object->id;
 
 		$resql = $db->query($sql);
 		if ($resql)
@@ -424,7 +426,7 @@ if ($socid > 0)
         print '<tr><td width="25%" valign="top">'.$langs->trans("LinkedToDolibarrMember").'</td>';
         print '<td colspan="3">';
         $adh=new Adherent($db);
-        $result=$adh->fetch('','',$objsoc->id);
+        $result=$adh->fetch('','',$object->id);
         if ($result > 0)
         {
             $adh->ref=$adh->getFullName($langs);
@@ -453,7 +455,7 @@ if ($socid > 0)
 	print '<table class="noborder" width="100%">';
 	print '<tr class="liste_titre">';
 	print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("Summary").'</td>';
-	print '<td align="right"><a href="'.DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$objsoc->id.'">'.$langs->trans("ShowCustomerPreview").'</a></td></tr></table></td>';
+	print '<td align="right"><a href="'.DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id.'">'.$langs->trans("ShowCustomerPreview").'</a></td></tr></table></td>';
 	print '</tr>';
 	print '</table>';
 	print '<br>';
@@ -467,7 +469,7 @@ if ($socid > 0)
 	{
 		$propal_static = new Propal($db);
 
-		$proposals = $propal_static->liste_array(0, 0, 0, $objsoc->id, $MAXLIST);
+		$proposals = $propal_static->liste_array(0, 0, 0, $object->id, $MAXLIST);
 
 		//var_dump($proposals);
 
@@ -475,7 +477,7 @@ if ($socid > 0)
 		$sql.= " p.datep as dp, p.fin_validite as datelimite";
 		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
 		$sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
-		$sql.= " AND s.rowid = ".$objsoc->id;
+		$sql.= " AND s.rowid = ".$object->id;
 		$sql.= " ORDER BY p.datep DESC";
 
 		$resql=$db->query($sql);
@@ -489,8 +491,8 @@ if ($socid > 0)
 		        print '<table class="noborder" width="100%">';
 
                 print '<tr class="liste_titre">';
-    			print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastPropals",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/comm/propal.php?socid='.$objsoc->id.'">'.$langs->trans("AllPropals").' ('.$num.')</a></td>';
-                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$objsoc->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
+    			print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastPropals",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/comm/propal.php?socid='.$object->id.'">'.$langs->trans("AllPropals").' ('.$num.')</a></td>';
+                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
     			print '</tr></table></td>';
     			print '</tr>';
             }
@@ -500,7 +502,7 @@ if ($socid > 0)
 			{
 				$objp = $db->fetch_object($resql);
 				print "<tr $bc[$var]>";
-				print "<td nowrap><a href=\"propal.php?id=$objp->propalid\">".img_object($langs->trans("ShowPropal"),"propal")." ".$objp->ref."</a>\n";
+				print '<td nowrap><a href="propal.php?id=$objp->propalid">'.img_object($langs->trans("ShowPropal"),"propal").' '.$objp->ref.'</a>'."\n";
 				if ( ($db->jdate($objp->dp) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == 1 )
 				{
 					print " ".img_warning();
@@ -533,7 +535,7 @@ if ($socid > 0)
 		$sql.= " c.date_commande as dc";
 		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
 		$sql.= " WHERE c.fk_soc = s.rowid ";
-		$sql.= " AND s.rowid = ".$objsoc->id;
+		$sql.= " AND s.rowid = ".$object->id;
 		$sql.= " ORDER BY c.date_commande DESC";
 
 		$resql=$db->query($sql);
@@ -547,8 +549,8 @@ if ($socid > 0)
         		print '<table class="noborder" width="100%">';
 
 			    print '<tr class="liste_titre">';
-    			print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastOrders",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/commande/liste.php?socid='.$objsoc->id.'">'.$langs->trans("AllOrders").' ('.$num.')</a></td>';
-                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$objsoc->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
+    			print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastOrders",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/commande/liste.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' ('.$num.')</a></td>';
+                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
     			print '</tr></table></td>';
     			print '</tr>';
 			}
@@ -585,7 +587,7 @@ if ($socid > 0)
 		$sql = "SELECT s.nom, s.rowid, c.rowid as id, c.ref as ref, c.statut, c.datec as dc";
 		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
 		$sql .= " WHERE c.fk_soc = s.rowid ";
-		$sql .= " AND s.rowid = ".$objsoc->id;
+		$sql .= " AND s.rowid = ".$object->id;
 		$sql .= " ORDER BY c.datec DESC";
 
 		$resql=$db->query($sql);
@@ -599,7 +601,7 @@ if ($socid > 0)
 
 			    print '<tr class="liste_titre">';
 				print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts",($num<=$MAXLIST?"":$MAXLIST)).'</td>';
-				print '<td align="right"><a href="'.DOL_URL_ROOT.'/contrat/liste.php?socid='.$objsoc->id.'">'.$langs->trans("AllContracts").' ('.$num.')</a></td></tr></table></td>';
+				print '<td align="right"><a href="'.DOL_URL_ROOT.'/contrat/liste.php?socid='.$object->id.'">'.$langs->trans("AllContracts").' ('.$num.')</a></td></tr></table></td>';
 				print '</tr>';
 			}
 			$i = 0;
@@ -642,7 +644,7 @@ if ($socid > 0)
 		$sql = "SELECT s.nom, s.rowid, f.rowid as id, f.ref, f.duree as duration, f.datei as startdate";
 		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
 		$sql .= " WHERE f.fk_soc = s.rowid";
-		$sql .= " AND s.rowid = ".$objsoc->id;
+		$sql .= " AND s.rowid = ".$object->id;
 		$sql .= " ORDER BY f.tms DESC";
 
 		$fichinter_static=new Fichinter($db);
@@ -657,7 +659,7 @@ if ($socid > 0)
 		        print '<table class="noborder" width="100%">';
 
 			    print '<tr class="liste_titre">';
-				print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastInterventions",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/fichinter/list.php?socid='.$objsoc->id.'">'.$langs->trans("AllInterventions").' ('.$num.')</td></tr></table></td>';
+				print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastInterventions",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/fichinter/list.php?socid='.$object->id.'">'.$langs->trans("AllInterventions").' ('.$num.')</td></tr></table></td>';
 				print '</tr>';
 				$var=!$var;
 			}
@@ -699,7 +701,7 @@ if ($socid > 0)
 		$sql.= ' SUM(pf.amount) as am';
 		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
 		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
-		$sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$objsoc->id;
+		$sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
 		$sql.= ' GROUP BY f.rowid, f.facnumber, f.type, f.amount, f.total, f.total_ttc,';
 		$sql.= ' f.datef, f.datec, f.paye, f.fk_statut,';
 		$sql.= ' s.nom, s.rowid';
@@ -717,8 +719,8 @@ if ($socid > 0)
 
 			    $tableaushown=1;
 				print '<tr class="liste_titre">';
-				print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomersBills",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/compta/facture.php?socid='.$objsoc->id.'">'.$langs->trans("AllBills").' ('.$num.')</a></td>';
-                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$objsoc->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
+				print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomersBills",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/compta/facture.php?socid='.$object->id.'">'.$langs->trans("AllBills").' ('.$num.')</a></td>';
+                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
 				print '</tr></table></td>';
 				print '</tr>';
 			}
@@ -772,25 +774,25 @@ if ($socid > 0)
 	if ($conf->propal->enabled && $user->rights->propale->creer)
 	{
 		$langs->load("propal");
-		print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/addpropal.php?socid='.$objsoc->id.'&amp;action=create">'.$langs->trans("AddProp").'</a>';
+		print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/addpropal.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddProp").'</a>';
 	}
 
 	if ($conf->commande->enabled && $user->rights->commande->creer)
 	{
 		$langs->load("orders");
-		print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/fiche.php?socid='.$objsoc->id.'&amp;action=create">'.$langs->trans("AddOrder").'</a>';
+		print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/fiche.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddOrder").'</a>';
 	}
 
 	if ($user->rights->contrat->creer)
 	{
 		$langs->load("contracts");
-		print '<a class="butAction" href="'.DOL_URL_ROOT.'/contrat/fiche.php?socid='.$objsoc->id.'&amp;action=create">'.$langs->trans("AddContract").'</a>';
+		print '<a class="butAction" href="'.DOL_URL_ROOT.'/contrat/fiche.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddContract").'</a>';
 	}
 
 	if ($conf->ficheinter->enabled && $user->rights->ficheinter->creer)
 	{
 		$langs->load("fichinter");
-		print '<a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/fiche.php?socid='.$objsoc->id.'&amp;action=create">'.$langs->trans("AddIntervention").'</a>';
+		print '<a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/fiche.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddIntervention").'</a>';
 	}
 
 	// Add invoice
@@ -799,7 +801,7 @@ if ($socid > 0)
 		if ($conf->deplacement->enabled)
 		{
 			$langs->load("trips");
-			print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/deplacement/fiche.php?socid='.$objsoc->id.'&amp;action=create">'.$langs->trans("AddTrip").'</a>';
+			print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/deplacement/fiche.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddTrip").'</a>';
 		}
 
 		if ($conf->facture->enabled)
@@ -807,7 +809,7 @@ if ($socid > 0)
 			if ($user->rights->facture->creer)
 			{
 				$langs->load("bills");
-				if ($objsoc->client != 0) print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&socid='.$objsoc->id.'">'.$langs->trans("AddBill").'</a>';
+				if ($object->client != 0) print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a>';
 				else print '<a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a>';
 			}
 			else
@@ -822,7 +824,7 @@ if ($socid > 0)
 	{
 		if ($user->rights->agenda->myactions->create)
 		{
-			print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&socid='.$objsoc->id.'">'.$langs->trans("AddAction").'</a>';
+			print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a>';
 		}
 		else
 		{
@@ -832,7 +834,7 @@ if ($socid > 0)
 
 	/*if ($user->rights->societe->contact->creer)
 	{
-		print '<a class="butAction" href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$objsoc->id.'&amp;action=create">'.$langs->trans("AddContact").'</a>';
+		print '<a class="butAction" href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddContact").'</a>';
 	}*/
 
 	print '</div>';
@@ -842,16 +844,16 @@ if ($socid > 0)
 	{
 	    print '<br>';
 		// List of contacts
-		show_contacts($conf,$langs,$db,$objsoc,$_SERVER["PHP_SELF"].'?socid='.$objsoc->id);
+		show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
 	}
 
     if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
     {
 		// List of todo actions
-		show_actions_todo($conf,$langs,$db,$objsoc);
+		show_actions_todo($conf,$langs,$db,$object);
 
         // List of done actions
-		show_actions_done($conf,$langs,$db,$objsoc);
+		show_actions_done($conf,$langs,$db,$object);
 	}
 }
 else
diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php
index b1f625a3475..870e5833782 100644
--- a/htdocs/comm/mailing/fiche.php
+++ b/htdocs/comm/mailing/fiche.php
@@ -722,18 +722,18 @@ else
 			print '</td></tr>';
 
 			// Description
-			print '<tr><td>'.$form->editfieldkey("MailTitle",'desc',$mil->titre,'id',$mil->id,$user->rights->mailing->creer).'</td><td colspan="3">';
-			print $form->editfieldval("MailTitle",'desc',$mil->titre,'id',$mil->id,$user->rights->mailing->creer);
+			print '<tr><td>'.$form->editfieldkey("MailTitle",'desc',$mil->titre,$mil,$user->rights->mailing->creer).'</td><td colspan="3">';
+			print $form->editfieldval("MailTitle",'desc',$mil->titre,$mil,$user->rights->mailing->creer);
 			print '</td></tr>';
 
 			// From
-			print '<tr><td>'.$form->editfieldkey("MailFrom",'from',$mil->email_from,'id',$mil->id,$user->rights->mailing->creer && $mil->statut < 3,'email').'</td><td colspan="3">';
-			print $form->editfieldval("MailFrom",'from',$mil->email_from,'id',$mil->id,$user->rights->mailing->creer && $mil->statut < 3,'email');
+			print '<tr><td>'.$form->editfieldkey("MailFrom",'from',$mil->email_from,$mil,$user->rights->mailing->creer && $mil->statut < 3,'email').'</td><td colspan="3">';
+			print $form->editfieldval("MailFrom",'from',$mil->email_from,$mil,$user->rights->mailing->creer && $mil->statut < 3,'email');
 			print '</td></tr>';
 
 			// Errors to
-			print '<tr><td>'.$form->editfieldkey("MailErrorsTo",'errorsto',$mil->email_errorsto,'id',$mil->id,$user->rights->mailing->creer && $mil->statut < 3,'email').'</td><td colspan="3">';
-			print $form->editfieldval("MailErrorsTo",'errorsto',$mil->email_errorsto,'id',$mil->id,$user->rights->mailing->creer && $mil->statut < 3,'email');
+			print '<tr><td>'.$form->editfieldkey("MailErrorsTo",'errorsto',$mil->email_errorsto,$mil,$user->rights->mailing->creer && $mil->statut < 3,'email').'</td><td colspan="3">';
+			print $form->editfieldval("MailErrorsTo",'errorsto',$mil->email_errorsto,$mil,$user->rights->mailing->creer && $mil->statut < 3,'email');
 			print '</td></tr>';
 
 			// Status
diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php
index 7e4cccbc8e9..14c965373ed 100644
--- a/htdocs/compta/deplacement/fiche.php
+++ b/htdocs/compta/deplacement/fiche.php
@@ -381,9 +381,9 @@ else if ($id)
 
 			// Type
 			print '<tr><td>';
-            print $form->editfieldkey("Type",'type',$langs->trans($object->type),'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
+            print $form->editfieldkey("Type",'type',$langs->trans($object->type),$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
 			print '</td><td>';
-            print $form->editfieldval("Type",'type',$langs->trans($object->type),'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
+            print $form->editfieldval("Type",'type',$langs->trans($object->type),$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'select:types_fees');
 			print '</td></tr>';
 
 			// Who
@@ -395,16 +395,16 @@ else if ($id)
 
 			// Date
 			print '<tr><td>';
-			print $form->editfieldkey("Date",'dated',$object->date,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
+			print $form->editfieldkey("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
 			print '</td><td>';
-			print $form->editfieldval("Date",'dated',$object->date,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
+			print $form->editfieldval("Date",'dated',$object->date,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'datepicker');
 			print '</td></tr>';
 
 			// Km/Price
 			print '<tr><td valign="top">';
-			print $form->editfieldkey("FeesKilometersOrAmout",'km',$object->km,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
+			print $form->editfieldkey("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
 			print '</td><td>';
-			print $form->editfieldval("FeesKilometersOrAmout",'km',$object->km,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
+			print $form->editfieldval("FeesKilometersOrAmout",'km',$object->km,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'numeric:6');
 			print "</td></tr>";
 
 			// Where
@@ -448,18 +448,18 @@ else if ($id)
 
 			// Public note
 			print '<tr><td valign="top">';
-			print $form->editfieldkey("NotePublic",'note_public',$object->note_public,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
+			print $form->editfieldkey("NotePublic",'note_public',$object->note_public,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
 			print '</td><td>';
-			print $form->editfieldval("NotePublic",'note_public',$object->note_public,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
+			print $form->editfieldval("NotePublic",'note_public',$object->note_public,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
 			print "</td></tr>";
 
 			// Private note
 			if (! $user->societe_id)
 			{
     			print '<tr><td valign="top">';
-    			print $form->editfieldkey("NotePrivate",'note',$object->note_private,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
+    			print $form->editfieldkey("NotePrivate",'note',$object->note_private,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
     			print '</td><td>';
-    			print $form->editfieldval("NotePrivate",'note',$object->note_private,'id',$object->id,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
+    			print $form->editfieldval("NotePrivate",'note',$object->note_private,$object,$conf->global->MAIN_EDIT_ALSO_INLINE && $user->rights->deplacement->creer,'ckeditor:dolibarr_notes:600:180');
     			print "</td></tr>";
 			}
 
diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php
index ff20b8166ac..7e6e9fe06ce 100644
--- a/htdocs/compta/paiement/fiche.php
+++ b/htdocs/compta/paiement/fiche.php
@@ -219,8 +219,8 @@ print '<table class="border" width="100%">';
 print '<tr><td valign="top" width="20%">'.$langs->trans('Ref').'</td><td colspan="3">'.$paiement->id.'</td></tr>';
 
 // Date payment
-print '<tr><td valign="top">'.$form->editfieldkey("Date",'date',$paiement->date,'id',$paiement->id,$user->rights->facture->paiement).'</td><td colspan="3">';
-print $form->editfieldval("Date",'date',$paiement->date,'id',$paiement->id,$user->rights->facture->paiement,'day');
+print '<tr><td valign="top">'.$form->editfieldkey("Date",'date',$paiement->date,$paiement,$user->rights->facture->paiement).'</td><td colspan="3">';
+print $form->editfieldval("Date",'date',$paiement->date,$paiement,$user->rights->facture->paiement,'day');
 print '</td></tr>';
 
 // Payment type (VIR, LIQ, ...)
@@ -228,16 +228,16 @@ $labeltype=$langs->trans("PaymentType".$paiement->type_code)!=("PaymentType".$pa
 print '<tr><td valign="top">'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$labeltype.'</td></tr>';
 
 // Payment numero
-print '<tr><td valign="top">'.$form->editfieldkey("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
-print $form->editfieldval("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'string');
+print '<tr><td valign="top">'.$form->editfieldkey("Numero",'num',$paiement->numero,$paiement,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
+print $form->editfieldval("Numero",'num',$paiement->numero,$paiement,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'string');
 print '</td></tr>';
 
 // Amount
 print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->montant).'&nbsp;'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
 
 // Note
-print '<tr><td valign="top">'.$form->editfieldkey("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->facture->paiement).'</td><td colspan="3">';
-print $form->editfieldval("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->facture->paiement,'text');
+print '<tr><td valign="top">'.$form->editfieldkey("Note",'note',$paiement->note,$paiement,$user->rights->facture->paiement).'</td><td colspan="3">';
+print $form->editfieldval("Note",'note',$paiement->note,$paiement,$user->rights->facture->paiement,'text');
 print '</td></tr>';
 
 // Bank account
diff --git a/htdocs/core/ajax/loadinplace.php b/htdocs/core/ajax/loadinplace.php
index e4ea090d0cf..166d6d3507d 100644
--- a/htdocs/core/ajax/loadinplace.php
+++ b/htdocs/core/ajax/loadinplace.php
@@ -66,8 +66,18 @@ if((isset($_GET['field']) && ! empty($_GET['field']))
 			$cachename = 'cache_'.GETPOST('method');
 			
 			$form = new Form($db);
-			$ret = $form->$methodname();
-			if ($ret > 0) echo json_encode($form->$cachename);
+			if (method_exists($form, $methodname))
+			{
+				$ret = $form->$methodname();
+				if ($ret > 0) echo json_encode($form->$cachename);
+			}
+			else
+			{
+				dol_include_once('/'.$element.'/class/'.$element.'.class.php');
+				$classname = ucfirst($element);
+				$object = new $classname($db);
+				print_r($object);
+			}
 		}
 		else
 		{
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 3d75a31e99f..ae7ec078472 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -68,16 +68,15 @@ class Form
     /**
      * Output key field for an editable field
      *
-     * @param   string	$text           Text of label or key to translate
-     * @param   string	$htmlname       Name of select field
-     * @param   string	$preselected    Value to show/edit
-     * @param   string	$paramkey       Key of parameter for Url (unique if there is several parameter to show). In most cases "id".
-     * @param   string	$paramvalue     Value of parameter for Url
-     * @param	boolean	$perm           Permission to allow button to edit parameter
+     * @param   string	$text			Text of label or key to translate
+     * @param   string	$htmlname		Name of select field
+     * @param   string	$preselected	Name of Value to show/edit (not used in this function)
+     * @param	object	$object			Object
+     * @param	boolean	$perm			Permission to allow button to edit parameter
      * @param	string	$typeofdata		Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height', 'select:xxx'...)
-     * @return	string    			    HTML edit field
+     * @return	string					HTML edit field
      */
-    function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string')
+    function editfieldkey($text,$htmlname,$preselected,$object,$perm,$typeofdata='string')
     {
     	global $conf,$langs;
     	
@@ -102,7 +101,7 @@ class Form
     		$ret.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
     		$ret.=$langs->trans($text);
     		$ret.='</td>';
-    		if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;'.$paramkey.'='.$paramvalue.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
+    		if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;id='.$object->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
     		$ret.='</tr></table>';
         }
         
@@ -115,13 +114,13 @@ class Form
      * @param	string	$text			Text of label (not used in this function)
      * @param	string	$htmlname		Name of select field
      * @param	string	$value			Value to show/edit
-     * @param	string	$paramkey		Key of parameter (unique if there is several parameter to show). In most cases "id".
+     * @param	object	$object			Object
      * @param	boolean	$perm			Permission to allow button to edit parameter
      * @param	string	$typeofdata		Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height', 'select:xxx'...)
      * @param	string	$editvalue		When in edit mode, use this value as $value instead of value
-     * @return  string   		      	HTML edit field
+     * @return  string					HTML edit field
      */
-    function editfieldval($text,$htmlname,$value,$paramkey,$paramvalue,$perm,$typeofdata='string',$editvalue='')
+    function editfieldval($text,$htmlname,$value,$object,$perm,$typeofdata='string',$editvalue='')
     {
         global $conf,$langs,$db;
         $ret='';
@@ -129,7 +128,7 @@ class Form
         // When option to edit inline is activated
         if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE))
         {
-            $ret.=$this->editInPlace($value, $htmlname, $perm, $typeofdata);
+            $ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata);
         }
         else
         {
@@ -139,7 +138,7 @@ class Form
                 $ret.='<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
                 $ret.='<input type="hidden" name="action" value="set'.$htmlname.'">';
                 $ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-                $ret.='<input type="hidden" name="'.$paramkey.'" value="'.$paramvalue.'">';
+                $ret.='<input type="hidden" name="id" value="'.$object->id.'">';
                 $ret.='<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
                 $ret.='<tr><td>';
                 if (preg_match('/^(string|email|numeric)/',$typeofdata))
@@ -153,7 +152,7 @@ class Form
                 }
                 else if ($typeofdata == 'day' || $typeofdata == 'datepicker')
                 {
-                    $ret.=$this->form_date($_SERVER['PHP_SELF'].($paramkey?'?'.$paramkey.'='.$paramvalue:''),$value,$htmlname);
+                    $ret.=$this->form_date($_SERVER['PHP_SELF'].($objectkey?'?id='.$object->id:''),$value,$htmlname);
                 }
                 else if (preg_match('/^ckeditor/',$typeofdata))
                 {
@@ -189,13 +188,14 @@ class Form
     /**
      * Output edit in place form
      *
+     * @param	object	$object			Object
      * @param	string	$value			Value to show/edit
      * @param	string	$htmlname		DIV ID (field name)
      * @param	int		$condition		Condition to edit
      * @param	string	$inputType		Type of input ('numeric', 'datepicker', 'textarea', 'ckeditor:dolibarr_zzz', 'select:xxx')
      * @return	string   		      	HTML edit in place
      */
-    private function editInPlace($value, $htmlname, $condition, $inputType='textarea')
+    private function editInPlace($object, $value, $htmlname, $condition, $inputType='textarea')
     {
     	global $conf;
 
@@ -206,7 +206,7 @@ class Form
     	else if (preg_match('/^numeric/',$inputType)) $value = price($value);
     	else if ($inputType == 'datepicker') $value = dol_print_date($value, 'day');
 
-    	if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && $condition)
+    	if ($condition)
     	{
     		if (preg_match('/^(string|email|numeric)/',$inputType))
     		{
@@ -215,13 +215,13 @@ class Form
     		}
     	    if ($inputType == 'datepicker')
     		{
-    			$out.= '<input id="timeStamp" type="hidden"/>'; // Use for timestamp format
+    			$out.= '<input id="timestamp_'.$htmlname.'" type="hidden"/>'."\n"; // Use for timestamp format
     		}
     		else if (preg_match('/^select/',$inputType))
     		{
     		    $tmp=explode(':',$inputType);
     		    $inputType=$tmp[0]; $inputOption=$tmp[1];
-    			$out.= '<input id="loadmethod" value="'.$inputOption.'" type="hidden"/>';
+    			$out.= '<input id="loadmethod_'.$htmlname.'" value="'.$inputOption.'" type="hidden"/>'."\n";
     		}
     		else if (preg_match('/^ckeditor/',$inputType))
     		{
@@ -229,17 +229,19 @@ class Form
     		    $inputType=$tmp[0]; $inputOption=$tmp[1];
     			if (! empty($conf->fckeditor->enabled))
     			{
-    				$out.= '<input id="toolbar" value="'.$inputOption.'" type="hidden"/>';
+    				$out.= '<input id="ckeditor_toolbar" value="'.$inputOption.'" type="hidden"/>'."\n";
     			}
     			else
     			{
     				$inputType = 'textarea';
     			}
     		}
-
-    		$out.= '<div class="editval_'.$inputType.'" id="val_'.$htmlname.'">';
-    		$out.= $value;
-    		$out.= '</div>'."\n";
+    		
+    		$out.= '<input id="element_'.$htmlname.'" value="'.$object->element.'" type="hidden">'."\n";
+    		$out.= '<input id="table_element_'.$htmlname.'" value="'.$object->table_element.'" type="hidden">'."\n";
+    		$out.= '<input id="fk_element_'.$htmlname.'" value="'.$object->id.'" type="hidden">'."\n";
+    		
+    		$out.= '<div id="val_'.$htmlname.'" class="editval_'.$inputType.'">'.$value.'</div>'."\n";
     	}
     	else
     	{
diff --git a/htdocs/core/js/editinplace.js b/htdocs/core/js/editinplace.js
index 8b09731cca5..acec45354b2 100644
--- a/htdocs/core/js/editinplace.js
+++ b/htdocs/core/js/editinplace.js
@@ -16,22 +16,18 @@ $(document).ready(function() {
 		rows		: 4,
 		id			: 'field',
 		tooltip		: tooltipInPlace,
-		placeholder	: placeholderInPlace,
+		placeholder	: '&nbsp;',
 		cancel		: cancelInPlace,
 		submit		: submitInPlace,
 		indicator	: indicatorInPlace,
 		loadurl		: urlLoadInPlace,
-		loaddata	: {
-			type: 'textarea',
-			element: element,
-			table_element: table_element,
-			fk_element: fk_element
+		loaddata	: function(result, settings) {
+			var htmlname = $(this).attr('id').substr(4);
+			return getParameters('textarea', htmlname);
 		},
-		submitdata	: {
-			type: 'textarea',
-			element: element,
-			table_element: table_element,
-			fk_element: fk_element
+		submitdata	: function(result, settings) {
+			var htmlname = $(this).attr('id').substr(4);
+			return getParameters('textarea', htmlname);
 		},
 		callback : function(result, settings) {
 			var obj = $.parseJSON(result);
@@ -61,19 +57,17 @@ $(document).ready(function() {
 		id			: 'field',
 		onblur		: 'ignore',
 		tooltip		: tooltipInPlace,
-		placeholder	: placeholderInPlace,
+		placeholder	: '&nbsp;',
 		cancel		: cancelInPlace,
 		submit		: submitInPlace,
 		indicator	: indicatorInPlace,
 		ckeditor	: {
 			customConfig: ckeditorConfig,
-			toolbar: $('#toolbar').val()
+			toolbar: $('#ckeditor_toolbar').val()
 		},
-		submitdata	: {
-			type: 'ckeditor',
-			element: element,
-			table_element: table_element,
-			fk_element: fk_element
+		submitdata	: function(result, settings) {
+			var htmlname = $(this).attr('id').substr(4);
+			return getParameters('ckeditor', htmlname);
 		},
 		callback : function(result, settings) {
 			var obj = $.parseJSON(result);
@@ -107,11 +101,9 @@ $(document).ready(function() {
 		cancel		: cancelInPlace,
 		submit		: submitInPlace,
 		indicator	: indicatorInPlace,
-		submitdata	: {
-			type: 'text',
-			element: element,
-			table_element: table_element,
-			fk_element: fk_element
+		submitdata	: function(result, settings) {
+			var htmlname = $(this).attr('id').substr(4);
+			return getParameters('text', htmlname);
 		},
 		callback : function(result, settings) {
 			var obj = $.parseJSON(result);
@@ -145,11 +137,9 @@ $(document).ready(function() {
 		cancel		: cancelInPlace,
 		submit		: submitInPlace,
 		indicator	: indicatorInPlace,
-		submitdata	: {
-			type: 'numeric',
-			element: element,
-			table_element: table_element,
-			fk_element: fk_element
+		submitdata	: function(result, settings) {
+			var htmlname = $(this).attr('id').substr(4);
+			return getParameters('numeric', htmlname);
 		},
 		callback : function(result, settings) {
 			var obj = $.parseJSON(result);
@@ -183,14 +173,9 @@ $(document).ready(function() {
 		cancel		: cancelInPlace,
 		submit		: submitInPlace,
 		indicator	: indicatorInPlace,
-		submitdata	: function(value, settings) {
-			return {
-				type: 'datepicker',
-				element: element,
-				table_element: table_element,
-				fk_element: fk_element,
-				timestamp: $('#timeStamp').val()
-			};
+		submitdata	: function(result, settings) {
+			var htmlname = $(this).attr('id').substr(4);
+			return getParameters('datepicker', htmlname);
 		},
 		callback : function(result, settings) {
 			var obj = $.parseJSON(result);
@@ -226,19 +211,13 @@ $(document).ready(function() {
 		submit		: submitInPlace,
 		indicator	: indicatorInPlace,
 		loadurl		: urlLoadInPlace,
-		loaddata	: {
-			type: 'select',
-			method: $('#loadmethod').val(),
-			element: element,
-			table_element: table_element,
-			fk_element: fk_element
+		loaddata	: function(result, settings) {
+			var htmlname = $(this).attr('id').substr(4);
+			return getParameters('select', htmlname);
 		},
-		submitdata	: {
-			type: 'select',
-			method: $('#loadmethod').val(),
-			element: element,
-			table_element: table_element,
-			fk_element: fk_element
+		submitdata	: function(result, settings) {
+			var htmlname = $(this).attr('id').substr(4);
+			return getParameters('select', htmlname);
 		},
 		callback : function(result, settings) {
 			var obj = $.parseJSON(result);
@@ -263,6 +242,29 @@ $(document).ready(function() {
 		$( '#val_' + $(this).attr('id') ).click();
 	});
 	
+	function getParameters(type, htmlname) {
+		var element = $( '#element_' + htmlname ).val();
+		var table_element = $( '#table_element_' + htmlname ).val();
+		var fk_element = $( '#fk_element_' + htmlname ).val();
+		var method = false;
+		var timestamp = false;
+		
+		if (type == 'select') {
+			var method = $( '#loadmethod_' + htmlname ).val();
+		} else if (type == 'datepicker') {
+			var timestamp = $('#timestamp_' + htmlname ).val();
+		}
+		
+		return {
+			type: type,
+			element: element,
+			table_element: table_element,
+			fk_element: fk_element,
+			method: method,
+			timestamp: timestamp
+		};
+	}
+	
 	$('.edit_autocomplete').editable(urlSaveInPlace, {
 		type		: 'autocomplete',
 		id			: 'field',
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 3e7fcea0c35..8bde8ea1446 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -689,14 +689,6 @@ function dol_get_fiche_head($links=array(), $active='0', $title='', $notab=0, $p
 
     if (! $notab) $out.="\n".'<div class="tabBar">'."\n";
 
-    // Parameters for edit in place
-    if (! empty($GLOBALS['object']))
-    {
-    	$out.='<div id="jeditable_element" class="hidden">'.$GLOBALS['object']->element.'</div>'."\n";
-    	$out.='<div id="jeditable_table_element" class="hidden">'.$GLOBALS['object']->table_element.'</div>'."\n";
-    	$out.='<div id="jeditable_fk_element" class="hidden">'.$GLOBALS['object']->id.'</div>'."\n";
-    }
-
     return $out;
 }
 
diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php
index 3db618616fc..8e352cd41d0 100644
--- a/htdocs/expedition/fiche.php
+++ b/htdocs/expedition/fiche.php
@@ -1016,8 +1016,8 @@ else
 			}
 
 			// Weight
-			print '<tr><td>'.$form->editfieldkey("Weight",'trueWeight',$object->trueWeight,'id',$object->id,$user->rights->expedition->creer).'</td><td colspan="3">';
-			print $form->editfieldval("Weight",'trueWeight',$object->trueWeight,'id',$object->id,$user->rights->expedition->creer);
+			print '<tr><td>'.$form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
+			print $form->editfieldval("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer);
 			print $object->weight_units?measuring_units_string($object->weight_units,"weight"):'';
 			print '</td></tr>';
 
@@ -1044,20 +1044,20 @@ else
 			print '</tr>';
 
 			// Width
-			print '<tr><td>'.$form->editfieldkey("Width",'trueWidth',$object->trueWidth,'id',$object->id,$user->rights->expedition->creer).'</td><td colspan="3">';
-			print $form->editfieldval("Width",'trueWidth',$object->trueWidth,'id',$object->id,$user->rights->expedition->creer);
+			print '<tr><td>'.$form->editfieldkey("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
+			print $form->editfieldval("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer);
 			print $object->trueWidth?measuring_units_string($object->width_units,"size"):'';
 			print '</td></tr>';
 
 			// Height
-			print '<tr><td>'.$form->editfieldkey("Height",'trueHeight',$object->trueHeight,'id',$object->id,$user->rights->expedition->creer).'</td><td colspan="3">';
-			print $form->editfieldval("Height",'trueHeight',$object->trueHeight,'id',$object->id,$user->rights->expedition->creer);
+			print '<tr><td>'.$form->editfieldkey("Height",'trueHeight',$object->trueHeight,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
+			print $form->editfieldval("Height",'trueHeight',$object->trueHeight,$object,$user->rights->expedition->creer);
 			print $object->trueHeight?measuring_units_string($object->height_units,"size"):'';
 			print '</td></tr>';
 
 			// Depth
-			print '<tr><td>'.$form->editfieldkey("Depth",'trueDepth',$object->trueDepth,'id',$object->id,$user->rights->expedition->creer).'</td><td colspan="3">';
-			print $form->editfieldval("Depth",'trueDepth',$object->trueDepth,'id',$object->id,$user->rights->expedition->creer);
+			print '<tr><td>'.$form->editfieldkey("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
+			print $form->editfieldval("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer);
 			print $object->trueDepth?measuring_units_string($object->depth_units,"size"):'';
 			print '</td></tr>';
 
@@ -1098,8 +1098,8 @@ else
 			print '</tr>';
 
 			// Tracking Number
-			print '<tr><td>'.$form->editfieldkey("TrackingNumber",'trackingnumber',$object->tracking_number,'id',$object->id,$user->rights->expedition->creer).'</td><td colspan="3">';
-			print $form->editfieldval("TrackingNumber",'trackingnumber',$object->tracking_url,'id',$object->id,$user->rights->expedition->creer,'string',$object->tracking_number);
+			print '<tr><td>'.$form->editfieldkey("TrackingNumber",'trackingnumber',$object->tracking_number,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
+			print $form->editfieldval("TrackingNumber",'trackingnumber',$object->tracking_url,$object,$user->rights->expedition->creer,'string',$object->tracking_number);
 			print '</td></tr>';
 
 			print "</table>\n";
diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php
index 7f65a2e840d..aa0b3abc031 100644
--- a/htdocs/fichinter/fiche.php
+++ b/htdocs/fichinter/fiche.php
@@ -816,9 +816,9 @@ else if ($id > 0 || ! empty($ref))
 
     // Description (must be a textarea and not html must be allowed (used in list view)
     print '<tr><td valign="top">';
-    print $form->editfieldkey("Description",'description',$object->description,'id',$object->id,$user->rights->ficheinter->creer,'textarea');
+    print $form->editfieldkey("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea');
     print '</td><td colspan="3">';
-    print $form->editfieldval("Description",'description',$object->description,'id',$object->id,$user->rights->ficheinter->creer,'textarea');
+    print $form->editfieldval("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea');
     print '</td>';
     print '</tr>';
 
@@ -857,18 +857,18 @@ else if ($id > 0 || ! empty($ref))
 
     // Public note
     print '<tr><td valign="top">';
-    print $form->editfieldkey("NotePublic",'note_public',$object->note_public,'id',$object->id,$user->rights->ficheinter->creer,'ckeditor:dolibarr_notes:600:180');
+    print $form->editfieldkey("NotePublic",'note_public',$object->note_public,$object,$user->rights->ficheinter->creer,'ckeditor:dolibarr_notes:600:180');
     print '</td><td colspan="3">';
-    print $form->editfieldval("NotePublic",'note_public',$object->note_public,'id',$object->id,$user->rights->ficheinter->creer,'ckeditor:dolibarr_notes:600:180');
+    print $form->editfieldval("NotePublic",'note_public',$object->note_public,$object,$user->rights->ficheinter->creer,'ckeditor:dolibarr_notes:600:180');
     print "</td></tr>";
 
     // Private note
     if (! $user->societe_id)
     {
     	print '<tr><td valign="top">';
-        print $form->editfieldkey("NotePrivate",'note_private',$object->note_private,'id',$object->id,$user->rights->ficheinter->creer,'ckeditor:dolibarr_notes:600:180');
+        print $form->editfieldkey("NotePrivate",'note_private',$object->note_private,$object,$user->rights->ficheinter->creer,'ckeditor:dolibarr_notes:600:180');
         print '</td><td colspan="3">';
-        print $form->editfieldval("NotePrivate",'note_private',$object->note_private,'id',$object->id,$user->rights->ficheinter->creer,'ckeditor:dolibarr_notes:600:180');
+        print $form->editfieldval("NotePrivate",'note_private',$object->note_private,$object,$user->rights->ficheinter->creer,'ckeditor:dolibarr_notes:600:180');
     	print "</td></tr>";
     }
 
diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php
index 3297961786b..14e0cb18e21 100644
--- a/htdocs/fourn/facture/fiche.php
+++ b/htdocs/fourn/facture/fiche.php
@@ -42,12 +42,13 @@ $langs->load('suppliers');
 $langs->load('companies');
 
 $mesg='';
-$facid=GETPOST("facid");
-$action=GETPOST("action");
+$id			= (GETPOST("facid") ? GETPOST("facid") : GETPOST("id"));
+$action		= GETPOST("action");
+$confirm	= GETPOST("confirm");
 
 // Security check
 if ($user->societe_id) $socid=$user->societe_id;
-$result = restrictedArea($user, 'fournisseur', $facid, 'facture_fourn', 'facture');
+$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
 
 $object=new FactureFournisseur($db);
 
@@ -58,7 +59,7 @@ $object=new FactureFournisseur($db);
  */
 
 // Action clone object
-if ($action == 'confirm_clone' && $_REQUEST['confirm'] == 'yes')
+if ($action == 'confirm_clone' && $confirm == 'yes')
 {
     if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
     {
@@ -66,25 +67,24 @@ if ($action == 'confirm_clone' && $_REQUEST['confirm'] == 'yes')
     }
     else
     {
-        $result=$object->createFromClone($facid);
+        $result=$object->createFromClone($id);
         if ($result > 0)
         {
-            header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result);
+            header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
             exit;
         }
         else
         {
             $langs->load("errors");
             $mesg='<div class="error">'.$langs->trans($object->error).'</div>';
-            $_GET['action']='';
-            $_GET['id']=$_REQUEST['id'];
+            $action='';
         }
     }
 }
 
-if ($action == 'confirm_valid' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->facture->valider)
+if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fournisseur->facture->valider)
 {
-    $object->fetch($facid);
+    $object->fetch($id);
     $result = $object->validate($user);
     if ($result < 0)
     {
@@ -92,12 +92,12 @@ if ($action == 'confirm_valid' && $_REQUEST['confirm'] == 'yes' && $user->rights
     }
 }
 
-if ($action == 'confirm_delete' && $_REQUEST['confirm'] == 'yes')
+if ($action == 'confirm_delete' && $confirm == 'yes')
 {
     if ($user->rights->fournisseur->facture->supprimer )
     {
-        $object->fetch($facid);
-        $result=$object->delete($facid);
+        $object->fetch($id);
+        $result=$object->delete($id);
         if ($result > 0)
         {
             Header('Location: index.php');
@@ -110,43 +110,41 @@ if ($action == 'confirm_delete' && $_REQUEST['confirm'] == 'yes')
     }
 }
 
-if ($action == 'confirm_deleteproductline' && $_REQUEST['confirm'] == 'yes')
+if ($action == 'confirm_deleteproductline' && $confirm == 'yes')
 {
     if ($user->rights->fournisseur->facture->creer)
     {
-        $object->fetch($facid);
+        $object->fetch($id);
         $object->deleteline($_REQUEST['lineid']);
-        $_GET['action'] = '';
+        $action = '';
     }
 }
 
-if ($action == 'confirm_paid' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->facture->creer)
+if ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer)
 {
-    $object->fetch($facid);
+    $object->fetch($id);
     $result=$object->set_paid($user);
 }
 
 // Set supplier ref
 if (($action == 'setref_supplier' || $action == 'set_ref_supplier') && $user->rights->fournisseur->facture->creer)
 {
-    $object->fetch($facid);
+    $object->fetch($id);
     $result=$object->set_ref_supplier($user, $_POST['ref_supplier']);
-    $_GET['facid']=$facid;
 }
 
 // Set supplier ref
 if ($action == 'setlabel' && $user->rights->fournisseur->facture->creer)
 {
-    $object->fetch($facid);
+    $object->fetch($id);
     $object->label=$_POST['label'];
     $result=$object->update($user);
     if ($result < 0) dol_print_error($db);
-    $_GET['facid']=$facid;
 }
 
 if ($action == 'setdate' && $user->rights->fournisseur->facture->creer)
 {
-    $object->fetch($facid);
+    $object->fetch($id);
     $object->date=dol_mktime(12,0,0,$_POST['datemonth'],$_POST['dateday'],$_POST['dateyear']);
     if ($object->date_echeance < $object->date) $object->date_echeance=$object->date;
     $result=$object->update($user);
@@ -154,7 +152,7 @@ if ($action == 'setdate' && $user->rights->fournisseur->facture->creer)
 }
 if ($action == 'setdate_echeance' && $user->rights->fournisseur->facture->creer)
 {
-    $object->fetch($facid);
+    $object->fetch($id);
     $object->date_echeance=dol_mktime(12,0,0,$_POST['date_echeancemonth'],$_POST['date_echeanceday'],$_POST['date_echeanceyear']);
     if ($object->date_echeance < $object->date) $object->date_echeance=$object->date;
     $result=$object->update($user);
@@ -164,7 +162,7 @@ if ($action == 'setdate_echeance' && $user->rights->fournisseur->facture->creer)
 // Delete payment
 if($action == 'deletepaiement')
 {
-    $object->fetch($_GET['facid']);
+    $object->fetch($id);
     if ($object->statut == 1 && $object->paye == 0 && $user->societe_id == 0)
     {
         $paiementfourn = new PaiementFourn($db);
@@ -192,13 +190,14 @@ if ($action == 'update' && ! $_POST['cancel'])
 
     if (! $error)
     {
+    	// TODO move to DAO class
         $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn set ';
         $sql .= " facnumber='".$db->escape(trim($_POST['facnumber']))."'";
         $sql .= ", libelle='".$db->escape(trim($_POST['libelle']))."'";
         $sql .= ", note='".$db->escape($_POST['note'])."'";
         $sql .= ", datef = '".$db->idate($date)."'";
         $sql .= ", date_lim_reglement = '".$db->idate($date_echeance)."'";
-        $sql .= ' WHERE rowid = '.$_GET['facid'].' ;';
+        $sql .= ' WHERE rowid = '.$id;
         $result = $db->query($sql);
     }
 }
@@ -259,10 +258,10 @@ if ($action == 'add' && $user->rights->fournisseur->facture->creer)
             $object->origin 	= $_POST['origin'];
             $object->origin_id = $_POST['originid'];
 
-            $facid = $object->create($user);
+            $id = $object->create($user);
 
             // Add lines
-            if ($facid > 0)
+            if ($id > 0)
             {
                 require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php');
                 $classname = ucfirst($subelement);
@@ -327,8 +326,8 @@ if ($action == 'add' && $user->rights->fournisseur->facture->creer)
         // If some invoice's lines already known
         else
         {
-            $facid = $object->create($user);
-            if ($facid < 0)
+            $id = $object->create($user);
+            if ($id < 0)
             {
                 $error++;
             }
@@ -376,7 +375,7 @@ if ($action == 'add' && $user->rights->fournisseur->facture->creer)
         else
         {
             $db->commit();
-            header('Location: fiche.php?facid='.$facid);
+            header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
             exit;
         }
     }
@@ -384,7 +383,7 @@ if ($action == 'add' && $user->rights->fournisseur->facture->creer)
 
 if ($action == 'del_ligne')
 {
-    $object->fetch($_GET['facid']);
+    $object->fetch($id);
     $object->deleteline($_GET['lineid']);
     $action = 'edit';
 }
@@ -394,7 +393,7 @@ if ($action == 'update_line')
 {
     if ($_REQUEST['etat'] == '1' && ! $_REQUEST['cancel']) // si on valide la modification
     {
-        $object->fetch($_GET['facid']);
+        $object->fetch($id);
 
         if ($_POST['puht'])
         {
@@ -441,7 +440,7 @@ if ($action == 'update_line')
 
 if ($action == 'addline')
 {
-    $ret=$object->fetch($_GET['facid']);
+    $ret=$object->fetch($id);
     if ($ret < 0)
     {
         dol_print_error($db,$object->error);
@@ -548,7 +547,7 @@ if ($action == 'addline')
 
 if ($action == 'classin')
 {
-    $object->fetch($_GET['facid']);
+    $object->fetch($id);
     $result=$object->setProject($_POST['projectid']);
 }
 
@@ -556,9 +555,10 @@ if ($action == 'classin')
 // Repasse la facture en mode brouillon
 if ($action == 'edit' && $user->rights->fournisseur->facture->creer)
 {
-    $object->fetch($_GET['facid']);
+    $object->fetch($id);
 
     // On verifie si la facture a des paiements
+    // TODO move to DAO class
     $sql = 'SELECT pf.amount';
     $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf';
     $sql.= ' WHERE pf.fk_facturefourn = '.$object->id;
@@ -599,14 +599,14 @@ if ($action == 'edit' && $user->rights->fournisseur->facture->creer)
 
 if ($action == 'reopen' && $user->rights->fournisseur->facture->creer)
 {
-    $result = $object->fetch($_GET['facid']);
+    $result = $object->fetch($id);
     if ($object->statut == 2
     || ($object->statut == 3 && $object->close_code != 'replaced'))
     {
         $result = $object->set_unpaid($user);
         if ($result > 0)
         {
-            Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$_GET['facid']);
+            Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
             exit;
         }
         else
@@ -655,7 +655,7 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P
 {
     $langs->load('mails');
 
-    $object->fetch($_GET['facid']);
+    $object->fetch($id);
     $result=$object->fetch_thirdparty();
     if ($result > 0)
     {
@@ -736,12 +736,12 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P
                         $error=0;
 
                         // Initialisation donnees
-                        $object->sendtoid			= $sendtoid;
+                        $object->sendtoid		= $sendtoid;
                         $object->actiontypecode	= $actiontypecode;
                         $object->actionmsg		= $actionmsg;
                         $object->actionmsg2		= $actionmsg2;
                         $object->fk_element		= $object->id;
-                        $object->elementtype		= $object->element;
+                        $object->elementtype	= $object->element;
 
                         // Appel des triggers
                         include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
@@ -758,7 +758,7 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P
                         {
                             // Redirect here
                             // This avoid sending mail twice if going out and then back to page
-                            Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&mesg='.urlencode($mesg));
+                            Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mesg='.urlencode($mesg));
                             exit;
                         }
                     }
@@ -811,7 +811,7 @@ if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_P
 if ($action	== 'builddoc')
 {
     // Save modele used
-    $object->fetch($_REQUEST['facid']);
+    $object->fetch($id);
     if ($_REQUEST['model'])
     {
         $object->setDocModel($user, $_REQUEST['model']);
@@ -823,7 +823,7 @@ if ($action	== 'builddoc')
         $outputlangs = new Translate("",$conf);
         $outputlangs->setDefaultLang($_REQUEST['lang_id']);
     }
-    $result=supplier_invoice_pdf_create($db, $object,$object->modelpdf,$outputlangs);
+    $result=supplier_invoice_pdf_create($db,$object,$object->modelpdf,$outputlangs);
     if ($result	<= 0)
     {
         dol_print_error($db,$result);
@@ -831,7 +831,7 @@ if ($action	== 'builddoc')
     }
     else
     {
-        Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
+        Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
         exit;
     }
 }
@@ -1117,7 +1117,7 @@ if ($action == 'create')
 }
 else
 {
-    if ($_GET['facid'] > 0)
+    if ($id > 0)
     {
         /* *************************************************************************** */
         /*                                                                             */
@@ -1129,16 +1129,15 @@ else
 
         $productstatic = new Product($db);
 
-        $fac = new FactureFournisseur($db);
-        $fac->fetch($_GET['facid']);
+        $object->fetch($id);
 
         $societe = new Fournisseur($db);
-        $societe->fetch($fac->socid);
+        $societe->fetch($object->socid);
 
         /*
          *	View card
          */
-        $head = facturefourn_prepare_head($fac);
+        $head = facturefourn_prepare_head($object);
         $titre=$langs->trans('SupplierInvoice');
         dol_fiche_head($head, 'card', $titre, 0, 'bill');
 
@@ -1147,7 +1146,7 @@ else
         // Confirmation de la suppression d'une ligne produit
         if ($action == 'confirm_delete_line')
         {
-            $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline', '', 1, 1);
+            $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline', '', 1, 1);
             if ($ret == 'html') print '<br>';
         }
 
@@ -1160,21 +1159,21 @@ else
             //array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1)
             );
             // Paiement incomplet. On demande si motif = escompte ou autre
-            $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$fac->ref),'confirm_clone',$formquestion,'yes', 1);
+            $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$object->ref),'confirm_clone',$formquestion,'yes', 1);
             if ($ret == 'html') print '<br>';
         }
 
         // Confirmation de la validation
         if ($action == 'valid')
         {
-            $ret=$form->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('ValidateBill'), $langs->trans('ConfirmValidateBill', $fac->ref), 'confirm_valid', '', 0, 1);
+            $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $langs->trans('ConfirmValidateBill', $object->ref), 'confirm_valid', '', 0, 1);
             if ($ret == 'html') print '<br>';
         }
 
         // Confirmation set paid
         if ($action == 'paid')
         {
-            $ret=$form->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $fac->ref), 'confirm_paid', '', 0, 1);
+            $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $object->ref), 'confirm_paid', '', 0, 1);
             if ($ret == 'html') print '<br>';
         }
 
@@ -1183,7 +1182,7 @@ else
          */
         if ($action == 'delete')
         {
-            $ret=$form->form_confirm('fiche.php?facid='.$fac->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1);
+            $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1);
             if ($ret == 'html') print '<br>';
         }
 
@@ -1195,37 +1194,37 @@ else
 
         // Ref
         print '<tr><td nowrap="nowrap" width="20%">'.$langs->trans("Ref").'</td><td colspan="4">';
-        print $form->showrefnav($fac,'facid','',1,'rowid','ref',$morehtmlref);
+        print $form->showrefnav($object,'id','',1,'rowid','ref',$morehtmlref);
         print '</td>';
         print "</tr>\n";
 
         // Ref supplier
-        print '<tr><td>'.$form->editfieldkey("RefSupplier",'ref_supplier',$fac->ref_supplier,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer)).'</td><td colspan="4">';
-        print $form->editfieldval("RefSupplier",'ref_supplier',$fac->ref_supplier,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer));
+        print '<tr><td>'.$form->editfieldkey("RefSupplier",'ref_supplier',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).'</td><td colspan="4">';
+        print $form->editfieldval("RefSupplier",'ref_supplier',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer));
         print '</td></tr>';
 
         // Third party
         print '<tr><td>'.$langs->trans('Supplier').'</td><td colspan="4">'.$societe->getNomUrl(1);
-        print ' &nbsp; (<a href="'.DOL_URL_ROOT.'/fourn/facture/index.php?socid='.$fac->socid.'">'.$langs->trans('OtherBills').'</a>)</td>';
+        print ' &nbsp; (<a href="'.DOL_URL_ROOT.'/fourn/facture/index.php?socid='.$object->socid.'">'.$langs->trans('OtherBills').'</a>)</td>';
         print '</tr>';
 
         // Type
         print '<tr><td>'.$langs->trans('Type').'</td><td colspan="4">';
-        print $fac->getLibType();
-        if ($fac->type == 1)
+        print $object->getLibType();
+        if ($object->type == 1)
         {
             $facreplaced=new FactureFournisseur($db);
-            $facreplaced->fetch($fac->fk_facture_source);
+            $facreplaced->fetch($object->fk_facture_source);
             print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
         }
-        if ($fac->type == 2)
+        if ($object->type == 2)
         {
             $facusing=new FactureFournisseur($db);
-            $facusing->fetch($fac->fk_facture_source);
+            $facusing->fetch($object->fk_facture_source);
             print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
         }
 
-        $facidavoir=$fac->getListIdAvoirFromInvoice();
+        $facidavoir=$object->getListIdAvoirFromInvoice();
         if (count($facidavoir) > 0)
         {
             print ' ('.$langs->transnoentities("InvoiceHasAvoir");
@@ -1250,8 +1249,8 @@ else
 
 
         // Label
-        print '<tr><td>'.$form->editfieldkey("Label",'label',$fac->label,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer)).'</td><td colspan="3">';
-        print $form->editfieldval("Label",'label',$fac->label,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer));
+        print '<tr><td>'.$form->editfieldkey("Label",'label',$object->label,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).'</td><td colspan="3">';
+        print $form->editfieldval("Label",'label',$object->label,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer));
         print '</td>';
 
         /*
@@ -1268,12 +1267,14 @@ else
         }
 
         print '<td rowspan="'.$nbrows.'" valign="top">';
+        
+        // TODO move to DAO class
         $sql  = 'SELECT datep as dp, pf.amount,';
         $sql .= ' c.libelle as paiement_type, p.num_paiement, p.rowid';
         $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p';
         $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
         $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
-        $sql .= ' WHERE pf.fk_facturefourn = '.$fac->id;
+        $sql .= ' WHERE pf.fk_facturefourn = '.$object->id;
         $sql .= ' ORDER BY dp DESC';
 
         $result = $db->query($sql);
@@ -1299,9 +1300,9 @@ else
                 print '<td>'.$objp->paiement_type.' '.$objp->num_paiement.'</td>';
                 print '<td align="right">'.price($objp->amount).'</td>';
                 print '<td align="center">';
-                if ($fac->statut == 1 && $fac->paye == 0 && $user->societe_id == 0)
+                if ($object->statut == 1 && $object->paye == 0 && $user->societe_id == 0)
                 {
-                    print '<a href="fiche.php?facid='.$fac->id.'&amp;action=deletepaiement&amp;paiement_id='.$objp->rowid.'">';
+                    print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=deletepaiement&amp;paiement_id='.$objp->rowid.'">';
                     print img_delete();
                     print '</a>';
                 }
@@ -1311,12 +1312,12 @@ else
                 $i++;
             }
 
-            if ($fac->paye == 0)
+            if ($object->paye == 0)
             {
                 print '<tr><td colspan="2" align="right">'.$langs->trans('AlreadyPaid').' :</td><td align="right"><b>'.price($totalpaye).'</b></td></tr>';
-                print '<tr><td colspan="2" align="right">'.$langs->trans("Billed").' :</td><td align="right" style="border: 1px solid;">'.price($fac->total_ttc).'</td></tr>';
+                print '<tr><td colspan="2" align="right">'.$langs->trans("Billed").' :</td><td align="right" style="border: 1px solid;">'.price($object->total_ttc).'</td></tr>';
 
-                $resteapayer = $fac->total_ttc - $totalpaye;
+                $resteapayer = $object->total_ttc - $totalpaye;
 
                 print '<tr><td colspan="2" align="right">'.$langs->trans('RemainderToPay').' :</td>';
                 print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>'.price($resteapayer).'</b></td></tr>';
@@ -1333,21 +1334,21 @@ else
         print '</tr>';
 
         // Date
-        print '<tr><td>'.$form->editfieldkey("Date",'date',$fac->datep,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer && $fac->getSommePaiement() <= 0)).'</td><td colspan="3">';
-        print $form->editfieldval("Date",'date',$fac->datep,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer && $fac->getSommePaiement() <= 0),'day');
+        print '<tr><td>'.$form->editfieldkey("Date",'date',$object->datep,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0)).'</td><td colspan="3">';
+        print $form->editfieldval("Date",'date',$object->datep,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'day');
         print '</td>';
 
         // Due date
-        print '<tr><td>'.$form->editfieldkey("DateMaxPayment",'date_echeance',$fac->date_echeance,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer && $fac->getSommePaiement() <= 0)).'</td><td colspan="3">';
-        print $form->editfieldval("DateMaxPayment",'date_echeance',$fac->date_echeance,'facid',$fac->id,($fac->statut<2 && $user->rights->fournisseur->facture->creer && $fac->getSommePaiement() <= 0),'day');
+        print '<tr><td>'.$form->editfieldkey("DateMaxPayment",'date_echeance',$object->date_echeance,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0)).'</td><td colspan="3">';
+        print $form->editfieldval("DateMaxPayment",'date_echeance',$object->date_echeance,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'day');
         print '</td>';
 
         // Status
-        $alreadypaid=$fac->getSommePaiement();
-        print '<tr><td>'.$langs->trans('Status').'</td><td colspan="3">'.$fac->getLibStatut(4,$alreadypaid).'</td></tr>';
+        $alreadypaid=$object->getSommePaiement();
+        print '<tr><td>'.$langs->trans('Status').'</td><td colspan="3">'.$object->getLibStatut(4,$alreadypaid).'</td></tr>';
 
-        print '<tr><td>'.$langs->trans('AmountHT').'</td><td align="right">'.price($fac->total_ht).'</td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
-        print '<tr><td>'.$langs->trans('AmountVAT').'</td><td align="right">'.price($fac->total_tva).'</td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
+        print '<tr><td>'.$langs->trans('AmountHT').'</td><td align="right">'.price($object->total_ht).'</td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
+        print '<tr><td>'.$langs->trans('AmountVAT').'</td><td align="right">'.price($object->total_tva).'</td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
 
         // Amount Local Taxes
         if ($mysoc->pays_code=='ES')
@@ -1355,17 +1356,17 @@ else
             if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
             {
                 print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->pays_code).'</td>';
-                print '<td align="right">'.price($fac->total_localtax1).'</td>';
+                print '<td align="right">'.price($object->total_localtax1).'</td>';
                 print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
             }
             if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
             {
                 print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->pays_code).'</td>';
-                print '<td align="right">'.price($fac->total_localtax2).'</td>';
+                print '<td align="right">'.price($object->total_localtax2).'</td>';
                 print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
             }
         }
-        print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right">'.price($fac->total_ttc).'</td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
+        print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right">'.price($object->total_ttc).'</td><td colspan="2" align="left">'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
 
         // Project
         if ($conf->projet->enabled)
@@ -1379,7 +1380,7 @@ else
             print '</td>';
             if ($action != 'classify')
             {
-                print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;facid='.$fac->id.'">';
+                print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
                 print img_edit($langs->trans('SetProject'),1);
                 print '</a></td>';
             }
@@ -1388,11 +1389,11 @@ else
             print '</td><td colspan="3">';
             if ($action == 'classify')
             {
-                $form->form_project($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->socid,$fac->fk_project,'projectid');
+                $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,'projectid');
             }
             else
             {
-                $form->form_project($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->socid,$fac->fk_project,'none');
+                $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,'none');
             }
             print '</td>';
             print '</tr>';
@@ -1407,7 +1408,7 @@ else
         print '<br>';
         print '<table class="noborder" width="100%">';
         $var=1;
-        $num=count($fac->lines);
+        $num=count($object->lines);
         for ($i = 0; $i < $num; $i++)
         {
             if ($i == 0)
@@ -1425,29 +1426,29 @@ else
             }
 
             // Show product and description
-            $type=$fac->lines[$i]->product_type?$fac->lines[$i]->product_type:$fac->lines[$i]->fk_product_type;
+            $type=$object->lines[$i]->product_type?$object->lines[$i]->product_type:$object->lines[$i]->fk_product_type;
             // Try to enhance type detection using date_start and date_end for free lines where type
             // was not saved.
-            if (! empty($fac->lines[$i]->date_start)) $type=1;
-            if (! empty($fac->lines[$i]->date_end)) $type=1;
+            if (! empty($object->lines[$i]->date_start)) $type=1;
+            if (! empty($object->lines[$i]->date_end)) $type=1;
 
             $var=!$var;
 
             // Edit line
-            if ($fac->statut == 0 && $action == 'mod_ligne' && $_GET['etat'] == '0' && $_GET['lineid'] == $fac->lines[$i]->rowid)
+            if ($object->statut == 0 && $action == 'mod_ligne' && $_GET['etat'] == '0' && $_GET['lineid'] == $object->lines[$i]->rowid)
             {
-                print '<form action="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;etat=1&amp;lineid='.$fac->lines[$i]->rowid.'" method="post">';
+                print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;etat=1&amp;lineid='.$object->lines[$i]->rowid.'" method="post">';
                 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
                 print '<input type="hidden" name="action" value="update_line">';
                 print '<tr '.$bc[$var].'>';
 
                 // Show product and description
                 print '<td>';
-                if (($conf->product->enabled || $conf->service->enabled) && $fac->lines[$i]->fk_product)
+                if (($conf->product->enabled || $conf->service->enabled) && $object->lines[$i]->fk_product)
                 {
-                    print '<input type="hidden" name="idprod" value="'.$fac->lines[$i]->fk_product.'">';
+                    print '<input type="hidden" name="idprod" value="'.$object->lines[$i]->fk_product.'">';
                     $product_static=new ProductFournisseur($db);
-                    $product_static->fetch($fac->lines[$i]->fk_product);
+                    $product_static->fetch($object->lines[$i]->fk_product);
                     $text=$product_static->getNomUrl(1);
                     $text.= ' - '.$product_static->libelle;
                     print $text;
@@ -1455,7 +1456,7 @@ else
                 }
                 else
                 {
-                    print $form->select_type_of_lines($fac->lines[$i]->product_type,'type',1);
+                    print $form->select_type_of_lines($object->lines[$i]->product_type,'type',1);
                     if ($conf->product->enabled && $conf->service->enabled) print '<br>';
                 }
 
@@ -1463,21 +1464,21 @@ else
                 require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
                 $nbrows=ROWS_2;
                 if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
-                $doleditor=new DolEditor('label',$fac->lines[$i]->description,'',128,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
+                $doleditor=new DolEditor('label',$object->lines[$i]->description,'',128,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
                 $doleditor->Create();
                 print '</td>';
 
                 // VAT
                 print '<td align="right">';
-                print $form->load_tva('tauxtva',$fac->lines[$i]->tva_tx,$societe,$mysoc);
+                print $form->load_tva('tauxtva',$object->lines[$i]->tva_tx,$societe,$mysoc);
                 print '</td>';
 
                 // Unit price
-                print '<td align="right" nowrap="nowrap"><input size="4" name="puht" type="text" value="'.price($fac->lines[$i]->pu_ht).'"></td>';
+                print '<td align="right" nowrap="nowrap"><input size="4" name="puht" type="text" value="'.price($object->lines[$i]->pu_ht).'"></td>';
 
                 print '<td align="right" nowrap="nowrap"><input size="4" name="puttc" type="text" value=""></td>';
 
-                print '<td align="right"><input size="1" name="qty" type="text" value="'.$fac->lines[$i]->qty.'"></td>';
+                print '<td align="right"><input size="1" name="qty" type="text" value="'.$object->lines[$i]->qty.'"></td>';
 
                 print '<td align="right" nowrap="nowrap">&nbsp;</td>';
 
@@ -1495,57 +1496,57 @@ else
 
                 // Show product and description
                 print '<td>';
-                if ($fac->lines[$i]->fk_product)
+                if ($object->lines[$i]->fk_product)
                 {
                     print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
 
                     $product_static=new ProductFournisseur($db);
-                    $product_static->fetch($fac->lines[$i]->fk_product);
+                    $product_static->fetch($object->lines[$i]->fk_product);
                     $text=$product_static->getNomUrl(1);
                     $text.= ' - '.$product_static->libelle;
-                    $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($fac->lines[$i]->description));
+                    $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($object->lines[$i]->description));
                     print $form->textwithtooltip($text,$description,3,'','',$i);
 
                     // Show range
-                    print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end);
+                    print_date_range($object->lines[$i]->date_start,$object->lines[$i]->date_end);
 
                     // Add description in form
-                    if ($conf->global->PRODUIT_DESC_IN_FORM) print ($fac->lines[$i]->description && $fac->lines[$i]->description!=$product_static->libelle)?'<br>'.dol_htmlentitiesbr($fac->lines[$i]->description):'';
+                    if ($conf->global->PRODUIT_DESC_IN_FORM) print ($object->lines[$i]->description && $object->lines[$i]->description!=$product_static->libelle)?'<br>'.dol_htmlentitiesbr($object->lines[$i]->description):'';
                 }
 
                 // Description - Editor wysiwyg
-                if (! $fac->lines[$i]->fk_product)
+                if (! $object->lines[$i]->fk_product)
                 {
                     if ($type==1) $text = img_object($langs->trans('Service'),'service');
                     else $text = img_object($langs->trans('Product'),'product');
-                    print $text.' '.nl2br($fac->lines[$i]->description);
+                    print $text.' '.nl2br($object->lines[$i]->description);
 
                     // Show range
-                    print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end);
+                    print_date_range($object->lines[$i]->date_start,$object->lines[$i]->date_end);
                 }
                 print '</td>';
 
                 // VAT
-                print '<td align="right">'.vatrate($fac->lines[$i]->tva_tx).'%</td>';
+                print '<td align="right">'.vatrate($object->lines[$i]->tva_tx).'%</td>';
 
                 // Unit price
-                print '<td align="right" nowrap="nowrap">'.price($fac->lines[$i]->pu_ht,'MU').'</td>';
+                print '<td align="right" nowrap="nowrap">'.price($object->lines[$i]->pu_ht,'MU').'</td>';
 
-                print '<td align="right" nowrap="nowrap">'.($fac->lines[$i]->pu_ttc?price($fac->lines[$i]->pu_ttc,'MU'):'&nbsp;').'</td>';
+                print '<td align="right" nowrap="nowrap">'.($object->lines[$i]->pu_ttc?price($object->lines[$i]->pu_ttc,'MU'):'&nbsp;').'</td>';
 
-                print '<td align="right">'.$fac->lines[$i]->qty.'</td>';
+                print '<td align="right">'.$object->lines[$i]->qty.'</td>';
 
-                print '<td align="right" nowrap="nowrap">'.price($fac->lines[$i]->total_ht).'</td>';
+                print '<td align="right" nowrap="nowrap">'.price($object->lines[$i]->total_ht).'</td>';
 
-                print '<td align="right" nowrap="nowrap">'.price($fac->lines[$i]->total_ttc).'</td>';
+                print '<td align="right" nowrap="nowrap">'.price($object->lines[$i]->total_ttc).'</td>';
 
                 print '<td align="center" width="16">';
-                if ($fac->statut == 0) print '<a href="fiche.php?facid='.$fac->id.'&amp;action=mod_ligne&amp;etat=0&amp;lineid='.$fac->lines[$i]->rowid.'">'.img_edit().'</a>';
+                if ($object->statut == 0) print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=mod_ligne&amp;etat=0&amp;lineid='.$object->lines[$i]->rowid.'">'.img_edit().'</a>';
                 else print '&nbsp;';
                 print '</td>';
 
                 print '<td align="center" width="16">';
-                if ($fac->statut == 0) print '<a href="fiche.php?facid='.$fac->id.'&amp;action=confirm_delete_line&amp;lineid='.$fac->lines[$i]->rowid.'">'.img_delete().'</a>';
+                if ($object->statut == 0) print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=confirm_delete_line&amp;lineid='.$object->lines[$i]->rowid.'">'.img_delete().'</a>';
                 else print '&nbsp;';
                 print '</td>';
 
@@ -1558,7 +1559,7 @@ else
          * Form to add new line
          */
 
-        if ($fac->statut == 0 && $action != 'mod_ligne')
+        if ($object->statut == 0 && $action != 'mod_ligne')
         {
             print '<tr class="liste_titre">';
             print '<td>';
@@ -1575,9 +1576,9 @@ else
             print '</tr>';
 
             // Add free products/services form
-            print '<form action="fiche.php?facid='.$fac->id.'&amp;action=addline" method="post">';
+            print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addline" method="post">';
             print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-            print '<input type="hidden" name="facid" value="'.$fac->id.'">';
+            print '<input type="hidden" name="facid" value="'.$object->id.'">';
             print '<input type="hidden" name="socid" value="'.$societe->id.'">';
 
             $var=true;
@@ -1634,15 +1635,14 @@ else
                 print '<td colspan="4">&nbsp;</td>';
                 print '</tr>';
 
-                print '<form name="addline_predef" action="fiche.php?facid='.$fac->id.'&amp;action=addline" method="post">';
+                print '<form name="addline_predef" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addline" method="post">';
                 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-                print '<input type="hidden" name="socid" value="'. $fac->socid .'">';
-                print '<input type="hidden" name="facid" value="'.$fac->id.'">';
-                print '<input type="hidden" name="socid" value="'.$fac->socid.'">';
+                print '<input type="hidden" name="socid" value="'. $object->socid .'">';
+                print '<input type="hidden" name="facid" value="'.$object->id.'">';
                 $var=! $var;
                 print '<tr '.$bc[$var].'>';
                 print '<td colspan="4">';
-                $form->select_produits_fournisseurs($fac->socid,'','idprodfournprice','',$filtre);
+                $form->select_produits_fournisseurs($object->socid,'','idprodfournprice','',$filtre);
                 print '</td>';
                 print '<td align="right"><input type="text" name="qty" value="1" size="1"></td>';
                 print '<td>&nbsp;</td>';
@@ -1667,11 +1667,11 @@ else
             print '<div class="tabsAction">';
 
             // Reopen a standard paid invoice
-            if (($fac->type == 0 || $fac->type == 1) && ($fac->statut == 2 || $fac->statut == 3))				// A paid invoice (partially or completely)
+            if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3))				// A paid invoice (partially or completely)
             {
-                if (! $facidnext && $fac->close_code != 'replaced')	// Not replaced by another invoice
+                if (! $facidnext && $object->close_code != 'replaced')	// Not replaced by another invoice
                 {
-                    print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$fac->id.'&amp;action=reopen">'.$langs->trans('ReOpen').'</a>';
+                    print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans('ReOpen').'</a>';
                 }
                 else
                 {
@@ -1680,39 +1680,39 @@ else
             }
 
             // Send by mail
-            if (($fac->statut == 1 || $fac->statut == 2))
+            if (($object->statut == 1 || $object->statut == 2))
             {
                 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->fournisseur->supplier_invoice_advance->send)
                 {
-                    print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$fac->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
+                    print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
                 }
                 else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
             }
 
 
             //Make payments
-            if ($action != 'edit' && $fac->statut == 1 && $fac->paye == 0  && $user->societe_id == 0)
+            if ($action != 'edit' && $object->statut == 1 && $object->paye == 0  && $user->societe_id == 0)
             {
-                print '<a class="butAction" href="paiement.php?facid='.$fac->id.'&amp;action=create">'.$langs->trans('DoPayment').'</a>';
+                print '<a class="butAction" href="paiement.php?facid='.$object->id.'&amp;action=create">'.$langs->trans('DoPayment').'</a>';
             }
 
             //Classify paid
-            if ($action != 'edit' && $fac->statut == 1 && $fac->paye == 0  && $user->societe_id == 0)
+            if ($action != 'edit' && $object->statut == 1 && $object->paye == 0  && $user->societe_id == 0)
             {
-                print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=paid"';
+                print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=paid"';
                 print '>'.$langs->trans('ClassifyPaid').'</a>';
 
-                //print '<a class="butAction" href="fiche.php?facid='.$fac->id.'&amp;action=paid">'.$langs->trans('ClassifyPaid').'</a>';
+                //print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=paid">'.$langs->trans('ClassifyPaid').'</a>';
             }
 
             //Validate
-            if ($action != 'edit' && $fac->statut == 0)
+            if ($action != 'edit' && $object->statut == 0)
             {
-                if (count($fac->lines))
+                if (count($object->lines))
                 {
                     if ($user->rights->fournisseur->facture->valider)
                     {
-                        print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'&amp;action=valid"';
+                        print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid"';
                         print '>'.$langs->trans('Validate').'</a>';
                     }
                     else
@@ -1726,13 +1726,13 @@ else
             //Clone
             if ($action != 'edit' && $user->rights->fournisseur->facture->creer)
             {
-                print '<a class="butAction" href="fiche.php?facid='.$fac->id.'&amp;action=clone&amp;socid='.$fac->socid.'">'.$langs->trans('ToClone').'</a>';
+                print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=clone&amp;socid='.$object->socid.'">'.$langs->trans('ToClone').'</a>';
             }
 
             //Delete
             if ($action != 'edit' && $user->rights->fournisseur->facture->supprimer)
             {
-                print '<a class="butActionDelete" href="fiche.php?facid='.$fac->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
+                print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
             }
             print '</div>';
 
@@ -1745,15 +1745,15 @@ else
                  * Documents generes
                  */
 
-                $ref=dol_sanitizeFileName($fac->ref);
-                $subdir = get_exdir($fac->id,2).$ref;
-                $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($fac->id,2).$ref;
-                $urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id;
+                $ref=dol_sanitizeFileName($object->ref);
+                $subdir = get_exdir($object->id,2).$ref;
+                $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref;
+                $urlsource=$_SERVER['PHP_SELF'].'?id='.$object->id;
                 $genallowed=$user->rights->fournisseur->facture->creer;
                 $delallowed=$user->rights->fournisseur->facture->supprimer;
 
                 print '<br>';
-                $somethingshown=$formfile->show_documents('facture_fournisseur',$subdir,$filedir,$urlsource,$genallowed,$delallowed,$fac->modelpdf);
+                $somethingshown=$formfile->show_documents('facture_fournisseur',$subdir,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf);
 
                 $object=$fac;
 
@@ -1778,8 +1778,8 @@ else
          */
         if ($action == 'presend')
         {
-            $ref = dol_sanitizeFileName($fac->ref);
-            $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($fac->id,2).$ref.'.pdf';
+            $ref = dol_sanitizeFileName($object->ref);
+            $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref.'.pdf';
 
             print '<br>';
             print_titre($langs->trans('SendBillByMail'));
@@ -1804,12 +1804,12 @@ else
             $formmail->withdeliveryreceipt=1;
             $formmail->withcancel=1;
             // Tableau des substitutions
-            $formmail->substit['__FACREF__']=$fac->ref;
+            $formmail->substit['__FACREF__']=$object->ref;
             // Tableau des parametres complementaires
             $formmail->param['action']='send';
             $formmail->param['models']='invoice_supplier_send';
-            $formmail->param['facid']=$fac->id;
-            $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?facid='.$fac->id;
+            $formmail->param['facid']=$object->id;
+            $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
 
             // Init list of files
             if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
diff --git a/htdocs/fourn/fiche.php b/htdocs/fourn/fiche.php
index 1db7e2c9b96..c81449c24ae 100644
--- a/htdocs/fourn/fiche.php
+++ b/htdocs/fourn/fiche.php
@@ -39,28 +39,29 @@ $langs->load('orders');
 $langs->load('companies');
 $langs->load('commercial');
 
+$action	= GETPOST('action');
+
 // Security check
-$socid = GETPOST("socid");
-if ($user->societe_id) $socid=$user->societe_id;
-$result = restrictedArea($user, 'societe&fournisseur', $socid, '');
+$id = (GETPOST("socid") ? GETPOST("socid") : GETPOST("id"));
+if ($user->societe_id) $id=$user->societe_id;
+$result = restrictedArea($user, 'societe&fournisseur', $id, '');
 
+$object = new Fournisseur($db);
 
 /*
  * Action
  */
 
-if ($_POST['action'] == 'setsupplieraccountancycode')
+if ($action == 'setsupplieraccountancycode')
 {
-    $societe = new Societe($db);
-    $result=$societe->fetch($_POST['socid']);
-    $societe->code_compta_fournisseur=$_POST["supplieraccountancycode"];
-    $result=$societe->update($societe->id,$user,1,0,1);
+    $result=$object->fetch($id);
+    $object->code_compta_fournisseur=$_POST["supplieraccountancycode"];
+    $result=$object->update($object->id,$user,1,0,1);
     if ($result < 0)
     {
-        $mesg=join(',',$societe->errors);
+        $mesg=join(',',$object->errors);
     }
-    $POST["action"]="";
-    $socid=$_POST["socid"];
+    $action="";
 }
 
 
@@ -69,18 +70,17 @@ if ($_POST['action'] == 'setsupplieraccountancycode')
  * View
  */
 
-$societe = new Fournisseur($db);
 $contactstatic = new Contact($db);
 $form = new Form($db);
 
-if ( $societe->fetch($socid) )
+if ($object->fetch($id))
 {
 	llxHeader('',$langs->trans('SupplierCard'));
 
 	/*
 	 * Affichage onglets
 	 */
-	$head = societe_prepare_head($societe);
+	$head = societe_prepare_head($object);
 
 	dol_fiche_head($head, 'supplier', $langs->trans("ThirdParty"),0,'company');
 
@@ -90,97 +90,97 @@ if ( $societe->fetch($socid) )
 
 	print '<table width="100%" class="border">';
 	print '<tr><td width="20%">'.$langs->trans("ThirdPartyName").'</td><td width="80%" colspan="3">';
-	$societe->next_prev_filter="te.fournisseur = 1";
-	print $form->showrefnav($societe,'socid','',($user->societe_id?0:1),'rowid','nom','','');
+	$object->next_prev_filter="te.fournisseur = 1";
+	print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','','');
 	print '</td></tr>';
 
     if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
     {
-        print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$societe->prefix_comm.'</td></tr>';
+        print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
     }
 
-	if ($societe->fournisseur)
+	if ($object->fournisseur)
 	{
         print '<tr>';
         print '<td nowrap="nowrap">'.$langs->trans("SupplierCode"). '</td><td colspan="3">';
-        print $societe->code_fournisseur;
-        if ($societe->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
+        print $object->code_fournisseur;
+        if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
         print '</td>';
         print '</tr>';
 
         print '<tr>';
         print '<td>';
-        print $form->editfieldkey("SupplierAccountancyCode",'supplieraccountancycode',$societe->code_compta_fournisseur,'socid',$societe->id,$user->rights->societe->creer);
+        print $form->editfieldkey("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer);
         print '</td><td colspan="3">';
-        print $form->editfieldval("SupplierAccountancyCode",'supplieraccountancycode',$societe->code_compta_fournisseur,'socid',$societe->id,$user->rights->societe->creer);
+        print $form->editfieldval("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer);
         print '</td>';
         print '</tr>';
 	}
 
 	// Address
 	print '<tr><td valign="top">'.$langs->trans("Address").'</td><td colspan="3">';
-	dol_print_address($societe->address,'gmap','thirdparty',$societe->id);
+	dol_print_address($object->address,'gmap','thirdparty',$object->id);
 	print '</td></tr>';
 
 	// Zip / Town
-	print '<tr><td nowrap="nowrap">'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td colspan="3">'.$societe->cp.(($societe->cp && $societe->ville)?' / ':'').$societe->ville.'</td>';
+	print '<tr><td nowrap="nowrap">'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td colspan="3">'.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town.'</td>';
 	print '</tr>';
 
 	// Country
 	print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
-	$img=picto_from_langcode($societe->pays_code);
-	if ($societe->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$societe->pays,$langs->trans("CountryIsInEEC"),1,0);
-	else print ($img?$img.' ':'').$societe->pays;
+	$img=picto_from_langcode($object->country_code);
+	if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0);
+	else print ($img?$img.' ':'').$object->country;
 	print '</td></tr>';
 
 	// Phone
-	print '<tr><td>'.$langs->trans("Phone").'</td><td style="min-width: 25%;">'.dol_print_phone($societe->tel,$societe->pays_code,0,$societe->id,'AC_TEL').'</td>';
+	print '<tr><td>'.$langs->trans("Phone").'</td><td style="min-width: 25%;">'.dol_print_phone($object->tel,$object->country_code,0,$object->id,'AC_TEL').'</td>';
 
 	// Fax
-	print '<td>'.$langs->trans("Fax").'</td><td style="min-width: 25%;">'.dol_print_phone($societe->fax,$societe->pays_code,0,$societe->id,'AC_FAX').'</td></tr>';
+	print '<td>'.$langs->trans("Fax").'</td><td style="min-width: 25%;">'.dol_print_phone($object->fax,$object->country_code,0,$object->id,'AC_FAX').'</td></tr>';
 
     // EMail
-	print '<td>'.$langs->trans('EMail').'</td><td colspan="3">'.dol_print_email($societe->email,0,$societe->id,'AC_EMAIL').'</td></tr>';
+	print '<td>'.$langs->trans('EMail').'</td><td colspan="3">'.dol_print_email($object->email,0,$object->id,'AC_EMAIL').'</td></tr>';
 
 	// Web
-	print '<tr><td>'.$langs->trans("Web")."</td><td colspan=\"3\">".dol_print_url($societe->url)."</td></tr>";
+	print '<tr><td>'.$langs->trans("Web")."</td><td colspan=\"3\">".dol_print_url($object->url)."</td></tr>";
 
 	// Assujetti a TVA ou pas
 	print '<tr>';
 	print '<td nowrap="nowrap">'.$langs->trans('VATIsUsed').'</td><td colspan="3">';
-	print yn($societe->tva_assuj);
+	print yn($object->tva_assuj);
 	print '</td>';
 	print '</tr>';
 
 	// Local Taxes
-	if($mysoc->pays_code=='ES')
+	if($mysoc->country_code=='ES')
 	{
 		if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
 		{
 			print '<tr><td nowrap="nowrap">'.$langs->trans('LocalTax1IsUsedES').'</td><td colspan="3">';
-			print yn($societe->localtax1_assuj);
+			print yn($object->localtax1_assuj);
 			print '</td></tr>';
 			print '<tr><td nowrap="nowrap">'.$langs->trans('LocalTax2IsUsedES').'</td><td colspan="3">';
-			print yn($societe->localtax2_assuj);
+			print yn($object->localtax2_assuj);
 			print '</td></tr>';
 		}
 		elseif($mysoc->localtax1_assuj=="1")
 		{
 			print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">';
-			print yn($societe->localtax1_assuj);
+			print yn($object->localtax1_assuj);
 			print '</td></tr>';
 		}
 		elseif($mysoc->localtax2_assuj=="1")
 		{
 			print '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">';
-			print yn($societe->localtax2_assuj);
+			print yn($object->localtax2_assuj);
 			print '</td></tr>';
 		}
 	}
 
     // TVA Intra
     print '<tr><td nowrap>'.$langs->trans('VATIntraVeryShort').'</td><td colspan="3">';
-    print $objsoc->tva_intra;
+    print $object->tva_intra;
     print '</td></tr>';
 
     // Module Adherent
@@ -191,7 +191,7 @@ if ( $societe->fetch($socid) )
         print '<tr><td width="25%" valign="top">'.$langs->trans("LinkedToDolibarrMember").'</td>';
         print '<td colspan="3">';
         $adh=new Adherent($db);
-        $result=$adh->fetch('','',$societe->id);
+        $result=$adh->fetch('','',$object->id);
         if ($result > 0)
         {
             $adh->ref=$adh->getFullName($langs);
@@ -216,7 +216,7 @@ if ( $societe->fetch($socid) )
 	print '<table class="noborder" width="100%">';
 	print '<tr class="liste_titre">';
 	print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("Summary").'</td>';
-	print '<td align="right"><a href="'.DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$societe->id.'">'.$langs->trans("ShowSupplierPreview").'</a></td></tr></table></td>';
+	print '<td align="right"><a href="'.DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id.'">'.$langs->trans("ShowSupplierPreview").'</a></td></tr></table></td>';
 	print '</tr>';
 	print '</table>';
 
@@ -229,7 +229,7 @@ if ( $societe->fetch($socid) )
 		print '<table class="noborder" width="100%">';
 		print '<tr class="liste_titre">';
 		print '<td>'.$langs->trans("ProductsAndServices").'</td><td align="right">';
-		print '<a href="'.DOL_URL_ROOT.'/fourn/product/liste.php?fourn_id='.$societe->id.'">'.$langs->trans("All").' ('.$societe->NbProduct().')';
+		print '<a href="'.DOL_URL_ROOT.'/fourn/product/liste.php?fourn_id='.$object->id.'">'.$langs->trans("All").' ('.$object->NbProduct().')';
 		print '</a></td></tr></table>';
 	}
 
@@ -243,9 +243,10 @@ if ( $societe->fetch($socid) )
 
 	if ($user->rights->fournisseur->commande->lire)
 	{
+		// TODO move to DAO class
 		$sql  = "SELECT p.rowid,p.ref, p.date_commande as dc, p.fk_statut";
 		$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p ";
-		$sql.= " WHERE p.fk_soc =".$societe->id;
+		$sql.= " WHERE p.fk_soc =".$object->id;
 		$sql.= " ORDER BY p.date_commande DESC";
 		$sql.= " ".$db->plimit($MAXLIST);
 		$resql=$db->query($sql);
@@ -261,8 +262,8 @@ if ( $societe->fetch($socid) )
 			    print '<tr class="liste_titre">';
     			print '<td colspan="3">';
     			print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans("LastOrders",($num<$MAXLIST?"":$MAXLIST)).'</td>';
-    			print '<td align="right"><a href="commande/liste.php?socid='.$societe->id.'">'.$langs->trans("AllOrders").' ('.$num.')</td>';
-                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?mode=supplier&socid='.$societe->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
+    			print '<td align="right"><a href="commande/liste.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' ('.$num.')</td>';
+                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
     			print '</tr></table>';
     			print '</td></tr>';
 			}
@@ -308,11 +309,12 @@ if ( $societe->fetch($socid) )
 
 	if ($user->rights->fournisseur->facture->lire)
 	{
+		// TODO move to DAO class
 		$sql = 'SELECT f.rowid,f.libelle,f.facnumber,f.fk_statut,f.datef as df,f.total_ttc as amount,f.paye,';
 		$sql.= ' SUM(pf.amount) as am';
 		$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
 		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn';
-		$sql.= ' WHERE f.fk_soc = '.$societe->id;
+		$sql.= ' WHERE f.fk_soc = '.$object->id;
 		$sql.= ' GROUP BY f.rowid,f.libelle,f.facnumber,f.fk_statut,f.datef,f.total_ttc,f.paye';
 		$sql.= ' ORDER BY f.datef DESC';
 		$resql=$db->query($sql);
@@ -326,8 +328,8 @@ if ( $societe->fetch($socid) )
 
 			    print '<tr class="liste_titre">';
     			print '<td colspan="4">';
-    			print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('LastSuppliersBills',($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="facture/index.php?socid='.$societe->id.'">'.$langs->trans('AllBills').' ('.$num.')</td>';
-                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?mode=supplier&socid='.$societe->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
+    			print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('LastSuppliersBills',($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="facture/index.php?socid='.$object->id.'">'.$langs->trans('AllBills').' ('.$num.')</td>';
+                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
     			print '</tr></table>';
     			print '</td></tr>';
 			}
@@ -370,13 +372,13 @@ if ( $societe->fetch($socid) )
 	if ($user->rights->fournisseur->commande->creer)
 	{
 		$langs->load("orders");
-		print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/fiche.php?action=create&socid='.$societe->id.'">'.$langs->trans("AddOrder").'</a>';
+		print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/fiche.php?action=create&socid='.$object->id.'">'.$langs->trans("AddOrder").'</a>';
 	}
 
 	if ($user->rights->fournisseur->facture->creer)
 	{
 		$langs->load("bills");
-		print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?action=create&socid='.$societe->id.'">'.$langs->trans("AddBill").'</a>';
+		print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a>';
 	}
 
     // Add action
@@ -384,7 +386,7 @@ if ( $societe->fetch($socid) )
     {
         if ($user->rights->agenda->myactions->create)
         {
-            print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&socid='.$societe->id.'">'.$langs->trans("AddAction").'</a>';
+            print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a>';
         }
         else
         {
@@ -404,16 +406,16 @@ if ( $societe->fetch($socid) )
     {
         print '<br>';
         // List of contacts
-        show_contacts($conf,$langs,$db,$societe,$_SERVER["PHP_SELF"].'?socid='.$societe->id);
+        show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?id='.$object->id);
     }
 
     if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
     {
         // List of todo actions
-        show_actions_todo($conf,$langs,$db,$societe);
+        show_actions_todo($conf,$langs,$db,$object);
 
         // List of done actions
-        show_actions_done($conf,$langs,$db,$societe);
+        show_actions_done($conf,$langs,$db,$object);
     }
 }
 else
diff --git a/htdocs/fourn/paiement/fiche.php b/htdocs/fourn/paiement/fiche.php
index 0f65dac448c..40c2639ff9b 100644
--- a/htdocs/fourn/paiement/fiche.php
+++ b/htdocs/fourn/paiement/fiche.php
@@ -35,9 +35,12 @@ $langs->load('companies');
 $langs->load("suppliers");
 
 $mesg='';
-$action=GETPOST('action');
-$id=GETPOST('id');
 
+$id			= GETPOST('id');
+$action		= GETPOST('action');
+$confirm	= GETPOST('confirm');
+
+$object = new PaiementFourn($db);
 
 /*
  * Actions
@@ -46,9 +49,9 @@ $id=GETPOST('id');
 if ($action == 'setnote' && $user->rights->fournisseur->facture->creer)
 {
     $db->begin();
-    $paiement = new PaiementFourn($db);
-    $paiement->fetch($id);
-    $result = $paiement->update_note(GETPOST('note'));
+    
+    $object->fetch($id);
+    $result = $object->update_note(GETPOST('note'));
     if ($result > 0)
     {
         $db->commit();
@@ -56,18 +59,17 @@ if ($action == 'setnote' && $user->rights->fournisseur->facture->creer)
     }
     else
     {
-        $mesg='<div class="error">'.$paiement->error.'</div>';
+        $mesg='<div class="error">'.$object->error.'</div>';
         $db->rollback();
     }
 }
 
-if ($action == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->facture->supprimer)
+if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer)
 {
 	$db->begin();
-
-	$paiement = new PaiementFourn($db);
-	$paiement->fetch($id);
-	$result = $paiement->delete();
+	
+	$object->fetch($id);
+	$result = $object->delete();
 	if ($result > 0)
 	{
 		$db->commit();
@@ -76,35 +78,33 @@ if ($action == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->
 	}
 	else
 	{
-		$mesg='<div class="error">'.$paiement->error.'</div>';
+		$mesg='<div class="error">'.$object->error.'</div>';
 		$db->rollback();
 	}
 }
 
-if ($action == 'confirm_valide' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->facture->valider)
+if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->fournisseur->facture->valider)
 {
 	$db->begin();
 
-	$paiement = new PaiementFourn($db);
-	$paiement->fetch($id);
-	if ($paiement->valide() >= 0)
+	$object->fetch($id);
+	if ($object->valide() >= 0)
 	{
 		$db->commit();
-		Header('Location: fiche.php?id='.$paiement->id);
+		Header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
 		exit;
 	}
 	else
 	{
-		$mesg='<div class="error">'.$paiement->error.'</div>';
+		$mesg='<div class="error">'.$object->error.'</div>';
 		$db->rollback();
 	}
 }
 
-if ($action == 'setnum' && !empty($_POST['num']))
+if ($action == 'setnum' && ! empty($_POST['num']))
 {
-	$paiement = new PaiementFourn($db);
-	$paiement->fetch($id);
-    $res = $paiement->update_num($_POST['num']);
+	$object->fetch($id);
+    $res = $object->update_num($_POST['num']);
 	if ($res === 0)
 	{
 		$mesg = '<div class="ok">'.$langs->trans('PaymentNumberUpdateSucceeded').'</div>';
@@ -115,12 +115,11 @@ if ($action == 'setnum' && !empty($_POST['num']))
 	}
 }
 
-if ($action == 'setdate' && !empty($_POST['dateday']))
+if ($action == 'setdate' && ! empty($_POST['dateday']))
 {
-	$paiement = new PaiementFourn($db);
-	$paiement->fetch($id);
+	$object->fetch($id);
     $datepaye = dol_mktime(12, 0, 0, $_POST['datemonth'], $_POST['dateday'], $_POST['dateyear']);
-	$res = $paiement->update_date($datepaye);
+	$res = $object->update_date($datepaye);
 	if ($res === 0)
 	{
 		$mesg = '<div class="ok">'.$langs->trans('PaymentDateUpdateSucceeded').'</div>';
@@ -154,8 +153,7 @@ $h++;
 
 dol_fiche_head($head, $hselected, $langs->trans('SupplierPayment'), 0, 'payment');
 
-$paiement = new PaiementFourn($db);
-$result=$paiement->fetch($id);
+$result=$object->fetch($id);
 if ($result > 0)
 {
 	/*
@@ -163,7 +161,7 @@ if ($result > 0)
 	 */
 	if ($action == 'delete')
 	{
-		$ret=$form->form_confirm('fiche.php?id='.$paiement->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete');
+		$ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete');
 		if ($ret == 'html') print '<br>';
 	}
 
@@ -172,48 +170,48 @@ if ($result > 0)
 	 */
 	if ($action == 'valide')
 	{
-		$ret=$form->form_confirm('fiche.php?id='.$paiement->id, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide');
+		$ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide');
 		if ($ret == 'html') print '<br>';
 	}
 
 	print '<table class="border" width="100%">';
 
 	print '<tr>';
-	print '<td valign="top" width="20%" colspan="2">'.$langs->trans('Ref').'</td><td colspan="3">'.$paiement->id.'</td></tr>';
+	print '<td valign="top" width="20%" colspan="2">'.$langs->trans('Ref').'</td><td colspan="3">'.$object->id.'</td></tr>';
 
 	// Date payment
-    print '<tr><td valign="top" colspan="2">'.$form->editfieldkey("Date",'date',$paiement->date,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
-    print $form->editfieldval("Date",'date',$paiement->date,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'day');
+    print '<tr><td valign="top" colspan="2">'.$form->editfieldkey("Date",'date',$object->date,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
+    print $form->editfieldval("Date",'date',$object->date,'id',$object->id,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'day');
     print '</td></tr>';
 
 	// Payment mode
-	print '<tr><td valign="top" colspan="2">'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$paiement->type_libelle.'</td></tr>';
+	print '<tr><td valign="top" colspan="2">'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$object->type_libelle.'</td></tr>';
 
 	// Payment numero
-    print '<tr><td valign="top" colspan="2">'.$form->editfieldkey("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
-    print $form->editfieldval("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'string');
+    print '<tr><td valign="top" colspan="2">'.$form->editfieldkey("Numero",'num',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
+    print $form->editfieldval("Numero",'num',$object->numero,'id',$object->id,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string');
     print '</td></tr>';
 
 	// Amount
-	print '<tr><td valign="top" colspan="2">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->montant).'&nbsp;'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
+	print '<tr><td valign="top" colspan="2">'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->montant).'&nbsp;'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
 
 	if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
 	{
-		print '<tr><td valign="top" colspan="2">'.$langs->trans('Status').'</td><td colspan="3">'.$paiement->getLibStatut(4).'</td></tr>';
+		print '<tr><td valign="top" colspan="2">'.$langs->trans('Status').'</td><td colspan="3">'.$object->getLibStatut(4).'</td></tr>';
 	}
 
 	// Note
-    print '<tr><td valign="top"" colspan="2">'.$form->editfieldkey("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
-    print $form->editfieldval("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->fournisseur->facture->creer,'text');
+    print '<tr><td valign="top"" colspan="2">'.$form->editfieldkey("Note",'note',$object->note,$object,$user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
+    print $form->editfieldval("Note",'note',$object->note,'id',$object->id,$user->rights->fournisseur->facture->creer,'text');
     print '</td></tr>';
 
     // Bank account
 	if ($conf->banque->enabled)
 	{
-		if ($paiement->bank_account)
+		if ($object->bank_account)
 		{
             $bankline=new AccountLine($db);
-            $bankline->fetch($paiement->bank_line);
+            $bankline->fetch($object->bank_line);
 
             print '<tr>';
             print '<td colspan="2">'.$langs->trans('BankTransactionLine').'</td>';
@@ -237,7 +235,7 @@ if ($result > 0)
 	$sql = 'SELECT f.rowid as ref, f.facnumber as ref_supplier, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom, s.rowid as socid';
 	$sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
 	$sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
-	$sql .= ' AND pf.fk_paiementfourn = '.$paiement->id;
+	$sql .= ' AND pf.fk_paiementfourn = '.$object->id;
 	$resql=$db->query($sql);
 	if ($resql)
 	{
@@ -310,20 +308,20 @@ if ($result > 0)
 	print '<div class="tabsAction">';
 	if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
 	{
-		if ($user->societe_id == 0 && $paiement->statut == 0 && $_GET['action'] == '')
+		if ($user->societe_id == 0 && $object->statut == 0 && $action == '')
 		{
 			if ($user->rights->fournisseur->facture->valider)
 			{
-				print '<a class="butAction" href="fiche.php?id='.$_GET['id'].'&amp;action=valide">'.$langs->trans('Valid').'</a>';
+				print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
 
 			}
 		}
 	}
-	if ($user->societe_id == 0 && $allow_delete && $paiement->statut == 0 && $_GET['action'] == '')
+	if ($user->societe_id == 0 && $allow_delete && $object->statut == 0 && $action == '')
 	{
 		if ($user->rights->fournisseur->facture->supprimer)
 		{
-			print '<a class="butActionDelete" href="fiche.php?id='.$_GET['id'].'&amp;action=delete">'.$langs->trans('Delete').'</a>';
+			print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
 
 		}
 	}
diff --git a/htdocs/product/canvas/product/actions_card_product.class.php b/htdocs/product/canvas/product/actions_card_product.class.php
index 6e66d669474..675285fe2c0 100755
--- a/htdocs/product/canvas/product/actions_card_product.class.php
+++ b/htdocs/product/canvas/product/actions_card_product.class.php
@@ -148,12 +148,12 @@ class ActionsCardProduct extends Product
             $this->tpl['showend']=dol_get_fiche_end();
 
             // Accountancy buy code
-			$this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodesell',$this->accountancy_code_sell,'id',$this->id,$user->rights->produit->creer);
-			$this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode",'productaccountancycodesell',$this->accountancy_code_sell,'id',$this->id,$user->rights->produit->creer);
+			$this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodesell',$this->accountancy_code_sell,$this,$user->rights->produit->creer);
+			$this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode",'productaccountancycodesell',$this->accountancy_code_sell,$this,$user->rights->produit->creer);
 
 			// Accountancy sell code
-			$this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode",'productaccountancycodebuy',$this->accountancy_code_buy,'id',$this->id,$user->rights->produit->creer);
-			$this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode",'productaccountancycodebuy',$this->accountancy_code_buy,'id',$this->id,$user->rights->produit->creer);
+			$this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode",'productaccountancycodebuy',$this->accountancy_code_buy,$this,$user->rights->produit->creer);
+			$this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode",'productaccountancycodebuy',$this->accountancy_code_buy,$this,$user->rights->produit->creer);
 		}
 
 		$this->tpl['finished'] = $this->object->finished;
diff --git a/htdocs/product/canvas/service/actions_card_service.class.php b/htdocs/product/canvas/service/actions_card_service.class.php
index 79dd098844a..f43399e4670 100755
--- a/htdocs/product/canvas/service/actions_card_service.class.php
+++ b/htdocs/product/canvas/service/actions_card_service.class.php
@@ -147,12 +147,12 @@ class ActionsCardService extends Product
             $this->tpl['showend']=dol_get_fiche_end();
 
 			// Accountancy buy code
-			$this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodesell',$this->accountancy_code_sell,'id',$this->id,$user->rights->produit->creer);
-			$this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode",'productaccountancycodesell',$this->accountancy_code_sell,'id',$this->id,$user->rights->produit->creer);
+			$this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodesell',$this->accountancy_code_sell,$this,$user->rights->produit->creer);
+			$this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode",'productaccountancycodesell',$this->accountancy_code_sell,$this,$user->rights->produit->creer);
 
 			// Accountancy sell code
-			$this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode",'productaccountancycodebuy',$this->accountancy_code_buy,'id',$this->id,$user->rights->produit->creer);
-			$this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode",'productaccountancycodebuy',$this->accountancy_code_buy,'id',$this->id,$user->rights->produit->creer);
+			$this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode",'productaccountancycodebuy',$this->accountancy_code_buy,$this,$user->rights->produit->creer);
+			$this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode",'productaccountancycodebuy',$this->accountancy_code_buy,$this,$user->rights->produit->creer);
 		}
 
 		$this->tpl['finished'] = $this->object->finished;
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index c3d176b71eb..c03a5a5acec 100644
--- a/htdocs/product/fiche.php
+++ b/htdocs/product/fiche.php
@@ -1012,13 +1012,13 @@ else
             print '</tr>';
 
             // Accountancy sell code
-            print '<tr><td>'.$form->editfieldkey("ProductAccountancySellCode",'productaccountancycodesell',$object->accountancy_code_sell,'id',$object->id,$user->rights->produit->creer).'</td><td colspan="2">';
-            print $form->editfieldval("ProductAccountancySellCode",'productaccountancycodesell',$object->accountancy_code_sell,'id',$object->id,$user->rights->produit->creer);
+            print '<tr><td>'.$form->editfieldkey("ProductAccountancySellCode",'productaccountancycodesell',$object->accountancy_code_sell,$object,$user->rights->produit->creer).'</td><td colspan="2">';
+            print $form->editfieldval("ProductAccountancySellCode",'productaccountancycodesell',$object->accountancy_code_sell,$object,$user->rights->produit->creer);
             print '</td></tr>';
 
             // Accountancy buy code
-            print '<tr><td>'.$form->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodebuy',$object->accountancy_code_buy,'id',$object->id,$user->rights->produit->creer).'</td><td colspan="2">';
-            print $form->editfieldval("ProductAccountancyBuyCode",'productaccountancycodebuy',$object->accountancy_code_buy,'id',$object->id,$user->rights->produit->creer);
+            print '<tr><td>'.$form->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodebuy',$object->accountancy_code_buy,$object,$user->rights->produit->creer).'</td><td colspan="2">';
+            print $form->editfieldval("ProductAccountancyBuyCode",'productaccountancycodebuy',$object->accountancy_code_buy,$object,$user->rights->produit->creer);
             print '</td></tr>';
 
             // Status (to sell)
diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php
index 549d06c8e1e..873c27b1ff2 100644
--- a/htdocs/product/stock/product.php
+++ b/htdocs/product/stock/product.php
@@ -277,8 +277,8 @@ if ($_GET["id"] || $_GET["ref"])
 		}
 
         // Stock
-        print '<tr><td>'.$form->editfieldkey("StockLimit",'stocklimit',$product->seuil_stock_alerte,'id',$product->id,$user->rights->produit->creer).'</td><td colspan="2">';
-        print $form->editfieldval("StockLimit",'stocklimit',$product->seuil_stock_alerte,'id',$product->id,$user->rights->produit->creer);
+        print '<tr><td>'.$form->editfieldkey("StockLimit",'stocklimit',$product->seuil_stock_alerte,$product,$user->rights->produit->creer).'</td><td colspan="2">';
+        print $form->editfieldval("StockLimit",'stocklimit',$product->seuil_stock_alerte,$product,$user->rights->produit->creer);
         print '</td></tr>';
 
 		// Last movement
-- 
GitLab