1<?php
2/* Copyright (C) 2001-2004  Rodolphe Quiedeville    <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019  Laurent Destailleur     <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2019  Regis Houssin           <regis.houssin@inodbox.com>
5 * Copyright (C) 2012       Marcos García           <marcosgdf@gmail.com>
6 * Copyright (C) 2013-2015  Raphaël Doursenaud      <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2015       Florian Henry           <florian.henry@open-concept.pro>
8 * Copyright (C) 2016-2018  Josep Lluis Amador      <joseplluis@lliuretic.cat>
9 * Copyright (C) 2016       Ferran Marcet      	    <fmarcet@2byte.es>
10 * Copyright (C) 2017       Rui Strecht      	    <rui.strecht@aliartalentos.com>
11 * Copyright (C) 2017       Juanjo Menent      	    <jmenent@2byte.es>
12 * Copyright (C) 2018       Nicolas ZABOURI         <info@inovea-conseil.com>
13 * Copyright (C) 2020       Open-Dsi         		<support@open-dsi.fr>
14
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
30/**
31 *	\file       htdocs/societe/list.php
32 *	\ingroup    societe
33 *	\brief      Page to show list of third parties
34 */
35
36require_once '../main.inc.php';
37include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
42require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
43
44$langs->loadLangs(array("companies", "commercial", "customers", "suppliers", "bills", "compta", "categories", "cashdesk"));
45
46$action = GETPOST('action', 'aZ09');
47$massaction = GETPOST('massaction', 'alpha');
48$show_files = GETPOST('show_files', 'int');
49$confirm = GETPOST('confirm', 'alpha');
50$toselect = GETPOST('toselect', 'array');
51$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'thirdpartylist';
52
53if ($contextpage == 'poslist')
54{
55	$_GET['optioncss'] = 'print';
56}
57
58// Security check
59$socid = GETPOST('socid', 'int');
60if ($user->socid) $socid = $user->socid;
61$result = restrictedArea($user, 'societe', $socid, '');
62
63$search_all = trim(GETPOST('search_all', 'alphanohtml') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
64$search_cti = preg_replace('/^0+/', '', preg_replace('/[^0-9]/', '', GETPOST('search_cti', 'alphanohtml'))); // Phone number without any special chars
65
66$search_id = trim(GETPOST("search_id", "int"));
67$search_nom = trim(GETPOST("search_nom", 'restricthtml'));
68$search_alias = trim(GETPOST("search_alias", 'restricthtml'));
69$search_nom_only = trim(GETPOST("search_nom_only", 'restricthtml'));
70$search_barcode = trim(GETPOST("search_barcode", 'alpha'));
71$search_customer_code = trim(GETPOST('search_customer_code', 'alpha'));
72$search_supplier_code = trim(GETPOST('search_supplier_code', 'alpha'));
73$search_account_customer_code = trim(GETPOST('search_account_customer_code', 'alpha'));
74$search_account_supplier_code = trim(GETPOST('search_account_supplier_code', 'alpha'));
75$search_address = trim(GETPOST('search_address', 'alpha'));
76$search_town = trim(GETPOST("search_town", 'alpha'));
77$search_zip = trim(GETPOST("search_zip", 'alpha'));
78$search_state = trim(GETPOST("search_state", 'alpha'));
79$search_region = trim(GETPOST("search_region", 'alpha'));
80$search_email = trim(GETPOST('search_email', 'alpha'));
81$search_phone = trim(GETPOST('search_phone', 'alpha'));
82$search_fax = trim(GETPOST('search_fax', 'alpha'));
83$search_url = trim(GETPOST('search_url', 'alpha'));
84$search_idprof1 = trim(GETPOST('search_idprof1', 'alpha'));
85$search_idprof2 = trim(GETPOST('search_idprof2', 'alpha'));
86$search_idprof3 = trim(GETPOST('search_idprof3', 'alpha'));
87$search_idprof4 = trim(GETPOST('search_idprof4', 'alpha'));
88$search_idprof5 = trim(GETPOST('search_idprof5', 'alpha'));
89$search_idprof6 = trim(GETPOST('search_idprof6', 'alpha'));
90$search_vat = trim(GETPOST('search_vat', 'alpha'));
91$search_sale = trim(GETPOST("search_sale", 'int'));
92$search_categ_cus = trim(GETPOST("search_categ_cus", 'int'));
93$search_categ_sup = trim(GETPOST("search_categ_sup", 'int'));
94$search_country = GETPOST("search_country", 'intcomma');
95$search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
96$search_staff = GETPOST("search_staff", 'int');
97$search_status = GETPOST("search_status", 'int');
98$search_type = GETPOST('search_type', 'alpha');
99$search_level = GETPOST("search_level", "array");
100$search_stcomm = GETPOST('search_stcomm', 'int');
101$search_import_key  = GETPOST("search_import_key", "alpha");
102$search_parent_name = GETPOST('search_parent_name', 'alpha');
103
104$type = GETPOST('type', 'alpha');
105$optioncss = GETPOST('optioncss', 'alpha');
106$mode = GETPOST("mode", 'alpha');
107$place = GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : '0'; // $place is string id of table for Bar or Restaurant
108
109$diroutputmassaction = $conf->societe->dir_output.'/temp/massgeneration/'.$user->id;
110
111$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
112$sortfield = GETPOST("sortfield", 'alpha');
113$sortorder = GETPOST("sortorder", 'alpha');
114$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
115if (!$sortorder) $sortorder = "ASC";
116if (!$sortfield) $sortfield = "s.nom";
117if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; }     // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
118$offset = $limit * $page;
119$pageprev = $page - 1;
120$pagenext = $page + 1;
121
122if ($type == 'c') { if (empty($contextpage) || $contextpage == 'thirdpartylist') $contextpage = 'customerlist'; if ($search_type == '') $search_type = '1,3'; }
123if ($type == 'p') { if (empty($contextpage) || $contextpage == 'thirdpartylist') $contextpage = 'prospectlist'; if ($search_type == '') $search_type = '2,3'; }
124if ($type == 't') { if (empty($contextpage) || $contextpage == 'poslist') $contextpage = 'poslist'; if ($search_type == '') $search_type = '1,2,3'; }
125if ($type == 'f') { if (empty($contextpage) || $contextpage == 'thirdpartylist') $contextpage = 'supplierlist'; if ($search_type == '') $search_type = '4'; }
126
127// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
128$object = new Societe($db);
129$hookmanager->initHooks(array('thirdpartylist'));
130$extrafields = new ExtraFields($db);
131
132// fetch optionals attributes and labels
133$extrafields->fetch_name_optionals_label($object->table_element);
134
135$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
136
137// List of fields to search into when doing a "search in all"
138$fieldstosearchall = array(
139	's.nom'=>"ThirdPartyName",
140	's.name_alias'=>"AliasNameShort",
141	's.code_client'=>"CustomerCode",
142	's.code_fournisseur'=>"SupplierCode",
143	's.code_compta'=>"CustomerAccountancyCodeShort",
144	's.code_compta_fournisseur'=>"SupplierAccountancyCodeShort",
145	's.zip'=>"Zip",
146	's.town'=>"Town",
147	's.email'=>"EMail",
148	's.url'=>"URL",
149	's.tva_intra'=>"VATIntra",
150	's.siren'=>"ProfId1",
151	's.siret'=>"ProfId2",
152	's.ape'=>"ProfId3",
153	's.phone'=>"Phone",
154	's.fax'=>"Fax",
155);
156if (($tmp = $langs->transnoentities("ProfId4".$mysoc->country_code)) && $tmp != "ProfId4".$mysoc->country_code && $tmp != '-') $fieldstosearchall['s.idprof4'] = 'ProfId4';
157if (($tmp = $langs->transnoentities("ProfId5".$mysoc->country_code)) && $tmp != "ProfId5".$mysoc->country_code && $tmp != '-') $fieldstosearchall['s.idprof5'] = 'ProfId5';
158if (($tmp = $langs->transnoentities("ProfId6".$mysoc->country_code)) && $tmp != "ProfId6".$mysoc->country_code && $tmp != '-') $fieldstosearchall['s.idprof6'] = 'ProfId6';
159if (!empty($conf->barcode->enabled)) $fieldstosearchall['s.barcode'] = 'Gencod';
160// Personalized search criterias. Example: $conf->global->THIRDPARTY_QUICKSEARCH_ON_FIELDS = 's.nom=ThirdPartyName;s.name_alias=AliasNameShort;s.code_client=CustomerCode'
161if (!empty($conf->global->THIRDPARTY_QUICKSEARCH_ON_FIELDS)) $fieldstosearchall = dolExplodeIntoArray($conf->global->THIRDPARTY_QUICKSEARCH_ON_FIELDS);
162
163
164// Define list of fields to show into list
165$checkedcustomercode = (in_array($contextpage, array('thirdpartylist', 'customerlist', 'prospectlist', 'poslist')) ? 1 : 0);
166$checkedsuppliercode = (in_array($contextpage, array('supplierlist')) ? 1 : 0);
167$checkedcustomeraccountcode = (in_array($contextpage, array('customerlist')) ? 1 : 0);
168$checkedsupplieraccountcode = (in_array($contextpage, array('supplierlist')) ? 1 : 0);
169$checkedtypetiers = 1;
170$checkedprofid1 = 0;
171$checkedprofid2 = 0;
172$checkedprofid3 = 0;
173$checkedprofid4 = 0;
174$checkedprofid5 = 0;
175$checkedprofid6 = 0;
176//$checkedprofid4=((($tmp = $langs->transnoentities("ProfId4".$mysoc->country_code)) && $tmp != "ProfId4".$mysoc->country_code && $tmp != '-') ? 1 : 0);
177//$checkedprofid5=((($tmp = $langs->transnoentities("ProfId5".$mysoc->country_code)) && $tmp != "ProfId5".$mysoc->country_code && $tmp != '-') ? 1 : 0);
178//$checkedprofid6=((($tmp = $langs->transnoentities("ProfId6".$mysoc->country_code)) && $tmp != "ProfId6".$mysoc->country_code && $tmp != '-') ? 1 : 0);
179$checkprospectlevel = (in_array($contextpage, array('prospectlist')) ? 1 : 0);
180$checkstcomm = (in_array($contextpage, array('prospectlist')) ? 1 : 0);
181$arrayfields = array(
182	's.rowid'=>array('label'=>"TechnicalID", 'position'=>1, 'checked'=>($conf->global->MAIN_SHOW_TECHNICAL_ID ? 1 : 0), 'enabled'=>($conf->global->MAIN_SHOW_TECHNICAL_ID ? 1 : 0)),
183	's.nom'=>array('label'=>"ThirdPartyName", 'position'=>2, 'checked'=>1),
184	's.name_alias'=>array('label'=>"AliasNameShort", 'position'=>3, 'checked'=>1),
185	's.barcode'=>array('label'=>"Gencod", 'position'=>5, 'checked'=>1, 'enabled'=>(!empty($conf->barcode->enabled))),
186	's.code_client'=>array('label'=>"CustomerCodeShort", 'position'=>10, 'checked'=>$checkedcustomercode),
187	's.code_fournisseur'=>array('label'=>"SupplierCodeShort", 'position'=>11, 'checked'=>$checkedsuppliercode, 'enabled'=>(!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))),
188	's.code_compta'=>array('label'=>"CustomerAccountancyCodeShort", 'position'=>13, 'checked'=>$checkedcustomeraccountcode),
189	's.code_compta_fournisseur'=>array('label'=>"SupplierAccountancyCodeShort", 'position'=>14, 'checked'=>$checkedsupplieraccountcode, 'enabled'=>(!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))),
190	's.address'=>array('label'=>"Address", 'position'=>19, 'checked'=>0),
191	's.town'=>array('label'=>"Town", 'position'=>20, 'checked'=>0),
192	's.zip'=>array('label'=>"Zip", 'position'=>21, 'checked'=>1),
193	'state.nom'=>array('label'=>"State", 'position'=>22, 'checked'=>0),
194	'region.nom'=>array('label'=>"Region", 'position'=>23, 'checked'=>0),
195	'country.code_iso'=>array('label'=>"Country", 'position'=>24, 'checked'=>0),
196	's.email'=>array('label'=>"Email", 'position'=>25, 'checked'=>0),
197	's.url'=>array('label'=>"Url", 'position'=>26, 'checked'=>0),
198	's.phone'=>array('label'=>"Phone", 'position'=>27, 'checked'=>1),
199	's.fax'=>array('label'=>"Fax", 'position'=>28, 'checked'=>0),
200	'typent.code'=>array('label'=>"ThirdPartyType", 'position'=>29, 'checked'=>$checkedtypetiers),
201	'staff.code'=>array('label'=>"Staff", 'position'=>30, 'checked'=>0),
202	's.siren'=>array('label'=>"ProfId1Short", 'position'=>40, 'checked'=>$checkedprofid1),
203	's.siret'=>array('label'=>"ProfId2Short", 'position'=>41, 'checked'=>$checkedprofid2),
204	's.ape'=>array('label'=>"ProfId3Short", 'position'=>42, 'checked'=>$checkedprofid3),
205	's.idprof4'=>array('label'=>"ProfId4Short", 'position'=>43, 'checked'=>$checkedprofid4),
206	's.idprof5'=>array('label'=>"ProfId5Short", 'position'=>44, 'checked'=>$checkedprofid5),
207	's.idprof6'=>array('label'=>"ProfId6Short", 'position'=>45, 'checked'=>$checkedprofid6),
208	's.tva_intra'=>array('label'=>"VATIntraShort", 'position'=>50, 'checked'=>0),
209	'customerorsupplier'=>array('label'=>'NatureOfThirdParty', 'position'=>61, 'checked'=>1),
210	's.fk_prospectlevel'=>array('label'=>"ProspectLevelShort", 'position'=>62, 'checked'=>$checkprospectlevel),
211	's.fk_stcomm'=>array('label'=>"StatusProsp", 'position'=>63, 'checked'=>$checkstcomm),
212	's2.nom'=>array('label'=>'ParentCompany', 'position'=>64, 'checked'=>0),
213	's.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
214	's.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
215	's.status'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
216	's.import_key'=>array('label'=>"ImportId", 'checked'=>0, 'position'=>1100),
217);
218// Extra fields
219include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
220
221$object->fields = dol_sort_array($object->fields, 'position');
222$arrayfields = dol_sort_array($arrayfields, 'position');
223
224
225/*
226 * Actions
227 */
228
229if ($action == "change")	// Change customer for TakePOS
230{
231	$idcustomer = GETPOST('idcustomer', 'int');
232
233	// Check if draft invoice already exists, if not create it
234	$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' AND entity IN (".getEntity('invoice').")";
235	$result = $db->query($sql);
236	$num_lines = $db->num_rows($result);
237	if ($num_lines == 0)
238	{
239		require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
240		$invoice = new Facture($db);
241		$constforthirdpartyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
242		$invoice->socid = $conf->global->$constforthirdpartyid;
243		$invoice->date = dol_now();
244		$invoice->module_source = 'takepos';
245		$invoice->pos_source = $_SESSION["takeposterminal"];
246		$placeid = $invoice->create($user);
247		$sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid=".$placeid;
248		$db->query($sql);
249	}
250
251	$sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_soc=".$idcustomer." where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
252	$resql = $db->query($sql);
253	?>
254	    <script>
255	    console.log("Reload page invoice.php with place=<?php print $place; ?>");
256	    parent.$("#poslines").load("invoice.php?place=<?php print $place; ?>", function() {
257	        //parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
258			<?php if (!$resql) { ?>
259				alert('Error failed to update customer on draft invoice.');
260			<?php } ?>
261	        parent.$.colorbox.close(); /* Close the popup */
262	    });
263	    </script>
264    <?php
265	exit;
266}
267
268if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
269if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
270
271$parameters = array();
272$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
273if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
274
275if (empty($reshook))
276{
277	// Selection of new fields
278	include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
279
280	// Did we click on purge search criteria ?
281	if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
282	{
283		$search_id = '';
284		$search_nom = '';
285		$search_alias = '';
286		$search_categ_cus = 0;
287		$search_categ_sup = 0;
288		$search_sale = '';
289		$search_barcode = "";
290		$search_customer_code = '';
291		$search_supplier_code = '';
292		$search_account_customer_code = '';
293		$search_account_supplier_code = '';
294		$search_address = '';
295		$search_town = "";
296		$search_zip = "";
297		$search_state = "";
298		$search_country = '';
299		$search_email = '';
300		$search_phone = '';
301		$search_fax = '';
302		$search_url = '';
303		$search_idprof1 = '';
304		$search_idprof2 = '';
305		$search_idprof3 = '';
306		$search_idprof4 = '';
307		$search_idprof5 = '';
308		$search_idprof6 = '';
309		$search_vat = '';
310		$search_type = '';
311		$search_type_thirdparty = '';
312		$search_staff = '';
313		$search_status = -1;
314		$search_stcomm = '';
315	 	$search_level = '';
316	 	$search_parent_name = '';
317	 	$search_import_key = '';
318	 	$toselect = '';
319		$search_array_options = array();
320	}
321
322	// Mass actions
323	$objectclass = 'Societe';
324	$objectlabel = 'ThirdParty';
325	$permissiontoread = $user->rights->societe->lire;
326	$permissiontodelete = $user->rights->societe->supprimer;
327	$uploaddir = $conf->societe->dir_output;
328	include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
329
330	if ($action == 'setstcomm')
331	{
332		$object = new Client($db);
333		$result = $object->fetch(GETPOST('stcommsocid'));
334		$object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcomm');
335		$result = $object->update($object->id, $user);
336		if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
337
338		$action = '';
339	}
340}
341
342if ($search_status == '') $search_status = 1; // always display active thirdparty first
343
344
345
346/*
347 * View
348 */
349
350/*
351 REM: Rules on permissions to see thirdparties
352 Internal or External user + No permission to see customers => See nothing
353 Internal user socid=0 + Permission to see ALL customers    => See all thirdparties
354 Internal user socid=0 + No permission to see ALL customers => See only thirdparties linked to user that are sale representative
355 External user socid=x + Permission to see ALL customers    => Can see only himself
356 External user socid=x + No permission to see ALL customers => Can see only himself
357 */
358
359$form = new Form($db);
360$formother = new FormOther($db);
361$companystatic = new Societe($db);
362$companyparent = new Societe($db);
363$formcompany = new FormCompany($db);
364$prospectstatic = new Client($db);
365$prospectstatic->client = 2;
366$prospectstatic->loadCacheOfProspStatus();
367
368
369$title = $langs->trans("ListOfThirdParties");
370if ($type == 'c' && (empty($search_type) || ($search_type == '1,3'))) $title = $langs->trans("ListOfCustomers");
371if ($type == 'p' && (empty($search_type) || ($search_type == '2,3'))) $title = $langs->trans("ListOfProspects");
372if ($type == 'f' && (empty($search_type) || ($search_type == '4'))) $title = $langs->trans("ListOfSuppliers");
373
374// Select every potentiels, and note each potentiels which fit in search parameters
375$tab_level = array();
376$sql = "SELECT code, label, sortorder";
377$sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
378$sql .= " WHERE active > 0";
379$sql .= " ORDER BY sortorder";
380$resql = $db->query($sql);
381if ($resql)
382{
383	while ($obj = $db->fetch_object($resql))
384	{
385		// Compute level text
386		$level = $langs->trans($obj->code);
387		if ($level == $obj->code) $level = $langs->trans($obj->label);
388		$tab_level[$obj->code] = $level;
389	}
390} else dol_print_error($db);
391
392$sql = "SELECT s.rowid, s.nom as name, s.name_alias, s.barcode, s.address, s.town, s.zip, s.datec, s.code_client, s.code_fournisseur, s.logo,";
393$sql .= " s.entity,";
394$sql .= " st.libelle as stcomm, st.picto as stcomm_picto, s.fk_stcomm as stcomm_id, s.fk_prospectlevel, s.prefix_comm, s.client, s.fournisseur, s.canvas, s.status as status,";
395$sql .= " s.email, s.phone, s.fax, s.url, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4 as idprof4, s.idprof5 as idprof5, s.idprof6 as idprof6, s.tva_intra, s.fk_pays,";
396$sql .= " s.tms as date_update, s.datec as date_creation,";
397$sql .= " s.code_compta, s.code_compta_fournisseur, s.parent as fk_parent,";
398$sql .= " s2.nom as name2,";
399$sql .= " typent.code as typent_code,";
400$sql .= " staff.code as staff_code,";
401$sql .= " country.code as country_code, country.label as country_label,";
402$sql .= " state.code_departement as state_code, state.nom as state_name,";
403$sql .= " region.code_region as region_code, region.nom as region_name";
404// We'll need these fields in order to filter by sale (including the case where the user can only see his prospects)
405if ($search_sale) $sql .= ", sc.fk_soc, sc.fk_user";
406// We'll need these fields in order to filter by categ
407if ($search_categ_cus) $sql .= ", cc.fk_categorie, cc.fk_soc";
408if ($search_categ_sup) $sql .= ", cs.fk_categorie, cs.fk_soc";
409// Add fields from extrafields
410if (!empty($extrafields->attributes[$object->table_element]['label'])) {
411	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
412}
413// Add fields from hooks
414$parameters = array();
415$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
416$sql .= $hookmanager->resPrint;
417$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
418$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s.parent = s2.rowid";
419if (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 (s.rowid = ef.fk_object)";
420$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
421$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
422$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_effectif as staff on (staff.id = s.fk_effectif)";
423$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
424$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as region on (region.	code_region = state.fk_region)";
425// We'll need this table joined to the select in order to filter by categ
426if (!empty($search_categ_cus)) $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
427if (!empty($search_categ_sup)) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs ON s.rowid = cs.fk_soc"; // We'll need this table joined to the select in order to filter by categ
428$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."c_stcomm as st ON s.fk_stcomm = st.id";
429// We'll need this table joined to the select in order to filter by sale
430if ($search_sale == -2) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
431elseif ($search_sale || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
432// Add table from hooks
433$parameters = array();
434$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
435$sql .= $hookmanager->resPrint;
436$sql .= " WHERE s.entity IN (".getEntity('societe').")";
437if (!$user->rights->societe->client->voir && !$socid)	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
438if ($search_sale && $search_sale != -2)    $sql .= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
439if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
440if ($search_sale == -2)    $sql .= " AND sc.fk_user IS NULL";
441elseif ($search_sale)          $sql .= " AND sc.fk_user = ".$db->escape($search_sale);
442if ($search_categ_cus > 0) $sql .= " AND cc.fk_categorie = ".$db->escape($search_categ_cus);
443if ($search_categ_sup > 0) $sql .= " AND cs.fk_categorie = ".$db->escape($search_categ_sup);
444if ($search_categ_cus == -2)   $sql .= " AND cc.fk_categorie IS NULL";
445if ($search_categ_sup == -2)   $sql .= " AND cs.fk_categorie IS NULL";
446
447if ($search_all)           $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
448if (strlen($search_cti))   $sql .= natural_search('s.phone', $search_cti);
449
450if ($search_id > 0)        $sql .= natural_search("s.rowid", $search_id, 1);
451if ($search_nom)           $sql .= natural_search("s.nom", $search_nom);
452if ($search_alias)         $sql .= natural_search("s.name_alias", $search_alias);
453if ($search_nom_only)      $sql .= natural_search("s.nom", $search_nom_only);
454if ($search_customer_code) $sql .= natural_search("s.code_client", $search_customer_code);
455if ($search_supplier_code) $sql .= natural_search("s.code_fournisseur", $search_supplier_code);
456if ($search_account_customer_code) $sql .= natural_search("s.code_compta", $search_account_customer_code);
457if ($search_account_supplier_code) $sql .= natural_search("s.code_compta_fournisseur", $search_account_supplier_code);
458if ($search_address)	   $sql.= natural_search('s.address', $search_address);
459if ($search_town)          $sql .= natural_search("s.town", $search_town);
460if (strlen($search_zip))   $sql .= natural_search("s.zip", $search_zip);
461if ($search_state)         $sql .= natural_search("state.nom", $search_state);
462if ($search_region)        $sql .= natural_search("region.nom", $search_region);
463if ($search_country && $search_country != '-1')       $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
464if ($search_email)         $sql .= natural_search("s.email", $search_email);
465if (strlen($search_phone)) $sql .= natural_search("s.phone", $search_phone);
466if (strlen($search_fax))   $sql .= natural_search("s.fax", $search_fax);
467if ($search_url)           $sql .= natural_search("s.url", $search_url);
468if (strlen($search_idprof1)) $sql .= natural_search("s.siren", $search_idprof1);
469if (strlen($search_idprof2)) $sql .= natural_search("s.siret", $search_idprof2);
470if (strlen($search_idprof3)) $sql .= natural_search("s.ape", $search_idprof3);
471if (strlen($search_idprof4)) $sql .= natural_search("s.idprof4", $search_idprof4);
472if (strlen($search_idprof5)) $sql .= natural_search("s.idprof5", $search_idprof5);
473if (strlen($search_idprof6)) $sql .= natural_search("s.idprof6", $search_idprof6);
474if (strlen($search_vat))     $sql .= natural_search("s.tva_intra", $search_vat);
475// Filter on type of thirdparty
476if ($search_type > 0 && in_array($search_type, array('1,3', '1,2,3', '2,3'))) $sql .= " AND s.client IN (".$db->sanitize($db->escape($search_type)).")";
477if ($search_type > 0 && in_array($search_type, array('4')))         $sql .= " AND s.fournisseur = 1";
478if ($search_type == '0') $sql .= " AND s.client = 0 AND s.fournisseur = 0";
479if ($search_status != '' && $search_status >= 0) $sql .= natural_search("s.status", $search_status, 2);
480if (!empty($conf->barcode->enabled) && $search_barcode) $sql .= natural_search("s.barcode", $search_barcode);
481if ($search_type_thirdparty && $search_type_thirdparty != '-1') $sql .= natural_search("s.fk_typent", $search_type_thirdparty, 2);
482if (!empty($search_staff) && $search_staff != '-1')            $sql .= natural_search("s.fk_effectif", $search_staff, 2);
483if ($search_level)  $sql .= natural_search("s.fk_prospectlevel", join(',', $search_level), 3);
484if ($search_parent_name)   $sql .= natural_search("s2.nom", $search_parent_name);
485if ($search_stcomm != '' && $search_stcomm != -2) $sql .= natural_search("s.fk_stcomm", $search_stcomm, 1);
486if ($search_import_key)    $sql .= natural_search("s.import_key", $search_import_key);
487// Add where from extra fields
488include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
489// Add where from hooks
490$parameters = array('socid' => $socid);
491$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
492if (empty($reshook)) {
493	if ($socid) $sql .= " AND s.rowid = ".$socid;
494}
495$sql .= $hookmanager->resPrint;
496
497// Add GroupBy from hooks
498$parameters = array('all' => $all, 'fieldstosearchall' => $fieldstosearchall);
499$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
500$sql .= $hookmanager->resPrint;
501
502$sql .= $db->order($sortfield, $sortorder);
503
504// Count total nb of records
505$nbtotalofrecords = '';
506if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
507{
508	$result = $db->query($sql);
509	$nbtotalofrecords = $db->num_rows($result);
510	if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
511	{
512		$page = 0;
513		$offset = 0;
514	}
515}
516
517$sql .= $db->plimit($limit + 1, $offset);
518
519$resql = $db->query($sql);
520if (!$resql)
521{
522	dol_print_error($db);
523	exit;
524}
525
526$num = $db->num_rows($resql);
527
528$arrayofselected = is_array($toselect) ? $toselect : array();
529
530if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && ($search_all != '' || $search_cti != '') && $action != 'list') {
531	$obj = $db->fetch_object($resql);
532	$id = $obj->rowid;
533	if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) {
534		if ($obj->client > 0) {
535			header("Location: ".DOL_URL_ROOT.'/comm/card.php?socid='.$id);
536			exit;
537		}
538		if ($obj->fournisseur > 0) {
539			header("Location: ".DOL_URL_ROOT.'/fourn/card.php?socid='.$id);
540			exit;
541		}
542	}
543
544	header("Location: ".DOL_URL_ROOT.'/societe/card.php?socid='.$id);
545	exit;
546}
547
548$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
549llxHeader('', $langs->trans("ThirdParty"), $help_url);
550
551$param = '';
552if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
553if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
554if ($search_all != '')     $param = "&sall=".urlencode($search_all);
555if ($search_categ_cus > 0) $param .= '&search_categ_cus='.urlencode($search_categ_cus);
556if ($search_categ_sup > 0) $param .= '&search_categ_sup='.urlencode($search_categ_sup);
557if ($search_sale > 0)	   $param .= '&search_sale='.urlencode($search_sale);
558if ($search_id > 0)        $param .= "&search_id=".urlencode($search_id);
559if ($search_nom != '')     $param .= "&search_nom=".urlencode($search_nom);
560if ($search_alias != '')   $param .= "&search_alias=".urlencode($search_alias);
561if ($search_address != '') $param .= '&search_address=' . urlencode($search_address);
562if ($search_town != '')    $param .= "&search_town=".urlencode($search_town);
563if ($search_zip != '')     $param .= "&search_zip=".urlencode($search_zip);
564if ($search_phone != '')   $param .= "&search_phone=".urlencode($search_phone);
565if ($search_fax != '')     $param .= "&search_fax=".urlencode($search_fax);
566if ($search_email != '')   $param .= "&search_email=".urlencode($search_email);
567if ($search_url != '')     $param .= "&search_url=".urlencode($search_url);
568if ($search_state != '')   $param .= "&search_state=".urlencode($search_state);
569if ($search_country != '') $param .= "&search_country=".urlencode($search_country);
570if ($search_customer_code != '') $param .= "&search_customer_code=".urlencode($search_customer_code);
571if ($search_supplier_code != '') $param .= "&search_supplier_code=".urlencode($search_supplier_code);
572if ($search_account_customer_code != '') $param .= "&search_account_customer_code=".urlencode($search_account_customer_code);
573if ($search_account_supplier_code != '') $param .= "&search_account_supplier_code=".urlencode($search_account_supplier_code);
574if ($search_barcode != '') $param .= "&search_barcode=".urlencode($search_barcode);
575if ($search_idprof1 != '') $param .= '&search_idprof1='.urlencode($search_idprof1);
576if ($search_idprof2 != '') $param .= '&search_idprof2='.urlencode($search_idprof2);
577if ($search_idprof3 != '') $param .= '&search_idprof3='.urlencode($search_idprof3);
578if ($search_idprof4 != '') $param .= '&search_idprof4='.urlencode($search_idprof4);
579if ($search_idprof5 != '') $param .= '&search_idprof5='.urlencode($search_idprof5);
580if ($search_idprof6 != '') $param .= '&search_idprof6='.urlencode($search_idprof6);
581if ($search_vat != '')     $param .= '&search_vat='.urlencode($search_vat);
582if ($search_type_thirdparty != '')    $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
583if ($search_type != '')    $param .= '&search_type='.urlencode($search_type);
584if (is_array($search_level) && count($search_level)) foreach ($search_level as $slevel) $param .= '&search_level[]='.urlencode($slevel);
585if ($search_status != '')  $param .= '&search_status='.urlencode($search_status);
586if ($search_stcomm != '')  $param .= '&search_stcomm='.urlencode($search_stcomm);
587if ($search_parent_name != '') $param .= '&search_parent_name='.urlencode($search_parent_name);
588if ($search_import_key != '') $param .= '&search_import_key='.urlencode($search_import_key);
589if ($type != '') $param .= '&type='.urlencode($type);
590if ($optioncss != '')      $param .= '&optioncss='.urlencode($optioncss);
591// Add $param from extra fields
592include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
593
594// Show delete result message
595if (GETPOST('delsoc'))
596{
597	setEventMessages($langs->trans("CompanyDeleted", GETPOST('delsoc')), null, 'mesgs');
598}
599
600// List of mass actions available
601$arrayofmassactions = array(
602	'presend'=>$langs->trans("SendByMail"),
603//    'builddoc'=>$langs->trans("PDFMerge"),
604);
605//if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
606if ($user->rights->societe->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
607if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
608$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
609
610$typefilter = '';
611$label = 'MenuNewThirdParty';
612
613if (!empty($type))
614{
615	$typefilter = '&amp;type='.$type;
616	if ($type == 'p') $label = 'MenuNewProspect';
617	if ($type == 'c') $label = 'MenuNewCustomer';
618	if ($type == 'f') $label = 'NewSupplier';
619}
620
621if ($contextpage == 'poslist' && $type == 't' && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
622	print get_htmloutput_mesg(img_warning('default').' '.$langs->trans("BecarefullChangeThirdpartyBeforeAddProductToInvoice"), '', 'warning', 1);
623}
624
625// Show the new button only when this page is not opend from the Extended POS (pop-up window)
626// but allow it too, when a user has the rights to create a new customer
627if ($contextpage != 'poslist') {
628	$url = DOL_URL_ROOT.'/societe/card.php?action=create'.$typefilter;
629	if (!empty($socid)) $url .= '&socid='.$socid;
630	$newcardbutton = dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', $url, '', $user->rights->societe->creer);
631} elseif ($user->rights->societe->creer) {
632	$url = DOL_URL_ROOT.'/societe/card.php?action=create&type=t&contextpage=poslist&optioncss=print&backtopage='.urlencode($_SERVER["PHP_SELF"].'?type=t&contextpage=poslist&nomassaction=1&optioncss=print&place='.$place);
633	$label = 'MenuNewCustomer';
634	$newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', $url);
635}
636
637print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="formfilter" autocomplete="off">';
638if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
639print '<input type="hidden" name="token" value="'.newToken().'">';
640print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
641print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
642print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
643//print '<input type="hidden" name="page" value="'.$page.'">';
644print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
645
646print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'building', 0, $newcardbutton, '', $limit, 0, 0, 1);
647
648$langs->load("other");
649$textprofid = array();
650foreach (array(1, 2, 3, 4, 5, 6) as $key)
651{
652	$label = $langs->transnoentities("ProfId".$key.$mysoc->country_code);
653	$textprofid[$key] = '';
654	if ($label != "ProfId".$key.$mysoc->country_code)
655	{	// Get only text between ()
656		if (preg_match('/\((.*)\)/i', $label, $reg)) $label = $reg[1];
657		$textprofid[$key] = $langs->trans("ProfIdShortDesc", $key, $mysoc->country_code, $label);
658	}
659}
660
661$topicmail = "Information";
662$modelmail = "thirdparty";
663$objecttmp = new Societe($db);
664$trackid = 'thi'.$object->id;
665include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
666
667if ($search_all)
668{
669	foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
670	print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
671}
672
673// Filter on categories
674$moreforfilter = '';
675if (empty($type) || $type == 'c' || $type == 'p')
676{
677	if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire)
678	{
679		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
680		$moreforfilter .= '<div class="divsearchfield">';
681	 	$moreforfilter .= $langs->trans('CustomersProspectsCategoriesShort').': ';
682		$moreforfilter .= $formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $langs->trans('CustomersProspectsCategoriesShort'));
683	 	$moreforfilter .= '</div>';
684	}
685}
686if (empty($type) || $type == 'f')
687{
688	if (!empty($conf->fournisseur->enabled) && !empty($conf->categorie->enabled) && $user->rights->categorie->lire)
689	{
690		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
691		$moreforfilter .= '<div class="divsearchfield">';
692		$moreforfilter .= $langs->trans('SuppliersCategoriesShort').': ';
693		$moreforfilter .= $formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1);
694		$moreforfilter .= '</div>';
695	}
696}
697
698// If the user can view prospects other than his'
699if ($user->rights->societe->client->voir || $socid)
700{
701 	$moreforfilter .= '<div class="divsearchfield">';
702 	$moreforfilter .= $langs->trans('SalesRepresentatives').': ';
703	$moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300', 1);
704	$moreforfilter .= '</div>';
705}
706if ($moreforfilter)
707{
708	print '<div class="liste_titre liste_titre_bydiv centpercent">';
709	print $moreforfilter;
710	$parameters = array('type'=>$type);
711	$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
712	print $hookmanager->resPrint;
713	print '</div>';
714}
715
716$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
717$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
718// Show the massaction checkboxes only when this page is not opend from the Extended POS
719if ($massactionbutton && $contextpage != 'poslist') $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
720
721if (empty($arrayfields['customerorsupplier']['checked'])) print '<input type="hidden" name="type" value="'.$type.'">';
722
723print '<div class="div-table-responsive">';
724print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
725
726// Fields title search
727print '<tr class="liste_titre_filter">';
728if (!empty($arrayfields['s.rowid']['checked']))
729{
730	print '<td class="liste_titre">';
731	print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
732	print '</td>';
733}
734if (!empty($arrayfields['s.nom']['checked']))
735{
736	print '<td class="liste_titre">';
737	if (!empty($search_nom_only) && empty($search_nom)) $search_nom = $search_nom_only;
738	print '<input class="flat searchstring maxwidth75imp" type="text" name="search_nom" value="'.dol_escape_htmltag($search_nom).'">';
739	print '</td>';
740}
741if (!empty($arrayfields['s.name_alias']['checked']))
742{
743	print '<td class="liste_titre">';
744	print '<input class="flat searchstring maxwidth75imp" type="text" name="search_alias" value="'.dol_escape_htmltag($search_alias).'">';
745	print '</td>';
746}
747// Barcode
748if (!empty($arrayfields['s.barcode']['checked']))
749{
750	print '<td class="liste_titre">';
751	print '<input class="flat searchstring maxwidth75imp" type="text" name="search_barcode" value="'.dol_escape_htmltag($search_barcode).'">';
752	print '</td>';
753}
754// Customer code
755if (!empty($arrayfields['s.code_client']['checked']))
756{
757	print '<td class="liste_titre">';
758	print '<input class="flat searchstring maxwidth75imp" type="text" name="search_customer_code" value="'.dol_escape_htmltag($search_customer_code).'">';
759	print '</td>';
760}
761// Supplier code
762if (!empty($arrayfields['s.code_fournisseur']['checked']))
763{
764	print '<td class="liste_titre">';
765	print '<input class="flat searchstring maxwidth75imp" type="text" name="search_supplier_code" value="'.dol_escape_htmltag($search_supplier_code).'">';
766	print '</td>';
767}
768// Account Customer code
769if (!empty($arrayfields['s.code_compta']['checked']))
770{
771	print '<td class="liste_titre">';
772	print '<input class="flat searchstring maxwidth75imp" type="text" name="search_account_customer_code" value="'.dol_escape_htmltag($search_account_customer_code).'">';
773	print '</td>';
774}
775// Account Supplier code
776if (!empty($arrayfields['s.code_compta_fournisseur']['checked']))
777{
778	print '<td class="liste_titre">';
779	print '<input class="flat maxwidth75imp" type="text" name="search_account_supplier_code" value="'.dol_escape_htmltag($search_account_supplier_code).'">';
780	print '</td>';
781}
782// Address
783if (!empty($arrayfields['s.address']['checked']))
784{
785	print '<td class="liste_titre">';
786	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_address" value="'.dol_escape_htmltag($search_address).'">';
787	print '</td>';
788}
789// Town
790if (!empty($arrayfields['s.town']['checked']))
791{
792	print '<td class="liste_titre">';
793	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
794	print '</td>';
795}
796// Zip
797if (!empty($arrayfields['s.zip']['checked']))
798{
799	print '<td class="liste_titre">';
800	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
801	print '</td>';
802}
803// State
804if (!empty($arrayfields['state.nom']['checked']))
805{
806	print '<td class="liste_titre">';
807	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
808	print '</td>';
809}
810// Region
811if (!empty($arrayfields['region.nom']['checked']))
812{
813	print '<td class="liste_titre">';
814	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_region" value="'.dol_escape_htmltag($search_region).'">';
815	print '</td>';
816}
817// Country
818if (!empty($arrayfields['country.code_iso']['checked']))
819{
820	print '<td class="liste_titre center">';
821	print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
822	print '</td>';
823}
824// Company type
825if (!empty($arrayfields['typent.code']['checked']))
826{
827	print '<td class="liste_titre maxwidthonsmartphone center">';
828	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), 'maxwidth75', 1);
829	print '</td>';
830}
831// Staff
832if (!empty($arrayfields['staff.code']['checked']))
833{
834	print '<td class="liste_titre maxwidthonsmartphone center">';
835	print $form->selectarray("search_staff", $formcompany->effectif_array(0), $search_staff, 0, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100', 1);
836	print '</td>';
837}
838if (!empty($arrayfields['s.email']['checked']))
839{
840	// Email
841	print '<td class="liste_titre">';
842	print '<input class="flat searchemail maxwidth50imp" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
843	print '</td>';
844}
845if (!empty($arrayfields['s.phone']['checked']))
846{
847	// Phone
848	print '<td class="liste_titre">';
849	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_phone" value="'.dol_escape_htmltag($search_phone).'">';
850	print '</td>';
851}
852if (!empty($arrayfields['s.fax']['checked']))
853{
854	// Fax
855	print '<td class="liste_titre">';
856	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_fax" value="'.dol_escape_htmltag($search_fax).'">';
857	print '</td>';
858}
859if (!empty($arrayfields['s.url']['checked']))
860{
861	// Url
862	print '<td class="liste_titre">';
863	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_url" value="'.dol_escape_htmltag($search_url).'">';
864	print '</td>';
865}
866if (!empty($arrayfields['s.siren']['checked']))
867{
868	// IdProf1
869	print '<td class="liste_titre">';
870	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof1" value="'.dol_escape_htmltag($search_idprof1).'">';
871	print '</td>';
872}
873if (!empty($arrayfields['s.siret']['checked']))
874{
875	// IdProf2
876	print '<td class="liste_titre">';
877	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof2" value="'.dol_escape_htmltag($search_idprof2).'">';
878	print '</td>';
879}
880if (!empty($arrayfields['s.ape']['checked']))
881{
882	// IdProf3
883	print '<td class="liste_titre">';
884	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof3" value="'.dol_escape_htmltag($search_idprof3).'">';
885	print '</td>';
886}
887if (!empty($arrayfields['s.idprof4']['checked']))
888{
889	// IdProf4
890	print '<td class="liste_titre">';
891	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof4" value="'.dol_escape_htmltag($search_idprof4).'">';
892	print '</td>';
893}
894if (!empty($arrayfields['s.idprof5']['checked']))
895{
896	// IdProf5
897	print '<td class="liste_titre">';
898	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof5" value="'.dol_escape_htmltag($search_idprof5).'">';
899	print '</td>';
900}
901if (!empty($arrayfields['s.idprof6']['checked']))
902{
903	// IdProf6
904	print '<td class="liste_titre">';
905	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof6" value="'.dol_escape_htmltag($search_idprof6).'">';
906	print '</td>';
907}
908if (!empty($arrayfields['s.tva_intra']['checked']))
909{
910	// Vat number
911	print '<td class="liste_titre">';
912	print '<input class="flat searchstring maxwidth50imp" type="text" name="search_vat" value="'.dol_escape_htmltag($search_vat).'">';
913	print '</td>';
914}
915
916// Type (customer/prospect/supplier)
917if (!empty($arrayfields['customerorsupplier']['checked']))
918{
919	print '<td class="liste_titre maxwidthonsmartphone center">';
920	if ($type != '') print '<input type="hidden" name="type" value="'.$type.'">';
921	print $formcompany->selectProspectCustomerType($search_type, 'search_type', 'search_type', 'list');
922	print '</select></td>';
923}
924// Prospect level
925if (!empty($arrayfields['s.fk_prospectlevel']['checked']))
926{
927 	print '<td class="liste_titre center">';
928 	print $form->multiselectarray('search_level', $tab_level, $search_level, 0, 0, 'width75', 0, 0, '', '', '', 2);
929	print '</td>';
930}
931// Prospect status
932if (!empty($arrayfields['s.fk_stcomm']['checked']))
933{
934	print '<td class="liste_titre maxwidthonsmartphone center">';
935	$arraystcomm = array();
936	foreach ($prospectstatic->cacheprospectstatus as $key => $val)
937	{
938		$arraystcomm[$val['id']] = ($langs->trans("StatusProspect".$val['id']) != "StatusProspect".$val['id'] ? $langs->trans("StatusProspect".$val['id']) : $val['label']);
939	}
940	print $form->selectarray('search_stcomm', $arraystcomm, $search_stcomm, -2, 0, 0, '', 0, 0, 0, '', '', 1);
941	print '</td>';
942}
943if (!empty($arrayfields['s2.nom']['checked']))
944{
945	print '<td class="liste_titre center">';
946	print '<input class="flat searchstring maxwidth75imp" type="text" name="search_parent_name" value="'.dol_escape_htmltag($search_parent_name).'">';
947	print '</td>';
948}
949// Extra fields
950include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
951
952// Fields from hook
953$parameters = array('arrayfields'=>$arrayfields);
954$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
955print $hookmanager->resPrint;
956// Date creation
957if (!empty($arrayfields['s.datec']['checked']))
958{
959	print '<td class="liste_titre">';
960	print '</td>';
961}
962// Date modification
963if (!empty($arrayfields['s.tms']['checked']))
964{
965	print '<td class="liste_titre">';
966	print '</td>';
967}
968// Status
969if (!empty($arrayfields['s.status']['checked']))
970{
971	print '<td class="liste_titre center minwidth75imp">';
972	print $form->selectarray('search_status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $search_status, 1, 0, 0, '', 0, 0, 0, '', '', 1);
973	print '</td>';
974}
975if (!empty($arrayfields['s.import_key']['checked']))
976{
977	print '<td class="liste_titre center">';
978	print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
979	print '</td>';
980}
981// Action column
982print '<td class="liste_titre center">';
983$searchpicto = $form->showFilterButtons();
984print $searchpicto;
985print '</td>';
986
987print "</tr>\n";
988
989print '<tr class="liste_titre">';
990if (!empty($arrayfields['s.rowid']['checked']))                   print_liste_field_titre($arrayfields['s.rowid']['label'], $_SERVER["PHP_SELF"], "s.rowid", "", $param, "", $sortfield, $sortorder);
991if (!empty($arrayfields['s.nom']['checked']))                     print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder);
992if (!empty($arrayfields['s.name_alias']['checked']))              print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", "", $param, "", $sortfield, $sortorder);
993if (!empty($arrayfields['s.barcode']['checked']))                 print_liste_field_titre($arrayfields['s.barcode']['label'], $_SERVER["PHP_SELF"], "s.barcode", $param, '', '', $sortfield, $sortorder);
994if (!empty($arrayfields['s.code_client']['checked']))             print_liste_field_titre($arrayfields['s.code_client']['label'], $_SERVER["PHP_SELF"], "s.code_client", "", $param, '', $sortfield, $sortorder);
995if (!empty($arrayfields['s.code_fournisseur']['checked']))        print_liste_field_titre($arrayfields['s.code_fournisseur']['label'], $_SERVER["PHP_SELF"], "s.code_fournisseur", "", $param, '', $sortfield, $sortorder);
996if (!empty($arrayfields['s.code_compta']['checked']))             print_liste_field_titre($arrayfields['s.code_compta']['label'], $_SERVER["PHP_SELF"], "s.code_compta", "", $param, '', $sortfield, $sortorder);
997if (!empty($arrayfields['s.code_compta_fournisseur']['checked'])) print_liste_field_titre($arrayfields['s.code_compta_fournisseur']['label'], $_SERVER["PHP_SELF"], "s.code_compta_fournisseur", "", $param, '', $sortfield, $sortorder);
998if (!empty($arrayfields['s.address']['checked']))		 print_liste_field_titre($arrayfields['s.address']['label'], $_SERVER['PHP_SELF'], 's.address', '', $param, '', $sortfield, $sortorder);
999if (!empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], "s.town", "", $param, '', $sortfield, $sortorder);
1000if (!empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], "s.zip", "", $param, '', $sortfield, $sortorder);
1001if (!empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1002if (!empty($arrayfields['region.nom']['checked']))       print_liste_field_titre($arrayfields['region.nom']['label'], $_SERVER["PHP_SELF"], "region.nom", "", $param, '', $sortfield, $sortorder);
1003if (!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 ');
1004if (!empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1005if (!empty($arrayfields['staff.code']['checked']))       print_liste_field_titre($arrayfields['staff.code']['label'], $_SERVER["PHP_SELF"], "staff.code", "", $param, '', $sortfield, $sortorder, 'center ');
1006if (!empty($arrayfields['s.email']['checked']))          print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder);
1007if (!empty($arrayfields['s.phone']['checked']))          print_liste_field_titre($arrayfields['s.phone']['label'], $_SERVER["PHP_SELF"], "s.phone", "", $param, '', $sortfield, $sortorder);
1008if (!empty($arrayfields['s.fax']['checked'])) print_liste_field_titre($arrayfields['s.fax']['label'], $_SERVER["PHP_SELF"], "s.fax", "", $param, '', $sortfield, $sortorder);
1009if (!empty($arrayfields['s.url']['checked']))            print_liste_field_titre($arrayfields['s.url']['label'], $_SERVER["PHP_SELF"], "s.url", "", $param, '', $sortfield, $sortorder);
1010if (!empty($arrayfields['s.siren']['checked']))          print_liste_field_titre($form->textwithpicto($langs->trans("ProfId1Short"), $textprofid[1], 1, 0), $_SERVER["PHP_SELF"], "s.siren", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1011if (!empty($arrayfields['s.siret']['checked']))          print_liste_field_titre($form->textwithpicto($langs->trans("ProfId2Short"), $textprofid[2], 1, 0), $_SERVER["PHP_SELF"], "s.siret", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1012if (!empty($arrayfields['s.ape']['checked']))            print_liste_field_titre($form->textwithpicto($langs->trans("ProfId3Short"), $textprofid[3], 1, 0), $_SERVER["PHP_SELF"], "s.ape", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1013if (!empty($arrayfields['s.idprof4']['checked']))        print_liste_field_titre($form->textwithpicto($langs->trans("ProfId4Short"), $textprofid[4], 1, 0), $_SERVER["PHP_SELF"], "s.idprof4", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1014if (!empty($arrayfields['s.idprof5']['checked']))        print_liste_field_titre($form->textwithpicto($langs->trans("ProfId5Short"), $textprofid[4], 1, 0), $_SERVER["PHP_SELF"], "s.idprof5", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1015if (!empty($arrayfields['s.idprof6']['checked']))        print_liste_field_titre($form->textwithpicto($langs->trans("ProfId6Short"), $textprofid[4], 1, 0), $_SERVER["PHP_SELF"], "s.idprof6", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1016if (!empty($arrayfields['s.tva_intra']['checked']))      print_liste_field_titre($arrayfields['s.tva_intra']['label'], $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1017if (!empty($arrayfields['customerorsupplier']['checked']))        print_liste_field_titre(''); // type of customer
1018if (!empty($arrayfields['s.fk_prospectlevel']['checked']))        print_liste_field_titre($arrayfields['s.fk_prospectlevel']['label'], $_SERVER["PHP_SELF"], "s.fk_prospectlevel", "", $param, '', $sortfield, $sortorder, 'center ');
1019if (!empty($arrayfields['s.fk_stcomm']['checked']))               print_liste_field_titre($arrayfields['s.fk_stcomm']['label'], $_SERVER["PHP_SELF"], "s.fk_stcomm", "", $param, '', $sortfield, $sortorder, 'center ');
1020if (!empty($arrayfields['s2.nom']['checked']))           print_liste_field_titre($arrayfields['s2.nom']['label'], $_SERVER["PHP_SELF"], "s2.nom", "", $param, '', $sortfield, $sortorder, 'center ');
1021// Extra fields
1022include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1023// Hook fields
1024$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1025$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1026print $hookmanager->resPrint;
1027if (!empty($arrayfields['s.datec']['checked']))      print_liste_field_titre($arrayfields['s.datec']['label'], $_SERVER["PHP_SELF"], "s.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1028if (!empty($arrayfields['s.tms']['checked']))        print_liste_field_titre($arrayfields['s.tms']['label'], $_SERVER["PHP_SELF"], "s.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1029if (!empty($arrayfields['s.status']['checked']))     print_liste_field_titre($arrayfields['s.status']['label'], $_SERVER["PHP_SELF"], "s.status", "", $param, '', $sortfield, $sortorder, 'center ');
1030if (!empty($arrayfields['s.import_key']['checked'])) print_liste_field_titre($arrayfields['s.import_key']['label'], $_SERVER["PHP_SELF"], "s.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
1031print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1032print "</tr>\n";
1033
1034
1035$i = 0;
1036$totalarray = array();
1037while ($i < min($num, $limit))
1038{
1039	$obj = $db->fetch_object($resql);
1040
1041	$companystatic->id = $obj->rowid;
1042	$companystatic->name = $obj->name;
1043	$companystatic->name_alias = $obj->name_alias;
1044	$companystatic->logo = $obj->logo;
1045	$companystatic->canvas = $obj->canvas;
1046	$companystatic->client = $obj->client;
1047	$companystatic->status = $obj->status;
1048	$companystatic->email = $obj->email;
1049	$companystatic->fournisseur = $obj->fournisseur;
1050	$companystatic->code_client = $obj->code_client;
1051	$companystatic->code_fournisseur = $obj->code_fournisseur;
1052	$companystatic->tva_intra = $obj->tva_intra;
1053	$companystatic->country_code = $obj->country_code;
1054
1055	$companystatic->code_compta_client = $obj->code_compta;
1056	$companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1057
1058   	$companystatic->fk_prospectlevel = $obj->fk_prospectlevel;
1059   	$companystatic->fk_parent = $obj->fk_parent;
1060	$companystatic->entity = $obj->entity;
1061
1062	print '<tr class="oddeven"';
1063	if ($contextpage == 'poslist')
1064	{
1065		print ' onclick="location.href=\'list.php?action=change&contextpage=poslist&idcustomer='.$obj->rowid.'&place='.urlencode($place).'\'"';
1066	}
1067	print '>';
1068	if (!empty($arrayfields['s.rowid']['checked']))
1069	{
1070		print '<td class="tdoverflowmax50">';
1071		print $obj->rowid;
1072		print "</td>\n";
1073		if (!$i) $totalarray['nbfield']++;
1074	}
1075	if (!empty($arrayfields['s.nom']['checked']))
1076	{
1077		$savalias = $obj->name_alias;
1078		if (!empty($arrayfields['s.name_alias']['checked'])) $companystatic->name_alias = '';
1079		print '<td'.(empty($conf->global->MAIN_SOCIETE_SHOW_COMPLETE_NAME) ? ' class="tdoverflowmax200"' : '').'>';
1080		if ($contextpage == 'poslist')
1081		{
1082			print $obj->name;
1083		} else {
1084			print $companystatic->getNomUrl(1, '', 100, 0, 1);
1085		}
1086		print "</td>\n";
1087		$companystatic->name_alias = $savalias;
1088		if (!$i) $totalarray['nbfield']++;
1089	}
1090	if (!empty($arrayfields['s.name_alias']['checked']))
1091	{
1092		print '<td class="tdoverflowmax200">';
1093		print $companystatic->name_alias;
1094		print "</td>\n";
1095		if (!$i) $totalarray['nbfield']++;
1096	}
1097	// Barcode
1098	if (!empty($arrayfields['s.barcode']['checked']))
1099	{
1100		print '<td>'.$obj->barcode.'</td>';
1101		if (!$i) $totalarray['nbfield']++;
1102	}
1103	// Customer code
1104	if (!empty($arrayfields['s.code_client']['checked']))
1105	{
1106		print '<td class="nowraponall">'.$obj->code_client.'</td>';
1107		if (!$i) $totalarray['nbfield']++;
1108	}
1109	// Supplier code
1110	if (!empty($arrayfields['s.code_fournisseur']['checked']))
1111	{
1112		print '<td class="nowraponall">'.$obj->code_fournisseur.'</td>';
1113		if (!$i) $totalarray['nbfield']++;
1114	}
1115	// Account customer code
1116	if (!empty($arrayfields['s.code_compta']['checked']))
1117	{
1118		print '<td>'.$obj->code_compta.'</td>';
1119		if (!$i) $totalarray['nbfield']++;
1120	}
1121	// Account supplier code
1122	if (!empty($arrayfields['s.code_compta_fournisseur']['checked']))
1123	{
1124		print '<td>'.$obj->code_compta_fournisseur.'</td>';
1125		if (!$i) $totalarray['nbfield']++;
1126	}
1127	// Address
1128	if (!empty($arrayfields['s.address']['checked']))
1129	{
1130		print '<td>'.$obj->address.'</td>';
1131		if (!$i) $totalarray['nbfield']++;
1132	}
1133	// Town
1134	if (!empty($arrayfields['s.town']['checked']))
1135	{
1136		print "<td>".$obj->town."</td>\n";
1137		if (!$i) $totalarray['nbfield']++;
1138	}
1139	// Zip
1140	if (!empty($arrayfields['s.zip']['checked']))
1141	{
1142		print "<td>".$obj->zip."</td>\n";
1143		if (!$i) $totalarray['nbfield']++;
1144	}
1145	// State
1146	if (!empty($arrayfields['state.nom']['checked']))
1147	{
1148		print "<td>".$obj->state_name."</td>\n";
1149		if (!$i) $totalarray['nbfield']++;
1150	}
1151	// Region
1152	if (!empty($arrayfields['region.nom']['checked']))
1153	{
1154		print "<td>".$obj->region_name."</td>\n";
1155		if (!$i) $totalarray['nbfield']++;
1156	}
1157	// Country
1158	if (!empty($arrayfields['country.code_iso']['checked']))
1159	{
1160		print '<td class="center tdoverflowmax100">';
1161		$labelcountry = ($obj->country_code && ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code)) ? $langs->trans("Country".$obj->country_code) : $obj->country_label;
1162		print $labelcountry;
1163		print '</td>';
1164		if (!$i) $totalarray['nbfield']++;
1165	}
1166	// Type ent
1167	if (!empty($arrayfields['typent.code']['checked']))
1168	{
1169		print '<td class="center">';
1170		if (!is_array($typenArray) || count($typenArray) == 0) $typenArray = $formcompany->typent_array(1);
1171		print $typenArray[$obj->typent_code];
1172		print '</td>';
1173		if (!$i) $totalarray['nbfield']++;
1174	}
1175	// Staff
1176	if (!empty($arrayfields['staff.code']['checked']))
1177	{
1178		print '<td class="center">';
1179		if (!is_array($staffArray) || count($staffArray) == 0) $staffArray = $formcompany->effectif_array(1);
1180		print $staffArray[$obj->staff_code];
1181		print '</td>';
1182		if (!$i) $totalarray['nbfield']++;
1183	}
1184	if (!empty($arrayfields['s.email']['checked']))
1185	{
1186		print '<td class="tdoverflowmax150">'.dol_print_email($obj->email, $obj->rowid, $obj->socid, 'AC_EMAIL', 0, 0, 1)."</td>\n";
1187		if (!$i) $totalarray['nbfield']++;
1188	}
1189	if (!empty($arrayfields['s.phone']['checked']))
1190	{
1191		print "<td>".dol_print_phone($obj->phone, $obj->country_code, 0, $obj->rowid, 'AC_TEL')."</td>\n";
1192		if (!$i) $totalarray['nbfield']++;
1193	}
1194	if (!empty($arrayfields['s.fax']['checked']))
1195	{
1196		print "<td>".dol_print_phone($obj->fax, $obj->country_code, 0, $obj->rowid, 'AC_TEL')."</td>\n";
1197		if (!$i) $totalarray['nbfield']++;
1198	}
1199	if (!empty($arrayfields['s.url']['checked']))
1200	{
1201		print "<td>".$obj->url."</td>\n";
1202		if (!$i) $totalarray['nbfield']++;
1203	}
1204	if (!empty($arrayfields['s.siren']['checked']))
1205	{
1206		print "<td>".$obj->idprof1."</td>\n";
1207		if (!$i) $totalarray['nbfield']++;
1208	}
1209	if (!empty($arrayfields['s.siret']['checked']))
1210	{
1211		print "<td>".$obj->idprof2."</td>\n";
1212		if (!$i) $totalarray['nbfield']++;
1213	}
1214	if (!empty($arrayfields['s.ape']['checked']))
1215	{
1216		print "<td>".$obj->idprof3."</td>\n";
1217		if (!$i) $totalarray['nbfield']++;
1218	}
1219	if (!empty($arrayfields['s.idprof4']['checked']))
1220	{
1221		print "<td>".$obj->idprof4."</td>\n";
1222		if (!$i) $totalarray['nbfield']++;
1223	}
1224	if (!empty($arrayfields['s.idprof5']['checked']))
1225	{
1226		print "<td>".$obj->idprof5."</td>\n";
1227		if (!$i) $totalarray['nbfield']++;
1228	}
1229	if (!empty($arrayfields['s.idprof6']['checked']))
1230	{
1231		print "<td>".$obj->idprof6."</td>\n";
1232		if (!$i) $totalarray['nbfield']++;
1233	}
1234	// VAT
1235	if (!empty($arrayfields['s.tva_intra']['checked']))
1236	{
1237		print "<td>";
1238		print $obj->tva_intra;
1239		if ($obj->tva_intra && !isValidVATID($companystatic))
1240		{
1241			print img_warning("BadVATNumber", '', '');
1242		}
1243		print "</td>\n";
1244		if (!$i) $totalarray['nbfield']++;
1245	}
1246	// Type
1247	if (!empty($arrayfields['customerorsupplier']['checked']))
1248	{
1249		print '<td class="center">';
1250		$s = '';
1251		if (($obj->client == 2 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
1252		{
1253			$s .= '<a class="customer-back opacitymedium" title="'.$langs->trans("Prospect").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Prospect"), 0, 1).'</a>';
1254		}
1255		if (($obj->client == 1 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
1256		{
1257			$s .= '<a class="customer-back" title="'.$langs->trans("Customer").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Customer"), 0, 1).'</a>';
1258		}
1259		if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $obj->fournisseur)
1260		{
1261			$s .= '<a class="vendor-back" title="'.$langs->trans("Supplier").'" href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Supplier"), 0, 1).'</a>';
1262		}
1263		print $s;
1264		print '</td>';
1265		if (!$i) $totalarray['nbfield']++;
1266	}
1267
1268	if (!empty($arrayfields['s.fk_prospectlevel']['checked']))
1269	{
1270		// Prospect level
1271		print '<td class="center">';
1272		print $companystatic->getLibProspLevel();
1273		print "</td>";
1274		if (!$i) $totalarray['nbfield']++;
1275	}
1276
1277	if (!empty($arrayfields['s.fk_stcomm']['checked']))
1278	{
1279		// Prospect status
1280		print '<td class="center nowrap"><div class="nowrap">';
1281		print '<div class="inline-block">'.$companystatic->LibProspCommStatut($obj->stcomm_id, 2, $prospectstatic->cacheprospectstatus[$obj->stcomm_id]['label'], $obj->stcomm_picto);
1282		print '</div> - <div class="inline-block">';
1283		foreach ($prospectstatic->cacheprospectstatus as $key => $val)
1284		{
1285			$titlealt = 'default';
1286			if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) $titlealt = $val['label'];
1287			if ($obj->stcomm_id != $val['id']) print '<a class="pictosubstatus" href="'.$_SERVER["PHP_SELF"].'?stcommsocid='.$obj->rowid.'&stcomm='.$val['code'].'&action=setstcomm&token='.newToken().$param.($page ? '&page='.urlencode($page) : '').'">'.img_action($titlealt, $val['code'], $val['picto']).'</a>';
1288		}
1289		print '</div></div></td>';
1290		if (!$i) $totalarray['nbfield']++;
1291	}
1292	// Parent company
1293	if (!empty($arrayfields['s2.nom']['checked']))
1294	{
1295		print '<td class="center tdoverflowmax100">';
1296		if ($companystatic->fk_parent > 0)
1297		{
1298			$companyparent->fetch($companystatic->fk_parent);
1299			print $companyparent->getNomUrl(1);
1300		}
1301		print "</td>";
1302		if (!$i) $totalarray['nbfield']++;
1303	}
1304	// Extra fields
1305	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1306	// Fields from hook
1307	$parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1308	$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1309	print $hookmanager->resPrint;
1310	// Date creation
1311	if (!empty($arrayfields['s.datec']['checked']))
1312	{
1313		print '<td class="center nowrap">';
1314		print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1315		print '</td>';
1316		if (!$i) $totalarray['nbfield']++;
1317	}
1318	// Date modification
1319	if (!empty($arrayfields['s.tms']['checked']))
1320	{
1321		print '<td class="center nowrap">';
1322		print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1323		print '</td>';
1324		if (!$i) $totalarray['nbfield']++;
1325	}
1326	// Status
1327	if (!empty($arrayfields['s.status']['checked']))
1328	{
1329		print '<td class="center nowrap">'.$companystatic->getLibStatut(5).'</td>';
1330		if (!$i) $totalarray['nbfield']++;
1331	}
1332	if (!empty($arrayfields['s.import_key']['checked']))
1333	{
1334		print '<td class="tdoverflowmax100">';
1335		print $obj->import_key;
1336		print "</td>\n";
1337		if (!$i) $totalarray['nbfield']++;
1338	}
1339
1340	// Action column (Show the massaction button only when this page is not opend from the Extended POS)
1341	print '<td class="nowrap center">';
1342	if (($massactionbutton || $massaction) && $contextpage != 'poslist')   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1343	{
1344		$selected = 0;
1345		if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
1346		print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1347	}
1348	print '</td>';
1349	if (!$i) $totalarray['nbfield']++;
1350
1351	print '</tr>'."\n";
1352	$i++;
1353}
1354
1355// If no record found
1356if ($num == 0)
1357{
1358	$colspan = 1;
1359	foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
1360	print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
1361}
1362
1363$db->free($resql);
1364
1365$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1366$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
1367print $hookmanager->resPrint;
1368
1369print "</table>";
1370print "</div>";
1371
1372print '</form>';
1373
1374// End of page
1375llxFooter();
1376$db->close();
1377