diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php
index 2a225234af63b35919b2662e65acec49b9276d7b..47b16c11e49f4a9c1d42a1b85226f4ac9b1ce58d 100644
--- a/htdocs/admin/commande.php
+++ b/htdocs/admin/commande.php
@@ -8,6 +8,7 @@
  * Copyright (C) 2008 	   Raphael Bertrand (Resultic)  <raphael.bertrand@resultic.fr>
  * Copyright (C) 2011-2012 Juanjo Menent			    <jmenent@2byte.es>
  * Copyright (C) 2011-2013 Philippe Grand			    <philippe.grand@atoo-net.com>
+ * Copyright (C) 2013 	   Florian Henry			    <florian.henry@open-concept.pro>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,6 +33,7 @@
 require '../main.inc.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
 
 $langs->load("admin");
 $langs->load("errors");
@@ -202,15 +204,9 @@ $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToM
 print_fiche_titre($langs->trans("OrdersSetup"),$linkback,'setup');
 print '<br>';
 
-$h = 0;
+$head = order_admin_prepare_head(null);
 
-$head[$h][0] = DOL_URL_ROOT."/admin/commande.php";
-$head[$h][1] = $langs->trans("Orders");
-$head[$h][2] = 'Order';
-$hselected=$h;
-$h++;
-
-dol_fiche_head($head, $hselected, $langs->trans("ModuleSetup"));
+dol_fiche_head($head, 'general', $langs->trans("ModuleSetup"), 0, 'order');
 
 /*
  * Orders Numbering model
diff --git a/htdocs/admin/order_extrafields.php b/htdocs/admin/order_extrafields.php
new file mode 100644
index 0000000000000000000000000000000000000000..5d740593a5fbe557d1f226673348158df9eaec1a
--- /dev/null
+++ b/htdocs/admin/order_extrafields.php
@@ -0,0 +1,157 @@
+<?php
+/* Copyright (C) 2001-2002	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
+ * Copyright (C) 2003		Jean-Louis Bergamo		<jlb@j1b.org>
+ * Copyright (C) 2004-2013	Laurent Destailleur		<eldy@users.sourceforge.net>
+ * Copyright (C) 2012		Regis Houssin			<regis.houssin@capnetworks.com>
+ * Copyright (C) 2012		Florian Henry			<florian.henry@open-concept.pro>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ *      \file       htdocs/admin/agenda_extrafields.php
+ *		\ingroup    agenda
+ *		\brief      Page to setup extra fields of agenda
+ */
+
+require '../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+
+
+if (!$user->admin)
+	accessforbidden();
+
+$langs->load("admin");
+$langs->load("other");
+
+$extrafields = new ExtraFields($db);
+$form = new Form($db);
+
+// List of supported format
+$tmptype2label=getStaticMember(get_class($extrafields),'type2label');
+$type2label=array('');
+foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val);
+
+$action=GETPOST('action', 'alpha');
+$attrname=GETPOST('attrname', 'alpha');
+$elementtype='commande';
+
+if (!$user->admin) accessforbidden();
+
+
+/*
+ * Actions
+ */
+
+require DOL_DOCUMENT_ROOT.'/core/admin_extrafields.inc.php';
+
+
+
+/*
+ * View
+ */
+
+
+llxHeader();
+
+$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
+print_fiche_titre($langs->trans("AgendaSetup"),$linkback,'setup');
+print "<br>\n";
+
+$head = order_admin_prepare_head(null);
+
+dol_fiche_head($head, 'attributes', $langs->trans("ModuleSetup"), 0, 'order');
+
+
+print $langs->trans("DefineHereComplementaryAttributes",$textobject).'<br>'."\n";
+print '<br>';
+
+// Load attribute_label
+$extrafields->fetch_name_optionals_label($elementtype);
+
+print "<table summary=\"listofattributes\" class=\"noborder\" width=\"100%\">";
+
+print '<tr class="liste_titre">';
+print '<td>'.$langs->trans("Label").'</td>';
+print '<td>'.$langs->trans("AttributeCode").'</td>';
+print '<td>'.$langs->trans("Type").'</td>';
+print '<td align="right">'.$langs->trans("Size").'</td>';
+print '<td align="center">'.$langs->trans("Unique").'</td>';
+print '<td align="center">'.$langs->trans("Required").'</td>';
+print '<td width="80">&nbsp;</td>';
+print "</tr>\n";
+
+$var=True;
+foreach($extrafields->attribute_type as $key => $value)
+{
+    $var=!$var;
+    print "<tr ".$bc[$var].">";
+    print "<td>".$extrafields->attribute_label[$key]."</td>\n";
+    print "<td>".$key."</td>\n";
+    print "<td>".$type2label[$extrafields->attribute_type[$key]]."</td>\n";
+    print '<td align="right">'.$extrafields->attribute_size[$key]."</td>\n";
+    print '<td align="center">'.yn($extrafields->attribute_unique[$key])."</td>\n";
+    print '<td align="center">'.yn($extrafields->attribute_required[$key])."</td>\n";
+    print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit&attrname='.$key.'">'.img_edit().'</a>';
+    print "&nbsp; <a href=\"".$_SERVER["PHP_SELF"]."?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
+    print "</tr>";
+    //      $i++;
+}
+
+print "</table>";
+
+dol_fiche_end();
+
+
+// Buttons
+if ($action != 'create' && $action != 'edit')
+{
+    print '<div class="tabsAction">';
+    print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create\">".$langs->trans("NewAttribute")."</a>";
+    print "</div>";
+}
+
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Creation d'un champ optionnel
+ /*                                                                            */
+/* ************************************************************************** */
+
+if ($action == 'create')
+{
+    print "<br>";
+    print_titre($langs->trans('NewAttribute'));
+
+    require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
+}
+
+/* ************************************************************************** */
+/*                                                                            */
+/* Edition d'un champ optionnel                                               */
+/*                                                                            */
+/* ************************************************************************** */
+if ($action == 'edit' && ! empty($attrname))
+{
+    print "<br>";
+    print_titre($langs->trans("FieldEdition", $attrname));
+
+    require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
+}
+
+llxFooter();
+
+$db->close();
+?>
\ No newline at end of file
diff --git a/htdocs/admin/supplier_invoice.php b/htdocs/admin/supplier_invoice.php
index 079d0c5c9150ef3c60c820f5ece478fc5061f186..a5331bca70c045d0d4dc9087f62f004beb71e609 100644
--- a/htdocs/admin/supplier_invoice.php
+++ b/htdocs/admin/supplier_invoice.php
@@ -330,7 +330,7 @@ $def = array();
 
 $sql = "SELECT nom";
 $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
-$sql.= " WHERE type = 'order_supplier'";
+$sql.= " WHERE type = 'invoice_supplier'";
 $sql.= " AND entity = ".$conf->entity;
 
 $resql=$db->query($sql);
@@ -409,7 +409,7 @@ foreach ($dirmodels as $reldir)
                     else
                     {
                         print '<td align="center">'."\n";
-                        print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=order_supplier">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
+                        print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=invoice_supplier">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
                         print "</td>";
                     }
 
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 493f34c3962455e7a82a50b8a648c03a2d032e05..47f18b8e5e86af830210ebbd9495297a8db05ee5 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -598,7 +598,7 @@ class Commande extends CommonOrder
      */
     function create($user, $notrigger=0)
     {
-        global $conf,$langs,$mysoc;
+        global $conf,$langs,$mysoc,$hookmanager;
         $error=0;
 
         // Clean parameters
@@ -760,6 +760,27 @@ class Commande extends CommonOrder
                         	}
                         }
                     }
+                    
+                    if (! $error)
+                    {
+	                    // Actions on extra fields (by external module or standard code)
+	                    // FIXME le hook fait double emploi avec le trigger !!
+	                    $hookmanager->initHooks(array('orderdao'));
+	                    $parameters=array('socid'=>$this->id);
+	                    $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
+	                    if (empty($reshook))
+	                    {
+	                    	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+	                    	{
+	                    		$result=$this->insertExtraFields();
+	                    		if ($result < 0)
+	                    		{
+	                    			$error++;
+	                    		}
+	                    	}
+	                    }
+	                    else if ($reshook < 0) $error++;
+                    }
 
                     if (! $notrigger)
                     {
@@ -2756,6 +2777,44 @@ class Commande extends CommonOrder
             return -1;
         }
     }
+    
+    /**
+     *	Update value of extrafields on the proposal
+     *
+     *	@param      User	$user       Object user that modify
+     *	@param      double	$remise      Amount discount
+     *	@return     int         		<0 if ko, >0 if ok
+     */
+    function update_extrafields($user)
+    {
+    	// Actions on extra fields (by external module or standard code)
+    	// FIXME le hook fait double emploi avec le trigger !!
+    	$hookmanager->initHooks(array('orderdao'));
+    	$parameters=array('id'=>$this->id);
+    	$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
+    	if (empty($reshook))
+    	{
+    		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+    		{
+    			$result=$this->insertExtraFields();
+    			if ($result < 0)
+    			{
+    				$error++;
+    			}
+    		}
+    	}
+    	else if ($reshook < 0) $error++;
+    	 
+    	if (!$error)
+    	{
+    		return 1;
+    	}
+    	else
+    	{
+    		return -1;
+    	}
+    	 
+    }
 
     /**
      * 	Return an array of order lines
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index ff08d7c96861435d57a838862898ea9b3cc772fe..455eb698722605c58c08df6c4257fbb3d8dca7ae 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -1,33 +1,34 @@
 <?php
 /* Copyright (C) 2003-2006 Rodolphe Quiedeville  <rodolphe@quiedeville.org>
  * Copyright (C) 2004-2013 Laurent Destailleur   <eldy@users.sourceforge.net>
- * Copyright (C) 2005      Marc Barilley / Ocebo <marc@ocebo.com>
- * Copyright (C) 2005-2012 Regis Houssin         <regis.houssin@capnetworks.com>
- * Copyright (C) 2006      Andre Cianfarani      <acianfa@free.fr>
- * Copyright (C) 2010-2013 Juanjo Menent         <jmenent@2byte.es>
- * Copyright (C) 2011      Philippe Grand        <philippe.grand@atoo-net.com>
- * Copyright (C) 2012      Christophe Battarel   <christophe.battarel@altairis.fr>
- * Copyright (C) 2012      Marcos García         <marcosgdf@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
+* Copyright (C) 2005      Marc Barilley / Ocebo <marc@ocebo.com>
+* Copyright (C) 2005-2012 Regis Houssin         <regis.houssin@capnetworks.com>
+* Copyright (C) 2006      Andre Cianfarani      <acianfa@free.fr>
+* Copyright (C) 2010-2013 Juanjo Menent         <jmenent@2byte.es>
+* Copyright (C) 2011      Philippe Grand        <philippe.grand@atoo-net.com>
+* Copyright (C) 2012      Christophe Battarel   <christophe.battarel@altairis.fr>
+* Copyright (C) 2012      Marcos García         <marcosgdf@gmail.com>
+* Copyright (C) 2013      Florian Henry         <florian.henry@open-concept.pro>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
 
 /**
  *	\file       htdocs/commande/fiche.php
- *	\ingroup    commande
- *	\brief      Page to show customer order
- */
+*	\ingroup    commande
+*	\brief      Page to show customer order
+*/
 
 require '../main.inc.php';
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
@@ -37,6 +38,7 @@ require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
 if (! empty($conf->propal->enabled))
 	require DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
 if (! empty($conf->projet->enabled)) {
@@ -75,6 +77,11 @@ if (! empty($user->societe_id)) $socid=$user->societe_id;
 $result=restrictedArea($user,'commande',$id);
 
 $object = new Commande($db);
+$extrafields = new ExtraFields($db);
+
+
+// fetch optionals attributes and labels
+$extralabels=$extrafields->fetch_name_optionals_label('commande');
 
 // Load object
 if ($id > 0 || ! empty($ref))
@@ -264,6 +271,9 @@ else if ($action == 'add' && $user->rights->commande->creer)
 			{
 				$object->linked_objects = array_merge($object->linked_objects, $other_linked_objects);
 			}
+				
+			// Fill array 'array_options' with data from add form
+			$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
 
 			$object_id = $object->create($user);
 
@@ -360,6 +370,9 @@ else if ($action == 'add' && $user->rights->commande->creer)
 		}
 		else
 		{
+			// Fill array 'array_options' with data from add form
+			$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+				
 			$object_id = $object->create($user);
 
 			// If some invoice's lines already known
@@ -545,14 +558,14 @@ else if ($action == 'addline' && $user->rights->commande->creer)
 	$tva_tx = (GETPOST('tva_tx')?GETPOST('tva_tx'):0);
 
 	if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && (GETPOST('qty') < 0))
-    {
-        setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors');
-        $error = true;
-    }
+	{
+		setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), 'errors');
+		$error = true;
+	}
 	if (empty($idprod) && GETPOST('type') < 0)
 	{
 		setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
-        $error = true;
+		$error = true;
 	}
 	if ((empty($idprod) || GETPOST('usenewaddlineform')) && (!($price_ht >= 0) || $price_ht == ''))	// Unit price can be 0 but not ''
 	{
@@ -560,15 +573,15 @@ else if ($action == 'addline' && $user->rights->commande->creer)
 		$error++;
 	}
 	if (! GETPOST('qty') && GETPOST('qty') == '')
-    {
-        setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
-        $error = true;
-    }
-    if (empty($idprod) && empty($product_desc))
-    {
-        setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
-        $error = true;
-    }
+	{
+		setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
+		$error = true;
+	}
+	if (empty($idprod) && empty($product_desc))
+	{
+		setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
+		$error = true;
+	}
 
 	if (! $error && (GETPOST('qty') >= 0) && (! empty($product_desc) || ! empty($idprod)))
 	{
@@ -655,18 +668,18 @@ else if ($action == 'addline' && $user->rights->commande->creer)
 					$desc = $prod->description;
 				}
 
-            	$desc=dol_concatdesc($desc,$product_desc);
-
-            	// Add custom code and origin country into description
-            	if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code)))
-            	{
-            		$tmptxt='(';
-            		if (! empty($prod->customcode)) $tmptxt.=$langs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode;
-            		if (! empty($prod->customcode) && ! empty($prod->country_code)) $tmptxt.=' - ';
-            		if (! empty($prod->country_code)) $tmptxt.=$langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code,0,$db,$langs,0);
-            		$tmptxt.=')';
-            		$desc= dol_concatdesc($desc, $tmptxt);
-            	}
+				$desc=dol_concatdesc($desc,$product_desc);
+
+				// Add custom code and origin country into description
+				if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code)))
+				{
+					$tmptxt='(';
+					if (! empty($prod->customcode)) $tmptxt.=$langs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode;
+					if (! empty($prod->customcode) && ! empty($prod->country_code)) $tmptxt.=' - ';
+					if (! empty($prod->country_code)) $tmptxt.=$langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code,0,$db,$langs,0);
+					$tmptxt.=')';
+					$desc= dol_concatdesc($desc, $tmptxt);
+				}
 			}
 
 			$type = $prod->type;
@@ -704,28 +717,28 @@ else if ($action == 'addline' && $user->rights->commande->creer)
 		{
 			// Insert line
 			$result = $object->addline(
-					$object->id,
-					$desc,
-					$pu_ht,
-					GETPOST('qty'),
-					$tva_tx,
-					$localtax1_tx,
-					$localtax2_tx,
-					$idprod,
-					GETPOST('remise_percent'),
-					$info_bits,
-					0,
-					$price_base_type,
-					$pu_ttc,
-					$date_start,
-					$date_end,
-					$type,
-					-1,
-					0,
-					GETPOST('fk_parent_line'),
-					$fournprice,
-					$buyingprice,
-					$label
+				$object->id,
+				$desc,
+				$pu_ht,
+				GETPOST('qty'),
+				$tva_tx,
+				$localtax1_tx,
+				$localtax2_tx,
+				$idprod,
+				GETPOST('remise_percent'),
+				$info_bits,
+				0,
+				$price_base_type,
+				$pu_ttc,
+				$date_start,
+				$date_end,
+				$type,
+				-1,
+				0,
+				GETPOST('fk_parent_line'),
+				$fournprice,
+				$buyingprice,
+				$label
 			);
 
 			if ($result > 0)
@@ -835,24 +848,24 @@ else if ($action == 'updateligne' && $user->rights->commande->creer && GETPOST('
 	if (! $error)
 	{
 		$result = $object->updateline(
-				GETPOST('lineid'),
-				$description,
-				$pu_ht,
-				GETPOST('qty'),
-				GETPOST('remise_percent'),
-				$vat_rate,
-				$localtax1_rate,
-				$localtax2_rate,
-				'HT',
-				$info_bits,
-				$date_start,
-				$date_end,
-				$type,
-				GETPOST('fk_parent_line'),
-				0,
-				$fournprice,
-				$buyingprice,
-				$label
+			GETPOST('lineid'),
+			$description,
+			$pu_ht,
+			GETPOST('qty'),
+			GETPOST('remise_percent'),
+			$vat_rate,
+			$localtax1_rate,
+			$localtax2_rate,
+			'HT',
+			$info_bits,
+			$date_start,
+			$date_end,
+			$type,
+			GETPOST('fk_parent_line'),
+			0,
+			$fournprice,
+			$buyingprice,
+			$label
 		);
 
 		if ($result >= 0)
@@ -1105,11 +1118,37 @@ else if ($action == 'remove_file')
 // Print file
 else if ($action == 'print_file' AND $user->rights->printipp->use)
 {
-    require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php';
-    $printer = new dolPrintIPP($db,$conf->global->PRINTIPP_HOST,$conf->global->PRINTIPP_PORT,$user->login,$conf->global->PRINTIPP_USER,$conf->global->PRINTIPP_PASSWORD);
+	require_once DOL_DOCUMENT_ROOT.'/core/class/dolprintipp.class.php';
+	$printer = new dolPrintIPP($db,$conf->global->PRINTIPP_HOST,$conf->global->PRINTIPP_PORT,$user->login,$conf->global->PRINTIPP_USER,$conf->global->PRINTIPP_PASSWORD);
     $printer->print_file(GETPOST('file','alpha'),GETPOST('printer','alpha'));
 }
 
+else if ($action == 'update_extras')
+{
+	// Fill array 'array_options' with data from update form
+	$extralabels=$extrafields->fetch_name_optionals_label('commande');
+	$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+
+	// Actions on extra fields (by external module or standard code)
+	// FIXME le hook fait double emploi avec le trigger !!
+	$hookmanager->initHooks(array('orderdao'));
+	$parameters=array('id'=>$object->id);
+	$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
+	if (empty($reshook))
+	{
+		if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+		{
+			$result=$object->insertExtraFields();
+			if ($result < 0)
+			{
+				$error++;
+			}
+		}
+	}
+	else if ($reshook < 0) $error++;
+
+}
+
 /*
  * Add file in email form
 */
@@ -1154,7 +1193,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
 		//        $file = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
 
 		//        if (is_readable($file))
-			//        {
+		//        {
 		if (GETPOST('sendto'))
 		{
 			// Le destinataire a ete fourni via le champ libre
@@ -1286,1200 +1325,1258 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
 			$mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
 			dol_syslog('Failed to read file: '.$file);
 		}
-			}
-			else
-			{
-				$langs->load("other");
-				$mesg='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Order")).'</div>';
-				dol_syslog($langs->trans('ErrorFailedToReadEntity', $langs->trans("Order")));
-			}
 	}
+	else
+	{
+		$langs->load("other");
+		$mesg='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Order")).'</div>';
+		dol_syslog($langs->trans('ErrorFailedToReadEntity', $langs->trans("Order")));
+	}
+}
 
-	if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->commande->creer)
+if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->commande->creer)
+{
+	if ($action == 'addcontact')
 	{
-		if ($action == 'addcontact')
+		if ($object->id > 0)
 		{
-			if ($object->id > 0)
-			{
-				$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
-				$result = $object->add_contact($contactid, GETPOST('type'), GETPOST('source'));
-			}
-
-			if ($result >= 0)
-			{
-				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
-				exit;
-			}
-			else
-			{
-				if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
-				{
-					$langs->load("errors");
-					$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
-				}
-				else
-				{
-					$mesg = '<div class="error">'.$object->error.'</div>';
-				}
-			}
+			$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
+			$result = $object->add_contact($contactid, GETPOST('type'), GETPOST('source'));
 		}
 
-		// bascule du statut d'un contact
-		else if ($action == 'swapstatut')
+		if ($result >= 0)
+		{
+			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+			exit;
+		}
+		else
 		{
-			if ($object->id > 0)
+			if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 			{
-				$result=$object->swapContactStatus(GETPOST('ligne'));
+				$langs->load("errors");
+				$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
 			}
 			else
 			{
-				dol_print_error($db);
+				$mesg = '<div class="error">'.$object->error.'</div>';
 			}
 		}
+	}
 
-		// Efface un contact
-		else if ($action == 'deletecontact')
+	// bascule du statut d'un contact
+	else if ($action == 'swapstatut')
+	{
+		if ($object->id > 0)
 		{
-			$result = $object->delete_contact($lineid);
-
-			if ($result >= 0)
-			{
-				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
-				exit;
-			}
-			else {
-				dol_print_error($db);
-			}
+			$result=$object->swapContactStatus(GETPOST('ligne'));
+		}
+		else
+		{
+			dol_print_error($db);
 		}
 	}
 
+	// Efface un contact
+	else if ($action == 'deletecontact')
+	{
+		$result = $object->delete_contact($lineid);
 
-	/*
-	 *	View
-	*/
+		if ($result >= 0)
+		{
+			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+			exit;
+		}
+		else {
+			dol_print_error($db);
+		}
+	}
+}
 
-	llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
 
-	$form = new Form($db);
-	$formfile = new FormFile($db);
-	$formorder = new FormOrder($db);
+/*
+ *	View
+*/
 
+llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
 
-	/*********************************************************************
-	 *
-	* Mode creation
-	*
-	*********************************************************************/
-	if ($action == 'create' && $user->rights->commande->creer)
-	{
-		//WYSIWYG Editor
-		require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
+$form = new Form($db);
+$formfile = new FormFile($db);
+$formorder = new FormOrder($db);
 
-		print_fiche_titre($langs->trans('CreateOrder'));
 
-		dol_htmloutput_mesg($mesg,$mesgs,'error');
+/*********************************************************************
+ *
+* Mode creation
+*
+*********************************************************************/
+if ($action == 'create' && $user->rights->commande->creer)
+{
+	//WYSIWYG Editor
+	require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
 
-		$soc = new Societe($db);
-		if ($socid>0) $res=$soc->fetch($socid);
+	print_fiche_titre($langs->trans('CreateOrder'));
 
-		if (! empty($origin) && ! empty($originid))
-		{
-			// Parse element/subelement (ex: project_task)
-			$element = $subelement = $origin;
-			if (preg_match('/^([^_]+)_([^_]+)/i',$origin,$regs))
-			{
-				$element = $regs[1];
-				$subelement = $regs[2];
-			}
+	dol_htmloutput_mesg($mesg,$mesgs,'error');
 
-			if ($element == 'project')
-			{
-				$projectid=$originid;
-			}
-			else
-			{
-				// For compatibility
-				if ($element == 'order' || $element == 'commande')    {
-					$element = $subelement = 'commande';
-				}
-				if ($element == 'propal')   {
-					$element = 'comm/propal'; $subelement = 'propal';
-				}
-				if ($element == 'contract') {
-					$element = $subelement = 'contrat';
-				}
+	$soc = new Societe($db);
+	if ($socid>0) $res=$soc->fetch($socid);
 
-				dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
+	if (! empty($origin) && ! empty($originid))
+	{
+		// Parse element/subelement (ex: project_task)
+		$element = $subelement = $origin;
+		if (preg_match('/^([^_]+)_([^_]+)/i',$origin,$regs))
+		{
+			$element = $regs[1];
+			$subelement = $regs[2];
+		}
 
-				$classname = ucfirst($subelement);
-				$objectsrc = new $classname($db);
-				$objectsrc->fetch($originid);
-				if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines'))  $objectsrc->fetch_lines();
-				$objectsrc->fetch_thirdparty();
-
-				$projectid          = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:'');
-				$ref_client         = (!empty($objectsrc->ref_client)?$objectsrc->ref_client:'');
-
-				$soc = $objectsrc->client;
-				$cond_reglement_id	= (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
-				$mode_reglement_id	= (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
-				$availability_id	= (!empty($objectsrc->availability_id)?$objectsrc->availability_id:(!empty($soc->availability_id)?$soc->availability_id:0));
-				$demand_reason_id	= (!empty($objectsrc->demand_reason_id)?$objectsrc->demand_reason_id:(!empty($soc->demand_reason_id)?$soc->demand_reason_id:0));
-				$remise_percent		= (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0));
-				$remise_absolue		= (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0));
-				$dateinvoice		= empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
-
-				$datedelivery		= (!empty($objectsrc->date_livraison)?$objectsrc->date_livraison:'');
-
-				$note_private		= (! empty($objectsrc->note) ? $objectsrc->note : (! empty($objectsrc->note_private) ? $objectsrc->note_private : ''));
-				$note_public		= (! empty($objectsrc->note_public) ? $objectsrc->note_public : '');
-
-				// Object source contacts list
-				$srccontactslist = $objectsrc->liste_contact(-1,'external',1);
-			}
+		if ($element == 'project')
+		{
+			$projectid=$originid;
 		}
 		else
 		{
-			$cond_reglement_id  = $soc->cond_reglement_id;
-			$mode_reglement_id  = $soc->mode_reglement_id;
-			$availability_id    = $soc->availability_id;
-			$demand_reason_id   = $soc->demand_reason_id;
-			$remise_percent     = $soc->remise_percent;
-			$remise_absolue     = 0;
-			$dateinvoice        = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
-			$projectid          = 0;
-		}
-		$absolute_discount=$soc->getAvailableDiscounts();
-
+			// For compatibility
+			if ($element == 'order' || $element == 'commande')    {
+				$element = $subelement = 'commande';
+			}
+			if ($element == 'propal')   {
+				$element = 'comm/propal'; $subelement = 'propal';
+			}
+			if ($element == 'contract') {
+				$element = $subelement = 'contrat';
+			}
 
+			dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
 
-		$nbrow=10;
+			$classname = ucfirst($subelement);
+			$objectsrc = new $classname($db);
+			$objectsrc->fetch($originid);
+			if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines'))  $objectsrc->fetch_lines();
+			$objectsrc->fetch_thirdparty();
 
-		print '<form name="crea_commande" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
-		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-		print '<input type="hidden" name="action" value="add">';
-		print '<input type="hidden" name="socid" value="'.$soc->id.'">' ."\n";
-		print '<input type="hidden" name="remise_percent" value="'.$soc->remise_client.'">';
-		print '<input type="hidden" name="origin" value="'.$origin.'">';
-		print '<input type="hidden" name="originid" value="'.$originid.'">';
+			$projectid          = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:'');
+			$ref_client         = (!empty($objectsrc->ref_client)?$objectsrc->ref_client:'');
 
-		print '<table class="border" width="100%">';
+			$soc = $objectsrc->client;
+			$cond_reglement_id	= (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
+			$mode_reglement_id	= (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
+			$availability_id	= (!empty($objectsrc->availability_id)?$objectsrc->availability_id:(!empty($soc->availability_id)?$soc->availability_id:0));
+			$demand_reason_id	= (!empty($objectsrc->demand_reason_id)?$objectsrc->demand_reason_id:(!empty($soc->demand_reason_id)?$soc->demand_reason_id:0));
+			$remise_percent		= (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0));
+			$remise_absolue		= (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0));
+			$dateinvoice		= empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
 
-		// Reference
-		print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans("Draft").'</td></tr>';
+			$datedelivery		= (!empty($objectsrc->date_livraison)?$objectsrc->date_livraison:'');
 
-		// Reference client
-		print '<tr><td>'.$langs->trans('RefCustomer').'</td><td colspan="2">';
-		//print '<input type="text" name="ref_client" value="'.$ref_client.'"></td>';
-		print '<input type="text" name="ref_client" value=""></td>';	// We must not use ref_client of proposal for an order
-		print '</tr>';
+			$note_private		= (! empty($objectsrc->note) ? $objectsrc->note : (! empty($objectsrc->note_private) ? $objectsrc->note_private : ''));
+			$note_public		= (! empty($objectsrc->note_public) ? $objectsrc->note_public : '');
 
-		// Client
-		print '<tr>';
-		print '<td class="fieldrequired">'.$langs->trans('Customer').'</td>';
-		if($socid>0)
-		{
-			print '<td colspan="2">';
-			print $soc->getNomUrl(1);
-			print '<input type="hidden" name="socid" value="'.$soc->id.'">';
-			print '</td>';
-		}
-		else
-		{
-			print '<td colspan="2">';
-			print $form->select_company('','socid','s.client = 1 OR s.client = 3',1);
-			print '</td>';
+			// Object source contacts list
+			$srccontactslist = $objectsrc->liste_contact(-1,'external',1);
 		}
-		print '</tr>'."\n";
+	}
+	else
+	{
+		$cond_reglement_id  = $soc->cond_reglement_id;
+		$mode_reglement_id  = $soc->mode_reglement_id;
+		$availability_id    = $soc->availability_id;
+		$demand_reason_id   = $soc->demand_reason_id;
+		$remise_percent     = $soc->remise_percent;
+		$remise_absolue     = 0;
+		$dateinvoice        = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
+		$projectid          = 0;
+	}
+	$absolute_discount=$soc->getAvailableDiscounts();
 
-		/*
-		 * Contact de la commande
-		*/
-		if($socid>0)
-		{
-			print "<tr><td>".$langs->trans("DefaultContact").'</td><td colspan="2">';
-			$form->select_contacts($soc->id,$setcontact,'contactidp',1,$srccontactslist);
-			print '</td></tr>';
 
-			// Ligne info remises tiers
-			print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="2">';
-			if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
-			else print $langs->trans("CompanyHasNoRelativeDiscount");
-			print '. ';
-			$absolute_discount=$soc->getAvailableDiscounts();
-			if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
-			else print $langs->trans("CompanyHasNoAbsoluteDiscount");
-			print '.';
-			print '</td></tr>';
-		}
-		// Date
-		print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td colspan="2">';
-		$form->select_date('','re','','','',"crea_commande",1,1);
-		print '</td></tr>';
 
-		// Date de livraison
-		print "<tr><td>".$langs->trans("DeliveryDate").'</td><td colspan="2">';
-		if (empty($datedelivery))
-		{
-			if (! empty($conf->global->DATE_LIVRAISON_WEEK_DELAY)) $datedelivery = time() + ((7*$conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
-			else $datedelivery=empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
-		}
-		$form->select_date($datedelivery,'liv_','','','',"crea_commande",1,1);
-		print "</td></tr>";
+	$nbrow=10;
 
-		// Conditions de reglement
-		print '<tr><td nowrap="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
-		$form->select_conditions_paiements($cond_reglement_id,'cond_reglement_id',-1,1);
-		print '</td></tr>';
+	print '<form name="crea_commande" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
+	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+	print '<input type="hidden" name="action" value="add">';
+	print '<input type="hidden" name="socid" value="'.$soc->id.'">' ."\n";
+	print '<input type="hidden" name="remise_percent" value="'.$soc->remise_client.'">';
+	print '<input type="hidden" name="origin" value="'.$origin.'">';
+	print '<input type="hidden" name="originid" value="'.$originid.'">';
 
-		// Mode de reglement
-		print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
-		$form->select_types_paiements($mode_reglement_id,'mode_reglement_id');
-		print '</td></tr>';
+	print '<table class="border" width="100%">';
 
-		// Delivery delay
-		print '<tr><td>'.$langs->trans('AvailabilityPeriod').'</td><td colspan="2">';
-		$form->select_availability($availability_id,'availability_id','',1);
-		print '</td></tr>';
+	// Reference
+	print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans("Draft").'</td></tr>';
+
+	// Reference client
+	print '<tr><td>'.$langs->trans('RefCustomer').'</td><td colspan="2">';
+	//print '<input type="text" name="ref_client" value="'.$ref_client.'"></td>';
+	print '<input type="text" name="ref_client" value=""></td>';	// We must not use ref_client of proposal for an order
+	print '</tr>';
+
+	// Client
+	print '<tr>';
+	print '<td class="fieldrequired">'.$langs->trans('Customer').'</td>';
+	if($socid>0)
+	{
+		print '<td colspan="2">';
+		print $soc->getNomUrl(1);
+		print '<input type="hidden" name="socid" value="'.$soc->id.'">';
+		print '</td>';
+	}
+	else
+	{
+		print '<td colspan="2">';
+		print $form->select_company('','socid','s.client = 1 OR s.client = 3',1);
+		print '</td>';
+	}
+	print '</tr>'."\n";
 
-		// What trigger creation
-		print '<tr><td>'.$langs->trans('Source').'</td><td colspan="2">';
-		$form->select_demand_reason($demand_reason_id,'demand_reason_id','',1);
+	/*
+	 * Contact de la commande
+	*/
+	if($socid>0)
+	{
+		print "<tr><td>".$langs->trans("DefaultContact").'</td><td colspan="2">';
+		$form->select_contacts($soc->id,$setcontact,'contactidp',1,$srccontactslist);
 		print '</td></tr>';
 
-		// Project
-		if (! empty($conf->projet->enabled) && $socid>0)
+		// Ligne info remises tiers
+		print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="2">';
+		if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
+		else print $langs->trans("CompanyHasNoRelativeDiscount");
+		print '. ';
+		$absolute_discount=$soc->getAvailableDiscounts();
+		if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
+		else print $langs->trans("CompanyHasNoAbsoluteDiscount");
+		print '.';
+		print '</td></tr>';
+	}
+	// Date
+	print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td colspan="2">';
+	$form->select_date('','re','','','',"crea_commande",1,1);
+	print '</td></tr>';
+
+	// Date de livraison
+	print "<tr><td>".$langs->trans("DeliveryDate").'</td><td colspan="2">';
+	if (empty($datedelivery))
+	{
+		if (! empty($conf->global->DATE_LIVRAISON_WEEK_DELAY)) $datedelivery = time() + ((7*$conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
+		else $datedelivery=empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
+	}
+	$form->select_date($datedelivery,'liv_','','','',"crea_commande",1,1);
+	print "</td></tr>";
+
+	// Conditions de reglement
+	print '<tr><td nowrap="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
+	$form->select_conditions_paiements($cond_reglement_id,'cond_reglement_id',-1,1);
+	print '</td></tr>';
+
+	// Mode de reglement
+	print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
+	$form->select_types_paiements($mode_reglement_id,'mode_reglement_id');
+	print '</td></tr>';
+
+	// Delivery delay
+	print '<tr><td>'.$langs->trans('AvailabilityPeriod').'</td><td colspan="2">';
+	$form->select_availability($availability_id,'availability_id','',1);
+	print '</td></tr>';
+
+	// What trigger creation
+	print '<tr><td>'.$langs->trans('Source').'</td><td colspan="2">';
+	$form->select_demand_reason($demand_reason_id,'demand_reason_id','',1);
+	print '</td></tr>';
+
+	// Project
+	if (! empty($conf->projet->enabled) && $socid>0)
+	{
+		print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';
+		$numprojet=select_projects($soc->id,$projectid);
+		if ($numprojet==0)
 		{
-			print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';
-			$numprojet=select_projects($soc->id,$projectid);
-			if ($numprojet==0)
-			{
-				print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/fiche.php?socid='.$soc->id.'&action=create">'.$langs->trans("AddProject").'</a>';
-			}
-			print '</td></tr>';
+			print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/fiche.php?socid='.$soc->id.'&action=create">'.$langs->trans("AddProject").'</a>';
 		}
+		print '</td></tr>';
+	}
 
-		// Other attributes
-		$parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
-		$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
-		if (empty($reshook) && ! empty($extrafields->attribute_label))
-		{
-			print $object->showOptionals($extrafields,'edit');
-		}
+	// Other attributes
+	$parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
+	$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
+	if (empty($reshook) && ! empty($extrafields->attribute_label))
+	{
+		print $object->showOptionals($extrafields,'edit');
+	}
 
-		// Template to use by default
-		print '<tr><td>'.$langs->trans('Model').'</td>';
-		print '<td colspan="2">';
-		include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
-		$liste=ModelePDFCommandes::liste_modeles($db);
-		print $form->selectarray('model',$liste,$conf->global->COMMANDE_ADDON_PDF);
-		print "</td></tr>";
+	// Template to use by default
+	print '<tr><td>'.$langs->trans('Model').'</td>';
+	print '<td colspan="2">';
+	include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
+	$liste=ModelePDFCommandes::liste_modeles($db);
+	print $form->selectarray('model',$liste,$conf->global->COMMANDE_ADDON_PDF);
+	print "</td></tr>";
+
+
+	// Note publique
+	print '<tr>';
+	print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
+	print '<td valign="top" colspan="2">';
 
+	$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
+	print $doleditor->Create(1);
+	//print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
+	print '</td></tr>';
 
-		// Note publique
+	// Note privee
+	if (! $user->societe_id)
+	{
 		print '<tr>';
-		print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
+		print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
 		print '<td valign="top" colspan="2">';
 
-		$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
+		$doleditor=new DolEditor('note', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
 		print $doleditor->Create(1);
-		//print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
+		//print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
 		print '</td></tr>';
+	}
+
+	if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
+	{
+		// TODO for compatibility
+		if ($origin == 'contrat')
+		{
+			// Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
+			$objectsrc->remise_absolue=$remise_absolue;
+			$objectsrc->remise_percent=$remise_percent;
+			$objectsrc->update_price(1);
+		}
 
-		// Note privee
-		if (! $user->societe_id)
+		print "\n<!-- ".$classname." info -->";
+		print "\n";
+		print '<input type="hidden" name="amount"         value="'.$objectsrc->total_ht.'">'."\n";
+		print '<input type="hidden" name="total"          value="'.$objectsrc->total_ttc.'">'."\n";
+		print '<input type="hidden" name="tva"            value="'.$objectsrc->total_tva.'">'."\n";
+		print '<input type="hidden" name="origin"         value="'.$objectsrc->element.'">';
+		print '<input type="hidden" name="originid"       value="'.$objectsrc->id.'">';
+
+		$newclassname=$classname;
+		if ($newclassname=='Propal') $newclassname='CommercialProposal';
+		print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
+		print '<tr><td>'.$langs->trans('TotalHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
+		print '<tr><td>'.$langs->trans('TotalVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
+		if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
 		{
-			print '<tr>';
-			print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
-			print '<td valign="top" colspan="2">';
+			print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
+		}
 
-			$doleditor=new DolEditor('note', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
-			print $doleditor->Create(1);
-			//print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
-			print '</td></tr>';
+		if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
+		{
+			print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
 		}
 
-		if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
+		print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
+	}
+	else
+	{
+		if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE))
 		{
-			// TODO for compatibility
-			if ($origin == 'contrat')
-			{
-				// Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
-				$objectsrc->remise_absolue=$remise_absolue;
-				$objectsrc->remise_percent=$remise_percent;
-				$objectsrc->update_price(1);
-			}
+			/*
+			 * Services/produits predefinis
+			*/
+			$NBLINES=8;
 
-			print "\n<!-- ".$classname." info -->";
-			print "\n";
-			print '<input type="hidden" name="amount"         value="'.$objectsrc->total_ht.'">'."\n";
-			print '<input type="hidden" name="total"          value="'.$objectsrc->total_ttc.'">'."\n";
-			print '<input type="hidden" name="tva"            value="'.$objectsrc->total_tva.'">'."\n";
-			print '<input type="hidden" name="origin"         value="'.$objectsrc->element.'">';
-			print '<input type="hidden" name="originid"       value="'.$objectsrc->id.'">';
-
-			$newclassname=$classname;
-			if ($newclassname=='Propal') $newclassname='CommercialProposal';
-			print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
-			print '<tr><td>'.$langs->trans('TotalHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
-			print '<tr><td>'.$langs->trans('TotalVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
-			if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
-			{
-				print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
-			}
+			print '<tr><td colspan="3">';
 
-			if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
+			print '<table class="noborder">';
+			print '<tr><td>'.$langs->trans('ProductsAndServices').'</td>';
+			print '<td>'.$langs->trans('Qty').'</td>';
+			print '<td>'.$langs->trans('ReductionShort').'</td>';
+			print '</tr>';
+			for ($i = 1 ; $i <= $NBLINES ; $i++)
 			{
-				print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
+				print '<tr><td>';
+				// multiprix
+				if (! empty($conf->global->PRODUIT_MULTIPRICES))
+					print $form->select_produits('','idprod'.$i,'',$conf->product->limit_size,$soc->price_level);
+				else
+					print $form->select_produits('','idprod'.$i,'',$conf->product->limit_size);
+				print '</td>';
+				print '<td><input type="text" size="3" name="qty'.$i.'" value="1"></td>';
+				print '<td><input type="text" size="3" name="remise_percent'.$i.'" value="'.$soc->remise_client.'">%</td></tr>';
 			}
 
-			print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
+			print '</table>';
+			print '</td></tr>';
 		}
-		else
-		{
-			if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE))
-			{
-				/*
-				 * Services/produits predefinis
-				*/
-				$NBLINES=8;
-
-				print '<tr><td colspan="3">';
-
-				print '<table class="noborder">';
-				print '<tr><td>'.$langs->trans('ProductsAndServices').'</td>';
-				print '<td>'.$langs->trans('Qty').'</td>';
-				print '<td>'.$langs->trans('ReductionShort').'</td>';
-				print '</tr>';
-				for ($i = 1 ; $i <= $NBLINES ; $i++)
-				{
-					print '<tr><td>';
-					// multiprix
-					if (! empty($conf->global->PRODUIT_MULTIPRICES))
-						print $form->select_produits('','idprod'.$i,'',$conf->product->limit_size,$soc->price_level);
-					else
-						print $form->select_produits('','idprod'.$i,'',$conf->product->limit_size);
-					print '</td>';
-					print '<td><input type="text" size="3" name="qty'.$i.'" value="1"></td>';
-					print '<td><input type="text" size="3" name="remise_percent'.$i.'" value="'.$soc->remise_client.'">%</td></tr>';
-				}
+	}
 
-				print '</table>';
-				print '</td></tr>';
-			}
-		}
+	print '</table>';
 
-		print '</table>';
+	// Button "Create Draft"
+	print '<br><center><input type="submit" class="button" name="bouton" value="'.$langs->trans('CreateDraft').'"></center>';
 
-		// Button "Create Draft"
-		print '<br><center><input type="submit" class="button" name="bouton" value="'.$langs->trans('CreateDraft').'"></center>';
+	print '</form>';
 
-		print '</form>';
 
+	// Show origin lines
+	if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
+	{
+		$title=$langs->trans('ProductsAndServices');
+		print_titre($title);
 
-		// Show origin lines
-		if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
-		{
-			$title=$langs->trans('ProductsAndServices');
-			print_titre($title);
+		print '<table class="noborder" width="100%">';
 
-			print '<table class="noborder" width="100%">';
+		$objectsrc->printOriginLinesList();
 
-			$objectsrc->printOriginLinesList();
+		print '</table>';
+	}
 
-			print '</table>';
-		}
+}
+else
+{
+	/* *************************************************************************** */
+	/*                                                                             */
+	/* Mode vue et edition                                                         */
+	/*                                                                             */
+	/* *************************************************************************** */
+	$now=dol_now();
 
-	}
-	else
+	if ($object->id > 0)
 	{
-		/* *************************************************************************** */
-		/*                                                                             */
-		/* Mode vue et edition                                                         */
-		/*                                                                             */
-		/* *************************************************************************** */
-		$now=dol_now();
-
-		if ($object->id > 0)
-		{
-			dol_htmloutput_mesg($mesg,$mesgs);
+		dol_htmloutput_mesg($mesg,$mesgs);
 
-			$product_static=new Product($db);
+		$product_static=new Product($db);
 
-			$soc = new Societe($db);
-			$soc->fetch($object->socid);
+		$soc = new Societe($db);
+		$soc->fetch($object->socid);
 
-			$author = new User($db);
-			$author->fetch($object->user_author_id);
+		$author = new User($db);
+		$author->fetch($object->user_author_id);
 
-			$head = commande_prepare_head($object);
-			dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), 0, 'order');
+		$head = commande_prepare_head($object);
+		dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), 0, 'order');
 
-			$formconfirm='';
+		$formconfirm='';
 
-			/*
-			 * Confirmation de la suppression de la commande
-			*/
-			if ($action == 'delete')
+		/*
+		 * Confirmation de la suppression de la commande
+		*/
+		if ($action == 'delete')
+		{
+			$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
+		}
+
+		/*
+		 * Confirmation de la validation
+		*/
+		if ($action == 'validate')
+		{
+			// on verifie si l'objet est en numerotation provisoire
+			$ref = substr($object->ref, 1, 4);
+			if ($ref == 'PROV')
 			{
-				$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
+				$numref = $object->getNextNumRef($soc);
 			}
-
-			/*
-			 * Confirmation de la validation
-			*/
-			if ($action == 'validate')
+			else
 			{
-				// on verifie si l'objet est en numerotation provisoire
-				$ref = substr($object->ref, 1, 4);
-				if ($ref == 'PROV')
-				{
-					$numref = $object->getNextNumRef($soc);
-				}
-				else
-				{
-					$numref = $object->ref;
-				}
-
-				$text=$langs->trans('ConfirmValidateOrder',$numref);
-				if (! empty($conf->notification->enabled))
-				{
-					require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
-					$notify=new Notify($db);
-					$text.='<br>';
-					$text.=$notify->confirmMessage('NOTIFY_VAL_ORDER',$object->socid);
-				}
-				$formquestion=array();
-				if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
-				{
-					$langs->load("stocks");
-					require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
-					$formproduct=new FormProduct($db);
-					$formquestion=array(
-							//'text' => $langs->trans("ConfirmClone"),
-							//array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1),
-							//array('type' => 'checkbox', 'name' => 'update_prices',   'label' => $langs->trans("PuttingPricesUpToDate"),   'value' => 1),
-					array('type' => 'other', 'name' => 'idwarehouse',   'label' => $langs->trans("SelectWarehouseForStockDecrease"),   'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
-				}
-
-				$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
+				$numref = $object->ref;
 			}
 
-			// Confirm back to draft status
-			if ($action == 'modif')
+			$text=$langs->trans('ConfirmValidateOrder',$numref);
+			if (! empty($conf->notification->enabled))
 			{
-				$text=$langs->trans('ConfirmUnvalidateOrder',$object->ref);
-				$formquestion=array();
-				if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
-				{
-					$langs->load("stocks");
-					require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
-					$formproduct=new FormProduct($db);
-					$formquestion=array(
-							//'text' => $langs->trans("ConfirmClone"),
-							//array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1),
-							//array('type' => 'checkbox', 'name' => 'update_prices',   'label' => $langs->trans("PuttingPricesUpToDate"),   'value' => 1),
-					array('type' => 'other', 'name' => 'idwarehouse',   'label' => $langs->trans("SelectWarehouseForStockIncrease"),   'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
-				}
-
-				$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnvalidateOrder'), $text, 'confirm_modif', $formquestion, "yes", 1, 220);
+				require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
+				$notify=new Notify($db);
+				$text.='<br>';
+				$text.=$notify->confirmMessage('NOTIFY_VAL_ORDER',$object->socid);
+			}
+			$formquestion=array();
+			if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
+			{
+				$langs->load("stocks");
+				require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
+				$formproduct=new FormProduct($db);
+				$formquestion=array(
+				//'text' => $langs->trans("ConfirmClone"),
+				//array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1),
+				//array('type' => 'checkbox', 'name' => 'update_prices',   'label' => $langs->trans("PuttingPricesUpToDate"),   'value' => 1),
+				array('type' => 'other', 'name' => 'idwarehouse',   'label' => $langs->trans("SelectWarehouseForStockDecrease"),   'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
 			}
 
+			$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
+		}
 
-			/*
-			 * Confirmation de la cloture
-			*/
-			if ($action == 'shipped')
+		// Confirm back to draft status
+		if ($action == 'modif')
+		{
+			$text=$langs->trans('ConfirmUnvalidateOrder',$object->ref);
+			$formquestion=array();
+			if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
 			{
-				$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_shipped', '', 0, 1);
+				$langs->load("stocks");
+				require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
+				$formproduct=new FormProduct($db);
+				$formquestion=array(
+				//'text' => $langs->trans("ConfirmClone"),
+				//array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1),
+				//array('type' => 'checkbox', 'name' => 'update_prices',   'label' => $langs->trans("PuttingPricesUpToDate"),   'value' => 1),
+				array('type' => 'other', 'name' => 'idwarehouse',   'label' => $langs->trans("SelectWarehouseForStockIncrease"),   'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
 			}
 
-			/*
-			 * Confirmation de l'annulation
-			*/
-			if ($action == 'cancel')
-			{
-				$text=$langs->trans('ConfirmCancelOrder',$object->ref);
-				$formquestion=array();
-				if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
-				{
-					$langs->load("stocks");
-					require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
-					$formproduct=new FormProduct($db);
-					$formquestion=array(
-							//'text' => $langs->trans("ConfirmClone"),
-							//array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1),
-							//array('type' => 'checkbox', 'name' => 'update_prices',   'label' => $langs->trans("PuttingPricesUpToDate"),   'value' => 1),
-					array('type' => 'other', 'name' => 'idwarehouse',   'label' => $langs->trans("SelectWarehouseForStockIncrease"),   'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
-				}
+			$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnvalidateOrder'), $text, 'confirm_modif', $formquestion, "yes", 1, 220);
+		}
 
-				$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Cancel'), $text, 'confirm_cancel', $formquestion, 0, 1);
-			}
 
-			/*
-			 * Confirmation de la suppression d'une ligne produit
-			*/
-			if ($action == 'ask_deleteline')
-			{
-				$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
-			}
+		/*
+		 * Confirmation de la cloture
+		*/
+		if ($action == 'shipped')
+		{
+			$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_shipped', '', 0, 1);
+		}
 
-			// Clone confirmation
-			if ($action == 'clone')
+		/*
+		 * Confirmation de l'annulation
+		*/
+		if ($action == 'cancel')
+		{
+			$text=$langs->trans('ConfirmCancelOrder',$object->ref);
+			$formquestion=array();
+			if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
 			{
-				// Create an array for form
+				$langs->load("stocks");
+				require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
+				$formproduct=new FormProduct($db);
 				$formquestion=array(
-						//'text' => $langs->trans("ConfirmClone"),
-						//array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1),
-						//array('type' => 'checkbox', 'name' => 'update_prices',   'label' => $langs->trans("PuttingPricesUpToDate"),   'value' => 1),
-				array('type' => 'other', 'name' => 'socid',   'label' => $langs->trans("SelectThirdParty"),   'value' => $form->select_company(GETPOST('socid','int'),'socid','(s.client=1 OR s.client=3)'))
-				);
-				// Paiement incomplet. On demande si motif = escompte ou autre
-				$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$object->ref),'confirm_clone',$formquestion,'yes',1);
+				//'text' => $langs->trans("ConfirmClone"),
+				//array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1),
+				//array('type' => 'checkbox', 'name' => 'update_prices',   'label' => $langs->trans("PuttingPricesUpToDate"),   'value' => 1),
+				array('type' => 'other', 'name' => 'idwarehouse',   'label' => $langs->trans("SelectWarehouseForStockIncrease"),   'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
 			}
 
-			if (! $formconfirm)
-			{
-				$parameters=array('lineid'=>$lineid);
-				$formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
-			}
+			$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Cancel'), $text, 'confirm_cancel', $formquestion, 0, 1);
+		}
 
-			// Print form confirm
-			print $formconfirm;
+		/*
+		 * Confirmation de la suppression d'une ligne produit
+		*/
+		if ($action == 'ask_deleteline')
+		{
+			$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
+		}
 
-			/*
-			 *   Commande
-			*/
-			$nbrow=9;
-			if (! empty($conf->projet->enabled)) $nbrow++;
+		// Clone confirmation
+		if ($action == 'clone')
+		{
+			// Create an array for form
+			$formquestion=array(
+			//'text' => $langs->trans("ConfirmClone"),
+			//array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1),
+			//array('type' => 'checkbox', 'name' => 'update_prices',   'label' => $langs->trans("PuttingPricesUpToDate"),   'value' => 1),
+			array('type' => 'other', 'name' => 'socid',   'label' => $langs->trans("SelectThirdParty"),   'value' => $form->select_company(GETPOST('socid','int'),'socid','(s.client=1 OR s.client=3)'))
+			);
+			// Paiement incomplet. On demande si motif = escompte ou autre
+			$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$object->ref),'confirm_clone',$formquestion,'yes',1);
+		}
 
-			//Local taxes
-			if($mysoc->localtax1_assuj=="1") $nbrow++;
-			if($mysoc->localtax2_assuj=="1") $nbrow++;
+		if (! $formconfirm)
+		{
+			$parameters=array('lineid'=>$lineid);
+			$formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
+		}
 
-			print '<table class="border" width="100%">';
+		// Print form confirm
+		print $formconfirm;
 
-			$linkback = '<a href="'.DOL_URL_ROOT.'/commande/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
+		/*
+		 *   Commande
+		*/
+		$nbrow=9;
+		if (! empty($conf->projet->enabled)) $nbrow++;
 
-			// Ref
-			print '<tr><td width="18%">'.$langs->trans('Ref').'</td>';
-			print '<td colspan="3">';
-			print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
-			print '</td>';
-			print '</tr>';
+		//Local taxes
+		if($mysoc->localtax1_assuj=="1") $nbrow++;
+		if($mysoc->localtax2_assuj=="1") $nbrow++;
 
-			// Ref commande client
-			print '<tr><td>';
-			print '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
-			print $langs->trans('RefCustomer').'</td><td align="left">';
-			print '</td>';
-			if ($action != 'refcustomer' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=refcustomer&amp;id='.$object->id.'">'.img_edit($langs->trans('Modify')).'</a></td>';
-			print '</tr></table>';
-			print '</td><td colspan="3">';
-			if ($user->rights->commande->creer && $action == 'refcustomer')
-			{
-				print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
-				print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-				print '<input type="hidden" name="action" value="set_ref_client">';
-				print '<input type="text" class="flat" size="20" name="ref_client" value="'.$object->ref_client.'">';
-				print ' <input type="submit" class="button" value="'.$langs->trans('Modify').'">';
-				print '</form>';
-			}
-			else
-			{
-				print $object->ref_client;
-			}
-			print '</td>';
-			print '</tr>';
+		print '<table class="border" width="100%">';
 
+		$linkback = '<a href="'.DOL_URL_ROOT.'/commande/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
 
-			// Third party
-			print '<tr><td>'.$langs->trans('Company').'</td>';
-			print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
-			print '</tr>';
+		// Ref
+		print '<tr><td width="18%">'.$langs->trans('Ref').'</td>';
+		print '<td colspan="3">';
+		print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
+		print '</td>';
+		print '</tr>';
 
-			if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
-			{
-				$filterabsolutediscount="fk_facture_source IS NULL";  // If we want deposit to be substracted to payments only and not to total of final invoice
-				$filtercreditnote="fk_facture_source IS NOT NULL";    // If we want deposit to be substracted to payments only and not to total of final invoice
-			}
-			else
-			{
-				$filterabsolutediscount="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')";
-				$filtercreditnote="fk_facture_source IS NOT NULL AND description <> '(DEPOSIT)'";
-			}
+		// Ref commande client
+		print '<tr><td>';
+		print '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
+		print $langs->trans('RefCustomer').'</td><td align="left">';
+		print '</td>';
+		if ($action != 'refcustomer' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=refcustomer&amp;id='.$object->id.'">'.img_edit($langs->trans('Modify')).'</a></td>';
+		print '</tr></table>';
+		print '</td><td colspan="3">';
+		if ($user->rights->commande->creer && $action == 'refcustomer')
+		{
+			print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
+			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+			print '<input type="hidden" name="action" value="set_ref_client">';
+			print '<input type="text" class="flat" size="20" name="ref_client" value="'.$object->ref_client.'">';
+			print ' <input type="submit" class="button" value="'.$langs->trans('Modify').'">';
+			print '</form>';
+		}
+		else
+		{
+			print $object->ref_client;
+		}
+		print '</td>';
+		print '</tr>';
 
-	        // Relative and absolute discounts
-	        $addrelativediscount='<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("EditRelativeDiscounts").'</a>';
-	        $addabsolutediscount='<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("EditGlobalDiscounts").'</a>';
-	        $addcreditnote='<a href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&socid='.$soc->id.'&type=2&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("AddCreditNote").'</a>';
-
-        	print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="3">';
-			if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
-			else print $langs->trans("CompanyHasNoRelativeDiscount");
-			print '. ';
-			$absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL');
-			$absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL');
-			$absolute_discount=price2num($absolute_discount,'MT');
-			$absolute_creditnote=price2num($absolute_creditnote,'MT');
-			if ($absolute_discount)
-			{
-				if ($object->statut > 0)
-				{
-					print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
-				}
-				else
-				{
-					// Remise dispo de type remise fixe (not credit note)
-					print '<br>';
-					$form->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id',$soc->id,$absolute_discount,$filterabsolutediscount);
-				}
-			}
-			if ($absolute_creditnote)
-			{
-				print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'. ';
-			}
-			if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
-			print '</td></tr>';
 
-			// Date
-			print '<tr><td>';
-			print '<table class="nobordernopadding" width="100%"><tr><td>';
-			print $langs->trans('Date');
-			print '</td>';
+		// Third party
+		print '<tr><td>'.$langs->trans('Company').'</td>';
+		print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
+		print '</tr>';
 
-			if ($action != 'editdate' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'),1).'</a></td>';
-			print '</tr></table>';
-			print '</td><td colspan="3">';
-			if ($action == 'editdate')
-			{
-				print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
-				print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-				print '<input type="hidden" name="action" value="setdate">';
-				$form->select_date($object->date,'order_','','','',"setdate");
-				print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
-				print '</form>';
-			}
-			else
-			{
-				print $object->date ? dol_print_date($object->date,'daytext') : '&nbsp;';
-			}
-			print '</td>';
-			print '</tr>';
+		if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
+		{
+			$filterabsolutediscount="fk_facture_source IS NULL";  // If we want deposit to be substracted to payments only and not to total of final invoice
+			$filtercreditnote="fk_facture_source IS NOT NULL";    // If we want deposit to be substracted to payments only and not to total of final invoice
+		}
+		else
+		{
+			$filterabsolutediscount="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')";
+			$filtercreditnote="fk_facture_source IS NOT NULL AND description <> '(DEPOSIT)'";
+		}
 
-			// Delivery date planed
-			print '<tr><td height="10">';
-			print '<table class="nobordernopadding" width="100%"><tr><td>';
-			print $langs->trans('DateDeliveryPlanned');
-			print '</td>';
-			if ($action != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
-			print '</tr></table>';
-			print '</td><td colspan="3">';
-			if ($action == 'editdate_livraison')
+		// Relative and absolute discounts
+		$addrelativediscount='<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("EditRelativeDiscounts").'</a>';
+		$addabsolutediscount='<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("EditGlobalDiscounts").'</a>';
+		$addcreditnote='<a href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&socid='.$soc->id.'&type=2&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("AddCreditNote").'</a>';
+
+		print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="3">';
+		if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
+		else print $langs->trans("CompanyHasNoRelativeDiscount");
+		print '. ';
+		$absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL');
+		$absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL');
+		$absolute_discount=price2num($absolute_discount,'MT');
+		$absolute_creditnote=price2num($absolute_creditnote,'MT');
+		if ($absolute_discount)
+		{
+			if ($object->statut > 0)
 			{
-				print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
-				print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-				print '<input type="hidden" name="action" value="setdate_livraison">';
-				$form->select_date($object->date_livraison?$object->date_livraison:-1,'liv_','','','',"setdate_livraison");
-				print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
-				print '</form>';
+				print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
 			}
 			else
 			{
-				print $object->date_livraison ? dol_print_date($object->date_livraison,'daytext') : '&nbsp;';
+				// Remise dispo de type remise fixe (not credit note)
+				print '<br>';
+				$form->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id',$soc->id,$absolute_discount,$filterabsolutediscount);
 			}
-			print '</td>';
-			print '</tr>';
+		}
+		if ($absolute_creditnote)
+		{
+			print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'. ';
+		}
+		if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
+		print '</td></tr>';
 
-			// Terms of payment
-			print '<tr><td height="10">';
-			print '<table class="nobordernopadding" width="100%"><tr><td>';
-			print $langs->trans('PaymentConditionsShort');
-			print '</td>';
-			if ($action != 'editconditions' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
-			print '</tr></table>';
-			print '</td><td colspan="3">';
-			if ($action == 'editconditions')
-			{
-				$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id',1);
-			}
-			else
-			{
-				$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none',1);
-			}
-			print '</td>';
+		// Date
+		print '<tr><td>';
+		print '<table class="nobordernopadding" width="100%"><tr><td>';
+		print $langs->trans('Date');
+		print '</td>';
+
+		if ($action != 'editdate' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'),1).'</a></td>';
+		print '</tr></table>';
+		print '</td><td colspan="3">';
+		if ($action == 'editdate')
+		{
+			print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
+			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+			print '<input type="hidden" name="action" value="setdate">';
+			$form->select_date($object->date,'order_','','','',"setdate");
+			print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
+			print '</form>';
+		}
+		else
+		{
+			print $object->date ? dol_print_date($object->date,'daytext') : '&nbsp;';
+		}
+		print '</td>';
+		print '</tr>';
 
-			print '</tr>';
+		// Delivery date planed
+		print '<tr><td height="10">';
+		print '<table class="nobordernopadding" width="100%"><tr><td>';
+		print $langs->trans('DateDeliveryPlanned');
+		print '</td>';
+		if ($action != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
+		print '</tr></table>';
+		print '</td><td colspan="3">';
+		if ($action == 'editdate_livraison')
+		{
+			print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
+			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+			print '<input type="hidden" name="action" value="setdate_livraison">';
+			$form->select_date($object->date_livraison?$object->date_livraison:-1,'liv_','','','',"setdate_livraison");
+			print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
+			print '</form>';
+		}
+		else
+		{
+			print $object->date_livraison ? dol_print_date($object->date_livraison,'daytext') : '&nbsp;';
+		}
+		print '</td>';
+		print '</tr>';
 
-			// Mode of payment
-			print '<tr><td height="10">';
-			print '<table class="nobordernopadding" width="100%"><tr><td>';
-			print $langs->trans('PaymentMode');
-			print '</td>';
-			if ($action != 'editmode' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
-			print '</tr></table>';
-			print '</td><td colspan="3">';
-			if ($action == 'editmode')
-			{
-				$form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
-			}
-			else
-			{
-				$form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none');
-			}
-			print '</td></tr>';
+		// Terms of payment
+		print '<tr><td height="10">';
+		print '<table class="nobordernopadding" width="100%"><tr><td>';
+		print $langs->trans('PaymentConditionsShort');
+		print '</td>';
+		if ($action != 'editconditions' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
+		print '</tr></table>';
+		print '</td><td colspan="3">';
+		if ($action == 'editconditions')
+		{
+			$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id',1);
+		}
+		else
+		{
+			$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none',1);
+		}
+		print '</td>';
 
-			// Availability
+		print '</tr>';
+
+		// Mode of payment
+		print '<tr><td height="10">';
+		print '<table class="nobordernopadding" width="100%"><tr><td>';
+		print $langs->trans('PaymentMode');
+		print '</td>';
+		if ($action != 'editmode' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
+		print '</tr></table>';
+		print '</td><td colspan="3">';
+		if ($action == 'editmode')
+		{
+			$form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
+		}
+		else
+		{
+			$form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none');
+		}
+		print '</td></tr>';
+
+		// Availability
+		print '<tr><td height="10">';
+		print '<table class="nobordernopadding" width="100%"><tr><td>';
+		print $langs->trans('AvailabilityPeriod');
+		print '</td>';
+		if ($action != 'editavailability' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editavailability&amp;id='.$object->id.'">'.img_edit($langs->trans('SetAvailability'),1).'</a></td>';
+		print '</tr></table>';
+		print '</td><td colspan="3">';
+		if ($action == 'editavailability')
+		{
+			$form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'availability_id',1);
+		}
+		else
+		{
+			$form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none',1);
+		}
+		print '</td></tr>';
+
+		// Source
+		print '<tr><td height="10">';
+		print '<table class="nobordernopadding" width="100%"><tr><td>';
+		print $langs->trans('Source');
+		print '</td>';
+		if ($action != 'editdemandreason' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdemandreason&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDemandReason'),1).'</a></td>';
+		print '</tr></table>';
+		print '</td><td colspan="3">';
+		if ($action == 'editdemandreason')
+		{
+			$form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1);
+		}
+		else
+		{
+			$form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none');
+		}
+		// Removed because using dictionnary is an admin feature, not a user feature. Ther is already the "star" to show info to admin users.
+		// This is to avoid too heavy screens and have an uniform look and feel for all screens.
+		//print '</td><td>';
+		//print '<a href="'.DOL_URL_ROOT.'/admin/dict.php?id=22&origin=order&originid='.$object->id.'">'.$langs->trans("DictionnarySource").'</a>';
+		print '</td></tr>';
+
+		// Project
+		if (! empty($conf->projet->enabled))
+		{
+			$langs->load('projects');
 			print '<tr><td height="10">';
 			print '<table class="nobordernopadding" width="100%"><tr><td>';
-			print $langs->trans('AvailabilityPeriod');
+			print $langs->trans('Project');
 			print '</td>';
-			if ($action != 'editavailability' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editavailability&amp;id='.$object->id.'">'.img_edit($langs->trans('SetAvailability'),1).'</a></td>';
+			if ($action != 'classify') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->trans('SetProject')).'</a></td>';
 			print '</tr></table>';
 			print '</td><td colspan="3">';
-			if ($action == 'editavailability')
+			//print "$object->id, $object->socid, $object->fk_project";
+			if ($action == 'classify')
 			{
-				$form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'availability_id',1);
+				$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid');
 			}
 			else
 			{
-				$form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none',1);
+				$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none');
 			}
 			print '</td></tr>';
+		}
 
-			// Source
-			print '<tr><td height="10">';
-			print '<table class="nobordernopadding" width="100%"><tr><td>';
-			print $langs->trans('Source');
-			print '</td>';
-			if ($action != 'editdemandreason' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdemandreason&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDemandReason'),1).'</a></td>';
-			print '</tr></table>';
-			print '</td><td colspan="3">';
-			if ($action == 'editdemandreason')
-			{
-				$form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1);
-			}
-			else
+		// Other attributes
+		$res=$object->fetch_optionals($object->id,$extralabels);
+		$parameters=array('colspan' => ' colspan="3"');
+		$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
+		if (empty($reshook) && ! empty($extrafields->attribute_label))
+		{
+
+			if ($action == 'edit_extras')
 			{
-				$form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none');
+				print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc">';
+				print '<input type="hidden" name="action" value="update_extras">';
+				print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+				print '<input type="hidden" name="id" value="'.$object->id.'">';
 			}
-			// Removed because using dictionnary is an admin feature, not a user feature. Ther is already the "star" to show info to admin users.
-			// This is to avoid too heavy screens and have an uniform look and feel for all screens.
-			//print '</td><td>';
-			//print '<a href="'.DOL_URL_ROOT.'/admin/dict.php?id=22&origin=order&originid='.$object->id.'">'.$langs->trans("DictionnarySource").'</a>';
-			print '</td></tr>';
 
-			// Project
-			if (! empty($conf->projet->enabled))
+			// TODO : use showOptionals($extrafields) function
+			foreach($extrafields->attribute_label as $key=>$label)
 			{
-				$langs->load('projects');
-				print '<tr><td height="10">';
-				print '<table class="nobordernopadding" width="100%"><tr><td>';
-				print $langs->trans('Project');
-				print '</td>';
-				if ($action != 'classify') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->trans('SetProject')).'</a></td>';
-				print '</tr></table>';
-				print '</td><td colspan="3">';
-				//print "$object->id, $object->socid, $object->fk_project";
-				if ($action == 'classify')
+				$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
+				if ($extrafields->attribute_type[$key] == 'separate')
 				{
-					$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid');
+					print $extrafields->showSeparator($key);
 				}
 				else
 				{
-					$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none');
+					print '<tr><td';
+					if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
+					print '>'.$label.'</td><td colspan="3">';
+
+					// Convert date into timestamp format
+					if (in_array($extrafields->attribute_type[$key],array('date','datetime')))
+					{
+						$value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$object->array_options['options_'.$key];
+					}
+
+					if ($action == 'edit_extras' &&  $user->rights->propal->creer)
+					{
+						print $extrafields->showInputField($key,$value);
+					}
+					else
+					{
+						print $extrafields->showOutputField($key,$value);
+					}
+					print '</td></tr>'."\n";
 				}
-				print '</td></tr>';
 			}
 
-			// Other attributes
-			$parameters=array('colspan' => ' colspan="3"');
-			$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
-			if (empty($reshook) && ! empty($extrafields->attribute_label))
-			{
-				print $object->showOptionals($extrafields,'edit');
+			if(count($extrafields->attribute_label) > 0) {
+
+				if ($action == 'edit_extras' && $user->rights->propal->creer)
+				{
+					print '<tr><td></td><td>';
+					print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
+					print '</form>';
+					print '</td></tr>';
+
+				}
+				else {
+					if ($object->statut == 0 && $user->rights->propal->creer)
+					{
+						print '<tr><td></td><td><a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras">'.img_picto('','edit').' '.$langs->trans('Modify').'</a></td></tr>';
+					}
+				}
 			}
+		}
 
-			$rowspan=4;
-			if ($mysoc->localtax1_assuj=="1") $rowspan++;
-			if ($mysoc->localtax2_assuj=="1") $rowspan++;
+		$rowspan=4;
+		if ($mysoc->localtax1_assuj=="1") $rowspan++;
+		if ($mysoc->localtax2_assuj=="1") $rowspan++;
 
-			// Total HT
-			print '<tr><td>'.$langs->trans('AmountHT').'</td>';
-			print '<td align="right">'.price($object->total_ht,'',$langs,'','',0,$conf->currency).'</td>';
+		// Total HT
+		print '<tr><td>'.$langs->trans('AmountHT').'</td>';
+		print '<td align="right">'.price($object->total_ht,'',$langs,'','',0,$conf->currency).'</td>';
 
-			// Margin Infos
-			if (! empty($conf->margin->enabled))
-			{
-				print '<td valign="top" width="50%" colspan="2" rowspan="'.$rowspan.'">';
-				$object->displayMarginInfos();
-				print '</td>';
-			}
-			else print '<td width="50%" colspan="2" rowspan="'.$rowspan.'"></td>';
+		// Margin Infos
+		if (! empty($conf->margin->enabled))
+		{
+			print '<td valign="top" width="50%" colspan="2" rowspan="'.$rowspan.'">';
+			$object->displayMarginInfos();
+			print '</td>';
+		}
+		else print '<td width="50%" colspan="2" rowspan="'.$rowspan.'"></td>';
 
-			print '</tr>';
+		print '</tr>';
 
-			// Total TVA
-			print '<tr><td>'.$langs->trans('AmountVAT').'</td><td align="right">'.price($object->total_tva,'',$langs,'','',0,$conf->currency).'</td></tr>';
+		// Total TVA
+		print '<tr><td>'.$langs->trans('AmountVAT').'</td><td align="right">'.price($object->total_tva,'',$langs,'','',0,$conf->currency).'</td></tr>';
 
-			// Amount Local Taxes
-			if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
-			{
-				print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
-				print '<td align="right">'.price($object->total_localtax1,'',$langs,'','',0,$conf->currency).'</td></tr>';
-			}
-			if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
-			{
-				print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
-				print '<td align="right">'.price($object->total_localtax2,'',$langs,'','',0,$conf->currency).'</td></tr>';
-			}
+		// Amount Local Taxes
+		if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
+		{
+			print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
+			print '<td align="right">'.price($object->total_localtax1,'',$langs,'','',0,$conf->currency).'</td></tr>';
+		}
+		if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
+		{
+			print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
+			print '<td align="right">'.price($object->total_localtax2,'',$langs,'','',0,$conf->currency).'</td></tr>';
+		}
 
-			// Total TTC
-			print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right">'.price($object->total_ttc,'',$langs,'','',0,$conf->currency).'</td></tr>';
+		// Total TTC
+		print '<tr><td>'.$langs->trans('AmountTTC').'</td><td align="right">'.price($object->total_ttc,'',$langs,'','',0,$conf->currency).'</td></tr>';
 
-			// Statut
-			print '<tr><td>'.$langs->trans('Status').'</td><td>'.$object->getLibStatut(4).'</td></tr>';
+		// Statut
+		print '<tr><td>'.$langs->trans('Status').'</td><td>'.$object->getLibStatut(4).'</td></tr>';
 
-			print '</table><br>';
-			print "\n";
+		print '</table><br>';
+		print "\n";
 
-			if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
-			{
-				$blocname = 'contacts';
-				$title = $langs->trans('ContactsAddresses');
-				include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
-			}
+		if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
+		{
+			$blocname = 'contacts';
+			$title = $langs->trans('ContactsAddresses');
+			include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
+		}
 
-			if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
-			{
-				$blocname = 'notes';
-				$title = $langs->trans('Notes');
-				include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
-			}
+		if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
+		{
+			$blocname = 'notes';
+			$title = $langs->trans('Notes');
+			include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
+		}
 
-			/*
-			 * Lines
-			*/
-			$result = $object->getLinesArray();
+		/*
+		 * Lines
+		*/
+		$result = $object->getLinesArray();
 
-			$numlines = count($object->lines);
+		$numlines = count($object->lines);
 
-			if (! empty($conf->use_javascript_ajax) && $object->statut == 0)
-			{
-				include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
-			}
+		if (! empty($conf->use_javascript_ajax) && $object->statut == 0)
+		{
+			include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
+		}
 
-			print '<table id="tablelines" class="noborder" width="100%">';
+		print '<table id="tablelines" class="noborder" width="100%">';
 
-			// Show object lines
-			if (! empty($object->lines))
-				$ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,1);
+		// Show object lines
+		if (! empty($object->lines))
+			$ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,1);
 
-			/*
-			 * Form to add new line
-			*/
-			if ($object->statut == 0 && $user->rights->commande->creer)
+		/*
+		 * Form to add new line
+		*/
+		if ($object->statut == 0 && $user->rights->commande->creer)
+		{
+			if ($action != 'editline')
 			{
-				if ($action != 'editline')
+				$var=true;
+
+				if ($conf->global->MAIN_FEATURES_LEVEL > 1)
+				{
+					// Add free or predefined products/services
+					$object->formAddObjectLine(1,$mysoc,$soc);
+				}
+				else
 				{
-					$var=true;
+					// Add free products/services
+					$object->formAddFreeProduct(1,$mysoc,$soc);
 
-					if ($conf->global->MAIN_FEATURES_LEVEL > 1)
-					{
-						// Add free or predefined products/services
-						$object->formAddObjectLine(1,$mysoc,$soc);
-					}
-					else
+					// Add predefined products/services
+					if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
 					{
-						// Add free products/services
-						$object->formAddFreeProduct(1,$mysoc,$soc);
-
-						// Add predefined products/services
-						if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
-						{
-							$var=!$var;
-							$object->formAddPredefinedProduct(1,$mysoc,$soc);
-						}
+						$var=!$var;
+						$object->formAddPredefinedProduct(1,$mysoc,$soc);
 					}
-
-					$parameters=array();
-					$reshook=$hookmanager->executeHooks('formAddObjectLine',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
 				}
+
+				$parameters=array();
+				$reshook=$hookmanager->executeHooks('formAddObjectLine',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
 			}
-			print '</table>';
-			print '</div>';
+		}
+		print '</table>';
+		print '</div>';
 
 
-			/*
-			 * Boutons actions
-			*/
-			if ($action != 'presend')
+		/*
+		 * Boutons actions
+		*/
+		if ($action != 'presend')
+		{
+			if ($user->societe_id == 0 && $action <> 'editline')
 			{
-				if ($user->societe_id == 0 && $action <> 'editline')
+				print '<div class="tabsAction">';
+
+				// Valid
+				if ($object->statut == 0 && $object->total_ttc >= 0 && $numlines > 0 && $user->rights->commande->valider)
 				{
-					print '<div class="tabsAction">';
+					print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Validate').'</a></div>';
+				}
 
-					// Valid
-					if ($object->statut == 0 && $object->total_ttc >= 0 && $numlines > 0 && $user->rights->commande->valider)
-					{
-						print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Validate').'</a></div>';
-					}
+				// Edit
+				if ($object->statut == 1 && $user->rights->commande->creer)
+				{
+					print '<div class="inline-block divButAction"><a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=modif">'.$langs->trans('Modify').'</a></div>';
+				}
 
-					// Edit
-					if ($object->statut == 1 && $user->rights->commande->creer)
+				// Send
+				if ($object->statut > 0)
+				{
+					if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send))
 					{
-						print '<div class="inline-block divButAction"><a class="butAction" href="fiche.php?id='.$object->id.'&amp;action=modif">'.$langs->trans('Modify').'</a></div>';
+						print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a></div>';
 					}
+					else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a></div>';
+				}
 
-					// Send
-					if ($object->statut > 0)
-					{
-						if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send))
-						{
-							print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a></div>';
-						}
-						else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a></div>';
-					}
+				// Ship
+				$numshipping=0;
+				if (! empty($conf->expedition->enabled))
+				{
+					$numshipping = $object->nb_expedition();
 
-					// Ship
-					$numshipping=0;
-					if (! empty($conf->expedition->enabled))
+					if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfProductsLines() > 0)
 					{
-						$numshipping = $object->nb_expedition();
-
-						if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfProductsLines() > 0)
+						if (($conf->expedition_bon->enabled && $user->rights->expedition->creer)
+							|| ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer))
 						{
-							if (($conf->expedition_bon->enabled && $user->rights->expedition->creer)
-									|| ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer))
+							if ($user->rights->expedition->creer)
 							{
-								if ($user->rights->expedition->creer)
-								{
-									print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id.'">'.$langs->trans('ShipProduct').'</a></div>';
-								}
-								else
-								{
-									print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('ShipProduct').'</a></div>';
-								}
+								print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id.'">'.$langs->trans('ShipProduct').'</a></div>';
 							}
 							else
 							{
-								$langs->load("errors");
-								print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("ErrorModuleSetupNotComplete")).'">'.$langs->trans('ShipProduct').'</a></div>';
+								print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('ShipProduct').'</a></div>';
 							}
 						}
+						else
+						{
+							$langs->load("errors");
+							print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("ErrorModuleSetupNotComplete")).'">'.$langs->trans('ShipProduct').'</a></div>';
+						}
 					}
+				}
 
-                    // Create intervention
-                    if ($conf->ficheinter->enabled)
-                    {
-                    	$langs->load("interventions");
-
-                        if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfServicesLines() > 0)
-                        {
-                              if ($user->rights->ficheinter->creer)
-                              {
-                                  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/fiche.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans('AddIntervention').'</a></div>';
-                              }
-                              else
-                              {
-                                  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('AddIntervention').'</a></div>';
-                              }
-                      }
-                    }
-
-					// Reopen a closed order
-					if ($object->statut == 3)
-					{
-						print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans('ReOpen').'</a></div>';
-					}
-
+				// Create intervention
+				if ($conf->ficheinter->enabled)
+				{
+					$langs->load("interventions");
 
-					// Create bill and Classify billed
-					if (! empty($conf->facture->enabled) && $object->statut > 0  && ! $object->billed)
+					if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfServicesLines() > 0)
 					{
-						if ($user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER))
+						if ($user->rights->ficheinter->creer)
 						{
-							print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a></div>';
+							print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/fiche.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans('AddIntervention').'</a></div>';
 						}
-						if ($user->rights->commande->creer && $object->statut > 2 && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORsKFLOW_BILL_ON_SHIPMENT))
+						else
 						{
-							print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled">'.$langs->trans("ClassifyBilled").'</a></div>';
+							print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('AddIntervention').'</a></div>';
 						}
 					}
+				}
+
+				// Reopen a closed order
+				if ($object->statut == 3)
+				{
+					print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans('ReOpen').'</a></div>';
+				}
+
 
-					// Set to shipped
-					if (($object->statut == 1 || $object->statut == 2) && $user->rights->commande->cloturer)
+				// Create bill and Classify billed
+				if (! empty($conf->facture->enabled) && $object->statut > 0  && ! $object->billed)
+				{
+					if ($user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER))
 					{
-						print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=shipped">'.$langs->trans('ClassifyShipped').'</a></div>';
+						print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a></div>';
 					}
-
-					// Clone
-					if ($user->rights->commande->creer)
+					if ($user->rights->commande->creer && $object->statut > 2 && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORsKFLOW_BILL_ON_SHIPMENT))
 					{
-						print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&amp;object=order">'.$langs->trans("ToClone").'</a></div>';
+						print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled">'.$langs->trans("ClassifyBilled").'</a></div>';
 					}
+				}
+
+				// Set to shipped
+				if (($object->statut == 1 || $object->statut == 2) && $user->rights->commande->cloturer)
+				{
+					print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=shipped">'.$langs->trans('ClassifyShipped').'</a></div>';
+				}
 
-					// Cancel order
-					if ($object->statut == 1 && $user->rights->commande->annuler)
+				// Clone
+				if ($user->rights->commande->creer)
+				{
+					print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&amp;object=order">'.$langs->trans("ToClone").'</a></div>';
+				}
+
+				// Cancel order
+				if ($object->statut == 1 && $user->rights->commande->annuler)
+				{
+					print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=cancel">'.$langs->trans('Cancel').'</a></div>';
+				}
+
+				// Delete order
+				if ($user->rights->commande->supprimer)
+				{
+					if ($numshipping == 0)
 					{
-						print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=cancel">'.$langs->trans('Cancel').'</a></div>';
+						print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>';
 					}
-
-					// Delete order
-					if ($user->rights->commande->supprimer)
+					else
 					{
-						if ($numshipping == 0)
-						{
-							print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>';
-						}
-						else
-						{
-							print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("ShippingExist").'">'.$langs->trans("Delete").'</a></div>';
-						}
+						print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("ShippingExist").'">'.$langs->trans("Delete").'</a></div>';
 					}
-
-					print '</div>';
 				}
-				print '<br>';
-			}
-
 
-			if ($action != 'presend')
-			{
-				print '<table width="100%"><tr><td width="50%" valign="top">';
-				print '<a name="builddoc"></a>'; // ancre
-
-				/*
-				 * Documents generes
-				*
-				*/
-				$comref = dol_sanitizeFileName($object->ref);
-				$file = $conf->commande->dir_output . '/' . $comref . '/' . $comref . '.pdf';
-				$relativepath = $comref.'/'.$comref.'.pdf';
-				$filedir = $conf->commande->dir_output . '/' . $comref;
-				$urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
-				$genallowed=$user->rights->commande->creer;
-				$delallowed=$user->rights->commande->supprimer;
-				$printer = false;
-				if ($user->rights->printipp->use AND $conf->printipp->enabled) $printer = true;
-				$somethingshown=$formfile->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang,$printer);
-
-				/*
-				 * Linked object block
-				*/
-				$somethingshown=$object->showLinkedObjectBlock();
-
-				print '</td><td valign="top" width="50%">';
-
-				// List of actions on element
-				include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
-				$formactions=new FormActions($db);
-				$somethingshown=$formactions->showactions($object,'order',$socid);
-
-				print '</td></tr></table>';
+				print '</div>';
 			}
+			print '<br>';
+		}
+
 
+		if ($action != 'presend')
+		{
+			print '<table width="100%"><tr><td width="50%" valign="top">';
+			print '<a name="builddoc"></a>'; // ancre
 
 			/*
-			 * Action presend
+			 * Documents generes
 			*
 			*/
-			if ($action == 'presend')
-			{
-				$ref = dol_sanitizeFileName($object->ref);
-				include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-				$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref,'/'));
-				$file=$fileparams['fullname'];
+			$comref = dol_sanitizeFileName($object->ref);
+			$file = $conf->commande->dir_output . '/' . $comref . '/' . $comref . '.pdf';
+			$relativepath = $comref.'/'.$comref.'.pdf';
+			$filedir = $conf->commande->dir_output . '/' . $comref;
+			$urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
+			$genallowed=$user->rights->commande->creer;
+			$delallowed=$user->rights->commande->supprimer;
+			$printer = false;
+			if ($user->rights->printipp->use AND $conf->printipp->enabled) $printer = true;
+			$somethingshown=$formfile->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang,$printer);
 
-				// Build document if it not exists
-				if (! $file || ! is_readable($file))
+			/*
+			 * Linked object block
+			*/
+			$somethingshown=$object->showLinkedObjectBlock();
+
+			print '</td><td valign="top" width="50%">';
+
+			// List of actions on element
+			include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
+			$formactions=new FormActions($db);
+			$somethingshown=$formactions->showactions($object,'order',$socid);
+
+			print '</td></tr></table>';
+		}
+
+
+		/*
+		 * Action presend
+		*
+		*/
+		if ($action == 'presend')
+		{
+			$ref = dol_sanitizeFileName($object->ref);
+			include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+			$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref,'/'));
+			$file=$fileparams['fullname'];
+
+			// Build document if it not exists
+			if (! $file || ! is_readable($file))
+			{
+				// Define output language
+				$outputlangs = $langs;
+				$newlang='';
+				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
+				if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
+				if (! empty($newlang))
 				{
-					// Define output language
-					$outputlangs = $langs;
-					$newlang='';
-					if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
-					if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
-					if (! empty($newlang))
-					{
-						$outputlangs = new Translate("",$conf);
-						$outputlangs->setDefaultLang($newlang);
-					}
+					$outputlangs = new Translate("",$conf);
+					$outputlangs->setDefaultLang($newlang);
+				}
 
-					$result=commande_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
-					if ($result <= 0)
-					{
-						dol_print_error($db,$result);
-						exit;
-					}
-					$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref,'/'));
-					$file=$fileparams['fullname'];
+				$result=commande_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+				if ($result <= 0)
+				{
+					dol_print_error($db,$result);
+					exit;
 				}
+				$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref,'/'));
+				$file=$fileparams['fullname'];
+			}
 
-				print '<br>';
-				print_titre($langs->trans('SendOrderByMail'));
-
-				// Cree l'objet formulaire mail
-				include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
-				$formmail = new FormMail($db);
-				$formmail->fromtype = 'user';
-				$formmail->fromid   = $user->id;
-				$formmail->fromname = $user->getFullName($langs);
-				$formmail->frommail = $user->email;
-				$formmail->withfrom=1;
-				$liste=array();
-				foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value)	$liste[$key]=$value;
-				$formmail->withto=GETPOST('sendto')?GETPOST('sendto'):$liste;
-				$formmail->withtocc=$liste;
-				$formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
-				$formmail->withtopic=$langs->trans('SendOrderRef','__ORDERREF__');
-				$formmail->withfile=2;
-				$formmail->withbody=1;
-				$formmail->withdeliveryreceipt=1;
-				$formmail->withcancel=1;
-				// Tableau des substitutions
-				$formmail->substit['__ORDERREF__']=$object->ref;
-				$formmail->substit['__SIGNATURE__']=$user->signature;
-				$formmail->substit['__PERSONALIZED__']='';
-				$formmail->substit['__CONTACTCIVNAME__']='';
-
-				$custcontact='';
-				$contactarr=array();
-				$contactarr=$object->liste_contact(-1,'external');
-
-				if (is_array($contactarr) && count($contactarr)>0) {
-					foreach($contactarr as $contact) {
-						if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) {
-							$contactstatic=new Contact($db);
-							$contactstatic->fetch($contact['id']);
-							$custcontact=$contactstatic->getFullName($langs,1);
-						}
-					}
+			print '<br>';
+			print_titre($langs->trans('SendOrderByMail'));
 
-					if (!empty($custcontact)) {
-						$formmail->substit['__CONTACTCIVNAME__']=$custcontact;
+			// Cree l'objet formulaire mail
+			include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
+			$formmail = new FormMail($db);
+			$formmail->fromtype = 'user';
+			$formmail->fromid   = $user->id;
+			$formmail->fromname = $user->getFullName($langs);
+			$formmail->frommail = $user->email;
+			$formmail->withfrom=1;
+			$liste=array();
+			foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value)	$liste[$key]=$value;
+			$formmail->withto=GETPOST('sendto')?GETPOST('sendto'):$liste;
+			$formmail->withtocc=$liste;
+			$formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
+			$formmail->withtopic=$langs->trans('SendOrderRef','__ORDERREF__');
+			$formmail->withfile=2;
+			$formmail->withbody=1;
+			$formmail->withdeliveryreceipt=1;
+			$formmail->withcancel=1;
+			// Tableau des substitutions
+			$formmail->substit['__ORDERREF__']=$object->ref;
+			$formmail->substit['__SIGNATURE__']=$user->signature;
+			$formmail->substit['__PERSONALIZED__']='';
+			$formmail->substit['__CONTACTCIVNAME__']='';
+
+			$custcontact='';
+			$contactarr=array();
+			$contactarr=$object->liste_contact(-1,'external');
+
+			if (is_array($contactarr) && count($contactarr)>0) {
+				foreach($contactarr as $contact) {
+					if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) {
+						$contactstatic=new Contact($db);
+						$contactstatic->fetch($contact['id']);
+						$custcontact=$contactstatic->getFullName($langs,1);
 					}
 				}
 
-				// Tableau des parametres complementaires
-				$formmail->param['action']='send';
-				$formmail->param['models']='order_send';
-				$formmail->param['orderid']=$object->id;
-				$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
-
-				// Init list of files
-				if (GETPOST("mode")=='init')
-				{
-					$formmail->clear_attached_files();
-					$formmail->add_attached_files($file,basename($file),dol_mimetype($file));
+				if (!empty($custcontact)) {
+					$formmail->substit['__CONTACTCIVNAME__']=$custcontact;
 				}
+			}
 
-				// Show form
-				$formmail->show_form();
+			// Tableau des parametres complementaires
+			$formmail->param['action']='send';
+			$formmail->param['models']='order_send';
+			$formmail->param['orderid']=$object->id;
+			$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
 
-				print '<br>';
+			// Init list of files
+			if (GETPOST("mode")=='init')
+			{
+				$formmail->clear_attached_files();
+				$formmail->add_attached_files($file,basename($file),dol_mimetype($file));
 			}
+
+			// Show form
+			$formmail->show_form();
+
+			print '<br>';
 		}
 	}
+}
 
 
 llxFooter();
diff --git a/htdocs/core/lib/order.lib.php b/htdocs/core/lib/order.lib.php
index dbb531cbcf4751f55a369dbe2e2feb07903cf820..8e8700ac7417a0433c1c6a1a11b5115f036e3a63 100644
--- a/htdocs/core/lib/order.lib.php
+++ b/htdocs/core/lib/order.lib.php
@@ -109,4 +109,35 @@ function commande_prepare_head($object)
     return $head;
 }
 
+/**
+ *  Return array head with list of tabs to view object informations.
+ *
+ *  @param	Object	$object		order
+ *  @return	array   	        head array with tabs
+ */
+function order_admin_prepare_head($object)
+{
+	global $langs, $conf, $user;
+
+	$h = 0;
+	$head = array();
+
+	$head[$h][0] = DOL_URL_ROOT.'/admin/order.php';
+	$head[$h][1] = $langs->trans("Miscellaneous");
+	$head[$h][2] = 'general';
+	$h++;
+
+	complete_head_from_modules($conf,$langs,$object,$head,$h,'order_admin');
+
+	$head[$h][0] = DOL_URL_ROOT.'/admin/order_extrafields.php';
+	$head[$h][1] = $langs->trans("ExtraFields");
+	$head[$h][2] = 'attributes';
+	$h++;
+
+	complete_head_from_modules($conf,$langs,$object,$head,$h,'order_admin','remove');
+
+	return $head;
+}
+
+
 ?>
diff --git a/htdocs/core/modules/supplier_order/modules_commandefournisseur.php b/htdocs/core/modules/supplier_order/modules_commandefournisseur.php
index d14d4ae5f435f35a522ef0251706273c853895f2..72268b62831ffdf6dee7146bf969f9b1392a0741 100644
--- a/htdocs/core/modules/supplier_order/modules_commandefournisseur.php
+++ b/htdocs/core/modules/supplier_order/modules_commandefournisseur.php
@@ -50,7 +50,7 @@ abstract class ModelePDFSuppliersOrders extends CommonDocGenerator
 	{
 		global $conf;
 
-		$type='supplier_order';
+		$type='order_supplier';
 		$liste=array();
 
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
diff --git a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php
index fcf0c6763f523b4e85f2643ad20ee4e9c2812320..013834fcb55e637cfe640b1fe597d482325efbf5 100644
--- a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php
+++ b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php
@@ -99,11 +99,8 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 		$this->franchise=!$mysoc->tva_assuj;
 
         // Get source company
-        //if (! is_object($object->thirdparty)) $object->fetch_thirdparty();
-        //$this->emetteur=$object->thirdparty;
-        //if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
 		$this->emetteur=$mysoc;
-        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
+		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
 
 		// Defini position des colonnes
 		$this->posxdesc=$this->marge_gauche+1;
@@ -287,7 +284,39 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 
 					// Description of product line
 					$curX = $this->posxdesc-1;
-                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,0,0,1);
+					$showpricebeforepagebreak=1;
+
+					$pdf->startTransaction();
+					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
+					$pageposafter=$pdf->getPage();
+					if ($pageposafter > $pageposbefore)	// There is a pagebreak
+					{
+						$pdf->rollbackTransaction(true);
+						$pageposafter=$pageposbefore;
+						//print $pageposafter.'-'.$pageposbefore;exit;
+						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
+						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
+						$posyafter=$pdf->GetY();
+						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
+						{
+							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
+							{
+								$pdf->AddPage('','',true);
+								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
+								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
+								$pdf->setPage($pagenb+1);
+							}
+						}
+						else
+						{
+							// We found a page break
+							$showpricebeforepagebreak=0;
+						}
+					}
+					else	// No pagebreak
+					{
+						$pdf->commitTransaction();
+					}
 
 					$nexY = $pdf->GetY();
                     $pageposafter=$pdf->getPage();
@@ -296,19 +325,19 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
 
 					// We suppose that a too long description is moved completely on next page
-					if ($pageposafter > $pageposbefore) {
+					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
 						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
 					}
 
 					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
 
 					// VAT Rate
-                    if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
-                    {
-                        $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
-                        $pdf->SetXY($this->posxtva, $curY);
-                        $pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R');
-                    }
+					if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
+					{
+						$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
+						$pdf->SetXY($this->posxtva, $curY);
+						$pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R');
+					}
 
 					// Unit price before discount
 					$pdf->SetXY($this->posxup, $curY);
@@ -335,22 +364,35 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 
 					$localtax1ligne=$object->lines[$i]->total_localtax1;
 					$localtax2ligne=$object->lines[$i]->total_localtax2;
+					$localtax1_rate=$object->lines[$i]->localtax1_tx;
+					$localtax2_rate=$object->lines[$i]->localtax2_tx;
+					$localtax1_type=$object->lines[$i]->localtax1_type;
+					$localtax2_type=$object->lines[$i]->localtax2_type;
 
 					if (! empty($object->remise_percent)) $tvaligne-=($tvaligne*$object->remise_percent)/100;
 					if (! empty($object->remise_percent)) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
 					if (! empty($object->remise_percent)) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
 
 					$vatrate=(string) $object->lines[$i]->tva_tx;
-					$localtax1rate=(string) $object->lines[$i]->localtax1_tx;
-					$localtax2rate=(string) $object->lines[$i]->localtax2_tx;
+					// TODO : store local taxes types into object lines and remove this
+					$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$mysoc);
+					if ((! isset($localtax1_type)) || $localtax1_type=='') $localtax1_type = $localtaxtmp_array[0];
+					if ((! isset($localtax2_type)) || $localtax2_type=='') $localtax2_type = $localtaxtmp_array[2];
+					//end TODO
+
+				    // retrieve global local tax
+					if ($localtax1_type == '7') $localtax1_rate = $localtaxtmp_array[1];
+					if ($localtax2_type == '7') $localtax2_rate = $localtaxtmp_array[3];
+
+					if ($localtax1_type && ($localtax1ligne != 0 || $localtax1_type == '7'))
+						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
+					if ($localtax2_type && ($localtax2ligne != 0 || $localtax2_type == '7'))
+						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
 
 					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
-					if (! isset($this->tva[$vatrate]))				$this->tva[$vatrate]='';
-					if (! isset($this->localtax1[$localtax1rate]))	$this->localtax1[$localtax1rate]='';
-					if (! isset($this->localtax2[$localtax2rate]))	$this->localtax2[$localtax2rate]='';
+					if (! isset($this->tva[$vatrate])) 				$this->tva[$vatrate]='';
 					$this->tva[$vatrate] += $tvaligne;
-					$this->localtax1[$localtax1rate]+=$localtax1ligne;
-					$this->localtax2[$localtax2rate]+=$localtax2ligne;
+
 
 					// Add line
 					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
@@ -379,6 +421,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 						$pagenb++;
 						$pdf->setPage($pagenb);
 						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
 					}
 					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
 					{
@@ -395,6 +438,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 						$pdf->AddPage();
 						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
 						$pagenb++;
+						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
 					}
 				}
 
@@ -422,8 +466,8 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 					$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
 				}
 
-                // Pied de page
-				$this->_pagefoot($pdf, $object, $outputlangs);
+				// Pied de page
+				$this->_pagefoot($pdf,$object,$outputlangs);
 				$pdf->AliasNbPages();
 
 				$pdf->Close();
@@ -485,128 +529,55 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 	function _tableau_info(&$pdf, $object, $posy, $outputlangs)
 	{
 	    global $conf;
-
 	    $default_font_size = pdf_getPDFFontSize($outputlangs);
 
-	    $pdf->SetFont('','', $default_font_size - 1);
+        // If France, show VAT mention if not applicable
+		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
+		{
+			$pdf->SetFont('','B', $default_font_size - 2);
+			$pdf->SetXY($this->marge_gauche, $posy);
+			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
 
-	    // If France, show VAT mention if not applicable
-	    /*if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
-	    {
-	        $pdf->SetFont('','B', $default_font_size - 2);
-	        $pdf->SetXY($this->marge_gauche, $posy);
-	        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
+			$posy=$pdf->GetY()+4;
+		}
 
-	        $posy=$pdf->GetY()+4;
-	    }*/
+		$posxval=52;
 
 	    // Show payments conditions
-	    if ($object->cond_reglement_code || $object->cond_reglement)
+	    if (!empty($object->cond_reglement_code) || $object->cond_reglement)
 	    {
 	        $pdf->SetFont('','B', $default_font_size - 2);
 	        $pdf->SetXY($this->marge_gauche, $posy);
 	        $titre = $outputlangs->transnoentities("PaymentConditions").':';
 	        $pdf->MultiCell(80, 4, $titre, 0, 'L');
 
-	        $pdf->SetFont('','', $default_font_size - 2);
-	        $pdf->SetXY(52, $posy);
-	        $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
-	        $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
-	        $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L');
+			$pdf->SetFont('','', $default_font_size - 2);
+			$pdf->SetXY($posxval, $posy);
+			$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
+			$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
+			$pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L');
 
 	        $posy=$pdf->GetY()+3;
 	    }
 
-        // Check a payment mode is defined
-        /* Not used with orders
-		if (empty($object->mode_reglement_code)
-        	&& ! $conf->global->FACTURE_CHQ_NUMBER
-        	&& ! $conf->global->FACTURE_RIB_NUMBER)
-		{
-            $pdf->SetXY($this->marge_gauche, $posy);
-            $pdf->SetTextColor(200,0,0);
-            $pdf->SetFont('','B', $default_font_size - 2);
-            $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
-            $pdf->SetTextColor(0,0,0);
-
-            $posy=$pdf->GetY()+1;
-        }
-		*/
-
-	    // Show payment mode
-        if ($object->mode_reglement_code
-	    //    && $object->mode_reglement_code != 'CHQ'
-	    //    && $object->mode_reglement_code != 'VIR'
-	    )
+      	// Show payment mode
+        if (!empty($object->mode_reglement_code))
         {
-            $pdf->SetFont('','B', $default_font_size - 2);
-            $pdf->SetXY($this->marge_gauche, $posy);
-            $titre = $outputlangs->transnoentities("PaymentMode").':';
-            $pdf->MultiCell(80, 4, $titre, 0, 'L');
-
-            $pdf->SetFont('','', $default_font_size - 2);
-	        $pdf->SetXY(52, $posy);
-            $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
-            $pdf->MultiCell(80, 4, $lib_mode_reg,0,'L');
-
-            $posy=$pdf->GetY()+2;
-        }
-
-        // Show payment mode CHQ
-        /*
-        if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
-        {
-            // Si mode reglement non force ou si force a CHQ
-            if (! empty($conf->global->FACTURE_CHQ_NUMBER))
-            {
-                if ($conf->global->FACTURE_CHQ_NUMBER > 0)
-                {
-                    $account = new Account($this->db);
-                    $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
-
-                    $pdf->SetXY($this->marge_gauche, $posy);
-                    $pdf->SetFont('','B', $default_font_size - 3);
-                    $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio).':',0,'L',0);
-                    $posy=$pdf->GetY()+1;
-                    $pdf->SetXY($this->marge_gauche, $posy);
-                    $pdf->SetFont('','', $default_font_size - 3);
-                    $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
-                    $posy=$pdf->GetY()+2;
-                }
-                if ($conf->global->FACTURE_CHQ_NUMBER == -1)
-                {
-                    $pdf->SetXY($this->marge_gauche, $posy);
-                    $pdf->SetFont('','B', $default_font_size - 3);
-                    $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedToShort').' '.$outputlangs->convToOutputCharset($this->emetteur->name).' '.$outputlangs->transnoentities('SendTo').':',0,'L',0);
-                    $posy=$pdf->GetY()+1;
-
-                    $pdf->SetXY($this->marge_gauche, $posy);
-                    $pdf->SetFont('','', $default_font_size - 3);
-                    $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
-                    $posy=$pdf->GetY()+2;
-                }
-            }
-        }
-
-        // If payment mode not forced or forced to VIR, show payment with BAN
-        if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
-        {
-            if (! empty($conf->global->FACTURE_RIB_NUMBER))
-            {
-                $account = new Account($this->db);
-                $account->fetch($conf->global->FACTURE_RIB_NUMBER);
-
-                $curx=$this->marge_gauche;
-                $cury=$posy;
+        	$pdf->SetFont('','B', $default_font_size - 2);
+        	$pdf->SetXY($this->marge_gauche, $posy);
+        	$titre = $outputlangs->transnoentities("PaymentMode").':';
+        	$pdf->MultiCell(80, 5, $titre, 0, 'L');
 
-                $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
+        	$pdf->SetFont('','', $default_font_size - 2);
+        	$pdf->SetXY($posxval, $posy);
+        	$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
+        	$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
 
-                $posy+=2;
-            }
+        	$posy=$pdf->GetY()+2;
         }
-		*/
 
-	    return $posy;
+		
+		return $posy;
 	}
 
 	/**
@@ -990,6 +961,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
 		{
 			$pdf->SetTextColor(0,0,60);
 			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date_commande,"day",false,$outputlangs,true), '', 'R');
+			$pdf->MultiCell(190, 3, $outputlangs->transnoentities("DateDeliveryPlanned")." : " . dol_print_date($object->date_livraison,"day",false,$outputlangs,true), '', 'R');
 		}
 		else
 		{
diff --git a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql
index 0c95236b1d51223526ba14a4262477706f311419..fef019afd87da14a38ae99c5c1cbe936bfe5aa5e 100755
--- a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql
+++ b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql
@@ -154,6 +154,7 @@ ALTER TABLE llx_propaldet MODIFY COLUMN localtax2_type varchar(10)	NOT NULL DEFA
 UPDATE llx_c_tva set localtax1=0, localtax1_type='0' where localtax1_type = '7';
 UPDATE llx_c_tva set localtax2=0, localtax2_type='0' where localtax2_type = '7';
 
+ALTER TABLE llx_facture_fourn_det ADD COLUMN info_bits integer NOT NULL DEFAULT 0 after date_end;
 
 ALTER TABLE llx_actioncomm ADD COLUMN code varchar(32) NULL after fk_action;
 
@@ -210,10 +211,12 @@ ALTER TABLE llx_user ADD COLUMN   fk_state          integer        DEFAULT 0;
 ALTER TABLE llx_user ADD COLUMN   fk_country        integer        DEFAULT 0;
 ALTER TABLE llx_product_price ADD COLUMN import_key varchar(14) AFTER price_by_qty;
 
-
+DROP TABLE llx_printer_ipp;
 CREATE TABLE llx_printer_ipp 
 (
 	rowid int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
+	tms 	timestamp,
+	datec 	datetime,
 	printer_name text NOT NULL, 
 	printer_location text NOT NULL,
 	printer_uri varchar(256) NOT NULL,
@@ -224,11 +227,19 @@ CREATE TABLE llx_printer_ipp
 
 ALTER TABLE llx_socpeople ADD COLUMN ref_ext varchar(128) after entity;
 
+create table llx_commande_extrafields
+(
+  rowid                     integer AUTO_INCREMENT PRIMARY KEY,
+  tms                       timestamp,
+  fk_object                 integer NOT NULL,
+  import_key                varchar(14)
+) ENGINE=innodb;
+ALTER TABLE llx_commande_extrafields ADD INDEX idx_commande_extrafields (fk_object);
+
 ALTER TABLE llx_socpeople ADD COLUMN note_public text after note;
 ALTER TABLE llx_societe ADD COLUMN note_public text after note;
 
+ALTER TABLE llx_facture_fourn_det ADD COLUMN info_bits integer NOT NULL DEFAULT 0 after date_end;
 ALTER TABLE llx_actioncomm ADD COLUMN transparency integer after fk_user_action;
 
-ALTER TABLE llx_facture_fourn_det ADD COLUMN info_bits integer DEFAULT 0;
-
 INSERT INTO llx_c_action_trigger (rowid,code,label,description,elementtype,rang) VALUES (29,'FICHINTER_SENTBYMAIL','Intervention sent by mail','Executed when a intervention is sent by mail','ficheinter',29);
diff --git a/htdocs/install/mysql/tables/llx_commande_extrafields.key.sql b/htdocs/install/mysql/tables/llx_commande_extrafields.key.sql
new file mode 100755
index 0000000000000000000000000000000000000000..74e8820ef2410145d07ec02457a34884c09d7f2f
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_commande_extrafields.key.sql
@@ -0,0 +1,20 @@
+-- ===================================================================
+-- Copyright (C) 2013 Jean-Francois FERRY	<jfefe@aternatik.fr>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ===================================================================
+
+
+ALTER TABLE llx_commande_extrafields ADD INDEX idx_commande_extrafields (fk_object);
diff --git a/htdocs/install/mysql/tables/llx_commande_extrafields.sql b/htdocs/install/mysql/tables/llx_commande_extrafields.sql
new file mode 100755
index 0000000000000000000000000000000000000000..44ca056b8492f16fcaf42d1265789b4174b1c506
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_commande_extrafields.sql
@@ -0,0 +1,26 @@
+-- ========================================================================
+-- Copyright (C) 2013 Florian Henry  <florian.henry@open-concept.pro>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+--
+-- ========================================================================
+
+create table llx_commande_extrafields
+(
+  rowid                     integer AUTO_INCREMENT PRIMARY KEY,
+  tms                       timestamp,
+  fk_object                 integer NOT NULL,
+  import_key                varchar(14)                          		-- import key
+) ENGINE=innodb;
+
diff --git a/htdocs/install/mysql/tables/llx_facture_fourn.key.sql b/htdocs/install/mysql/tables/llx_facture_fourn.key.sql
index 8bb0db5a552288f5ac783be774b904706bf8f2ef..481974a6c4dae668ebc42edbdef0110f77f3941b 100644
--- a/htdocs/install/mysql/tables/llx_facture_fourn.key.sql
+++ b/htdocs/install/mysql/tables/llx_facture_fourn.key.sql
@@ -18,7 +18,7 @@
 -- ============================================================================
 
 
-ALTER TABLE llx_facture_fourn ADD UNIQUE INDEX uk_facture_fourn_ref (facnumber, fk_soc, entity);
+ALTER TABLE llx_facture_fourn ADD UNIQUE INDEX uk_facture_fourn_ref (ref, fk_soc, entity);
 
 ALTER TABLE llx_facture_fourn ADD INDEX idx_facture_fourn_date_lim_reglement (date_lim_reglement);
 
diff --git a/htdocs/install/mysql/tables/llx_printer_ipp.sql b/htdocs/install/mysql/tables/llx_printer_ipp.sql
index 0e030b24c95504f197e5725047bcb52e04ad96b0..cb898432fe59cb920e7fb72e8de30ae6f3fba385 100644
--- a/htdocs/install/mysql/tables/llx_printer_ipp.sql
+++ b/htdocs/install/mysql/tables/llx_printer_ipp.sql
@@ -18,11 +18,13 @@
 
 CREATE TABLE llx_printer_ipp 
 (
-	rowid int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
-	printer_name text NOT NULL, 
-	printer_location text NOT NULL,
-	printer_uri varchar(256) NOT NULL,
-	copy int(11) NOT NULL DEFAULT '1',
-	module varchar(16) NOT NULL,
-	login varchar(32) NOT NULL,
+ rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ tms 	timestamp,
+ datec 	datetime,
+ printer_name text NOT NULL, 
+ printer_location text NOT NULL,
+ printer_uri varchar(256) NOT NULL,
+ copy integer NOT NULL DEFAULT '1',
+ module varchar(16) NOT NULL,
+ login varchar(32) NOT NULL
 )ENGINE=innodb;
diff --git a/htdocs/install/pgsql/functions/functions.sql b/htdocs/install/pgsql/functions/functions.sql
index b1f9282b6bf664dc4d1935aa96a10544ff8ef442..697fef486e29c1e31b353887d20de0cfc7ee0aaa 100644
--- a/htdocs/install/pgsql/functions/functions.sql
+++ b/htdocs/install/pgsql/functions/functions.sql
@@ -117,3 +117,4 @@ CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_user FOR EACH ROW EX
 CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_user_extrafields FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
 CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_usergroup FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
 CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_cronjob FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();
+CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_printer_ipp FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms();