dolibarr 19.0.3
html.formexpensereport.class.php
Go to the documentation of this file.
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
29{
33 public $db;
34
38 public $error = '';
39
40
46 public function __construct($db)
47 {
48 $this->db = $db;
49 }
50
51
62 public function selectExpensereportStatus($selected = '', $htmlname = 'fk_statut', $useempty = 1, $useshortlabel = 0)
63 {
64 global $langs;
65
66 $tmpep = new ExpenseReport($this->db);
67
68 $html = '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
69 if ($useempty) {
70 $html.='<option value="-1">&nbsp;</option>';
71 }
72 $arrayoflabels = $tmpep->labelStatus;
73 if ($useshortlabel) {
74 $arrayoflabels = $tmpep->labelStatusShort;
75 }
76 foreach ($arrayoflabels as $key => $val) {
77 if ($selected != '' && $selected == $key) {
78 $html .= '<option value="'.$key.'" selected>';
79 } else {
80 $html .= '<option value="'.$key.'">';
81 }
82 $html .= $langs->trans($val);
83 $html .= '</option>';
84 }
85 $html .= '</select>';
86 $html .= ajax_combobox($htmlname);
87 print $html;
88 return $html;
89 }
90
100 public function selectTypeExpenseReport($selected = '', $htmlname = 'type', $showempty = 0, $active = 1)
101 {
102 // phpcs:enable
103 global $langs, $user;
104 $langs->load("trips");
105
106 $out = '';
107
108 $out .= '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
109 if ($showempty) {
110 $out .= '<option value="-1"';
111 if ($selected == -1) {
112 $out .= ' selected';
113 }
114 $out .= '>&nbsp;</option>';
115 }
116
117 $sql = "SELECT c.id, c.code, c.label as type FROM ".$this->db->prefix()."c_type_fees as c";
118 if ($active >= 0) {
119 $sql .= " WHERE c.active = ".((int) $active);
120 }
121 $sql .= " ORDER BY c.label ASC";
122 $resql = $this->db->query($sql);
123 if ($resql) {
124 $num = $this->db->num_rows($resql);
125 $i = 0;
126
127 while ($i < $num) {
128 $obj = $this->db->fetch_object($resql);
129 $out .= '<option value="'.$obj->id.'"';
130 if ($obj->code == $selected || $obj->id == $selected) {
131 $out .= ' selected';
132 }
133 $out .= '>';
134 if ($obj->code != $langs->trans($obj->code)) {
135 $out .= $langs->trans($obj->code);
136 } else {
137 $out .= $langs->trans($obj->type);
138 }
139 $i++;
140 }
141 }
142 $out .= '</select>';
143 $out .= ajax_combobox($htmlname);
144
145 return $out;
146 }
147}
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:455
Class to manage Trips and Expenses.
Class to manage generation of HTML components for contract module.
selectExpensereportStatus($selected='', $htmlname='fk_statut', $useempty=1, $useshortlabel=0)
Retourne la liste deroulante des differents etats d'une note de frais.
selectTypeExpenseReport($selected='', $htmlname='type', $showempty=0, $active=1)
Return list of types of notes with select value = id.