dolibarr  19.0.0-dev
html.formprojet.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2013 Florian Henry <florian.henry@open-concept.pro>
3  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
4  * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
31 {
35  public $db;
36 
40  public $error = '';
41 
42  public $errors = array();
43 
44 
45  public $nboftasks;
46 
47 
53  public function __construct($db)
54  {
55  $this->db = $db;
56  }
57 
58  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
59 
81  public function select_projects($socid = -1, $selected = '', $htmlname = 'projectid', $maxlength = 16, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $morecss = '', $htmlid = '', $morefilter = '')
82  {
83  // phpcs:enable
84  global $langs, $conf, $form;
85 
86  $selected_input_value = '';
87  if (is_object($selected)) {
88  $selected_input_value = $selected->ref;
89  $selected = $selected->id;
90  }
91 
92  $out = '';
93 
94  if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT)) {
95  $placeholder = '';
96 
97  if ($selected && empty($selected_input_value)) {
98  require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
99  $project = new Project($this->db);
100  $project->fetch($selected);
101  $selected_input_value = $project->ref;
102  }
103  $urloption = 'socid=' . ((int) $socid) . '&htmlname=' . urlencode($htmlname) . '&discardclosed=' . ((int) $discard_closed);
104  if ($morefilter == 'usage_organize_event=1') {
105  $urloption .= '&usage_organize_event=1';
106  }
107  $out .= '<input type="text" class="minwidth200' . ($morecss ? ' ' . $morecss : '') . '" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' />';
108 
109  $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array());
110  } else {
111  $out .= $this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, abs($discard_closed), $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid, $morecss, $morefilter);
112  }
113  if ($discard_closed > 0) {
114  if (!empty($form)) {
115  $out .= $form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
116  }
117  }
118 
119  if (empty($nooutput)) {
120  print $out;
121  return '';
122  } else {
123  return $out;
124  }
125  }
126 
127  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
128 
150  public function select_projects_list($socid = -1, $selected = '', $htmlname = 'projectid', $maxlength = 24, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $htmlid = '', $morecss = 'maxwidth500', $morefilter = '')
151  {
152  // phpcs:enable
153  global $user, $conf, $langs;
154 
155  require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
156 
157  if (empty($htmlid)) {
158  $htmlid = $htmlname;
159  }
160 
161  $out = '';
162  $outarray = array();
163 
164  $hideunselectables = false;
165  if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
166  $hideunselectables = true;
167  }
168 
169  $projectsListId = false;
170  if (empty($user->rights->projet->all->lire)) {
171  $projectstatic = new Project($this->db);
172  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
173  }
174 
175  // Search all projects
176  $sql = "SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias";
177  $sql .= " FROM " . $this->db->prefix() . "projet as p LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc";
178  $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
179  if ($projectsListId !== false) {
180  $sql .= " AND p.rowid IN (" . $this->db->sanitize($projectsListId) . ")";
181  }
182  if ($socid == 0) {
183  $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
184  }
185  if ($socid > 0) {
186  if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)) {
187  $sql .= " AND (p.fk_soc=" . ((int) $socid) . " OR p.fk_soc IS NULL)";
188  } elseif ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all') { // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
189  $sql .= " AND (p.fk_soc IN (" . $this->db->sanitize(((int) $socid) . ", " . $conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) . ") OR p.fk_soc IS NULL)";
190  }
191  }
192  if (!empty($filterkey)) {
193  $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
194  }
195  if ($morefilter) {
196  $sql .= ' AND (' . $this->db->sanitize($morefilter, 0, 1) . ')';
197  }
198  $sql .= " ORDER BY p.ref ASC";
199 
200  $resql = $this->db->query($sql);
201  if ($resql) {
202  if (!empty($conf->use_javascript_ajax)) {
203  $morecss .= ' minwidth100';
204  }
205  if (empty($option_only)) {
206  $out .= '<select class="flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlid . '" name="' . $htmlname . '">';
207  }
208  if (!empty($show_empty)) {
209  if (is_numeric($show_empty)) {
210  $out .= '<option value="0">&nbsp;</option>';
211  } else {
212  $out .= '<option value="-1">'.$show_empty.'</option>';
213  }
214  }
215  $num = $this->db->num_rows($resql);
216  $i = 0;
217  if ($num) {
218  while ($i < $num) {
219  $obj = $this->db->fetch_object($resql);
220  // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
221  if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
222  // Do nothing
223  } else {
224  if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) { // We discard closed except if selected
225  $i++;
226  continue;
227  }
228 
229  $labeltoshow = dol_trunc($obj->ref, 18);
230  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
231  //else $labeltoshow.=' ('.$langs->trans("Private").')';
232  $labeltoshow .= ', ' . dol_trunc($obj->title, $maxlength);
233  if ($obj->name) {
234  $labeltoshow .= ' - ' . $obj->name;
235  if ($obj->name_alias) {
236  $labeltoshow .= ' (' . $obj->name_alias . ')';
237  }
238  }
239 
240  $disabled = 0;
241  if ($obj->fk_statut == 0) {
242  $disabled = 1;
243  $labeltoshow .= ' - ' . $langs->trans("Draft");
244  } elseif ($obj->fk_statut == 2) {
245  if ($discard_closed == 2) {
246  $disabled = 1;
247  }
248  $labeltoshow .= ' - ' . $langs->trans("Closed");
249  } elseif (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
250  $disabled = 1;
251  $labeltoshow .= ' - ' . $langs->trans("LinkedToAnotherCompany");
252  }
253 
254  if (!empty($selected) && $selected == $obj->rowid) {
255  $out .= '<option value="' . $obj->rowid . '" selected';
256  //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
257  $out .= '>' . $labeltoshow . '</option>';
258  } else {
259  if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
260  $resultat = '';
261  } else {
262  $resultat = '<option value="' . $obj->rowid . '"';
263  if ($disabled) {
264  $resultat .= ' disabled';
265  }
266  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
267  //else $labeltoshow.=' ('.$langs->trans("Private").')';
268  $resultat .= '>';
269  $resultat .= $labeltoshow;
270  $resultat .= '</option>';
271  }
272  $out .= $resultat;
273 
274  $outarray[] = array(
275  'key' => (int) $obj->rowid,
276  'value' => $obj->ref,
277  'ref' => $obj->ref,
278  'labelx' => $labeltoshow,
279  'label' => ($disabled ? '<span class="opacitymedium">' . $labeltoshow . '</span>' : $labeltoshow),
280  'disabled' => (bool) $disabled
281  );
282  }
283  }
284  $i++;
285  }
286  }
287 
288  $this->db->free($resql);
289 
290  if (!$mode) {
291  if (empty($option_only)) {
292  $out .= '</select>';
293  }
294 
295  // Use select2 selector
296  if (!empty($conf->use_javascript_ajax)) {
297  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
298  $comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
299  $out .= $comboenhancement;
300  $morecss .= ' minwidth100';
301  }
302 
303  if (empty($nooutput)) {
304  print $out;
305  return '';
306  } else {
307  return $out;
308  }
309  } else {
310  return $outarray;
311  }
312  } else {
313  dol_print_error($this->db);
314  return -1;
315  }
316  }
317 
336  public function selectTasks($socid = -1, $selected = '', $htmlname = 'taskid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showmore = 'all', $usertofilter = null)
337  {
338  global $user, $conf, $langs;
339 
340  require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
341 
342  if (is_null($usertofilter)) {
343  $usertofilter = $user;
344  }
345 
346  $out = '';
347 
348  $hideunselectables = false;
349  if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
350  $hideunselectables = true;
351  }
352 
353  if (empty($projectsListId)) {
354  if (empty($usertofilter->rights->projet->all->lire)) {
355  $projectstatic = new Project($this->db);
356  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
357  }
358  }
359 
360  // Search all projects
361  $sql = "SELECT t.rowid, t.ref as tref, t.label as tlabel, t.progress,";
362  $sql .= " p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, p.usage_task,";
363  $sql .= " s.nom as name";
364  $sql .= " FROM " . $this->db->prefix() . "projet as p";
365  $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc,";
366  $sql .= " " . $this->db->prefix() . "projet_task as t";
367  $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
368  $sql .= " AND t.fk_projet = p.rowid";
369  if ($projectsListId) {
370  $sql .= " AND p.rowid IN (" . $this->db->sanitize($projectsListId) . ")";
371  }
372  if ($socid == 0) {
373  $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
374  }
375  if ($socid > 0) {
376  $sql .= " AND (p.fk_soc=" . ((int) $socid) . " OR p.fk_soc IS NULL)";
377  }
378  $sql .= " ORDER BY p.ref, t.ref ASC";
379 
380  $resql = $this->db->query($sql);
381  if ($resql) {
382  // Use select2 selector
383  if (empty($option_only) && !empty($conf->use_javascript_ajax)) {
384  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
385  $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
386  $out .= $comboenhancement;
387  $morecss .= ' minwidth150';
388  }
389 
390  if (empty($option_only)) {
391  $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlname . '" name="' . $htmlname . '">';
392  }
393  if (!empty($show_empty)) {
394  $out .= '<option value="0" class="optiongrey">';
395  if (!is_numeric($show_empty)) {
396  //if (!empty($conf->use_javascript_ajax)) $out .= '<span class="opacitymedium">aaa';
397  $out .= $show_empty;
398  //if (!empty($conf->use_javascript_ajax)) $out .= '</span>';
399  } else {
400  $out .= '&nbsp;';
401  }
402  $out .= '</option>';
403  }
404 
405  $num = $this->db->num_rows($resql);
406  $i = 0;
407  if ($num) {
408  while ($i < $num) {
409  $obj = $this->db->fetch_object($resql);
410  // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
411  if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire)) {
412  // Do nothing
413  } else {
414  if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
415  $i++;
416  continue;
417  }
418 
419  $labeltoshow = '';
420  $titletoshow = '';
421 
422  $disabled = 0;
423  if ($obj->fk_statut == Project::STATUS_DRAFT) {
424  $disabled = 1;
425  } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
426  if ($discard_closed == 2) {
427  $disabled = 1;
428  }
429  } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
430  $disabled = 1;
431  }
432 
433  if (preg_match('/all/', $showmore)) {
434  $labeltoshow .= dol_trunc($obj->ref, 18); // Project ref
435  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
436  //else $labeltoshow.=' ('.$langs->trans("Private").')';
437  $labeltoshow .= ' ' . dol_trunc($obj->title, $maxlength);
438  $titletoshow = $labeltoshow;
439 
440  if ($obj->name) {
441  $labeltoshow .= ' (' . $obj->name . ')';
442  $titletoshow .= ' <span class="opacitymedium">(' . $obj->name . ')</span>';
443  }
444 
445  $disabled = 0;
446  if ($obj->fk_statut == Project::STATUS_DRAFT) {
447  $disabled = 1;
448  $labeltoshow .= ' - ' . $langs->trans("Draft");
449  $titletoshow .= ' - <span class="opacitymedium">' . $langs->trans("Draft") . '</span>';
450  } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
451  if ($discard_closed == 2) {
452  $disabled = 1;
453  }
454  $labeltoshow .= ' - ' . $langs->trans("Closed");
455  $titletoshow .= ' - <span class="opacitymedium">' . $langs->trans("Closed") . '</span>';
456  } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
457  $disabled = 1;
458  $labeltoshow .= ' - ' . $langs->trans("LinkedToAnotherCompany");
459  $titletoshow .= ' - <span class="opacitymedium">' . $langs->trans("LinkedToAnotherCompany") . '</span>';
460  }
461  $labeltoshow .= ' - ';
462  $titletoshow .= ' - ';
463  }
464 
465  // Label for task
466  $labeltoshow .= $obj->tref . ' ' . dol_trunc($obj->tlabel, $maxlength);
467  $titletoshow .= $obj->tref . ' ' . dol_trunc($obj->tlabel, $maxlength);
468  if ($obj->usage_task && preg_match('/progress/', $showmore)) {
469  $labeltoshow .= ' <span class="opacitymedium">(' . $obj->progress . '%)</span>';
470  $titletoshow .= ' <span class="opacitymedium">(' . $obj->progress . '%)</span>';
471  }
472 
473  if (!empty($selected) && $selected == $obj->rowid) {
474  $out .= '<option value="' . $obj->rowid . '" selected';
475  $out .= ' data-html="' . dol_escape_htmltag($titletoshow) . '"';
476  //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
477  $out .= '>' . $labeltoshow . '</option>';
478  } else {
479  if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
480  $resultat = '';
481  } else {
482  $resultat = '<option value="' . $obj->rowid . '"';
483  if ($disabled) {
484  $resultat .= ' disabled';
485  }
486  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
487  //else $labeltoshow.=' ('.$langs->trans("Private").')';
488  $resultat .= ' data-html="' . dol_escape_htmltag($titletoshow) . '"';
489  $resultat .= '>';
490  $resultat .= $labeltoshow;
491  $resultat .= '</option>';
492  }
493  $out .= $resultat;
494  }
495  }
496  $i++;
497  }
498  }
499  if (empty($option_only)) {
500  $out .= '</select>';
501  }
502 
503  $this->nboftasks = $num;
504 
505  print $out;
506 
507  $this->db->free($resql);
508  return $num;
509  } else {
510  dol_print_error($this->db);
511  return -1;
512  }
513  }
514 
515 
516  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
517 
529  public function select_element($table_element, $socid = 0, $morecss = '', $limitonstatus = -2, $projectkey = "fk_projet", $placeholder = '')
530  {
531  // phpcs:enable
532  global $conf, $langs;
533 
534  if ($table_element == 'projet_task') {
535  return ''; // Special cas of element we never link to a project (already always done)
536  }
537 
538  $linkedtothirdparty = false;
539  if (!in_array($table_element, array(
540  'don',
541  'expensereport_det',
542  'expensereport', 'loan',
543  'stock_mouvement',
544  'payment_salary',
545  'payment_various',
546  'salary',
547  'chargesociales',
548  'entrepot')
549  )) {
550  $linkedtothirdparty = true;
551  }
552 
553  $sqlfilter = '';
554 
555  //print $table_element;
556  switch ($table_element) {
557  case "loan":
558  $sql = "SELECT t.rowid, t.label as ref";
559  break;
560  case "facture":
561  $sql = "SELECT t.rowid, t.ref as ref";
562  break;
563  case "facture_fourn":
564  $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
565  break;
566  case "commande_fourn":
567  case "commande_fournisseur":
568  $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
569  break;
570  case "facture_rec":
571  $sql = "SELECT t.rowid, t.titre as ref";
572  break;
573  case "actioncomm":
574  $sql = "SELECT t.id as rowid, t.label as ref";
575  $projectkey = "fk_project";
576  break;
577  case "expensereport":
578  return '';
579  case "expensereport_det":
580  /*$sql = "SELECT rowid, '' as ref"; // table is llx_expensereport_det
581  $projectkey="fk_projet";
582  break;*/
583  return '';
584  case "commande":
585  case "contrat":
586  case "fichinter":
587  $sql = "SELECT t.rowid, t.ref";
588  break;
589  case 'stock_mouvement':
590  $sql = "SELECT t.rowid, t.label as ref";
591  $projectkey = 'fk_origin';
592  break;
593  case "payment_salary":
594  $sql = "SELECT t.rowid, t.num_payment as ref"; // TODO In a future fill and use real ref field
595  break;
596  case "payment_various":
597  $sql = "SELECT t.rowid, t.num_payment as ref";
598  break;
599  case "chargesociales":
600  default:
601  $sql = "SELECT t.rowid, t.ref";
602  break;
603  }
604  if ($linkedtothirdparty) {
605  $sql .= ", s.nom as name";
606  }
607  $sql .= " FROM " . $this->db->prefix() . $table_element . " as t";
608  if ($linkedtothirdparty) {
609  $sql .= ", " . $this->db->prefix() . "societe as s";
610  }
611  $sql .= " WHERE " . $projectkey . " is null";
612  if (!empty($socid) && $linkedtothirdparty) {
613  if (is_numeric($socid)) {
614  $sql .= " AND t.fk_soc = " . ((int) $socid);
615  } else {
616  $sql .= " AND t.fk_soc IN (" . $this->db->sanitize($socid) . ")";
617  }
618  }
619  if (!in_array($table_element, array('expensereport_det', 'stock_mouvement'))) {
620  $sql .= ' AND t.entity IN (' . getEntity('project') . ')';
621  }
622  if ($linkedtothirdparty) {
623  $sql .= " AND s.rowid = t.fk_soc";
624  }
625  if ($sqlfilter) {
626  $sql .= " AND " . $sqlfilter;
627  }
628  $sql .= " ORDER BY ref DESC";
629 
630  dol_syslog(get_class($this) . '::select_element', LOG_DEBUG);
631  $resql = $this->db->query($sql);
632  if ($resql) {
633  $num = $this->db->num_rows($resql);
634  $i = 0;
635  $sellist = '';
636 
637  if ($num > 0) {
638  $sellist = '<select class="flat elementselect css' . $table_element . ($morecss ? ' ' . $morecss : '') . '" name="elementselect">';
639  $sellist .= '<option value="-1"' . ($placeholder ? ' class="optiongrey"' : '') . '>' . $placeholder . '</option>';
640  while ($i < $num) {
641  $obj = $this->db->fetch_object($resql);
642  $ref = $obj->ref ? $obj->ref : $obj->rowid;
643  if (!empty($obj->ref_supplier)) {
644  $ref .= ' (' . $obj->ref_supplier . ')';
645  }
646  if (!empty($obj->name)) {
647  $ref .= ' - ' . $obj->name;
648  }
649  $sellist .= '<option value="' . $obj->rowid . '">' . $ref . '</option>';
650  $i++;
651  }
652  $sellist .= '</select>';
653  }
654  /*else
655  {
656  $sellist = '<select class="flat" name="elementselect">';
657  $sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
658  $sellist.= '</select>';
659  }*/
660  $this->db->free($resql);
661 
662  return $sellist;
663  } else {
664  dol_print_error($this->db);
665  $this->error = $this->db->lasterror();
666  $this->errors[] = $this->db->lasterror();
667  dol_syslog(get_class($this) . "::select_element " . $this->error, LOG_ERR);
668  return -1;
669  }
670  }
671 
672 
687  public function selectOpportunityStatus($htmlname, $preselected = '-1', $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss = '', $noadmininfo = 0, $addcombojs = 0)
688  {
689  global $conf, $langs, $user;
690 
691  $sql = "SELECT rowid, code, label, percent";
692  $sql .= " FROM " . $this->db->prefix() . 'c_lead_status';
693  $sql .= " WHERE active = 1";
694  $sql .= " ORDER BY position";
695 
696  $resql = $this->db->query($sql);
697  if ($resql) {
698  $num = $this->db->num_rows($resql);
699  $i = 0;
700  if ($num > 0) {
701  $sellist = '<select class="flat oppstatus' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlname . '" name="' . $htmlname . '">';
702  if ($showempty) {
703  // Without &nbsp, strange move of screen when switching value
704  $sellist .= '<option value="-1">&nbsp;</option>';
705  }
706  if ($showallnone) {
707  $sellist .= '<option value="all"' . ($preselected == 'all' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("OnlyOpportunitiesShort") . '</option>';
708  $sellist .= '<option value="openedopp"' . ($preselected == 'openedopp' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("OpenedOpportunitiesShort") . '</option>';
709  $sellist .= '<option value="notopenedopp"' . ($preselected == 'notopenedopp' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("NotOpenedOpportunitiesShort") . '</option>';
710  $sellist .= '<option value="none"' . ($preselected == 'none' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("NotAnOpportunityShort") . '</option>';
711  }
712  while ($i < $num) {
713  $obj = $this->db->fetch_object($resql);
714 
715  $sellist .= '<option value="' . $obj->rowid . '" defaultpercent="' . $obj->percent . '" elemcode="' . $obj->code . '"';
716  if ($obj->rowid == $preselected) {
717  $sellist .= ' selected="selected"';
718  }
719  $sellist .= '>';
720  if ($useshortlabel) {
721  $finallabel = ($langs->transnoentitiesnoconv("OppStatus" . $obj->code) != "OppStatus" . $obj->code ? $langs->transnoentitiesnoconv("OppStatus" . $obj->code) : $obj->label);
722  } else {
723  $finallabel = ($langs->transnoentitiesnoconv("OppStatus" . $obj->code) != "OppStatus" . $obj->code ? $langs->transnoentitiesnoconv("OppStatus" . $obj->code) : $obj->label);
724  if ($showpercent) {
725  $finallabel .= ' (' . $obj->percent . '%)';
726  }
727  }
728  $sellist .= $finallabel;
729  $sellist .= '</option>';
730  $i++;
731  }
732  $sellist .= '</select>';
733 
734  if ($user->admin && !$noadmininfo) {
735  $sellist .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
736  }
737 
738  if ($addcombojs) {
739  $sellist .= ajax_combobox($htmlname);
740  }
741  }
742  /*else
743  {
744  $sellist = '<select class="flat" name="elementselect">';
745  $sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
746  $sellist.= '</select>';
747  }*/
748  $this->db->free($resql);
749 
750  return $sellist;
751  } else {
752  $this->error = $this->db->lasterror();
753  $this->errors[] = $this->db->lasterror();
754  dol_syslog(get_class($this) . "::selectOpportunityStatus " . $this->error, LOG_ERR);
755  return -1;
756  }
757  }
758 
771  public function selectInvoiceAndLine($selectedInvoiceId = 0, $selectedLineId = 0, $htmlNameInvoice = 'invoiceid', $htmlNameInvoiceLine = 'invoicelineid', $morecss = 'maxwidth500', $filters = array(), $lineOnly = 0)
772  {
773  global $user, $conf, $langs;
774 
775  require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
776 
777  $out = '';
778  if (empty($lineOnly)) {
779  // Search Invoice
780  $sql = "SELECT f.rowid, f.ref as fref,";
781  $sql .= ' s.nom as name';
782  $sql .= ' FROM ' . $this->db->prefix() . 'projet as p';
783  $sql .= ' INNER JOIN ' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc';
784  $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facture as f ON f.fk_projet = p.rowid';
785  $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
786  if (!empty($filters)) {
787  foreach ($filters as $key => $value) {
788  if ($key == 'p.rowid') {
789  $sql .= " AND p.rowid=" . (int) $value;
790  }
791  if ($key == 'f.rowid') {
792  $sql .= " AND f.rowid=" . (int) $value;
793  }
794  }
795  }
796  $sql .= " ORDER BY p.ref, f.ref ASC";
797 
798  $resql = $this->db->query($sql);
799  if ($resql) {
800  // Use select2 selector
801  if (!empty($conf->use_javascript_ajax)) {
802  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
803  $comboenhancement = ajax_combobox($htmlNameInvoice, array(array('method'=>'getLines', 'url'=>dol_buildpath('/core/ajax/ajaxinvoiceline.php', 1), 'htmlname'=>$htmlNameInvoiceLine)), 0, 0);
804  $out .= $comboenhancement;
805  $morecss = 'minwidth200imp maxwidth500';
806  }
807 
808  $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoice . '" name="' . $htmlNameInvoice . '">';
809  $num = $this->db->num_rows($resql);
810  if ($num) {
811  while ($obj = $this->db->fetch_object($resql)) {
812  $labeltoshow = $obj->fref; // Invoice ref
813  if ($obj->name) {
814  $labeltoshow .= ' - ' . $obj->name;
815  }
816 
817  $out .= '<option value="' . $obj->rowid . '" ';
818  if (!empty($selectedInvoiceId) && $selectedInvoiceId == $obj->rowid) {
819  $out .= ' selected ';
820  }
821  $out .= '>' . $labeltoshow . '</option>';
822  }
823  }
824  $out .= '</select>';
825  } else {
826  dol_print_error($this->db->lasterror);
827  return '';
828  }
829  }
830 
831  // Search Invoice Line
832  $sql = "SELECT fd.rowid, fd.label, fd.description";
833  $sql .= ' FROM ' . $this->db->prefix() . 'projet as p';
834  $sql .= ' INNER JOIN ' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc';
835  $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facture as f ON f.fk_projet = p.rowid';
836  $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facturedet as fd ON fd.fk_facture = f.rowid';
837  $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
838  if (!empty($filters)) {
839  foreach ($filters as $key => $value) {
840  if ($key == 'p.rowid') {
841  $sql .= " AND p.rowid=" . (int) $value;
842  }
843  }
844  }
845  if (!empty($selectedInvoiceId)) {
846  $sql .= " AND f.rowid=" . (int) $selectedInvoiceId;
847  }
848  $sql .= " ORDER BY p.ref, f.ref ASC";
849  $resql = $this->db->query($sql);
850  if ($resql) {
851  // Use select2 selector
852  if (empty($lineOnly)) {
853  if (!empty($conf->use_javascript_ajax)) {
854  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
855  $comboenhancement = ajax_combobox($htmlNameInvoiceLine, '', 0, 0);
856  $out .= $comboenhancement;
857  $morecss = 'minwidth200imp maxwidth500';
858  }
859 
860  $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoiceLine . '" name="' . $htmlNameInvoiceLine . '">';
861  }
862  $num = $this->db->num_rows($resql);
863  if ($num) {
864  while ($obj = $this->db->fetch_object($resql)) {
865  $labeltoshow .= $obj->description; // Invoice ref
866 
867  $out .= '<option value="' . $obj->rowid . '" ';
868  if (!empty($selectedLineId) && $selectedLineId == $obj->rowid) {
869  $out .= ' selected ';
870  }
871  $out .= '>' . $labeltoshow . '</option>';
872  }
873  }
874  if (empty($lineOnly)) {
875  $out .= '</select>';
876  }
877  } else {
878  dol_print_error($this->db->lasterror);
879  return '';
880  }
881 
882  return $out;
883  }
884 }
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to a page to transform a common input field into an au...
Definition: ajax.lib.php:47
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:449
Class to manage building of HTML components.
select_element($table_element, $socid=0, $morecss='', $limitonstatus=-2, $projectkey="fk_projet", $placeholder='')
Build a HTML select list of element of same thirdparty to suggest to link them to project.
select_projects_list($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey='', $nooutput=0, $forceaddid=0, $htmlid='', $morecss='maxwidth500', $morefilter='')
Returns an array with projects qualified for a third party.
select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey='', $nooutput=0, $forceaddid=0, $morecss='', $htmlid='', $morefilter='')
Output a combo list with projects qualified for a third party / user.
selectInvoiceAndLine($selectedInvoiceId=0, $selectedLineId=0, $htmlNameInvoice='invoiceid', $htmlNameInvoiceLine='invoicelineid', $morecss='maxwidth500', $filters=array(), $lineOnly=0)
Output a combo list with invoices and lines qualified for a project.
selectTasks($socid=-1, $selected='', $htmlname='taskid', $maxlength=24, $option_only=0, $show_empty='1', $discard_closed=0, $forcefocus=0, $disabled=0, $morecss='maxwidth500', $projectsListId='', $showmore='all', $usertofilter=null)
Output a combo list with tasks qualified for a third party.
selectOpportunityStatus($htmlname, $preselected='-1', $showempty=1, $useshortlabel=0, $showallnone=0, $showpercent=0, $morecss='', $noadmininfo=0, $addcombojs=0)
Build a HTML select list of element of same thirdparty to suggest to link them to project.
__construct($db)
Constructor.
Class to manage projects.
const STATUS_CLOSED
Closed status.
const STATUS_DRAFT
Draft status.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...