2
0
forked from Wavyzz/dolibarr

FIX filter on categories

This commit is contained in:
Laurent Destailleur
2022-10-11 03:01:09 +02:00
parent 92d0dff65d
commit f516a4b052
9 changed files with 1196 additions and 1112 deletions

View File

@@ -73,15 +73,15 @@ $massaction = GETPOST('massaction', 'alpha');
$show_files = GETPOST('show_files', 'int'); $show_files = GETPOST('show_files', 'int');
$confirm = GETPOST('confirm', 'alpha'); $confirm = GETPOST('confirm', 'alpha');
$toselect = GETPOST('toselect', 'array'); $toselect = GETPOST('toselect', 'array');
$optioncss = GETPOST('optioncss', 'alpha');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'invoicelist'; $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'invoicelist';
if ($contextpage == 'poslist') { if ($contextpage == 'poslist') {
$_GET['optioncss'] = 'print'; $optioncss = 'print';
} }
$lineid = GETPOST('lineid', 'int'); $lineid = GETPOST('lineid', 'int');
$userid = GETPOST('userid', 'int'); $userid = GETPOST('userid', 'int');
$search_product_category = GETPOST('search_product_category', 'int');
$search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha'); $search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
$search_refcustomer = GETPOST('search_refcustomer', 'alpha'); $search_refcustomer = GETPOST('search_refcustomer', 'alpha');
$search_type = GETPOST('search_type', 'int'); $search_type = GETPOST('search_type', 'int');
@@ -137,10 +137,10 @@ $search_datelimit_endyear = GETPOST('search_datelimit_endyear', 'int');
$search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear); $search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear);
$search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear); $search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear);
$search_categ_cus = GETPOST("search_categ_cus", 'int'); $search_categ_cus = GETPOST("search_categ_cus", 'int');
$search_product_category = GETPOST('search_product_category', 'int');
$search_fac_rec_source_title = GETPOST("search_fac_rec_source_title", 'alpha'); $search_fac_rec_source_title = GETPOST("search_fac_rec_source_title", 'alpha');
$search_btn = GETPOST('button_search', 'alpha'); $search_btn = GETPOST('button_search', 'alpha');
$search_remove_btn = GETPOST('button_removefilter', 'alpha'); $search_remove_btn = GETPOST('button_removefilter', 'alpha');
$optioncss = GETPOST('optioncss', 'alpha');
$option = GETPOST('search_option'); $option = GETPOST('search_option');
if ($option == 'late') { if ($option == 'late') {
@@ -581,9 +581,6 @@ if (!$sall) {
$sql .= ', SUM(pf.amount) as dynamount_payed, SUM(pf.multicurrency_amount) as multicurrency_dynamount_payed'; $sql .= ', SUM(pf.amount) as dynamount_payed, SUM(pf.multicurrency_amount) as multicurrency_dynamount_payed';
} }
*/ */
if ($search_categ_cus && $search_categ_cus != -1) {
$sql .= ", cc.fk_categorie, cc.fk_soc";
}
// Add fields from extrafields // Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label'])) { if (!empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
@@ -598,10 +595,6 @@ $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
if (!empty($search_categ_cus) && $search_categ_cus != '-1') {
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ
}
$sql .= ', '.MAIN_DB_PREFIX.'facture as f'; $sql .= ', '.MAIN_DB_PREFIX.'facture as f';
if ($sortfield == "f.datef") { if ($sortfield == "f.datef") {
$sql .= $db->hintindex('idx_facture_datef'); $sql .= $db->hintindex('idx_facture_datef');
@@ -619,10 +612,6 @@ if (!$sall) {
if ($sall || $search_product_category > 0) { if ($sall || $search_product_category > 0) {
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture';
} }
if ($search_product_category > 0) {
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
}
if (!empty($search_fac_rec_source_title)) { if (!empty($search_fac_rec_source_title)) {
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_rec as facrec ON f.fk_fac_rec_source=facrec.rowid'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_rec as facrec ON f.fk_fac_rec_source=facrec.rowid';
} }
@@ -646,9 +635,6 @@ $sql .= ' AND f.entity IN ('.getEntity('invoice').')';
if (empty($user->rights->societe->client->voir) && !$socid) { if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
} }
if ($search_product_category > 0) {
$sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
}
if ($socid > 0) { if ($socid > 0) {
$sql .= ' AND s.rowid = '.((int) $socid); $sql .= ' AND s.rowid = '.((int) $socid);
} }
@@ -746,12 +732,6 @@ if ($search_multicurrency_montant_ttc != '') {
if ($search_login) { if ($search_login) {
$sql .= natural_search(array('u.login', 'u.firstname', 'u.lastname'), $search_login); $sql .= natural_search(array('u.login', 'u.firstname', 'u.lastname'), $search_login);
} }
if ($search_categ_cus > 0) {
$sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus);
}
if ($search_categ_cus == -2) {
$sql .= " AND cc.fk_categorie IS NULL";
}
if ($search_status != '-1' && $search_status != '') { if ($search_status != '-1' && $search_status != '') {
if (is_numeric($search_status) && $search_status >= 0) { if (is_numeric($search_status) && $search_status >= 0) {
if ($search_status == '0') { if ($search_status == '0') {
@@ -813,6 +793,58 @@ if ($search_user > 0) {
if (!empty($search_fac_rec_source_title)) { if (!empty($search_fac_rec_source_title)) {
$sql .= natural_search('facrec.titre', $search_fac_rec_source_title); $sql .= natural_search('facrec.titre', $search_fac_rec_source_title);
} }
// Search for tag/category ($searchCategoryProductList is an array of ID)
$searchCategoryProductList = $search_product_category ? array($search_product_category) : array();
$searchCategoryProductOperator = 0;
if (!empty($searchCategoryProductList)) {
$searchCategoryProductSqlList = array();
$listofcategoryid = '';
foreach ($searchCategoryProductList as $searchCategoryProduct) {
if (intval($searchCategoryProduct) == -2) {
$searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product)";
} elseif (intval($searchCategoryProduct) > 0) {
$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
}
}
if ($listofcategoryid) {
$searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
}
if ($searchCategoryProductOperator == 1) {
if (!empty($searchCategoryProductSqlList)) {
$sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
}
} else {
if (!empty($searchCategoryProductSqlList)) {
$sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
}
}
}
$searchCategoryCustomerList = $search_categ_cus ? array($search_categ_cus) : array();;
$searchCategoryCustomerOperator = 0;
// Search for tag/category ($searchCategoryCustomerList is an array of ID)
if (!empty($searchCategoryCustomerList)) {
$searchCategoryCustomerSqlList = array();
$listofcategoryid = '';
foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
if (intval($searchCategoryCustomer) == -2) {
$searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc)";
} elseif (intval($searchCategoryCustomer) > 0) {
$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
}
}
if ($listofcategoryid) {
$searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
}
if ($searchCategoryCustomerOperator == 1) {
if (!empty($searchCategoryCustomerSqlList)) {
$sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
}
} else {
if (!empty($searchCategoryCustomerSqlList)) {
$sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
}
}
}
// Add where from extra fields // Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
// Add where from hooks // Add where from hooks

View File

@@ -1096,7 +1096,7 @@ class Translate
if ($obj) { if ($obj) {
// If a translation exists, we use it lese we use the default label // If a translation exists, we use it lese we use the default label
$this->cache_currencies[$obj->code_iso]['label'] = ($obj->code_iso && $this->trans("Currency".$obj->code_iso) != "Currency".$obj->code_iso ? $this->trans("Currency".$obj->code_iso) : ($obj->label != '-' ? $obj->label : '')); $this->cache_currencies[$obj->code_iso]['label'] = ($obj->code_iso && $this->trans("Currency".$obj->code_iso) != "Currency".$obj->code_iso ? $this->trans("Currency".$obj->code_iso) : ($obj->label != '-' ? $obj->label : ''));
$this->cache_currencies[$obj->code_iso]['unicode'] = (array) json_decode($obj->unicode, true); $this->cache_currencies[$obj->code_iso]['unicode'] = (array) json_decode((empty($obj->unicode) ? '' : $obj->unicode), true);
$label[$obj->code_iso] = $this->cache_currencies[$obj->code_iso]['label']; $label[$obj->code_iso] = $this->cache_currencies[$obj->code_iso]['label'];
} }
$i++; $i++;

View File

@@ -967,7 +967,10 @@ function sanitizeVal($out = '', $check = 'alphanohtml', $filter = null, $options
break; break;
case 'custom': case 'custom':
if (empty($filter)) { if (empty($filter)) {
return 'BadFourthParameterForGETPOST'; return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
}
if (empty($options)) {
return 'BadParameterForGETPOST - Param 4 of sanitizeVal()';
} }
$out = filter_var($out, $filter, $options); $out = filter_var($out, $filter, $options);
break; break;

View File

@@ -72,7 +72,6 @@ $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search
$search_label = GETPOST("search_label", "alpha"); $search_label = GETPOST("search_label", "alpha");
$search_amount_no_tax = GETPOST("search_amount_no_tax", "alpha"); $search_amount_no_tax = GETPOST("search_amount_no_tax", "alpha");
$search_amount_all_tax = GETPOST("search_amount_all_tax", "alpha"); $search_amount_all_tax = GETPOST("search_amount_all_tax", "alpha");
$search_product_category = GETPOST('search_product_category', 'int');
$search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha'); $search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
$search_refsupplier = GETPOST('search_refsupplier', 'alpha'); $search_refsupplier = GETPOST('search_refsupplier', 'alpha');
$search_type = GETPOST('search_type', 'int'); $search_type = GETPOST('search_type', 'int');
@@ -116,10 +115,10 @@ $search_datelimit_endmonth = GETPOST('search_datelimit_endmonth', 'int');
$search_datelimit_endyear = GETPOST('search_datelimit_endyear', 'int'); $search_datelimit_endyear = GETPOST('search_datelimit_endyear', 'int');
$search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear); $search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear);
$search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear); $search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear);
$toselect = GETPOST('toselect', 'array');
$search_btn = GETPOST('button_search', 'alpha'); $search_btn = GETPOST('button_search', 'alpha');
$search_remove_btn = GETPOST('button_removefilter', 'alpha'); $search_remove_btn = GETPOST('button_removefilter', 'alpha');
$search_categ_sup = trim(GETPOST("search_categ_sup", 'int')); $search_categ_sup = trim(GETPOST("search_categ_sup", 'int'));
$search_product_category = GETPOST('search_product_category', 'int');
$option = GETPOST('search_option'); $option = GETPOST('search_option');
if ($option == 'late') { if ($option == 'late') {
@@ -162,9 +161,9 @@ $search_array_options = $extrafields->getOptionalsFromPost($object->table_elemen
$fieldstosearchall = array( $fieldstosearchall = array(
'f.ref'=>'Ref', 'f.ref'=>'Ref',
'f.ref_supplier'=>'RefSupplier', 'f.ref_supplier'=>'RefSupplier',
'pd.description'=>'Description',
's.nom'=>"ThirdParty",
'f.note_public'=>'NotePublic', 'f.note_public'=>'NotePublic',
's.nom'=>"ThirdParty",
'pd.description'=>'Description',
); );
if (empty($user->socid)) { if (empty($user->socid)) {
$fieldstosearchall["f.note_private"] = "NotePrivate"; $fieldstosearchall["f.note_private"] = "NotePrivate";
@@ -296,10 +295,10 @@ if (empty($reshook)) {
$search_datelimit_end = ''; $search_datelimit_end = '';
$toselect = array(); $toselect = array();
$search_array_options = array(); $search_array_options = array();
$search_categ_sup = 0;
$filter = ''; $filter = '';
$option = ''; $option = '';
$socid = ""; $socid = "";
$search_categ_sup = 0;
} }
// Mass actions // Mass actions
@@ -421,9 +420,6 @@ $sql .= " state.code_departement as state_code, state.nom as state_name,";
$sql .= " country.code as country_code,"; $sql .= " country.code as country_code,";
$sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_label,"; $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_label,";
$sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender'; $sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender';
if ($search_categ_sup && $search_categ_sup != '-1') {
$sql .= ", cs.fk_categorie, cs.fk_soc";
}
// We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0) // We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0)
// TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field. // TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field.
if (!$search_all) { if (!$search_all) {
@@ -443,10 +439,6 @@ $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
if (!empty($search_categ_sup) && $search_categ_supplier != '-1') {
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs ON s.rowid = cs.fk_soc";
}
$sql .= ', '.MAIN_DB_PREFIX.'facture_fourn as f'; $sql .= ', '.MAIN_DB_PREFIX.'facture_fourn as f';
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
@@ -457,9 +449,6 @@ if (!$search_all) {
if ($search_all || $search_product_category > 0) { if ($search_all || $search_product_category > 0) {
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as pd ON f.rowid=pd.fk_facture_fourn'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as pd ON f.rowid=pd.fk_facture_fourn';
} }
if ($search_product_category > 0) {
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
}
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid';
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet";
// We'll need this table joined to the select in order to filter by sale // We'll need this table joined to the select in order to filter by sale
@@ -479,9 +468,6 @@ $sql .= ' AND f.entity IN ('.getEntity('facture_fourn').')';
if (empty($user->rights->societe->client->voir) && !$socid) { if (empty($user->rights->societe->client->voir) && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
} }
if ($search_product_category > 0) {
$sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
}
if ($socid > 0) { if ($socid > 0) {
$sql .= ' AND s.rowid = '.((int) $socid); $sql .= ' AND s.rowid = '.((int) $socid);
} }
@@ -598,11 +584,57 @@ if ($option == 'late') {
if ($search_label) { if ($search_label) {
$sql .= natural_search('f.libelle', $search_label); $sql .= natural_search('f.libelle', $search_label);
} }
if ($search_categ_sup > 0) { $searchCategorySupplierList = $search_categ_sup ? array($search_categ_sup) : array();
$sql .= " AND cs.fk_categorie = ".((int) $search_categ_sup); $searchCategorySupplierOperator = 0;
// Search for tag/category ($searchCategorySupplierList is an array of ID)
if (!empty($searchCategorySupplierList)) {
$searchCategorySupplierSqlList = array();
$listofcategoryid = '';
foreach ($searchCategorySupplierList as $searchCategorySupplier) {
if (intval($searchCategorySupplier) == -2) {
$searchCategorySupplierSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc)";
} elseif (intval($searchCategorySupplier) > 0) {
$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplier);
}
}
if ($listofcategoryid) {
$searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
}
if ($searchCategorySupplierOperator == 1) {
if (!empty($searchCategorySupplierSqlList)) {
$sql .= " AND (".implode(' OR ', $searchCategorySupplierSqlList).")";
}
} else {
if (!empty($searchCategorySupplierSqlList)) {
$sql .= " AND (".implode(' AND ', $searchCategorySupplierSqlList).")";
}
}
}
// Search for tag/category ($searchCategoryProductList is an array of ID)
$searchCategoryProductList = $search_product_category ? array($search_product_category) : array();
$searchCategorySupplierOperator = 0;
if (!empty($searchCategoryProductList)) {
$searchCategoryProductSqlList = array();
$listofcategoryid = '';
foreach ($searchCategoryProductList as $searchCategoryProduct) {
if (intval($searchCategoryProduct) == -2) {
$searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product)";
} elseif (intval($searchCategoryProduct) > 0) {
$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
}
}
if ($listofcategoryid) {
$searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
}
if ($searchCategoryProductOperator == 1) {
if (!empty($searchCategoryProductSqlList)) {
$sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
}
} else {
if (!empty($searchCategoryProductSqlList)) {
$sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
}
} }
if ($search_categ_sup == -2) {
$sql .= " AND cs.fk_categorie IS NULL";
} }
if ($search_status != '' && $search_status >= 0) { if ($search_status != '' && $search_status >= 0) {
$sql .= " AND f.fk_statut = ".((int) $search_status); $sql .= " AND f.fk_statut = ".((int) $search_status);
@@ -640,9 +672,6 @@ if (!$search_all) {
$sql .= ' country.code,'; $sql .= ' country.code,';
$sql .= " p.rowid, p.ref, p.title,"; $sql .= " p.rowid, p.ref, p.title,";
$sql .= " u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender"; $sql .= " u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender";
if ($search_categ_sup && $search_categ_sup != '-1') {
$sql .= ", cs.fk_categorie, cs.fk_soc";
}
if (!empty($extrafields->attributes[$object->table_element]['label'])) { if (!empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
//prevent error with sql_mode=only_full_group_by //prevent error with sql_mode=only_full_group_by
@@ -678,7 +707,10 @@ $sql .= $db->plimit($limit + 1, $offset);
//print $sql; //print $sql;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) { if (!$resql) {
dol_print_error($db);
}
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$arrayofselected = is_array($toselect) ? $toselect : array(); $arrayofselected = is_array($toselect) ? $toselect : array();
@@ -1747,6 +1779,17 @@ if ($resql) {
include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
} }
// If no record found
if ($num == 0) {
$colspan = 1;
foreach ($arrayfields as $key => $val) {
if (!empty($val['checked'])) {
$colspan++;
}
}
print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
}
$db->free($resql); $db->free($resql);
$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql); $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
@@ -1773,9 +1816,6 @@ if ($resql) {
$title = ''; $title = '';
print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
} else {
dol_print_error($db);
}
// End of page // End of page
llxFooter(); llxFooter();

View File

@@ -472,7 +472,7 @@ $moreforfilter.= '</div>';*/
// Filter on categories // Filter on categories
$moreforfilter = ''; $moreforfilter = '';
if (isModEnabled('categorie') && $user->rights->categorie->lire) { if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
$moreforfilter .= '<div class="divsearchfield">'; $moreforfilter .= '<div class="divsearchfield">';
$moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"'); $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"');
$categoriesKnowledgeArr = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', '', 64, 0, 1); $categoriesKnowledgeArr = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', '', 64, 0, 1);

View File

@@ -682,7 +682,7 @@ print '</tr>'."\n";
$needToFetchEachLine = 0; $needToFetchEachLine = 0;
if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) { if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) { foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
if (preg_match('/\$object/', $val)) { if ($val && preg_match('/\$object/', $val)) {
$needToFetchEachLine++; // There is at least one compute field that use $object $needToFetchEachLine++; // There is at least one compute field that use $object
} }
} }

View File

@@ -270,6 +270,7 @@ foreach ($search as $key => $val) {
if ($search_all) { if ($search_all) {
$sql .= natural_search(array_keys($fieldstosearchall), $search_all); $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
} }
// Search for tag/category
$searchCategoryProductSqlList = array(); $searchCategoryProductSqlList = array();
if ($searchCategoryProductOperator == 1) { if ($searchCategoryProductOperator == 1) {
$existsCategoryProductList = array(); $existsCategoryProductList = array();
@@ -314,7 +315,6 @@ if ($searchCategoryProductOperator == 1) {
$sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
} }
} }
//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
// Add where from extra fields // Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
// Add where from hooks // Add where from hooks

View File

@@ -375,7 +375,7 @@ if ($result || !($id > 0)) {
$morefilters = ' AND d.fk_product IN ('.$db->sanitize((is_array($listofprodids) && count($listofprodids)) ? join(',', $listofprodids) : '0').')'; $morefilters = ' AND d.fk_product IN ('.$db->sanitize((is_array($listofprodids) && count($listofprodids)) ? join(',', $listofprodids) : '0').')';
} }
if ($search_categ == -2) { if ($search_categ == -2) {
$morefilters = ' AND d.fk_product NOT IN (SELECT cp.fk_product from '.MAIN_DB_PREFIX.'categorie_product as cp)'; $morefilters = ' AND NOT EXISTS (SELECT cp.fk_product FROM '.MAIN_DB_PREFIX.'categorie_product as cp WHERE d.fk_product = cp.fk_product)';
} }
if ($key == 'propal') { if ($key == 'propal') {

View File

@@ -46,7 +46,7 @@ $mode = GETPOST('mode', 'aZ');
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
$search_categ = GETPOST("search_categ", 'alpha'); $search_categ = GETPOST("search_categ", 'int');
$search_projectstatus = GETPOST('search_projectstatus'); $search_projectstatus = GETPOST('search_projectstatus');
if (!isset($search_projectstatus) || $search_projectstatus === '') { if (!isset($search_projectstatus) || $search_projectstatus === '') {
@@ -335,10 +335,6 @@ $sql .= " t.datec as date_creation, t.dateo as date_start, t.datee as date_end,
$sql .= " t.rowid as id, t.ref, t.label, t.planned_workload, t.duration_effective, t.progress, t.fk_statut,"; $sql .= " t.rowid as id, t.ref, t.label, t.planned_workload, t.duration_effective, t.progress, t.fk_statut,";
$sql .= " t.description, t.fk_task_parent"; $sql .= " t.description, t.fk_task_parent";
$sql .= " ,t.budget_amount"; $sql .= " ,t.budget_amount";
// We'll need these fields in order to filter by categ
if ($search_categ > 0) {
$sql .= ", cs.fk_categorie, cs.fk_project";
}
// Add sum fields // Add sum fields
if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed']['checked'])) { if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed']['checked'])) {
$sql .= " , SUM(tt.task_duration * ".$db->ifsql("invoice_id IS NULL", "1", "0").") as tobill, SUM(tt.task_duration * ".$db->ifsql("invoice_id IS NULL", "0", "1").") as billed"; $sql .= " , SUM(tt.task_duration * ".$db->ifsql("invoice_id IS NULL", "1", "0").") as tobill, SUM(tt.task_duration * ".$db->ifsql("invoice_id IS NULL", "0", "1").") as billed";
@@ -355,10 +351,6 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // N
$sql .= $hookmanager->resPrint; $sql .= $hookmanager->resPrint;
$sql .= " FROM ".MAIN_DB_PREFIX."projet as p"; $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
// We'll need this table joined to the select in order to filter by categ
if ($search_categ > 0) {
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_project as cs ON p.rowid = cs.fk_project"; // We'll need this table joined to the select in order to filter by categ
}
$sql .= ", ".MAIN_DB_PREFIX."projet_task as t"; $sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed']['checked'])) { if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed']['checked'])) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_time as tt ON tt.fk_task = t.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_time as tt ON tt.fk_task = t.rowid";
@@ -384,12 +376,6 @@ if (is_object($projectstatic) && $projectstatic->id > 0) {
if ($socid) { if ($socid) {
$sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")"; $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
} }
if ($search_categ > 0) {
$sql .= " AND cs.fk_categorie = ".((int) $search_categ);
}
if ($search_categ == -2) {
$sql .= " AND cs.fk_categorie IS NULL";
}
if ($search_project_ref) { if ($search_project_ref) {
$sql .= natural_search('p.ref', $search_project_ref); $sql .= natural_search('p.ref', $search_project_ref);
} }
@@ -448,6 +434,32 @@ if ($search_project_user > 0) {
if ($search_task_user > 0) { if ($search_task_user > 0) {
$sql .= " AND ect.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listoftaskcontacttype))).") AND ect.element_id = t.rowid AND ect.fk_socpeople = ".((int) $search_task_user); $sql .= " AND ect.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listoftaskcontacttype))).") AND ect.element_id = t.rowid AND ect.fk_socpeople = ".((int) $search_task_user);
} }
// Search for tag/category ($searchCategoryProjectList is an array of ID)
$searchCategoryProjectList = array($search_categ);
$searchCategoryProjectOperator = 0;
if (!empty($searchCategoryProjectList)) {
$searchCategoryProjectSqlList = array();
$listofcategoryid = '';
foreach ($searchCategoryProjectList as $searchCategoryProject) {
if (intval($searchCategoryProject) == -2) {
$searchCategoryProjectSqlList[] = "NOT EXISTS (SELECT ck.fk_project FROM ".MAIN_DB_PREFIX."categorie_project as ck WHERE p.rowid = ck.fk_project)";
} elseif (intval($searchCategoryProject) > 0) {
$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProject);
}
}
if ($listofcategoryid) {
$searchCategoryProjectSqlList[] = " EXISTS (SELECT ck.fk_project FROM ".MAIN_DB_PREFIX."categorie_project as ck WHERE p.rowid = ck.fk_project AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
}
if ($searchCategoryProjectOperator == 1) {
if (!empty($searchCategoryProjectSqlList)) {
$sql .= " AND (".implode(' OR ', $searchCategoryProjectSqlList).")";
}
} else {
if (!empty($searchCategoryProjectSqlList)) {
$sql .= " AND (".implode(' AND ', $searchCategoryProjectSqlList).")";
}
}
}
// Add where from extra fields // Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
// Add where from hooks // Add where from hooks
@@ -459,9 +471,6 @@ if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed
$sql .= " s.nom, s.rowid,"; $sql .= " s.nom, s.rowid,";
$sql .= " t.datec, t.dateo, t.datee, t.tms,"; $sql .= " t.datec, t.dateo, t.datee, t.tms,";
$sql .= " t.rowid, t.ref, t.label, t.planned_workload, t.duration_effective, t.progress,t.budget_amount, t.fk_statut"; $sql .= " t.rowid, t.ref, t.label, t.planned_workload, t.duration_effective, t.progress,t.budget_amount, t.fk_statut";
if ($search_categ) {
$sql .= ", cs.fk_categorie, cs.fk_project";
}
// Add fields from extrafields // Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label'])) { if (!empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
@@ -675,7 +684,7 @@ if (isModEnabled('categorie') && $user->rights->categorie->lire) {
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$moreforfilter .= '<div class="divsearchfield">'; $moreforfilter .= '<div class="divsearchfield">';
$tmptitle = $langs->trans('ProjectCategories'); $tmptitle = $langs->trans('ProjectCategories');
$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('project', $search_categ, 'search_categ', 0, $tmptitle, 'maxwidth300'); $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('project', $search_categ, 'search_categ', 1, $tmptitle, 'maxwidth300');
$moreforfilter .= '</div>'; $moreforfilter .= '</div>';
} }