33 require
'../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
42 $langs->loadLangs(array(
'contracts',
'products',
'companies',
'compta'));
44 $action =
GETPOST(
'action',
'aZ09');
45 $massaction =
GETPOST(
'massaction',
'alpha');
46 $show_files =
GETPOST(
'show_files',
'int');
47 $confirm =
GETPOST(
'confirm',
'alpha');
48 $toselect =
GETPOST(
'toselect',
'array');
49 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'contractlist';
51 $search_name =
GETPOST(
'search_name',
'alpha');
52 $search_email =
GETPOST(
'search_email',
'alpha');
53 $search_town =
GETPOST(
'search_town',
'alpha');
54 $search_zip =
GETPOST(
'search_zip',
'alpha');
55 $search_state =
GETPOST(
"search_state",
'alpha');
56 $search_country =
GETPOST(
"search_country",
'int');
57 $search_type_thirdparty =
GETPOST(
"search_type_thirdparty",
'int');
58 $search_contract =
GETPOST(
'search_contract',
'alpha');
59 $search_ref_customer =
GETPOST(
'search_ref_customer',
'alpha');
60 $search_ref_supplier =
GETPOST(
'search_ref_supplier',
'alpha');
61 $sall = (
GETPOST(
'search_all',
'alphanohtml') !=
'') ?
GETPOST(
'search_all',
'alphanohtml') :
GETPOST(
'sall',
'alphanohtml');
62 $search_status =
GETPOST(
'search_status',
'alpha');
63 $socid =
GETPOST(
'socid',
'int');
64 $search_user =
GETPOST(
'search_user',
'int');
65 $search_sale =
GETPOST(
'search_sale',
'int');
66 $search_product_category =
GETPOST(
'search_product_category',
'int');
67 $search_dfmonth =
GETPOST(
'search_dfmonth',
'int');
68 $search_dfyear =
GETPOST(
'search_dfyear',
'int');
69 $search_op2df =
GETPOST(
'search_op2df',
'alpha');
70 $search_date_startday =
GETPOST(
'search_date_startday',
'int');
71 $search_date_startmonth =
GETPOST(
'search_date_startmonth',
'int');
72 $search_date_startyear =
GETPOST(
'search_date_startyear',
'int');
73 $search_date_endday =
GETPOST(
'search_date_endday',
'int');
74 $search_date_endmonth =
GETPOST(
'search_date_endmonth',
'int');
75 $search_date_endyear =
GETPOST(
'search_date_endyear',
'int');
76 $search_date_start =
dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
77 $search_date_end =
dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
79 $optioncss =
GETPOST(
'optioncss',
'alpha');
81 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
82 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
83 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
85 if (empty($page) || $page == -1) {
88 $offset = $limit * $page;
89 $pageprev = $page - 1;
90 $pagenext = $page + 1;
101 $socid = $user->socid;
105 $diroutputmassaction = $conf->contrat->dir_output.
'/temp/massgeneration/'.$user->id;
107 $staticcontrat =
new Contrat($db);
110 if ($search_status ==
'') {
116 $hookmanager->initHooks(array(
'contractlist'));
120 $extrafields->fetch_name_optionals_label($object->table_element);
122 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
124 $fieldstosearchall = array(
126 'c.ref_customer'=>
'RefCustomer',
127 'c.ref_supplier'=>
'RefSupplier',
128 's.nom'=>
"ThirdParty",
129 'c.note_public'=>
'NotePublic',
131 if (empty($user->socid)) {
132 $fieldstosearchall[
"c.note_private"] =
"NotePrivate";
135 $arrayfields = array(
136 'c.ref'=>array(
'label'=>$langs->trans(
"Ref"),
'checked'=>1,
'position'=>10),
137 'c.ref_customer'=>array(
'label'=>$langs->trans(
"RefCustomer"),
'checked'=>1,
'position'=>12),
138 'c.ref_supplier'=>array(
'label'=>$langs->trans(
"RefSupplier"),
'checked'=>1,
'position'=>14),
139 's.nom'=>array(
'label'=>$langs->trans(
"ThirdParty"),
'checked'=>1,
'position'=>30),
140 's.email'=>array(
'label'=>$langs->trans(
"ThirdPartyEmail"),
'checked'=>0,
'position'=>30),
141 's.town'=>array(
'label'=>$langs->trans(
"Town"),
'checked'=>0,
'position'=>31),
142 's.zip'=>array(
'label'=>$langs->trans(
"Zip"),
'checked'=>1,
'position'=>32),
143 'state.nom'=>array(
'label'=>$langs->trans(
"StateShort"),
'checked'=>0,
'position'=>33),
144 'country.code_iso'=>array(
'label'=>$langs->trans(
"Country"),
'checked'=>0,
'position'=>34),
145 'sale_representative'=>array(
'label'=>$langs->trans(
"SaleRepresentativesOfThirdParty"),
'checked'=>-1,
'position'=>80),
146 'c.date_contrat'=>array(
'label'=>$langs->trans(
"DateContract"),
'checked'=>1,
'position'=>45),
147 'c.datec'=>array(
'label'=>$langs->trans(
"DateCreation"),
'checked'=>0,
'position'=>500),
148 'c.tms'=>array(
'label'=>$langs->trans(
"DateModificationShort"),
'checked'=>0,
'position'=>500),
149 'lower_planned_end_date'=>array(
'label'=>$langs->trans(
"LowerDateEndPlannedShort"),
'checked'=>1,
'position'=>900,
'help'=>$langs->trans(
"LowerDateEndPlannedShort")),
150 'status'=>array(
'label'=>$langs->trans(
"Status"),
'checked'=>1,
'position'=>1000),
153 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_array_fields.tpl.php';
163 if (
GETPOST(
'cancel',
'alpha')) {
164 $action =
'list'; $massaction =
'';
166 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
170 $parameters = array(
'socid'=>$socid);
171 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
176 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
179 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
180 $search_dfmonth =
'';
189 $search_country =
'';
190 $search_contract =
"";
191 $search_ref_customer =
"";
192 $search_ref_supplier =
"";
195 $search_product_category =
'';
196 $search_date_startday =
'';
197 $search_date_startmonth =
'';
198 $search_date_startyear =
'';
199 $search_date_endday =
'';
200 $search_date_endmonth =
'';
201 $search_date_endyear =
'';
202 $search_date_start =
'';
203 $search_date_end =
'';
207 $search_type_thirdparty =
'';
208 $search_array_options = array();
211 if (empty($reshook)) {
212 $objectclass =
'Contrat';
213 $objectlabel =
'Contracts';
214 $permissiontoread = $user->rights->contrat->lire;
215 $permissiontodelete = $user->rights->contrat->supprimer;
216 $uploaddir = $conf->contrat->dir_output;
217 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
231 $contracttmp =
new Contrat($db);
235 $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,";
236 $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,';
237 $sql .=
" typent.code as typent_code,";
238 $sql .=
" state.code_departement as state_code, state.nom as state_name,";
239 $sql .=
" MIN(".$db->ifsql(
"cd.statut=4",
"cd.date_fin_validite",
"null").
") as lower_planned_end_date,";
240 $sql .=
" SUM(".$db->ifsql(
"cd.statut=0", 1, 0).
') as nb_initial,';
241 $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,';
242 $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,';
243 $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,';
244 $sql .=
" SUM(".$db->ifsql(
"cd.statut=5", 1, 0).
') as nb_closed';
246 if (!empty($extrafields->attributes[$object->table_element][
'label'])) {
247 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
248 $sql .= ($extrafields->attributes[$object->table_element][
'type'][$key] !=
'separate' ?
", ef.".$key.
" as options_".$key :
'');
252 $parameters = array();
253 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
254 $sql .= $hookmanager->resPrint;
255 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
256 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as country on (country.rowid = s.fk_pays)";
257 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_typent as typent on (typent.id = s.fk_typent)";
258 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as state on (state.rowid = s.fk_departement)";
259 if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
260 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
262 $sql .=
", ".MAIN_DB_PREFIX.
"contrat as c";
263 if (!empty($extrafields->attributes[$object->table_element][
'label']) && is_array($extrafields->attributes[$object->table_element][
'label']) && count($extrafields->attributes[$object->table_element][
'label'])) {
264 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element.
"_extrafields as ef on (c.rowid = ef.fk_object)";
266 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd ON c.rowid = cd.fk_contrat";
267 if ($search_product_category > 0) {
268 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_product as cp ON cp.fk_product=cd.fk_product';
270 if ($search_user > 0) {
271 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact as ec";
272 $sql .=
", ".MAIN_DB_PREFIX.
"c_type_contact as tc";
274 $sql .=
" WHERE c.fk_soc = s.rowid ";
275 $sql .=
' AND c.entity IN ('.getEntity(
'contract').
')';
276 if ($search_type_thirdparty !=
'' && $search_type_thirdparty > 0) {
277 $sql .=
" AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).
')';
279 if ($search_product_category > 0) {
280 $sql .=
" AND cp.fk_categorie = ".((int) $search_product_category);
283 $sql .=
" AND s.rowid = ".((int) $socid);
285 if (empty($user->rights->societe->client->voir) && !$socid) {
286 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
288 if ($search_date_start) {
289 $sql .=
" AND c.date_contrat >= '".$db->idate($search_date_start).
"'";
291 if ($search_date_end) {
292 $sql .=
" AND c.date_contrat <= '".$db->idate($search_date_end).
"'";
300 if ($search_contract) {
301 $sql .=
natural_search(array(
'c.rowid',
'c.ref'), $search_contract);
303 if (!empty($search_ref_customer)) {
304 $sql .=
natural_search(array(
'c.ref_customer'), $search_ref_customer);
306 if (!empty($search_ref_supplier)) {
307 $sql .=
natural_search(array(
'c.ref_supplier'), $search_ref_supplier);
315 if ($search_country && $search_country !=
'-1') {
316 $sql .=
" AND s.fk_pays IN (".$db->sanitize($search_country).
')';
318 if ($search_sale > 0) {
319 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
324 if ($search_user > 0) {
325 $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);
328 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_sql.tpl.php';
330 $parameters = array();
331 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
332 $sql .= $hookmanager->resPrint;
333 $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,";
334 $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,';
335 $sql .=
" typent.code,";
336 $sql .=
" state.code_departement, state.nom";
338 if (!empty($extrafields->attributes[$object->table_element][
'label'])) {
339 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $val) {
340 $sql .= ($extrafields->attributes[$object->table_element][
'type'][$key] !=
'separate' ?
", ef.".$key :
'');
344 $parameters = array(
'search_dfyear' => $search_dfyear,
'search_op2df'=>$search_op2df);
345 $reshook = $hookmanager->executeHooks(
'printFieldListGroupBy', $parameters, $object);
346 $sql .= $hookmanager->resPrint;
348 $parameters = array(
'search_dfyear' => $search_dfyear,
'search_op2df'=>$search_op2df);
349 $reshook = $hookmanager->executeHooks(
'printFieldListHaving', $parameters, $object);
350 if (empty($reshook)) {
351 if ($search_dfyear > 0 && $search_op2df) {
352 if ($search_op2df ==
'<=') {
353 $sql .=
" HAVING MIN(".$db->ifsql(
"cd.statut=4",
"cd.date_fin_validite",
"null").
") <= '".$db->idate(
dol_get_last_day($search_dfyear, $search_dfmonth,
false)).
"'";
354 } elseif ($search_op2df ==
'>=') {
355 $sql .=
" HAVING MIN(".$db->ifsql(
"cd.statut=4",
"cd.date_fin_validite",
"null").
") >= '".$db->idate(
dol_get_first_day($search_dfyear, $search_dfmonth,
false)).
"'";
357 $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)).
"'";
361 $sql .= $hookmanager->resPrint;
363 $nbtotalofrecords =
'';
364 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
368 if ($search_dfyear > 0 && $search_op2df) {
369 $resql = $db->query($sql, 0,
'auto', 1);
370 while ($db->fetch_object(
$resql)) {
371 if (empty($nbtotalofrecords)) {
372 $nbtotalofrecords = 1;
378 $sqlforcount = preg_replace(
'/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/',
'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
379 $sqlforcount = preg_replace(
'/LEFT JOIN '.MAIN_DB_PREFIX.
'contratdet as cd ON c.rowid = cd.fk_contrat/',
'', $sqlforcount);
380 $sqlforcount = preg_replace(
'/LEFT JOIN '.MAIN_DB_PREFIX.
'categorie_product as cp ON cp.fk_product=cd.fk_product/',
'', $sqlforcount);
381 $sqlforcount = preg_replace(
'/AND cp.fk_categorie = '.((
int) $search_product_category).
'/',
'', $sqlforcount);
382 $sqlforcount = preg_replace(
'/GROUP BY.*$/',
'', $sqlforcount);
384 $resql = $db->query($sqlforcount);
385 $objforcount = $db->fetch_object(
$resql);
386 $nbtotalofrecords = $objforcount->nbtotalofrecords;
389 if (($page * $limit) > $nbtotalofrecords) {
395 $sql .= $db->order($sortfield, $sortorder);
397 $sql .= $db->plimit($limit + 1, $offset);
400 $resql = $db->query($sql);
406 $num = $db->num_rows(
$resql);
409 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall && !$page) {
410 $obj = $db->fetch_object(
$resql);
412 header(
"Location: ".DOL_URL_ROOT.
'/contrat/card.php?id='.$id);
420 llxHeader(
'', $langs->trans(
"Contracts"));
424 $arrayofselected = is_array($toselect) ? $toselect : array();
429 if (empty($search_name)) {
430 $search_name = $soc->name;
435 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
436 $param .=
'&contextpage='.urlencode($contextpage);
438 if ($limit > 0 && $limit != $conf->liste_limit) {
439 $param .=
'&limit='.urlencode($limit);
442 $param .=
'&sall='.urlencode($sall);
444 if ($search_contract !=
'') {
445 $param .=
'&search_contract='.urlencode($search_contract);
447 if ($search_name !=
'') {
448 $param .=
'&search_name='.urlencode($search_name);
450 if ($search_email !=
'') {
451 $param .=
'&search_email='.urlencode($search_email);
453 if ($search_ref_customer !=
'') {
454 $param .=
'&search_ref_customer='.urlencode($search_ref_customer);
456 if ($search_ref_supplier !=
'') {
457 $param .=
'&search_ref_supplier='.urlencode($search_ref_supplier);
459 if ($search_op2df !=
'') {
460 $param .=
'&search_op2df='.urlencode($search_op2df);
462 if ($search_date_startday > 0) {
463 $param .=
'&search_date_startday='.urlencode($search_date_startday);
465 if ($search_date_startmonth > 0) {
466 $param .=
'&search_date_startmonth='.urlencode($search_date_startmonth);
468 if ($search_date_startyear > 0) {
469 $param .=
'&search_date_startyear='.urlencode($search_date_startyear);
471 if ($search_date_endday > 0) {
472 $param .=
'&search_date_endday='.urlencode($search_date_endday);
474 if ($search_date_endmonth > 0) {
475 $param .=
'&search_date_endmonth='.urlencode($search_date_endmonth);
477 if ($search_date_endyear > 0) {
478 $param .=
'&search_date_endyear='.urlencode($search_date_endyear);
480 if ($search_dfyear > 0) {
481 $param .=
'&search_dfyear='.urlencode($search_dfyear);
483 if ($search_dfmonth > 0) {
484 $param .=
'&search_dfmonth='.urlencode($search_dfmonth);
486 if ($search_sale > 0) {
487 $param .=
'&search_sale='.urlencode($search_sale);
489 if ($search_user > 0) {
490 $param .=
'&search_user='.urlencode($search_user);
492 if ($search_type_thirdparty > 0) {
493 $param .=
'&search_type_thirdparty='.urlencode($search_type_thirdparty);
495 if ($search_country !=
'') {
496 $param .=
"&search_country=".urlencode($search_country);
498 if ($search_product_category > 0) {
499 $param .=
'&search_product_category='.urlencode($search_product_category);
502 $param .=
'&show_files='.urlencode($show_files);
504 if ($optioncss !=
'') {
505 $param .=
'&optioncss='.urlencode($optioncss);
508 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_param.tpl.php';
511 $arrayofmassactions = array(
512 'generate_doc'=>
img_picto(
'',
'pdf',
'class="pictofixedwidth"').$langs->trans(
"ReGeneratePDF"),
513 'builddoc'=>
img_picto(
'',
'pdf',
'class="pictofixedwidth"').$langs->trans(
"PDFMerge"),
514 'presend'=>
img_picto(
'',
'email',
'class="pictofixedwidth"').$langs->trans(
"SendByMail"),
516 if ($user->rights->contrat->supprimer) {
517 $arrayofmassactions[
'predelete'] =
img_picto(
'',
'delete',
'class="pictofixedwidth"').$langs->trans(
"Delete");
519 if (in_array($massaction, array(
'presend',
'predelete'))) {
520 $arrayofmassactions = array();
522 $massactionbutton =
$form->selectMassAction(
'', $arrayofmassactions);
524 $url = DOL_URL_ROOT.
'/contrat/card.php?action=create';
525 if (!empty($socid)) {
526 $url .=
'&socid='.((int) $socid);
528 $newcardbutton =
dolGetButtonTitle($langs->trans(
'NewContractSubscription'),
'',
'fa fa-plus-circle', $url,
'', $user->rights->contrat->creer);
530 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
531 if ($optioncss !=
'') {
532 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
534 print
'<input type="hidden" name="token" value="'.newToken().
'">';
535 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
536 print
'<input type="hidden" name="action" value="list">';
537 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
538 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
539 print
'<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
541 print_barre_liste($langs->trans(
"ListOfContracts"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
'contract', 0, $newcardbutton,
'', $limit, 0, 0, 1);
543 $topicmail =
"SendContractRef";
544 $modelmail =
"contract";
546 $trackid =
'con'.$object->id;
547 include DOL_DOCUMENT_ROOT.
'/core/tpl/massactions_pre.tpl.php';
550 foreach ($fieldstosearchall as $key => $val) {
551 $fieldstosearchall[$key] = $langs->trans($val);
553 print
'<div class="divsearchfieldfilter">'.$langs->trans(
"FilterOnInto", $sall).join(
', ', $fieldstosearchall).
'</div>';
559 if ($user->rights->user->user->lire) {
560 $langs->load(
"commercial");
561 $moreforfilter .=
'<div class="divsearchfield">';
562 $tmptitle = $langs->trans(
'ThirdPartiesOfSaleRepresentative');
563 $moreforfilter .=
img_picto($tmptitle,
'user',
'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale,
'search_sale', $user, 0, $tmptitle,
'widthcentpercentminusx maxwidth300');
564 $moreforfilter .=
'</div>';
567 if ($user->rights->user->user->lire) {
568 $moreforfilter .=
'<div class="divsearchfield">';
569 $tmptitle = $langs->trans(
'LinkedToSpecificUsers');
570 $moreforfilter .=
img_picto($tmptitle,
'user',
'class="pictofixedwidth"').$form->select_dolusers($search_user,
'search_user', $tmptitle,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'widthcentpercentminusx maxwidth300');
571 $moreforfilter .=
'</div>';
574 if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
575 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
576 $moreforfilter .=
'<div class="divsearchfield">';
577 $tmptitle = $langs->trans(
'IncludingProductWithTag');
578 $cate_arbo =
$form->select_all_categories(Categorie::TYPE_PRODUCT,
null,
'parent',
null,
null, 1);
579 $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);
580 $moreforfilter .=
'</div>';
583 $parameters = array();
584 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters);
585 if (empty($reshook)) {
586 $moreforfilter .= $hookmanager->resPrint;
588 $moreforfilter = $hookmanager->resPrint;
591 if (!empty($moreforfilter)) {
592 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
593 print $moreforfilter;
597 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
598 $selectedfields =
$form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
599 if ($massactionbutton) {
600 $selectedfields .=
$form->showCheckAddButtons(
'checkforselect', 1);
603 print
'<div class="div-table-responsive">';
604 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
606 print
'<tr class="liste_titre_filter">';
607 if (!empty($arrayfields[
'c.ref'][
'checked'])) {
608 print
'<td class="liste_titre">';
609 print
'<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).
'">';
612 if (!empty($arrayfields[
'c.ref_customer'][
'checked'])) {
613 print
'<td class="liste_titre">';
614 print
'<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).
'">';
617 if (!empty($arrayfields[
'c.ref_supplier'][
'checked'])) {
618 print
'<td class="liste_titre">';
619 print
'<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).
'">';
622 if (!empty($arrayfields[
's.nom'][
'checked'])) {
623 print
'<td class="liste_titre">';
624 print
'<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).
'">';
627 if (!empty($arrayfields[
's.email'][
'checked'])) {
628 print
'<td class="liste_titre">';
629 print
'<input type="text" class="flat" size="6" name="search_email" value="'.dol_escape_htmltag($search_email).
'">';
633 if (!empty($arrayfields[
's.town'][
'checked'])) {
634 print
'<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.dol_escape_htmltag($search_town).
'"></td>';
637 if (!empty($arrayfields[
's.zip'][
'checked'])) {
638 print
'<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.dol_escape_htmltag($search_zip).
'"></td>';
641 if (!empty($arrayfields[
'state.nom'][
'checked'])) {
642 print
'<td class="liste_titre">';
643 print
'<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).
'">';
647 if (!empty($arrayfields[
'country.code_iso'][
'checked'])) {
648 print
'<td class="liste_titre center">';
649 print
$form->select_country($search_country,
'search_country',
'', 0,
'minwidth100imp maxwidth100');
653 if (!empty($arrayfields[
'typent.code'][
'checked'])) {
654 print
'<td class="liste_titre maxwidthonsmartphone center">';
655 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);
658 if (!empty($arrayfields[
'sale_representative'][
'checked'])) {
659 print
'<td class="liste_titre"></td>';
661 if (!empty($arrayfields[
'c.date_contrat'][
'checked'])) {
662 print
'<td class="liste_titre center">';
663 print
'<div class="nowrap">';
664 print
$form->selectDate($search_date_start ? $search_date_start : -1,
'search_date_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'From'));
666 print
'<div class="nowrap">';
667 print
$form->selectDate($search_date_end ? $search_date_end : -1,
'search_date_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'to'));
672 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_input.tpl.php';
675 $parameters = array(
'arrayfields'=>$arrayfields);
676 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters);
677 print $hookmanager->resPrint;
679 if (!empty($arrayfields[
'c.datec'][
'checked'])) {
680 print
'<td class="liste_titre">';
684 if (!empty($arrayfields[
'c.tms'][
'checked'])) {
685 print
'<td class="liste_titre">';
689 if (!empty($arrayfields[
'lower_planned_end_date'][
'checked'])) {
690 print
'<td class="liste_titre nowraponall center">';
691 $arrayofoperators = array(
'0'=>
'',
'='=>
'=',
'<='=>
'<=',
'>='=>
'>=');
692 print
$form->selectarray(
'search_op2df', $arrayofoperators, $search_op2df, 0, 0, 0,
'', 0, 0, 0,
'',
'maxwidth50imp');
694 print $formother->select_month($search_dfmonth,
'search_dfmonth', 1, 0);
696 print $formother->selectyear($search_dfyear,
'search_dfyear', 1, 20, 5, 0, 0,
'');
700 if (!empty($arrayfields[
'status'][
'checked'])) {
701 print
'<td class="liste_titre right" colspan="4"></td>';
703 print
'<td class="liste_titre center">';
704 $searchpicto =
$form->showFilterButtons();
709 print
'<tr class="liste_titre">';
710 if (!empty($arrayfields[
'c.ref'][
'checked'])) {
711 print_liste_field_titre($arrayfields[
'c.ref'][
'label'], $_SERVER[
"PHP_SELF"],
"c.ref",
"", $param,
'', $sortfield, $sortorder);
713 if (!empty($arrayfields[
'c.ref_customer'][
'checked'])) {
714 print_liste_field_titre($arrayfields[
'c.ref_customer'][
'label'], $_SERVER[
"PHP_SELF"],
"c.ref_customer",
"", $param,
'', $sortfield, $sortorder);
716 if (!empty($arrayfields[
'c.ref_supplier'][
'checked'])) {
717 print_liste_field_titre($arrayfields[
'c.ref_supplier'][
'label'], $_SERVER[
"PHP_SELF"],
"c.ref_supplier",
"", $param,
'', $sortfield, $sortorder);
719 if (!empty($arrayfields[
's.nom'][
'checked'])) {
720 print_liste_field_titre($arrayfields[
's.nom'][
'label'], $_SERVER[
"PHP_SELF"],
"s.nom",
"", $param,
'', $sortfield, $sortorder);
722 if (!empty($arrayfields[
's.email'][
'checked'])) {
723 print_liste_field_titre($arrayfields[
's.email'][
'label'], $_SERVER[
"PHP_SELF"],
"s.email",
"", $param,
'', $sortfield, $sortorder);
725 if (!empty($arrayfields[
's.town'][
'checked'])) {
726 print_liste_field_titre($arrayfields[
's.town'][
'label'], $_SERVER[
"PHP_SELF"],
's.town',
'', $param,
'', $sortfield, $sortorder);
728 if (!empty($arrayfields[
's.zip'][
'checked'])) {
729 print_liste_field_titre($arrayfields[
's.zip'][
'label'], $_SERVER[
"PHP_SELF"],
's.zip',
'', $param,
'', $sortfield, $sortorder);
731 if (!empty($arrayfields[
'state.nom'][
'checked'])) {
732 print_liste_field_titre($arrayfields[
'state.nom'][
'label'], $_SERVER[
"PHP_SELF"],
"state.nom",
"", $param,
'', $sortfield, $sortorder);
734 if (!empty($arrayfields[
'country.code_iso'][
'checked'])) {
735 print_liste_field_titre($arrayfields[
'country.code_iso'][
'label'], $_SERVER[
"PHP_SELF"],
"country.code_iso",
"", $param,
'', $sortfield, $sortorder,
'center ');
737 if (!empty($arrayfields[
'typent.code'][
'checked'])) {
738 print_liste_field_titre($arrayfields[
'typent.code'][
'label'], $_SERVER[
"PHP_SELF"],
"typent.code",
"", $param,
'', $sortfield, $sortorder,
'center ');
740 if (!empty($arrayfields[
'sale_representative'][
'checked'])) {
741 print_liste_field_titre($arrayfields[
'sale_representative'][
'label'], $_SERVER[
"PHP_SELF"],
"",
"", $param,
'', $sortfield, $sortorder);
743 if (!empty($arrayfields[
'c.date_contrat'][
'checked'])) {
744 print_liste_field_titre($arrayfields[
'c.date_contrat'][
'label'], $_SERVER[
"PHP_SELF"],
"c.date_contrat",
"", $param,
'', $sortfield, $sortorder,
'center ');
747 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_title.tpl.php';
749 $parameters = array(
'arrayfields'=>$arrayfields,
'param'=>$param,
'sortfield'=>$sortfield,
'sortorder'=>$sortorder);
750 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters);
751 print $hookmanager->resPrint;
752 if (!empty($arrayfields[
'c.datec'][
'checked'])) {
753 print_liste_field_titre($arrayfields[
'c.datec'][
'label'], $_SERVER[
"PHP_SELF"],
"c.datec",
"", $param,
'', $sortfield, $sortorder,
'center nowrap ');
755 if (!empty($arrayfields[
'c.tms'][
'checked'])) {
756 print_liste_field_titre($arrayfields[
'c.tms'][
'label'], $_SERVER[
"PHP_SELF"],
"c.tms",
"", $param,
'', $sortfield, $sortorder,
'center nowrap ');
758 if (!empty($arrayfields[
'lower_planned_end_date'][
'checked'])) {
759 print_liste_field_titre($arrayfields[
'lower_planned_end_date'][
'label'], $_SERVER[
"PHP_SELF"],
"lower_planned_end_date",
"", $param,
'', $sortfield, $sortorder,
'center ');
761 if (!empty($arrayfields[
'status'][
'checked'])) {
762 print_liste_field_titre($staticcontratligne->LibStatut(0, 3, -1,
'class="nochangebackground"'),
'',
'',
'',
'',
'width="16"');
763 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 0,
'class="nochangebackground"'),
'',
'',
'',
'',
'width="16"');
764 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 1,
'class="nochangebackground"'),
'',
'',
'',
'',
'width="16"');
765 print_liste_field_titre($staticcontratligne->LibStatut(5, 3, -1,
'class="nochangebackground"'),
'',
'',
'',
'',
'width="16"');
767 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ');
770 $totalarray = array();
771 $totalarray[
'nbfield'] = 0;
772 $typenArray = array();
773 $cacheCountryIDCode = array();
775 while ($i < min($num, $limit)) {
776 $obj = $db->fetch_object(
$resql);
778 $contracttmp->ref = $obj->ref;
779 $contracttmp->id = $obj->rowid;
780 $contracttmp->ref_customer = $obj->ref_customer;
781 $contracttmp->ref_supplier = $obj->ref_supplier;
783 if ($obj->socid > 0) {
784 $result = $socstatic->fetch($obj->socid);
795 if ($obj->country_id > 0) {
796 if (!isset($cacheCountryIDCode[$obj->country_id][
'code'])) {
797 $tmparray =
getCountry($obj->country_id,
'all');
798 $cacheCountryIDCode[$obj->country_id] = array(
'code'=> empty($tmparray[
'code']) ?
'' : $tmparray[
'code'],
'label' => empty($tmparray[
'label']) ?
'' : $tmparray[
'label']);
800 $socstatic->country_code = $cacheCountryIDCode[$obj->country_id][
'code'];
801 $socstatic->country = $cacheCountryIDCode[$obj->country_id][
'label'];
805 print
'<tr class="oddeven">';
808 if (!empty($arrayfields[
'c.ref'][
'checked'])) {
809 print
'<td class="nowraponall">';
810 print $contracttmp->getNomUrl(1);
814 if (!empty($obj->note_private) || !empty($obj->note_public)) {
815 print
' <span class="note">';
816 print
'<a href="'.DOL_URL_ROOT.
'/contrat/note.php?id='.$obj->rowid.
'&save_lastsearch_values=1">'.
img_picto($langs->trans(
"ViewPrivateNote"),
'note').
'</a>';
822 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.$obj->rowid;
823 print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
830 if (!empty($arrayfields[
'c.ref_customer'][
'checked'])) {
831 print
'<td class="tdoverflowmax200" title="'.dol_escape_htmltag(
dol_string_nohtmltag($contracttmp->getFormatedCustomerRef($obj->ref_customer))).
'">'.$contracttmp->getFormatedCustomerRef($obj->ref_customer).
'</td>';
833 if (!empty($arrayfields[
'c.ref_supplier'][
'checked'])) {
834 print
'<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).
'">'.
dol_escape_htmltag($obj->ref_supplier).
'</td>';
836 if (!empty($arrayfields[
's.nom'][
'checked'])) {
837 print
'<td class="tdoverflowmax150">';
838 if ($obj->socid > 0) {
840 print $socstatic->getNomUrl(1,
'');
845 if (!empty($arrayfields[
's.email'][
'checked'])) {
846 print
'<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->email).
'">'.
dol_print_email($obj->email, 0, $obj->socid, 0, 0, 1, 1).
'</td>';
849 if (!empty($arrayfields[
's.town'][
'checked'])) {
850 print
'<td class="nocellnopadd">';
854 $totalarray[
'nbfield']++;
858 if (!empty($arrayfields[
's.zip'][
'checked'])) {
859 print
'<td class="nocellnopadd">';
863 $totalarray[
'nbfield']++;
867 if (!empty($arrayfields[
'state.nom'][
'checked'])) {
868 print
"<td>".$obj->state_name.
"</td>\n";
870 $totalarray[
'nbfield']++;
874 if (!empty($arrayfields[
'country.code_iso'][
'checked'])) {
875 print
'<td class="center">';
876 print $socstatic->country;
879 $totalarray[
'nbfield']++;
883 if (!empty($arrayfields[
'typent.code'][
'checked'])) {
884 print
'<td class="center">';
885 if (count($typenArray) == 0) {
886 $typenArray = $formcompany->typent_array(1);
888 print $typenArray[$obj->typent_code];
891 $totalarray[
'nbfield']++;
894 if (!empty($arrayfields[
'sale_representative'][
'checked'])) {
897 if ($obj->socid > 0) {
898 $listsalesrepresentatives = $socstatic->getSalesRepresentatives($user);
899 if ($listsalesrepresentatives < 0) {
902 $nbofsalesrepresentative = count($listsalesrepresentatives);
903 if ($nbofsalesrepresentative > 6) {
905 print $nbofsalesrepresentative;
906 } elseif ($nbofsalesrepresentative > 0) {
907 $userstatic =
new User($db);
909 foreach ($listsalesrepresentatives as $val) {
910 $userstatic->id = $val[
'id'];
911 $userstatic->lastname = $val[
'lastname'];
912 $userstatic->firstname = $val[
'firstname'];
913 $userstatic->email = $val[
'email'];
914 $userstatic->statut = $val[
'statut'];
915 $userstatic->entity = $val[
'entity'];
916 $userstatic->photo = $val[
'photo'];
917 $userstatic->login = $val[
'login'];
918 $userstatic->phone = $val[
'phone'];
919 $userstatic->job = $val[
'job'];
920 $userstatic->gender = $val[
'gender'];
923 print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1,
'', 0, 0, 12) : $userstatic->getNomUrl(-2);
925 if ($j < $nbofsalesrepresentative) {
938 if (!empty($arrayfields[
'c.date_contrat'][
'checked'])) {
939 print
'<td class="center">'.dol_print_date($db->jdate($obj->date_contrat),
'day',
'tzserver').
'</td>';
942 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_print_fields.tpl.php';
944 $parameters = array(
'arrayfields'=>$arrayfields,
'obj'=>$obj,
'i'=>$i,
'totalarray'=>&$totalarray);
945 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters);
946 print $hookmanager->resPrint;
948 if (!empty($arrayfields[
'c.datec'][
'checked'])) {
949 print
'<td class="center nowrap">';
950 print
dol_print_date($db->jdate($obj->date_creation),
'dayhour',
'tzuser');
953 $totalarray[
'nbfield']++;
957 if (!empty($arrayfields[
'c.tms'][
'checked'])) {
958 print
'<td class="center nowrap">';
959 print
dol_print_date($db->jdate($obj->date_update),
'dayhour',
'tzuser');
962 $totalarray[
'nbfield']++;
966 if (!empty($arrayfields[
'lower_planned_end_date'][
'checked'])) {
967 print
'<td class="center nowrapforall">';
968 print
dol_print_date($db->jdate($obj->lower_planned_end_date),
'day',
'tzuser');
971 $totalarray[
'nbfield']++;
975 if (!empty($arrayfields[
'status'][
'checked'])) {
976 print
'<td class="center">'.($obj->nb_initial > 0 ? $obj->nb_initial :
'').
'</td>';
977 print
'<td class="center">'.($obj->nb_running > 0 ? $obj->nb_running :
'').
'</td>';
978 print
'<td class="center">'.($obj->nb_expired > 0 ? $obj->nb_expired :
'').
'</td>';
979 print
'<td class="center">'.($obj->nb_closed > 0 ? $obj->nb_closed :
'').
'</td>';
982 print
'<td class="nowrap center">';
983 if ($massactionbutton || $massaction) {
985 if (in_array($obj->rowid, $arrayofselected)) {
988 print
'<input id="cb'.$obj->rowid.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.
'"'.($selected ?
' checked="checked"' :
'').
'>';
992 $totalarray[
'nbfield']++;
1002 foreach ($arrayfields as $key => $val) {
1003 if (!empty($val[
'checked'])) {
1007 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
1012 $parameters = array(
'arrayfields'=>$arrayfields,
'sql'=>$sql);
1013 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters);
1014 print $hookmanager->resPrint;
1021 $hidegeneratedfilelistifempty = 1;
1022 if ($massaction ==
'builddoc' || $action ==
'remove_file' || $show_files) {
1023 $hidegeneratedfilelistifempty = 0;
1027 $urlsource = $_SERVER[
'PHP_SELF'].
'?sortfield='.$sortfield.
'&sortorder='.$sortorder;
1028 $urlsource .= str_replace(
'&',
'&', $param);
1030 $filedir = $diroutputmassaction;
1031 $genallowed = $user->rights->contrat->lire;
1032 $delallowed = $user->rights->contrat->lire;
1034 print $formfile->showdocuments(
'massfilesarea_contract',
'', $filedir, $urlsource, 0, $delallowed,
'', 1, 1, 0, 48, 1, $param, $title,
'',
'',
'',
null, $hidegeneratedfilelistifempty);