dolibarr 25.0.0-alpha
list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
6 * Copyright (C) 2014-2019 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
8 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
9 * Copyright (C) 2016-2018 Ferran Marcet <fmarcet@2byte.es>
10 * Copyright (C) 2019 Nicolas Zabouri <info@inovea-conseil.com>
11 * Copyright (C) 2021-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
12 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
13 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
14 * Copyright (C) 2024 Benjamin Falière <benjamin.faliere@altairis.fr>
15 * Copyright (C) 2025 Charlene Benke <charlene@patas-monkey.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29 */
30
37// Load Dolibarr environment
38require '../main.inc.php';
47require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/phone.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
50require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
51require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
52require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
53require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
54if (isModEnabled("category")) {
55 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
56}
57
58// Load translation files required by the page
59$langs->loadLangs(array('contracts', 'products', 'companies', 'compta'));
60
61$action = GETPOST('action', 'aZ09');
62$massaction = GETPOST('massaction', 'alpha');
63$show_files = GETPOSTINT('show_files');
64$confirm = GETPOST('confirm', 'alpha');
65$toselect = GETPOST('toselect', 'array:int');
66$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'contractlist'; // To manage different context of search
67$optioncss = GETPOST('optioncss', 'alpha');
68$mode = GETPOST('mode', 'alpha');
69
70$socid = GETPOSTINT('socid');
71
72$search_name = GETPOST('search_name', 'alpha');
73$search_phone = GETPOST('search_phone', 'alpha');
74$search_phone_mobile = GETPOST('search_phone_mobile', 'alpha');
75$search_email = GETPOST('search_email', 'alpha');
76$search_town = GETPOST('search_town', 'alpha');
77$search_zip = GETPOST('search_zip', 'alpha');
78$search_state = GETPOST("search_state", 'alpha');
79$search_country = GETPOST("search_country", 'aZ09');
80$search_type_thirdparty = GETPOST("search_type_thirdparty", 'intcomma');
81$search_contract = GETPOST('search_contract', 'alpha');
82$search_ref_customer = GETPOST('search_ref_customer', 'alpha');
83$search_ref_supplier = GETPOST('search_ref_supplier', 'alpha');
84$search_type = (GETPOSTISSET('search_type') ? GETPOSTINT('search_type') : -1);
85$search_all = GETPOST('search_all', 'alphanohtml');
86$search_status = GETPOST('search_status', 'alpha');
87$search_signed_status = GETPOST('search_signed_status', 'alpha');
88$search_note_public = GETPOST('search_note_public', 'alpha');
89$search_note_private = GETPOST('search_note_private', 'alpha');
90
91$search_user = GETPOST('search_user', 'intcomma');
92$search_sale = GETPOST('search_sale', 'intcomma');
93$search_product_category = GETPOST('search_product_category', 'intcomma');
94$search_dfmonth = GETPOSTINT('search_dfmonth');
95$search_dfyear = GETPOSTINT('search_dfyear');
96$search_op2df = GETPOST('search_op2df', 'alpha');
97$search_date_startday = GETPOSTINT('search_date_startday');
98$search_date_startmonth = GETPOSTINT('search_date_startmonth');
99$search_date_startyear = GETPOSTINT('search_date_startyear');
100$search_date_endday = GETPOSTINT('search_date_endday');
101$search_date_endmonth = GETPOSTINT('search_date_endmonth');
102$search_date_endyear = GETPOSTINT('search_date_endyear');
103$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
104$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
105$searchCategoryCustomerOperator = 0;
106if (GETPOSTISSET('formfilteraction')) {
107 $searchCategoryCustomerOperator = GETPOSTINT('search_category_customer_operator');
108} elseif (getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT')) {
109 $searchCategoryCustomerOperator = getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT');
110}
111$searchCategoryCustomerList = GETPOST('search_category_customer_list', 'array');
112
113$search_date_creation_startmonth = GETPOSTINT('search_date_creation_startmonth');
114$search_date_creation_startyear = GETPOSTINT('search_date_creation_startyear');
115$search_date_creation_startday = GETPOSTINT('search_date_creation_startday');
116$search_date_creation_start = dol_mktime(0, 0, 0, $search_date_creation_startmonth, $search_date_creation_startday, $search_date_creation_startyear); // Use tzserver
117$search_date_creation_endmonth = GETPOSTINT('search_date_creation_endmonth');
118$search_date_creation_endyear = GETPOSTINT('search_date_creation_endyear');
119$search_date_creation_endday = GETPOSTINT('search_date_creation_endday');
120$search_date_creation_end = dol_mktime(23, 59, 59, $search_date_creation_endmonth, $search_date_creation_endday, $search_date_creation_endyear); // Use tzserver
121
122$search_date_modif_startmonth = GETPOSTINT('search_date_modif_startmonth');
123$search_date_modif_startyear = GETPOSTINT('search_date_modif_startyear');
124$search_date_modif_startday = GETPOSTINT('search_date_modif_startday');
125$search_date_modif_start = dol_mktime(0, 0, 0, $search_date_modif_startmonth, $search_date_modif_startday, $search_date_modif_startyear); // Use tzserver
126$search_date_modif_endmonth = GETPOSTINT('search_date_modif_endmonth');
127$search_date_modif_endyear = GETPOSTINT('search_date_modif_endyear');
128$search_date_modif_endday = GETPOSTINT('search_date_modif_endday');
129$search_date_modif_end = dol_mktime(23, 59, 59, $search_date_modif_endmonth, $search_date_modif_endday, $search_date_modif_endyear); // Use tzserver
130
131// Load variable for pagination
132$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
133$sortfield = GETPOST('sortfield', 'aZ09comma');
134$sortorder = GETPOST('sortorder', 'aZ09comma');
135$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
136if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
137 // If $page is not defined, or '' or -1 or if we click on clear filters
138 $page = 0;
139}
140$offset = $limit * $page;
141$pageprev = $page - 1;
142$pagenext = $page + 1;
143if (!$sortfield) {
144 $sortfield = 'c.ref';
145}
146if (!$sortorder) {
147 $sortorder = 'DESC';
148}
149
150// Security check
151$id = GETPOSTINT('id');
152if ($user->socid > 0) {
153 $socid = $user->socid;
154}
155
156$hookmanager->initHooks(array('contractlist'));
157
158$result = restrictedArea($user, 'contrat', $id);
159
160$diroutputmassaction = $conf->contract->dir_output.'/temp/massgeneration/'.$user->id;
161
162if ($search_status == '') {
163 $search_status = 1;
164}
165
166// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
167$object = new Contrat($db);
168$staticcontratligne = new ContratLigne($db);
169
170// fetch optionals attributes and labels
171$extrafields->fetch_name_optionals_label($object->table_element);
172
173$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
174// List of fields to search into when doing a "search in all"
175$fieldstosearchall = array();
176foreach ($object->fields as $key => $val) {
177 if (!empty($val['searchall'])) {
178 $fieldstosearchall['c.'.$key] = $val['label'];
179 }
180}
181$fieldstosearchall["s.nom"] = "ThirdParty";
182if (empty($user->socid)) {
183 $fieldstosearchall["c.note_private"] = "NotePrivate";
184}
185$parameters = array('fieldstosearchall' => $fieldstosearchall);
186$reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
187if ($reshook > 0) {
188 $fieldstosearchall = $hookmanager->resArray['fieldstosearchall'];
189} elseif ($reshook == 0) {
190 if (!empty($hookmanager->resArray['fieldstosearchall'])) {
191 $fieldstosearchall = array_merge($fieldstosearchall, $hookmanager->resArray['fieldstosearchall']);
192 }
193}
194
195$arrayfields = array(
196 'c.ref' => array('label' => $langs->trans("Ref"), 'checked' => '1', 'position' => 10),
197 'c.ref_customer' => array('label' => $langs->trans("RefCustomer"), 'checked' => '1', 'position' => 12),
198 'c.ref_supplier' => array('label' => $langs->trans("RefSupplier"), 'checked' => '1', 'position' => 14),
199 'c.fk_contract_type' => array('label' => $langs->trans("ContractType"), 'checked' => '1', 'position' => 16),
200 's.nom' => array('label' => $langs->trans("ThirdParty"), 'checked' => '1', 'position' => 30),
201 's.town' => array('label' => $langs->trans("Town"), 'checked' => '0', 'position' => 31),
202 's.zip' => array('label' => $langs->trans("Zip"), 'checked' => '1', 'position' => 32),
203 'state.nom' => array('label' => $langs->trans("StateShort"), 'checked' => '0', 'position' => 33),
204 'country.code_iso' => array('label' => $langs->trans("Country"), 'checked' => '0', 'position' => 34),
205 's.phone' => array('label' => $langs->trans("Phone"), 'checked' => '1', 'position' => 100),
206 's.phone_mobile' => array('label' => $langs->trans("PhoneMobile"), 'checked' => '1', 'position' => 102),
207 's.email' => array('label' => $langs->trans("ThirdPartyEmail"), 'checked' => '0', 'position' => 115),
208 'sale_representative' => array('label' => $langs->trans("SaleRepresentativesOfThirdParty"), 'checked' => '-1', 'position' => 130),
209 'c.date_contrat' => array('label' => $langs->trans("DateContract"), 'checked' => '1', 'position' => 140),
210 'c.datec' => array('label' => $langs->trans("DateCreation"), 'checked' => '0', 'position' => 500),
211 'c.tms' => array('label' => $langs->trans("DateModificationShort"), 'checked' => '0', 'position' => 500),
212 'c.note_public' => array('label' => $langs->trans("NotePublic"), 'checked' => '0', 'position' => 520, 'enabled' => (string) (!getDolGlobalInt('MAIN_LIST_HIDE_PUBLIC_NOTES'))),
213 'c.note_private' => array('label' => $langs->trans("NotePrivate"), 'checked' => '0', 'position' => 521, 'enabled' => (string) (!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES'))),
214 'lower_planned_end_date' => array('label' => $langs->trans("LowerDateEndPlannedShort"), 'checked' => '1', 'position' => 900, 'help' => $langs->trans("LowerDateEndPlannedShort")),
215 'status' => array('label' => $langs->trans("Status"), 'checked' => '1', 'position' => 1000),
216 'c.signed_status' => array('label' => $langs->trans('SignedStatus'), 'checked' => '0', 'position' => 1001),
217);
218// Extra fields
219include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
220// Add hook to complete $arrayfield
221$parameters = array('arrayfields' => &$arrayfields);
222$reshook = $hookmanager->executeHooks('completeArrayFields', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
223
224$object->fields = dol_sort_array($object->fields, 'position');
225$arrayfields = dol_sort_array($arrayfields, 'position');
226
227if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
228 $search_sale = $user->id;
229}
230
231$permissiontoread = $user->hasRight('contrat', 'lire');
232$permissiontoadd = $user->hasRight('contrat', 'creer');
233$permissiontodelete = $user->hasRight('contrat', 'supprimer');
234
235$result = restrictedArea($user, 'contrat', 0);
236
237
238
239/*
240 * Actions
241 */
242
243if (GETPOST('cancel', 'alpha')) {
244 $action = 'list';
245 $massaction = '';
246}
247if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
248 $massaction = '';
249}
250
251$parameters = array('socid' => $socid, 'arrayfields' => &$arrayfields);
252$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
253if ($reshook < 0) {
254 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
255}
256
257include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
258// Purge search criteria
259if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
260 $search_dfmonth = '';
261 $search_dfyear = '';
262 $search_op2df = '';
263 $search_name = "";
264 $search_town = '';
265 $search_zip = "";
266 $search_state = "";
267 $search_country = '';
268 $search_phone = "";
269 $search_phone_mobile = "";
270 $search_email = "";
271 $search_type_thirdparty = '';
272 $search_contract = "";
273 $search_ref_customer = "";
274 $search_ref_supplier = "";
275 $search_type = -1;
276 $search_user = '';
277 $search_sale = '';
278 $search_product_category = '';
279 $search_date_startday = '';
280 $search_date_startmonth = '';
281 $search_date_startyear = '';
282 $search_date_endday = '';
283 $search_date_endmonth = '';
284 $search_date_endyear = '';
285 $search_date_start = '';
286 $search_date_end = '';
287 $search_all = "";
288 $search_date_creation_startmonth = "";
289 $search_date_creation_startyear = "";
290 $search_date_creation_startday = "";
291 $search_date_creation_start = "";
292 $search_date_creation_endmonth = "";
293 $search_date_creation_endyear = "";
294 $search_date_creation_endday = "";
295 $search_date_creation_end = "";
296 $search_date_modif_startmonth = "";
297 $search_date_modif_startyear = "";
298 $search_date_modif_startday = "";
299 $search_date_modif_start = "";
300 $search_date_modif_endmonth = "";
301 $search_date_modif_endyear = "";
302 $search_date_modif_endday = "";
303 $search_date_modif_end = "";
304 $search_status = "";
305 $search_signed_status = '';
306 $search_note_public = "";
307 $search_note_private = "";
308 $toselect = array();
309 $searchCategoryCustomerList = array();
310 $search_array_options = array();
311}
312
313if (empty($reshook)) {
314 $objectclass = 'Contrat';
315 $objectlabel = 'Contracts';
316 $uploaddir = $conf->contract->dir_output;
317 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
318}
319
320
321/*
322 * View
323 */
324
325$form = new Form($db);
326$formfile = new FormFile($db);
327$formother = new FormOther($db);
328$socstatic = new Societe($db);
329$formcompany = new FormCompany($db);
330$contracttmp = new Contrat($db);
331
332$now = dol_now();
333
334$title = "";
335
336$sql = 'SELECT';
337$sql .= " c.rowid, c.ref, c.datec as date_creation, c.tms as date_modification, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.fk_contract_type, c.note_private, c.note_public, c.entity, c.signed_status,";
338$sql .= ' s.rowid as socid, s.nom as name, s.name_alias, s.email, s.town, s.zip, s.fk_pays as country_id, s.phone, s.phone_mobile, s.client, s.code_client, s.status as company_status, s.logo as company_logo,';
339$sql .= " typent.code as typent_code, c.note_public, c.note_private,";
340$sql .= " state.code_departement as state_code, state.nom as state_name,";
341// TODO Add a denormalized field "denormalized_lower_planned_end_date" so we can remove this subrequests ?
342if ($arrayfields['lower_planned_end_date']['checked'] || ($search_dfyear > 0 && $search_op2df)) {
343 $sql .= " (SELECT MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") FROM ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid) as lower_planned_end_date,"; // lowest expiration date among open service lines
344}
345$sql .= " (SELECT SUM(".$db->ifsql("cd.statut=0", '1', '0').') FROM '.MAIN_DB_PREFIX.'contratdet as cd WHERE cd.fk_contrat = c.rowid) as nb_initial,';
346$sql .= " (SELECT SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", '1', '0').') FROM '.MAIN_DB_PREFIX.'contratdet as cd WHERE cd.fk_contrat = c.rowid) as nb_running,';
347$sql .= " (SELECT SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", '1', '0').') FROM '.MAIN_DB_PREFIX.'contratdet as cd WHERE cd.fk_contrat = c.rowid) as nb_expired,';
348$sql .= " (SELECT SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contract->services->expires->warning_delay)."')", '1', '0').') FROM '.MAIN_DB_PREFIX.'contratdet as cd WHERE cd.fk_contrat = c.rowid) as nb_late,';
349$sql .= " (SELECT SUM(".$db->ifsql("cd.statut=5", '1', '0').') FROM '.MAIN_DB_PREFIX.'contratdet as cd WHERE cd.fk_contrat = c.rowid) as nb_closed';
350// Add fields from extrafields
351if (!empty($extrafields->attributes[$object->table_element]['label'])) {
352 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
353 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
354 }
355}
356// Add fields from hooks
357$parameters = array();
358$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
359$sql .= $hookmanager->resPrint;
360$sql = preg_replace('/,\s*$/', '', $sql);
361
362$sqlfields = $sql; // $sql fields to remove for count total
363
364$sql .= " FROM ".MAIN_DB_PREFIX."contrat as c";
365$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (c.fk_soc = s.rowid)";
366$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
367$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
368$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
369if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
370 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (c.rowid = ef.fk_object)";
371}
372if ($search_user > 0) {
373 $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
374 $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
375}
376// Add table from hooks
377$parameters = array();
378$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
379$sql .= $hookmanager->resPrint;
380$sql .= " WHERE c.entity IN (".getEntity('contract').")";
381if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
382 $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
383}
384if ($socid > 0) {
385 $sql .= " AND s.rowid = ".((int) $socid);
386}
387if ($search_date_start) {
388 $sql .= " AND c.date_contrat >= '".$db->idate($search_date_start)."'";
389}
390if ($search_date_end) {
391 $sql .= " AND c.date_contrat <= '".$db->idate($search_date_end)."'";
392}
393if ($search_name) {
394 $sql .= natural_search('s.nom', $search_name);
395}
396if ($search_email) {
397 $sql .= natural_search('s.email', $search_email);
398}
399if ($search_phone) {
400 $sql .= dol_natural_search_phone($db, array('s.phone', 's.phone_mobile'), $search_phone);
401}
402if ($search_phone_mobile) {
403 $sql .= dol_natural_search_phone($db, array('s.phone', 's.phone_mobile'), $search_phone_mobile);
404}
405if ($search_contract) {
406 $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
407}
408if (!empty($search_ref_customer)) {
409 $sql .= natural_search(array('c.ref_customer'), $search_ref_customer);
410}
411if (!empty($search_ref_supplier)) {
412 $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
413}
414if ($search_type >= 0) {
415 $sql .= " AND c.fk_contract_type = ".((int) $search_type);
416}
417if ($search_zip) {
418 $sql .= natural_search(array('s.zip'), $search_zip);
419}
420if ($search_town) {
421 $sql .= natural_search(array('s.town'), $search_town);
422}
423if ($search_state) {
424 $sql .= natural_search(array('state.nom'), $search_state);
425}
426if ($search_country && $search_country != '-1') {
427 $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
428}
429if (!empty($search_note_private)) {
430 $sql .= natural_search(array('c.note_private'), $search_note_private);
431}
432if (!empty($search_note_public)) {
433 $sql .= natural_search(array('c.note_public'), $search_note_public);
434}
435
436/*if ($search_sale > 0) {
437 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
438}*/
439if ($search_all) {
440 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
441}
442if ($search_user > 0) {
443 $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".((int) $search_user);
444}
445// Search on sale representative
446if ($search_sale && $search_sale != '-1') {
447 if ($search_sale == -2) {
448 $sql .= " AND ".getSalesRepresentativeSqlFilter('c.fk_soc', 0, 1);
449 } elseif ($search_sale > 0) {
450 $sql .= " AND ".getSalesRepresentativeSqlFilter('c.fk_soc', (int) $search_sale);
451 }
452}
453// Search for tag/category ($searchCategoryProductList is an array of ID)
454$searchCategoryProductOperator = GETPOSTINT('search_category_product_operator');
455$searchCategoryProductList = array($search_product_category);
456if (!empty($searchCategoryProductList)) {
457 $searchCategoryProductSqlList = array();
458 $listofcategoryid = '';
459 foreach ($searchCategoryProductList as $searchCategoryProduct) {
460 if (intval($searchCategoryProduct) == -2) {
461 $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product)";
462 } elseif (intval($searchCategoryProduct) > 0) {
463 if ($searchCategoryProductOperator == 0) {
464 $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
465 } else {
466 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
467 }
468 }
469 }
470 if ($listofcategoryid) {
471 $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
472 }
473 if ($searchCategoryProductOperator == 1) {
474 if (!empty($searchCategoryProductSqlList)) {
475 $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
476 }
477 } else {
478 if (!empty($searchCategoryProductSqlList)) {
479 $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
480 }
481 }
482}
483$searchCategoryCustomerSqlList = array();
484if ($searchCategoryCustomerOperator == 1) {
485 $existsCategoryCustomerList = array();
486 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
487 if (intval($searchCategoryCustomer) == -2) {
488 $sqlCategoryCustomerNotExists = " NOT EXISTS (";
489 $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
490 $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
491 $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid";
492 $sqlCategoryCustomerNotExists .= " )";
493 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
494 } elseif (intval($searchCategoryCustomer) > 0) {
495 $existsCategoryCustomerList[] = $db->escape($searchCategoryCustomer);
496 }
497 }
498 if (!empty($existsCategoryCustomerList)) {
499 $sqlCategoryCustomerExists = " EXISTS (";
500 $sqlCategoryCustomerExists .= " SELECT cat_cus.fk_soc";
501 $sqlCategoryCustomerExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
502 $sqlCategoryCustomerExists .= " WHERE cat_cus.fk_soc = s.rowid";
503 $sqlCategoryCustomerExists .= " AND cat_cus.fk_categorie IN (".$db->sanitize(implode(',', $existsCategoryCustomerList)).")";
504 $sqlCategoryCustomerExists .= " )";
505 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerExists;
506 }
507 if (!empty($searchCategoryCustomerSqlList)) {
508 $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
509 }
510} else {
511 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
512 if (intval($searchCategoryCustomer) == -2) {
513 $sqlCategoryCustomerNotExists = " NOT EXISTS (";
514 $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
515 $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
516 $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid";
517 $sqlCategoryCustomerNotExists .= " )";
518 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
519 } elseif (intval($searchCategoryCustomer) > 0) {
520 $searchCategoryCustomerSqlList[] = "s.rowid IN (SELECT fk_soc FROM ".$db->prefix()."categorie_societe WHERE fk_categorie = ".((int) $searchCategoryCustomer).")";
521 }
522 }
523 if (!empty($searchCategoryCustomerSqlList)) {
524 $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
525 }
526}
527
528if ($search_date_creation_start) {
529 $sql .= " AND c.datec >= '".$db->idate($search_date_creation_start)."'";
530}
531if ($search_date_creation_end) {
532 $sql .= " AND c.datec <= '".$db->idate($search_date_creation_end)."'";
533}
534
535if ($search_date_modif_start) {
536 $sql .= " AND c.tms >= '".$db->idate($search_date_modif_start)."'";
537}
538if ($search_date_modif_end) {
539 $sql .= " AND c.tms <= '".$db->idate($search_date_modif_end)."'";
540}
541if ($search_signed_status != '' && $search_signed_status >= 0) {
542 $sql .= " AND c.signed_status = ".((int) $search_signed_status);
543}
544
545// Add where from extra fields
546include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
547// Add where from hooks
548$parameters = array();
549$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
550$sql .= $hookmanager->resPrint;
551// Add where from hooks
552$parameters = array('search_dfyear' => $search_dfyear, 'search_op2df' => $search_op2df);
553$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
554$sql .= $hookmanager->resPrint;
555// Add HAVING from hooks
556$parameters = array('search_dfyear' => $search_dfyear, 'search_op2df' => $search_op2df);
557$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
558if (empty($reshook)) {
559 if ($search_dfyear > 0 && $search_op2df) {
560 if ($search_op2df == '<=') {
561 //$sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."'";
562 $sql .= " HAVING lower_planned_end_date <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."'";
563 } elseif ($search_op2df == '>=') {
564 //$sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
565 $sql .= " HAVING lower_planned_end_date >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
566 } else {
567 //$sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
568 $sql .= " HAVING lower_planned_end_date <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."' AND lower_planned_end_date >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
569 }
570 $sql .= empty($hookmanager->resPrint) ? "" : " AND ".$hookmanager->resPrint;
571 } else {
572 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
573 }
574} else {
575 $sql = $hookmanager->resPrint;
576}
577
578// Count total nb of records
579$nbtotalofrecords = '';
580if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
581 //$result = $db->query($sql);
582 //$nbtotalofrecords = $db->num_rows($result);
583
584 if ($search_dfyear > 0 && $search_op2df) {
585 $resql = $db->query($sql, 0, 'auto', 1);
586 if ($resql) {
587 while ($db->fetch_object($resql)) {
588 if (empty($nbtotalofrecords)) {
589 $nbtotalofrecords = 1; // We can't make +1 because init value is ''
590 } else {
591 $nbtotalofrecords++;
592 }
593 }
594 } else {
595 dol_print_error($db);
596 }
597 } else {
598 /* The fast and low memory method to get and count full list converts the sql into a sql count */
599 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
600
601 $sqlforcount = str_replace('LEFT JOIN '.MAIN_DB_PREFIX.'c_country as country on (country.rowid = s.fk_pays)', '', $sqlforcount);
602 $sqlforcount = str_replace('LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as typent on (typent.id = s.fk_typent)', '', $sqlforcount);
603 if (!$search_state) { // The join is required by the filter on the state name
604 $sqlforcount = str_replace('LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as state on (state.rowid = s.fk_departement)', '', $sqlforcount);
605 }
606 $sqlforcount = str_replace('LEFT JOIN '.MAIN_DB_PREFIX.'contratdet as cd ON c.rowid = cd.fk_contrat', '', $sqlforcount);
607 //$sqlforcount = str_replace('LEFT JOIN '.MAIN_DB_PREFIX.'contrat_extrafields as ef on (c.rowid = ef.fk_object)', '', $sqlforcount); // We my need this if there is filters on extrafields
608 $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount);
609
610 $resql = $db->query($sqlforcount);
611 if ($resql) {
612 $objforcount = $db->fetch_object($resql);
613 $nbtotalofrecords = $objforcount->nbtotalofrecords;
614 } else {
615 dol_print_error($db);
616 }
617 }
618
619 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
620 $page = 0;
621 $offset = 0;
622 }
623 $db->free($resql);
624}
625
626// Complete request and execute it with limit
627$sql .= $db->order($sortfield, $sortorder);
628if ($limit) {
629 $sql .= $db->plimit($limit + 1, $offset);
630}
631
632$resql = $db->query($sql);
633if (!$resql) {
634 dol_print_error($db);
635 exit;
636}
637
638$num = $db->num_rows($resql);
639
640// Direct jump if only one record found
641if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
642 $obj = $db->fetch_object($resql);
643 $id = $obj->rowid;
644 header("Location: ".DOL_URL_ROOT.'/contrat/card.php?id='.$id);
645 exit;
646}
647
648
649// Output page
650// --------------------------------------------------------------------
651$title = $langs->trans("Contracts");
652$help_url = 'EN:Module_Contracts|FR:Module_Contrat|ES:Contratos_de_servicio';
653
654llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-contrat page-list bodyforlist');
655
656$i = 0;
657
658$arrayofselected = is_array($toselect) ? $toselect : array();
659
660if ($socid > 0) {
661 $soc = new Societe($db);
662 $soc->fetch($socid);
663 if (empty($search_name)) {
664 $search_name = $soc->name;
665 }
666}
667
668$param = '';
669if (!empty($mode)) {
670 $param .= '&mode='.urlencode($mode);
671}
672if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
673 $param .= '&contextpage='.urlencode($contextpage);
674}
675if ($limit > 0 && $limit != $conf->liste_limit) {
676 $param .= '&limit='.((int) $limit);
677}
678if ($search_all != '') {
679 $param .= '&search_all='.urlencode($search_all);
680}
681if ($search_contract != '') {
682 $param .= '&search_contract='.urlencode($search_contract);
683}
684if ($search_name != '') {
685 $param .= '&search_name='.urlencode($search_name);
686}
687if ($search_phone != '') {
688 $param .= '&search_phone='.urlencode($search_phone);
689}
690if ($search_phone_mobile != '') {
691 $param .= '&search_phone_mobile='.urlencode($search_phone_mobile);
692}
693if ($search_email != '') {
694 $param .= '&search_email='.urlencode($search_email);
695}
696if ($search_ref_customer != '') {
697 $param .= '&search_ref_customer='.urlencode($search_ref_customer);
698}
699if ($search_ref_supplier != '') {
700 $param .= '&search_ref_supplier='.urlencode($search_ref_supplier);
701}
702if ($search_type >= 0) {
703 $param .= '&search_type='.$search_type;
704}
705if ($search_note_private != '') {
706 $param .= '&search_note_private='.urlencode($search_note_private);
707}
708if ($search_note_public != '') {
709 $param .= '&search_note_public='.urlencode($search_note_public);
710}
711if ($search_op2df != '') {
712 $param .= '&search_op2df='.urlencode($search_op2df);
713}
714if ($search_date_creation_startmonth) {
715 $param .= '&search_date_creation_startmonth='.urlencode((string) ($search_date_creation_startmonth));
716}
717if ($search_date_creation_startyear) {
718 $param .= '&search_date_creation_startyear='.urlencode((string) ($search_date_creation_startyear));
719}
720if ($search_date_creation_startday) {
721 $param .= '&search_date_creation_startday='.urlencode((string) ($search_date_creation_startday));
722}
723if ($search_date_creation_start) {
724 $param .= '&search_date_creation_start='.urlencode((string) $search_date_creation_start);
725}
726if ($search_date_creation_endmonth) {
727 $param .= '&search_date_creation_endmonth='.urlencode((string) ($search_date_creation_endmonth));
728}
729if ($search_date_creation_endyear) {
730 $param .= '&search_date_creation_endyear='.urlencode((string) ($search_date_creation_endyear));
731}
732if ($search_date_creation_endday) {
733 $param .= '&search_date_creation_endday='.urlencode((string) ($search_date_creation_endday));
734}
735if ($search_date_creation_end) {
736 $param .= '&search_date_creation_end='.urlencode((string) $search_date_creation_end);
737}
738if ($search_date_modif_startmonth) {
739 $param .= '&search_date_modif_startmonth='.urlencode((string) ($search_date_modif_startmonth));
740}
741if ($search_date_modif_startyear) {
742 $param .= '&search_date_modif_startyear='.urlencode((string) ($search_date_modif_startyear));
743}
744if ($search_date_modif_startday) {
745 $param .= '&search_date_modif_startday='.urlencode((string) ($search_date_modif_startday));
746}
747if ($search_date_modif_start) {
748 $param .= '&search_date_modif_start='.urlencode((string) $search_date_modif_start);
749}
750if ($search_date_modif_endmonth) {
751 $param .= '&search_date_modif_endmonth='.urlencode((string) ($search_date_modif_endmonth));
752}
753if ($search_date_modif_endyear) {
754 $param .= '&search_date_modif_endyear='.urlencode((string) ($search_date_modif_endyear));
755}
756if ($search_date_modif_endday) {
757 $param .= '&search_date_modif_endday='.urlencode((string) ($search_date_modif_endday));
758}
759if ($search_date_modif_end) {
760 $param .= '&search_date_modif_end=' . urlencode((string) $search_date_modif_end);
761}
762if ($search_date_startday > 0) {
763 $param .= '&search_date_startday='.urlencode((string) ($search_date_startday));
764}
765if ($search_date_startmonth > 0) {
766 $param .= '&search_date_startmonth='.urlencode((string) ($search_date_startmonth));
767}
768if ($search_date_startyear > 0) {
769 $param .= '&search_date_startyear='.urlencode((string) ($search_date_startyear));
770}
771if ($search_date_endday > 0) {
772 $param .= '&search_date_endday='.urlencode((string) ($search_date_endday));
773}
774if ($search_date_endmonth > 0) {
775 $param .= '&search_date_endmonth='.urlencode((string) ($search_date_endmonth));
776}
777if ($search_date_endyear > 0) {
778 $param .= '&search_date_endyear='.urlencode((string) ($search_date_endyear));
779}
780if ($search_dfyear > 0) {
781 $param .= '&search_dfyear='.urlencode((string) ($search_dfyear));
782}
783if ($search_dfmonth > 0) {
784 $param .= '&search_dfmonth='.urlencode((string) ($search_dfmonth));
785}
786if ($search_signed_status != '' && $search_signed_status >= 0) {
787 $param .= '&search_signed_status='.urlencode($search_signed_status);
788}
789if ($search_sale > 0) {
790 $param .= '&search_sale='.urlencode($search_sale);
791}
792if ($search_user > 0) {
793 $param .= '&search_user='.urlencode((string) ($search_user));
794}
795if ($search_type_thirdparty > 0) {
796 $param .= '&search_type_thirdparty='.urlencode((string) ($search_type_thirdparty));
797}
798if ($search_town != '') {
799 $param .= '&search_town='.urlencode($search_town);
800}
801if ($search_zip != '') {
802 $param .= '&search_zip='.urlencode($search_zip);
803}
804if ($search_state != '') {
805 $param .= '&search_state='.urlencode($search_state);
806}
807if ($search_country != '') {
808 $param .= "&search_country=".urlencode($search_country);
809}
810if ($search_product_category > 0) {
811 $param .= '&search_product_category='.urlencode((string) ($search_product_category));
812}
813if ($show_files) {
814 $param .= '&show_files='.urlencode((string) ($show_files));
815}
816if ($optioncss != '') {
817 $param .= '&optioncss='.urlencode($optioncss);
818}
819foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
820 $param .= "&search_category_customer_list[]=".urlencode($searchCategoryCustomer);
821}
822// Add $param from extra fields
823include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
824
825// List of mass actions available
826$arrayofmassactions = array(
827 'generate_doc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
828 'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
829 'presend' => img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
830);
831if (!empty($permissiontodelete)) {
832 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
833}
834if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
835 $arrayofmassactions = array();
836}
837$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
838
839$url = DOL_URL_ROOT.'/contrat/card.php?action=create';
840if (!empty($socid)) {
841 $url .= '&socid='.((int) $socid);
842}
843$newcardbutton = '';
844$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
845$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
846$newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.'/contrat/stats/index.php?'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', ($mode == 'statistics' ? 2 : 1), array('morecss' => 'reposition'));
847$newcardbutton .= dolGetButtonTitleSeparator();
848$newcardbutton .= dolGetButtonTitle($langs->trans('NewContractSubscription'), '', 'fa fa-plus-circle', $url, '', $user->hasRight('contrat', 'creer'));
849
850print '<form method="POST" id="searchFormList" action="'.$_SERVER['PHP_SELF'].'">'."\n";
851if ($optioncss != '') {
852 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
853}
854print '<input type="hidden" name="token" value="'.newToken().'">';
855print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
856print '<input type="hidden" name="action" value="list">';
857print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
858print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
859print '<input type="hidden" name="page" value="'.$page.'">';
860print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
861print '<input type="hidden" name="page_y" value="">';
862print '<input type="hidden" name="mode" value="'.$mode.'">';
863
864// @phan-suppress-next-line PhanPluginSuspiciousParamOrder
865print_barre_liste($langs->trans("Contracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, $newcardbutton, '', $limit, 0, 0, 1);
866
867$topicmail = "SendContractRef";
868$modelmail = "contract";
869$objecttmp = new Contrat($db);
870$trackid = 'con'.$object->id;
871include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
872
873if ($search_all) {
874 $setupstring = '';
875 foreach ($fieldstosearchall as $key => $val) {
876 $fieldstosearchall[$key] = $langs->trans($val);
877 $setupstring .= $key."=".$val.";";
878 }
879 print '<!-- Search done like if CONTRACT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
880 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
881}
882
883$moreforfilter = '';
884
885// If the user can view prospects other than his'
886if ($user->hasRight('user', 'user', 'lire')) {
887 $langs->load("commercial");
888 $moreforfilter .= '<div class="divsearchfield">';
889 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
890 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'widthcentpercentminusx maxwidth300');
891 $moreforfilter .= '</div>';
892}
893// If the user can view other users
894if ($user->hasRight('user', 'user', 'lire')) {
895 $moreforfilter .= '<div class="divsearchfield">';
896 $tmptitle = $langs->trans('LinkedToSpecificUsers');
897 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, null, 0, '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
898 $moreforfilter .= '</div>';
899}
900// If the user can view categories of products
901if (isModEnabled('category') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
902 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
903 $moreforfilter .= '<div class="divsearchfield">';
904 $tmptitle = $langs->trans('IncludingProductWithTag');
905 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 2);
906 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, '', 'widthcentpercentminusx maxwidth300', 1);
907 $moreforfilter .= '</div>';
908}
909// Filter on customer categories
910if (getDolGlobalString('MAIN_SEARCH_CATEGORY_CUSTOMER_ON_CONTRACT_LIST') && isModEnabled("category") && $user->hasRight('categorie', 'lire')) {
911 $moreforfilter .= '<div class="divsearchfield">';
912 $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort');
913 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
914 $categoriesArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 2);
915 $categoriesArr[-2] = '- '.$langs->trans('NotCategorized').' -';
916 $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle);
917 $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_customer_operator" name="search_category_customer_operator" value="1"'.($searchCategoryCustomerOperator == 1 ? ' checked="checked"' : '').'/>';
918 $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click
919 $moreforfilter .= '</div>';
920}
921
922$parameters = array();
923$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
924if (empty($reshook)) {
925 $moreforfilter .= $hookmanager->resPrint;
926} else {
927 $moreforfilter = $hookmanager->resPrint;
928}
929
930if (!empty($moreforfilter)) {
931 print '<div class="liste_titre liste_titre_bydiv centpercent">';
932 print $moreforfilter;
933 print '</div>';
934}
935
936$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
937$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields
938if ($massactionbutton) {
939 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
940}
941
942print '<div class="div-table-responsive">';
943print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
944
945// Fields title search
946// --------------------------------------------------------------------
947print '<tr class="liste_titre_filter">';
948// Action column
949if ($conf->main_checkbox_left_column) {
950 print '<td class="liste_titre maxwidthsearch center">';
951 $searchpicto = $form->showFilterButtons('left');
952 print $searchpicto;
953 print '</td>';
954}
955if (!empty($arrayfields['c.ref']['checked'])) {
956 print '<td class="liste_titre">';
957 print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
958 print '</td>';
959}
960if (!empty($arrayfields['c.ref_customer']['checked'])) {
961 print '<td class="liste_titre">';
962 print '<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
963 print '</td>';
964}
965if (!empty($arrayfields['c.ref_supplier']['checked'])) {
966 print '<td class="liste_titre">';
967 print '<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'">';
968 print '</td>';
969}
970if (!empty($arrayfields['c.fk_contract_type']['checked'])) {
971 print '<td class="liste_titre">';
972 print $form->selectarray('search_type', array('-1' => '', '0' => $langs->trans('CustomerContract'), '1' => $langs->trans('SupplierContract')), $search_type, 0, 0, 0, '', 0, 0, 0, '', 'flat maxwidth100');
973 print '</td>';
974}
975if (!empty($arrayfields['s.nom']['checked'])) {
976 print '<td class="liste_titre">';
977 print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'"'.($user->socid > 0 ? " disabled" : "").'>';
978 print '</td>';
979}
980// Town
981if (!empty($arrayfields['s.town']['checked'])) {
982 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
983}
984// Zip
985if (!empty($arrayfields['s.zip']['checked'])) {
986 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
987}
988// State
989if (!empty($arrayfields['state.nom']['checked'])) {
990 print '<td class="liste_titre">';
991 print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
992 print '</td>';
993}
994// Country
995if (!empty($arrayfields['country.code_iso']['checked'])) {
996 print '<td class="liste_titre center">';
997 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
998 print '</td>';
999}
1000// Phone
1001if (!empty($arrayfields['s.phone']['checked'])) {
1002 print '<td class="liste_titre">';
1003 print '<input type="text" class="flat width50" name="search_phone" value="'.dol_escape_htmltag($search_phone).'">';
1004 print '</td>';
1005}
1006// Phone mobile
1007if (!empty($arrayfields['s.phone_mobile']['checked'])) {
1008 print '<td class="liste_titre">';
1009 print '<input type="text" class="flat width50" name="search_phone_mobile" value="'.dol_escape_htmltag($search_phone_mobile).'">';
1010 print '</td>';
1011}
1012// Email
1013if (!empty($arrayfields['s.email']['checked'])) {
1014 print '<td class="liste_titre">';
1015 print '<input type="text" class="flat width75" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
1016 print '</td>';
1017}
1018// Company type
1019if (!empty($arrayfields['typent.code']['checked'])) {
1020 print '<td class="liste_titre maxwidthonsmartphone center">';
1021 print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, getDolGlobalString('SOCIETE_SORT_ON_TYPEENT', 'ASC'), '', 1);
1022 print '</td>';
1023}
1024if (!empty($arrayfields['sale_representative']['checked'])) {
1025 print '<td class="liste_titre"></td>';
1026}
1027if (!empty($arrayfields['c.date_contrat']['checked'])) {
1028 print '<td class="liste_titre center">';
1029 print '<div class="nowrapfordate">';
1030 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1031 print '</div>';
1032 print '<div class="nowrapfordate">';
1033 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1034 print '</div>';
1035 print '</td>';
1036}
1037// Signed status
1038if (!empty($arrayfields['c.signed_status']['checked'])) {
1039 print '<td class="liste_titre center">';
1040 $list_signed_status = $object->getSignedStatusLocalisedArray();
1041 print $form->selectarray('search_signed_status', $list_signed_status, $search_signed_status, 1, 0, 0, '', 1, 0, 0, '', 'search_status');
1042 print '</td>';
1043}
1044// Public note
1045if (!empty($arrayfields['c.note_public']['checked'])) {
1046 print '<td class="liste_titre center">';
1047 print '<input class="flat" size="10" type="text" name="search_note_public" value="'.dol_escape_htmltag($search_note_public).'">';
1048 print '</td>';
1049}
1050// Private note
1051if (!empty($arrayfields['c.note_private']['checked'])) {
1052 print '<td class="liste_titre center">';
1053 print '<input class="flat" size="10" type="text" name="search_note_private" value="'.dol_escape_htmltag($search_note_private).'">';
1054 print '</td>';
1055}
1056// Extra fields
1057include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1058
1059// Fields from hook
1060$parameters = array('arrayfields' => $arrayfields);
1061$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1062print $hookmanager->resPrint;
1063// Creation date
1064if (!empty($arrayfields['c.datec']['checked'])) {
1065 print '<td class="liste_titre center nowraponall">';
1066 print '<div class="nowrapfordate">';
1067 print $form->selectDate($search_date_creation_start ? $search_date_creation_start : -1, 'search_date_creation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1068 print '</div>';
1069 print '<div class="nowrapfordate">';
1070 print $form->selectDate($search_date_creation_end ? $search_date_creation_end : -1, 'search_date_creation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1071 print '</div>';
1072 print '</td>';
1073}
1074// Modification date
1075if (!empty($arrayfields['c.tms']['checked'])) {
1076 print '<td class="liste_titre center nowraponall">';
1077 print '<div class="nowrapfordate">';
1078 print $form->selectDate($search_date_modif_start ? $search_date_modif_start : -1, 'search_date_modif_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1079 print '</div>';
1080 print '<div class="nowrapfordate">';
1081 print $form->selectDate($search_date_modif_end ? $search_date_modif_end : -1, 'search_date_modif_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1082 print '</div>';
1083 print '</td>';
1084}
1085// First end date
1086if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
1087 print '<td class="liste_titre nowraponall center">';
1088 $arrayofoperators = array('0' => '', '=' => '=', '<=' => '<=', '>=' => '>=');
1089 print $form->selectarray('search_op2df', $arrayofoperators, $search_op2df, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth50imp');
1090 print '<br>';
1091 print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0);
1092 print ' ';
1093 print $formother->selectyear($search_dfyear, 'search_dfyear', 1, 20, 5, 0, 0, '');
1094 print '</td>';
1095}
1096// Status
1097if (!empty($arrayfields['status']['checked'])) {
1098 print '<td class="liste_titre right" colspan="4"></td>';
1099}
1100
1101// Action column
1102if (!$conf->main_checkbox_left_column) {
1103 print '<td class="liste_titre center">';
1104 $searchpicto = $form->showFilterButtons();
1105 print $searchpicto;
1106 print '</td>';
1107}
1108print '</tr>'."\n";
1109
1110$totalarray = array();
1111$totalarray['nbfield'] = 0;
1112
1113// Fields title label
1114// --------------------------------------------------------------------
1115print '<tr class="liste_titre">';
1116if ($conf->main_checkbox_left_column) {
1117 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1118 $totalarray['nbfield']++; // For the column action
1119}
1120if (!empty($arrayfields['c.ref']['checked'])) {
1121 // False positive @phan-suppress-next-line PhanTypeInvalidDimOffset
1122 print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);
1123 $totalarray['nbfield']++; // For the column action
1124}
1125if (!empty($arrayfields['c.ref_customer']['checked'])) {
1126 print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer", "", $param, '', $sortfield, $sortorder);
1127 $totalarray['nbfield']++; // For the column action
1128}
1129if (!empty($arrayfields['c.ref_supplier']['checked'])) {
1130 print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier", "", $param, '', $sortfield, $sortorder);
1131 $totalarray['nbfield']++; // For the column action
1132}
1133if (!empty($arrayfields['c.fk_contract_type']['checked'])) {
1134 print_liste_field_titre($arrayfields['c.fk_contract_type']['label'], $_SERVER["PHP_SELF"], "c.fk_contract_type", "", $param, '', $sortfield, $sortorder);
1135 $totalarray['nbfield']++;
1136}
1137if (!empty($arrayfields['s.nom']['checked'])) {
1138 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
1139 $totalarray['nbfield']++; // For the column action
1140}
1141if (!empty($arrayfields['s.town']['checked'])) {
1142 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1143 $totalarray['nbfield']++; // For the column action
1144}
1145if (!empty($arrayfields['s.zip']['checked'])) {
1146 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1147 $totalarray['nbfield']++; // For the column action
1148}
1149if (!empty($arrayfields['state.nom']['checked'])) {
1150 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1151 $totalarray['nbfield']++; // For the column action
1152}
1153if (!empty($arrayfields['country.code_iso']['checked'])) {
1154 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1155 $totalarray['nbfield']++; // For the column action
1156}
1157if (!empty($arrayfields['s.phone']['checked'])) {
1158 print_liste_field_titre($arrayfields['s.phone']['label'], $_SERVER["PHP_SELF"], "s.phone", "", $param, '', $sortfield, $sortorder);
1159 $totalarray['nbfield']++; // For the column action
1160}
1161if (!empty($arrayfields['s.phone_mobile']['checked'])) {
1162 print_liste_field_titre($arrayfields['s.phone_mobile']['label'], $_SERVER["PHP_SELF"], "s.phone_mobile", "", $param, '', $sortfield, $sortorder);
1163 $totalarray['nbfield']++; // For the column action
1164}
1165if (!empty($arrayfields['s.email']['checked'])) {
1166 print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder);
1167 $totalarray['nbfield']++; // For the column action
1168}
1169if (!empty($arrayfields['typent.code']['checked'])) {
1170 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1171 $totalarray['nbfield']++; // For the column action
1172}
1173if (!empty($arrayfields['sale_representative']['checked'])) {
1174 print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
1175 $totalarray['nbfield']++; // For the column action
1176}
1177if (!empty($arrayfields['c.date_contrat']['checked'])) {
1178 print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat", "", $param, '', $sortfield, $sortorder, 'center ');
1179 $totalarray['nbfield']++; // For the column action
1180}
1181if (!empty($arrayfields['c.signed_status']['checked'])) {
1182 print_liste_field_titre($arrayfields['c.signed_status']['label'], $_SERVER["PHP_SELF"], "c.signed_status", "", $param, '', $sortfield, $sortorder, 'center ');
1183 $totalarray['nbfield']++;
1184}
1185if (!empty($arrayfields['c.note_public']['checked'])) {
1186 print_liste_field_titre($arrayfields['c.note_public']['label'], $_SERVER["PHP_SELF"], "c.note_public", "", $param, '', $sortfield, $sortorder, 'center ');
1187 $totalarray['nbfield']++;
1188}
1189if (!empty($arrayfields['c.note_private']['checked'])) {
1190 print_liste_field_titre($arrayfields['c.note_private']['label'], $_SERVER["PHP_SELF"], "c.note_private", "", $param, '', $sortfield, $sortorder, 'center ');
1191 $totalarray['nbfield']++;
1192}
1193// Extra fields
1194include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1195// Hook fields
1196$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
1197$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1198print $hookmanager->resPrint;
1199if (!empty($arrayfields['c.datec']['checked'])) {
1200 print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1201 $totalarray['nbfield']++; // For the column action
1202}
1203if (!empty($arrayfields['c.tms']['checked'])) {
1204 print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1205 $totalarray['nbfield']++; // For the column action
1206}
1207if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
1208 print_liste_field_titre($arrayfields['lower_planned_end_date']['label'], $_SERVER["PHP_SELF"], "lower_planned_end_date", "", $param, '', $sortfield, $sortorder, 'center ');
1209 $totalarray['nbfield']++; // For the column action
1210}
1211if (!empty($arrayfields['status']['checked'])) {
1212 print_liste_field_titre($staticcontratligne->LibStatut(0, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1213 $totalarray['nbfield']++; // For the column action
1214 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 0, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1215 $totalarray['nbfield']++; // For the column action
1216 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1217 $totalarray['nbfield']++; // For the column action
1218 print_liste_field_titre($staticcontratligne->LibStatut(5, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1219 $totalarray['nbfield']++; // For the column action
1220}
1221if (!$conf->main_checkbox_left_column) {
1222 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1223 $totalarray['nbfield']++; // For the column action
1224}
1225print "</tr>\n";
1226
1227// Loop on record
1228// --------------------------------------------------------------------
1229$i = 0;
1230$savnbfield = $totalarray['nbfield'];
1231$totalarray = array();
1232$totalarray['nbfield'] = 0;
1233$typenArray = array();
1234$cacheCountryIDCode = array();
1235$imaxinloop = ($limit ? min($num, $limit) : $num);
1236$showinvalidemail = getDolGlobalInt('MAIN_SHOW_INVALID_EMAIL_IN_LIST', 1); // in list, we check only syntax of emails
1237while ($i < $imaxinloop) {
1238 $obj = $db->fetch_object($resql);
1239 if (empty($obj)) {
1240 break; // Should not happen
1241 }
1242
1243 $contracttmp->ref = $obj->ref;
1244 $contracttmp->id = $obj->rowid;
1245 $contracttmp->ref_customer = $obj->ref_customer;
1246 $contracttmp->ref_supplier = $obj->ref_supplier;
1247
1248 $contracttmp->nbofserviceswait = $obj->nb_initial;
1249 $contracttmp->nbofservicesopened = $obj->nb_running;
1250 $contracttmp->nbofservicesexpired = $obj->nb_expired;
1251 $contracttmp->nbofservicesclosed = $obj->nb_closed;
1252 $contracttmp->signed_status = $obj->signed_status;
1253
1254 $socstatic->id = $obj->socid;
1255 $socstatic->name = $obj->name;
1256 $socstatic->name_alias = $obj->name_alias;
1257 $socstatic->email = $obj->email;
1258 $socstatic->status = $obj->company_status;
1259 $socstatic->logo = $obj->company_logo;
1260 $socstatic->country_id = $obj->country_id;
1261 $socstatic->country_code = '';
1262 $socstatic->country = '';
1263
1264 if ($obj->country_id > 0) {
1265 if (!isset($cacheCountryIDCode[$obj->country_id]['code'])) {
1266 $tmparray = getCountry($obj->country_id, 'all');
1267 $cacheCountryIDCode[$obj->country_id] = array('code' => empty($tmparray['code']) ? '' : $tmparray['code'], 'label' => empty($tmparray['label']) ? '' : $tmparray['label']);
1268 }
1269 $socstatic->country_code = $cacheCountryIDCode[$obj->country_id]['code'];
1270 $socstatic->country = $cacheCountryIDCode[$obj->country_id]['label'];
1271 }
1272
1273 if ($mode == 'kanban') {
1274 if ($i == 0) {
1275 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1276 print '<div class="box-flex-container kanban">';
1277 }
1278 // Output Kanban
1279 $arraydata = array();
1280 $arraydata['thirdparty'] = $socstatic;
1281 $arraydata['selected'] = in_array($obj->rowid, $arrayofselected);
1282 $contracttmp->date_contrat = $obj->date_contrat;
1283 print $contracttmp->getKanbanView('', $arraydata);
1284 if ($i == ($imaxinloop - 1)) {
1285 print '</div>';
1286 print '</td></tr>';
1287 }
1288 } else {
1289 // Show here line of result
1290 print '<tr data-rowid="'.$object->id.'" class="oddeven row-with-select">';
1291 // Action column
1292 if ($conf->main_checkbox_left_column) {
1293 print '<td class="nowrap center">';
1294 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1295 $selected = 0;
1296 if (in_array($obj->rowid, $arrayofselected)) {
1297 $selected = 1;
1298 }
1299 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1300 }
1301 print '</td>';
1302 if (!$i) {
1303 $totalarray['nbfield']++;
1304 }
1305 }
1306 // Ref
1307 if (!empty($arrayfields['c.ref']['checked'])) {
1308 print '<td class="nowraponall">';
1309 print $contracttmp->getNomUrl(1);
1310 if ($obj->nb_late) {
1311 print img_warning($langs->trans("Late"));
1312 }
1313 if (!empty($obj->note_private) || !empty($obj->note_public)) {
1314 print ' <span class="note">';
1315 print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"), 'note').'</a>';
1316 print '</span>';
1317 }
1318
1319 $filename = dol_sanitizeFileName($obj->ref);
1320 $filedir = $conf->contrat->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
1321 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1322 print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
1323 print '</td>';
1324
1325 print '</td>';
1326 if (!$i) {
1327 $totalarray['nbfield']++;
1328 }
1329 }
1330
1331 // Ref thirdparty
1332 if (!empty($arrayfields['c.ref_customer']['checked'])) {
1333 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag(dol_string_nohtmltag($contracttmp->getFormatedCustomerRef($obj->ref_customer))).'">'.$contracttmp->getFormatedCustomerRef($obj->ref_customer).'</td>';
1334 if (!$i) {
1335 $totalarray['nbfield']++;
1336 }
1337 }
1338 if (!empty($arrayfields['c.ref_supplier']['checked'])) {
1339 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>';
1340 }
1341 if (!empty($arrayfields['c.fk_contract_type']['checked'])) {
1342 $contractTypeLabels = array(0 => $langs->trans('CustomerContract'), 1 => $langs->trans('SupplierContract'));
1343 print '<td>'.dol_escape_htmltag($contractTypeLabels[(int) $obj->fk_contract_type] ?? '').'</td>';
1344 if (!$i) {
1345 $totalarray['nbfield']++;
1346 }
1347 }
1348 if (!empty($arrayfields['s.nom']['checked'])) {
1349 print '<td class="tdoverflowmax150">';
1350 if ($obj->socid > 0) {
1351 // TODO Use a cache for this string
1352 print $socstatic->getNomUrl(1, '');
1353 }
1354 print '</td>';
1355 }
1356 // Town
1357 if (!empty($arrayfields['s.town']['checked'])) {
1358 print '<td class="nocellnopadd">';
1359 print $obj->town;
1360 print '</td>';
1361 if (!$i) {
1362 $totalarray['nbfield']++;
1363 }
1364 }
1365 // Zip
1366 if (!empty($arrayfields['s.zip']['checked'])) {
1367 print '<td class="center nocellnopadd">';
1368 print $obj->zip;
1369 print '</td>';
1370 if (!$i) {
1371 $totalarray['nbfield']++;
1372 }
1373 }
1374 // State
1375 if (!empty($arrayfields['state.nom']['checked'])) {
1376 print "<td>".$obj->state_name."</td>\n";
1377 if (!$i) {
1378 $totalarray['nbfield']++;
1379 }
1380 }
1381 // Country
1382 if (!empty($arrayfields['country.code_iso']['checked'])) {
1383 print '<td class="center tdoverflowmax100" title="'.dolPrintHTMLForAttribute($socstatic->country).'">';
1384 print dol_escape_htmltag($socstatic->country);
1385 print '</td>';
1386 if (!$i) {
1387 $totalarray['nbfield']++;
1388 }
1389 }
1390 // Phone
1391 if (!empty($arrayfields['s.phone']['checked'])) {
1392 print '<td class="tdoverflowmax200" title="'.dolPrintHTMLForAttribute((empty($socstatic->country_code) ? '' : $socstatic->country_code.': ').$obj->phone).'">'.dol_print_phone($obj->phone, $socstatic->country_code, 0, $socstatic->id).'</td>';
1393 }
1394 // Phone mobile
1395 if (!empty($arrayfields['s.phone_mobile']['checked'])) {
1396 print '<td class="tdoverflowmax200" title="'.dolPrintHTMLForAttribute((empty($socstatic->country_code) ? '' : $socstatic->country_code.': ').$obj->phone_mobile).'">'.dol_print_phone($obj->phone_mobile, $socstatic->country_code, 0, $socstatic->id).'</td>';
1397 }
1398 // Email
1399 if (!empty($arrayfields['s.email']['checked'])) {
1400 print '<td class="tdoverflowmax200" title="'.dolPrintHTMLForAttribute((string) $obj->email).'">'.dol_print_email((string) $obj->email, 0, $obj->socid, 1, 0, $showinvalidemail, 1).'</td>';
1401 }
1402
1403 // Type ent
1404 if (!empty($arrayfields['typent.code']['checked'])) {
1405 print '<td class="center">';
1406 if (count($typenArray) == 0) {
1407 $typenArray = $formcompany->typent_array(1);
1408 }
1409 print $typenArray[$obj->typent_code];
1410 print '</td>';
1411 if (!$i) {
1412 $totalarray['nbfield']++;
1413 }
1414 }
1415 if (!empty($arrayfields['sale_representative']['checked'])) {
1416 // Sales representatives
1417 print '<td>';
1418 if ($obj->socid > 0) {
1419 $listsalesrepresentatives = $socstatic->getSalesRepresentatives($user);
1420 if ($listsalesrepresentatives < 0) {
1421 dol_print_error($db);
1422 }
1423 $nbofsalesrepresentative = count($listsalesrepresentatives);
1424 if ($nbofsalesrepresentative > 6) {
1425 // We print only number
1426 print $nbofsalesrepresentative;
1427 } elseif ($nbofsalesrepresentative > 0) {
1428 $userstatic = new User($db);
1429 $j = 0;
1430 foreach ($listsalesrepresentatives as $val) {
1431 $userstatic->id = $val['id'];
1432 $userstatic->lastname = $val['lastname'];
1433 $userstatic->firstname = $val['firstname'];
1434 $userstatic->email = $val['email'];
1435 $userstatic->status = $val['statut'];
1436 $userstatic->entity = $val['entity'];
1437 $userstatic->photo = $val['photo'];
1438 $userstatic->login = $val['login'];
1439 $userstatic->phone = $val['phone'];
1440 $userstatic->job = $val['job'];
1441 $userstatic->gender = $val['gender'];
1442
1443 //print '<div class="float">':
1444 print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
1445 $j++;
1446 if ($j < $nbofsalesrepresentative) {
1447 print ' ';
1448 }
1449 //print '</div>';
1450 }
1451 }
1452 //else print $langs->trans("NoSalesRepresentativeAffected");
1453 } else {
1454 print '&nbsp;';
1455 }
1456 print '</td>';
1457 }
1458 // Date
1459 if (!empty($arrayfields['c.date_contrat']['checked'])) {
1460 print '<td class="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzserver').'</td>';
1461 }
1462 // Signed Status
1463 if (!empty($arrayfields['c.signed_status']['checked'])) {
1464 print '<td class="center">'.$contracttmp->getLibSignedStatus(5).'</td>';
1465 if (!$i) {
1466 $totalarray['nbfield']++;
1467 }
1468 }
1469 // public note
1470 if (!empty($arrayfields['c.note_public']['checked'])) {
1471 print '<td class="center">'.$obj->note_public.'</td>';
1472 if (!$i) {
1473 $totalarray['nbfield']++;
1474 }
1475 }
1476 // private note
1477 if (!empty($arrayfields['c.note_private']['checked'])) {
1478 print '<td class="center">'.$obj->note_private.'</td>';
1479 if (!$i) {
1480 $totalarray['nbfield']++;
1481 }
1482 }
1483 // Extra fields
1484 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1485 // Fields from hook
1486 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1487 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1488 print $hookmanager->resPrint;
1489 // Date creation
1490 if (!empty($arrayfields['c.datec']['checked'])) {
1491 print '<td class="center nowrap">';
1492 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1493 print '</td>';
1494 if (!$i) {
1495 $totalarray['nbfield']++;
1496 }
1497 }
1498 // Date modification
1499 if (!empty($arrayfields['c.tms']['checked'])) {
1500 print '<td class="center nowrap">';
1501 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
1502 print '</td>';
1503 if (!$i) {
1504 $totalarray['nbfield']++;
1505 }
1506 }
1507 // Date lower end date
1508 if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
1509 print '<td class="center nowrapforall">';
1510 print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
1511 print '</td>';
1512 if (!$i) {
1513 $totalarray['nbfield']++;
1514 }
1515 }
1516 // Status
1517 if (!empty($arrayfields['status']['checked'])) {
1518 print '<td class="center">'.($obj->nb_initial > 0 ? $obj->nb_initial : '').'</td>';
1519 print '<td class="center">'.($obj->nb_running > 0 ? $obj->nb_running : '').'</td>';
1520 print '<td class="center">'.($obj->nb_expired > 0 ? $obj->nb_expired : '').'</td>';
1521 print '<td class="center">'.($obj->nb_closed > 0 ? $obj->nb_closed : '').'</td>';
1522 if (!$i) {
1523 $totalarray['nbfield']++;
1524 $totalarray['nbfield']++;
1525 $totalarray['nbfield']++;
1526 $totalarray['nbfield']++;
1527 }
1528 }
1529 // Action column
1530 if (!$conf->main_checkbox_left_column) {
1531 print '<td class="nowrap center">';
1532 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1533 $selected = 0;
1534 if (in_array($obj->rowid, $arrayofselected)) {
1535 $selected = 1;
1536 }
1537 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1538 }
1539 print '</td>';
1540 if (!$i) {
1541 $totalarray['nbfield']++;
1542 }
1543 }
1544
1545 print '</tr>'."\n";
1546 }
1547 $i++;
1548}
1549
1550// If no record found
1551if ($num == 0) {
1552 $colspan = 4; // Include the 4 columns of status
1553 foreach ($arrayfields as $key => $val) {
1554 if (!empty($val['checked'])) {
1555 $colspan++;
1556 }
1557 }
1558 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1559}
1560
1561$db->free($resql);
1562
1563$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
1564$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1565print $hookmanager->resPrint;
1566
1567print '</table>'."\n";
1568print '</div>'."\n";
1569
1570print '</form>'."\n";
1571
1572$hidegeneratedfilelistifempty = 1;
1573if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1574 $hidegeneratedfilelistifempty = 0;
1575}
1576
1577// Show list of available documents
1578$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1579$urlsource .= str_replace('&amp;', '&', $param);
1580
1581$filedir = $diroutputmassaction;
1582$genallowed = $permissiontoread;
1583$delallowed = $permissiontoadd;
1584
1585print $formfile->showdocuments('massfilesarea_contract', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1586
1587
1588llxFooter();
1589$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage lines of contracts.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
static multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='', $nu='', $placeholder='', $addjscombo=-1)
Show a multiselect form from an array.
Class to help generate other html components Only common components are here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:616
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:635
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
dol_natural_search_phone($db, $fields, $value, $nofirstand=0)
Build a natural_search() SQL fragment for a phone/fax field, tolerant of the international storage fo...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.