37 require
'../main.inc.php';
38 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
45 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
49 $langs->loadLangs(array(
'contracts',
'products',
'companies',
'compta'));
51 $action =
GETPOST(
'action',
'aZ09');
52 $massaction =
GETPOST(
'massaction',
'alpha');
54 $confirm =
GETPOST(
'confirm',
'alpha');
55 $toselect =
GETPOST(
'toselect',
'array');
56 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'contractlist';
57 $optioncss =
GETPOST(
'optioncss',
'alpha');
58 $mode =
GETPOST(
'mode',
'alpha');
62 $search_name =
GETPOST(
'search_name',
'alpha');
63 $search_email =
GETPOST(
'search_email',
'alpha');
64 $search_town =
GETPOST(
'search_town',
'alpha');
65 $search_zip =
GETPOST(
'search_zip',
'alpha');
66 $search_state =
GETPOST(
"search_state",
'alpha');
67 $search_country =
GETPOST(
"search_country",
'aZ09');
68 $search_type_thirdparty =
GETPOST(
"search_type_thirdparty",
'intcomma');
69 $search_contract =
GETPOST(
'search_contract',
'alpha');
70 $search_ref_customer =
GETPOST(
'search_ref_customer',
'alpha');
71 $search_ref_supplier =
GETPOST(
'search_ref_supplier',
'alpha');
72 $search_all = (
GETPOST(
'search_all',
'alphanohtml') !=
'') ?
GETPOST(
'search_all',
'alphanohtml') :
GETPOST(
'sall',
'alphanohtml');
73 $search_status =
GETPOST(
'search_status',
'alpha');
74 $search_user =
GETPOST(
'search_user',
'intcomma');
75 $search_sale =
GETPOST(
'search_sale',
'intcomma');
76 $search_product_category =
GETPOST(
'search_product_category',
'intcomma');
77 $search_dfmonth =
GETPOSTINT(
'search_dfmonth');
79 $search_op2df =
GETPOST(
'search_op2df',
'alpha');
80 $search_date_startday =
GETPOSTINT(
'search_date_startday');
81 $search_date_startmonth =
GETPOSTINT(
'search_date_startmonth');
82 $search_date_startyear =
GETPOSTINT(
'search_date_startyear');
83 $search_date_endday =
GETPOSTINT(
'search_date_endday');
84 $search_date_endmonth =
GETPOSTINT(
'search_date_endmonth');
85 $search_date_endyear =
GETPOSTINT(
'search_date_endyear');
86 $search_date_start =
dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
87 $search_date_end =
dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
88 $searchCategoryCustomerOperator = 0;
90 $searchCategoryCustomerOperator =
GETPOSTINT(
'search_category_customer_operator');
94 $searchCategoryCustomerList =
GETPOST(
'search_category_customer_list',
'array');
96 $search_date_creation_startmonth =
GETPOSTINT(
'search_date_creation_startmonth');
97 $search_date_creation_startyear =
GETPOSTINT(
'search_date_creation_startyear');
98 $search_date_creation_startday =
GETPOSTINT(
'search_date_creation_startday');
99 $search_date_creation_start =
dol_mktime(0, 0, 0, $search_date_creation_startmonth, $search_date_creation_startday, $search_date_creation_startyear);
100 $search_date_creation_endmonth =
GETPOSTINT(
'search_date_creation_endmonth');
101 $search_date_creation_endyear =
GETPOSTINT(
'search_date_creation_endyear');
102 $search_date_creation_endday =
GETPOSTINT(
'search_date_creation_endday');
103 $search_date_creation_end =
dol_mktime(23, 59, 59, $search_date_creation_endmonth, $search_date_creation_endday, $search_date_creation_endyear);
105 $search_date_modif_startmonth =
GETPOSTINT(
'search_date_modif_startmonth');
106 $search_date_modif_startyear =
GETPOSTINT(
'search_date_modif_startyear');
107 $search_date_modif_startday =
GETPOSTINT(
'search_date_modif_startday');
108 $search_date_modif_start =
dol_mktime(0, 0, 0, $search_date_modif_startmonth, $search_date_modif_startday, $search_date_modif_startyear);
109 $search_date_modif_endmonth =
GETPOSTINT(
'search_date_modif_endmonth');
110 $search_date_modif_endyear =
GETPOSTINT(
'search_date_modif_endyear');
111 $search_date_modif_endday =
GETPOSTINT(
'search_date_modif_endday');
112 $search_date_modif_end =
dol_mktime(23, 59, 59, $search_date_modif_endmonth, $search_date_modif_endday, $search_date_modif_endyear);
116 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
117 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
119 if (empty($page) || $page < 0 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
123 $offset = $limit * $page;
124 $pageprev = $page - 1;
125 $pagenext = $page + 1;
127 $sortfield =
'c.ref';
135 if ($user->socid > 0) {
136 $socid = $user->socid;
140 $diroutputmassaction = $conf->contrat->dir_output.
'/temp/massgeneration/'.$user->id;
142 $staticcontrat =
new Contrat($db);
145 if ($search_status ==
'') {
151 $hookmanager->initHooks(array(
'contractlist'));
155 $extrafields->fetch_name_optionals_label(
$object->table_element);
157 $search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
159 $fieldstosearchall = array();
160 foreach (
$object->fields as $key => $val) {
161 if (!empty($val[
'searchall'])) {
162 $fieldstosearchall[
'c.'.$key] = $val[
'label'];
165 $fieldstosearchall[
"s.nom"] =
"ThirdParty";
166 if (empty($user->socid)) {
167 $fieldstosearchall[
"c.note_private"] =
"NotePrivate";
169 $parameters = array(
'fieldstosearchall' => $fieldstosearchall);
170 $reshook = $hookmanager->executeHooks(
'completeFieldsToSearchAll', $parameters,
$object, $action);
172 $fieldstosearchall = $hookmanager->resArray[
'fieldstosearchall'];
173 } elseif ($reshook == 0) {
174 if (!empty($hookmanager->resArray[
'fieldstosearchall'])) {
175 $fieldstosearchall = array_merge($fieldstosearchall, $hookmanager->resArray[
'fieldstosearchall']);
179 $arrayfields = array(
180 'c.ref' => array(
'label' => $langs->trans(
"Ref"),
'checked' => 1,
'position' => 10),
181 'c.ref_customer' => array(
'label' => $langs->trans(
"RefCustomer"),
'checked' => 1,
'position' => 12),
182 'c.ref_supplier' => array(
'label' => $langs->trans(
"RefSupplier"),
'checked' => 1,
'position' => 14),
183 's.nom' => array(
'label' => $langs->trans(
"ThirdParty"),
'checked' => 1,
'position' => 30),
184 's.email' => array(
'label' => $langs->trans(
"ThirdPartyEmail"),
'checked' => 0,
'position' => 30),
185 's.town' => array(
'label' => $langs->trans(
"Town"),
'checked' => 0,
'position' => 31),
186 's.zip' => array(
'label' => $langs->trans(
"Zip"),
'checked' => 1,
'position' => 32),
187 'state.nom' => array(
'label' => $langs->trans(
"StateShort"),
'checked' => 0,
'position' => 33),
188 'country.code_iso' => array(
'label' => $langs->trans(
"Country"),
'checked' => 0,
'position' => 34),
189 'sale_representative' => array(
'label' => $langs->trans(
"SaleRepresentativesOfThirdParty"),
'checked' => -1,
'position' => 80),
190 'c.date_contrat' => array(
'label' => $langs->trans(
"DateContract"),
'checked' => 1,
'position' => 45),
191 'c.datec' => array(
'label' => $langs->trans(
"DateCreation"),
'checked' => 0,
'position' => 500),
192 'c.tms' => array(
'label' => $langs->trans(
"DateModificationShort"),
'checked' => 0,
'position' => 500),
193 'lower_planned_end_date' => array(
'label' => $langs->trans(
"LowerDateEndPlannedShort"),
'checked' => 1,
'position' => 900,
'help' => $langs->trans(
"LowerDateEndPlannedShort")),
194 'status' => array(
'label' => $langs->trans(
"Status"),
'checked' => 1,
'position' => 1000),
197 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_array_fields.tpl.php';
201 '@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields';
203 if (!$user->hasRight(
'societe',
'client',
'voir')) {
204 $search_sale = $user->id;
207 $permissiontoread = $user->hasRight(
'contrat',
'lire');
208 $permissiontoadd = $user->hasRight(
'contrat',
'creer');
209 $permissiontodelete = $user->hasRight(
'contrat',
'supprimer');
219 if (
GETPOST(
'cancel',
'alpha')) {
223 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
227 $parameters = array(
'socid' => $socid,
'arrayfields' => &$arrayfields);
228 $reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
233 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
235 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
236 $search_dfmonth =
'';
245 $search_country =
'';
246 $search_contract =
"";
247 $search_ref_customer =
"";
248 $search_ref_supplier =
"";
251 $search_product_category =
'';
252 $search_date_startday =
'';
253 $search_date_startmonth =
'';
254 $search_date_startyear =
'';
255 $search_date_endday =
'';
256 $search_date_endmonth =
'';
257 $search_date_endyear =
'';
258 $search_date_start =
'';
259 $search_date_end =
'';
261 $search_date_creation_startmonth =
"";
262 $search_date_creation_startyear =
"";
263 $search_date_creation_startday =
"";
264 $search_date_creation_start =
"";
265 $search_date_creation_endmonth =
"";
266 $search_date_creation_endyear =
"";
267 $search_date_creation_endday =
"";
268 $search_date_creation_end =
"";
269 $search_date_modif_startmonth =
"";
270 $search_date_modif_startyear =
"";
271 $search_date_modif_startday =
"";
272 $search_date_modif_start =
"";
273 $search_date_modif_endmonth =
"";
274 $search_date_modif_endyear =
"";
275 $search_date_modif_endday =
"";
276 $search_date_modif_end =
"";
279 $search_type_thirdparty =
'';
280 $searchCategoryCustomerList = array();
281 $search_array_options = array();
284 if (empty($reshook)) {
285 $objectclass =
'Contrat';
286 $objectlabel =
'Contracts';
287 $uploaddir = $conf->contrat->dir_output;
288 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
296 $form =
new Form($db);
301 $contracttmp =
new Contrat($db);
308 $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,";
309 $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,';
310 $sql .=
" typent.code as typent_code,";
311 $sql .=
" state.code_departement as state_code, state.nom as state_name,";
312 $sql .=
" MIN(".$db->ifsql(
"cd.statut=4",
"cd.date_fin_validite",
"null").
") as lower_planned_end_date,";
313 $sql .=
" SUM(".$db->ifsql(
"cd.statut=0", 1, 0).
') as nb_initial,';
314 $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,';
315 $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,';
316 $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,';
317 $sql .=
" SUM(".$db->ifsql(
"cd.statut=5", 1, 0).
') as nb_closed';
319 if (!empty($extrafields->attributes[
$object->table_element][
'label'])) {
320 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $val) {
321 $sql .= ($extrafields->attributes[
$object->table_element][
'type'][$key] !=
'separate' ?
", ef.".$key.
" as options_".$key :
'');
325 $parameters = array();
326 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters,
$object, $action);
327 $sql .= $hookmanager->resPrint;
328 $sql = preg_replace(
'/,\s*$/',
'',
$sql);
332 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
333 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as country on (country.rowid = s.fk_pays)";
334 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_typent as typent on (typent.id = s.fk_typent)";
335 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as state on (state.rowid = s.fk_departement)";
336 $sql .=
", ".MAIN_DB_PREFIX.
"contrat as c";
337 if (!empty($extrafields->attributes[
$object->table_element][
'label']) && is_array($extrafields->attributes[
$object->table_element][
'label']) && count($extrafields->attributes[
$object->table_element][
'label'])) {
338 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as ef on (c.rowid = ef.fk_object)";
340 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd ON c.rowid = cd.fk_contrat";
341 if ($search_user > 0) {
342 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
343 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as tc";
345 $sql .=
" WHERE c.fk_soc = s.rowid ";
346 $sql .=
' AND c.entity IN ('.getEntity(
'contract').
')';
347 if ($search_type_thirdparty !=
'' && $search_type_thirdparty > 0) {
348 $sql .=
" AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).
')';
351 $sql .=
" AND s.rowid = ".((int) $socid);
353 if ($search_date_start) {
354 $sql .=
" AND c.date_contrat >= '".$db->idate($search_date_start).
"'";
356 if ($search_date_end) {
357 $sql .=
" AND c.date_contrat <= '".$db->idate($search_date_end).
"'";
365 if ($search_contract) {
368 if (!empty($search_ref_customer)) {
371 if (!empty($search_ref_supplier)) {
380 if ($search_country && $search_country !=
'-1') {
381 $sql .=
" AND s.fk_pays IN (".$db->sanitize($search_country).
')';
389 if ($search_user > 0) {
390 $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);
393 if ($search_sale && $search_sale !=
'-1') {
394 if ($search_sale == -2) {
395 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";
396 } elseif ($search_sale > 0) {
397 $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).
")";
401 $searchCategoryProductOperator = -1;
402 $searchCategoryProductList = array($search_product_category);
403 if (!empty($searchCategoryProductList)) {
404 $searchCategoryProductSqlList = array();
405 $listofcategoryid =
'';
406 foreach ($searchCategoryProductList as $searchCategoryProduct) {
407 if (intval($searchCategoryProduct) == -2) {
408 $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)";
409 } elseif (intval($searchCategoryProduct) > 0) {
410 if ($searchCategoryProductOperator == 0) {
411 $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).
")";
413 $listofcategoryid .= ($listofcategoryid ?
', ' :
'') .((
int) $searchCategoryProduct);
417 if ($listofcategoryid) {
418 $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).
"))";
420 if ($searchCategoryProductOperator == 1) {
421 if (!empty($searchCategoryProductSqlList)) {
422 $sql .=
" AND (".implode(
' OR ', $searchCategoryProductSqlList).
")";
425 if (!empty($searchCategoryProductSqlList)) {
426 $sql .=
" AND (".implode(
' AND ', $searchCategoryProductSqlList).
")";
430 $searchCategoryCustomerSqlList = array();
431 if ($searchCategoryCustomerOperator == 1) {
432 $existsCategoryCustomerList = array();
433 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
434 if (intval($searchCategoryCustomer) == -2) {
435 $sqlCategoryCustomerNotExists =
" NOT EXISTS (";
436 $sqlCategoryCustomerNotExists .=
" SELECT cat_cus.fk_soc";
437 $sqlCategoryCustomerNotExists .=
" FROM ".$db->prefix().
"categorie_societe AS cat_cus";
438 $sqlCategoryCustomerNotExists .=
" WHERE cat_cus.fk_soc = s.rowid";
439 $sqlCategoryCustomerNotExists .=
" )";
440 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
441 } elseif (intval($searchCategoryCustomer) > 0) {
442 $existsCategoryCustomerList[] = $db->escape($searchCategoryCustomer);
445 if (!empty($existsCategoryCustomerList)) {
446 $sqlCategoryCustomerExists =
" EXISTS (";
447 $sqlCategoryCustomerExists .=
" SELECT cat_cus.fk_soc";
448 $sqlCategoryCustomerExists .=
" FROM ".$db->prefix().
"categorie_societe AS cat_cus";
449 $sqlCategoryCustomerExists .=
" WHERE cat_cus.fk_soc = s.rowid";
450 $sqlCategoryCustomerExists .=
" AND cat_cus.fk_categorie IN (".$db->sanitize(implode(
',', $existsCategoryCustomerList)).
")";
451 $sqlCategoryCustomerExists .=
" )";
452 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerExists;
454 if (!empty($searchCategoryCustomerSqlList)) {
455 $sql .=
" AND (".implode(
' OR ', $searchCategoryCustomerSqlList).
")";
458 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
459 if (intval($searchCategoryCustomer) == -2) {
460 $sqlCategoryCustomerNotExists =
" NOT EXISTS (";
461 $sqlCategoryCustomerNotExists .=
" SELECT cat_cus.fk_soc";
462 $sqlCategoryCustomerNotExists .=
" FROM ".$db->prefix().
"categorie_societe AS cat_cus";
463 $sqlCategoryCustomerNotExists .=
" WHERE cat_cus.fk_soc = s.rowid";
464 $sqlCategoryCustomerNotExists .=
" )";
465 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
466 } elseif (intval($searchCategoryCustomer) > 0) {
467 $searchCategoryCustomerSqlList[] =
"s.rowid IN (SELECT fk_soc FROM ".$db->prefix().
"categorie_societe WHERE fk_categorie = ".((int) $searchCategoryCustomer).
")";
470 if (!empty($searchCategoryCustomerSqlList)) {
471 $sql .=
" AND (".implode(
' AND ', $searchCategoryCustomerSqlList).
")";
475 if ($search_date_creation_start) {
476 $sql .=
" AND c.datec >= '".$db->idate($search_date_creation_start).
"'";
478 if ($search_date_creation_end) {
479 $sql .=
" AND c.datec <= '".$db->idate($search_date_creation_end).
"'";
482 if ($search_date_modif_start) {
483 $sql .=
" AND c.tms >= '".$db->idate($search_date_modif_start).
"'";
485 if ($search_date_modif_end) {
486 $sql .=
" AND c.tms <= '".$db->idate($search_date_modif_end).
"'";
490 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
492 $parameters = array();
493 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters,
$object, $action);
494 $sql .= $hookmanager->resPrint;
495 $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,";
496 $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,';
497 $sql .=
" typent.code,";
498 $sql .=
" state.code_departement, state.nom";
500 if (!empty($extrafields->attributes[
$object->table_element][
'label'])) {
501 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $val) {
502 $sql .= ($extrafields->attributes[
$object->table_element][
'type'][$key] !=
'separate' ?
", ef.".$key :
'');
506 $parameters = array(
'search_dfyear' => $search_dfyear,
'search_op2df' => $search_op2df);
507 $reshook = $hookmanager->executeHooks(
'printFieldListGroupBy', $parameters,
$object);
508 $sql .= $hookmanager->resPrint;
510 $parameters = array(
'search_dfyear' => $search_dfyear,
'search_op2df' => $search_op2df);
511 $reshook = $hookmanager->executeHooks(
'printFieldListHaving', $parameters,
$object, $action);
512 if (empty($reshook)) {
513 if ($search_dfyear > 0 && $search_op2df) {
514 if ($search_op2df ==
'<=') {
515 $sql .=
" HAVING MIN(".$db->ifsql(
"cd.statut=4",
"cd.date_fin_validite",
"null").
") <= '".$db->idate(
dol_get_last_day($search_dfyear, $search_dfmonth,
false)).
"'";
516 } elseif ($search_op2df ==
'>=') {
517 $sql .=
" HAVING MIN(".$db->ifsql(
"cd.statut=4",
"cd.date_fin_validite",
"null").
") >= '".$db->idate(
dol_get_first_day($search_dfyear, $search_dfmonth,
false)).
"'";
519 $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)).
"'";
523 $sql .= $hookmanager->resPrint;
526 $nbtotalofrecords =
'';
531 if ($search_dfyear > 0 && $search_op2df) {
532 $resql = $db->query(
$sql, 0,
'auto', 1);
533 while ($db->fetch_object($resql)) {
534 if (empty($nbtotalofrecords)) {
535 $nbtotalofrecords = 1;
542 $sqlforcount = preg_replace(
'/^'.preg_quote($sqlfields,
'/').
'/',
'SELECT COUNT(*) as nbtotalofrecords',
$sql);
543 $sqlforcount = preg_replace(
'/LEFT JOIN '.MAIN_DB_PREFIX.
'contratdet as cd ON c.rowid = cd.fk_contrat /',
'', $sqlforcount);
544 $sqlforcount = preg_replace(
'/GROUP BY.*$/',
'', $sqlforcount);
546 $resql = $db->query($sqlforcount);
548 $objforcount = $db->fetch_object($resql);
549 $nbtotalofrecords = $objforcount->nbtotalofrecords;
555 if (($page * $limit) > $nbtotalofrecords) {
563 $sql .= $db->order($sortfield, $sortorder);
565 $sql .= $db->plimit($limit + 1, $offset);
568 $resql = $db->query(
$sql);
574 $num = $db->num_rows($resql);
577 if ($num == 1 &&
getDolGlobalString(
'MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
578 $obj = $db->fetch_object($resql);
580 header(
"Location: ".DOL_URL_ROOT.
'/contrat/card.php?id='.$id);
588 llxHeader(
'', $langs->trans(
"Contracts"));
592 $arrayofselected = is_array($toselect) ? $toselect : array();
597 if (empty($search_name)) {
598 $search_name = $soc->name;
604 $param .=
'&mode='.urlencode($mode);
606 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
607 $param .=
'&contextpage='.urlencode($contextpage);
609 if ($limit > 0 && $limit != $conf->liste_limit) {
610 $param .=
'&limit='.((int) $limit);
612 if ($search_all !=
'') {
613 $param .=
'&search_all='.urlencode($search_all);
615 if ($search_contract !=
'') {
616 $param .=
'&search_contract='.urlencode($search_contract);
618 if ($search_name !=
'') {
619 $param .=
'&search_name='.urlencode($search_name);
621 if ($search_email !=
'') {
622 $param .=
'&search_email='.urlencode($search_email);
624 if ($search_ref_customer !=
'') {
625 $param .=
'&search_ref_customer='.urlencode($search_ref_customer);
627 if ($search_ref_supplier !=
'') {
628 $param .=
'&search_ref_supplier='.urlencode($search_ref_supplier);
630 if ($search_op2df !=
'') {
631 $param .=
'&search_op2df='.urlencode($search_op2df);
633 if ($search_date_creation_startmonth) {
634 $param .=
'&search_date_creation_startmonth='.urlencode((
string) ($search_date_creation_startmonth));
636 if ($search_date_creation_startyear) {
637 $param .=
'&search_date_creation_startyear='.urlencode((
string) ($search_date_creation_startyear));
639 if ($search_date_creation_startday) {
640 $param .=
'&search_date_creation_startday='.urlencode((
string) ($search_date_creation_startday));
642 if ($search_date_creation_start) {
643 $param .=
'&search_date_creation_start='.urlencode($search_date_creation_start);
645 if ($search_date_creation_endmonth) {
646 $param .=
'&search_date_creation_endmonth='.urlencode((
string) ($search_date_creation_endmonth));
648 if ($search_date_creation_endyear) {
649 $param .=
'&search_date_creation_endyear='.urlencode((
string) ($search_date_creation_endyear));
651 if ($search_date_creation_endday) {
652 $param .=
'&search_date_creation_endday='.urlencode((
string) ($search_date_creation_endday));
654 if ($search_date_creation_end) {
655 $param .=
'&search_date_creation_end='.urlencode($search_date_creation_end);
657 if ($search_date_modif_startmonth) {
658 $param .=
'&search_date_modif_startmonth='.urlencode((
string) ($search_date_modif_startmonth));
660 if ($search_date_modif_startyear) {
661 $param .=
'&search_date_modif_startyear='.urlencode((
string) ($search_date_modif_startyear));
663 if ($search_date_modif_startday) {
664 $param .=
'&search_date_modif_startday='.urlencode((
string) ($search_date_modif_startday));
666 if ($search_date_modif_start) {
667 $param .=
'&search_date_modif_start='.urlencode($search_date_modif_start);
669 if ($search_date_modif_endmonth) {
670 $param .=
'&search_date_modif_endmonth='.urlencode((
string) ($search_date_modif_endmonth));
672 if ($search_date_modif_endyear) {
673 $param .=
'&search_date_modif_endyear='.urlencode((
string) ($search_date_modif_endyear));
675 if ($search_date_modif_endday) {
676 $param .=
'&search_date_modif_endday='.urlencode((
string) ($search_date_modif_endday));
678 if ($search_date_modif_end) {
679 $param .=
'&search_date_modif_end=' . urlencode($search_date_modif_end);
681 if ($search_date_startday > 0) {
682 $param .=
'&search_date_startday='.urlencode((
string) ($search_date_startday));
684 if ($search_date_startmonth > 0) {
685 $param .=
'&search_date_startmonth='.urlencode((
string) ($search_date_startmonth));
687 if ($search_date_startyear > 0) {
688 $param .=
'&search_date_startyear='.urlencode((
string) ($search_date_startyear));
690 if ($search_date_endday > 0) {
691 $param .=
'&search_date_endday='.urlencode((
string) ($search_date_endday));
693 if ($search_date_endmonth > 0) {
694 $param .=
'&search_date_endmonth='.urlencode((
string) ($search_date_endmonth));
696 if ($search_date_endyear > 0) {
697 $param .=
'&search_date_endyear='.urlencode((
string) ($search_date_endyear));
699 if ($search_dfyear > 0) {
700 $param .=
'&search_dfyear='.urlencode((
string) ($search_dfyear));
702 if ($search_dfmonth > 0) {
703 $param .=
'&search_dfmonth='.urlencode((
string) ($search_dfmonth));
705 if ($search_sale > 0) {
706 $param .=
'&search_sale='.urlencode($search_sale);
708 if ($search_user > 0) {
709 $param .=
'&search_user='.urlencode((
string) ($search_user));
711 if ($search_type_thirdparty > 0) {
712 $param .=
'&search_type_thirdparty='.urlencode((
string) ($search_type_thirdparty));
714 if ($search_country !=
'') {
715 $param .=
"&search_country=".urlencode($search_country);
717 if ($search_product_category > 0) {
718 $param .=
'&search_product_category='.urlencode((
string) ($search_product_category));
721 $param .=
'&show_files='.urlencode((
string) ($show_files));
723 if ($optioncss !=
'') {
724 $param .=
'&optioncss='.urlencode($optioncss);
726 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
727 $param .=
"&search_category_customer_list[]=".urlencode($searchCategoryCustomer);
730 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_param.tpl.php';
733 $arrayofmassactions = array(
734 'generate_doc' =>
img_picto(
'',
'pdf',
'class="pictofixedwidth"').$langs->trans(
"ReGeneratePDF"),
735 'builddoc' =>
img_picto(
'',
'pdf',
'class="pictofixedwidth"').$langs->trans(
"PDFMerge"),
736 'presend' =>
img_picto(
'',
'email',
'class="pictofixedwidth"').$langs->trans(
"SendByMail"),
738 if (!empty($permissiontodelete)) {
739 $arrayofmassactions[
'predelete'] =
img_picto(
'',
'delete',
'class="pictofixedwidth"').$langs->trans(
"Delete");
741 if (
GETPOSTINT(
'nomassaction') || in_array($massaction, array(
'presend',
'predelete'))) {
742 $arrayofmassactions = array();
744 $massactionbutton = $form->selectMassAction(
'', $arrayofmassactions);
746 $url = DOL_URL_ROOT.
'/contrat/card.php?action=create';
747 if (!empty($socid)) {
748 $url .=
'&socid='.((int) $socid);
751 $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'));
752 $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'));
754 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'NewContractSubscription'),
'',
'fa fa-plus-circle', $url,
'', $user->hasRight(
'contrat',
'creer'));
756 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
'PHP_SELF'].
'">'.
"\n";
757 if ($optioncss !=
'') {
758 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
760 print
'<input type="hidden" name="token" value="'.newToken().
'">';
761 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
762 print
'<input type="hidden" name="action" value="list">';
763 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
764 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
765 print
'<input type="hidden" name="page" value="'.$page.
'">';
766 print
'<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
767 print
'<input type="hidden" name="page_y" value="">';
768 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
771 print_barre_liste($langs->trans(
"Contracts"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
'contract', 0, $newcardbutton,
'', $limit, 0, 0, 1);
773 $topicmail =
"SendContractRef";
774 $modelmail =
"contract";
776 $trackid =
'con'.$object->id;
777 include DOL_DOCUMENT_ROOT.
'/core/tpl/massactions_pre.tpl.php';
781 foreach ($fieldstosearchall as $key => $val) {
782 $fieldstosearchall[$key] = $langs->trans($val);
783 $setupstring .= $key.
"=".$val.
";";
785 print
'<!-- Search done like if CONTRACT_QUICKSEARCH_ON_FIELDS = '.$setupstring.
' -->'.
"\n";
786 print
'<div class="divsearchfieldfilter">'.$langs->trans(
"FilterOnInto", $search_all).implode(
', ', $fieldstosearchall).
'</div>'.
"\n";
792 if ($user->hasRight(
'user',
'user',
'lire')) {
793 $langs->load(
"commercial");
794 $moreforfilter .=
'<div class="divsearchfield">';
795 $tmptitle = $langs->trans(
'ThirdPartiesOfSaleRepresentative');
796 $moreforfilter .=
img_picto($tmptitle,
'user',
'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale,
'search_sale', $user, 0, $tmptitle,
'widthcentpercentminusx maxwidth300');
797 $moreforfilter .=
'</div>';
800 if ($user->hasRight(
'user',
'user',
'lire')) {
801 $moreforfilter .=
'<div class="divsearchfield">';
802 $tmptitle = $langs->trans(
'LinkedToSpecificUsers');
803 $moreforfilter .=
img_picto($tmptitle,
'user',
'class="pictofixedwidth"').$form->select_dolusers($search_user,
'search_user', $tmptitle,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
804 $moreforfilter .=
'</div>';
807 if (
isModEnabled(
'category') && $user->hasRight(
'categorie',
'lire') && ($user->hasRight(
'produit',
'lire') || $user->hasRight(
'service',
'lire'))) {
808 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
809 $moreforfilter .=
'<div class="divsearchfield">';
810 $tmptitle = $langs->trans(
'IncludingProductWithTag');
811 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT,
'',
'parent', 64, 0, 2);
812 $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);
813 $moreforfilter .=
'</div>';
817 $moreforfilter .=
'<div class="divsearchfield">';
818 $tmptitle = $langs->transnoentities(
'CustomersProspectsCategoriesShort');
819 $moreforfilter .=
img_picto($tmptitle,
'category',
'class="pictofixedwidth"');
820 $categoriesArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER,
'',
'', 64, 0, 2);
821 $categoriesArr[-2] =
'- '.$langs->trans(
'NotCategorized').
' -';
822 $moreforfilter .=
Form::multiselectarray(
'search_category_customer_list', $categoriesArr, $searchCategoryCustomerList, 0, 0,
'minwidth300', 0, 0,
'',
'category', $tmptitle);
823 $moreforfilter .=
' <input type="checkbox" class="valignmiddle" id="search_category_customer_operator" name="search_category_customer_operator" value="1"'.($searchCategoryCustomerOperator == 1 ?
' checked="checked"' :
'').
'/>';
824 $moreforfilter .= $form->textwithpicto(
'', $langs->trans(
'UseOrOperatorForCategories') .
' : ' . $tmptitle, 1,
'help',
'', 0, 2,
'tooltip_cat_cus');
825 $moreforfilter .=
'</div>';
828 $parameters = array();
829 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters,
$object, $action);
830 if (empty($reshook)) {
831 $moreforfilter .= $hookmanager->resPrint;
833 $moreforfilter = $hookmanager->resPrint;
836 if (!empty($moreforfilter)) {
837 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
838 print $moreforfilter;
842 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
843 $selectedfields = $form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage,
getDolGlobalString(
'MAIN_CHECKBOX_LEFT_COLUMN'));
844 if ($massactionbutton) {
845 $selectedfields .= $form->showCheckAddButtons(
'checkforselect', 1);
848 print
'<div class="div-table-responsive">';
849 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
853 print
'<tr class="liste_titre_filter">';
856 print
'<td class="liste_titre maxwidthsearch center">';
857 $searchpicto = $form->showFilterButtons(
'left');
861 if (!empty($arrayfields[
'c.ref'][
'checked'])) {
862 print
'<td class="liste_titre">';
863 print
'<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).
'">';
866 if (!empty($arrayfields[
'c.ref_customer'][
'checked'])) {
867 print
'<td class="liste_titre">';
868 print
'<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).
'">';
871 if (!empty($arrayfields[
'c.ref_supplier'][
'checked'])) {
872 print
'<td class="liste_titre">';
873 print
'<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).
'">';
876 if (!empty($arrayfields[
's.nom'][
'checked'])) {
877 print
'<td class="liste_titre">';
878 print
'<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).
'">';
881 if (!empty($arrayfields[
's.email'][
'checked'])) {
882 print
'<td class="liste_titre">';
883 print
'<input type="text" class="flat" size="6" name="search_email" value="'.dol_escape_htmltag($search_email).
'">';
887 if (!empty($arrayfields[
's.town'][
'checked'])) {
888 print
'<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.dol_escape_htmltag($search_town).
'"></td>';
891 if (!empty($arrayfields[
's.zip'][
'checked'])) {
892 print
'<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'"></td>';
895 if (!empty($arrayfields[
'state.nom'][
'checked'])) {
896 print
'<td class="liste_titre">';
897 print
'<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).
'">';
901 if (!empty($arrayfields[
'country.code_iso'][
'checked'])) {
902 print
'<td class="liste_titre center">';
903 print $form->select_country($search_country,
'search_country',
'', 0,
'minwidth100imp maxwidth100');
907 if (!empty($arrayfields[
'typent.code'][
'checked'])) {
908 print
'<td class="liste_titre maxwidthonsmartphone center">';
909 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' : $conf->global->SOCIETE_SORT_ON_TYPEENT),
'', 1);
912 if (!empty($arrayfields[
'sale_representative'][
'checked'])) {
913 print
'<td class="liste_titre"></td>';
915 if (!empty($arrayfields[
'c.date_contrat'][
'checked'])) {
916 print
'<td class="liste_titre center">';
917 print
'<div class="nowrapfordate">';
918 print $form->selectDate($search_date_start ? $search_date_start : -1,
'search_date_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'From'));
920 print
'<div class="nowrapfordate">';
921 print $form->selectDate($search_date_end ? $search_date_end : -1,
'search_date_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'to'));
926 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_input.tpl.php';
929 $parameters = array(
'arrayfields' => $arrayfields);
930 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters,
$object, $action);
931 print $hookmanager->resPrint;
933 if (!empty($arrayfields[
'c.datec'][
'checked'])) {
934 print
'<td class="liste_titre center nowraponall">';
935 print
'<div class="nowrapfordate">';
936 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'));
938 print
'<div class="nowrapfordate">';
939 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'));
944 if (!empty($arrayfields[
'c.tms'][
'checked'])) {
945 print
'<td class="liste_titre center nowraponall">';
946 print
'<div class="nowrapfordate">';
947 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'));
949 print
'<div class="nowrapfordate">';
950 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'));
955 if (!empty($arrayfields[
'lower_planned_end_date'][
'checked'])) {
956 print
'<td class="liste_titre nowraponall center">';
957 $arrayofoperators = array(
'0' =>
'',
'=' =>
'=',
'<=' =>
'<=',
'>=' =>
'>=');
958 print $form->selectarray(
'search_op2df', $arrayofoperators, $search_op2df, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth50imp');
960 print $formother->select_month($search_dfmonth,
'search_dfmonth', 1, 0);
962 print $formother->selectyear($search_dfyear,
'search_dfyear', 1, 20, 5, 0, 0,
'');
966 if (!empty($arrayfields[
'status'][
'checked'])) {
967 print
'<td class="liste_titre right" colspan="4"></td>';
972 print
'<td class="liste_titre center">';
973 $searchpicto = $form->showFilterButtons();
979 $totalarray = array();
980 $totalarray[
'nbfield'] = 0;
984 print
'<tr class="liste_titre">';
986 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ');
987 $totalarray[
'nbfield']++;
989 if (!empty($arrayfields[
'c.ref'][
'checked'])) {
990 print_liste_field_titre($arrayfields[
'c.ref'][
'label'], $_SERVER[
"PHP_SELF"],
"c.ref",
"", $param,
'', $sortfield, $sortorder);
991 $totalarray[
'nbfield']++;
993 if (!empty($arrayfields[
'c.ref_customer'][
'checked'])) {
994 print_liste_field_titre($arrayfields[
'c.ref_customer'][
'label'], $_SERVER[
"PHP_SELF"],
"c.ref_customer",
"", $param,
'', $sortfield, $sortorder);
995 $totalarray[
'nbfield']++;
997 if (!empty($arrayfields[
'c.ref_supplier'][
'checked'])) {
998 print_liste_field_titre($arrayfields[
'c.ref_supplier'][
'label'], $_SERVER[
"PHP_SELF"],
"c.ref_supplier",
"", $param,
'', $sortfield, $sortorder);
999 $totalarray[
'nbfield']++;
1001 if (!empty($arrayfields[
's.nom'][
'checked'])) {
1002 print_liste_field_titre($arrayfields[
's.nom'][
'label'], $_SERVER[
"PHP_SELF"],
"s.nom",
"", $param,
'', $sortfield, $sortorder);
1003 $totalarray[
'nbfield']++;
1005 if (!empty($arrayfields[
's.email'][
'checked'])) {
1006 print_liste_field_titre($arrayfields[
's.email'][
'label'], $_SERVER[
"PHP_SELF"],
"s.email",
"", $param,
'', $sortfield, $sortorder);
1007 $totalarray[
'nbfield']++;
1009 if (!empty($arrayfields[
's.town'][
'checked'])) {
1010 print_liste_field_titre($arrayfields[
's.town'][
'label'], $_SERVER[
"PHP_SELF"],
's.town',
'', $param,
'', $sortfield, $sortorder);
1011 $totalarray[
'nbfield']++;
1013 if (!empty($arrayfields[
's.zip'][
'checked'])) {
1014 print_liste_field_titre($arrayfields[
's.zip'][
'label'], $_SERVER[
"PHP_SELF"],
's.zip',
'', $param,
'', $sortfield, $sortorder);
1015 $totalarray[
'nbfield']++;
1017 if (!empty($arrayfields[
'state.nom'][
'checked'])) {
1018 print_liste_field_titre($arrayfields[
'state.nom'][
'label'], $_SERVER[
"PHP_SELF"],
"state.nom",
"", $param,
'', $sortfield, $sortorder);
1019 $totalarray[
'nbfield']++;
1021 if (!empty($arrayfields[
'country.code_iso'][
'checked'])) {
1022 print_liste_field_titre($arrayfields[
'country.code_iso'][
'label'], $_SERVER[
"PHP_SELF"],
"country.code_iso",
"", $param,
'', $sortfield, $sortorder,
'center ');
1023 $totalarray[
'nbfield']++;
1025 if (!empty($arrayfields[
'typent.code'][
'checked'])) {
1026 print_liste_field_titre($arrayfields[
'typent.code'][
'label'], $_SERVER[
"PHP_SELF"],
"typent.code",
"", $param,
'', $sortfield, $sortorder,
'center ');
1027 $totalarray[
'nbfield']++;
1029 if (!empty($arrayfields[
'sale_representative'][
'checked'])) {
1030 print_liste_field_titre($arrayfields[
'sale_representative'][
'label'], $_SERVER[
"PHP_SELF"],
"",
"", $param,
'', $sortfield, $sortorder);
1031 $totalarray[
'nbfield']++;
1033 if (!empty($arrayfields[
'c.date_contrat'][
'checked'])) {
1034 print_liste_field_titre($arrayfields[
'c.date_contrat'][
'label'], $_SERVER[
"PHP_SELF"],
"c.date_contrat",
"", $param,
'', $sortfield, $sortorder,
'center ');
1035 $totalarray[
'nbfield']++;
1038 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_title.tpl.php';
1040 $parameters = array(
'arrayfields' => $arrayfields,
'param' => $param,
'sortfield' => $sortfield,
'sortorder' => $sortorder,
'totalarray' => &$totalarray);
1041 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters,
$object, $action);
1042 print $hookmanager->resPrint;
1043 if (!empty($arrayfields[
'c.datec'][
'checked'])) {
1044 print_liste_field_titre($arrayfields[
'c.datec'][
'label'], $_SERVER[
"PHP_SELF"],
"c.datec",
"", $param,
'', $sortfield, $sortorder,
'center nowrap ');
1045 $totalarray[
'nbfield']++;
1047 if (!empty($arrayfields[
'c.tms'][
'checked'])) {
1048 print_liste_field_titre($arrayfields[
'c.tms'][
'label'], $_SERVER[
"PHP_SELF"],
"c.tms",
"", $param,
'', $sortfield, $sortorder,
'center nowrap ');
1049 $totalarray[
'nbfield']++;
1051 if (!empty($arrayfields[
'lower_planned_end_date'][
'checked'])) {
1052 print_liste_field_titre($arrayfields[
'lower_planned_end_date'][
'label'], $_SERVER[
"PHP_SELF"],
"lower_planned_end_date",
"", $param,
'', $sortfield, $sortorder,
'center ');
1053 $totalarray[
'nbfield']++;
1055 if (!empty($arrayfields[
'status'][
'checked'])) {
1056 print_liste_field_titre($staticcontratligne->LibStatut(0, 3, -1,
'class="nochangebackground"'),
'',
'',
'',
'',
'width="16"');
1057 $totalarray[
'nbfield']++;
1058 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 0,
'class="nochangebackground"'),
'',
'',
'',
'',
'width="16"');
1059 $totalarray[
'nbfield']++;
1060 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 1,
'class="nochangebackground"'),
'',
'',
'',
'',
'width="16"');
1061 $totalarray[
'nbfield']++;
1062 print_liste_field_titre($staticcontratligne->LibStatut(5, 3, -1,
'class="nochangebackground"'),
'',
'',
'',
'',
'width="16"');
1063 $totalarray[
'nbfield']++;
1066 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ');
1067 $totalarray[
'nbfield']++;
1074 $savnbfield = $totalarray[
'nbfield'];
1075 $totalarray = array();
1076 $totalarray[
'nbfield'] = 0;
1077 $typenArray = array();
1078 $cacheCountryIDCode = array();
1079 $imaxinloop = ($limit ? min($num, $limit) : $num);
1080 while ($i < $imaxinloop) {
1081 $obj = $db->fetch_object($resql);
1086 $contracttmp->ref = $obj->ref;
1087 $contracttmp->id = $obj->rowid;
1088 $contracttmp->ref_customer = $obj->ref_customer;
1089 $contracttmp->ref_supplier = $obj->ref_supplier;
1091 $contracttmp->nbofserviceswait = $obj->nb_initial;
1092 $contracttmp->nbofservicesopened = $obj->nb_running;
1093 $contracttmp->nbofservicesexpired = $obj->nb_expired;
1094 $contracttmp->nbofservicesclosed = $obj->nb_closed;
1096 $socstatic->id = $obj->socid;
1097 $socstatic->name = $obj->name;
1098 $socstatic->name_alias = $obj->name_alias;
1099 $socstatic->email = $obj->email;
1100 $socstatic->status = $obj->company_status;
1101 $socstatic->logo = $obj->company_logo;
1102 $socstatic->country_id = $obj->country_id;
1103 $socstatic->country_code =
'';
1104 $socstatic->country =
'';
1106 if ($obj->country_id > 0) {
1107 if (!isset($cacheCountryIDCode[$obj->country_id][
'code'])) {
1108 $tmparray =
getCountry($obj->country_id,
'all');
1109 $cacheCountryIDCode[$obj->country_id] = array(
'code' => empty($tmparray[
'code']) ?
'' : $tmparray[
'code'],
'label' => empty($tmparray[
'label']) ?
'' : $tmparray[
'label']);
1111 $socstatic->country_code = $cacheCountryIDCode[$obj->country_id][
'code'];
1112 $socstatic->country = $cacheCountryIDCode[$obj->country_id][
'label'];
1115 if ($mode ==
'kanban') {
1117 print
'<tr class="trkanban"><td colspan="'.$savnbfield.
'">';
1118 print
'<div class="box-flex-container kanban">';
1121 $arraydata = array();
1122 $arraydata[
'thirdparty'] = $socstatic;
1123 $arraydata[
'selected'] = in_array($obj->rowid, $arrayofselected);
1124 $contracttmp->date_contrat = $obj->date_contrat;
1125 print $contracttmp->getKanbanView(
'', $arraydata);
1126 if ($i == ($imaxinloop - 1)) {
1132 print
'<tr data-rowid="'.$object->id.
'" class="oddeven">';
1135 print
'<td class="nowrap center">';
1136 if ($massactionbutton || $massaction) {
1138 if (in_array($obj->rowid, $arrayofselected)) {
1141 print
'<input id="cb'.$obj->rowid.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1145 $totalarray[
'nbfield']++;
1149 if (!empty($arrayfields[
'c.ref'][
'checked'])) {
1150 print
'<td class="nowraponall">';
1151 print $contracttmp->getNomUrl(1);
1152 if ($obj->nb_late) {
1155 if (!empty($obj->note_private) || !empty($obj->note_public)) {
1156 print
' <span class="note">';
1157 print
'<a href="'.DOL_URL_ROOT.
'/contrat/note.php?id='.$obj->rowid.
'&save_lastsearch_values=1">'.
img_picto($langs->trans(
"ViewPrivateNote"),
'note').
'</a>';
1163 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.$obj->rowid;
1164 print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
1169 $totalarray[
'nbfield']++;
1174 if (!empty($arrayfields[
'c.ref_customer'][
'checked'])) {
1175 print
'<td class="tdoverflowmax200" title="'.dol_escape_htmltag(
dol_string_nohtmltag($contracttmp->getFormatedCustomerRef($obj->ref_customer))).
'">'.$contracttmp->getFormatedCustomerRef($obj->ref_customer).
'</td>';
1177 $totalarray[
'nbfield']++;
1180 if (!empty($arrayfields[
'c.ref_supplier'][
'checked'])) {
1181 print
'<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).
'">'.
dol_escape_htmltag($obj->ref_supplier).
'</td>';
1183 if (!empty($arrayfields[
's.nom'][
'checked'])) {
1184 print
'<td class="tdoverflowmax150">';
1185 if ($obj->socid > 0) {
1187 print $socstatic->getNomUrl(1,
'');
1192 if (!empty($arrayfields[
's.email'][
'checked'])) {
1193 print
'<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->email).
'">'.
dol_print_email($obj->email, 0, $obj->socid, 1, 0, 1, 1).
'</td>';
1196 if (!empty($arrayfields[
's.town'][
'checked'])) {
1197 print
'<td class="nocellnopadd">';
1201 $totalarray[
'nbfield']++;
1205 if (!empty($arrayfields[
's.zip'][
'checked'])) {
1206 print
'<td class="nocellnopadd">';
1210 $totalarray[
'nbfield']++;
1214 if (!empty($arrayfields[
'state.nom'][
'checked'])) {
1215 print
"<td>".$obj->state_name.
"</td>\n";
1217 $totalarray[
'nbfield']++;
1221 if (!empty($arrayfields[
'country.code_iso'][
'checked'])) {
1222 print
'<td class="center tdoverflowmax100" title="'.dol_escape_htmltag($socstatic->country).
'">';
1226 $totalarray[
'nbfield']++;
1230 if (!empty($arrayfields[
'typent.code'][
'checked'])) {
1231 print
'<td class="center">';
1232 if (count($typenArray) == 0) {
1233 $typenArray = $formcompany->typent_array(1);
1235 print $typenArray[$obj->typent_code];
1238 $totalarray[
'nbfield']++;
1241 if (!empty($arrayfields[
'sale_representative'][
'checked'])) {
1244 if ($obj->socid > 0) {
1245 $listsalesrepresentatives = $socstatic->getSalesRepresentatives($user);
1246 if ($listsalesrepresentatives < 0) {
1249 $nbofsalesrepresentative = count($listsalesrepresentatives);
1250 if ($nbofsalesrepresentative > 6) {
1252 print $nbofsalesrepresentative;
1253 } elseif ($nbofsalesrepresentative > 0) {
1254 $userstatic =
new User($db);
1256 foreach ($listsalesrepresentatives as $val) {
1257 $userstatic->id = $val[
'id'];
1258 $userstatic->lastname = $val[
'lastname'];
1259 $userstatic->firstname = $val[
'firstname'];
1260 $userstatic->email = $val[
'email'];
1261 $userstatic->status = $val[
'statut'];
1262 $userstatic->entity = $val[
'entity'];
1263 $userstatic->photo = $val[
'photo'];
1264 $userstatic->login = $val[
'login'];
1265 $userstatic->phone = $val[
'phone'];
1266 $userstatic->job = $val[
'job'];
1267 $userstatic->gender = $val[
'gender'];
1270 print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1,
'', 0, 0, 12) : $userstatic->getNomUrl(-2);
1272 if ($j < $nbofsalesrepresentative) {
1285 if (!empty($arrayfields[
'c.date_contrat'][
'checked'])) {
1286 print
'<td class="center">'.dol_print_date($db->jdate($obj->date_contrat),
'day',
'tzserver').
'</td>';
1289 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_print_fields.tpl.php';
1291 $parameters = array(
'arrayfields' => $arrayfields,
'obj' => $obj,
'i' => $i,
'totalarray' => &$totalarray);
1292 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters,
$object, $action);
1293 print $hookmanager->resPrint;
1295 if (!empty($arrayfields[
'c.datec'][
'checked'])) {
1296 print
'<td class="center nowrap">';
1297 print
dol_print_date($db->jdate($obj->date_creation),
'dayhour',
'tzuser');
1300 $totalarray[
'nbfield']++;
1304 if (!empty($arrayfields[
'c.tms'][
'checked'])) {
1305 print
'<td class="center nowrap">';
1306 print
dol_print_date($db->jdate($obj->date_modification),
'dayhour',
'tzuser');
1309 $totalarray[
'nbfield']++;
1313 if (!empty($arrayfields[
'lower_planned_end_date'][
'checked'])) {
1314 print
'<td class="center nowrapforall">';
1315 print
dol_print_date($db->jdate($obj->lower_planned_end_date),
'day',
'tzuser');
1318 $totalarray[
'nbfield']++;
1322 if (!empty($arrayfields[
'status'][
'checked'])) {
1323 print
'<td class="center">'.($obj->nb_initial > 0 ? $obj->nb_initial :
'').
'</td>';
1324 print
'<td class="center">'.($obj->nb_running > 0 ? $obj->nb_running :
'').
'</td>';
1325 print
'<td class="center">'.($obj->nb_expired > 0 ? $obj->nb_expired :
'').
'</td>';
1326 print
'<td class="center">'.($obj->nb_closed > 0 ? $obj->nb_closed :
'').
'</td>';
1328 $totalarray[
'nbfield']++;
1329 $totalarray[
'nbfield']++;
1330 $totalarray[
'nbfield']++;
1331 $totalarray[
'nbfield']++;
1336 print
'<td class="nowrap center">';
1337 if ($massactionbutton || $massaction) {
1339 if (in_array($obj->rowid, $arrayofselected)) {
1342 print
'<input id="cb'.$obj->rowid.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1346 $totalarray[
'nbfield']++;
1358 foreach ($arrayfields as $key => $val) {
1359 if (!empty($val[
'checked'])) {
1363 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
1368 $parameters = array(
'arrayfields' => $arrayfields,
'sql' =>
$sql);
1369 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters,
$object, $action);
1370 print $hookmanager->resPrint;
1372 print
'</table>'.
"\n";
1373 print
'</div>'.
"\n";
1375 print
'</form>'.
"\n";
1377 $hidegeneratedfilelistifempty = 1;
1378 if ($massaction ==
'builddoc' || $action ==
'remove_file' || $show_files) {
1379 $hidegeneratedfilelistifempty = 0;
1383 $urlsource = $_SERVER[
'PHP_SELF'].
'?sortfield='.$sortfield.
'&sortorder='.$sortorder;
1384 $urlsource .= str_replace(
'&',
'&', $param);
1386 $filedir = $diroutputmassaction;
1387 $genallowed = $permissiontoread;
1388 $delallowed = $permissiontoadd;
1390 print $formfile->showdocuments(
'massfilesarea_contract',
'', $filedir, $urlsource, 0, $delallowed,
'', 1, 1, 0, 48, 1, $param, $title,
'',
'',
'',
null, $hidegeneratedfilelistifempty);
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage contracts.
Class to manage lines of contracts.
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.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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...
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
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_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 a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
print_barre_liste($title, $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.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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 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, $mode=0)
Check permissions of a user to show a page and an object.