260 global $conf, $hookmanager, $langs;
265 $action = $this->action;
266 $object = $this->object;
267 $limit = $this->limit;
269 $sortfield = $this->sortfield;
270 $sortorder = $this->sortorder;
271 $titleKey = $this->titleKey;
272 $contextpage = $this->contextpage;
273 $search = $this->search;
274 $arrayfields = $this->arrayfields;
275 $elementEn = $object->element;
276 if ($object->element ==
'commande') {
277 $elementEn =
'order';
278 } elseif ($object->element ==
'facture') {
279 $elementEn =
'invoice';
284 if ($elementEn ==
'invoice') {
289 $emptyValueKey = ($elementEn ==
'order' ? -5 : -1);
292 $limit = $conf->liste_limit;
297 $offset = $limit * ($page - 1);
299 reset($object->fields);
300 $sortfield =
't.' . key($object->fields);
306 $socid = (int)
$context->logged_thirdparty->id;
311 $sql .= $object->getFieldList(
't');
312 $sql .=
", t.entity as element_entity";
314 $parameters = array();
315 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters, $object, $action);
316 $sql .= $hookmanager->resPrint;
317 $sql = preg_replace(
'/,\s*$/',
'', $sql);
321 $sql .=
" FROM " . $this->db->prefix() . $object->table_element .
" as t";
323 $parameters = array();
324 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters, $object, $action);
325 $sql .= $hookmanager->resPrint;
326 if ($object->ismultientitymanaged == 1) {
327 $sql .=
" WHERE t.entity IN (" .
getEntity($object->element, (
GETPOSTINT(
'search_current_entity') ? 0 : 1)) .
")";
329 $sql .=
" WHERE 1 = 1";
332 $sql .=
" AND t.fk_soc = " . ((int) $socid);
334 $sql .=
" AND t.fk_statut <> 0";
336 foreach ($search as $key => $val) {
337 if (array_key_exists($key, $object->fields)) {
338 if (($key ==
'status' || $key ==
'fk_statut') && $search[$key] == $emptyValueKey) {
341 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
342 if ((strpos($object->fields[$key][
'type'],
'integer:') === 0) || (strpos($object->fields[$key][
'type'],
'sellist:') === 0) || !empty($object->fields[$key][
'arrayofkeyval'])) {
343 if ($search[$key] ==
"$emptyValueKey" || ($search[$key] ===
'0' && (empty($object->fields[$key][
'arrayofkeyval']) || !array_key_exists(
'0', $object->fields[$key][
'arrayofkeyval'])))) {
348 if ($search[$key] !=
'') {
349 $sql .=
natural_search(
"t." . $this->db->escape($key), $search[$key], (($key ==
'status' || $key ==
'fk_statut') ? ($search[$key] < 0 ? 1 : 2) : $mode_search));
352 if (preg_match(
'/(_dtstart|_dtend)$/', $key) && $search[$key] !=
'') {
353 $columnName = preg_replace(
'/(_dtstart|_dtend)$/',
'', $key);
354 if (preg_match(
'/^(date|timestamp|datetime)/', $object->fields[$columnName][
'type'])) {
355 if (preg_match(
'/_dtstart$/', $key)) {
356 $sql .=
" AND t." . $this->db->escape($columnName) .
" >= '" . $this->db->idate($search[$key]) .
"'";
358 if (preg_match(
'/_dtend$/', $key)) {
359 $sql .=
" AND t." . $this->db->escape($columnName) .
" <= '" . $this->db->idate($search[$key]) .
"'";
369 $parameters = array();
370 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $object, $action);
371 $sql .= $hookmanager->resPrint;
374 $nbtotalofrecords = 0;
377 $sqlforcount = preg_replace(
'/^' . preg_quote($sqlfields,
'/') .
'/',
'SELECT COUNT(*) as nbtotalofrecords', $sql);
378 $sqlforcount = preg_replace(
'/GROUP BY .*$/',
'', $sqlforcount);
379 $resql = $this->db->query($sqlforcount);
381 $objforcount = $this->db->fetch_object($resql);
382 $nbtotalofrecords = (int) $objforcount->nbtotalofrecords;
387 if ($offset > $nbtotalofrecords) {
392 $this->db->free($resql);
396 $sql .= $this->db->order($sortfield, $sortorder);
398 $sql .= $this->db->plimit($limit, $offset);
401 $resql = $this->db->query($sql);
407 $num = $this->db->num_rows($resql);
409 $nbpages = ceil($nbtotalofrecords / $limit);
417 $sortFieldList = explode(
",", $sortfield);
418 $sortOrderList = explode(
",", $sortorder);
420 if (!empty($sortFieldList)) {
421 foreach ($sortFieldList as $sortField) {
422 if (isset($sortOrderList[$sortFieldIndex])) {
423 $sortList[$sortField] = $sortOrderList[$sortFieldIndex];
430 $param .=
'&contextpage=' . urlencode($contextpage);
431 $param .=
'&limit=' . $limit;
432 foreach ($search as $key => $val) {
433 if (is_array($search[$key])) {
434 foreach ($search[$key] as $skey) {
436 $param .=
'&search_' . $key .
'[]=' . urlencode($skey);
439 } elseif (preg_match(
'/(_dtstart|_dtend)$/', $key) && !empty($val)) {
440 $param .=
'&search_' . $key .
'month=' . (
GETPOSTINT(
'search_' . $key .
'month'));
441 $param .=
'&search_' . $key .
'day=' . (
GETPOSTINT(
'search_' . $key .
'day'));
442 $param .=
'&search_' . $key .
'year=' . (
GETPOSTINT(
'search_' . $key .
'year'));
443 } elseif ($search[$key] !=
'') {
444 $param .=
'&search_' . $key .
'=' . urlencode($search[$key]);
448 $parameters = array();
449 $reshook = $hookmanager->executeHooks(
'printFieldListSearchParam', $parameters, $object, $action);
450 $param .= $hookmanager->resPrint;
453 $html .=
'<form method="POST" id="searchFormList" action="' . $url_file .
'">' .
"\n";
455 $html .=
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
456 $html .=
'<input type="hidden" name="action" value="list">';
457 $html .=
'<input type="hidden" name="sortfield" value="' . $sortfield .
'">';
458 $html .=
'<input type="hidden" name="sortorder" value="' . $sortorder .
'">';
459 $html .=
'<input type="hidden" name="page" value="' . $page .
'">';
460 $html .=
'<input type="hidden" name="contextpage" value="' . $contextpage .
'">';
463 $pagination_param = $param .
'&sortfield=' . $sortfield .
'&sortorder=' . $sortorder;
464 $html .=
'<nav id="webportal-' . $elementEn .
'-pagination">';
466 $html .=
'<li><strong>' . $langs->trans($titleKey) .
'</strong> (' . $nbtotalofrecords .
')</li>';
470 $html .= static::generatePageListNav($url_file . $pagination_param, $nbpages, $page);
475 $html .=
'<table id="webportal-' . $elementEn .
'-list" responsive="scroll" role="grid">';
490 $html .=
'<tr role="search-row">';
493 $html .=
'<td data-col="row-checkbox" >';
494 $html .=
' <button class="btn-filter-icon btn-search-filters-icon" type="submit" name="button_search_x" value="x" aria-label="'.dol_escape_htmltag($langs->trans(
'Search')).
'" ></button>';
495 $html .=
' <button class="btn-filter-icon btn-remove-search-filters-icon" type="submit" name="button_removefilter_x" value="x" aria-label="'.dol_escape_htmltag($langs->trans(
'RemoveSearchFilters')).
'"></button>';
498 foreach ($object->fields as $key => $val) {
499 if (!empty($arrayfields[
't.' . $key][
'checked'])) {
500 $html .=
'<td data-label="' . $arrayfields[
't.' . $key][
'label'] .
'" data-col="'.dol_escape_htmltag($key).
'" >';
501 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
502 $html .= $this->form->selectarray(
'search_' . $key, $val[
'arrayofkeyval'], (isset($search[$key]) ? $search[$key] :
''), $val[
'notnull'], 0, 0,
'', 1, 0, 0,
'',
'');
503 } elseif (preg_match(
'/^(date|timestamp|datetime)/', $val[
'type'])) {
504 $postDateStart =
dol_mktime(0, 0, 0, $search[$key .
'_dtstartmonth'], $search[$key .
'_dtstartday'], $search[$key .
'_dtstartyear']);
505 $postDateEnd =
dol_mktime(0, 0, 0, $search[$key .
'_dtendmonth'], $search[$key .
'_dtendday'], $search[$key .
'_dtendyear']);
507 $html .=
'<div class="grid width150">';
508 $html .= $this->form->inputDate(
'search_' . $key .
'_dtstart', $postDateStart ? $postDateStart :
'', $langs->trans(
'From'));
510 $html .=
'<div class="grid width150">';
511 $html .= $this->form->inputDate(
'search_' . $key .
'_dtend', $postDateEnd ? $postDateEnd :
'', $langs->trans(
'to'));
514 $html .=
'<input type="text" name="search_' . $key .
'" value="' .
dol_escape_htmltag(isset($search[$key]) ? $search[$key] :
'') .
'">';
520 $parameters = array(
'arrayfields' => $arrayfields);
521 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters, $object, $action);
522 $html .= $hookmanager->resPrint;
524 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
525 $html .=
'<td data-label="' . $arrayfields[
'remain_to_pay'][
'label'] .
'">';
529 if (!empty($arrayfields[
'download_link'][
'checked'])) {
530 $html .=
'<td data-label="' . $arrayfields[
'download_link'][
'label'] .
'">';
535 if (!empty($arrayfields[
'signature_link'][
'checked'])) {
536 $html .=
'<td data-label="' . $arrayfields[
'signature_link'][
'label'] .
'">';
542 $totalarray = array();
543 $totalarray[
'nbfield'] = 0;
550 $html .=
'<th data-col="row-checkbox" ></th>';
551 $totalarray[
'nbfield']++;
553 foreach ($object->fields as $key => $val) {
554 $tableKey =
't.' . $key;
555 if (!empty($arrayfields[$tableKey][
'checked'])) {
557 if (array_key_exists($tableKey, $sortList)) {
558 $tableOrder = strtolower($sortList[$tableKey]);
560 $url_param = $url_file .
'&sortfield=' . $tableKey .
'&sortorder=' . ($tableOrder ==
'desc' ?
'asc' :
'desc') . $param;
561 $html .=
'<th data-col="'.dol_escape_htmltag($key).
'" scope="col"' . ($tableOrder !=
'' ?
' table-order="' . $tableOrder .
'"' :
'') .
'>';
562 $html .=
'<a href="' . $url_param .
'">';
563 $html .= $langs->trans($arrayfields[
't.' . $key][
'label']);
566 $totalarray[
'nbfield']++;
570 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
571 $html .=
'<th scope="col">';
572 $html .= $langs->trans($arrayfields[
'remain_to_pay'][
'label']);
574 $totalarray[
'nbfield']++;
577 if (!empty($arrayfields[
'download_link'][
'checked'])) {
578 $html .=
'<th scope="col">';
579 $html .= $langs->trans($arrayfields[
'download_link'][
'label']);
581 $totalarray[
'nbfield']++;
585 if (!empty($arrayfields[
'signature_link'][
'checked'])) {
586 $html .=
'<th scope="col">';
587 $html .= $langs->trans($arrayfields[
'signature_link'][
'label']);
589 $totalarray[
'nbfield']++;
594 $parameters = array(
'arrayfields' => $arrayfields,
'sortfield' => $sortfield,
'sortorder' => $sortorder,
'totalarray' => &$totalarray);
595 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $object, $action);
596 $html .= $hookmanager->resPrint;
604 $idCompany = (int) $socid;
605 if (!isset($this->companyStaticList[$socid])) {
606 $companyStatic =
new Societe($this->db);
607 $companyStatic->fetch($idCompany);
608 $this->companyStaticList[$idCompany] = $companyStatic;
610 $companyStatic = $this->companyStaticList[$socid];
619 $imaxinloop = ($limit ? min($num, $limit) : $num);
620 while ($i < $imaxinloop) {
621 $obj = $this->db->fetch_object($resql);
627 $object->setVarsFromFetchObj($obj);
631 if ($elementEn ==
'invoice') {
633 $payment = $object->getSommePaiement();
634 $totalcreditnotes = $object->getSumCreditNotesUsed();
635 $totaldeposits = $object->getSumDepositsUsed();
638 $totalpay = $payment + $totalcreditnotes + $totaldeposits;
639 $remaintopay =
price2num($object->total_ttc - $totalpay);
644 $remaincreditnote = $discount->getAvailableDiscounts($companyStatic,
'',
'rc.fk_facture_source=' . $object->id);
645 $remaintopay = -$remaincreditnote;
650 $html .=
'<tr data-rowid="' . $object->id .
'">';
652 $html .=
'<td class="nowraponall">';
655 $totalarray[
'nbfield']++;
658 foreach ($object->fields as $key => $val) {
659 if (!empty($arrayfields[
't.' . $key][
'checked'])) {
660 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
't.' . $key][
'label'] .
'">';
661 if ($key ==
'status' || $key ==
'fk_statut') {
662 if ($elementEn ==
'invoice') {
664 $html .= $object->getLibStatut(5, $payment);
666 $html .= $object->getLibStatut(5);
668 } elseif ($key ==
'rowid') {
669 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $object->id,
'');
671 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $object->$key,
'');
677 $totalarray[
'nbfield']++;
679 if (!empty($val[
'isameasure']) && $val[
'isameasure'] == 1) {
681 $totalarray[
'pos'][$totalarray[
'nbfield']] =
't.' . $key;
683 if (!isset($totalarray[
'val'])) {
684 $totalarray[
'val'] = array();
686 if (!isset($totalarray[
'val'][
't.' . $key])) {
687 $totalarray[
'val'][
't.' . $key] = 0;
689 $totalarray[
'val'][
't.' . $key] += $object->$key;
694 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
695 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
'remain_to_pay'][
'label'] .
'">';
696 $html .= $this->form->showOutputFieldForObject($object, $arrayfields[
'remain_to_pay'],
'remain_to_pay', $remaintopay,
'');
700 $totalarray[
'nbfield']++;
704 if (!empty($arrayfields[
'download_link'][
'checked'])) {
705 $element = $object->element;
706 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
'download_link'][
'label'] .
'">';
708 $filedir = $conf->{$element}->multidir_output[$obj->element_entity] .
'/' .
dol_sanitizeFileName($obj->ref);
709 $html .= $this->form->getDocumentsLink($element, $filename, $filedir);
712 $totalarray[
'nbfield']++;
717 if (!empty($arrayfields[
'signature_link'][
'checked'])) {
718 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
'signature_link'][
'label'] .
'">';
720 $html .= $this->form->getSignatureLink(
'proposal', $object);
724 $totalarray[
'nbfield']++;
729 $parameters = array(
'arrayfields' => $arrayfields,
'object' => $object,
'obj' => $obj,
'i' => $i,
'totalarray' => &$totalarray);
730 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $object, $action);
731 $html .= $hookmanager->resPrint;
739 if (!empty($totalarray[
'totalizable']) && is_array($totalarray[
'totalizable'])) {
740 foreach ($totalarray[
'totalizable'] as $keytotalizable => $valtotalizable) {
741 $totalarray[
'pos'][$valtotalizable[
'pos']] = $keytotalizable;
742 $totalarray[
'val'][$keytotalizable] = isset($valtotalizable[
'total']) ? $valtotalizable[
'total'] : 0;
746 if (isset($totalarray[
'pos'])) {
749 while ($i < $totalarray[
'nbfield']) {
751 if (!empty($totalarray[
'pos'][$i])) {
752 $html .=
'<td class="nowraponall essai">';
753 $html .=
price(!empty($totalarray[
'val'][$totalarray[
'pos'][$i]]) ? $totalarray[
'val'][$totalarray[
'pos'][$i]] : 0);
757 $html .=
'<td>' . $langs->trans(
"Total") .
'</td>';
759 $html .=
'<td></td>';
769 foreach ($arrayfields as $key => $val) {
770 if (!empty($val[
'checked'])) {
774 $html .=
'<tr><td colspan="' . $colspan .
'"><span class="opacitymedium">' . $langs->trans(
"NoRecordFound") .
'</span></td></tr>';
779 $this->db->free($resql);
781 $parameters = array(
'arrayfields' => $arrayfields,
'sql' => $sql);
782 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters, $object, $action);
783 $html .= $hookmanager->resPrint;