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