dolibarr 21.0.0-alpha
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
63 public function selectExpensereportStatus($selected = 0, $htmlname = 'fk_statut', $useempty = 1, $useshortlabel = 0, $morecss = '')
64 {
65 global $langs;
66
67 $tmpep = new ExpenseReport($this->db);
68
69 $html = '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
70 if ($useempty) {
71 $html.='<option value="-1">&nbsp;</option>';
72 }
73 $arrayoflabels = $tmpep->labelStatus;
74 if ($useshortlabel) {
75 $arrayoflabels = $tmpep->labelStatusShort;
76 }
77 foreach ($arrayoflabels as $key => $val) {
78 if (!empty($selected) && $selected == $key) {
79 $html .= '<option value="'.$key.'" selected>';
80 } else {
81 $html .= '<option value="'.$key.'">';
82 }
83 $html .= $langs->trans($val);
84 $html .= '</option>';
85 }
86 $html .= '</select>'."\n";
87
88 $html .= ajax_combobox($htmlname, array(), 0, 0, 'resolve', ($useempty < 0 ? (string) $useempty : '-1'), $morecss);
89
90 return $html;
91 }
92
102 public function selectTypeExpenseReport($selected = 0, $htmlname = 'type', $showempty = 0, $active = 1)
103 {
104 // phpcs:enable
105 global $langs, $user;
106 $langs->load("trips");
107
108 $out = '';
109
110 $out .= '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
111 if ($showempty) {
112 $out .= '<option value="-1"';
113 if ($selected == -1) {
114 $out .= ' selected';
115 }
116 $out .= '>&nbsp;</option>';
117 }
118
119 $sql = "SELECT c.id, c.code, c.label as type FROM ".$this->db->prefix()."c_type_fees as c";
120 if ($active >= 0) {
121 $sql .= " WHERE c.active = ".((int) $active);
122 }
123 $sql .= " ORDER BY c.label ASC";
124 $resql = $this->db->query($sql);
125 if ($resql) {
126 $num = $this->db->num_rows($resql);
127 $i = 0;
128
129 while ($i < $num) {
130 $obj = $this->db->fetch_object($resql);
131 $out .= '<option value="'.$obj->id.'"';
132 if ($obj->code == $selected || $obj->id == $selected) {
133 $out .= ' selected';
134 }
135 $out .= '>';
136 if ($obj->code != $langs->trans($obj->code)) {
137 $out .= $langs->trans($obj->code);
138 } else {
139 $out .= $langs->trans($obj->type);
140 }
141 $i++;
142 }
143 }
144 $out .= '</select>';
145 $out .= ajax_combobox($htmlname);
146
147 return $out;
148 }
149}
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:456
Class to manage Trips and Expenses.
Class to manage generation of HTML components for contract module.
selectExpensereportStatus($selected=0, $htmlname='fk_statut', $useempty=1, $useshortlabel=0, $morecss='')
Return the combobox for the different statuses of an expense report The list values are the ids from ...
selectTypeExpenseReport($selected=0, $htmlname='type', $showempty=0, $active=1)
Return list of types of notes with select value = id.