257 global $conf, $hookmanager, $langs;
262 $action = $this->action;
263 $object = $this->object;
264 $limit = $this->limit;
266 $sortfield = $this->sortfield;
267 $sortorder = $this->sortorder;
268 $titleKey = $this->titleKey;
269 $contextpage = $this->contextpage;
270 $search = $this->search;
271 $arrayfields = $this->arrayfields;
272 $elementEn = $object->element;
273 if ($object->element ==
'commande') {
274 $elementEn =
'order';
275 } elseif ($object->element ==
'facture') {
276 $elementEn =
'invoice';
281 if ($elementEn ==
'invoice') {
286 $emptyValueKey = ($elementEn ==
'order' ? -5 : -1);
289 $limit = $conf->liste_limit;
294 $offset = $limit * ($page - 1);
296 reset($object->fields);
297 $sortfield =
't.' . key($object->fields);
303 $socid = (int) $context->logged_thirdparty->id;
308 $sql .= $object->getFieldList(
't');
309 $sql .=
", t.entity as element_entity";
311 $parameters = array();
312 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters, $object, $action);
313 $sql .= $hookmanager->resPrint;
314 $sql = preg_replace(
'/,\s*$/',
'', $sql);
318 $sql .=
" FROM " . $this->db->prefix() . $object->table_element .
" as t";
320 $parameters = array();
321 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters, $object, $action);
322 $sql .= $hookmanager->resPrint;
323 if ($object->ismultientitymanaged == 1) {
324 $sql .=
" WHERE t.entity IN (" .
getEntity($object->element, (
GETPOSTINT(
'search_current_entity') ? 0 : 1)) .
")";
326 $sql .=
" WHERE 1 = 1";
329 $sql .=
" AND t.fk_soc = " . ((int) $socid);
331 $sql .=
" AND t.fk_statut <> 0";
333 foreach ($search as $key => $val) {
334 if (array_key_exists($key, $object->fields)) {
335 if (($key ==
'status' || $key ==
'fk_statut') && $search[$key] == $emptyValueKey) {
338 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
339 if ((strpos($object->fields[$key][
'type'],
'integer:') === 0) || (strpos($object->fields[$key][
'type'],
'sellist:') === 0) || !empty($object->fields[$key][
'arrayofkeyval'])) {
340 if ($search[$key] ==
"$emptyValueKey" || ($search[$key] ===
'0' && (empty($object->fields[$key][
'arrayofkeyval']) || !array_key_exists(
'0', $object->fields[$key][
'arrayofkeyval'])))) {
345 if ($search[$key] !=
'') {
346 $sql .=
natural_search(
"t." . $this->db->escape($key), $search[$key], (($key ==
'status' || $key ==
'fk_statut') ? ($search[$key] < 0 ? 1 : 2) : $mode_search));
349 if (preg_match(
'/(_dtstart|_dtend)$/', $key) && $search[$key] !=
'') {
350 $columnName = preg_replace(
'/(_dtstart|_dtend)$/',
'', $key);
351 if (preg_match(
'/^(date|timestamp|datetime)/', $object->fields[$columnName][
'type'])) {
352 if (preg_match(
'/_dtstart$/', $key)) {
353 $sql .=
" AND t." . $this->db->escape($columnName) .
" >= '" . $this->db->idate($search[$key]) .
"'";
355 if (preg_match(
'/_dtend$/', $key)) {
356 $sql .=
" AND t." . $this->db->escape($columnName) .
" <= '" . $this->db->idate($search[$key]) .
"'";
366 $parameters = array();
367 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $object, $action);
368 $sql .= $hookmanager->resPrint;
371 $nbtotalofrecords = 0;
374 $sqlforcount = preg_replace(
'/^' . preg_quote($sqlfields,
'/') .
'/',
'SELECT COUNT(*) as nbtotalofrecords', $sql);
375 $sqlforcount = preg_replace(
'/GROUP BY .*$/',
'', $sqlforcount);
376 $resql = $this->db->query($sqlforcount);
378 $objforcount = $this->db->fetch_object($resql);
379 $nbtotalofrecords = (int) $objforcount->nbtotalofrecords;
384 if ($offset > $nbtotalofrecords) {
389 $this->db->free($resql);
393 $sql .= $this->db->order($sortfield, $sortorder);
395 $sql .= $this->db->plimit($limit, $offset);
398 $resql = $this->db->query($sql);
404 $num = $this->db->num_rows($resql);
406 $nbpages = ceil($nbtotalofrecords / $limit);
414 $sortFieldList = explode(
",", $sortfield);
415 $sortOrderList = explode(
",", $sortorder);
417 if (!empty($sortFieldList)) {
418 foreach ($sortFieldList as $sortField) {
419 if (isset($sortOrderList[$sortFieldIndex])) {
420 $sortList[$sortField] = $sortOrderList[$sortFieldIndex];
427 $param .=
'&contextpage=' . urlencode($contextpage);
428 $param .=
'&limit=' . $limit;
429 foreach ($search as $key => $val) {
430 if (is_array($search[$key])) {
431 foreach ($search[$key] as $skey) {
433 $param .=
'&search_' . $key .
'[]=' . urlencode($skey);
436 } elseif (preg_match(
'/(_dtstart|_dtend)$/', $key) && !empty($val)) {
437 $param .=
'&search_' . $key .
'month=' . (
GETPOSTINT(
'search_' . $key .
'month'));
438 $param .=
'&search_' . $key .
'day=' . (
GETPOSTINT(
'search_' . $key .
'day'));
439 $param .=
'&search_' . $key .
'year=' . (
GETPOSTINT(
'search_' . $key .
'year'));
440 } elseif ($search[$key] !=
'') {
441 $param .=
'&search_' . $key .
'=' . urlencode($search[$key]);
445 $parameters = array();
446 $reshook = $hookmanager->executeHooks(
'printFieldListSearchParam', $parameters, $object, $action);
447 $param .= $hookmanager->resPrint;
449 $url_file = $context->getControllerUrl($context->controller);
450 $html .=
'<form method="POST" id="searchFormList" action="' . $url_file .
'">' .
"\n";
451 $html .= $context->getFormToken();
452 $html .=
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
453 $html .=
'<input type="hidden" name="action" value="list">';
454 $html .=
'<input type="hidden" name="sortfield" value="' . $sortfield .
'">';
455 $html .=
'<input type="hidden" name="sortorder" value="' . $sortorder .
'">';
456 $html .=
'<input type="hidden" name="page" value="' . $page .
'">';
457 $html .=
'<input type="hidden" name="contextpage" value="' . $contextpage .
'">';
460 $pagination_param = $param .
'&sortfield=' . $sortfield .
'&sortorder=' . $sortorder;
461 $html .=
'<nav id="webportal-' . $elementEn .
'-pagination">';
463 $html .=
'<li><strong>' . $langs->trans($titleKey) .
'</strong> (' . $nbtotalofrecords .
')</li>';
467 $html .= static::generatePageListNav($url_file . $pagination_param, $nbpages, $page);
472 $html .=
'<table id="webportal-' . $elementEn .
'-list" responsive="scroll" role="grid">';
487 $html .=
'<tr role="search-row">';
490 $html .=
'<td data-col="row-checkbox" >';
491 $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>';
492 $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>';
495 foreach ($object->fields as $key => $val) {
496 if (!empty($arrayfields[
't.' . $key][
'checked'])) {
497 $html .=
'<td data-label="' . $arrayfields[
't.' . $key][
'label'] .
'" data-col="'.dol_escape_htmltag($key).
'" >';
498 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
499 $html .= $this->form->selectarray(
'search_' . $key, $val[
'arrayofkeyval'], (isset($search[$key]) ? $search[$key] :
''), $val[
'notnull'], 0, 0,
'', 1, 0, 0,
'',
'');
500 } elseif (preg_match(
'/^(date|timestamp|datetime)/', $val[
'type'])) {
501 $postDateStart =
dol_mktime(0, 0, 0, $search[$key .
'_dtstartmonth'], $search[$key .
'_dtstartday'], $search[$key .
'_dtstartyear']);
502 $postDateEnd =
dol_mktime(0, 0, 0, $search[$key .
'_dtendmonth'], $search[$key .
'_dtendday'], $search[$key .
'_dtendyear']);
504 $html .=
'<div class="grid width150">';
505 $html .= $this->form->inputDate(
'search_' . $key .
'_dtstart', $postDateStart ? $postDateStart :
'', $langs->trans(
'From'));
507 $html .=
'<div class="grid width150">';
508 $html .= $this->form->inputDate(
'search_' . $key .
'_dtend', $postDateEnd ? $postDateEnd :
'', $langs->trans(
'to'));
511 $html .=
'<input type="text" name="search_' . $key .
'" value="' .
dol_escape_htmltag(isset($search[$key]) ? $search[$key] :
'') .
'">';
517 $parameters = array(
'arrayfields' => $arrayfields);
518 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters, $object, $action);
519 $html .= $hookmanager->resPrint;
521 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
522 $html .=
'<td data-label="' . $arrayfields[
'remain_to_pay'][
'label'] .
'">';
526 if (!empty($arrayfields[
'download_link'][
'checked'])) {
527 $html .=
'<td data-label="' . $arrayfields[
'download_link'][
'label'] .
'">';
533 $totalarray = array();
534 $totalarray[
'nbfield'] = 0;
541 $html .=
'<th data-col="row-checkbox" ></th>';
542 $totalarray[
'nbfield']++;
544 foreach ($object->fields as $key => $val) {
545 $tableKey =
't.' . $key;
546 if (!empty($arrayfields[$tableKey][
'checked'])) {
548 if (array_key_exists($tableKey, $sortList)) {
549 $tableOrder = strtolower($sortList[$tableKey]);
551 $url_param = $url_file .
'&sortfield=' . $tableKey .
'&sortorder=' . ($tableOrder ==
'desc' ?
'asc' :
'desc') . $param;
552 $html .=
'<th data-col="'.dol_escape_htmltag($key).
'" scope="col"' . ($tableOrder !=
'' ?
' table-order="' . $tableOrder .
'"' :
'') .
'>';
553 $html .=
'<a href="' . $url_param .
'">';
554 $html .= $langs->trans($arrayfields[
't.' . $key][
'label']);
557 $totalarray[
'nbfield']++;
561 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
562 $html .=
'<th scope="col">';
563 $html .= $langs->trans($arrayfields[
'remain_to_pay'][
'label']);
565 $totalarray[
'nbfield']++;
568 if (!empty($arrayfields[
'download_link'][
'checked'])) {
569 $html .=
'<th scope="col">';
570 $html .= $langs->trans($arrayfields[
'download_link'][
'label']);
572 $totalarray[
'nbfield']++;
576 $parameters = array(
'arrayfields' => $arrayfields,
'sortfield' => $sortfield,
'sortorder' => $sortorder,
'totalarray' => &$totalarray);
577 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $object, $action);
578 $html .= $hookmanager->resPrint;
586 $idCompany = (int) $socid;
587 if (!isset($this->companyStaticList[$socid])) {
588 $companyStatic =
new Societe($this->db);
589 $companyStatic->fetch($idCompany);
590 $this->companyStaticList[$idCompany] = $companyStatic;
592 $companyStatic = $this->companyStaticList[$socid];
601 $imaxinloop = ($limit ? min($num, $limit) : $num);
602 while ($i < $imaxinloop) {
603 $obj = $this->db->fetch_object($resql);
609 $object->setVarsFromFetchObj($obj);
613 if ($elementEn ==
'invoice') {
615 $payment = $object->getSommePaiement();
616 $totalcreditnotes = $object->getSumCreditNotesUsed();
617 $totaldeposits = $object->getSumDepositsUsed();
620 $totalpay = $payment + $totalcreditnotes + $totaldeposits;
621 $remaintopay =
price2num($object->total_ttc - $totalpay);
626 $remaincreditnote = $discount->getAvailableDiscounts($companyStatic,
'',
'rc.fk_facture_source=' . $object->id);
627 $remaintopay = -$remaincreditnote;
632 $html .=
'<tr data-rowid="' . $object->id .
'">';
634 $html .=
'<td class="nowraponall">';
637 $totalarray[
'nbfield']++;
640 foreach ($object->fields as $key => $val) {
641 if (!empty($arrayfields[
't.' . $key][
'checked'])) {
642 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
't.' . $key][
'label'] .
'">';
643 if ($key ==
'status' || $key ==
'fk_statut') {
644 if ($elementEn ==
'invoice') {
646 $html .= $object->getLibStatut(5, $payment);
648 $html .= $object->getLibStatut(5);
650 } elseif ($key ==
'rowid') {
651 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $object->id,
'');
653 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $object->$key,
'');
659 $totalarray[
'nbfield']++;
661 if (!empty($val[
'isameasure']) && $val[
'isameasure'] == 1) {
663 $totalarray[
'pos'][$totalarray[
'nbfield']] =
't.' . $key;
665 if (!isset($totalarray[
'val'])) {
666 $totalarray[
'val'] = array();
668 if (!isset($totalarray[
'val'][
't.' . $key])) {
669 $totalarray[
'val'][
't.' . $key] = 0;
671 $totalarray[
'val'][
't.' . $key] += $object->$key;
676 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
677 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
'remain_to_pay'][
'label'] .
'">';
678 $html .= $this->form->showOutputFieldForObject($object, $arrayfields[
'remain_to_pay'],
'remain_to_pay', $remaintopay,
'');
682 $totalarray[
'nbfield']++;
686 if (!empty($arrayfields[
'download_link'][
'checked'])) {
687 $element = $object->element;
688 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
'download_link'][
'label'] .
'">';
690 $filedir = $conf->{$element}->multidir_output[$obj->element_entity] .
'/' .
dol_sanitizeFileName($obj->ref);
691 $html .= $this->form->getDocumentsLink($element, $filename, $filedir);
694 $totalarray[
'nbfield']++;
698 $parameters = array(
'arrayfields' => $arrayfields,
'object' => $object,
'obj' => $obj,
'i' => $i,
'totalarray' => &$totalarray);
699 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $object, $action);
700 $html .= $hookmanager->resPrint;
709 if (!empty($totalarray[
'totalizable']) && is_array($totalarray[
'totalizable'])) {
710 foreach ($totalarray[
'totalizable'] as $keytotalizable => $valtotalizable) {
711 $totalarray[
'pos'][$valtotalizable[
'pos']] = $keytotalizable;
712 $totalarray[
'val'][$keytotalizable] = isset($valtotalizable[
'total']) ? $valtotalizable[
'total'] : 0;
716 if (isset($totalarray[
'pos'])) {
719 while ($i < $totalarray[
'nbfield']) {
721 if (!empty($totalarray[
'pos'][$i])) {
722 $html .=
'<td class="nowraponall essai">';
723 $html .=
price(!empty($totalarray[
'val'][$totalarray[
'pos'][$i]]) ? $totalarray[
'val'][$totalarray[
'pos'][$i]] : 0);
727 $html .=
'<td>' . $langs->trans(
"Total") .
'</td>';
729 $html .=
'<td></td>';
739 foreach ($arrayfields as $key => $val) {
740 if (!empty($val[
'checked'])) {
744 $html .=
'<tr><td colspan="' . $colspan .
'"><span class="opacitymedium">' . $langs->trans(
"NoRecordFound") .
'</span></td></tr>';
749 $this->db->free($resql);
751 $parameters = array(
'arrayfields' => $arrayfields,
'sql' => $sql);
752 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters, $object, $action);
753 $html .= $hookmanager->resPrint;