246 global $conf, $hookmanager, $langs;
251 $action = $this->action;
252 $object = $this->object;
253 $limit = $this->limit;
255 $sortfield = $this->sortfield;
256 $sortorder = $this->sortorder;
257 $titleKey = $this->titleKey;
258 $contextpage = $this->contextpage;
259 $search = $this->search;
260 $arrayfields = $this->arrayfields;
261 $elementEn = $object->element;
262 if ($object->element ==
'commande') {
263 $elementEn =
'order';
264 } elseif ($object->element ==
'facture') {
265 $elementEn =
'invoice';
270 if ($elementEn ==
'invoice') {
275 $emptyValueKey = ($elementEn ==
'order' ? -5 : -1);
278 $limit = $conf->liste_limit;
283 $offset = $limit * ($page - 1);
285 reset($object->fields);
286 $sortfield =
't.' . key($object->fields);
292 $socid = (int) $context->logged_thirdparty->id;
297 $sql .= $object->getFieldList(
't');
298 $sql .=
", t.entity as element_entity";
300 $parameters = array();
301 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters, $object, $action);
302 $sql .= $hookmanager->resPrint;
303 $sql = preg_replace(
'/,\s*$/',
'', $sql);
307 $sql .=
" FROM " . $this->db->prefix() . $object->table_element .
" as t";
309 $parameters = array();
310 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters, $object, $action);
311 $sql .= $hookmanager->resPrint;
312 if ($object->ismultientitymanaged == 1) {
313 $sql .=
" WHERE t.entity IN (" .
getEntity($object->element, (
GETPOSTINT(
'search_current_entity') ? 0 : 1)) .
")";
315 $sql .=
" WHERE 1 = 1";
318 $sql .=
" AND t.fk_soc = " . ((int) $socid);
320 $sql .=
" AND t.fk_statut <> 0";
322 foreach ($search as $key => $val) {
323 if (array_key_exists($key, $object->fields)) {
324 if (($key ==
'status' || $key ==
'fk_statut') && $search[$key] == $emptyValueKey) {
327 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
328 if ((strpos($object->fields[$key][
'type'],
'integer:') === 0) || (strpos($object->fields[$key][
'type'],
'sellist:') === 0) || !empty($object->fields[$key][
'arrayofkeyval'])) {
329 if ($search[$key] ==
"$emptyValueKey" || ($search[$key] ===
'0' && (empty($object->fields[$key][
'arrayofkeyval']) || !array_key_exists(
'0', $object->fields[$key][
'arrayofkeyval'])))) {
334 if ($search[$key] !=
'') {
335 $sql .=
natural_search(
"t." . $this->db->escape($key), $search[$key], (($key ==
'status' || $key ==
'fk_statut') ? ($search[$key] < 0 ? 1 : 2) : $mode_search));
338 if (preg_match(
'/(_dtstart|_dtend)$/', $key) && $search[$key] !=
'') {
339 $columnName = preg_replace(
'/(_dtstart|_dtend)$/',
'', $key);
340 if (preg_match(
'/^(date|timestamp|datetime)/', $object->fields[$columnName][
'type'])) {
341 if (preg_match(
'/_dtstart$/', $key)) {
342 $sql .=
" AND t." . $this->db->escape($columnName) .
" >= '" . $this->db->idate($search[$key]) .
"'";
344 if (preg_match(
'/_dtend$/', $key)) {
345 $sql .=
" AND t." . $this->db->escape($columnName) .
" <= '" . $this->db->idate($search[$key]) .
"'";
355 $parameters = array();
356 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $object, $action);
357 $sql .= $hookmanager->resPrint;
360 $nbtotalofrecords = 0;
363 $sqlforcount = preg_replace(
'/^' . preg_quote($sqlfields,
'/') .
'/',
'SELECT COUNT(*) as nbtotalofrecords', $sql);
364 $sqlforcount = preg_replace(
'/GROUP BY .*$/',
'', $sqlforcount);
365 $resql = $this->db->query($sqlforcount);
367 $objforcount = $this->db->fetch_object($resql);
368 $nbtotalofrecords = (int) $objforcount->nbtotalofrecords;
373 if ($offset > $nbtotalofrecords) {
378 $this->db->free($resql);
382 $sql .= $this->db->order($sortfield, $sortorder);
384 $sql .= $this->db->plimit($limit, $offset);
387 $resql = $this->db->query($sql);
393 $num = $this->db->num_rows($resql);
395 $nbpages = ceil($nbtotalofrecords / $limit);
403 $sortFieldList = explode(
",", $sortfield);
404 $sortOrderList = explode(
",", $sortorder);
406 if (!empty($sortFieldList)) {
407 foreach ($sortFieldList as $sortField) {
408 if (isset($sortOrderList[$sortFieldIndex])) {
409 $sortList[$sortField] = $sortOrderList[$sortFieldIndex];
416 $param .=
'&contextpage=' . urlencode($contextpage);
417 $param .=
'&limit=' . $limit;
418 foreach ($search as $key => $val) {
419 if (is_array($search[$key])) {
420 foreach ($search[$key] as $skey) {
422 $param .=
'&search_' . $key .
'[]=' . urlencode($skey);
425 } elseif (preg_match(
'/(_dtstart|_dtend)$/', $key) && !empty($val)) {
426 $param .=
'&search_' . $key .
'month=' . (
GETPOSTINT(
'search_' . $key .
'month'));
427 $param .=
'&search_' . $key .
'day=' . (
GETPOSTINT(
'search_' . $key .
'day'));
428 $param .=
'&search_' . $key .
'year=' . (
GETPOSTINT(
'search_' . $key .
'year'));
429 } elseif ($search[$key] !=
'') {
430 $param .=
'&search_' . $key .
'=' . urlencode($search[$key]);
434 $parameters = array();
435 $reshook = $hookmanager->executeHooks(
'printFieldListSearchParam', $parameters, $object, $action);
436 $param .= $hookmanager->resPrint;
438 $url_file = $context->getControllerUrl($context->controller);
439 $html .=
'<form method="POST" id="searchFormList" action="' . $url_file .
'">' .
"\n";
440 $html .= $context->getFormToken();
441 $html .=
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
442 $html .=
'<input type="hidden" name="action" value="list">';
443 $html .=
'<input type="hidden" name="sortfield" value="' . $sortfield .
'">';
444 $html .=
'<input type="hidden" name="sortorder" value="' . $sortorder .
'">';
445 $html .=
'<input type="hidden" name="page" value="' . $page .
'">';
446 $html .=
'<input type="hidden" name="contextpage" value="' . $contextpage .
'">';
449 $pagination_param = $param .
'&sortfield=' . $sortfield .
'&sortorder=' . $sortorder;
450 $html .=
'<nav id="webportal-' . $elementEn .
'-pagination">';
452 $html .=
'<li><strong>' . $langs->trans($titleKey) .
'</strong> (' . $nbtotalofrecords .
')</li>';
456 $html .= static::generatePageListNav($url_file . $pagination_param, $nbpages, $page);
461 $html .=
'<table id="webportal-' . $elementEn .
'-list" responsive="scroll" role="grid">';
476 $html .=
'<tr role="search-row">';
479 $html .=
'<td data-col="row-checkbox" >';
480 $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>';
481 $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>';
484 foreach ($object->fields as $key => $val) {
485 if (!empty($arrayfields[
't.' . $key][
'checked'])) {
486 $html .=
'<td data-label="' . $arrayfields[
't.' . $key][
'label'] .
'" data-col="'.dol_escape_htmltag($key).
'" >';
487 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
488 $html .= $this->form->selectarray(
'search_' . $key, $val[
'arrayofkeyval'], (isset($search[$key]) ? $search[$key] :
''), $val[
'notnull'], 0, 0,
'', 1, 0, 0,
'',
'');
489 } elseif (preg_match(
'/^(date|timestamp|datetime)/', $val[
'type'])) {
490 $postDateStart =
GETPOST(
'search_' . $key .
'_dtstart',
'alphanohtml');
491 $postDateEnd =
GETPOST(
'search_' . $key .
'_dtend',
'alphanohtml');
493 $html .=
'<div class="grid">';
494 $html .= $this->form->inputDate(
'search_' . $key .
'_dtstart', $postDateStart ? $postDateStart :
'', $langs->trans(
'From'));
496 $html .=
'<div class="grid">';
497 $html .= $this->form->inputDate(
'search_' . $key .
'_dtend', $postDateEnd ? $postDateEnd :
'', $langs->trans(
'to'));
500 $html .=
'<input type="text" name="search_' . $key .
'" value="' .
dol_escape_htmltag(isset($search[$key]) ? $search[$key] :
'') .
'">';
506 $parameters = array(
'arrayfields' => $arrayfields);
507 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters, $object, $action);
508 $html .= $hookmanager->resPrint;
510 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
511 $html .=
'<td data-label="' . $arrayfields[
'remain_to_pay'][
'label'] .
'">';
515 if (!empty($arrayfields[
'download_link'][
'checked'])) {
516 $html .=
'<td data-label="' . $arrayfields[
'download_link'][
'label'] .
'">';
522 if (!empty($arrayfields[
'signature_link'][
'checked'])) {
523 $html .=
'<td data-label="' . $arrayfields[
'signature_link'][
'label'] .
'">';
528 $totalarray = array();
529 $totalarray[
'nbfield'] = 0;
536 $html .=
'<th data-col="row-checkbox" ></th>';
537 $totalarray[
'nbfield']++;
539 foreach ($object->fields as $key => $val) {
540 $tableKey =
't.' . $key;
541 if (!empty($arrayfields[$tableKey][
'checked'])) {
543 if (array_key_exists($tableKey, $sortList)) {
544 $tableOrder = strtolower($sortList[$tableKey]);
546 $url_param = $url_file .
'&sortfield=' . $tableKey .
'&sortorder=' . ($tableOrder ==
'desc' ?
'asc' :
'desc') . $param;
547 $html .=
'<th data-col="'.dol_escape_htmltag($key).
'" scope="col"' . ($tableOrder !=
'' ?
' table-order="' . $tableOrder .
'"' :
'') .
'>';
548 $html .=
'<a href="' . $url_param .
'">';
549 $html .= $langs->trans($arrayfields[
't.' . $key][
'label']);
552 $totalarray[
'nbfield']++;
556 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
557 $html .=
'<th scope="col">';
558 $html .= $langs->trans($arrayfields[
'remain_to_pay'][
'label']);
560 $totalarray[
'nbfield']++;
563 if (!empty($arrayfields[
'download_link'][
'checked'])) {
564 $html .=
'<th scope="col">';
565 $html .= $langs->trans($arrayfields[
'download_link'][
'label']);
567 $totalarray[
'nbfield']++;
571 if (!empty($arrayfields[
'signature_link'][
'checked'])) {
572 $html .=
'<th scope="col">';
573 $html .= $langs->trans($arrayfields[
'signature_link'][
'label']);
575 $totalarray[
'nbfield']++;
580 $parameters = array(
'arrayfields' => $arrayfields,
'sortfield' => $sortfield,
'sortorder' => $sortorder,
'totalarray' => &$totalarray);
581 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $object, $action);
582 $html .= $hookmanager->resPrint;
590 $idCompany = (int) $socid;
591 if (!isset($this->companyStaticList[$socid])) {
592 $companyStatic =
new Societe($this->db);
593 $companyStatic->fetch($idCompany);
594 $this->companyStaticList[$idCompany] = $companyStatic;
596 $companyStatic = $this->companyStaticList[$socid];
605 $imaxinloop = ($limit ? min($num, $limit) : $num);
606 while ($i < $imaxinloop) {
607 $obj = $this->db->fetch_object($resql);
613 $object->setVarsFromFetchObj($obj);
617 if ($elementEn ==
'invoice') {
619 $payment = $object->getSommePaiement();
620 $totalcreditnotes = $object->getSumCreditNotesUsed();
621 $totaldeposits = $object->getSumDepositsUsed();
624 $totalpay = $payment + $totalcreditnotes + $totaldeposits;
625 $remaintopay =
price2num($object->total_ttc - $totalpay);
630 $remaincreditnote = $discount->getAvailableDiscounts($companyStatic,
'',
'rc.fk_facture_source=' . $object->id);
631 $remaintopay = -$remaincreditnote;
636 $html .=
'<tr data-rowid="' . $object->id .
'">';
638 $html .=
'<td class="nowraponall">';
641 $totalarray[
'nbfield']++;
644 foreach ($object->fields as $key => $val) {
645 if (!empty($arrayfields[
't.' . $key][
'checked'])) {
646 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
't.' . $key][
'label'] .
'">';
647 if ($key ==
'status' || $key ==
'fk_statut') {
648 if ($elementEn ==
'invoice') {
650 $html .= $object->getLibStatut(5, $payment);
652 $html .= $object->getLibStatut(5);
654 } elseif ($key ==
'rowid') {
655 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $object->id,
'');
657 $html .= $this->form->showOutputFieldForObject($object, $val, $key, $object->$key,
'');
663 $totalarray[
'nbfield']++;
665 if (!empty($val[
'isameasure']) && $val[
'isameasure'] == 1) {
667 $totalarray[
'pos'][$totalarray[
'nbfield']] =
't.' . $key;
669 if (!isset($totalarray[
'val'])) {
670 $totalarray[
'val'] = array();
672 if (!isset($totalarray[
'val'][
't.' . $key])) {
673 $totalarray[
'val'][
't.' . $key] = 0;
675 $totalarray[
'val'][
't.' . $key] += $object->$key;
680 if (!empty($arrayfields[
'remain_to_pay'][
'checked'])) {
681 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
'remain_to_pay'][
'label'] .
'">';
682 $html .= $this->form->showOutputFieldForObject($object, $arrayfields[
'remain_to_pay'],
'remain_to_pay', $remaintopay,
'');
686 $totalarray[
'nbfield']++;
690 if (!empty($arrayfields[
'download_link'][
'checked'])) {
691 $element = $object->element;
692 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
'download_link'][
'label'] .
'">';
694 $filedir = $conf->{$element}->multidir_output[$obj->element_entity] .
'/' .
dol_sanitizeFileName($obj->ref);
695 $html .= $this->form->getDocumentsLink($element, $filename, $filedir);
698 $totalarray[
'nbfield']++;
703 if (!empty($arrayfields[
'signature_link'][
'checked'])) {
704 $html .=
'<td class="nowraponall" data-label="' . $arrayfields[
'signature_link'][
'label'] .
'">';
706 $html .= $this->form->getSignatureLink(
'proposal', $object);
710 $totalarray[
'nbfield']++;
715 $parameters = array(
'arrayfields' => $arrayfields,
'object' => $object,
'obj' => $obj,
'i' => $i,
'totalarray' => &$totalarray);
716 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $object, $action);
717 $html .= $hookmanager->resPrint;
725 if (!empty($totalarray[
'totalizable']) && is_array($totalarray[
'totalizable'])) {
726 foreach ($totalarray[
'totalizable'] as $keytotalizable => $valtotalizable) {
727 $totalarray[
'pos'][$valtotalizable[
'pos']] = $keytotalizable;
728 $totalarray[
'val'][$keytotalizable] = isset($valtotalizable[
'total']) ? $valtotalizable[
'total'] : 0;
732 if (isset($totalarray[
'pos'])) {
735 while ($i < $totalarray[
'nbfield']) {
737 if (!empty($totalarray[
'pos'][$i])) {
738 $html .=
'<td class="nowraponall essai">';
739 $html .=
price(!empty($totalarray[
'val'][$totalarray[
'pos'][$i]]) ? $totalarray[
'val'][$totalarray[
'pos'][$i]] : 0);
743 $html .=
'<td>' . $langs->trans(
"Total") .
'</td>';
745 $html .=
'<td></td>';
755 foreach ($arrayfields as $key => $val) {
756 if (!empty($val[
'checked'])) {
760 $html .=
'<tr><td colspan="' . $colspan .
'"><span class="opacitymedium">' . $langs->trans(
"NoRecordFound") .
'</span></td></tr>';
765 $this->db->free($resql);
767 $parameters = array(
'arrayfields' => $arrayfields,
'sql' => $sql);
768 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters, $object, $action);
769 $html .= $hookmanager->resPrint;