diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index d8f523f16da..535654458a7 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -277,7 +277,7 @@ $help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos' //llxHeader('',$langs->trans('Proposal'),$help_url); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; $sql .= ' s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client, '; $sql .= " typent.code as typent_code,"; $sql .= " ava.rowid as availability,"; diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 885081e84a1..3efa8f534a4 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -271,7 +271,7 @@ $help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_P // llxHeader('',$title,$help_url); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; $sql .= ' s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,'; $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,"; diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index c61bfdf6819..ca2a8f6ae44 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -413,7 +413,7 @@ $formcompany = new FormCompany($db); $thirdpartystatic = new Societe($db); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; $sql .= ' f.rowid as id, f.ref, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,'; $sql .= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,'; $sql .= ' f.fk_user_author,'; diff --git a/htdocs/expedition/list.php b/htdocs/expedition/list.php index 28c0673ef17..20bb6f298cb 100644 --- a/htdocs/expedition/list.php +++ b/htdocs/expedition/list.php @@ -211,8 +211,9 @@ $helpurl = 'EN:Module_Shipments|FR:Module_Expéditions|ES:Módulo_Ex llxHeader('', $langs->trans('ListOfSendings'), $helpurl); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; -$sql .= " e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.weight, e.weight_units, e.date_delivery as delivery_date, l.date_delivery as date_reception, e.fk_statut, e.billed, e.tracking_number,"; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; +$sql .= " e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.weight, e.weight_units, e.date_delivery as delivery_date, e.fk_statut, e.billed, e.tracking_number,"; +$sql .= " l.date_delivery as date_reception,"; $sql .= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, "; $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,"; @@ -242,11 +243,12 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON e.fk_user_author = u.rowid'; - +if ($search_user > 0) { // Get link to order to get the order id in eesource.fk_source + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as eesource ON eesource.fk_target = e.rowid AND eesource.targettype = 'shipping' AND eesource.sourcetype = 'commande'"; +} // We'll need this table joined to the select in order to filter by sale if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; -if ($search_user > 0) -{ +if ($search_user > 0) { $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec"; $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc"; } @@ -274,6 +276,11 @@ if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')'; if ($search_tracking) $sql .= natural_search("e.tracking_number", $search_tracking); if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')'; if ($search_sale > 0) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$search_sale; +if ($search_user > 0) +{ + // The contact on a shipment is also the contact of the order. + $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal' AND ec.element_id = eesource.fk_source AND ec.fk_socpeople = ".$db->escape($search_user); +} if ($search_ref_exp) $sql .= natural_search('e.ref', $search_ref_exp); if ($search_ref_liv) $sql .= natural_search('l.ref', $search_ref_liv); if ($search_company) $sql .= natural_search('s.nom', $search_company); diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index 2b77801fee3..c5173ccddeb 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -521,7 +521,7 @@ $help_url = ''; // llxHeader('',$title,$help_url); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, s.email,'; $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,"; diff --git a/htdocs/supplier_proposal/list.php b/htdocs/supplier_proposal/list.php index d74f2fbdec3..421ac40b447 100644 --- a/htdocs/supplier_proposal/list.php +++ b/htdocs/supplier_proposal/list.php @@ -249,7 +249,7 @@ $help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur'; //llxHeader('',$langs->trans('CommRequest'),$help_url); $sql = 'SELECT'; -if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,'; $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,";