From 8386e8a54182f78e06f8764b343c7903b39f9a93 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 9 Jan 2012 09:55:20 +0100 Subject: [PATCH 1/4] Fix: can debug rounding. to simulate the rounded total --- htdocs/admin/limits.php | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) 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(); From 85d7285519c1fe340103c2bc6f8f8023512165f7 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 9 Jan 2012 11:12:07 +0100 Subject: [PATCH 2/4] =?UTF-8?q?[bug=20#275]=20Ajout=20contacts=20-=20choix?= =?UTF-8?q?=20par=20"par=20d=C3=A9faut"=20de=20l'entreprise=20du=20fournis?= =?UTF-8?q?seur=20Fix:=20uniform=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/fourn/commande/contact.php | 91 +++++++++++++++---------------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/htdocs/fourn/commande/contact.php b/htdocs/fourn/commande/contact.php index 0f3e6ea5dff..68a1512eaaa 100644 --- a/htdocs/fourn/commande/contact.php +++ b/htdocs/fourn/commande/contact.php @@ -1,7 +1,7 @@ * Copyright (C) 2005-2009 Destailleur Laurent - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-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 @@ -34,54 +34,55 @@ $langs->load("orders"); $langs->load("sendings"); $langs->load("companies"); +$id = GETPOST('id', 'int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action', 'alpha'); + // Security check -$id = isset($_GET["id"])?$_GET["id"]:''; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'commande_fournisseur', $id,''); +$object = new CommandeFournisseur($db); + /* * Ajout d'un nouveau contact */ -if ($_POST["action"] == 'addcontact' && $user->rights->commande->creer) +if ($action == 'addcontact' && $user->rights->commande->creer) { + $result = $object->fetch($id); - $result = 0; - $commande = new CommandeFournisseur($db); - $result = $commande->fetch($_GET["id"]); - - if ($result > 0 && $_GET["id"] > 0) + if ($result > 0 && $id > 0) { - $result = $commande->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]); + $result = $object->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]); } if ($result >= 0) { - Header("Location: contact.php?id=".$commande->id); + Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { - if ($commande->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; } else { - $mesg = '
'.$commande->error.'
'; + $mesg = '
'.$object->error.'
'; } } } // bascule du statut d'un contact -if ($_GET["action"] == 'swapstatut' && $user->rights->commande->creer) +if ($action == 'swapstatut' && $user->rights->commande->creer) { - $commande = new CommandeFournisseur($db); - if ($commande->fetch(GETPOST("id"))) + if ($object->fetch($id)) { - $result=$commande->swapContactStatus(GETPOST('ligne')); + $result=$object->swapContactStatus(GETPOST('ligne')); } else { @@ -90,15 +91,14 @@ if ($_GET["action"] == 'swapstatut' && $user->rights->commande->creer) } // Efface un contact -if ($_GET["action"] == 'deleteline' && $user->rights->commande->creer) +if ($action == 'deleteline' && $user->rights->commande->creer) { - $commande = new CommandeFournisseur($db); - $commande->fetch($_GET["id"]); - $result = $commande->delete_contact($_GET["lineid"]); + $object->fetch($id); + $result = $object->delete_contact($_GET["lineid"]); if ($result >= 0) { - Header("Location: contact.php?id=".$commande->id); + Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { @@ -127,19 +127,17 @@ $userstatic=new User($db); /* *************************************************************************** */ dol_htmloutput_mesg($mesg); -$id = $_GET['id']; -$ref= $_GET['ref']; if ($id > 0 || ! empty($ref)) { $langs->trans("OrderCard"); - $commande = new CommandeFournisseur($db); - if ( $commande->fetch($_GET['id'],$_GET['ref']) > 0) + + if ($object->fetch($id, $ref) > 0) { $soc = new Societe($db); - $soc->fetch($commande->socid); + $soc->fetch($object->socid); - $head = ordersupplier_prepare_head($commande); + $head = ordersupplier_prepare_head($object); dol_fiche_head($head, 'contact', $langs->trans("SupplierOrder"), 0, 'order'); @@ -151,7 +149,7 @@ if ($id > 0 || ! empty($ref)) // Ref print ''.$langs->trans("Ref").''; print ''; - print $form->showrefnav($commande,'ref','',1,'ref','ref'); + print $form->showrefnav($object,'ref','',1,'ref','ref'); print ''; print ''; @@ -175,7 +173,7 @@ if ($id > 0 || ! empty($ref)) * Ajouter une ligne de contact * Non affiche en mode modification de ligne */ - if ($_GET["action"] != 'editline' && $user->rights->fournisseur->facture->creer) + if ($action != 'editline' && $user->rights->fournisseur->facture->creer) { print ''; print ''.$langs->trans("Source").''; @@ -187,11 +185,11 @@ if ($id > 0 || ! empty($ref)) $var = false; - print '
'; + print ''; print ''; print ''; print ''; - print ''; + print ''; // Ligne ajout pour contact interne print ""; @@ -205,22 +203,22 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; - //$userAlreadySelected = $commande->getListContactId('internal'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type + //$userAlreadySelected = $object->getListContactId('internal'); // On ne doit pas desactiver un contact deja selectionner car on doit pouvoir le seclectionner une deuxieme fois pour un autre type $form->select_users($user->id,'contactid',0,$userAlreadySelected); print ''; print ''; - $formcompany->selectTypeContact($commande, '', 'type','internal'); + $formcompany->selectTypeContact($object, '', 'type','internal'); print ''; print ''; print ''; print '
'; - print '
'; + print ''; print ''; print ''; print ''; - print ''; + print ''; // Ligne ajout pour contact externe $var=!$var; @@ -231,8 +229,8 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; - $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$commande->client->id; - $selectedCompany = $formcompany->selectCompaniesForNewContact($commande, 'id', $selectedCompany, 'newcompany'); + $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$soc->id; + $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany'); print ''; print ''; @@ -240,7 +238,7 @@ if ($id > 0 || ! empty($ref)) if ($nbofcontacts == 0) print $langs->trans("NoContactDefined"); print ''; print ''; - $formcompany->selectTypeContact($commande, '', 'type','external'); + $formcompany->selectTypeContact($object, '', 'type','external'); print ''; print ' 0 || ! empty($ref)) foreach(array('internal','external') as $source) { - $tab = $commande->liste_contact(-1,$source); + $tab = $object->liste_contact(-1,$source); $num=count($tab); $i = 0; @@ -290,11 +288,11 @@ if ($id > 0 || ! empty($ref)) $companystatic->fetch($tab[$i]['socid']); print $companystatic->getNomUrl(1); } - if ($tab[$i]['socid'] < 0) + else if ($tab[$i]['socid'] < 0) { print $conf->global->MAIN_INFO_SOCIETE_NOM; } - if (! $tab[$i]['socid']) + else if (! $tab[$i]['socid']) { print ' '; } @@ -324,17 +322,17 @@ if ($id > 0 || ! empty($ref)) // Statut print ''; // Activation desativation du contact - if ($commande->statut >= 0) print ''; + if ($object->statut >= 0) print ''; print $contactstatic->LibStatut($tab[$i]['status'],3); - if ($commande->statut >= 0) print ''; + if ($object->statut >= 0) print ''; print ''; // Icon update et delete print ''; - if ($commande->statut < 5 && $user->rights->commande->creer) + if ($object->statut < 5 && $user->rights->commande->creer) { print ' '; - print ''; + print ''; print img_delete(); print ''; } @@ -354,7 +352,8 @@ if ($id > 0 || ! empty($ref)) } } +llxFooter(); + $db->close(); -llxFooter(); ?> \ No newline at end of file From 4eb88be3b61f1c1456ef9d69deb39b94b0f4c218 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 9 Jan 2012 11:28:37 +0100 Subject: [PATCH 3/4] Fix: bad rights --- htdocs/fourn/commande/contact.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/fourn/commande/contact.php b/htdocs/fourn/commande/contact.php index 68a1512eaaa..5a80d98ec7d 100644 --- a/htdocs/fourn/commande/contact.php +++ b/htdocs/fourn/commande/contact.php @@ -49,7 +49,7 @@ $object = new CommandeFournisseur($db); * Ajout d'un nouveau contact */ -if ($action == 'addcontact' && $user->rights->commande->creer) +if ($action == 'addcontact' && $user->rights->fournisseur->commande->creer) { $result = $object->fetch($id); @@ -78,7 +78,7 @@ if ($action == 'addcontact' && $user->rights->commande->creer) } // bascule du statut d'un contact -if ($action == 'swapstatut' && $user->rights->commande->creer) +if ($action == 'swapstatut' && $user->rights->fournisseur->commande->creer) { if ($object->fetch($id)) { @@ -91,7 +91,7 @@ if ($action == 'swapstatut' && $user->rights->commande->creer) } // Efface un contact -if ($action == 'deleteline' && $user->rights->commande->creer) +if ($action == 'deleteline' && $user->rights->fournisseur->commande->creer) { $object->fetch($id); $result = $object->delete_contact($_GET["lineid"]); @@ -329,7 +329,7 @@ if ($id > 0 || ! empty($ref)) // Icon update et delete print ''; - if ($object->statut < 5 && $user->rights->commande->creer) + if ($object->statut < 5 && $user->rights->fournisseur->commande->creer) { print ' '; print ''; From 376759c13d6e7bc4be26fe2c8c4311159f466c65 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 10 Jan 2012 06:57:44 +0800 Subject: [PATCH 4/4] Fix: refactoring elements sharing management between entities --- htdocs/core/ajax/constantonoff.php | 6 +++--- htdocs/core/class/conf.class.php | 17 ++++------------- htdocs/core/lib/admin.lib.php | 2 +- htdocs/core/lib/ajax.lib.php | 15 ++++++++++----- 4 files changed, 18 insertions(+), 22 deletions(-) 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= '