From e79fffaccf2b7a55aa2f8f5f89bcd77ceed318c7 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Fri, 22 Apr 2022 16:09:52 +0200 Subject: [PATCH 1/8] NEW customer category filter on contract list --- htdocs/contrat/list.php | 71 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 6c23cfcf720..065fb9d6c0c 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -37,6 +37,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +if (!empty($conf->categorie->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +} // Load translation files required by the page $langs->loadLangs(array('contracts', 'products', 'companies', 'compta')); @@ -75,6 +78,13 @@ $search_date_endmonth = GETPOST('search_date_endmonth', 'int'); $search_date_endyear = GETPOST('search_date_endyear', 'int'); $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear); +$searchCategoryCustomerOperator = 0; +if (GETPOSTISSET('formfilteraction')) { + $searchCategoryCustomerOperator = GETPOST('search_category_customer_operator', 'int'); +} elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) { + $searchCategoryCustomerOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT; +} +$searchCategoryCustomerList = GETPOST('search_category_customer_list', 'array'); $optioncss = GETPOST('optioncss', 'alpha'); @@ -205,6 +215,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $search_status = ""; $toselect = ''; $search_type_thirdparty = ''; + $searchCategoryCustomerList = array(); $search_array_options = array(); } @@ -321,6 +332,50 @@ if ($sall) { if ($search_user > 0) { $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".((int) $search_user); } +$searchCategoryCustomerSqlList = array(); +if ($searchCategoryCustomerOperator == 1) { + $existsCategoryCustomerList = array(); + foreach ($searchCategoryCustomerList as $searchCategoryCustomer) { + if (intval($searchCategoryCustomer) == -2) { + $sqlCategoryCustomerNotExists = " NOT EXISTS ("; + $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc"; + $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus"; + $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid"; + $sqlCategoryCustomerNotExists .= " )"; + $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists; + } elseif (intval($searchCategoryCustomer) > 0) { + $existsCategoryCustomerList[] = $db->escape($searchCategoryCustomer); + } + } + if (!empty($existsCategoryCustomerList)) { + $sqlCategoryCustomerExists = " EXISTS ("; + $sqlCategoryCustomerExists .= " SELECT cat_cus.fk_soc"; + $sqlCategoryCustomerExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus"; + $sqlCategoryCustomerExists .= " WHERE cat_cus.fk_soc = s.rowid"; + $sqlCategoryCustomerExists .= " AND cat_cus.fk_categorie IN (".$db->sanitize(implode(',', $existsCategoryCustomerList)).")"; + $sqlCategoryCustomerExists .= " )"; + $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerExists; + } + if (!empty($searchCategoryCustomerSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")"; + } +} else { + foreach ($searchCategoryCustomerList as $searchCategoryCustomer) { + if (intval($searchCategoryCustomer) == -2) { + $sqlCategoryCustomerNotExists = " NOT EXISTS ("; + $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc"; + $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus"; + $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid"; + $sqlCategoryCustomerNotExists .= " )"; + $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists; + } elseif (intval($searchCategoryCustomer) > 0) { + $searchCategoryCustomerSqlList[] = "s.rowid IN (SELECT fk_soc FROM ".$db->prefix()."categorie_societe WHERE fk_categorie = ".((int) $searchCategoryCustomer).")"; + } + } + if (!empty($searchCategoryCustomerSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")"; + } +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks @@ -372,7 +427,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { } } } else { - $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM '.$db->prefix().'societe/', 'SELECT COUNT(*) as nbtotalofrecords FROM '.$db->prefix().'societe', $sql); $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'contratdet as cd ON c.rowid = cd.fk_contrat/', '', $sqlforcount); $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product/', '', $sqlforcount); $sqlforcount = preg_replace('/AND cp.fk_categorie = '.((int) $search_product_category).'/', '', $sqlforcount); @@ -498,6 +553,9 @@ if ($show_files) { if ($optioncss != '') { $param .= '&optioncss='.urlencode($optioncss); } +foreach ($searchCategoryCustomerList as $searchCategoryCustomer) { + $param .= "&search_category_customer_list[]=".urlencode($searchCategoryCustomer); +} // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -573,6 +631,17 @@ if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($use $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'widthcentpercentminusx maxwidth300', 1); $moreforfilter .= ''; } +// Filter on customer categories +if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) { + $moreforfilter .= '
'; + $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort'); + $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"'); + $categoriesProductArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 1); + $categoriesProductArr[-2] = '- '.$langs->trans('NotCategorized').' -'; + $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesProductArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle); + $moreforfilter .= ' '; + $moreforfilter .= '
'; +} $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook From ed23e3f3c38712a4d4ccd5d600b0ecfc57eb0b44 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Fri, 6 May 2022 16:09:26 +0200 Subject: [PATCH 2/8] NEW separate categories filters and add an help --- htdocs/contrat/list.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 065fb9d6c0c..9886a24885a 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -633,13 +633,15 @@ if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($use } // Filter on customer categories if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) { + $moreforfilter .= ' | '; $moreforfilter .= '
'; $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort'); $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"'); $categoriesProductArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 1); $categoriesProductArr[-2] = '- '.$langs->trans('NotCategorized').' -'; $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesProductArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle); - $moreforfilter .= ' '; + $moreforfilter .= ' '; + $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip1'); // Tooltip on click $moreforfilter .= '
'; } From b989d35279b49bdaf991b004acb0945f9e80879d Mon Sep 17 00:00:00 2001 From: lvessiller Date: Fri, 6 May 2022 16:18:00 +0200 Subject: [PATCH 3/8] NEW tooltip identifier --- htdocs/contrat/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 9886a24885a..3c5ea5c2604 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -641,7 +641,7 @@ if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) { $categoriesProductArr[-2] = '- '.$langs->trans('NotCategorized').' -'; $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesProductArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle); $moreforfilter .= ' '; - $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip1'); // Tooltip on click + $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_su'); // Tooltip on click $moreforfilter .= ''; } From 3778e2530714ebcdcdad86c00f588a03c7e7f629 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Fri, 6 May 2022 16:18:55 +0200 Subject: [PATCH 4/8] NEW tooltip identifier --- htdocs/contrat/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 3c5ea5c2604..97416f9ac72 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -641,7 +641,7 @@ if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) { $categoriesProductArr[-2] = '- '.$langs->trans('NotCategorized').' -'; $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesProductArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle); $moreforfilter .= ' '; - $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_su'); // Tooltip on click + $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click $moreforfilter .= ''; } From a411259ad3d309c3cfbfd480d5c10625ecd95e2b Mon Sep 17 00:00:00 2001 From: lvessiller Date: Mon, 16 May 2022 17:17:52 +0200 Subject: [PATCH 5/8] NEW separate categories filters --- htdocs/contrat/list.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 97416f9ac72..ec34df6191d 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -633,7 +633,6 @@ if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($use } // Filter on customer categories if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) { - $moreforfilter .= ' | '; $moreforfilter .= '
'; $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort'); $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"'); From 18a1cbb4a0b957d055e9c36c297e5bd71fa86098 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Mon, 23 May 2022 09:53:17 +0200 Subject: [PATCH 6/8] NEW MAIN_SEARCH_CATEGORY_CUSTOMER_ON_LISTS const to show category customer filter --- htdocs/contrat/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 2aaad952d1f..1ab27ab289a 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -638,7 +638,7 @@ if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($use $moreforfilter .= '
'; } // Filter on customer categories -if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) { +if (!empty($conf->global->MAIN_SEARCH_CATEGORY_CUSTOMER_ON_LISTS) && !empty($conf->categorie->enabled) && $user->rights->categorie->lire) { $moreforfilter .= '
'; $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort'); $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"'); From d537493b42556ab184243da70e7658e3379cbcf6 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Mon, 23 May 2022 12:27:55 +0200 Subject: [PATCH 7/8] NEW rename categoriesArr varibale --- htdocs/contrat/list.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 1ab27ab289a..037aecf5c1d 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -642,9 +642,9 @@ if (!empty($conf->global->MAIN_SEARCH_CATEGORY_CUSTOMER_ON_LISTS) && !empty($con $moreforfilter .= '
'; $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort'); $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"'); - $categoriesProductArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 1); - $categoriesProductArr[-2] = '- '.$langs->trans('NotCategorized').' -'; - $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesProductArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle); + $categoriesArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 1); + $categoriesArr[-2] = '- '.$langs->trans('NotCategorized').' -'; + $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle); $moreforfilter .= ' '; $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click $moreforfilter .= '
'; From 864b49677bbd9e4bc8a046f5424120d130811d4e Mon Sep 17 00:00:00 2001 From: lvessiller-opendsi Date: Sat, 26 Nov 2022 10:45:01 +0100 Subject: [PATCH 8/8] Update list.php --- htdocs/contrat/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 24d345daa88..b6894313987 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -661,7 +661,7 @@ if (isModEnabled('categorie') && $user->rights->categorie->lire && ($user->right $moreforfilter .= '
'; } // Filter on customer categories -if (!empty($conf->global->MAIN_SEARCH_CATEGORY_CUSTOMER_ON_LISTS) && !empty($conf->categorie->enabled) && $user->rights->categorie->lire) { +if (!empty($conf->global->MAIN_SEARCH_CATEGORY_CUSTOMER_ON_CONTRACT_LIST) && !empty($conf->categorie->enabled) && $user->rights->categorie->lire) { $moreforfilter .= '
'; $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort'); $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');