diff --git a/htdocs/commissions/css/commissions.css b/htdocs/commissions/css/commissions.css
deleted file mode 100644
index 72eeed1895c26b9be4fb05a167bca564f3da0dd6..0000000000000000000000000000000000000000
--- a/htdocs/commissions/css/commissions.css
+++ /dev/null
@@ -1,3 +0,0 @@
-div.mainmenu.commissions {
-  background : url('../img/commissions.png') no-repeat 20px 0;
-}
\ No newline at end of file
diff --git a/htdocs/commissions/img/object_commissions.png b/htdocs/commissions/img/object_commissions.png
deleted file mode 100644
index 39f09967046b32c8563a44af9da1b0b454175626..0000000000000000000000000000000000000000
Binary files a/htdocs/commissions/img/object_commissions.png and /dev/null differ
diff --git a/htdocs/commissions/index.php b/htdocs/commissions/index.php
index 69e799c99f102c28dc233388a566cb0ed5da288d..65e2ad70b212b492ff599c6e76da2187b86edee4 100644
--- a/htdocs/commissions/index.php
+++ b/htdocs/commissions/index.php
@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2012      Christophe Battarel  <christophe.battarel@altairis.fr>
+/* Copyright (C) 2012	Christophe Battarel	<christophe.battarel@altairis.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
@@ -16,28 +16,27 @@
  */
 
 /**
- *	\file       htdocs/custom/commissions/index.php
+ *	\file       htdocs/commissions/index.php
  *	\ingroup    commissions
  *	\brief      Page des commissions par agent commercial
- *	\version    $Id: facture.php,v 1.84 2011/08/08 16:07:47 eldy Exp $
  */
 
 require("../main.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
 require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
-require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");  
-if ($conf->marges->enabled) 
-  require_once(DOL_DOCUMENT_ROOT."/marges/lib/marges.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
+if (! empty($conf->margin->enabled))
+	require_once(DOL_DOCUMENT_ROOT."/margin/lib/margins.lib.php");
 
 $langs->load("companies");
 $langs->load("bills");
 $langs->load("products");
-if ($conf->marges->enabled) 
-  $langs->load("marges");
 $langs->load("commissions");
-																							 
+if (! empty($conf->margin->enabled))
+	$langs->load("margins");
+
 // Security check
-$agentid = isset($_REQUEST["agentid"])?$_REQUEST["agentid"]:'';
+$agentid = GETPOST('agentid','int');
 
 $mesg = '';
 
@@ -57,7 +56,7 @@ if (!empty($_POST['enddatemonth']))
 /*
  * View
  */
-                                                              
+
 $userstatic = new User($db);
 $companystatic = new Societe($db);
 $invoicestatic=new Facture($db);
@@ -65,10 +64,10 @@ $invoicestatic=new Facture($db);
 $form = new Form($db);
 
 llxHeader('',$langs->trans("Commissions"));
-                                                               
+
 $text=$langs->trans("Commissions");
 print_fiche_titre($text);
-                                                               
+
 print '<form method="post" name="sel">';
 print '<table class="border" width="100%">';
 
@@ -78,7 +77,7 @@ if ($agentid > 0) {
       print '<td colspan="4">';
       print $form->select_dolusers($selected=$agentid,$htmlname='agentid',$show_empty=1,$exclude='',$disabled=0,$include='',$enableonly='');
       print '</td></tr>';
-      
+
       if (! $sortorder) $sortorder="ASC";
       if (! $sortfield) $sortfield="s.nom";
 }
@@ -91,7 +90,7 @@ else {
   if (! $sortfield) $sortfield="u.login";
 }
 
-// Date d�but
+// Date d�but
 print '<td>'.$langs->trans('StartDate').'</td>';
 print '<td width="20%">';
 $form->select_date($startdate,'startdate','','',1,"sel",1,1);
@@ -181,25 +180,25 @@ if ($result)
 
   print '<br>';
 	print_barre_liste($langs->trans("CommissionDetails"),$page,$_SERVER["PHP_SELF"],"&amp;socid=$societe->id",$sortfield,$sortorder,'',$num,0,'');
-	
+
 	$i = 0;
 	print "<table class=\"noborder\" width=\"100%\">";
 
 	print '<tr class="liste_titre">';
-	if ($agentid > 0) 
+	if ($agentid > 0)
    	print_liste_field_titre($langs->trans("Customer"),$_SERVER["PHP_SELF"],"s.nom","","&amp;agentid=".$_REQUEST["agentid"],'align="center"',$sortfield,$sortorder);
   else
   	print_liste_field_titre($langs->trans("CommercialAgent"),$_SERVER["PHP_SELF"],"u.login","","&amp;agentid=".$_REQUEST["agentid"],'align="center"',$sortfield,$sortorder);
-  	
+
   // product commission
   if ($conf->global->COMMISSION_BASE == "MARGES")
 	  print_liste_field_titre($langs->trans("ProductMargin"),$_SERVER["PHP_SELF"],"productBase","","&amp;agentid=".$_REQUEST["agentid"],'align="right"',$sortfield,$sortorder);
   elseif ($conf->global->COMMISSION_BASE == "CA")
 	  print_liste_field_titre($langs->trans("ProductCA"),$_SERVER["PHP_SELF"],"productBase","","&amp;agentid=".$_REQUEST["agentid"],'align="right"',$sortfield,$sortorder);
-	
+
   print_liste_field_titre($langs->trans("CommissionRate"),$_SERVER["PHP_SELF"],"","","&amp;agentid=".$_REQUEST["agentid"],'align="right"',$sortfield,$sortorder);
 	print_liste_field_titre($langs->trans("ProductCommission"),$_SERVER["PHP_SELF"],"","","&amp;agentid=".$_REQUEST["agentid"],'align="right"',$sortfield,$sortorder);
-	
+
   // service commission
   if ($conf->global->COMMISSION_BASE == "MARGES")
   	print_liste_field_titre($langs->trans("ServiceMargin"),$_SERVER["PHP_SELF"],"serviceBase","","&amp;agentid=".$_REQUEST["agentid"],'align="right"',$sortfield,$sortorder);
@@ -210,7 +209,7 @@ if ($result)
 	print_liste_field_titre($langs->trans("ServiceCommission"),$_SERVER["PHP_SELF"],"","","&amp;agentid=".$_REQUEST["agentid"],'align="right"',$sortfield,$sortorder);
 	// total commission
 	print_liste_field_titre($langs->trans("TotalCommission"),$_SERVER["PHP_SELF"],"","","&amp;agentid=".$_REQUEST["agentid"],'align="right"',$sortfield,$sortorder);
-	
+
 	print "</tr>\n";
 
 	$cumul_base_produit = 0;
@@ -222,7 +221,7 @@ if ($result)
 		$var=True;
 		while ($i < $num && $i < $conf->liste_limit)
 		{
-			$objp = $db->fetch_object($result);     
+			$objp = $db->fetch_object($result);
 
 			$var=!$var;
 
@@ -288,25 +287,23 @@ else
 }
 $db->free($result);
 
+
+llxFooter();
 $db->close();
-   
-llxFooter('$Date: 2011/08/08 16:07:47 $ - $Revision: 1.84 $');
 ?>
 <script type="text/javascript">
-
 $(document).ready(function() {
-  
-  $("#agentid").change(function() {    
+
+  $("#agentid").change(function() {
      $("div.fiche form").submit();
   });
-  
-  $("#selIncluded").change(function() {    
+
+  $("#selIncluded").change(function() {
      $("div.fiche form").submit();
   });
-  
+
 	$("#totalBase").html("<?php echo price($cumul_base_produit + $cumul_base_service); ?>");
 	$("#totalCommission").html("<?php echo price($cumul_commission_produit + $cumul_commission_service); ?>");
 
 });
-
 </script>
\ No newline at end of file
diff --git a/htdocs/commissions/lib/commissions.lib.php b/htdocs/commissions/lib/commissions.lib.php
index 65d9a7e69f9935d5228a996eddcd82492a9ff2f3..ca71d41536cde6f2e5594ac6b1b1d457343e0484 100644
--- a/htdocs/commissions/lib/commissions.lib.php
+++ b/htdocs/commissions/lib/commissions.lib.php
@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2012      Christophe Battarel  <christophe.battarel@altairis.fr>
+/* Copyright (C) 2012	Christophe Battarel	<christophe.battarel@altairis.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
@@ -12,14 +12,12 @@
  * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- * or see http://www.gnu.org/
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /**
- *	\file			/marges/lib/commissions.lib.php
- *  \ingroup		marges
+ *	\file			/htdocs/commissions/lib/commissions.lib.php
+ *  \ingroup		commissions
  *  \brief			Library for common commissions functions
  */
 
@@ -35,7 +33,7 @@ function commissions_admin_prepare_head()
 	$h = 0;
 	$head = array();
 
-	$head[$h][0] = dol_buildpath("/commissions/admin/commissions.php",1);
+	$head[$h][0] = DOL_URL_ROOT.'/commissions/admin/commissions.php';
 	$head[$h][1] = $langs->trans("Parameters");
 	$head[$h][2] = 'parameters';
 	$h++;
@@ -44,9 +42,9 @@ function commissions_admin_prepare_head()
     // Entries must be declared in modules descriptor with line
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
     // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to remove a tab
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'margesadmin');
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'commissionsadmin');
 
     return $head;
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php
index d64b5b98916c805806acc5ba69d721df511cf060..494867ec94f57dc15989122e626ab0c5799911e2 100755
--- a/htdocs/core/class/commondocgenerator.class.php
+++ b/htdocs/core/class/commondocgenerator.class.php
@@ -78,10 +78,10 @@ abstract class CommonDocGenerator
         {
         	$mysoc->country=$outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code);
         }
-        if (empty($mysoc->state) && ! empty($mysoc->state_code))
-        {
-        	$mysoc->state=getState($mysoc->state_code,0);
-        }
+        if (empty($mysoc->state) && ! empty($mysoc->state_code))
+        {
+        	$mysoc->state=getState($mysoc->state_code,0);
+        }
 
         $logotouse=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
 
diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php
index 34297a7c1fc4e9bd4892d9ad271082eeb07094f5..d43aee672caf796d7da8236dcfca58e175efe489 100644
--- a/htdocs/core/db/pgsql.class.php
+++ b/htdocs/core/db/pgsql.class.php
@@ -380,7 +380,7 @@ class DoliDBPgsql
 		if (! $name) $name="postgres";    // When try to connect using admin user
 
 		// try first Unix domain socket (local)
-		if ((empty($host) || $host == "socket") && ! defined('NOLOCALSOCKETPGCONNECT'))
+		if ((! empty($host) && $host == "socket") && ! defined('NOLOCALSOCKETPGCONNECT'))
 		{
 			$con_string = "dbname='".$name."' user='".$login."' password='".$passwd."'";    // $name may be empty
 			$this->db = pg_connect($con_string);
diff --git a/htdocs/core/modules/modCommissions.class.php b/htdocs/core/modules/modCommissions.class.php
index 18193953b5c19194231cabaf109d379e4f6ea1c1..b03fa23c6d1da18c26ab3ea2f17c661a44be7376 100644
--- a/htdocs/core/modules/modCommissions.class.php
+++ b/htdocs/core/modules/modCommissions.class.php
@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2012      Christophe Battarel  <christophe.battarel@altairis.fr>
+/* Copyright (C) 2012	Christophe Battarel	<christophe.battarel@altairis.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
@@ -16,14 +16,12 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-/**     \defgroup   mymodule     Module MyModule
- *      \brief      Module to manage commissions
- */
-
 /**
- *      \file       htdocs/includes/modules/modCommissions.class.php
- *      \ingroup    commissions
- *      \brief      Description and activation file for module Commissions
+ * 	\defgroup   commissions     Module Commissions
+ * 	\brief      Example of a module descriptor.
+ * 	\file       htdocs/core/modules/modCommissions.class.php
+ * 	\ingroup    commissions
+ * 	\brief      Description and activation file for module Commissions
  */
 include_once(DOL_DOCUMENT_ROOT ."/core/modules/DolibarrModules.class.php");
 
@@ -34,11 +32,11 @@ include_once(DOL_DOCUMENT_ROOT ."/core/modules/DolibarrModules.class.php");
 class modCommissions extends DolibarrModules
 {
     /**
-     *   Constructor. Define names, constants, directories, boxes, permissions
+     * 	Constructor
      *
-     *   @param		DoliDB		$db		Database handler
+     * 	@param	DoliDB	$db		Database handler
      */
-	function modCommissions($db)
+	function __construct($db)
 	{
 		$this->db = $db;
 
@@ -52,7 +50,7 @@ class modCommissions extends DolibarrModules
 		// It is used to group modules in module setup page
 		$this->family = "financial";
 		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
-		$this->name = mb_ereg_replace('^mod','',get_class($this), "i");
+		$this->name = preg_replace('/^mod/i','',get_class($this));
 		// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
 		$this->description = "Commissions management";
 		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
@@ -67,43 +65,27 @@ class modCommissions extends DolibarrModules
 
 		// Data directories to create when module is enabled.
 		$this->dirs = array();
-		//$this->dirs[0] = DOL_DATA_ROOT.'/Marges';
-        //$this->dirs[1] = DOL_DATA_ROOT.'/mymodule/temp;
-
-		// Relative path to module style sheet if exists. Example: '/mymodule/mycss.css'.
-		$this->style_sheet = '/commissions/css/commissions.css';
 
 		// Config pages. Put here list of php page names stored in admmin directory used to setup module.
 		$this->config_page_url = array("commissions.php");
 
 		// Dependencies
-		$this->depends = array("modFacture", "modMarges");		// List of modules id that must be enabled if this module is enabled
+		$this->depends = array("modFacture", "modMargin");		// List of modules id that must be enabled if this module is enabled
 		$this->requiredby = array();	// List of modules id to disable if this one is disabled
-		$this->phpmin = array(4,1);					// Minimum version of PHP required by module
-		$this->need_dolibarr_version = array(3,1);	// Minimum version of Dolibarr required by module
+		$this->phpmin = array(5,1);					// Minimum version of PHP required by module
+		$this->need_dolibarr_version = array(3,2);	// Minimum version of Dolibarr required by module
 		$this->langfiles = array("commissions");
 
 		// Constants
 		$this->const = array();			// List of particular constants to add when module is enabled
-    //$this->const = array(    0=>array('MAIN_MODULE_MARGES_HOOKS', 'chaine', 'propalcard',    'Hooks list for displaying Marges data on entity lists', 0, 'current', 1)    );
 
 		// New pages on tabs
-		$this->tabs = array(
-		);
-
+		$this->tabs = array();
 
 		// Boxes
 		$this->boxes = array();			// List of boxes
 		$r=0;
 
-		// Add here list of php file(s) stored in includes/boxes that contains class to show a box.
-		// Example:
-        //$this->boxes[$r][1] = "myboxa.php";
-    	//$r++;
-        //$this->boxes[$r][1] = "myboxb.php";
-    	//$r++;
-
-
 		// Permissions
 		$this->rights = array();		// Permission array used by this module
 		$r=0;
@@ -122,8 +104,9 @@ class modCommissions extends DolibarrModules
 		$this->menu = array();			// List of menus to add
 		$r = 0;
 
-    // left menu entry
-    $this->menu[$r]=array(	'fk_menu'=>0,			// Put 0 if this is a top menu
+		// left menu entry
+		$this->menu[$r]=array(
+				'fk_menu'=>0,			// Put 0 if this is a top menu
     			'type'=>'top',			// This is a Top menu entry
     			'titre'=>'Commissions',
     			'mainmenu'=>'commissions',
@@ -135,8 +118,7 @@ class modCommissions extends DolibarrModules
     			'perms'=>'1',			// Use 'perms'=>'$user->rights->monmodule->level1->level2' if you want your menu with a permission rules
     			'target'=>'',
     			'user'=>2);				// 0=Menu for internal users, 1=external users, 2=both
-    $r++;
-
+		$r++;
  	}
 
 	/**
diff --git a/htdocs/langs/fr_FR/commissions.lang b/htdocs/langs/fr_FR/commissions.lang
index a38a9e5861263ea10e5a30c349af4366dbd952e5..350b12a809999558bffbe4d1189571642377b473 100644
--- a/htdocs/langs/fr_FR/commissions.lang
+++ b/htdocs/langs/fr_FR/commissions.lang
@@ -1,4 +1,4 @@
-# Dolibarr language file - fr_FR - marges
+# Dolibarr language file - fr_FR - commissions
 CHARSET=UTF-8
 
 commissionsSetup=Paramétrage de la gestion des commissions
diff --git a/htdocs/commissions/img/commissions.png b/htdocs/theme/amarok/img/commissions.png
similarity index 100%
rename from htdocs/commissions/img/commissions.png
rename to htdocs/theme/amarok/img/commissions.png
diff --git a/htdocs/theme/auguria/img/commissions.png b/htdocs/theme/auguria/img/commissions.png
new file mode 100644
index 0000000000000000000000000000000000000000..b1e139e3fbad0fd57430b5f2e9e2639a7ef92a8c
Binary files /dev/null and b/htdocs/theme/auguria/img/commissions.png differ
diff --git a/htdocs/theme/bureau2crea/img/commissions.png b/htdocs/theme/bureau2crea/img/commissions.png
new file mode 100644
index 0000000000000000000000000000000000000000..b1e139e3fbad0fd57430b5f2e9e2639a7ef92a8c
Binary files /dev/null and b/htdocs/theme/bureau2crea/img/commissions.png differ
diff --git a/htdocs/theme/cameleo/img/commissions.png b/htdocs/theme/cameleo/img/commissions.png
new file mode 100644
index 0000000000000000000000000000000000000000..b1e139e3fbad0fd57430b5f2e9e2639a7ef92a8c
Binary files /dev/null and b/htdocs/theme/cameleo/img/commissions.png differ
diff --git a/htdocs/theme/eldy/img/commissions.png b/htdocs/theme/eldy/img/commissions.png
new file mode 100644
index 0000000000000000000000000000000000000000..b1e139e3fbad0fd57430b5f2e9e2639a7ef92a8c
Binary files /dev/null and b/htdocs/theme/eldy/img/commissions.png differ