diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index 8f634db6ea0..65a3f95779d 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -551,7 +551,7 @@ $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields $sql = 'SELECT'; -if ($search_all || $search_user > 0) { +if ($search_all > 0) { $sql = 'SELECT DISTINCT'; } $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax , s.address, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client,'; @@ -596,13 +596,6 @@ if ($search_all) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON p.fk_user_author = u.rowid'; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr ON pr.rowid = p.fk_projet"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_availability as ava on (ava.rowid = p.fk_availability)"; -if ($search_user > 0) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_contact as c"; - $sql .= " ON c.element_id = p.rowid AND c.fk_socpeople = ".((int) $search_user); - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_type_contact as tc"; - $sql .= " ON c.fk_c_type_contact = tc.rowid AND tc.element='propal' AND tc.source='internal'"; -} - // Add table from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook @@ -725,6 +718,15 @@ if ($search_date_signature_start) { if ($search_date_signature_end) { $sql .= " AND p.date_signature <= '".$db->idate($search_date_signature_end)."'"; } +// Search on user +if ($search_user > 0) { + $sql .= " AND EXISTS ("; + $sql .= " SELECT ec.fk_c_type_contact, ec.element_id, ec.fk_socpeople"; + $sql .= " FROM llx_element_contact as ec"; + $sql .= " INNER JOIN llx_c_type_contact as tc"; + $sql .= " ON ec.fk_c_type_contact = tc.rowid AND tc.element='propal' AND tc.source='internal'"; + $sql .= " WHERE ec.element_id = p.rowid AND ec.fk_socpeople = ".((int) $search_user).")"; +} // Search on sale representative if ($search_sale && $search_sale != '-1') { if ($search_sale == -2) { diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 7f3b1fd401b..5278090d66d 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -831,7 +831,7 @@ $help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_P // Build and execute select // -------------------------------------------------------------------- $sql = 'SELECT'; -if ($search_all || $search_user > 0) { +if ($search_all) { $sql = 'SELECT DISTINCT'; } $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax, s.address, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client,'; @@ -878,11 +878,6 @@ if ($search_all) { } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = c.fk_projet"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON c.fk_user_author = u.rowid'; -if ($search_user > 0) { - $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec"; - $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc"; -} - // Add table from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -980,9 +975,6 @@ if (empty($arrayfields['s.name_alias']['checked']) && $search_company) { if ($search_parent_name) { $sql .= natural_search('s2.nom', $search_parent_name); } -if ($search_user > 0) { - $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".((int) $search_user); -} if ($search_total_ht != '') { $sql .= natural_search('c.total_ht', $search_total_ht, 1); } @@ -1031,6 +1023,15 @@ if ($search_fk_mode_reglement > 0) { if ($search_fk_input_reason > 0) { $sql .= " AND c.fk_input_reason = ".((int) $search_fk_input_reason); } +// Search on user +if ($search_user > 0) { + $sql .= " AND EXISTS ("; + $sql .= " SELECT ec.fk_c_type_contact, ec.element_id, ec.fk_socpeople"; + $sql .= " FROM llx_element_contact as ec"; + $sql .= " INNER JOIN llx_c_type_contact as tc"; + $sql .= " ON ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal'"; + $sql .= " WHERE ec.element_id = c.rowid AND ec.fk_socpeople = ".((int) $search_user).")"; +} // Search on sale representative if ($search_sale && $search_sale != '-1') { if ($search_sale == -2) { diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index a28296951ab..e6e48620158 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -1,23 +1,24 @@ - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2004-2016 Laurent Destailleur - * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2015 Regis Houssin - * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2010-2020 Juanjo Menent - * Copyright (C) 2012 Christophe Battarel - * Copyright (C) 2013 Florian Henry - * Copyright (C) 2013 Cédric Salvador - * Copyright (C) 2015 Jean-François Ferry - * Copyright (C) 2015-2022 Ferran Marcet - * Copyright (C) 2017 Josep Lluís Amador - * Copyright (C) 2018 Charlene Benke - * Copyright (C) 2019-2021 Alexandre Spangaro - * Copyright (C) 2023 Nick Fragoulis - * Copyright (C) 2023 Joachim Kueter - * Copyright (C) 2024 MDW - * Copyright (C) 2024 Frédéric France +/* Copyright (C) 2002-2006 Rodolphe Quiedeville + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2004-2016 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2015 Regis Houssin + * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2010-2020 Juanjo Menent + * Copyright (C) 2012 Christophe Battarel + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2013 Cédric Salvador + * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2015-2022 Ferran Marcet + * Copyright (C) 2017 Josep Lluís Amador + * Copyright (C) 2018 Charlene Benke + * Copyright (C) 2019-2021 Alexandre Spangaro + * Copyright (C) 2023 Nick Fragoulis + * Copyright (C) 2023 Joachim Kueter + * Copyright (C) 2024 MDW + * Copyright (C) 2024 Frédéric France + * Copyright (C) 2021-2024 Anthony Berton * * 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 @@ -630,7 +631,7 @@ $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfi // Build and execute select // -------------------------------------------------------------------- $sql = 'SELECT'; -if ($search_all || $search_user > 0) { +if ($search_all) { $sql = 'SELECT DISTINCT'; } $sql .= ' f.rowid as id, f.ref, f.ref_client, f.fk_soc, f.type, f.subtype, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, f.total_ht, f.total_tva, f.total_ttc,'; @@ -692,10 +693,6 @@ if (!empty($search_fac_rec_source_title)) { } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid'; -if ($search_user > 0) { - $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec"; - $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc"; -} // Add table from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook @@ -868,12 +865,18 @@ if ($search_late == 'late') { /*if ($search_sale > 0) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale); }*/ -if ($search_user > 0) { - $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='facture' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".((int) $search_user); -} if (!empty($search_fac_rec_source_title)) { $sql .= natural_search('facrec.titre', $search_fac_rec_source_title); } +// Search on user +if ($search_user > 0) { + $sql .= " AND EXISTS ("; + $sql .= " SELECT ec.fk_c_type_contact, ec.element_id, ec.fk_socpeople"; + $sql .= " FROM llx_element_contact as ec"; + $sql .= " INNER JOIN llx_c_type_contact as tc"; + $sql .= " ON ec.fk_c_type_contact = tc.rowid AND tc.element='facture' AND tc.source='internal'"; + $sql .= " WHERE ec.element_id = f.rowid AND ec.fk_socpeople = ".((int) $search_user).")"; +} // Search on sale representative if ($search_sale && $search_sale != '-1') { if ($search_sale == -2) { @@ -1119,16 +1122,16 @@ if ($search_customer_code) { $param .= '&search_customer_code='.urlencode($search_customer_code); } if ($search_sale > 0) { - $param .= '&search_sale='.urlencode($search_sale); + $param .= '&search_sale='.urlencode((string) $search_sale); } if ($search_user > 0) { - $param .= '&search_user='.urlencode((string) ($search_user)); + $param .= '&search_user='.urlencode((string) $search_user); } if ($search_login) { $param .= '&search_login='.urlencode($search_login); } if ($search_product_category > 0) { - $param .= '&search_product_category='.urlencode((string) ($search_product_category)); + $param .= '&search_product_category='.urlencode((string) $search_product_category); } if ($search_montant_ht != '') { $param .= '&search_montant_ht='.urlencode($search_montant_ht);