243 global $conf, $hookmanager, $langs;
248 $action = $this->action;
249 $object = $this->object;
250 $limit = $this->limit;
252 $sortfield = $this->sortfield;
253 $sortorder = $this->sortorder;
254 $titleKey = $this->titleKey;
255 $contextpage = $this->contextpage;
256 $search = $this->search;
257 $arrayfields = $this->arrayfields;
258 $elementEn = $object->element;
259 if ($object->element ==
'commande') {
260 $elementEn =
'order';
261 } elseif ($object->element ==
'facture') {
262 $elementEn =
'invoice';
267 if ($elementEn ==
'invoice') {
272 $emptyValueKey = ($elementEn ==
'order' ? -5 : -1);
275 $limit = $conf->liste_limit;
280 $offset = $limit * ($page - 1);
282 reset($object->fields);
283 $sortfield =
't.' . key($object->fields);
289 $socid = (int) $context->logged_thirdparty->id;
294 $sql .= $object->getFieldList(
't');
295 $sql .=
", t.entity as element_entity";
297 $parameters = array();
298 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters, $object, $action);
299 $sql .= $hookmanager->resPrint;
300 $sql = preg_replace(
'/,\s*$/',
'', $sql);
304 $sql .=
" FROM " . $this->db->prefix() . $object->table_element .
" as t";
306 $parameters = array();
307 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters, $object, $action);
308 $sql .= $hookmanager->resPrint;
309 if ($object->ismultientitymanaged == 1) {
310 $sql .=
" WHERE t.entity IN (" .
getEntity($object->element, (
GETPOSTINT(
'search_current_entity') ? 0 : 1)) .
")";
312 $sql .=
" WHERE 1 = 1";
315 $sql .=
" AND t.fk_soc = " . ((int) $socid);
317 $sql .=
" AND t.fk_statut <> 0";
319 foreach ($search as $key => $val) {
320 if (array_key_exists($key, $object->fields)) {
321 if (($key ==
'status' || $key ==
'fk_statut') && $search[$key] == $emptyValueKey) {
324 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
325 if ((strpos($object->fields[$key][
'type'],
'integer:') === 0) || (strpos($object->fields[$key][
'type'],
'sellist:') === 0) || !empty($object->fields[$key][
'arrayofkeyval'])) {
326 if ($search[$key] ==
"$emptyValueKey" || ($search[$key] ===
'0' && (empty($object->fields[$key][
'arrayofkeyval']) || !array_key_exists(
'0', $object->fields[$key][
'arrayofkeyval'])))) {
331 if ($search[$key] !=
'') {
332 $sql .=
natural_search(
"t." . $this->db->escape($key), $search[$key], (($key ==
'status' || $key ==
'fk_statut') ? ($search[$key] < 0 ? 1 : 2) : $mode_search));
335 if (preg_match(
'/(_dtstart|_dtend)$/', $key) && $search[$key] !=
'') {
336 $columnName = preg_replace(
'/(_dtstart|_dtend)$/',
'', $key);
337 if (preg_match(
'/^(date|timestamp|datetime)/', $object->fields[$columnName][
'type'])) {
338 if (preg_match(
'/_dtstart$/', $key)) {
339 $sql .=
" AND t." . $this->db->escape($columnName) .
" >= '" . $this->db->idate($search[$key]) .
"'";
341 if (preg_match(
'/_dtend$/', $key)) {
342 $sql .=
" AND t." . $this->db->escape($columnName) .
" <= '" . $this->db->idate($search[$key]) .
"'";
352 $parameters = array();
353 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $object, $action);
354 $sql .= $hookmanager->resPrint;
357 $nbtotalofrecords = 0;
360 $sqlforcount = preg_replace(
'/^' . preg_quote($sqlfields,
'/') .
'/',
'SELECT COUNT(*) as nbtotalofrecords', $sql);
361 $sqlforcount = preg_replace(
'/GROUP BY .*$/',
'', $sqlforcount);
362 $resql = $this->db->query($sqlforcount);
364 $objforcount = $this->db->fetch_object($resql);
365 $nbtotalofrecords = (int) $objforcount->nbtotalofrecords;
370 if ($offset > $nbtotalofrecords) {
375 $this->db->free($resql);
379 $sql .= $this->db->order($sortfield, $sortorder);
381 $sql .= $this->db->plimit($limit, $offset);
384 $resql = $this->db->query($sql);
390 $num = $this->db->num_rows($resql);
392 $nbpages = ceil($nbtotalofrecords / $limit);
400 $sortFieldList = explode(
",", $sortfield);
401 $sortOrderList = explode(
",", $sortorder);
403 if (!empty($sortFieldList)) {
404 foreach ($sortFieldList as $sortField) {
405 if (isset($sortOrderList[$sortFieldIndex])) {
406 $sortList[$sortField] = $sortOrderList[$sortFieldIndex];
413 $param .=
'&contextpage=' . urlencode($contextpage);
414 $param .=
'&limit=' . $limit;
415 foreach ($search as $key => $val) {
416 if (is_array($search[$key])) {
417 foreach ($search[$key] as $skey) {
419 $param .=
'&search_' . $key .
'[]=' . urlencode($skey);
422 } elseif (preg_match(
'/(_dtstart|_dtend)$/', $key) && !empty($val)) {
423 $param .=
'&search_' . $key .
'month=' . (
GETPOSTINT(
'search_' . $key .
'month'));
424 $param .=
'&search_' . $key .
'day=' . (
GETPOSTINT(
'search_' . $key .
'day'));
425 $param .=
'&search_' . $key .
'year=' . (
GETPOSTINT(
'search_' . $key .
'year'));
426 } elseif ($search[$key] !=
'') {
427 $param .=
'&search_' . $key .
'=' . urlencode($search[$key]);
431 $parameters = array();
432 $reshook = $hookmanager->executeHooks(
'printFieldListSearchParam', $parameters, $object, $action);
433 $param .= $hookmanager->resPrint;
435 $url_file = $context->getControllerUrl($context->controller);
436 $html .=
'<form method="POST" id="searchFormList" action="' . $url_file .
'">' .
"\n";
437 $html .= $context->getFormToken();
438 $html .=
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
439 $html .=
'<input type="hidden" name="action" value="list">';
440 $html .=
'<input type="hidden" name="sortfield" value="' . $sortfield .
'">';
441 $html .=
'<input type="hidden" name="sortorder" value="' . $sortorder .
'">';
442 $html .=
'<input type="hidden" name="page" value="' . $page .
'">';
443 $html .=
'<input type="hidden" name="contextpage" value="' . $contextpage .
'">';
446 $pagination_param = $param .
'&sortfield=' . $sortfield .
'&sortorder=' . $sortorder;
447 $html .=
'<nav id="webportal-' . $elementEn .
'-pagination">';
449 $html .=
'<li><strong>' . $langs->trans($titleKey) .
'</strong> (' . $nbtotalofrecords .
')</li>';
453 $html .= static::generatePageListNav($url_file . $pagination_param, $nbpages, $page);
458 $html .=
'<table id="webportal-' . $elementEn .
'-list" responsive="scroll" role="grid">';
473 $html .=
'<tr role="search-row">';
476 $html .=
'<td data-col="row-checkbox" >';
477 $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>';
478 $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>';
481 foreach ($object->fields as $key => $val) {
482 if (!empty($arrayfields[
't.' . $key][
'checked'])) {
483 $html .=
'<td data-label="' . $arrayfields[
't.' . $key][
'label'] .
'" data-col="'.dol_escape_htmltag($key).
'" >';
484 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
485 $html .= $this->form->selectarray(
'search_' . $key, $val[
'arrayofkeyval'], (isset($search[$key]) ? $search[$key] :
''), $val[
'notnull'], 0, 0,
'', 1, 0, 0,
'',
'');
486 } elseif (preg_match(
'/^(date|timestamp|datetime)/', $val[
'type'])) {
487 $postDateStart =
GETPOST(
'search_' . $key .
'_dtstart',
'alphanohtml');
488 $postDateEnd =
GETPOST(
'search_' . $key .
'_dtend',
'alphanohtml');
490 $html .=
'<div class="grid">';
491 $html .= $this->form->inputDate(
'search_' . $key .
'_dtstart', $postDateStart ? $postDateStart :
'', $langs->trans(
'From'));
493 $html .=
'<div class="grid">';
494 $html .= $this->form->inputDate(
'search_' . $key .
'_dtend', $postDateEnd ? $postDateEnd :
'', $langs->trans(
'to'));
497 $html .=
'<input type="text" name="search_' . $key .
'" value="' .
dol_escape_htmltag(isset($search[$key]) ? $search[$key] :
'') .
'">';
503 $parameters = array(
'arrayfields' => $arrayfields);
504 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters, $object, $action);
505 $html .= $hookmanager->resPrint;
507 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
508 $html .=
'<td data-label="' . $arrayfields[
'remain_to_pay'][
'label'] .
'">';
512 if (!empty($arrayfields[
'download_link'][
'checked'])) {
513 $html .=
'<td data-label="' . $arrayfields[
'download_link'][
'label'] .
'">';
519 $totalarray = array();
520 $totalarray[
'nbfield'] = 0;
527 $html .=
'<th data-col="row-checkbox" ></th>';
528 $totalarray[
'nbfield']++;
530 foreach ($object->fields as $key => $val) {
531 $tableKey =
't.' . $key;
532 if (!empty($arrayfields[$tableKey][
'checked'])) {
534 if (array_key_exists($tableKey, $sortList)) {
535 $tableOrder = strtolower($sortList[$tableKey]);
537 $url_param = $url_file .
'&sortfield=' . $tableKey .
'&sortorder=' . ($tableOrder ==
'desc' ?
'asc' :
'desc') . $param;
538 $html .=
'<th data-col="'.dol_escape_htmltag($key).
'" scope="col"' . ($tableOrder !=
'' ?
' table-order="' . $tableOrder .
'"' :
'') .
'>';
539 $html .=
'<a href="' . $url_param .
'">';
540 $html .= $langs->trans($arrayfields[
't.' . $key][
'label']);
543 $totalarray[
'nbfield']++;
547 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
548 $html .=
'<th scope="col">';
549 $html .= $langs->trans($arrayfields[
'remain_to_pay'][
'label']);
551 $totalarray[
'nbfield']++;
554 if (!empty($arrayfields[
'download_link'][
'checked'])) {
555 $html .=
'<th scope="col">';
556 $html .= $langs->trans($arrayfields[
'download_link'][
'label']);
558 $totalarray[
'nbfield']++;
562 $parameters = array(
'arrayfields' => $arrayfields,
'sortfield' => $sortfield,
'sortorder' => $sortorder,
'totalarray' => &$totalarray);
563 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $object, $action);
564 $html .= $hookmanager->resPrint;
572 $idCompany = (int) $socid;
573 if (!isset($this->companyStaticList[$socid])) {
574 $companyStatic =
new Societe($this->db);
575 $companyStatic->fetch($idCompany);
576 $this->companyStaticList[$idCompany] = $companyStatic;
578 $companyStatic = $this->companyStaticList[$socid];
587 $imaxinloop = ($limit ? min($num, $limit) : $num);
588 while ($i < $imaxinloop) {
589 $obj = $this->db->fetch_object($resql);
595 $object->setVarsFromFetchObj($obj);
599 if ($elementEn ==
'invoice') {
601 $payment = $object->getSommePaiement();
602 $totalcreditnotes = $object->getSumCreditNotesUsed();
603 $totaldeposits = $object->getSumDepositsUsed();
606 $totalpay = $payment + $totalcreditnotes + $totaldeposits;
607 $remaintopay =
price2num($object->total_ttc - $totalpay);
612 $remaincreditnote = $discount->getAvailableDiscounts($companyStatic,
'',
'rc.fk_facture_source=' . $object->id);
613 $remaintopay = -$remaincreditnote;
618 $html .=
'<tr data-rowid="' . $object->id .
'">';
620 $html .=
'<td class="nowraponall">';
623 $totalarray[
'nbfield']++;
626 foreach ($object->fields as $key => $val) {
627 if (!empty($arrayfields[
't.' . $key][
'checked'])) {
628 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
't.' . $key][
'label'] .
'">';
629 if ($key ==
'status' || $key ==
'fk_statut') {
630 if ($elementEn ==
'invoice') {
632 $html .= $object->getLibStatut(5, $payment);
634 $html .= $object->getLibStatut(5);
636 } elseif ($key ==
'rowid') {
637 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $object->id,
'');
639 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $object->$key,
'');
645 $totalarray[
'nbfield']++;
647 if (!empty($val[
'isameasure']) && $val[
'isameasure'] == 1) {
649 $totalarray[
'pos'][$totalarray[
'nbfield']] =
't.' . $key;
651 if (!isset($totalarray[
'val'])) {
652 $totalarray[
'val'] = array();
654 if (!isset($totalarray[
'val'][
't.' . $key])) {
655 $totalarray[
'val'][
't.' . $key] = 0;
657 $totalarray[
'val'][
't.' . $key] += $object->$key;
662 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
663 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
'remain_to_pay'][
'label'] .
'">';
664 $html .= $this->form->showOutputFieldForObject($object, $arrayfields[
'remain_to_pay'],
'remain_to_pay', $remaintopay,
'');
668 $totalarray[
'nbfield']++;
672 if (!empty($arrayfields[
'download_link'][
'checked'])) {
673 $element = $object->element;
674 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
'download_link'][
'label'] .
'">';
676 $filedir = $conf->{$element}->multidir_output[$obj->element_entity] .
'/' .
dol_sanitizeFileName($obj->ref);
677 $html .= $this->form->getDocumentsLink($element, $filename, $filedir);
680 $totalarray[
'nbfield']++;
684 $parameters = array(
'arrayfields' => $arrayfields,
'object' => $object,
'obj' => $obj,
'i' => $i,
'totalarray' => &$totalarray);
685 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $object, $action);
686 $html .= $hookmanager->resPrint;
695 if (!empty($totalarray[
'totalizable']) && is_array($totalarray[
'totalizable'])) {
696 foreach ($totalarray[
'totalizable'] as $keytotalizable => $valtotalizable) {
697 $totalarray[
'pos'][$valtotalizable[
'pos']] = $keytotalizable;
698 $totalarray[
'val'][$keytotalizable] = isset($valtotalizable[
'total']) ? $valtotalizable[
'total'] : 0;
702 if (isset($totalarray[
'pos'])) {
705 while ($i < $totalarray[
'nbfield']) {
707 if (!empty($totalarray[
'pos'][$i])) {
708 $html .=
'<td class="nowraponall essai">';
709 $html .=
price(!empty($totalarray[
'val'][$totalarray[
'pos'][$i]]) ? $totalarray[
'val'][$totalarray[
'pos'][$i]] : 0);
713 $html .=
'<td>' . $langs->trans(
"Total") .
'</td>';
715 $html .=
'<td></td>';
725 foreach ($arrayfields as $key => $val) {
726 if (!empty($val[
'checked'])) {
730 $html .=
'<tr><td colspan="' . $colspan .
'"><span class="opacitymedium">' . $langs->trans(
"NoRecordFound") .
'</span></td></tr>';
735 $this->db->free($resql);
737 $parameters = array(
'arrayfields' => $arrayfields,
'sql' => $sql);
738 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters, $object, $action);
739 $html .= $hookmanager->resPrint;