html.formexpensereport.class.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /* Copyright (C) 2012-2013 Charles-Fr BENKE <charles.fr@benke.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. * or see https://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/class/html.formexpensereport.class.php
  20. * \ingroup core
  21. * \brief File of class with all html predefined components
  22. */
  23. /**
  24. * Class to manage generation of HTML components for contract module
  25. */
  26. class FormExpenseReport
  27. {
  28. /**
  29. * @var DoliDB Database handler.
  30. */
  31. public $db;
  32. /**
  33. * @var string Error code (or message)
  34. */
  35. public $error = '';
  36. /**
  37. * Constructor
  38. *
  39. * @param DoliDB $db Database handler
  40. */
  41. public function __construct($db)
  42. {
  43. $this->db = $db;
  44. }
  45. /**
  46. * Retourne la liste deroulante des differents etats d'une note de frais.
  47. * Les valeurs de la liste sont les id de la table c_expensereport_statuts
  48. *
  49. * @param int $selected preselect status
  50. * @param string $htmlname Name of HTML select
  51. * @param int $useempty 1=Add empty line
  52. * @param int $useshortlabel Use short labels
  53. * @return string HTML select with status
  54. */
  55. public function selectExpensereportStatus($selected = '', $htmlname = 'fk_statut', $useempty = 1, $useshortlabel = 0)
  56. {
  57. global $langs;
  58. $tmpep = new ExpenseReport($this->db);
  59. print '<select class="flat" name="'.$htmlname.'">';
  60. if ($useempty) print '<option value="-1">&nbsp;</option>';
  61. $arrayoflabels = $tmpep->statuts;
  62. if ($useshortlabel) $arrayoflabels = $tmpep->statuts_short;
  63. foreach ($arrayoflabels as $key => $val)
  64. {
  65. if ($selected != '' && $selected == $key)
  66. {
  67. print '<option value="'.$key.'" selected>';
  68. } else {
  69. print '<option value="'.$key.'">';
  70. }
  71. print $langs->trans($val);
  72. print '</option>';
  73. }
  74. print '</select>';
  75. }
  76. /**
  77. * Return list of types of notes with select value = id
  78. *
  79. * @param int $selected Preselected type
  80. * @param string $htmlname Name of field in form
  81. * @param int $showempty Add an empty field
  82. * @param int $active 1=Active only, 0=Unactive only, -1=All
  83. * @return string Select html
  84. */
  85. public function selectTypeExpenseReport($selected = '', $htmlname = 'type', $showempty = 0, $active = 1)
  86. {
  87. // phpcs:enable
  88. global $langs, $user;
  89. $langs->load("trips");
  90. $out = '';
  91. $out .= '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
  92. if ($showempty)
  93. {
  94. $out .= '<option value="-1"';
  95. if ($selected == -1) $out .= ' selected';
  96. $out .= '>&nbsp;</option>';
  97. }
  98. $sql = "SELECT c.id, c.code, c.label as type FROM ".MAIN_DB_PREFIX."c_type_fees as c";
  99. if ($active >= 0) $sql .= " WHERE c.active = ".$active;
  100. $sql .= " ORDER BY c.label ASC";
  101. $resql = $this->db->query($sql);
  102. if ($resql)
  103. {
  104. $num = $this->db->num_rows($resql);
  105. $i = 0;
  106. while ($i < $num)
  107. {
  108. $obj = $this->db->fetch_object($resql);
  109. $out .= '<option value="'.$obj->id.'"';
  110. if ($obj->code == $selected || $obj->id == $selected) $out .= ' selected';
  111. $out .= '>';
  112. if ($obj->code != $langs->trans($obj->code)) $out .= $langs->trans($obj->code);
  113. else $out .= $langs->trans($obj->type);
  114. $i++;
  115. }
  116. }
  117. $out .= '</select>';
  118. $out .= ajax_combobox($htmlname);
  119. return $out;
  120. }
  121. }