From ee02ff43d75996d1fe5de07d029e5bc9553210d0 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 7 Jul 2016 12:19:20 +0200 Subject: [PATCH 01/87] Fix: add entity field in llx_societe_remise_except, useful when third-sharing is used with multicompany --- htdocs/comm/remx.php | 6 +- htdocs/core/class/discount.class.php | 17 +- htdocs/core/class/html.form.class.php | 177 +++++++++--------- .../install/mysql/migration/3.9.0-4.0.0.sql | 1 + .../tables/llx_societe_remise_except.sql | 25 +-- htdocs/install/upgrade2.php | 149 +++++++++++++-- htdocs/langs/en_US/install.lang | 1 + htdocs/societe/class/societe.class.php | 28 +-- 8 files changed, 265 insertions(+), 139 deletions(-) diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index b682b214da8..9407553f325 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -248,7 +248,8 @@ if ($socid > 0) $remise_all=$remise_user=0; $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; - $sql.= " WHERE rc.fk_soc =". $object->id; + $sql.= " WHERE rc.fk_soc = " . $object->id; + $sql.= " AND rc.entity = " . $conf->entity; $sql.= " AND (fk_facture_line IS NULL AND fk_facture IS NULL)"; $sql.= " GROUP BY rc.fk_user"; $resql=$db->query($sql); @@ -318,7 +319,8 @@ if ($socid > 0) $sql.= " fa.facnumber as ref, fa.type as type"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid"; - $sql.= " WHERE rc.fk_soc =". $object->id; + $sql.= " WHERE rc.fk_soc = " . $object->id; + $sql.= " AND rc.entity = " . $conf->entity; $sql.= " AND u.rowid = rc.fk_user"; $sql.= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)"; $sql.= " ORDER BY rc.datec DESC"; diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index e256dbfb649..9a59801f720 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -66,6 +66,8 @@ class DiscountAbsolute */ function fetch($rowid,$fk_facture_source=0) { + global $conf; + // Check parameters if (! $rowid && ! $fk_facture_source) { @@ -81,9 +83,9 @@ class DiscountAbsolute $sql.= " f.facnumber as ref_facture_source"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid"; - $sql.= " WHERE"; - if ($rowid) $sql.= " sr.rowid=".$rowid; - if ($fk_facture_source) $sql.= " sr.fk_facture_source=".$fk_facture_source; + $sql.= " WHERE sr.entity = " . $conf->entity; + if ($rowid) $sql.= " AND sr.rowid=".$rowid; + if ($fk_facture_source) $sql.= " AND sr.fk_facture_source=".$fk_facture_source; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); @@ -150,11 +152,11 @@ class DiscountAbsolute // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except"; - $sql.= " (datec, fk_soc, fk_user, description,"; + $sql.= " (entity, datec, fk_soc, fk_user, description,"; $sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,"; $sql.= " fk_facture_source"; $sql.= ")"; - $sql.= " VALUES ('".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',"; + $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',"; $sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.","; $sql.= " ".($this->fk_facture_source?"'".$this->fk_facture_source."'":"null"); $sql.= ")"; @@ -343,10 +345,13 @@ class DiscountAbsolute */ function getAvailableDiscounts($company='', $user='',$filter='', $maxvalue=0) { + global $conf; + $sql = "SELECT SUM(rc.amount_ttc) as amount"; // $sql = "SELECT rc.amount_ttc as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; - $sql.= " WHERE (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available + $sql.= " WHERE rc.entity = " . $conf->entity; + $sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id; if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id; if ($filter) $sql.=' AND ('.$filter.')'; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 507f45a12f8..334aabbd362 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -203,7 +203,7 @@ class Form $ret.=$doleditor->Create(1); } $ret.=''; - + $ret.=''; $ret.=''; if (preg_match('/ckeditor|textarea/',$typeofdata)) $ret.='
'."\n"; @@ -493,7 +493,7 @@ class Form /** * Generate select HTML to choose massaction - * + * * @param string $selected Selected value * @param int $arrayofaction array('code'=>'label', ...). The code is the key stored into the GETPOST('massaction') when submitting action. * @return string Select list @@ -501,9 +501,9 @@ class Form function selectMassAction($selected, $arrayofaction) { global $conf,$langs,$hookmanager; - + if (count($arrayofaction) == 0) return; - + $disabled=0; $ret='
'; $ret.='
'; - + $ret.=' '; - + return $ret; } - + /** * Return combo list of activated countries, into language of user * @@ -1029,9 +1029,9 @@ class Form $textifempty=''; // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. //if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty=''; - if (! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) + if (! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) { - if ($showempty && ! is_numeric($showempty)) $textifempty=$langs->trans($showempty); + if ($showempty && ! is_numeric($showempty)) $textifempty=$langs->trans($showempty); else $textifempty.=$langs->trans("All"); } if ($showempty) $out.= ''."\n"; @@ -1117,7 +1117,8 @@ class Form $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $sql.= " re.description, re.fk_facture_source"; $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re"; - $sql.= " WHERE fk_soc = ".(int) $socid; + $sql.= " WHERE re.fk_soc = ".(int) $socid; + $sql.= " AND re.entity = " . $conf->entity; if ($filter) $sql.= " AND ".$filter; $sql.= " ORDER BY re.description ASC"; @@ -1350,7 +1351,7 @@ class Form * @param integer $show_every 0=default list, 1=add also a value "Everybody" at beginning of list * @param string $enableonlytext If option $enableonly is set, we use this text to explain into label why record is disabled. Not used if enableonly is empty. * @param string $morecss More css - * @param int $noactive Show only active users (this will also happened whatever is this option if USER_HIDE_INACTIVE_IN_COMBOBOX is on). + * @param int $noactive Show only active users (this will also happened whatever is this option if USER_HIDE_INACTIVE_IN_COMBOBOX is on). * @return string HTML select string * @see select_dolgroups */ @@ -1881,7 +1882,7 @@ class Form $outlabel=$objp->label; $outdesc=$objp->description; $outbarcode=$objp->barcode; - + $outtype=$objp->fk_product_type; $outdurationvalue=$outtype == Product::TYPE_SERVICE?substr($objp->duration,0,dol_strlen($objp->duration)-1):''; $outdurationunit=$outtype == Product::TYPE_SERVICE?substr($objp->duration,-1):''; @@ -1898,13 +1899,13 @@ class Form $opt.= $objp->ref; if ($outbarcode) $opt.=' ('.$outbarcode.')'; $opt.=' - '.dol_trunc($label,$maxlengtharticle).' - '; - + $objRef = $objp->ref; if (! empty($filterkey) && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i','$1',$objRef,1); $outval.=$objRef; if ($outbarcode) $outval.=' ('.$outbarcode.')'; $outval.=' - '.dol_trunc($label,$maxlengtharticle).' - '; - + $found=0; // Multiprice @@ -1986,9 +1987,9 @@ class Form } // Price by customer - if (empty($hidepriceinlabel) && !empty($conf->global->PRODUIT_CUSTOMER_PRICES)) + if (empty($hidepriceinlabel) && !empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { - if (!empty($objp->idprodcustprice)) + if (!empty($objp->idprodcustprice)) { $found = 1; @@ -2066,7 +2067,7 @@ class Form { global $langs,$conf; global $price_level, $status, $finished; - + $selected_input_value=''; if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { @@ -2198,11 +2199,11 @@ class Form if ($filterkey && $filterkey != '') $label=preg_replace('/('.preg_quote($filterkey).')/i','$1',$label,1); $opt.=$objp->ref; - if (! empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) + if (! empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) $opt.=' ('.$objp->ref_fourn.')'; $opt.=' - '; $outval.=$objRef; - if (! empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) + if (! empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) $outval.=' ('.$objRefFourn.')'; $outval.=' - '; $opt.=dol_trunc($label, 72).' - '; @@ -2805,7 +2806,7 @@ class Form { // If not good status if ($active >= 0 && $arraytypes['active'] != $active) continue; - + // On passe si on a demande de filtrer sur des modes de paiments particuliers if (count($filterarray) && ! in_array($arraytypes['type'],$filterarray)) continue; @@ -3168,13 +3169,13 @@ class Form $langs->load("categories"); include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - + // For backward compatibility if (is_numeric($type)) { dol_syslog(__METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING); } - + $cat = new Categorie($this->db); $cate_arbo = $cat->get_full_arbo($type,$excludeafterid); @@ -3794,7 +3795,7 @@ class Form } } } - + /** * Show form with multicurrency code * @@ -3824,7 +3825,7 @@ class Form print !empty($selected) ? currency_name($selected,1) : ' '; } } - + /** * Show form with multicurrency rate * @@ -3837,7 +3838,7 @@ class Form function form_multicurrency_rate($page, $rate='', $htmlname='multicurrency_tx', $currency='') { global $langs, $mysoc, $conf; - + if ($htmlname != "none") { print '
'; @@ -4068,7 +4069,7 @@ class Form /** * Return array of currencies in user language - * + * * @param string $selected preselected currency code * @param string $htmlname name of HTML select list * @param integer $useempty 1=Add empty line @@ -4081,7 +4082,7 @@ class Form $langs->loadCacheCurrencies(''); // Load ->cache_currencies $TCurrency = array(); - + $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency'; $sql.= " WHERE entity IN ('".getEntity('mutlicurrency')."')"; $resql = $db->query($sql); @@ -4089,7 +4090,7 @@ class Form { while ($obj = $db->fetch_object($resql)) $TCurrency[$obj->code] = $obj->code; } - + $out=''; $out.= ''; return $out; } - + /** * Load into the cache vat rates of a country * @@ -4204,7 +4205,7 @@ class Form $defaulttx=preg_replace('/\s*\(.*\)/','',$defaulttx); } //var_dump($selectedrate.'-'.$defaulttx.'-'.$defaultnpr.'-'.$defaultcode); - + // Check parameters if (is_object($societe_vendeuse) && ! $societe_vendeuse->country_code) { @@ -4303,7 +4304,7 @@ class Form $return.= '"'; if ($defaultcode) // If defaultcode is defined, we used it in priority to select combo option instead of using rate+npr flag { - if ($defaultcode == $rate['code']) $return.= ' selected'; + if ($defaultcode == $rate['code']) $return.= ' selected'; } elseif ($rate['txtva'] == $defaulttx && $rate['nprtva'] == $defaultnpr) { @@ -4312,7 +4313,7 @@ class Form $return.= '>'.vatrate($rate['libtva']); //$return.=($rate['code']?' '.$rate['code']:''); $return.= (empty($rate['code']) && $rate['nprtva']) ? ' *': ''; // We show the * (old behaviour only if new vat code is not used) - + $return.= ''; } @@ -4616,7 +4617,7 @@ class Form { $tmparray=dol_getdate($adddateof); $retstring.=' -