Skip to content

Commit

Permalink
Fix join into left join
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Nov 8, 2019
1 parent cb1e595 commit 8309062
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
24 changes: 16 additions & 8 deletions htdocs/core/class/html.formother.class.php
Expand Up @@ -382,15 +382,16 @@ public function select_categories($type, $selected = 0, $htmlname = 'search_cate
/**
* Return select list for categories (to use in form search selectors)
*
* @param string $selected Preselected value
* @param string $htmlname Name of combo list (example: 'search_sale')
* @param User $user Object user
* @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status
* @param int $showempty 1=show also an empty value
* @param string $morecss More CSS
* @return string Html combo list code
* @param string $selected Preselected value
* @param string $htmlname Name of combo list (example: 'search_sale')
* @param User $user Object user
* @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status
* @param int $showempty 1=show also an empty value
* @param string $morecss More CSS
* @param int $norepresentative Show also an entry "Not categorized"
* @return string Html combo list code
*/
public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '')
public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
{
// phpcs:enable
global $conf, $langs;
Expand Down Expand Up @@ -498,6 +499,13 @@ public function select_salesrepresentatives($selected, $htmlname, $user, $showst
{
dol_print_error($this->db);
}

if ($norepresentative)
{
$langs->load("companies");
$out.='<option value="-2"'.($selected == -2 ? ' selected':'').'>- '.$langs->trans("NoSalesRepresentativeAffected").' -</option>';
}

$out.='</select>';

return $out;
Expand Down
12 changes: 7 additions & 5 deletions htdocs/societe/list.php
@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2019 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
Expand Down Expand Up @@ -409,13 +409,15 @@
if (! empty($search_categ_sup)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs ON s.rowid = cs.fk_soc"; // We'll need this table joined to the select in order to filter by categ
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."c_stcomm as st ON s.fk_stcomm = st.id";
// We'll need this table joined to the select in order to filter by sale
if ($search_sale || (!$user->rights->societe->client->voir && !$socid)) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if ($search_sale == -2) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
elseif ($search_sale || (!$user->rights->societe->client->voir && !$socid)) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE s.entity IN (".getEntity('societe').")";
if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid) $sql.= " AND s.rowid = ".$socid;
if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
if ($search_sale != -2) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
if (! $user->rights->fournisseur->lire) $sql.=" AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
if ($search_sale) $sql.= " AND sc.fk_user = ".$db->escape($search_sale);
if ($search_sale == -2) $sql.= " AND sc.fk_user IS NULL";
elseif ($search_sale) $sql.= " AND sc.fk_user = ".$db->escape($search_sale);
if ($search_categ_cus > 0) $sql.= " AND cc.fk_categorie = ".$db->escape($search_categ_cus);
if ($search_categ_sup > 0) $sql.= " AND cs.fk_categorie = ".$db->escape($search_categ_sup);
if ($search_categ_cus == -2) $sql.= " AND cc.fk_categorie IS NULL";
Expand Down Expand Up @@ -659,7 +661,7 @@
{
$moreforfilter.='<div class="divsearchfield">';
$moreforfilter.=$langs->trans('SalesRepresentatives'). ': ';
$moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300');
$moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300', 1);
$moreforfilter.='</div>';
}
if ($moreforfilter)
Expand Down

0 comments on commit 8309062

Please sign in to comment.