Merge pull request #20695 from Easya-Solutions/new-project-list-filter-category-customer

NEW customer category filter on project list
This commit is contained in:
Laurent Destailleur 2022-11-26 10:43:25 +01:00 committed by GitHub
commit 7f44d1f915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,6 +113,13 @@ $search_accept_booth_suggestions = GETPOST('search_accept_booth_suggestions', 'i
$search_price_registration = GETPOST("search_price_registration", 'alpha');
$search_price_booth = GETPOST("search_price_booth", 'alpha');
$search_login = GETPOST('search_login', 'alpha');
$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');
$mine = ((GETPOST('mode') == 'mine') ? 1 : 0);
@ -594,6 +601,50 @@ if (!empty($searchCategoryProjectList)) {
}
}
}
$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 = p.fk_soc";
$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 = p.fk_soc";
$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 = p.fk_soc";
$sqlCategoryCustomerNotExists .= " )";
$searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
} elseif (intval($searchCategoryCustomer) > 0) {
$searchCategoryCustomerSqlList[] = "p.fk_soc 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
@ -794,6 +845,9 @@ if ($search_login) {
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';
@ -900,6 +954,18 @@ if (isModEnabled('categorie') && $user->rights->categorie->lire) {
$formcategory = new FormCategory($db);
$moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PROJECT, $search_category_array);
}
// Filter on customer categories
if (!empty($conf->global->MAIN_SEARCH_CATEGORY_CUSTOMER_ON_PROJECT_LIST) && !empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
$moreforfilter .= '<div class="divsearchfield">';
$tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort');
$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
$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 .= ' <input type="checkbox" class="valignmiddle" id="search_category_customer_operator" name="search_category_customer_operator" value="1"'.($searchCategoryCustomerOperator == 1 ? ' checked="checked"' : '').'/>';
$moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click
$moreforfilter .= '</div>';
}
if (!empty($moreforfilter)) {
print '<div class="liste_titre liste_titre_bydiv centpercent">';