mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
NEW customer category filter on contract list
This commit is contained in:
parent
25fbd3b385
commit
e79fffaccf
|
|
@ -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 .= '</div>';
|
||||
}
|
||||
// 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>';
|
||||
}
|
||||
|
||||
$parameters = array();
|
||||
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user