diff --git a/htdocs/admin/limits.php b/htdocs/admin/limits.php
index 65d4ad8f95f..3b8458f3965 100644
--- a/htdocs/admin/limits.php
+++ b/htdocs/admin/limits.php
@@ -252,6 +252,54 @@ else
}
+// Important: can debug rounding, to simulate the rounded total
+/*
+print '
'.$langs->trans("VATRoundedByLine").' ('.$langs->trans("DolibarrDefault").')
';
+
+foreach($vat_rates as $vat)
+{
+ for ($qty=1; $qty<=2; $qty++)
+ {
+ $s1=10/3;
+ $s2=2/7;
+
+ // Round by line
+ $tmparray1=calcul_price_total(1,$qty*price2num($s1,'MU'),0,$vat,0,0,0,'HT',0);
+ $tmparray2=calcul_price_total(1,$qty*price2num($s2,'MU'),0,$vat,0,0,0,'HT',0);
+ $total_ht = $tmparray1[0] + $tmparray2[0];
+ $total_tva = $tmparray1[1] + $tmparray2[1];
+ $total_ttc = $tmparray1[2] + $tmparray2[2];
+
+ print $langs->trans("UnitPriceOfProduct").": ".(price2num($s1,'MU') + price2num($s2,'MU'));
+ print " x ".$langs->trans("Quantity").": ".$qty;
+ print " - ".$langs->trans("VAT").": ".$vat.'%';
+ print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$total_ht.' / '.$total_tva.' / '.$total_ttc."
\n";
+ }
+}
+
+print '
'.$langs->trans("VATRoundedOnTotal").'
';
+
+foreach($vat_rates as $vat)
+{
+ for ($qty=1; $qty<=2; $qty++)
+ {
+ $s1=10/3;
+ $s2=2/7;
+
+ // Global round
+ $subtotal_ht = (($qty*price2num($s1,'MU')) + ($qty*price2num($s2,'MU')));
+ $tmparray3=calcul_price_total(1,$subtotal_ht,0,$vat,0,0,0,'HT',0);
+ $total_ht = $tmparray3[0];
+ $total_tva = $tmparray3[1];
+ $total_ttc = $tmparray3[2];
+
+ print $langs->trans("UnitPriceOfProduct").": ".price2num($s1+$s2,'MU');
+ print " x ".$langs->trans("Quantity").": ".$qty;
+ print " - ".$langs->trans("VAT").": ".$vat.'%';
+ print " -> ".$langs->trans("TotalPriceAfterRounding").": ".$total_ht.' / '.$total_tva.' / '.$total_ttc."
\n";
+ }
+}
+*/
llxFooter();
diff --git a/htdocs/core/ajax/constantonoff.php b/htdocs/core/ajax/constantonoff.php
index c6aeab1ac61..1231b4ff9eb 100644
--- a/htdocs/core/ajax/constantonoff.php
+++ b/htdocs/core/ajax/constantonoff.php
@@ -1,5 +1,5 @@
+/* Copyright (C) 2011-2012 Regis Houssin
*
* 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
@@ -51,11 +51,11 @@ if((isset($_GET['action']) && ! empty($_GET['action'])) && (isset($_GET['name'])
{
if ($_GET['action'] == 'set')
{
- dolibarr_set_const($db, $_GET['name'], 1, 'chaine', 0, '', $conf->entity);
+ dolibarr_set_const($db, GETPOST('name','alpha'), 1, 'chaine', 0, '', GETPOST('entity','int'));
}
else if ($_GET['action'] == 'del')
{
- dolibarr_del_const($db, $_GET['name'], $conf->entity);
+ dolibarr_del_const($db, GETPOST('name','alpha'), GETPOST('entity','int'));
}
}
}
diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php
index bd254742731..c7083dcba99 100644
--- a/htdocs/core/class/conf.class.php
+++ b/htdocs/core/class/conf.class.php
@@ -191,28 +191,19 @@ class Conf
$this->modules[]=$module;
}
}
- // Sharings between entities
- else if ($value && preg_match('/^MULTICOMPANY_([A-Z_]+)_SHARING$/',$key,$reg))
- {
- $module=strtolower($reg[1]);
- $multicompany_sharing[$module]=$value;
- }
}
$i++;
}
- // Sharings between entities
- if (! empty($this->multicompany->enabled) && ! empty($multicompany_sharing))
+ // Load shared elements between entities
+ if (! empty($this->multicompany->enabled))
{
$ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php');
if ($ret)
{
$mc = new ActionsMulticompany($db);
-
- foreach($multicompany_sharing as $key => $value)
- {
- $this->entities[$key]=$mc->check_entity($value);
- }
+ $this->multicompany->entity = $mc->loadEntity();
+ $this->entities = $mc->loadSharedElements();
}
}
}
diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php
index 41efdc2ef3c..c735baee1de 100644
--- a/htdocs/core/lib/admin.lib.php
+++ b/htdocs/core/lib/admin.lib.php
@@ -463,7 +463,7 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE name = ".$db->encrypt($name,1);
- if ($entity > 0) $sql.= " AND entity = ".$entity;
+ if ($entity >= 0) $sql.= " AND entity = ".$entity;
dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql);
diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php
index 42df2a82211..e01ae8ef04e 100644
--- a/htdocs/core/lib/ajax.lib.php
+++ b/htdocs/core/lib/ajax.lib.php
@@ -218,13 +218,16 @@ function ajax_combobox($htmlname)
/**
* On/off button for constant
*
- * @param code Name of constant
- * @param input Input element
+ * @param string $code Name of constant
+ * @param array $input Input element
+ * @param int $entity Entity to set
* TODO add different method for other input (show/hide, disable, ..)
*/
-function ajax_constantonoff($code,$input=array())
+function ajax_constantonoff($code,$input=array(),$entity=false)
{
global $conf, $langs;
+
+ $entity = ((! empty($entity) && is_numeric($entity) && $entity > 0) || $entity == 0 ? $entity : $conf->entity);
$out= '