dolibarr 18.0.6
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 Alexandre Spangaro <aspangaro@open-dsi.fr>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33// Load Dolibarr environment
34require '../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
41if (isModEnabled("categorie")) {
42 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
43}
44
45// Load translation files required by the page
46$langs->loadLangs(array('contracts', 'products', 'companies', 'compta'));
47
48$action = GETPOST('action', 'aZ09');
49$massaction = GETPOST('massaction', 'alpha');
50$show_files = GETPOST('show_files', 'int');
51$confirm = GETPOST('confirm', 'alpha');
52$toselect = GETPOST('toselect', 'array');
53$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contractlist'; // To manage different context of search
54$optioncss = GETPOST('optioncss', 'alpha');
55$mode = GETPOST('mode', 'alpha');
56
57$search_name = GETPOST('search_name', 'alpha');
58$search_email = GETPOST('search_email', 'alpha');
59$search_town = GETPOST('search_town', 'alpha');
60$search_zip = GETPOST('search_zip', 'alpha');
61$search_state = GETPOST("search_state", 'alpha');
62$search_country = GETPOST("search_country", 'int');
63$search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
64$search_contract = GETPOST('search_contract', 'alpha');
65$search_ref_customer = GETPOST('search_ref_customer', 'alpha');
66$search_ref_supplier = GETPOST('search_ref_supplier', 'alpha');
67$search_all = (GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
68$search_status = GETPOST('search_status', 'alpha');
69$socid = GETPOST('socid', 'int');
70$search_user = GETPOST('search_user', 'int');
71$search_sale = GETPOST('search_sale', 'int');
72$search_product_category = GETPOST('search_product_category', 'int');
73$search_dfmonth = GETPOST('search_dfmonth', 'int');
74$search_dfyear = GETPOST('search_dfyear', 'int');
75$search_op2df = GETPOST('search_op2df', 'alpha');
76$search_date_startday = GETPOST('search_date_startday', 'int');
77$search_date_startmonth = GETPOST('search_date_startmonth', 'int');
78$search_date_startyear = GETPOST('search_date_startyear', 'int');
79$search_date_endday = GETPOST('search_date_endday', 'int');
80$search_date_endmonth = GETPOST('search_date_endmonth', 'int');
81$search_date_endyear = GETPOST('search_date_endyear', 'int');
82$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
83$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
84$searchCategoryCustomerOperator = 0;
85if (GETPOSTISSET('formfilteraction')) {
86 $searchCategoryCustomerOperator = GETPOST('search_category_customer_operator', 'int');
87} elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) {
88 $searchCategoryCustomerOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
89}
90$searchCategoryCustomerList = GETPOST('search_category_customer_list', 'array');
91
92// Load variable for pagination
93$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
94$sortfield = GETPOST('sortfield', 'aZ09comma');
95$sortorder = GETPOST('sortorder', 'aZ09comma');
96$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
97if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
98 // If $page is not defined, or '' or -1 or if we click on clear filters
99 $page = 0;
100}
101$offset = $limit * $page;
102$pageprev = $page - 1;
103$pagenext = $page + 1;
104if (!$sortfield) {
105 $sortfield = 'c.ref';
106}
107if (!$sortorder) {
108 $sortorder = 'DESC';
109}
110
111// Security check
112$id = GETPOST('id', 'int');
113if ($user->socid) {
114 $socid = $user->socid;
115}
116$result = restrictedArea($user, 'contrat', $id);
117
118$diroutputmassaction = $conf->contrat->dir_output.'/temp/massgeneration/'.$user->id;
119
120$staticcontrat = new Contrat($db);
121$staticcontratligne = new ContratLigne($db);
122
123if ($search_status == '') {
124 $search_status = 1;
125}
126
127// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
128$object = new Contrat($db);
129$hookmanager->initHooks(array('contractlist'));
130$extrafields = new ExtraFields($db);
131
132// fetch optionals attributes and labels
133$extrafields->fetch_name_optionals_label($object->table_element);
134
135$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
136// List of fields to search into when doing a "search in all"
137$fieldstosearchall = array();
138foreach ($object->fields as $key => $val) {
139 if (!empty($val['searchall'])) {
140 $fieldstosearchall['c.'.$key] = $val['label'];
141 }
142}
143$fieldstosearchall["s.nom"] = "ThirdParty";
144if (empty($user->socid)) {
145 $fieldstosearchall["c.note_private"] = "NotePrivate";
146}
147$parameters = array('fieldstosearchall'=>$fieldstosearchall);
148$reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
149if ($reshook > 0) {
150 $fieldstosearchall = $hookmanager->resArray['fieldstosearchall'];
151} elseif ($reshook == 0) {
152 if (!empty($hookmanager->resArray['fieldstosearchall'])) {
153 $fieldstosearchall = array_merge($fieldstosearchall, $hookmanager->resArray['fieldstosearchall']);
154 }
155}
156
157$arrayfields = array(
158 'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1, 'position'=>10),
159 'c.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1, 'position'=>12),
160 'c.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1, 'position'=>14),
161 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>30),
162 's.email'=>array('label'=>$langs->trans("ThirdPartyEmail"), 'checked'=>0, 'position'=>30),
163 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0, 'position'=>31),
164 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1, 'position'=>32),
165 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0, 'position'=>33),
166 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0, 'position'=>34),
167 'sale_representative'=>array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>-1, 'position'=>80),
168 'c.date_contrat'=>array('label'=>$langs->trans("DateContract"), 'checked'=>1, 'position'=>45),
169 'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
170 'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
171 'lower_planned_end_date'=>array('label'=>$langs->trans("LowerDateEndPlannedShort"), 'checked'=>1, 'position'=>900, 'help'=>$langs->trans("LowerDateEndPlannedShort")),
172 'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
173);
174// Extra fields
175include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
176
177$object->fields = dol_sort_array($object->fields, 'position');
178$arrayfields = dol_sort_array($arrayfields, 'position');
179
180$permissiontoread = $user->hasRight('contrat', 'lire');
181$permissiontoadd = $user->hasRight('contrat', 'creer');
182$permissiontodelete = $user->hasRight('contrat', 'supprimer');
183
184
185/*
186 * Actions
187 */
188
189if (GETPOST('cancel', 'alpha')) {
190 $action = 'list';
191 $massaction = '';
192}
193if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
194 $massaction = '';
195}
196
197$parameters = array('socid'=>$socid);
198$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
199if ($reshook < 0) {
200 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
201}
202
203include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
204
205// Purge search criteria
206if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
207 $search_dfmonth = '';
208 $search_dfyear = '';
209 $search_op2df = '';
210 $search_name = "";
211 $search_email = "";
212 $search_town = '';
213 $search_zip = "";
214 $search_state = "";
215 $search_type = '';
216 $search_country = '';
217 $search_contract = "";
218 $search_ref_customer = "";
219 $search_ref_supplier = "";
220 $search_user = '';
221 $search_sale = '';
222 $search_product_category = '';
223 $search_date_startday = '';
224 $search_date_startmonth = '';
225 $search_date_startyear = '';
226 $search_date_endday = '';
227 $search_date_endmonth = '';
228 $search_date_endyear = '';
229 $search_date_start = '';
230 $search_date_end = '';
231 $search_all = "";
232 $search_status = "";
233 $toselect = array();
234 $search_type_thirdparty = '';
235 $searchCategoryCustomerList = array();
236 $search_array_options = array();
237}
238
239if (empty($reshook)) {
240 $objectclass = 'Contrat';
241 $objectlabel = 'Contracts';
242 $uploaddir = $conf->contrat->dir_output;
243 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
244}
245
246
247/*
248 * View
249 */
250
251$form = new Form($db);
252$formfile = new FormFile($db);
253$formother = new FormOther($db);
254$socstatic = new Societe($db);
255$formcompany = new FormCompany($db);
256$contracttmp = new Contrat($db);
257
258$now = dol_now();
259
260$title = "";
261
262$sql = 'SELECT';
263$sql .= " c.rowid, c.ref, c.datec as date_creation, c.tms as date_update, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public, c.entity,";
264$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.client, s.code_client, s.status as company_status, s.logo as company_logo,';
265$sql .= " typent.code as typent_code,";
266$sql .= " state.code_departement as state_code, state.nom as state_name,";
267$sql .= " MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") as lower_planned_end_date,";
268$sql .= " SUM(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
269$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", 1, 0).') as nb_running,';
270$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", 1, 0).') as nb_expired,';
271$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,';
272$sql .= " SUM(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed';
273// Add fields from extrafields
274if (!empty($extrafields->attributes[$object->table_element]['label'])) {
275 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
276 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
277 }
278}
279// Add fields from hooks
280$parameters = array();
281$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
282$sql .= $hookmanager->resPrint;
283$sql = preg_replace('/,\s*$/', '', $sql);
284
285$sqlfields = $sql; // $sql fields to remove for count total
286
287$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
288$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
289$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
290$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
291if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
292 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
293}
294$sql .= ", ".MAIN_DB_PREFIX."contrat as c";
295if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
296 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (c.rowid = ef.fk_object)";
297}
298$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
299if ($search_user > 0) {
300 $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
301 $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
302}
303$sql .= " WHERE c.fk_soc = s.rowid ";
304$sql .= ' AND c.entity IN ('.getEntity('contract').')';
305if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
306 $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
307}
308if ($socid) {
309 $sql .= " AND s.rowid = ".((int) $socid);
310}
311if (empty($user->rights->societe->client->voir) && !$socid) {
312 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
313}
314if ($search_date_start) {
315 $sql .= " AND c.date_contrat >= '".$db->idate($search_date_start)."'";
316}
317if ($search_date_end) {
318 $sql .= " AND c.date_contrat <= '".$db->idate($search_date_end)."'";
319}
320if ($search_name) {
321 $sql .= natural_search('s.nom', $search_name);
322}
323if ($search_email) {
324 $sql .= natural_search('s.email', $search_email);
325}
326if ($search_contract) {
327 $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
328}
329if (!empty($search_ref_customer)) {
330 $sql .= natural_search(array('c.ref_customer'), $search_ref_customer);
331}
332if (!empty($search_ref_supplier)) {
333 $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
334}
335if ($search_zip) {
336 $sql .= natural_search(array('s.zip'), $search_zip);
337}
338if ($search_town) {
339 $sql .= natural_search(array('s.town'), $search_town);
340}
341if ($search_country && $search_country != '-1') {
342 $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
343}
344if ($search_sale > 0) {
345 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
346}
347if ($search_all) {
348 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
349}
350if ($search_user > 0) {
351 $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);
352}
353// Search for tag/category ($searchCategoryProductList is an array of ID)
354$searchCategoryProductOperator = -1;
355$searchCategoryProductList = array($search_product_category);
356if (!empty($searchCategoryProductList)) {
357 $searchCategoryProductSqlList = array();
358 $listofcategoryid = '';
359 foreach ($searchCategoryProductList as $searchCategoryProduct) {
360 if (intval($searchCategoryProduct) == -2) {
361 $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)";
362 } elseif (intval($searchCategoryProduct) > 0) {
363 if ($searchCategoryProductOperator == 0) {
364 $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).")";
365 } else {
366 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
367 }
368 }
369 }
370 if ($listofcategoryid) {
371 $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)."))";
372 }
373 if ($searchCategoryProductOperator == 1) {
374 if (!empty($searchCategoryProductSqlList)) {
375 $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
376 }
377 } else {
378 if (!empty($searchCategoryProductSqlList)) {
379 $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
380 }
381 }
382}
383$searchCategoryCustomerSqlList = array();
384if ($searchCategoryCustomerOperator == 1) {
385 $existsCategoryCustomerList = array();
386 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
387 if (intval($searchCategoryCustomer) == -2) {
388 $sqlCategoryCustomerNotExists = " NOT EXISTS (";
389 $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
390 $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
391 $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid";
392 $sqlCategoryCustomerNotExists .= " )";
393 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
394 } elseif (intval($searchCategoryCustomer) > 0) {
395 $existsCategoryCustomerList[] = $db->escape($searchCategoryCustomer);
396 }
397 }
398 if (!empty($existsCategoryCustomerList)) {
399 $sqlCategoryCustomerExists = " EXISTS (";
400 $sqlCategoryCustomerExists .= " SELECT cat_cus.fk_soc";
401 $sqlCategoryCustomerExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
402 $sqlCategoryCustomerExists .= " WHERE cat_cus.fk_soc = s.rowid";
403 $sqlCategoryCustomerExists .= " AND cat_cus.fk_categorie IN (".$db->sanitize(implode(',', $existsCategoryCustomerList)).")";
404 $sqlCategoryCustomerExists .= " )";
405 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerExists;
406 }
407 if (!empty($searchCategoryCustomerSqlList)) {
408 $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
409 }
410} else {
411 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
412 if (intval($searchCategoryCustomer) == -2) {
413 $sqlCategoryCustomerNotExists = " NOT EXISTS (";
414 $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
415 $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
416 $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid";
417 $sqlCategoryCustomerNotExists .= " )";
418 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
419 } elseif (intval($searchCategoryCustomer) > 0) {
420 $searchCategoryCustomerSqlList[] = "s.rowid IN (SELECT fk_soc FROM ".$db->prefix()."categorie_societe WHERE fk_categorie = ".((int) $searchCategoryCustomer).")";
421 }
422 }
423 if (!empty($searchCategoryCustomerSqlList)) {
424 $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
425 }
426}
427// Add where from extra fields
428include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
429// Add where from hooks
430$parameters = array();
431$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
432$sql .= $hookmanager->resPrint;
433$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public, c.entity,";
434$sql .= ' s.rowid, s.nom, s.name_alias, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client, s.status, s.logo,';
435$sql .= " typent.code,";
436$sql .= " state.code_departement, state.nom";
437// Add fields from extrafields
438if (!empty($extrafields->attributes[$object->table_element]['label'])) {
439 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
440 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');
441 }
442}
443// Add where from hooks
444$parameters = array('search_dfyear' => $search_dfyear, 'search_op2df'=>$search_op2df);
445$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
446$sql .= $hookmanager->resPrint;
447// Add HAVING from hooks
448$parameters = array('search_dfyear' => $search_dfyear, 'search_op2df'=>$search_op2df);
449$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
450if (empty($reshook)) {
451 if ($search_dfyear > 0 && $search_op2df) {
452 if ($search_op2df == '<=') {
453 $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."'";
454 } elseif ($search_op2df == '>=') {
455 $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
456 } else {
457 $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))."'";
458 }
459 }
460}
461$sql .= $hookmanager->resPrint;
462
463// Count total nb of records
464$nbtotalofrecords = '';
465if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
466 //$result = $db->query($sql);
467 //$nbtotalofrecords = $db->num_rows($result);
468
469 if ($search_dfyear > 0 && $search_op2df) {
470 $resql = $db->query($sql, 0, 'auto', 1);
471 while ($db->fetch_object($resql)) {
472 if (empty($nbtotalofrecords)) {
473 $nbtotalofrecords = 1; // We can't make +1 because init value is ''
474 } else {
475 $nbtotalofrecords++;
476 }
477 }
478 } else {
479 /* The fast and low memory method to get and count full list converts the sql into a sql count */
480 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
481 $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'contratdet as cd ON c.rowid = cd.fk_contrat /', '', $sqlforcount);
482 $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount);
483
484 $resql = $db->query($sqlforcount);
485 if ($resql) {
486 $objforcount = $db->fetch_object($resql);
487 $nbtotalofrecords = $objforcount->nbtotalofrecords;
488 } else {
489 dol_print_error($db);
490 }
491 }
492
493 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
494 $page = 0;
495 $offset = 0;
496 }
497 $db->free($resql);
498}
499
500// Complete request and execute it with limit
501$sql .= $db->order($sortfield, $sortorder);
502if ($limit) {
503 $sql .= $db->plimit($limit + 1, $offset);
504}
505
506$resql = $db->query($sql);
507if (!$resql) {
508 dol_print_error($db);
509 exit;
510}
511
512$num = $db->num_rows($resql);
513
514// Direct jump if only one record found
515if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
516 $obj = $db->fetch_object($resql);
517 $id = $obj->rowid;
518 header("Location: ".DOL_URL_ROOT.'/contrat/card.php?id='.$id);
519 exit;
520}
521
522
523// Output page
524// --------------------------------------------------------------------
525
526llxHeader('', $langs->trans("Contracts"));
527
528$i = 0;
529
530$arrayofselected = is_array($toselect) ? $toselect : array();
531
532if ($socid > 0) {
533 $soc = new Societe($db);
534 $soc->fetch($socid);
535 if (empty($search_name)) {
536 $search_name = $soc->name;
537 }
538}
539
540$param = '';
541if (!empty($mode)) {
542 $param .= '&mode='.urlencode($mode);
543}
544if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
545 $param .= '&contextpage='.urlencode($contextpage);
546}
547if ($limit > 0 && $limit != $conf->liste_limit) {
548 $param .= '&limit='.((int) $limit);
549}
550if ($search_all != '') {
551 $param .= '&search_all='.urlencode($search_all);
552}
553if ($search_contract != '') {
554 $param .= '&search_contract='.urlencode($search_contract);
555}
556if ($search_name != '') {
557 $param .= '&search_name='.urlencode($search_name);
558}
559if ($search_email != '') {
560 $param .= '&search_email='.urlencode($search_email);
561}
562if ($search_ref_customer != '') {
563 $param .= '&search_ref_customer='.urlencode($search_ref_customer);
564}
565if ($search_ref_supplier != '') {
566 $param .= '&search_ref_supplier='.urlencode($search_ref_supplier);
567}
568if ($search_op2df != '') {
569 $param .= '&search_op2df='.urlencode($search_op2df);
570}
571if ($search_date_startday > 0) {
572 $param .= '&search_date_startday='.urlencode($search_date_startday);
573}
574if ($search_date_startmonth > 0) {
575 $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
576}
577if ($search_date_startyear > 0) {
578 $param .= '&search_date_startyear='.urlencode($search_date_startyear);
579}
580if ($search_date_endday > 0) {
581 $param .= '&search_date_endday='.urlencode($search_date_endday);
582}
583if ($search_date_endmonth > 0) {
584 $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
585}
586if ($search_date_endyear > 0) {
587 $param .= '&search_date_endyear='.urlencode($search_date_endyear);
588}
589if ($search_dfyear > 0) {
590 $param .= '&search_dfyear='.urlencode($search_dfyear);
591}
592if ($search_dfmonth > 0) {
593 $param .= '&search_dfmonth='.urlencode($search_dfmonth);
594}
595if ($search_sale > 0) {
596 $param .= '&search_sale='.urlencode($search_sale);
597}
598if ($search_user > 0) {
599 $param .= '&search_user='.urlencode($search_user);
600}
601if ($search_type_thirdparty > 0) {
602 $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
603}
604if ($search_country != '') {
605 $param .= "&search_country=".urlencode($search_country);
606}
607if ($search_product_category > 0) {
608 $param .= '&search_product_category='.urlencode($search_product_category);
609}
610if ($show_files) {
611 $param .= '&show_files='.urlencode($show_files);
612}
613if ($optioncss != '') {
614 $param .= '&optioncss='.urlencode($optioncss);
615}
616foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
617 $param .= "&search_category_customer_list[]=".urlencode($searchCategoryCustomer);
618}
619// Add $param from extra fields
620include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
621
622// List of mass actions available
623$arrayofmassactions = array(
624 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
625 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
626 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
627);
628if (!empty($permissiontodelete)) {
629 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
630}
631if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
632 $arrayofmassactions = array();
633}
634$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
635
636$url = DOL_URL_ROOT.'/contrat/card.php?action=create';
637if (!empty($socid)) {
638 $url .= '&socid='.((int) $socid);
639}
640$newcardbutton = '';
641$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'));
642$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'));
643$newcardbutton .= dolGetButtonTitle($langs->trans('NewContractSubscription'), '', 'fa fa-plus-circle', $url, '', $user->rights->contrat->creer);
644
645print '<form method="POST" id="searchFormList" action="'.$_SERVER['PHP_SELF'].'">'."\n";
646if ($optioncss != '') {
647 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
648}
649print '<input type="hidden" name="token" value="'.newToken().'">';
650print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
651print '<input type="hidden" name="action" value="list">';
652print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
653print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
654print '<input type="hidden" name="page" value="'.$page.'">';
655print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
656print '<input type="hidden" name="page_y" value="">';
657print '<input type="hidden" name="mode" value="'.$mode.'">';
658
659print_barre_liste($langs->trans("Contracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, $newcardbutton, '', $limit, 0, 0, 1);
660
661$topicmail = "SendContractRef";
662$modelmail = "contract";
663$objecttmp = new Contrat($db);
664$trackid = 'con'.$object->id;
665include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
666
667if ($search_all) {
668 $setupstring = '';
669 foreach ($fieldstosearchall as $key => $val) {
670 $fieldstosearchall[$key] = $langs->trans($val);
671 $setupstring .= $key."=".$val.";";
672 }
673 print '<!-- Search done like if CONTRACT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
674 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
675}
676
677$moreforfilter = '';
678
679// If the user can view prospects other than his'
680if ($user->rights->user->user->lire) {
681 $langs->load("commercial");
682 $moreforfilter .= '<div class="divsearchfield">';
683 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
684 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'widthcentpercentminusx maxwidth300');
685 $moreforfilter .= '</div>';
686}
687// If the user can view other users
688if ($user->rights->user->user->lire) {
689 $moreforfilter .= '<div class="divsearchfield">';
690 $tmptitle = $langs->trans('LinkedToSpecificUsers');
691 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
692 $moreforfilter .= '</div>';
693}
694// If the user can view categories of products
695if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
696 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
697 $moreforfilter .= '<div class="divsearchfield">';
698 $tmptitle = $langs->trans('IncludingProductWithTag');
699 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
700 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'widthcentpercentminusx maxwidth300', 1);
701 $moreforfilter .= '</div>';
702}
703// Filter on customer categories
704if (!empty($conf->global->MAIN_SEARCH_CATEGORY_CUSTOMER_ON_CONTRACT_LIST) && isModEnabled("categorie") && $user->hasRight('categorie', 'lire')) {
705 $moreforfilter .= '<div class="divsearchfield">';
706 $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort');
707 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
708 $categoriesArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 1);
709 $categoriesArr[-2] = '- '.$langs->trans('NotCategorized').' -';
710 $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle);
711 $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_customer_operator" name="search_category_customer_operator" value="1"'.($searchCategoryCustomerOperator == 1 ? ' checked="checked"' : '').'/>';
712 $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click
713 $moreforfilter .= '</div>';
714}
715
716$parameters = array();
717$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
718if (empty($reshook)) {
719 $moreforfilter .= $hookmanager->resPrint;
720} else {
721 $moreforfilter = $hookmanager->resPrint;
722}
723
724if (!empty($moreforfilter)) {
725 print '<div class="liste_titre liste_titre_bydiv centpercent">';
726 print $moreforfilter;
727 print '</div>';
728}
729
730$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
731$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
732if ($massactionbutton) {
733 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
734}
735
736print '<div class="div-table-responsive">';
737print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
738
739// Fields title search
740// --------------------------------------------------------------------
741print '<tr class="liste_titre_filter">';
742// Action column
743if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
744 print '<td class="liste_titre maxwidthsearch center">';
745 $searchpicto = $form->showFilterButtons('left');
746 print $searchpicto;
747 print '</td>';
748}
749if (!empty($arrayfields['c.ref']['checked'])) {
750 print '<td class="liste_titre">';
751 print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
752 print '</td>';
753}
754if (!empty($arrayfields['c.ref_customer']['checked'])) {
755 print '<td class="liste_titre">';
756 print '<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
757 print '</td>';
758}
759if (!empty($arrayfields['c.ref_supplier']['checked'])) {
760 print '<td class="liste_titre">';
761 print '<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'">';
762 print '</td>';
763}
764if (!empty($arrayfields['s.nom']['checked'])) {
765 print '<td class="liste_titre">';
766 print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
767 print '</td>';
768}
769if (!empty($arrayfields['s.email']['checked'])) {
770 print '<td class="liste_titre">';
771 print '<input type="text" class="flat" size="6" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
772 print '</td>';
773}
774// Town
775if (!empty($arrayfields['s.town']['checked'])) {
776 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
777}
778// Zip
779if (!empty($arrayfields['s.zip']['checked'])) {
780 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
781}
782// State
783if (!empty($arrayfields['state.nom']['checked'])) {
784 print '<td class="liste_titre">';
785 print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
786 print '</td>';
787}
788// Country
789if (!empty($arrayfields['country.code_iso']['checked'])) {
790 print '<td class="liste_titre center">';
791 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
792 print '</td>';
793}
794// Company type
795if (!empty($arrayfields['typent.code']['checked'])) {
796 print '<td class="liste_titre maxwidthonsmartphone center">';
797 print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
798 print '</td>';
799}
800if (!empty($arrayfields['sale_representative']['checked'])) {
801 print '<td class="liste_titre"></td>';
802}
803if (!empty($arrayfields['c.date_contrat']['checked'])) {
804 print '<td class="liste_titre center">';
805 print '<div class="nowrap">';
806 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
807 print '</div>';
808 print '<div class="nowrap">';
809 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
810 print '</div>';
811 print '</td>';
812}
813// Extra fields
814include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
815
816// Fields from hook
817$parameters = array('arrayfields'=>$arrayfields);
818$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
819print $hookmanager->resPrint;
820// Date creation
821if (!empty($arrayfields['c.datec']['checked'])) {
822 print '<td class="liste_titre">';
823 print '</td>';
824}
825// Date modification
826if (!empty($arrayfields['c.tms']['checked'])) {
827 print '<td class="liste_titre">';
828 print '</td>';
829}
830// First end date
831if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
832 print '<td class="liste_titre nowraponall center">';
833 $arrayofoperators = array('0'=>'', '='=>'=', '<='=>'<=', '>='=>'>=');
834 print $form->selectarray('search_op2df', $arrayofoperators, $search_op2df, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth50imp');
835 print '</br>';
836 print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0);
837 print ' ';
838 print $formother->selectyear($search_dfyear, 'search_dfyear', 1, 20, 5, 0, 0, '');
839 print '</td>';
840}
841// Status
842if (!empty($arrayfields['status']['checked'])) {
843 print '<td class="liste_titre right" colspan="4"></td>';
844}
845
846// Action column
847if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
848 print '<td class="liste_titre center">';
849 $searchpicto = $form->showFilterButtons();
850 print $searchpicto;
851 print '</td>';
852}
853print '</tr>'."\n";
854
855$totalarray = array();
856$totalarray['nbfield'] = 0;
857
858// Fields title label
859// --------------------------------------------------------------------
860print '<tr class="liste_titre">';
861if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
862 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
863 $totalarray['nbfield']++; // For the column action
864}
865if (!empty($arrayfields['c.ref']['checked'])) {
866 print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);
867 $totalarray['nbfield']++; // For the column action
868}
869if (!empty($arrayfields['c.ref_customer']['checked'])) {
870 print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer", "", $param, '', $sortfield, $sortorder);
871 $totalarray['nbfield']++; // For the column action
872}
873if (!empty($arrayfields['c.ref_supplier']['checked'])) {
874 print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier", "", $param, '', $sortfield, $sortorder);
875 $totalarray['nbfield']++; // For the column action
876}
877if (!empty($arrayfields['s.nom']['checked'])) {
878 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
879 $totalarray['nbfield']++; // For the column action
880}
881if (!empty($arrayfields['s.email']['checked'])) {
882 print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder);
883 $totalarray['nbfield']++; // For the column action
884}
885if (!empty($arrayfields['s.town']['checked'])) {
886 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
887 $totalarray['nbfield']++; // For the column action
888}
889if (!empty($arrayfields['s.zip']['checked'])) {
890 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
891 $totalarray['nbfield']++; // For the column action
892}
893if (!empty($arrayfields['state.nom']['checked'])) {
894 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
895 $totalarray['nbfield']++; // For the column action
896}
897if (!empty($arrayfields['country.code_iso']['checked'])) {
898 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
899 $totalarray['nbfield']++; // For the column action
900}
901if (!empty($arrayfields['typent.code']['checked'])) {
902 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
903 $totalarray['nbfield']++; // For the column action
904}
905if (!empty($arrayfields['sale_representative']['checked'])) {
906 print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
907 $totalarray['nbfield']++; // For the column action
908}
909if (!empty($arrayfields['c.date_contrat']['checked'])) {
910 print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat", "", $param, '', $sortfield, $sortorder, 'center ');
911 $totalarray['nbfield']++; // For the column action
912}
913// Extra fields
914include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
915// Hook fields
916$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
917$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
918print $hookmanager->resPrint;
919if (!empty($arrayfields['c.datec']['checked'])) {
920 print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
921 $totalarray['nbfield']++; // For the column action
922}
923if (!empty($arrayfields['c.tms']['checked'])) {
924 print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
925 $totalarray['nbfield']++; // For the column action
926}
927if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
928 print_liste_field_titre($arrayfields['lower_planned_end_date']['label'], $_SERVER["PHP_SELF"], "lower_planned_end_date", "", $param, '', $sortfield, $sortorder, 'center ');
929 $totalarray['nbfield']++; // For the column action
930}
931if (!empty($arrayfields['status']['checked'])) {
932 print_liste_field_titre($staticcontratligne->LibStatut(0, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
933 $totalarray['nbfield']++; // For the column action
934 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 0, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
935 $totalarray['nbfield']++; // For the column action
936 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
937 $totalarray['nbfield']++; // For the column action
938 print_liste_field_titre($staticcontratligne->LibStatut(5, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
939 $totalarray['nbfield']++; // For the column action
940}
941if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
942 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
943 $totalarray['nbfield']++; // For the column action
944}
945print "</tr>\n";
946
947// Loop on record
948// --------------------------------------------------------------------
949$i = 0;
950$savnbfield = $totalarray['nbfield'];
951$totalarray = array();
952$totalarray['nbfield'] = 0;
953$typenArray = array();
954$cacheCountryIDCode = array();
955$imaxinloop = ($limit ? min($num, $limit) : $num);
956while ($i < $imaxinloop) {
957 $obj = $db->fetch_object($resql);
958 if (empty($obj)) {
959 break; // Should not happen
960 }
961
962 $contracttmp->ref = $obj->ref;
963 $contracttmp->id = $obj->rowid;
964 $contracttmp->ref_customer = $obj->ref_customer;
965 $contracttmp->ref_supplier = $obj->ref_supplier;
966
967 $contracttmp->nbofserviceswait = $obj->nb_initial;
968 $contracttmp->nbofservicesopened = $obj->nb_running;
969 $contracttmp->nbofservicesexpired = $obj->nb_expired;
970 $contracttmp->nbofservicesclosed = $obj->nb_closed;
971
972 $socstatic->id = $obj->socid;
973 $socstatic->name = $obj->name;
974 $socstatic->name_alias = $obj->name_alias;
975 $socstatic->email = $obj->email;
976 $socstatic->status = $obj->company_status;
977 $socstatic->logo = $obj->company_logo;
978 $socstatic->country_id = $obj->country_id;
979 $socstatic->country_code = '';
980 $socstatic->country = '';
981
982 if ($obj->country_id > 0) {
983 if (!isset($cacheCountryIDCode[$obj->country_id]['code'])) {
984 $tmparray = getCountry($obj->country_id, 'all');
985 $cacheCountryIDCode[$obj->country_id] = array('code'=> empty($tmparray['code']) ? '' : $tmparray['code'], 'label' => empty($tmparray['label']) ? '' : $tmparray['label']);
986 }
987 $socstatic->country_code = $cacheCountryIDCode[$obj->country_id]['code'];
988 $socstatic->country = $cacheCountryIDCode[$obj->country_id]['label'];
989 }
990
991 if ($mode == 'kanban') {
992 if ($i == 0) {
993 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
994 print '<div class="box-flex-container kanban">';
995 }
996 // Output Kanban
997 $arraydata['thirdparty'] = $socstatic;
998 $arraydata['selected'] = in_array($obj->rowid, $arrayofselected);
999 $contracttmp->date_contrat = $obj->date_contrat;
1000 print $contracttmp->getKanbanView('', $arraydata);
1001 if ($i == ($imaxinloop - 1)) {
1002 print '</div>';
1003 print '</td></tr>';
1004 }
1005 } else {
1006 // Show here line of result
1007 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
1008 // Action column
1009 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1010 print '<td class="nowrap center">';
1011 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1012 $selected = 0;
1013 if (in_array($obj->rowid, $arrayofselected)) {
1014 $selected = 1;
1015 }
1016 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1017 }
1018 print '</td>';
1019 if (!$i) {
1020 $totalarray['nbfield']++;
1021 }
1022 }
1023 // Ref
1024 if (!empty($arrayfields['c.ref']['checked'])) {
1025 print '<td class="nowraponall">';
1026 print $contracttmp->getNomUrl(1);
1027 if ($obj->nb_late) {
1028 print img_warning($langs->trans("Late"));
1029 }
1030 if (!empty($obj->note_private) || !empty($obj->note_public)) {
1031 print ' <span class="note">';
1032 print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"), 'note').'</a>';
1033 print '</span>';
1034 }
1035
1036 $filename = dol_sanitizeFileName($obj->ref);
1037 $filedir = $conf->contrat->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
1038 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1039 print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
1040 print '</td>';
1041
1042 print '</td>';
1043 if (!$i) {
1044 $totalarray['nbfield']++;
1045 }
1046 }
1047
1048 // Ref thirdparty
1049 if (!empty($arrayfields['c.ref_customer']['checked'])) {
1050 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag(dol_string_nohtmltag($contracttmp->getFormatedCustomerRef($obj->ref_customer))).'">'.$contracttmp->getFormatedCustomerRef($obj->ref_customer).'</td>';
1051 if (!$i) {
1052 $totalarray['nbfield']++;
1053 }
1054 }
1055 if (!empty($arrayfields['c.ref_supplier']['checked'])) {
1056 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>';
1057 }
1058 if (!empty($arrayfields['s.nom']['checked'])) {
1059 print '<td class="tdoverflowmax150">';
1060 if ($obj->socid > 0) {
1061 // TODO Use a cache for this string
1062 print $socstatic->getNomUrl(1, '');
1063 }
1064 print '</td>';
1065 }
1066 // Email
1067 if (!empty($arrayfields['s.email']['checked'])) {
1068 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->email).'">'.dol_print_email($obj->email, 0, $obj->socid, 0, 0, 1, 1).'</td>';
1069 }
1070 // Town
1071 if (!empty($arrayfields['s.town']['checked'])) {
1072 print '<td class="nocellnopadd">';
1073 print $obj->town;
1074 print '</td>';
1075 if (!$i) {
1076 $totalarray['nbfield']++;
1077 }
1078 }
1079 // Zip
1080 if (!empty($arrayfields['s.zip']['checked'])) {
1081 print '<td class="nocellnopadd">';
1082 print $obj->zip;
1083 print '</td>';
1084 if (!$i) {
1085 $totalarray['nbfield']++;
1086 }
1087 }
1088 // State
1089 if (!empty($arrayfields['state.nom']['checked'])) {
1090 print "<td>".$obj->state_name."</td>\n";
1091 if (!$i) {
1092 $totalarray['nbfield']++;
1093 }
1094 }
1095 // Country
1096 if (!empty($arrayfields['country.code_iso']['checked'])) {
1097 print '<td class="center tdoverflowmax100" title="'.dol_escape_htmltag($socstatic->country).'">';
1098 print dol_escape_htmltag($socstatic->country);
1099 print '</td>';
1100 if (!$i) {
1101 $totalarray['nbfield']++;
1102 }
1103 }
1104 // Type ent
1105 if (!empty($arrayfields['typent.code']['checked'])) {
1106 print '<td class="center">';
1107 if (count($typenArray) == 0) {
1108 $typenArray = $formcompany->typent_array(1);
1109 }
1110 print $typenArray[$obj->typent_code];
1111 print '</td>';
1112 if (!$i) {
1113 $totalarray['nbfield']++;
1114 }
1115 }
1116 if (!empty($arrayfields['sale_representative']['checked'])) {
1117 // Sales representatives
1118 print '<td>';
1119 if ($obj->socid > 0) {
1120 $listsalesrepresentatives = $socstatic->getSalesRepresentatives($user);
1121 if ($listsalesrepresentatives < 0) {
1122 dol_print_error($db);
1123 }
1124 $nbofsalesrepresentative = count($listsalesrepresentatives);
1125 if ($nbofsalesrepresentative > 6) {
1126 // We print only number
1127 print $nbofsalesrepresentative;
1128 } elseif ($nbofsalesrepresentative > 0) {
1129 $userstatic = new User($db);
1130 $j = 0;
1131 foreach ($listsalesrepresentatives as $val) {
1132 $userstatic->id = $val['id'];
1133 $userstatic->lastname = $val['lastname'];
1134 $userstatic->firstname = $val['firstname'];
1135 $userstatic->email = $val['email'];
1136 $userstatic->statut = $val['statut'];
1137 $userstatic->entity = $val['entity'];
1138 $userstatic->photo = $val['photo'];
1139 $userstatic->login = $val['login'];
1140 $userstatic->phone = $val['phone'];
1141 $userstatic->job = $val['job'];
1142 $userstatic->gender = $val['gender'];
1143
1144 //print '<div class="float">':
1145 print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
1146 $j++;
1147 if ($j < $nbofsalesrepresentative) {
1148 print ' ';
1149 }
1150 //print '</div>';
1151 }
1152 }
1153 //else print $langs->trans("NoSalesRepresentativeAffected");
1154 } else {
1155 print '&nbsp;';
1156 }
1157 print '</td>';
1158 }
1159 // Date
1160 if (!empty($arrayfields['c.date_contrat']['checked'])) {
1161 print '<td class="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzserver').'</td>';
1162 }
1163 // Extra fields
1164 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1165 // Fields from hook
1166 $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1167 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1168 print $hookmanager->resPrint;
1169 // Date creation
1170 if (!empty($arrayfields['c.datec']['checked'])) {
1171 print '<td class="center nowrap">';
1172 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1173 print '</td>';
1174 if (!$i) {
1175 $totalarray['nbfield']++;
1176 }
1177 }
1178 // Date modification
1179 if (!empty($arrayfields['c.tms']['checked'])) {
1180 print '<td class="center nowrap">';
1181 print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1182 print '</td>';
1183 if (!$i) {
1184 $totalarray['nbfield']++;
1185 }
1186 }
1187 // Date lower end date
1188 if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
1189 print '<td class="center nowrapforall">';
1190 print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
1191 print '</td>';
1192 if (!$i) {
1193 $totalarray['nbfield']++;
1194 }
1195 }
1196 // Status
1197 if (!empty($arrayfields['status']['checked'])) {
1198 print '<td class="center">'.($obj->nb_initial > 0 ? $obj->nb_initial : '').'</td>';
1199 print '<td class="center">'.($obj->nb_running > 0 ? $obj->nb_running : '').'</td>';
1200 print '<td class="center">'.($obj->nb_expired > 0 ? $obj->nb_expired : '').'</td>';
1201 print '<td class="center">'.($obj->nb_closed > 0 ? $obj->nb_closed : '').'</td>';
1202 if (!$i) {
1203 $totalarray['nbfield']++;
1204 $totalarray['nbfield']++;
1205 $totalarray['nbfield']++;
1206 $totalarray['nbfield']++;
1207 }
1208 }
1209 // Action column
1210 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1211 print '<td class="nowrap center">';
1212 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1213 $selected = 0;
1214 if (in_array($obj->rowid, $arrayofselected)) {
1215 $selected = 1;
1216 }
1217 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1218 }
1219 print '</td>';
1220 if (!$i) {
1221 $totalarray['nbfield']++;
1222 }
1223 }
1224
1225 print '</tr>'."\n";
1226 }
1227 $i++;
1228}
1229
1230// If no record found
1231if ($num == 0) {
1232 $colspan = 4; // Include the 4 columns of status
1233 foreach ($arrayfields as $key => $val) {
1234 if (!empty($val['checked'])) {
1235 $colspan++;
1236 }
1237 }
1238 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1239}
1240
1241$db->free($resql);
1242
1243$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1244$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1245print $hookmanager->resPrint;
1246
1247print '</table>'."\n";
1248print '</div>'."\n";
1249
1250print '</form>'."\n";
1251
1252$hidegeneratedfilelistifempty = 1;
1253if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1254 $hidegeneratedfilelistifempty = 0;
1255}
1256
1257// Show list of available documents
1258$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1259$urlsource .= str_replace('&amp;', '&', $param);
1260
1261$filedir = $diroutputmassaction;
1262$genallowed = $permissiontoread;
1263$delallowed = $permissiontoadd;
1264
1265print $formfile->showdocuments('massfilesarea_contract', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1266
1267
1268llxFooter();
1269$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage contracts.
Class to manage lines of contracts.
Class to manage standard extra fields.
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='', $elemtype='', $placeholder='', $addjscombo=-1)
Show a multiselect form from an array.
Classe permettant la generation de composants html autre Only common components are here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $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:578
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:597
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
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.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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, $mode=0)
Check permissions of a user to show a page and an object.