dolibarr 24.0.3
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 ($socid > 0) {
672 $param .= '&socid='.((int) $socid);
673}
674if ($search_all != '') {
675 $param .= '&search_all='.urlencode($search_all);
676}
677if ($search_contract != '') {
678 $param .= '&search_contract='.urlencode($search_contract);
679}
680if ($search_name != '') {
681 $param .= '&search_name='.urlencode($search_name);
682}
683if ($search_phone != '') {
684 $param .= '&search_phone='.urlencode($search_phone);
685}
686if ($search_phone_mobile != '') {
687 $param .= '&search_phone_mobile='.urlencode($search_phone_mobile);
688}
689if ($search_email != '') {
690 $param .= '&search_email='.urlencode($search_email);
691}
692if ($search_ref_customer != '') {
693 $param .= '&search_ref_customer='.urlencode($search_ref_customer);
694}
695if ($search_ref_supplier != '') {
696 $param .= '&search_ref_supplier='.urlencode($search_ref_supplier);
697}
698if ($search_note_private != '') {
699 $param .= '&search_note_private='.urlencode($search_note_private);
700}
701if ($search_note_public != '') {
702 $param .= '&search_note_public='.urlencode($search_note_public);
703}
704if ($search_op2df != '') {
705 $param .= '&search_op2df='.urlencode($search_op2df);
706}
707if ($search_date_creation_startmonth) {
708 $param .= '&search_date_creation_startmonth='.urlencode((string) ($search_date_creation_startmonth));
709}
710if ($search_date_creation_startyear) {
711 $param .= '&search_date_creation_startyear='.urlencode((string) ($search_date_creation_startyear));
712}
713if ($search_date_creation_startday) {
714 $param .= '&search_date_creation_startday='.urlencode((string) ($search_date_creation_startday));
715}
716if ($search_date_creation_start) {
717 $param .= '&search_date_creation_start='.urlencode((string) $search_date_creation_start);
718}
719if ($search_date_creation_endmonth) {
720 $param .= '&search_date_creation_endmonth='.urlencode((string) ($search_date_creation_endmonth));
721}
722if ($search_date_creation_endyear) {
723 $param .= '&search_date_creation_endyear='.urlencode((string) ($search_date_creation_endyear));
724}
725if ($search_date_creation_endday) {
726 $param .= '&search_date_creation_endday='.urlencode((string) ($search_date_creation_endday));
727}
728if ($search_date_creation_end) {
729 $param .= '&search_date_creation_end='.urlencode((string) $search_date_creation_end);
730}
731if ($search_date_modif_startmonth) {
732 $param .= '&search_date_modif_startmonth='.urlencode((string) ($search_date_modif_startmonth));
733}
734if ($search_date_modif_startyear) {
735 $param .= '&search_date_modif_startyear='.urlencode((string) ($search_date_modif_startyear));
736}
737if ($search_date_modif_startday) {
738 $param .= '&search_date_modif_startday='.urlencode((string) ($search_date_modif_startday));
739}
740if ($search_date_modif_start) {
741 $param .= '&search_date_modif_start='.urlencode((string) $search_date_modif_start);
742}
743if ($search_date_modif_endmonth) {
744 $param .= '&search_date_modif_endmonth='.urlencode((string) ($search_date_modif_endmonth));
745}
746if ($search_date_modif_endyear) {
747 $param .= '&search_date_modif_endyear='.urlencode((string) ($search_date_modif_endyear));
748}
749if ($search_date_modif_endday) {
750 $param .= '&search_date_modif_endday='.urlencode((string) ($search_date_modif_endday));
751}
752if ($search_date_modif_end) {
753 $param .= '&search_date_modif_end=' . urlencode((string) $search_date_modif_end);
754}
755if ($search_date_startday > 0) {
756 $param .= '&search_date_startday='.urlencode((string) ($search_date_startday));
757}
758if ($search_date_startmonth > 0) {
759 $param .= '&search_date_startmonth='.urlencode((string) ($search_date_startmonth));
760}
761if ($search_date_startyear > 0) {
762 $param .= '&search_date_startyear='.urlencode((string) ($search_date_startyear));
763}
764if ($search_date_endday > 0) {
765 $param .= '&search_date_endday='.urlencode((string) ($search_date_endday));
766}
767if ($search_date_endmonth > 0) {
768 $param .= '&search_date_endmonth='.urlencode((string) ($search_date_endmonth));
769}
770if ($search_date_endyear > 0) {
771 $param .= '&search_date_endyear='.urlencode((string) ($search_date_endyear));
772}
773if ($search_dfyear > 0) {
774 $param .= '&search_dfyear='.urlencode((string) ($search_dfyear));
775}
776if ($search_dfmonth > 0) {
777 $param .= '&search_dfmonth='.urlencode((string) ($search_dfmonth));
778}
779if ($search_signed_status != '' && $search_signed_status >= 0) {
780 $param .= '&search_signed_status='.urlencode($search_signed_status);
781}
782if ($search_sale > 0) {
783 $param .= '&search_sale='.urlencode($search_sale);
784}
785if ($search_user > 0) {
786 $param .= '&search_user='.urlencode((string) ($search_user));
787}
788if ($search_type_thirdparty > 0) {
789 $param .= '&search_type_thirdparty='.urlencode((string) ($search_type_thirdparty));
790}
791if ($search_town != '') {
792 $param .= '&search_town='.urlencode($search_town);
793}
794if ($search_zip != '') {
795 $param .= '&search_zip='.urlencode($search_zip);
796}
797if ($search_state != '') {
798 $param .= '&search_state='.urlencode($search_state);
799}
800if ($search_country != '') {
801 $param .= "&search_country=".urlencode($search_country);
802}
803if ($search_product_category > 0) {
804 $param .= '&search_product_category='.urlencode((string) ($search_product_category));
805}
806if ($show_files) {
807 $param .= '&show_files='.urlencode((string) ($show_files));
808}
809if ($optioncss != '') {
810 $param .= '&optioncss='.urlencode($optioncss);
811}
812foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
813 $param .= "&search_category_customer_list[]=".urlencode($searchCategoryCustomer);
814}
815// Add $param from extra fields
816include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
817
818// List of mass actions available
819$arrayofmassactions = array(
820 'generate_doc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
821 'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
822 'presend' => img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
823);
824if (!empty($permissiontodelete)) {
825 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
826}
827if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
828 $arrayofmassactions = array();
829}
830$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
831
832$url = DOL_URL_ROOT.'/contrat/card.php?action=create';
833if (!empty($socid)) {
834 $url .= '&socid='.((int) $socid);
835}
836$newcardbutton = '';
837$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'));
838$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'));
839$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'));
840$newcardbutton .= dolGetButtonTitleSeparator();
841$newcardbutton .= dolGetButtonTitle($langs->trans('NewContractSubscription'), '', 'fa fa-plus-circle', $url, '', $user->hasRight('contrat', 'creer'));
842
843print '<form method="POST" id="searchFormList" action="'.$_SERVER['PHP_SELF'].'">'."\n";
844if ($optioncss != '') {
845 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
846}
847print '<input type="hidden" name="token" value="'.newToken().'">';
848print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
849print '<input type="hidden" name="action" value="list">';
850print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
851print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
852print '<input type="hidden" name="page" value="'.$page.'">';
853print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
854print '<input type="hidden" name="page_y" value="">';
855print '<input type="hidden" name="mode" value="'.$mode.'">';
856
857// @phan-suppress-next-line PhanPluginSuspiciousParamOrder
858print_barre_liste($langs->trans("Contracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, $newcardbutton, '', $limit, 0, 0, 1);
859
860$topicmail = "SendContractRef";
861$modelmail = "contract";
862$objecttmp = new Contrat($db);
863$trackid = 'con'.$object->id;
864include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
865
866if ($search_all) {
867 $setupstring = '';
868 foreach ($fieldstosearchall as $key => $val) {
869 $fieldstosearchall[$key] = $langs->trans($val);
870 $setupstring .= $key."=".$val.";";
871 }
872 print '<!-- Search done like if CONTRACT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
873 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
874}
875
876$moreforfilter = '';
877
878// If the user can view prospects other than his'
879if ($user->hasRight('user', 'user', 'lire')) {
880 $langs->load("commercial");
881 $moreforfilter .= '<div class="divsearchfield">';
882 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
883 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'widthcentpercentminusx maxwidth300');
884 $moreforfilter .= '</div>';
885}
886// If the user can view other users
887if ($user->hasRight('user', 'user', 'lire')) {
888 $moreforfilter .= '<div class="divsearchfield">';
889 $tmptitle = $langs->trans('LinkedToSpecificUsers');
890 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, null, 0, '', '', '0', 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
891 $moreforfilter .= '</div>';
892}
893// If the user can view categories of products
894if (isModEnabled('category') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
895 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
896 $moreforfilter .= '<div class="divsearchfield">';
897 $tmptitle = $langs->trans('IncludingProductWithTag');
898 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 2);
899 $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);
900 $moreforfilter .= '</div>';
901}
902// Filter on customer categories
903if (getDolGlobalString('MAIN_SEARCH_CATEGORY_CUSTOMER_ON_CONTRACT_LIST') && isModEnabled("category") && $user->hasRight('categorie', 'lire')) {
904 $moreforfilter .= '<div class="divsearchfield">';
905 $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort');
906 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
907 $categoriesArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 2);
908 $categoriesArr[-2] = '- '.$langs->trans('NotCategorized').' -';
909 $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle);
910 $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_customer_operator" name="search_category_customer_operator" value="1"'.($searchCategoryCustomerOperator == 1 ? ' checked="checked"' : '').'/>';
911 $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click
912 $moreforfilter .= '</div>';
913}
914
915$parameters = array();
916$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
917if (empty($reshook)) {
918 $moreforfilter .= $hookmanager->resPrint;
919} else {
920 $moreforfilter = $hookmanager->resPrint;
921}
922
923if (!empty($moreforfilter)) {
924 print '<div class="liste_titre liste_titre_bydiv centpercent">';
925 print $moreforfilter;
926 print '</div>';
927}
928
929$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
930$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields
931if ($massactionbutton) {
932 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
933}
934
935print '<div class="div-table-responsive">';
936print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
937
938// Fields title search
939// --------------------------------------------------------------------
940print '<tr class="liste_titre_filter">';
941// Action column
942if ($conf->main_checkbox_left_column) {
943 print '<td class="liste_titre maxwidthsearch center">';
944 $searchpicto = $form->showFilterButtons('left');
945 print $searchpicto;
946 print '</td>';
947}
948if (!empty($arrayfields['c.ref']['checked'])) {
949 print '<td class="liste_titre">';
950 print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
951 print '</td>';
952}
953if (!empty($arrayfields['c.ref_customer']['checked'])) {
954 print '<td class="liste_titre">';
955 print '<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
956 print '</td>';
957}
958if (!empty($arrayfields['c.ref_supplier']['checked'])) {
959 print '<td class="liste_titre">';
960 print '<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'">';
961 print '</td>';
962}
963if (!empty($arrayfields['s.nom']['checked'])) {
964 print '<td class="liste_titre">';
965 print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'"'.($user->socid > 0 ? " disabled" : "").'>';
966 print '</td>';
967}
968// Town
969if (!empty($arrayfields['s.town']['checked'])) {
970 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
971}
972// Zip
973if (!empty($arrayfields['s.zip']['checked'])) {
974 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
975}
976// State
977if (!empty($arrayfields['state.nom']['checked'])) {
978 print '<td class="liste_titre">';
979 print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
980 print '</td>';
981}
982// Country
983if (!empty($arrayfields['country.code_iso']['checked'])) {
984 print '<td class="liste_titre center">';
985 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
986 print '</td>';
987}
988// Phone
989if (!empty($arrayfields['s.phone']['checked'])) {
990 print '<td class="liste_titre">';
991 print '<input type="text" class="flat width50" name="search_phone" value="'.dol_escape_htmltag($search_phone).'">';
992 print '</td>';
993}
994// Phone mobile
995if (!empty($arrayfields['s.phone_mobile']['checked'])) {
996 print '<td class="liste_titre">';
997 print '<input type="text" class="flat width50" name="search_phone_mobile" value="'.dol_escape_htmltag($search_phone_mobile).'">';
998 print '</td>';
999}
1000// Email
1001if (!empty($arrayfields['s.email']['checked'])) {
1002 print '<td class="liste_titre">';
1003 print '<input type="text" class="flat width75" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
1004 print '</td>';
1005}
1006// Company type
1007if (!empty($arrayfields['typent.code']['checked'])) {
1008 print '<td class="liste_titre maxwidthonsmartphone center">';
1009 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);
1010 print '</td>';
1011}
1012if (!empty($arrayfields['sale_representative']['checked'])) {
1013 print '<td class="liste_titre"></td>';
1014}
1015if (!empty($arrayfields['c.date_contrat']['checked'])) {
1016 print '<td class="liste_titre center">';
1017 print '<div class="nowrapfordate">';
1018 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1019 print '</div>';
1020 print '<div class="nowrapfordate">';
1021 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1022 print '</div>';
1023 print '</td>';
1024}
1025// Signed status
1026if (!empty($arrayfields['c.signed_status']['checked'])) {
1027 print '<td class="liste_titre center">';
1028 $list_signed_status = $object->getSignedStatusLocalisedArray();
1029 print $form->selectarray('search_signed_status', $list_signed_status, $search_signed_status, 1, 0, 0, '', 1, 0, 0, '', 'search_status');
1030 print '</td>';
1031}
1032// Public note
1033if (!empty($arrayfields['c.note_public']['checked'])) {
1034 print '<td class="liste_titre center">';
1035 print '<input class="flat" size="10" type="text" name="search_note_public" value="'.dol_escape_htmltag($search_note_public).'">';
1036 print '</td>';
1037}
1038// Private note
1039if (!empty($arrayfields['c.note_private']['checked'])) {
1040 print '<td class="liste_titre center">';
1041 print '<input class="flat" size="10" type="text" name="search_note_private" value="'.dol_escape_htmltag($search_note_private).'">';
1042 print '</td>';
1043}
1044// Extra fields
1045include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1046
1047// Fields from hook
1048$parameters = array('arrayfields' => $arrayfields);
1049$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1050print $hookmanager->resPrint;
1051// Creation date
1052if (!empty($arrayfields['c.datec']['checked'])) {
1053 print '<td class="liste_titre center nowraponall">';
1054 print '<div class="nowrapfordate">';
1055 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'));
1056 print '</div>';
1057 print '<div class="nowrapfordate">';
1058 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'));
1059 print '</div>';
1060 print '</td>';
1061}
1062// Modification date
1063if (!empty($arrayfields['c.tms']['checked'])) {
1064 print '<td class="liste_titre center nowraponall">';
1065 print '<div class="nowrapfordate">';
1066 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'));
1067 print '</div>';
1068 print '<div class="nowrapfordate">';
1069 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'));
1070 print '</div>';
1071 print '</td>';
1072}
1073// First end date
1074if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
1075 print '<td class="liste_titre nowraponall center">';
1076 $arrayofoperators = array('0' => '', '=' => '=', '<=' => '<=', '>=' => '>=');
1077 print $form->selectarray('search_op2df', $arrayofoperators, $search_op2df, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth50imp');
1078 print '<br>';
1079 print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0);
1080 print ' ';
1081 print $formother->selectyear($search_dfyear, 'search_dfyear', 1, 20, 5, 0, 0, '');
1082 print '</td>';
1083}
1084// Status
1085if (!empty($arrayfields['status']['checked'])) {
1086 print '<td class="liste_titre right" colspan="4"></td>';
1087}
1088
1089// Action column
1090if (!$conf->main_checkbox_left_column) {
1091 print '<td class="liste_titre center">';
1092 $searchpicto = $form->showFilterButtons();
1093 print $searchpicto;
1094 print '</td>';
1095}
1096print '</tr>'."\n";
1097
1098$totalarray = array();
1099$totalarray['nbfield'] = 0;
1100
1101// Fields title label
1102// --------------------------------------------------------------------
1103print '<tr class="liste_titre">';
1104if ($conf->main_checkbox_left_column) {
1105 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1106 $totalarray['nbfield']++; // For the column action
1107}
1108if (!empty($arrayfields['c.ref']['checked'])) {
1109 // False positive @phan-suppress-next-line PhanTypeInvalidDimOffset
1110 print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);
1111 $totalarray['nbfield']++; // For the column action
1112}
1113if (!empty($arrayfields['c.ref_customer']['checked'])) {
1114 print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer", "", $param, '', $sortfield, $sortorder);
1115 $totalarray['nbfield']++; // For the column action
1116}
1117if (!empty($arrayfields['c.ref_supplier']['checked'])) {
1118 print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier", "", $param, '', $sortfield, $sortorder);
1119 $totalarray['nbfield']++; // For the column action
1120}
1121if (!empty($arrayfields['s.nom']['checked'])) {
1122 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
1123 $totalarray['nbfield']++; // For the column action
1124}
1125if (!empty($arrayfields['s.town']['checked'])) {
1126 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1127 $totalarray['nbfield']++; // For the column action
1128}
1129if (!empty($arrayfields['s.zip']['checked'])) {
1130 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1131 $totalarray['nbfield']++; // For the column action
1132}
1133if (!empty($arrayfields['state.nom']['checked'])) {
1134 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1135 $totalarray['nbfield']++; // For the column action
1136}
1137if (!empty($arrayfields['country.code_iso']['checked'])) {
1138 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1139 $totalarray['nbfield']++; // For the column action
1140}
1141if (!empty($arrayfields['s.phone']['checked'])) {
1142 print_liste_field_titre($arrayfields['s.phone']['label'], $_SERVER["PHP_SELF"], "s.phone", "", $param, '', $sortfield, $sortorder);
1143 $totalarray['nbfield']++; // For the column action
1144}
1145if (!empty($arrayfields['s.phone_mobile']['checked'])) {
1146 print_liste_field_titre($arrayfields['s.phone_mobile']['label'], $_SERVER["PHP_SELF"], "s.phone_mobile", "", $param, '', $sortfield, $sortorder);
1147 $totalarray['nbfield']++; // For the column action
1148}
1149if (!empty($arrayfields['s.email']['checked'])) {
1150 print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder);
1151 $totalarray['nbfield']++; // For the column action
1152}
1153if (!empty($arrayfields['typent.code']['checked'])) {
1154 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1155 $totalarray['nbfield']++; // For the column action
1156}
1157if (!empty($arrayfields['sale_representative']['checked'])) {
1158 print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
1159 $totalarray['nbfield']++; // For the column action
1160}
1161if (!empty($arrayfields['c.date_contrat']['checked'])) {
1162 print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat", "", $param, '', $sortfield, $sortorder, 'center ');
1163 $totalarray['nbfield']++; // For the column action
1164}
1165if (!empty($arrayfields['c.signed_status']['checked'])) {
1166 print_liste_field_titre($arrayfields['c.signed_status']['label'], $_SERVER["PHP_SELF"], "c.signed_status", "", $param, '', $sortfield, $sortorder, 'center ');
1167 $totalarray['nbfield']++;
1168}
1169if (!empty($arrayfields['c.note_public']['checked'])) {
1170 print_liste_field_titre($arrayfields['c.note_public']['label'], $_SERVER["PHP_SELF"], "c.note_public", "", $param, '', $sortfield, $sortorder, 'center ');
1171 $totalarray['nbfield']++;
1172}
1173if (!empty($arrayfields['c.note_private']['checked'])) {
1174 print_liste_field_titre($arrayfields['c.note_private']['label'], $_SERVER["PHP_SELF"], "c.note_private", "", $param, '', $sortfield, $sortorder, 'center ');
1175 $totalarray['nbfield']++;
1176}
1177// Extra fields
1178include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1179// Hook fields
1180$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
1181$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1182print $hookmanager->resPrint;
1183if (!empty($arrayfields['c.datec']['checked'])) {
1184 print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1185 $totalarray['nbfield']++; // For the column action
1186}
1187if (!empty($arrayfields['c.tms']['checked'])) {
1188 print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1189 $totalarray['nbfield']++; // For the column action
1190}
1191if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
1192 print_liste_field_titre($arrayfields['lower_planned_end_date']['label'], $_SERVER["PHP_SELF"], "lower_planned_end_date", "", $param, '', $sortfield, $sortorder, 'center ');
1193 $totalarray['nbfield']++; // For the column action
1194}
1195if (!empty($arrayfields['status']['checked'])) {
1196 print_liste_field_titre($staticcontratligne->LibStatut(0, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1197 $totalarray['nbfield']++; // For the column action
1198 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 0, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1199 $totalarray['nbfield']++; // For the column action
1200 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1201 $totalarray['nbfield']++; // For the column action
1202 print_liste_field_titre($staticcontratligne->LibStatut(5, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1203 $totalarray['nbfield']++; // For the column action
1204}
1205if (!$conf->main_checkbox_left_column) {
1206 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1207 $totalarray['nbfield']++; // For the column action
1208}
1209print "</tr>\n";
1210
1211// Loop on record
1212// --------------------------------------------------------------------
1213$i = 0;
1214$savnbfield = $totalarray['nbfield'];
1215$totalarray = array();
1216$totalarray['nbfield'] = 0;
1217$typenArray = array();
1218$cacheCountryIDCode = array();
1219$imaxinloop = ($limit ? min($num, $limit) : $num);
1220$showinvalidemail = getDolGlobalInt('MAIN_SHOW_INVALID_EMAIL_IN_LIST', 1); // in list, we check only syntax of emails
1221while ($i < $imaxinloop) {
1222 $obj = $db->fetch_object($resql);
1223 if (empty($obj)) {
1224 break; // Should not happen
1225 }
1226
1227 $contracttmp->ref = $obj->ref;
1228 $contracttmp->id = $obj->rowid;
1229 $contracttmp->ref_customer = $obj->ref_customer;
1230 $contracttmp->ref_supplier = $obj->ref_supplier;
1231
1232 $contracttmp->nbofserviceswait = $obj->nb_initial;
1233 $contracttmp->nbofservicesopened = $obj->nb_running;
1234 $contracttmp->nbofservicesexpired = $obj->nb_expired;
1235 $contracttmp->nbofservicesclosed = $obj->nb_closed;
1236 $contracttmp->signed_status = $obj->signed_status;
1237
1238 $socstatic->id = $obj->socid;
1239 $socstatic->name = $obj->name;
1240 $socstatic->name_alias = $obj->name_alias;
1241 $socstatic->email = $obj->email;
1242 $socstatic->status = $obj->company_status;
1243 $socstatic->logo = $obj->company_logo;
1244 $socstatic->country_id = $obj->country_id;
1245 $socstatic->country_code = '';
1246 $socstatic->country = '';
1247
1248 if ($obj->country_id > 0) {
1249 if (!isset($cacheCountryIDCode[$obj->country_id]['code'])) {
1250 $tmparray = getCountry($obj->country_id, 'all');
1251 $cacheCountryIDCode[$obj->country_id] = array('code' => empty($tmparray['code']) ? '' : $tmparray['code'], 'label' => empty($tmparray['label']) ? '' : $tmparray['label']);
1252 }
1253 $socstatic->country_code = $cacheCountryIDCode[$obj->country_id]['code'];
1254 $socstatic->country = $cacheCountryIDCode[$obj->country_id]['label'];
1255 }
1256
1257 if ($mode == 'kanban') {
1258 if ($i == 0) {
1259 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1260 print '<div class="box-flex-container kanban">';
1261 }
1262 // Output Kanban
1263 $arraydata = array();
1264 $arraydata['thirdparty'] = $socstatic;
1265 $arraydata['selected'] = in_array($obj->rowid, $arrayofselected);
1266 $contracttmp->date_contrat = $obj->date_contrat;
1267 print $contracttmp->getKanbanView('', $arraydata);
1268 if ($i == ($imaxinloop - 1)) {
1269 print '</div>';
1270 print '</td></tr>';
1271 }
1272 } else {
1273 // Show here line of result
1274 print '<tr data-rowid="'.$object->id.'" class="oddeven row-with-select">';
1275 // Action column
1276 if ($conf->main_checkbox_left_column) {
1277 print '<td class="nowrap center">';
1278 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1279 $selected = 0;
1280 if (in_array($obj->rowid, $arrayofselected)) {
1281 $selected = 1;
1282 }
1283 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1284 }
1285 print '</td>';
1286 if (!$i) {
1287 $totalarray['nbfield']++;
1288 }
1289 }
1290 // Ref
1291 if (!empty($arrayfields['c.ref']['checked'])) {
1292 print '<td class="nowraponall">';
1293 print $contracttmp->getNomUrl(1);
1294 if ($obj->nb_late) {
1295 print img_warning($langs->trans("Late"));
1296 }
1297 if (!empty($obj->note_private) || !empty($obj->note_public)) {
1298 print ' <span class="note">';
1299 print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"), 'note').'</a>';
1300 print '</span>';
1301 }
1302
1303 $filename = dol_sanitizeFileName($obj->ref);
1304 $filedir = $conf->contrat->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
1305 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1306 print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
1307 print '</td>';
1308
1309 print '</td>';
1310 if (!$i) {
1311 $totalarray['nbfield']++;
1312 }
1313 }
1314
1315 // Ref thirdparty
1316 if (!empty($arrayfields['c.ref_customer']['checked'])) {
1317 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag(dol_string_nohtmltag($contracttmp->getFormatedCustomerRef($obj->ref_customer))).'">'.$contracttmp->getFormatedCustomerRef($obj->ref_customer).'</td>';
1318 if (!$i) {
1319 $totalarray['nbfield']++;
1320 }
1321 }
1322 if (!empty($arrayfields['c.ref_supplier']['checked'])) {
1323 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>';
1324 }
1325 if (!empty($arrayfields['s.nom']['checked'])) {
1326 print '<td class="tdoverflowmax150">';
1327 if ($obj->socid > 0) {
1328 // TODO Use a cache for this string
1329 print $socstatic->getNomUrl(1, '');
1330 }
1331 print '</td>';
1332 }
1333 // Town
1334 if (!empty($arrayfields['s.town']['checked'])) {
1335 print '<td class="nocellnopadd">';
1336 print $obj->town;
1337 print '</td>';
1338 if (!$i) {
1339 $totalarray['nbfield']++;
1340 }
1341 }
1342 // Zip
1343 if (!empty($arrayfields['s.zip']['checked'])) {
1344 print '<td class="center nocellnopadd">';
1345 print $obj->zip;
1346 print '</td>';
1347 if (!$i) {
1348 $totalarray['nbfield']++;
1349 }
1350 }
1351 // State
1352 if (!empty($arrayfields['state.nom']['checked'])) {
1353 print "<td>".$obj->state_name."</td>\n";
1354 if (!$i) {
1355 $totalarray['nbfield']++;
1356 }
1357 }
1358 // Country
1359 if (!empty($arrayfields['country.code_iso']['checked'])) {
1360 print '<td class="center tdoverflowmax100" title="'.dolPrintHTMLForAttribute($socstatic->country).'">';
1361 print dol_escape_htmltag($socstatic->country);
1362 print '</td>';
1363 if (!$i) {
1364 $totalarray['nbfield']++;
1365 }
1366 }
1367 // Phone
1368 if (!empty($arrayfields['s.phone']['checked'])) {
1369 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>';
1370 }
1371 // Phone mobile
1372 if (!empty($arrayfields['s.phone_mobile']['checked'])) {
1373 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>';
1374 }
1375 // Email
1376 if (!empty($arrayfields['s.email']['checked'])) {
1377 print '<td class="tdoverflowmax200" title="'.dolPrintHTMLForAttribute($obj->email).'">'.dol_print_email($obj->email, 0, $obj->socid, 1, 0, $showinvalidemail, 1).'</td>';
1378 }
1379
1380 // Type ent
1381 if (!empty($arrayfields['typent.code']['checked'])) {
1382 print '<td class="center">';
1383 if (count($typenArray) == 0) {
1384 $typenArray = $formcompany->typent_array(1);
1385 }
1386 print $typenArray[$obj->typent_code];
1387 print '</td>';
1388 if (!$i) {
1389 $totalarray['nbfield']++;
1390 }
1391 }
1392 if (!empty($arrayfields['sale_representative']['checked'])) {
1393 // Sales representatives
1394 print '<td>';
1395 if ($obj->socid > 0) {
1396 $listsalesrepresentatives = $socstatic->getSalesRepresentatives($user);
1397 if ($listsalesrepresentatives < 0) {
1399 }
1400 $nbofsalesrepresentative = count($listsalesrepresentatives);
1401 if ($nbofsalesrepresentative > 6) {
1402 // We print only number
1403 print $nbofsalesrepresentative;
1404 } elseif ($nbofsalesrepresentative > 0) {
1405 $userstatic = new User($db);
1406 $j = 0;
1407 foreach ($listsalesrepresentatives as $val) {
1408 $userstatic->id = $val['id'];
1409 $userstatic->lastname = $val['lastname'];
1410 $userstatic->firstname = $val['firstname'];
1411 $userstatic->email = $val['email'];
1412 $userstatic->status = $val['statut'];
1413 $userstatic->entity = $val['entity'];
1414 $userstatic->photo = $val['photo'];
1415 $userstatic->login = $val['login'];
1416 $userstatic->phone = $val['phone'];
1417 $userstatic->job = $val['job'];
1418 $userstatic->gender = $val['gender'];
1419
1420 //print '<div class="float">':
1421 print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
1422 $j++;
1423 if ($j < $nbofsalesrepresentative) {
1424 print ' ';
1425 }
1426 //print '</div>';
1427 }
1428 }
1429 //else print $langs->trans("NoSalesRepresentativeAffected");
1430 } else {
1431 print '&nbsp;';
1432 }
1433 print '</td>';
1434 }
1435 // Date
1436 if (!empty($arrayfields['c.date_contrat']['checked'])) {
1437 print '<td class="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzserver').'</td>';
1438 }
1439 // Signed Status
1440 if (!empty($arrayfields['c.signed_status']['checked'])) {
1441 print '<td class="center">'.$contracttmp->getLibSignedStatus(5).'</td>';
1442 if (!$i) {
1443 $totalarray['nbfield']++;
1444 }
1445 }
1446 // public note
1447 if (!empty($arrayfields['c.note_public']['checked'])) {
1448 print '<td class="center">'.$obj->note_public.'</td>';
1449 if (!$i) {
1450 $totalarray['nbfield']++;
1451 }
1452 }
1453 // private note
1454 if (!empty($arrayfields['c.note_private']['checked'])) {
1455 print '<td class="center">'.$obj->note_private.'</td>';
1456 if (!$i) {
1457 $totalarray['nbfield']++;
1458 }
1459 }
1460 // Extra fields
1461 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1462 // Fields from hook
1463 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1464 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1465 print $hookmanager->resPrint;
1466 // Date creation
1467 if (!empty($arrayfields['c.datec']['checked'])) {
1468 print '<td class="center nowrap">';
1469 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1470 print '</td>';
1471 if (!$i) {
1472 $totalarray['nbfield']++;
1473 }
1474 }
1475 // Date modification
1476 if (!empty($arrayfields['c.tms']['checked'])) {
1477 print '<td class="center nowrap">';
1478 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
1479 print '</td>';
1480 if (!$i) {
1481 $totalarray['nbfield']++;
1482 }
1483 }
1484 // Date lower end date
1485 if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
1486 print '<td class="center nowrapforall">';
1487 print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
1488 print '</td>';
1489 if (!$i) {
1490 $totalarray['nbfield']++;
1491 }
1492 }
1493 // Status
1494 if (!empty($arrayfields['status']['checked'])) {
1495 print '<td class="center">'.($obj->nb_initial > 0 ? $obj->nb_initial : '').'</td>';
1496 print '<td class="center">'.($obj->nb_running > 0 ? $obj->nb_running : '').'</td>';
1497 print '<td class="center">'.($obj->nb_expired > 0 ? $obj->nb_expired : '').'</td>';
1498 print '<td class="center">'.($obj->nb_closed > 0 ? $obj->nb_closed : '').'</td>';
1499 if (!$i) {
1500 $totalarray['nbfield']++;
1501 $totalarray['nbfield']++;
1502 $totalarray['nbfield']++;
1503 $totalarray['nbfield']++;
1504 }
1505 }
1506 // Action column
1507 if (!$conf->main_checkbox_left_column) {
1508 print '<td class="nowrap center">';
1509 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1510 $selected = 0;
1511 if (in_array($obj->rowid, $arrayofselected)) {
1512 $selected = 1;
1513 }
1514 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1515 }
1516 print '</td>';
1517 if (!$i) {
1518 $totalarray['nbfield']++;
1519 }
1520 }
1521
1522 print '</tr>'."\n";
1523 }
1524 $i++;
1525}
1526
1527// If no record found
1528if ($num == 0) {
1529 $colspan = 4; // Include the 4 columns of status
1530 foreach ($arrayfields as $key => $val) {
1531 if (!empty($val['checked'])) {
1532 $colspan++;
1533 }
1534 }
1535 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1536}
1537
1538$db->free($resql);
1539
1540$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
1541$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1542print $hookmanager->resPrint;
1543
1544print '</table>'."\n";
1545print '</div>'."\n";
1546
1547print '</form>'."\n";
1548
1549$hidegeneratedfilelistifempty = 1;
1550if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1551 $hidegeneratedfilelistifempty = 0;
1552}
1553
1554// Show list of available documents
1555$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1556$urlsource .= str_replace('&amp;', '&', $param);
1557
1558$filedir = $diroutputmassaction;
1559$genallowed = $permissiontoread;
1560$delallowed = $permissiontoadd;
1561
1562print $formfile->showdocuments('massfilesarea_contract', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1563
1564
1565llxFooter();
1566$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.