浏览代码

FIX filter on categories

Laurent Destailleur 2 年之前
父节点
当前提交
f516a4b052

+ 55 - 23
htdocs/compta/facture/list.php

@@ -73,15 +73,15 @@ $massaction = GETPOST('massaction', 'alpha');
 $show_files = GETPOST('show_files', 'int');
 $confirm = GETPOST('confirm', 'alpha');
 $toselect = GETPOST('toselect', 'array');
+$optioncss = GETPOST('optioncss', 'alpha');
 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'invoicelist';
 
 if ($contextpage == 'poslist') {
-	$_GET['optioncss'] = 'print';
+	$optioncss = 'print';
 }
 
 $lineid = GETPOST('lineid', '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_refcustomer = GETPOST('search_refcustomer', 'alpha');
 $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_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear);
 $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_btn = GETPOST('button_search', 'alpha');
 $search_remove_btn = GETPOST('button_removefilter', 'alpha');
-$optioncss = GETPOST('optioncss', 'alpha');
 
 $option = GETPOST('search_option');
 if ($option == 'late') {
@@ -581,9 +581,6 @@ if (!$sall) {
 	$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
 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
 	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_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)";
-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';
 if ($sortfield == "f.datef") {
 	$sql .= $db->hintindex('idx_facture_datef');
@@ -619,10 +612,6 @@ if (!$sall) {
 if ($sall || $search_product_category > 0) {
 	$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)) {
 	$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) {
 	$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) {
 	$sql .= ' AND s.rowid = '.((int) $socid);
 }
@@ -746,12 +732,6 @@ if ($search_multicurrency_montant_ttc != '') {
 if ($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 (is_numeric($search_status) && $search_status >= 0) {
 		if ($search_status == '0') {
@@ -813,6 +793,58 @@ if ($search_user > 0) {
 if (!empty($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
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
 // Add where from hooks

+ 1 - 1
htdocs/core/class/translate.class.php

@@ -1096,7 +1096,7 @@ class Translate
 				if ($obj) {
 					// 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]['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'];
 				}
 				$i++;

+ 4 - 1
htdocs/core/lib/functions.lib.php

@@ -967,7 +967,10 @@ function sanitizeVal($out = '', $check = 'alphanohtml', $filter = null, $options
 			break;
 		case 'custom':
 			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);
 			break;

+ 1072 - 1032
htdocs/fourn/facture/list.php

@@ -72,7 +72,6 @@ $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search
 $search_label = GETPOST("search_label", "alpha");
 $search_amount_no_tax = GETPOST("search_amount_no_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_refsupplier = GETPOST('search_refsupplier', 'alpha');
 $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_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);
-$toselect = GETPOST('toselect', 'array');
 $search_btn = GETPOST('button_search', 'alpha');
 $search_remove_btn = GETPOST('button_removefilter', 'alpha');
 $search_categ_sup = trim(GETPOST("search_categ_sup", 'int'));
+$search_product_category = GETPOST('search_product_category', 'int');
 
 $option = GETPOST('search_option');
 if ($option == 'late') {
@@ -162,9 +161,9 @@ $search_array_options = $extrafields->getOptionalsFromPost($object->table_elemen
 $fieldstosearchall = array(
 	'f.ref'=>'Ref',
 	'f.ref_supplier'=>'RefSupplier',
-	'pd.description'=>'Description',
-	's.nom'=>"ThirdParty",
 	'f.note_public'=>'NotePublic',
+	's.nom'=>"ThirdParty",
+	'pd.description'=>'Description',
 );
 if (empty($user->socid)) {
 	$fieldstosearchall["f.note_private"] = "NotePrivate";
@@ -296,10 +295,10 @@ if (empty($reshook)) {
 		$search_datelimit_end = '';
 		$toselect = array();
 		$search_array_options = array();
+		$search_categ_sup = 0;
 		$filter = '';
 		$option = '';
 		$socid = "";
-		$search_categ_sup = 0;
 	}
 
 	// 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 .= " 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';
-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)
 // 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) {
@@ -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_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)";
-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';
 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)";
@@ -457,9 +449,6 @@ if (!$search_all) {
 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';
 }
-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."projet as p ON p.rowid = f.fk_projet";
 // 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) {
 	$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) {
 	$sql .= ' AND s.rowid = '.((int) $socid);
 }
@@ -598,11 +584,57 @@ if ($option == 'late') {
 if ($search_label) {
 	$sql .= natural_search('f.libelle', $search_label);
 }
-if ($search_categ_sup > 0) {
-	$sql .= " AND cs.fk_categorie = ".((int) $search_categ_sup);
+$searchCategorySupplierList = $search_categ_sup ? array($search_categ_sup) : array();
+$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).")";
+		}
+	}
 }
-if ($search_categ_sup == -2) {
-	$sql .= " AND cs.fk_categorie IS NULL";
+// 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_status != '' && $search_status >= 0) {
 	$sql .= " AND f.fk_statut = ".((int) $search_status);
@@ -640,9 +672,6 @@ if (!$search_all) {
 	$sql .= ' country.code,';
 	$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";
-	if ($search_categ_sup && $search_categ_sup != '-1') {
-		$sql .= ", cs.fk_categorie, cs.fk_soc";
-	}
 	if (!empty($extrafields->attributes[$object->table_element]['label'])) {
 		foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
 			//prevent error with sql_mode=only_full_group_by
@@ -678,1105 +707,1116 @@ $sql .= $db->plimit($limit + 1, $offset);
 //print $sql;
 
 $resql = $db->query($sql);
-if ($resql) {
-	$num = $db->num_rows($resql);
+if (!$resql) {
+	dol_print_error($db);
+}
 
-	$arrayofselected = is_array($toselect) ? $toselect : array();
+$num = $db->num_rows($resql);
 
-	if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) {
-		$obj = $db->fetch_object($resql);
-		$id = $obj->facid;
+$arrayofselected = is_array($toselect) ? $toselect : array();
 
-		header("Location: ".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id);
-		exit;
-	}
+if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) {
+	$obj = $db->fetch_object($resql);
+	$id = $obj->facid;
 
-	llxHeader('', $langs->trans("SuppliersInvoices"), 'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores');
+	header("Location: ".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id);
+	exit;
+}
 
-	if ($socid) {
-		$soc = new Societe($db);
-		$soc->fetch($socid);
-		if (empty($search_company)) {
-			$search_company = $soc->name;
-			$search_company_alias = $soc->name_alias;
-		}
-	}
+llxHeader('', $langs->trans("SuppliersInvoices"), 'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores');
 
-	$param = '&socid='.$socid;
-	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
-		$param .= '&contextpage='.urlencode($contextpage);
-	}
-	if ($limit > 0 && $limit != $conf->liste_limit) {
-		$param .= '&limit='.urlencode($limit);
-	}
-	if ($search_all) {
-		$param .= '&search_all='.urlencode($search_all);
-	}
-	if ($search_date_startday) {
-		$param .= '&search_date_startday='.urlencode($search_date_startday);
-	}
-	if ($search_date_startmonth) {
-		$param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
-	}
-	if ($search_date_startyear) {
-		$param .= '&search_date_startyear='.urlencode($search_date_startyear);
-	}
-	if ($search_date_endday) {
-		$param .= '&search_date_endday='.urlencode($search_date_endday);
-	}
-	if ($search_date_endmonth) {
-		$param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
-	}
-	if ($search_date_endyear) {
-		$param .= '&search_date_endyear='.urlencode($search_date_endyear);
-	}
-	if ($search_datelimit_startday) {
-		$param .= '&search_datelimit_startday='.urlencode($search_datelimit_startday);
-	}
-	if ($search_datelimit_startmonth) {
-		$param .= '&search_datelimit_startmonth='.urlencode($search_datelimit_startmonth);
-	}
-	if ($search_datelimit_startyear) {
-		$param .= '&search_datelimit_startyear='.urlencode($search_datelimit_startyear);
-	}
-	if ($search_datelimit_endday) {
-		$param .= '&search_datelimit_endday='.urlencode($search_datelimit_endday);
-	}
-	if ($search_datelimit_endmonth) {
-		$param .= '&search_datelimit_endmonth='.urlencode($search_datelimit_endmonth);
-	}
-	if ($search_datelimit_endyear) {
-		$param .= '&search_datelimit_endyear='.urlencode($search_datelimit_endyear);
-	}
-	if ($search_ref) {
-		$param .= '&search_ref='.urlencode($search_ref);
-	}
-	if ($search_refsupplier) {
-		$param .= '&search_refsupplier='.urlencode($search_refsupplier);
-	}
-	if ($search_type != '') {
-		$param .= '&search_type='.urlencode($search_type);
-	}
-	if ($search_label) {
-		$param .= '&search_label='.urlencode($search_label);
-	}
-	if ($search_company) {
-		$param .= '&search_company='.urlencode($search_company);
-	}
-	if ($search_company_alias) {
-		$param .= '&search_company_alias='.urlencode($search_company_alias);
-	}
-	if ($search_login) {
-		$param .= '&search_login='.urlencode($search_login);
-	}
-	if ($search_montant_ht != '') {
-		$param .= '&search_montant_ht='.urlencode($search_montant_ht);
-	}
-	if ($search_montant_vat != '') {
-		$param .= '&search_montant_vat='.urlencode($search_montant_vat);
-	}
-	if ($search_montant_localtax1 != '') {
-		$param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
-	}
-	if ($search_montant_localtax2 != '') {
-		$param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
-	}
-	if ($search_montant_ttc != '') {
-		$param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
-	}
-	if ($search_multicurrency_code != '') {
-		$param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
-	}
-	if ($search_multicurrency_tx != '') {
-		$param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
-	}
-	if ($search_multicurrency_montant_ht != '') {
-		$param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
-	}
-	if ($search_multicurrency_montant_vat != '') {
-		$param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
-	}
-	if ($search_multicurrency_montant_ttc != '') {
-		$param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
-	}
-	if ($search_amount_no_tax) {
-		$param .= '&search_amount_no_tax='.urlencode($search_amount_no_tax);
-	}
-	if ($search_amount_all_tax) {
-		$param .= '&search_amount_all_tax='.urlencode($search_amount_all_tax);
-	}
-	if ($search_status >= 0) {
-		$param .= "&search_status=".urlencode($search_status);
-	}
-	if ($show_files) {
-		$param .= '&show_files='.urlencode($show_files);
-	}
-	if ($option) {
-		$param .= "&search_option=".urlencode($option);
-	}
-	if ($optioncss != '') {
-		$param .= '&optioncss='.urlencode($optioncss);
-	}
-	if ($search_categ_sup > 0) {
-		$param .= '&search_categ_sup='.urlencode($search_categ_sup);
-	}
-	if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
-		$param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
+if ($socid) {
+	$soc = new Societe($db);
+	$soc->fetch($socid);
+	if (empty($search_company)) {
+		$search_company = $soc->name;
+		$search_company_alias = $soc->name_alias;
 	}
+}
 
-	// Add $param from extra fields
-	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
-	// Add $param from hooks
-	$parameters = array();
-	$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
-	$param .= $hookmanager->resPrint;
-
-	// List of mass actions available
-	$arrayofmassactions = array(
-		'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
-		'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
-		//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
-		//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
-	);
+$param = '&socid='.$socid;
+if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
+	$param .= '&contextpage='.urlencode($contextpage);
+}
+if ($limit > 0 && $limit != $conf->liste_limit) {
+	$param .= '&limit='.urlencode($limit);
+}
+if ($search_all) {
+	$param .= '&search_all='.urlencode($search_all);
+}
+if ($search_date_startday) {
+	$param .= '&search_date_startday='.urlencode($search_date_startday);
+}
+if ($search_date_startmonth) {
+	$param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
+}
+if ($search_date_startyear) {
+	$param .= '&search_date_startyear='.urlencode($search_date_startyear);
+}
+if ($search_date_endday) {
+	$param .= '&search_date_endday='.urlencode($search_date_endday);
+}
+if ($search_date_endmonth) {
+	$param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
+}
+if ($search_date_endyear) {
+	$param .= '&search_date_endyear='.urlencode($search_date_endyear);
+}
+if ($search_datelimit_startday) {
+	$param .= '&search_datelimit_startday='.urlencode($search_datelimit_startday);
+}
+if ($search_datelimit_startmonth) {
+	$param .= '&search_datelimit_startmonth='.urlencode($search_datelimit_startmonth);
+}
+if ($search_datelimit_startyear) {
+	$param .= '&search_datelimit_startyear='.urlencode($search_datelimit_startyear);
+}
+if ($search_datelimit_endday) {
+	$param .= '&search_datelimit_endday='.urlencode($search_datelimit_endday);
+}
+if ($search_datelimit_endmonth) {
+	$param .= '&search_datelimit_endmonth='.urlencode($search_datelimit_endmonth);
+}
+if ($search_datelimit_endyear) {
+	$param .= '&search_datelimit_endyear='.urlencode($search_datelimit_endyear);
+}
+if ($search_ref) {
+	$param .= '&search_ref='.urlencode($search_ref);
+}
+if ($search_refsupplier) {
+	$param .= '&search_refsupplier='.urlencode($search_refsupplier);
+}
+if ($search_type != '') {
+	$param .= '&search_type='.urlencode($search_type);
+}
+if ($search_label) {
+	$param .= '&search_label='.urlencode($search_label);
+}
+if ($search_company) {
+	$param .= '&search_company='.urlencode($search_company);
+}
+if ($search_company_alias) {
+	$param .= '&search_company_alias='.urlencode($search_company_alias);
+}
+if ($search_login) {
+	$param .= '&search_login='.urlencode($search_login);
+}
+if ($search_montant_ht != '') {
+	$param .= '&search_montant_ht='.urlencode($search_montant_ht);
+}
+if ($search_montant_vat != '') {
+	$param .= '&search_montant_vat='.urlencode($search_montant_vat);
+}
+if ($search_montant_localtax1 != '') {
+	$param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
+}
+if ($search_montant_localtax2 != '') {
+	$param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
+}
+if ($search_montant_ttc != '') {
+	$param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
+}
+if ($search_multicurrency_code != '') {
+	$param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
+}
+if ($search_multicurrency_tx != '') {
+	$param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
+}
+if ($search_multicurrency_montant_ht != '') {
+	$param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
+}
+if ($search_multicurrency_montant_vat != '') {
+	$param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
+}
+if ($search_multicurrency_montant_ttc != '') {
+	$param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
+}
+if ($search_amount_no_tax) {
+	$param .= '&search_amount_no_tax='.urlencode($search_amount_no_tax);
+}
+if ($search_amount_all_tax) {
+	$param .= '&search_amount_all_tax='.urlencode($search_amount_all_tax);
+}
+if ($search_status >= 0) {
+	$param .= "&search_status=".urlencode($search_status);
+}
+if ($show_files) {
+	$param .= '&show_files='.urlencode($show_files);
+}
+if ($option) {
+	$param .= "&search_option=".urlencode($option);
+}
+if ($optioncss != '') {
+	$param .= '&optioncss='.urlencode($optioncss);
+}
+if ($search_categ_sup > 0) {
+	$param .= '&search_categ_sup='.urlencode($search_categ_sup);
+}
+if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
+	$param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
+}
 
-	if (isModEnabled('paymentbybanktransfer') && !empty($user->rights->paymentbybanktransfer->create)) {
-		$langs->load('withdrawals');
-		$arrayofmassactions['banktransfertrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeBankTransferOrder");
-	}
-	if ($user->rights->fournisseur->facture->supprimer) {
-		$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
-	}
-	if (in_array($massaction, array('presend', 'predelete'))) {
-		$arrayofmassactions = array();
-	}
-	$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
+// Add $param from extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
+// Add $param from hooks
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
+$param .= $hookmanager->resPrint;
+
+// List of mass actions available
+$arrayofmassactions = array(
+	'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
+	'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
+	//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
+	//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
+);
 
-	$url = DOL_URL_ROOT.'/fourn/facture/card.php?action=create';
-	if (!empty($socid)) {
-		$url .= '&socid='.urlencode($socid);
-	}
-	$newcardbutton = dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer));
+if (isModEnabled('paymentbybanktransfer') && !empty($user->rights->paymentbybanktransfer->create)) {
+	$langs->load('withdrawals');
+	$arrayofmassactions['banktransfertrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeBankTransferOrder");
+}
+if ($user->rights->fournisseur->facture->supprimer) {
+	$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
+}
+if (in_array($massaction, array('presend', 'predelete'))) {
+	$arrayofmassactions = array();
+}
+$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
 
-	$i = 0;
-	print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
-	if ($optioncss != '') {
-		print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
-	}
-	print '<input type="hidden" name="token" value="'.newToken().'">';
-	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
-	print '<input type="hidden" name="action" value="list">';
-	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
-	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
-	print '<input type="hidden" name="socid" value="'.$socid.'">';
-
-	print_barre_liste($langs->trans("BillsSuppliers").($socid ? ' '.$soc->name : ''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_invoice', 0, $newcardbutton, '', $limit, 0, 0, 1);
-
-	$topicmail = "SendBillRef";
-	$modelmail = "invoice_supplier_send";
-	$objecttmp = new FactureFournisseur($db);
-	$trackid = 'sinv'.$object->id;
-	include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
-
-	if ($search_all) {
-		foreach ($fieldstosearchall as $key => $val) {
-			$fieldstosearchall[$key] = $langs->trans($val);
-		}
-		print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
-	}
+$url = DOL_URL_ROOT.'/fourn/facture/card.php?action=create';
+if (!empty($socid)) {
+	$url .= '&socid='.urlencode($socid);
+}
+$newcardbutton = dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer));
 
-	// If the user can view prospects other than his'
-	$moreforfilter = '';
-	if ($user->rights->user->user->lire) {
-		$langs->load("commercial");
-		$moreforfilter .= '<div class="divsearchfield">';
-		$tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
-		$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
-		$moreforfilter .= '</div>';
-	}
-	// If the user can view prospects other than his'
-	if ($user->rights->user->user->lire) {
-		$moreforfilter .= '<div class="divsearchfield">';
-		$tmptitle = $langs->trans('LinkedToSpecificUsers');
-		$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
-		$moreforfilter .= '</div>';
-	}
-	// If the user can view prospects other than his'
-	if (isModEnabled('categorie') && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
-		include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
-		$moreforfilter .= '<div class="divsearchfield">';
-		$tmptitle = $langs->trans('IncludingProductWithTag');
-		$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
-		$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth300 widthcentpercentminusx', 1);
-		$moreforfilter .= '</div>';
-	}
+$i = 0;
+print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
+if ($optioncss != '') {
+	print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
+}
+print '<input type="hidden" name="token" value="'.newToken().'">';
+print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
+print '<input type="hidden" name="action" value="list">';
+print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
+print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
+print '<input type="hidden" name="socid" value="'.$socid.'">';
 
-	if (isModEnabled('categorie')) {
-		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
-		$moreforfilter .= '<div class="divsearchfield">';
-		$tmptitle = $langs->trans('SuppliersCategoriesShort');
-		$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1, $tmptitle);
-		$moreforfilter .= '</div>';
-	}
-	$parameters = array();
-	$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
-	if (empty($reshook)) {
-		$moreforfilter .= $hookmanager->resPrint;
-	} else {
-		$moreforfilter = $hookmanager->resPrint;
-	}
+print_barre_liste($langs->trans("BillsSuppliers").($socid ? ' '.$soc->name : ''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_invoice', 0, $newcardbutton, '', $limit, 0, 0, 1);
 
-	if ($moreforfilter) {
-		print '<div class="liste_titre liste_titre_bydiv centpercent">';
-		print $moreforfilter;
-		print '</div>';
-	}
+$topicmail = "SendBillRef";
+$modelmail = "invoice_supplier_send";
+$objecttmp = new FactureFournisseur($db);
+$trackid = 'sinv'.$object->id;
+include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
 
-	$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
-	$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
-	if ($massactionbutton) {
-		$selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
+if ($search_all) {
+	foreach ($fieldstosearchall as $key => $val) {
+		$fieldstosearchall[$key] = $langs->trans($val);
 	}
+	print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
+}
 
-	print '<div class="div-table-responsive">';
-	print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
+// If the user can view prospects other than his'
+$moreforfilter = '';
+if ($user->rights->user->user->lire) {
+	$langs->load("commercial");
+	$moreforfilter .= '<div class="divsearchfield">';
+	$tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
+	$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
+	$moreforfilter .= '</div>';
+}
+// If the user can view prospects other than his'
+if ($user->rights->user->user->lire) {
+	$moreforfilter .= '<div class="divsearchfield">';
+	$tmptitle = $langs->trans('LinkedToSpecificUsers');
+	$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
+	$moreforfilter .= '</div>';
+}
+// If the user can view prospects other than his'
+if (isModEnabled('categorie') && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
+	include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
+	$moreforfilter .= '<div class="divsearchfield">';
+	$tmptitle = $langs->trans('IncludingProductWithTag');
+	$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
+	$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth300 widthcentpercentminusx', 1);
+	$moreforfilter .= '</div>';
+}
 
-	// Line for filters
-	print '<tr class="liste_titre_filter">';
-	// Ref
-	if (!empty($arrayfields['f.ref']['checked'])) {
-		print '<td class="liste_titre left">';
-		print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
-		print '</td>';
-	}
-	// Ref supplier
-	if (!empty($arrayfields['f.ref_supplier']['checked'])) {
-		print '<td class="liste_titre">';
-		print '<input class="flat maxwidth75" type="text" name="search_refsupplier" value="'.dol_escape_htmltag($search_refsupplier).'">';
-		print '</td>';
-	}
-	// Type
-	if (!empty($arrayfields['f.type']['checked'])) {
-		print '<td class="liste_titre maxwidthonsmartphone">';
-		$listtype = array(
-				FactureFournisseur::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
-				FactureFournisseur::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
-				FactureFournisseur::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
-				FactureFournisseur::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
-		);
-		/*
-		if (!empty($conf->global->INVOICE_USE_SITUATION))
-		{
-			$listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
-		}
-		*/
-		//$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma");     // A proformat invoice is not an invoice but must be an order.
-		print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
-		print '</td>';
-	}
-	// Label
-	if (!empty($arrayfields['f.label']['checked'])) {
-		print '<td class="liste_titre">';
-		print '<input class="flat maxwidth75" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
-		print '</td>';
-	}
-	// Date invoice
-	if (!empty($arrayfields['f.datef']['checked'])) {
-		print '<td class="liste_titre center">';
-		print '<div class="nowrap">';
-		print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
-		print '</div>';
-		print '<div class="nowrap">';
-		print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
-		print '</div>';
-		print '</td>';
-	}
-	// Date due
-	if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
-		print '<td class="liste_titre center">';
-		print '<div class="nowrap">';
-		/*
-		print $langs->trans('From').' ';
-		print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1);
-		print '</div>';
-		print '<div class="nowrap">';
-		print $langs->trans('to').' ';*/
-		print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before"));
-		print '<br><input type="checkbox" name="search_option" value="late"'.($option == 'late' ? ' checked' : '').'> '.$langs->trans("Alert");
-		print '</div>';
-		print '</td>';
-	}
-	// Project
-	if (!empty($arrayfields['p.ref']['checked'])) {
-		print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
-	}
-	// Thirpdarty
-	if (!empty($arrayfields['s.nom']['checked'])) {
-		print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'"'.($socid > 0 ? " disabled" : "").'></td>';
-	}
-	// Alias
-	if (!empty($arrayfields['s.name_alias']['checked'])) {
-		print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'"></td>';
-	}
-	// Town
-	if (!empty($arrayfields['s.town']['checked'])) {
-		print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
-	}
-	// Zip
-	if (!empty($arrayfields['s.zip']['checked'])) {
-		print '<td class="liste_titre center"><input class="flat maxwidth50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
-	}
-	// State
-	if (!empty($arrayfields['state.nom']['checked'])) {
-		print '<td class="liste_titre">';
-		print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
-		print '</td>';
-	}
-	// Country
-	if (!empty($arrayfields['country.code_iso']['checked'])) {
-		print '<td class="liste_titre center">';
-		print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
-		print '</td>';
-	}
-	// Company type
-	if (!empty($arrayfields['typent.code']['checked'])) {
-		print '<td class="liste_titre maxwidthonsmartphone center">';
-		print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
-		print '</td>';
-	}
-	// Condition of payment
-	if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
-		print '<td class="liste_titre left">';
-		print $form->getSelectConditionsPaiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100');
-		print '</td>';
-	}
-	// Payment mode
-	if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
-		print '<td class="liste_titre left">';
-		print $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 20, 1, 'maxwidth100', 1);
-		print '</td>';
-	}
-	if (!empty($arrayfields['f.total_ht']['checked'])) {
-		// Amount without tax
-		print '<td class="liste_titre right">';
-		print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['f.total_vat']['checked'])) {
-		// Amount vat
-		print '<td class="liste_titre right">';
-		print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['f.total_localtax1']['checked'])) {
-		// Amount tax 1
-		print '<td class="liste_titre right">';
-		print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.dol_escape_htmltag($search_montant_localtax1).'">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['f.total_localtax2']['checked'])) {
-		// Amount tax 2
-		print '<td class="liste_titre right">';
-		print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.dol_escape_htmltag($search_montant_localtax2).'">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['f.total_ttc']['checked'])) {
-		// Amount inc tac
-		print '<td class="liste_titre right">';
-		print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['u.login']['checked'])) {
-		// Author
-		print '<td class="liste_titre" align="center">';
-		print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['dynamount_payed']['checked'])) {
-		print '<td class="liste_titre right">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['rtp']['checked'])) {
-		print '<td class="liste_titre">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
-		// Currency
-		print '<td class="liste_titre">';
-		print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
-		print '</td>';
-	}
-	if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
-		// Currency rate
-		print '<td class="liste_titre">';
-		print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
-		// Amount
-		print '<td class="liste_titre right">';
-		print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
-		// Amount
-		print '<td class="liste_titre right">';
-		print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
-		// Amount
-		print '<td class="liste_titre right">';
-		print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
-		print '<td class="liste_titre">';
-		print '</td>';
-	}
-	if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
-		print '<td class="liste_titre right">';
-		print '</td>';
-	}
-	// Extra fields
-	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
-
-	// Fields from hook
-	$parameters = array('arrayfields'=>$arrayfields);
-	$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
-	print $hookmanager->resPrint;
-	// Date creation
-	if (!empty($arrayfields['f.datec']['checked'])) {
-		print '<td class="liste_titre">';
-		print '</td>';
-	}
-	// Date modification
-	if (!empty($arrayfields['f.tms']['checked'])) {
-		print '<td class="liste_titre">';
-		print '</td>';
-	}
-	// Status
-	if (!empty($arrayfields['f.fk_statut']['checked'])) {
-		print '<td class="liste_titre maxwidthonsmartphone right">';
-		$liststatus = array('0'=>$langs->trans("Draft"), '1'=>$langs->trans("Unpaid"), '2'=>$langs->trans("Paid"));
-		print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', '', 1);
-		print '</td>';
-	}
-	// Action column
-	print '<td class="liste_titre middle">';
-	$searchpicto = $form->showFilterButtons();
-	print $searchpicto;
-	print '</td>';
+if (isModEnabled('categorie')) {
+	require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
+	$moreforfilter .= '<div class="divsearchfield">';
+	$tmptitle = $langs->trans('SuppliersCategoriesShort');
+	$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1, $tmptitle);
+	$moreforfilter .= '</div>';
+}
+$parameters = array();
+$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
+if (empty($reshook)) {
+	$moreforfilter .= $hookmanager->resPrint;
+} else {
+	$moreforfilter = $hookmanager->resPrint;
+}
 
-	print "</tr>\n";
+if ($moreforfilter) {
+	print '<div class="liste_titre liste_titre_bydiv centpercent">';
+	print $moreforfilter;
+	print '</div>';
+}
 
-	print '<tr class="liste_titre">';
-	if (!empty($arrayfields['f.ref']['checked'])) {
-		print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref,f.rowid', '', $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['f.ref_supplier']['checked'])) {
-		print_liste_field_titre($arrayfields['f.ref_supplier']['label'], $_SERVER["PHP_SELF"], 'f.ref_supplier', '', $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['f.type']['checked'])) {
-		print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['f.label']['checked'])) {
-		print_liste_field_titre($arrayfields['f.label']['label'], $_SERVER['PHP_SELF'], "f.libelle,f.rowid", '', $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['f.datef']['checked'])) {
-		print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef,f.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
-	}
-	if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
-		print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center ');
-	}
-	if (!empty($arrayfields['p.ref']['checked'])) {
-		print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['s.nom']['checked'])) {
-		print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['s.name_alias']['checked'])) {
-		print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['s.town']['checked'])) {
-		print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['s.zip']['checked'])) {
-		print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder, 'center ');
-	}
-	if (!empty($arrayfields['state.nom']['checked'])) {
-		print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.name_alias", "", $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['state.name_alias']['checked'])) {
-		print_liste_field_titre($arrayfields['state.name_alias']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['country.code_iso']['checked'])) {
-		print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
-	}
-	if (!empty($arrayfields['typent.code']['checked'])) {
-		print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
-	}
-	if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
-		print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
-		print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['f.total_ht']['checked'])) {
-		print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
-	}
-	if (!empty($arrayfields['f.total_vat']['checked'])) {
-		print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
-	}
-	if (!empty($arrayfields['f.total_localtax1']['checked'])) {
-		print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right ');
-	}
-	if (!empty($arrayfields['f.total_localtax2']['checked'])) {
-		print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right ');
-	}
-	if (!empty($arrayfields['f.total_ttc']['checked'])) {
-		print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
-	}
-	if (!empty($arrayfields['u.login']['checked'])) {
-		print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['dynamount_payed']['checked'])) {
-		print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
-	}
-	if (!empty($arrayfields['rtp']['checked'])) {
-		print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
-	}
-	if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
-		print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
-		print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
-		print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
-		print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
-		print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
-		print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
-	}
-	if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
-		print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
-	}
-	// Extra fields
-	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
-	// Hook fields
-	$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
-	$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
-	print $hookmanager->resPrint;
-	if (!empty($arrayfields['f.datec']['checked'])) {
-		print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
-	}
-	if (!empty($arrayfields['f.tms']['checked'])) {
-		print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
-	}
-	if (!empty($arrayfields['f.fk_statut']['checked'])) {
-		print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'right ');
-	}
-	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
-	print "</tr>\n";
-
-	$facturestatic = new FactureFournisseur($db);
-	$supplierstatic = new Fournisseur($db);
-	$projectstatic = new Project($db);
-	$userstatic = new User($db);
-
-	if ($num > 0) {
-		$i = 0;
-		$totalarray = array();
-		$totalarray['nbfield']=0;
-		$totalarray['val'] = array();
-		$totalarray['val']['f.total_ht']=0;
-		$totalarray['val']['f.total_vat']=0;
-		$totalarray['val']['f.total_localtax1']=0;
-		$totalarray['val']['f.total_localtax1']=0;
-		$totalarray['val']['f.total_ttc']=0;
-
-		while ($i < min($num, $limit)) {
-			$obj = $db->fetch_object($resql);
-
-			$datelimit = $db->jdate($obj->datelimite);
-			$facturestatic->id = $obj->facid;
-			$facturestatic->ref = $obj->ref;
-			$facturestatic->type = $obj->type;
-			$facturestatic->ref_supplier = $obj->ref_supplier;
-			$facturestatic->date_echeance = $db->jdate($obj->datelimite);
-			$facturestatic->statut = $obj->fk_statut;
-			$facturestatic->note_public = $obj->note_public;
-			$facturestatic->note_private = $obj->note_private;
-			$facturestatic->multicurrency_code = $obj->multicurrency_code;
-			$facturestatic->multicurrency_tx = $obj->multicurrency_tx;
-			$facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
-			$facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
-			$facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
-
-			$thirdparty->id = $obj->socid;
-			$thirdparty->name = $obj->name;
-			$thirdparty->name_alias = $obj->alias;
-			$thirdparty->client = $obj->client;
-			$thirdparty->fournisseur = $obj->fournisseur;
-			$thirdparty->code_client = $obj->code_client;
-			$thirdparty->code_compta_client = $obj->code_compta_client;
-			$thirdparty->code_fournisseur = $obj->code_fournisseur;
-			$thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur;
-			$thirdparty->email = $obj->email;
-			$thirdparty->country_code = $obj->country_code;
-
-			$paiement = $facturestatic->getSommePaiement();
-			$totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
-			$totaldeposits = $facturestatic->getSumDepositsUsed();
-			$totalpay = $paiement + $totalcreditnotes + $totaldeposits;
-			$remaintopay = $obj->total_ttc - $totalpay;
-			$multicurrency_paiement = $facturestatic->getSommePaiement(1);
-			$multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
-			$multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
-			$multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
-			$multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
-
-			$facturestatic->alreadypaid = ($paiement ? $paiement : 0);
-			$facturestatic->paye = $obj->paye;
-			$facturestatic->statut = $obj->fk_statut;
-			$facturestatic->type = $obj->type;
-
-
-			//If invoice has been converted and the conversion has been used, we dont have remain to pay on invoice
-			if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
-				if ($facturestatic->isCreditNoteUsed()) {
-					$remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed();
-				}
+$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
+$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
+if ($massactionbutton) {
+	$selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
+}
+
+print '<div class="div-table-responsive">';
+print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
+
+// Line for filters
+print '<tr class="liste_titre_filter">';
+// Ref
+if (!empty($arrayfields['f.ref']['checked'])) {
+	print '<td class="liste_titre left">';
+	print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
+	print '</td>';
+}
+// Ref supplier
+if (!empty($arrayfields['f.ref_supplier']['checked'])) {
+	print '<td class="liste_titre">';
+	print '<input class="flat maxwidth75" type="text" name="search_refsupplier" value="'.dol_escape_htmltag($search_refsupplier).'">';
+	print '</td>';
+}
+// Type
+if (!empty($arrayfields['f.type']['checked'])) {
+	print '<td class="liste_titre maxwidthonsmartphone">';
+	$listtype = array(
+			FactureFournisseur::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
+			FactureFournisseur::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
+			FactureFournisseur::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
+			FactureFournisseur::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
+	);
+	/*
+	if (!empty($conf->global->INVOICE_USE_SITUATION))
+	{
+		$listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
+	}
+	*/
+	//$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma");     // A proformat invoice is not an invoice but must be an order.
+	print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
+	print '</td>';
+}
+// Label
+if (!empty($arrayfields['f.label']['checked'])) {
+	print '<td class="liste_titre">';
+	print '<input class="flat maxwidth75" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
+	print '</td>';
+}
+// Date invoice
+if (!empty($arrayfields['f.datef']['checked'])) {
+	print '<td class="liste_titre center">';
+	print '<div class="nowrap">';
+	print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
+	print '</div>';
+	print '<div class="nowrap">';
+	print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
+	print '</div>';
+	print '</td>';
+}
+// Date due
+if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
+	print '<td class="liste_titre center">';
+	print '<div class="nowrap">';
+	/*
+	print $langs->trans('From').' ';
+	print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1);
+	print '</div>';
+	print '<div class="nowrap">';
+	print $langs->trans('to').' ';*/
+	print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before"));
+	print '<br><input type="checkbox" name="search_option" value="late"'.($option == 'late' ? ' checked' : '').'> '.$langs->trans("Alert");
+	print '</div>';
+	print '</td>';
+}
+// Project
+if (!empty($arrayfields['p.ref']['checked'])) {
+	print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
+}
+// Thirpdarty
+if (!empty($arrayfields['s.nom']['checked'])) {
+	print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'"'.($socid > 0 ? " disabled" : "").'></td>';
+}
+// Alias
+if (!empty($arrayfields['s.name_alias']['checked'])) {
+	print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'"></td>';
+}
+// Town
+if (!empty($arrayfields['s.town']['checked'])) {
+	print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
+}
+// Zip
+if (!empty($arrayfields['s.zip']['checked'])) {
+	print '<td class="liste_titre center"><input class="flat maxwidth50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
+}
+// State
+if (!empty($arrayfields['state.nom']['checked'])) {
+	print '<td class="liste_titre">';
+	print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
+	print '</td>';
+}
+// Country
+if (!empty($arrayfields['country.code_iso']['checked'])) {
+	print '<td class="liste_titre center">';
+	print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
+	print '</td>';
+}
+// Company type
+if (!empty($arrayfields['typent.code']['checked'])) {
+	print '<td class="liste_titre maxwidthonsmartphone center">';
+	print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
+	print '</td>';
+}
+// Condition of payment
+if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
+	print '<td class="liste_titre left">';
+	print $form->getSelectConditionsPaiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100');
+	print '</td>';
+}
+// Payment mode
+if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
+	print '<td class="liste_titre left">';
+	print $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 20, 1, 'maxwidth100', 1);
+	print '</td>';
+}
+if (!empty($arrayfields['f.total_ht']['checked'])) {
+	// Amount without tax
+	print '<td class="liste_titre right">';
+	print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
+	print '</td>';
+}
+if (!empty($arrayfields['f.total_vat']['checked'])) {
+	// Amount vat
+	print '<td class="liste_titre right">';
+	print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
+	print '</td>';
+}
+if (!empty($arrayfields['f.total_localtax1']['checked'])) {
+	// Amount tax 1
+	print '<td class="liste_titre right">';
+	print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.dol_escape_htmltag($search_montant_localtax1).'">';
+	print '</td>';
+}
+if (!empty($arrayfields['f.total_localtax2']['checked'])) {
+	// Amount tax 2
+	print '<td class="liste_titre right">';
+	print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.dol_escape_htmltag($search_montant_localtax2).'">';
+	print '</td>';
+}
+if (!empty($arrayfields['f.total_ttc']['checked'])) {
+	// Amount inc tac
+	print '<td class="liste_titre right">';
+	print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
+	print '</td>';
+}
+if (!empty($arrayfields['u.login']['checked'])) {
+	// Author
+	print '<td class="liste_titre" align="center">';
+	print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
+	print '</td>';
+}
+if (!empty($arrayfields['dynamount_payed']['checked'])) {
+	print '<td class="liste_titre right">';
+	print '</td>';
+}
+if (!empty($arrayfields['rtp']['checked'])) {
+	print '<td class="liste_titre">';
+	print '</td>';
+}
+if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
+	// Currency
+	print '<td class="liste_titre">';
+	print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
+	print '</td>';
+}
+if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
+	// Currency rate
+	print '<td class="liste_titre">';
+	print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
+	print '</td>';
+}
+if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
+	// Amount
+	print '<td class="liste_titre right">';
+	print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
+	print '</td>';
+}
+if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
+	// Amount
+	print '<td class="liste_titre right">';
+	print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
+	print '</td>';
+}
+if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
+	// Amount
+	print '<td class="liste_titre right">';
+	print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
+	print '</td>';
+}
+if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
+	print '<td class="liste_titre">';
+	print '</td>';
+}
+if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
+	print '<td class="liste_titre right">';
+	print '</td>';
+}
+// Extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
+
+// Fields from hook
+$parameters = array('arrayfields'=>$arrayfields);
+$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
+print $hookmanager->resPrint;
+// Date creation
+if (!empty($arrayfields['f.datec']['checked'])) {
+	print '<td class="liste_titre">';
+	print '</td>';
+}
+// Date modification
+if (!empty($arrayfields['f.tms']['checked'])) {
+	print '<td class="liste_titre">';
+	print '</td>';
+}
+// Status
+if (!empty($arrayfields['f.fk_statut']['checked'])) {
+	print '<td class="liste_titre maxwidthonsmartphone right">';
+	$liststatus = array('0'=>$langs->trans("Draft"), '1'=>$langs->trans("Unpaid"), '2'=>$langs->trans("Paid"));
+	print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', '', 1);
+	print '</td>';
+}
+// Action column
+print '<td class="liste_titre middle">';
+$searchpicto = $form->showFilterButtons();
+print $searchpicto;
+print '</td>';
+
+print "</tr>\n";
+
+print '<tr class="liste_titre">';
+if (!empty($arrayfields['f.ref']['checked'])) {
+	print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref,f.rowid', '', $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['f.ref_supplier']['checked'])) {
+	print_liste_field_titre($arrayfields['f.ref_supplier']['label'], $_SERVER["PHP_SELF"], 'f.ref_supplier', '', $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['f.type']['checked'])) {
+	print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['f.label']['checked'])) {
+	print_liste_field_titre($arrayfields['f.label']['label'], $_SERVER['PHP_SELF'], "f.libelle,f.rowid", '', $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['f.datef']['checked'])) {
+	print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef,f.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
+}
+if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
+	print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center ');
+}
+if (!empty($arrayfields['p.ref']['checked'])) {
+	print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['s.nom']['checked'])) {
+	print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['s.name_alias']['checked'])) {
+	print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['s.town']['checked'])) {
+	print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['s.zip']['checked'])) {
+	print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder, 'center ');
+}
+if (!empty($arrayfields['state.nom']['checked'])) {
+	print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.name_alias", "", $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['state.name_alias']['checked'])) {
+	print_liste_field_titre($arrayfields['state.name_alias']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['country.code_iso']['checked'])) {
+	print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
+}
+if (!empty($arrayfields['typent.code']['checked'])) {
+	print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
+}
+if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
+	print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
+}
+if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
+	print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
+}
+if (!empty($arrayfields['f.total_ht']['checked'])) {
+	print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
+}
+if (!empty($arrayfields['f.total_vat']['checked'])) {
+	print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
+}
+if (!empty($arrayfields['f.total_localtax1']['checked'])) {
+	print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right ');
+}
+if (!empty($arrayfields['f.total_localtax2']['checked'])) {
+	print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right ');
+}
+if (!empty($arrayfields['f.total_ttc']['checked'])) {
+	print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
+}
+if (!empty($arrayfields['u.login']['checked'])) {
+	print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['dynamount_payed']['checked'])) {
+	print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
+}
+if (!empty($arrayfields['rtp']['checked'])) {
+	print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
+}
+if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
+	print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
+	print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
+	print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
+	print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
+	print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
+	print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
+}
+if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
+	print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
+}
+// Extra fields
+include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
+// Hook fields
+$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
+$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
+print $hookmanager->resPrint;
+if (!empty($arrayfields['f.datec']['checked'])) {
+	print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
+}
+if (!empty($arrayfields['f.tms']['checked'])) {
+	print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
+}
+if (!empty($arrayfields['f.fk_statut']['checked'])) {
+	print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'right ');
+}
+print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
+print "</tr>\n";
+
+$facturestatic = new FactureFournisseur($db);
+$supplierstatic = new Fournisseur($db);
+$projectstatic = new Project($db);
+$userstatic = new User($db);
+
+if ($num > 0) {
+	$i = 0;
+	$totalarray = array();
+	$totalarray['nbfield']=0;
+	$totalarray['val'] = array();
+	$totalarray['val']['f.total_ht']=0;
+	$totalarray['val']['f.total_vat']=0;
+	$totalarray['val']['f.total_localtax1']=0;
+	$totalarray['val']['f.total_localtax1']=0;
+	$totalarray['val']['f.total_ttc']=0;
+
+	while ($i < min($num, $limit)) {
+		$obj = $db->fetch_object($resql);
+
+		$datelimit = $db->jdate($obj->datelimite);
+		$facturestatic->id = $obj->facid;
+		$facturestatic->ref = $obj->ref;
+		$facturestatic->type = $obj->type;
+		$facturestatic->ref_supplier = $obj->ref_supplier;
+		$facturestatic->date_echeance = $db->jdate($obj->datelimite);
+		$facturestatic->statut = $obj->fk_statut;
+		$facturestatic->note_public = $obj->note_public;
+		$facturestatic->note_private = $obj->note_private;
+		$facturestatic->multicurrency_code = $obj->multicurrency_code;
+		$facturestatic->multicurrency_tx = $obj->multicurrency_tx;
+		$facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
+		$facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
+		$facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
+
+		$thirdparty->id = $obj->socid;
+		$thirdparty->name = $obj->name;
+		$thirdparty->name_alias = $obj->alias;
+		$thirdparty->client = $obj->client;
+		$thirdparty->fournisseur = $obj->fournisseur;
+		$thirdparty->code_client = $obj->code_client;
+		$thirdparty->code_compta_client = $obj->code_compta_client;
+		$thirdparty->code_fournisseur = $obj->code_fournisseur;
+		$thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur;
+		$thirdparty->email = $obj->email;
+		$thirdparty->country_code = $obj->country_code;
+
+		$paiement = $facturestatic->getSommePaiement();
+		$totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
+		$totaldeposits = $facturestatic->getSumDepositsUsed();
+		$totalpay = $paiement + $totalcreditnotes + $totaldeposits;
+		$remaintopay = $obj->total_ttc - $totalpay;
+		$multicurrency_paiement = $facturestatic->getSommePaiement(1);
+		$multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
+		$multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
+		$multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
+		$multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
+
+		$facturestatic->alreadypaid = ($paiement ? $paiement : 0);
+		$facturestatic->paye = $obj->paye;
+		$facturestatic->statut = $obj->fk_statut;
+		$facturestatic->type = $obj->type;
+
+
+		//If invoice has been converted and the conversion has been used, we dont have remain to pay on invoice
+		if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
+			if ($facturestatic->isCreditNoteUsed()) {
+				$remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed();
 			}
+		}
 
-			print '<tr class="oddeven">';
-			if (!empty($arrayfields['f.ref']['checked'])) {
-				print '<td class="nowraponall">';
+		print '<tr class="oddeven">';
+		if (!empty($arrayfields['f.ref']['checked'])) {
+			print '<td class="nowraponall">';
 
-				print '<table class="nobordernopadding"><tr class="nocellnopadd">';
-				// Picto + Ref
-				print '<td class="nobordernopadding nowraponall">';
-				print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
+			print '<table class="nobordernopadding"><tr class="nocellnopadd">';
+			// Picto + Ref
+			print '<td class="nobordernopadding nowraponall">';
+			print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
 
-				$filename = dol_sanitizeFileName($obj->ref);
-				$filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
-				$subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
-				print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
-				print '</td></tr></table>';
+			$filename = dol_sanitizeFileName($obj->ref);
+			$filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
+			$subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
+			print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
+			print '</td></tr></table>';
 
-				print "</td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+			print "</td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
-			// Supplier ref
-			if (!empty($arrayfields['f.ref_supplier']['checked'])) {
-				print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
-				print $obj->ref_supplier;
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		// Supplier ref
+		if (!empty($arrayfields['f.ref_supplier']['checked'])) {
+			print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
+			print $obj->ref_supplier;
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
-			// Type
-			if (!empty($arrayfields['f.type']['checked'])) {
-				print '<td class="nowrap">';
-				print $facturestatic->getLibType();
-				print "</td>";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		// Type
+		if (!empty($arrayfields['f.type']['checked'])) {
+			print '<td class="nowrap">';
+			print $facturestatic->getLibType();
+			print "</td>";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
-			// Label
-			if (!empty($arrayfields['f.label']['checked'])) {
-				print '<td class="nowrap">';
-				print $obj->label;
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		// Label
+		if (!empty($arrayfields['f.label']['checked'])) {
+			print '<td class="nowrap">';
+			print $obj->label;
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
-			// Date
-			if (!empty($arrayfields['f.datef']['checked'])) {
-				print '<td class="center nowrap">';
-				print dol_print_date($db->jdate($obj->datef), 'day');
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		// Date
+		if (!empty($arrayfields['f.datef']['checked'])) {
+			print '<td class="center nowrap">';
+			print dol_print_date($db->jdate($obj->datef), 'day');
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
-			// Date limit
-			if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
-				print '<td class="center nowraponall">'.dol_print_date($datelimit, 'day');
-				if ($facturestatic->hasDelay()) {
-					print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
-				}
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		// Date limit
+		if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
+			print '<td class="center nowraponall">'.dol_print_date($datelimit, 'day');
+			if ($facturestatic->hasDelay()) {
+				print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
 			}
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
+			}
+		}
 
-			// Project
-			if (!empty($arrayfields['p.ref']['checked'])) {
-				print '<td class="nowrap">';
-				if ($obj->project_id > 0) {
-					$projectstatic->id = $obj->project_id;
-					$projectstatic->ref = $obj->project_ref;
-					$projectstatic->title = $obj->project_label;
-					print $projectstatic->getNomUrl(1);
-				}
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		// Project
+		if (!empty($arrayfields['p.ref']['checked'])) {
+			print '<td class="nowrap">';
+			if ($obj->project_id > 0) {
+				$projectstatic->id = $obj->project_id;
+				$projectstatic->ref = $obj->project_ref;
+				$projectstatic->title = $obj->project_label;
+				print $projectstatic->getNomUrl(1);
+			}
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
-			// Third party
-			if (!empty($arrayfields['s.nom']['checked'])) {
-				print '<td class="tdoverflowmax200">';
-				print $thirdparty->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		// Third party
+		if (!empty($arrayfields['s.nom']['checked'])) {
+			print '<td class="tdoverflowmax200">';
+			print $thirdparty->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// Alias
-			if (!empty($arrayfields['s.name_alias']['checked'])) {
-				print '<td class="tdoverflowmax200">';
-				print $thirdparty->name_alias;
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		}
+		// Alias
+		if (!empty($arrayfields['s.name_alias']['checked'])) {
+			print '<td class="tdoverflowmax200">';
+			print $thirdparty->name_alias;
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// Town
-			if (!empty($arrayfields['s.town']['checked'])) {
-				print '<td class="nocellnopadd">';
-				print $obj->town;
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		}
+		// Town
+		if (!empty($arrayfields['s.town']['checked'])) {
+			print '<td class="nocellnopadd">';
+			print $obj->town;
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// Zip
-			if (!empty($arrayfields['s.zip']['checked'])) {
-				print '<td class="nocellnopadd center tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">';
-				print dol_escape_htmltag($obj->zip);
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		}
+		// Zip
+		if (!empty($arrayfields['s.zip']['checked'])) {
+			print '<td class="nocellnopadd center tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">';
+			print dol_escape_htmltag($obj->zip);
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// State
-			if (!empty($arrayfields['state.nom']['checked'])) {
-				print "<td>".$obj->state_name."</td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		}
+		// State
+		if (!empty($arrayfields['state.nom']['checked'])) {
+			print "<td>".$obj->state_name."</td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// Country
-			if (!empty($arrayfields['country.code_iso']['checked'])) {
-				print '<td class="center">';
-				$tmparray = getCountry($obj->fk_pays, 'all');
-				print $tmparray['label'];
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		}
+		// Country
+		if (!empty($arrayfields['country.code_iso']['checked'])) {
+			print '<td class="center">';
+			$tmparray = getCountry($obj->fk_pays, 'all');
+			print $tmparray['label'];
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// Type ent
-			if (!empty($arrayfields['typent.code']['checked'])) {
-				print '<td class="center">';
-				if (empty($typenArray)) {
-					$typenArray = $formcompany->typent_array(1);
-				}
-				print $typenArray[$obj->typent_code];
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		}
+		// Type ent
+		if (!empty($arrayfields['typent.code']['checked'])) {
+			print '<td class="center">';
+			if (empty($typenArray)) {
+				$typenArray = $formcompany->typent_array(1);
+			}
+			print $typenArray[$obj->typent_code];
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
-			// Payment condition
-			if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
-				print '<td class="tdoverflowmax100">';
-				$form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 1);
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		// Payment condition
+		if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
+			print '<td class="tdoverflowmax100">';
+			$form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 1);
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// Payment mode
-			if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
-				print '<td class="tdoverflowmax100">';
-				$form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		}
+		// Payment mode
+		if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
+			print '<td class="tdoverflowmax100">';
+			$form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
-			// Amount HT
-			if (!empty($arrayfields['f.total_ht']['checked'])) {
-				  print '<td class="right nowrap"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
-				if (!$i) {
-					$totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
-				}
-				  $totalarray['val']['f.total_ht'] += $obj->total_ht;
+		// Amount HT
+		if (!empty($arrayfields['f.total_ht']['checked'])) {
+			  print '<td class="right nowrap"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// Amount VAT
-			if (!empty($arrayfields['f.total_vat']['checked'])) {
-				print '<td class="right nowrap"><span class="amount">'.price($obj->total_vat)."</span></td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
-				if (!$i) {
-					$totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat';
-				}
-				$totalarray['val']['f.total_vat'] += $obj->total_vat;
+			if (!$i) {
+				$totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
 			}
-			// Amount LocalTax1
-			if (!empty($arrayfields['f.total_localtax1']['checked'])) {
-				print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax1)."</span></td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
-				if (!$i) {
-					$totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
-				}
-				$totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
+			  $totalarray['val']['f.total_ht'] += $obj->total_ht;
+		}
+		// Amount VAT
+		if (!empty($arrayfields['f.total_vat']['checked'])) {
+			print '<td class="right nowrap"><span class="amount">'.price($obj->total_vat)."</span></td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// Amount LocalTax2
-			if (!empty($arrayfields['f.total_localtax2']['checked'])) {
-				print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax2)."</span></td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
-				if (!$i) {
-					$totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
-				}
-				$totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
+			if (!$i) {
+				$totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat';
 			}
-			// Amount TTC
-			if (!empty($arrayfields['f.total_ttc']['checked'])) {
-				print '<td class="right nowrap"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
-				if (!$i) {
-					$totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
-				}
-				$totalarray['val']['f.total_ttc'] += $obj->total_ttc;
+			$totalarray['val']['f.total_vat'] += $obj->total_vat;
+		}
+		// Amount LocalTax1
+		if (!empty($arrayfields['f.total_localtax1']['checked'])) {
+			print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax1)."</span></td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
+			}
+			if (!$i) {
+				$totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
+			}
+			$totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
+		}
+		// Amount LocalTax2
+		if (!empty($arrayfields['f.total_localtax2']['checked'])) {
+			print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax2)."</span></td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+			if (!$i) {
+				$totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
+			}
+			$totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
+		}
+		// Amount TTC
+		if (!empty($arrayfields['f.total_ttc']['checked'])) {
+			print '<td class="right nowrap"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
+			}
+			if (!$i) {
+				$totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
+			}
+			$totalarray['val']['f.total_ttc'] += $obj->total_ttc;
+		}
 
-			$userstatic->id = $obj->fk_user_author;
-			$userstatic->login = $obj->login;
-			$userstatic->lastname = $obj->lastname;
-			$userstatic->firstname = $obj->firstname;
-			$userstatic->email = $obj->user_email;
-			$userstatic->statut = $obj->user_statut;
-			$userstatic->entity = $obj->entity;
-			$userstatic->photo = $obj->photo;
-			$userstatic->office_phone = $obj->office_phone;
-			$userstatic->office_fax = $obj->office_fax;
-			$userstatic->user_mobile = $obj->user_mobile;
-			$userstatic->job = $obj->job;
-			$userstatic->gender = $obj->gender;
-
-			// Author
-			if (!empty($arrayfields['u.login']['checked'])) {
-				print '<td class="tdoverflowmax200">';
-				if ($userstatic->id) {
-					print $userstatic->getLoginUrl(-1);
-				} else {
-					print '&nbsp;';
-				}
-				print "</td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		$userstatic->id = $obj->fk_user_author;
+		$userstatic->login = $obj->login;
+		$userstatic->lastname = $obj->lastname;
+		$userstatic->firstname = $obj->firstname;
+		$userstatic->email = $obj->user_email;
+		$userstatic->statut = $obj->user_statut;
+		$userstatic->entity = $obj->entity;
+		$userstatic->photo = $obj->photo;
+		$userstatic->office_phone = $obj->office_phone;
+		$userstatic->office_fax = $obj->office_fax;
+		$userstatic->user_mobile = $obj->user_mobile;
+		$userstatic->job = $obj->job;
+		$userstatic->gender = $obj->gender;
+
+		// Author
+		if (!empty($arrayfields['u.login']['checked'])) {
+			print '<td class="tdoverflowmax200">';
+			if ($userstatic->id) {
+				print $userstatic->getLoginUrl(-1);
+			} else {
+				print '&nbsp;';
+			}
+			print "</td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
-			if (!empty($arrayfields['dynamount_payed']['checked'])) {
-				print '<td class="right nowrap"><span class="amount">'.(!empty($totalpay) ?price($totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
-				if (!$i) {
-					$totalarray['pos'][$totalarray['nbfield']] = 'totalam';
-				}
-				$totalarray['val']['totalam'] += $totalpay;
+		if (!empty($arrayfields['dynamount_payed']['checked'])) {
+			print '<td class="right nowrap"><span class="amount">'.(!empty($totalpay) ?price($totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+			if (!$i) {
+				$totalarray['pos'][$totalarray['nbfield']] = 'totalam';
+			}
+			$totalarray['val']['totalam'] += $totalpay;
+		}
 
-			if (!empty($arrayfields['rtp']['checked'])) {
-				print '<td class="right nowrap">'.(!empty($remaintopay) ?price($remaintopay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
-				if (!$i) {
-					$totalarray['pos'][$totalarray['nbfield']] = 'rtp';
-				}
-				$totalarray['val']['rtp'] += $remaintopay;
+		if (!empty($arrayfields['rtp']['checked'])) {
+			print '<td class="right nowrap">'.(!empty($remaintopay) ?price($remaintopay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+			if (!$i) {
+				$totalarray['pos'][$totalarray['nbfield']] = 'rtp';
+			}
+			$totalarray['val']['rtp'] += $remaintopay;
+		}
 
-			// Currency
-			if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
-				  print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		// Currency
+		if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
+			  print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
-			// Currency rate
-			if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
-				  print '<td class="nowrap">';
-				  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
-				  print "</td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		// Currency rate
+		if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
+			  print '<td class="nowrap">';
+			  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
+			  print "</td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// Amount HT
-			if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
-				  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		}
+		// Amount HT
+		if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
+			  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// Amount VAT
-			if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
-				print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		}
+		// Amount VAT
+		if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
+			print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			// Amount TTC
-			if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
-				print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		}
+		// Amount TTC
+		if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
+			print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
-			if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
-				print '<td class="right nowrap"><span class="amount">'.(!empty($multicurrency_totalpay) ?price($multicurrency_totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		}
+		if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
+			print '<td class="right nowrap"><span class="amount">'.(!empty($multicurrency_totalpay) ?price($multicurrency_totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
-			// Pending amount
-			if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
-				print '<td class="right nowrap"><span class="amount">';
-				print (!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '');
-				print '</span></td>'; // TODO Use a denormalized field
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
+		// Pending amount
+		if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
+			print '<td class="right nowrap"><span class="amount">';
+			print (!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '');
+			print '</span></td>'; // TODO Use a denormalized field
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
 
 
-			// Extra fields
-			include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
-			// Fields from hook
-			$parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
-			$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
-			print $hookmanager->resPrint;
-
-			// Date creation
-			if (!empty($arrayfields['f.datec']['checked'])) {
-				print '<td class="center nowrap">';
-				print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
-			}
-			// Date modification
-			if (!empty($arrayfields['f.tms']['checked'])) {
-				print '<td class="center nowrap">';
-				print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
-				print '</td>';
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
-			}
-			// Status
-			if (!empty($arrayfields['f.fk_statut']['checked'])) {
-				print '<td class="right nowrap">';
-				print $facturestatic->LibStatut($obj->paye, $obj->fk_statut, 5, $paiement, $obj->type);
-				print "</td>";
-				if (!$i) {
-					$totalarray['nbfield']++;
-				}
-			}
+		// Extra fields
+		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
+		// Fields from hook
+		$parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
+		$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
+		print $hookmanager->resPrint;
 
-			// Action column
-			print '<td class="nowrap center">';
-			if ($massactionbutton || $massaction) {   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
-				$selected = 0;
-				if (in_array($obj->facid, $arrayofselected)) {
-					$selected = 1;
-				}
-				print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
+		// Date creation
+		if (!empty($arrayfields['f.datec']['checked'])) {
+			print '<td class="center nowrap">';
+			print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
+			print '</td>';
+			if (!$i) {
+				$totalarray['nbfield']++;
 			}
+		}
+		// Date modification
+		if (!empty($arrayfields['f.tms']['checked'])) {
+			print '<td class="center nowrap">';
+			print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
 			print '</td>';
 			if (!$i) {
 				$totalarray['nbfield']++;
 			}
+		}
+		// Status
+		if (!empty($arrayfields['f.fk_statut']['checked'])) {
+			print '<td class="right nowrap">';
+			print $facturestatic->LibStatut($obj->paye, $obj->fk_statut, 5, $paiement, $obj->type);
+			print "</td>";
+			if (!$i) {
+				$totalarray['nbfield']++;
+			}
+		}
 
-			print "</tr>\n";
-
-			$i++;
+		// Action column
+		print '<td class="nowrap center">';
+		if ($massactionbutton || $massaction) {   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
+			$selected = 0;
+			if (in_array($obj->facid, $arrayofselected)) {
+				$selected = 1;
+			}
+			print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
+		}
+		print '</td>';
+		if (!$i) {
+			$totalarray['nbfield']++;
 		}
 
-		// Show total line
-		include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
-	}
+		print "</tr>\n";
 
-	$db->free($resql);
+		$i++;
+	}
 
-	$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
-	$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
-	print $hookmanager->resPrint;
+	// Show total line
+	include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
+}
 
-	print "</table>\n";
-	print '</div>';
+// 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>';
+}
 
-	print "</form>\n";
+$db->free($resql);
 
-	$hidegeneratedfilelistifempty = 1;
-	if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
-		$hidegeneratedfilelistifempty = 0;
-	}
+$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
+$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
+print $hookmanager->resPrint;
 
-	// Show list of available documents
-	$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
-	$urlsource .= str_replace('&amp;', '&', $param);
+print "</table>\n";
+print '</div>';
 
-	$filedir = $diroutputmassaction;
-	$genallowed = $user->rights->facture->lire;
-	$delallowed = $user->rights->facture->creer;
-	$title = '';
+print "</form>\n";
 
-	print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
-} else {
-	dol_print_error($db);
+$hidegeneratedfilelistifempty = 1;
+if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
+	$hidegeneratedfilelistifempty = 0;
 }
 
+// Show list of available documents
+$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
+$urlsource .= str_replace('&amp;', '&', $param);
+
+$filedir = $diroutputmassaction;
+$genallowed = $user->rights->facture->lire;
+$delallowed = $user->rights->facture->creer;
+$title = '';
+
+print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
+
 // End of page
 llxFooter();
 $db->close();

+ 1 - 1
htdocs/knowledgemanagement/knowledgerecord_list.php

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

+ 1 - 1
htdocs/partnership/partnership_list.php

@@ -682,7 +682,7 @@ print '</tr>'."\n";
 $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) {
 	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
 		}
 	}

+ 1 - 1
htdocs/product/inventory/list.php

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

+ 1 - 1
htdocs/product/stats/card.php

@@ -375,7 +375,7 @@ if ($result || !($id > 0)) {
 						$morefilters = ' AND d.fk_product IN ('.$db->sanitize((is_array($listofprodids) && count($listofprodids)) ? join(',', $listofprodids) : '0').')';
 					}
 					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') {

+ 29 - 20
htdocs/projet/tasks/list.php

@@ -46,7 +46,7 @@ $mode = GETPOST('mode', 'aZ');
 $id = GETPOST('id', 'int');
 
 $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');
 if (!isset($search_projectstatus) || $search_projectstatus === '') {
@@ -332,13 +332,9 @@ $distinct = 'DISTINCT'; // We add distinct until we are added a protection to be
 $sql = "SELECT ".$distinct." p.rowid as projectid, p.ref as projectref, p.title as projecttitle, p.fk_statut as projectstatus, p.datee as projectdatee, p.fk_opp_status, p.public, p.fk_user_creat as projectusercreate, p.usage_bill_time,";
 $sql .= " s.nom as name, s.name_alias as alias, s.rowid as socid,";
 $sql .= " t.datec as date_creation, t.dateo as date_start, t.datee as date_end, t.tms as date_update,";
-$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.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
 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";
@@ -355,10 +351,6 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // N
 $sql .= $hookmanager->resPrint;
 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
 $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";
 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";
@@ -384,12 +376,6 @@ if (is_object($projectstatic) && $projectstatic->id > 0) {
 if ($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) {
 	$sql .= natural_search('p.ref', $search_project_ref);
 }
@@ -448,6 +434,32 @@ if ($search_project_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);
 }
+// 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
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
 // Add where from hooks
@@ -459,9 +471,6 @@ if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed
 	$sql .= " s.nom, s.rowid,";
 	$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";
-	if ($search_categ) {
-		$sql .= ", cs.fk_categorie, cs.fk_project";
-	}
 	// Add fields from extrafields
 	if (!empty($extrafields->attributes[$object->table_element]['label'])) {
 		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';
 	$moreforfilter .= '<div class="divsearchfield">';
 	$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>';
 }