html.formexpensereport.class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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" id="'.$htmlname.'" name="'.$htmlname.'">';
  60. if ($useempty) {
  61. print '<option value="-1">&nbsp;</option>';
  62. }
  63. $arrayoflabels = $tmpep->statuts;
  64. if ($useshortlabel) {
  65. $arrayoflabels = $tmpep->statuts_short;
  66. }
  67. foreach ($arrayoflabels as $key => $val) {
  68. if ($selected != '' && $selected == $key) {
  69. print '<option value="'.$key.'" selected>';
  70. } else {
  71. print '<option value="'.$key.'">';
  72. }
  73. print $langs->trans($val);
  74. print '</option>';
  75. }
  76. print '</select>';
  77. print ajax_combobox($htmlname);
  78. }
  79. /**
  80. * Return list of types of notes with select value = id
  81. *
  82. * @param int $selected Preselected type
  83. * @param string $htmlname Name of field in form
  84. * @param int $showempty Add an empty field
  85. * @param int $active 1=Active only, 0=Unactive only, -1=All
  86. * @return string Select html
  87. */
  88. public function selectTypeExpenseReport($selected = '', $htmlname = 'type', $showempty = 0, $active = 1)
  89. {
  90. // phpcs:enable
  91. global $langs, $user;
  92. $langs->load("trips");
  93. $out = '';
  94. $out .= '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
  95. if ($showempty) {
  96. $out .= '<option value="-1"';
  97. if ($selected == -1) {
  98. $out .= ' selected';
  99. }
  100. $out .= '>&nbsp;</option>';
  101. }
  102. $sql = "SELECT c.id, c.code, c.label as type FROM ".MAIN_DB_PREFIX."c_type_fees as c";
  103. if ($active >= 0) {
  104. $sql .= " WHERE c.active = ".((int) $active);
  105. }
  106. $sql .= " ORDER BY c.label ASC";
  107. $resql = $this->db->query($sql);
  108. if ($resql) {
  109. $num = $this->db->num_rows($resql);
  110. $i = 0;
  111. while ($i < $num) {
  112. $obj = $this->db->fetch_object($resql);
  113. $out .= '<option value="'.$obj->id.'"';
  114. if ($obj->code == $selected || $obj->id == $selected) {
  115. $out .= ' selected';
  116. }
  117. $out .= '>';
  118. if ($obj->code != $langs->trans($obj->code)) {
  119. $out .= $langs->trans($obj->code);
  120. } else {
  121. $out .= $langs->trans($obj->type);
  122. }
  123. $i++;
  124. }
  125. }
  126. $out .= '</select>';
  127. $out .= ajax_combobox($htmlname);
  128. return $out;
  129. }
  130. }