NEW customer category filter on project list
This commit is contained in:
parent
25fbd3b385
commit
86fa7ae24e
@ -108,6 +108,13 @@ $search_accept_conference_suggestions = GETPOST('search_accept_conference_sugges
|
||||
$search_accept_booth_suggestions = GETPOST('search_accept_booth_suggestions', 'int');
|
||||
$search_price_registration = GETPOST("search_price_registration", 'alpha');
|
||||
$search_price_booth = GETPOST("search_price_booth", '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);
|
||||
@ -286,6 +293,7 @@ if (empty($reshook)) {
|
||||
$search_price_registration = '';
|
||||
$search_price_booth = '';
|
||||
$toselect = '';
|
||||
$searchCategoryCustomerList = array();
|
||||
$search_array_options = array();
|
||||
$search_category_array = array();
|
||||
}
|
||||
@ -544,6 +552,50 @@ if ($search_price_registration != '') {
|
||||
if ($search_price_booth != '') {
|
||||
$sql .= natural_search('p.price_booth', $search_price_booth, 1);
|
||||
}
|
||||
$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
|
||||
@ -738,6 +790,9 @@ if ($search_price_booth != '') {
|
||||
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';
|
||||
|
||||
@ -843,6 +898,17 @@ if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
|
||||
$formcategory = new FormCategory($db);
|
||||
$moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PROJECT, $search_category_array);
|
||||
}
|
||||
// Filter on customer categories
|
||||
if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
|
||||
$moreforfilter .= '<div class="divsearchfield">';
|
||||
$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 .= ' <input type="checkbox" class="valignmiddle" id="search_category_customer_operator" name="search_category_customer_operator" value="1"'.($searchCategoryCustomerOperator == 1 ? ' checked="checked"' : '').'/><label class="none valignmiddle" for="search_category_customer_operator">'.$langs->trans('UseOrOperatorForCategories').'</label>';
|
||||
$moreforfilter .= '</div>';
|
||||
}
|
||||
|
||||
if (!empty($moreforfilter)) {
|
||||
print '<div class="liste_titre liste_titre_bydiv centpercent">';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user