Fixed #13021 $g_view_history_threshold ignored in print_bug_page.php
[mantis.git] / billing_inc.php
blob929cbd0ab8bca1532e4141bc58c4730514094273
1 <?php
2 # MantisBT - A PHP based bugtracking system
4 # MantisBT 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 2 of the License, or
7 # (at your option) any later version.
9 # MantisBT 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.
14 # You should have received a copy of the GNU General Public License
15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This include file prints out the bug bugnote_stats
19 * $f_bug_id must already be defined
21 * @package MantisBT
22 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
23 * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
24 * @link http://www.mantisbt.org
26 * @uses bugnote_api.php
27 * @uses collapse_api.php
28 * @uses config_api.php
29 * @uses database_api.php
30 * @uses filter_api.php
31 * @uses gpc_api.php
32 * @uses helper_api.php
33 * @uses lang_api.php
34 * @uses string_api.php
35 * @uses utility_api.php
38 if ( !defined( 'BILLING_INC_ALLOW' ) ) {
39 return;
42 require_api( 'bugnote_api.php' );
43 require_api( 'collapse_api.php' );
44 require_api( 'config_api.php' );
45 require_api( 'database_api.php' );
46 require_api( 'filter_api.php' );
47 require_api( 'gpc_api.php' );
48 require_api( 'helper_api.php' );
49 require_api( 'lang_api.php' );
50 require_api( 'string_api.php' );
51 require_api( 'utility_api.php' );
54 <a id="bugnotestats"></a><br />
55 <?php
56 collapse_open( 'bugnotestats' );
58 $t_today = date( "d:m:Y" );
59 $t_date_submitted = isset( $t_bug ) ? date( "d:m:Y", $t_bug->date_submitted ) : $t_today;
61 $t_bugnote_stats_from_def = $t_date_submitted;
62 $t_bugnote_stats_from_def_ar = explode ( ":", $t_bugnote_stats_from_def );
63 $t_bugnote_stats_from_def_d = $t_bugnote_stats_from_def_ar[0];
64 $t_bugnote_stats_from_def_m = $t_bugnote_stats_from_def_ar[1];
65 $t_bugnote_stats_from_def_y = $t_bugnote_stats_from_def_ar[2];
67 $t_bugnote_stats_from_d = gpc_get_int('start_day', $t_bugnote_stats_from_def_d);
68 $t_bugnote_stats_from_m = gpc_get_int('start_month', $t_bugnote_stats_from_def_m);
69 $t_bugnote_stats_from_y = gpc_get_int('start_year', $t_bugnote_stats_from_def_y);
71 $t_bugnote_stats_to_def = $t_today;
72 $t_bugnote_stats_to_def_ar = explode ( ":", $t_bugnote_stats_to_def );
73 $t_bugnote_stats_to_def_d = $t_bugnote_stats_to_def_ar[0];
74 $t_bugnote_stats_to_def_m = $t_bugnote_stats_to_def_ar[1];
75 $t_bugnote_stats_to_def_y = $t_bugnote_stats_to_def_ar[2];
77 $t_bugnote_stats_to_d = gpc_get_int('end_day', $t_bugnote_stats_to_def_d);
78 $t_bugnote_stats_to_m = gpc_get_int('end_month', $t_bugnote_stats_to_def_m);
79 $t_bugnote_stats_to_y = gpc_get_int('end_year', $t_bugnote_stats_to_def_y);
81 $f_get_bugnote_stats_button = gpc_get_string('get_bugnote_stats_button', '');
82 $f_bugnote_cost = gpc_get_int( 'bugnote_cost', '' );
83 $f_project_id = helper_get_current_project();
85 if ( ON == config_get( 'time_tracking_with_billing' ) ) {
86 $t_cost_col = true;
87 } else {
88 $t_cost_col = false;
92 <form method="post" action="">
93 <?php # CSRF protection not required here - form does not result in modifications ?>
94 <input type="hidden" name="id" value="<?php echo isset( $f_bug_id ) ? $f_bug_id : 0 ?>" />
95 <table class="width100" cellspacing="0">
96 <tr>
97 <td class="form-title" colspan="4">
98 <?php
99 collapse_icon( 'bugnotestats' );
101 <?php echo lang_get( 'time_tracking' ) ?>
102 </td>
103 </tr>
104 <tr class="row-2">
105 <td class="category" width="25%">
106 <?php
107 $t_filter = array();
108 $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] = 'on';
109 $t_filter[FILTER_PROPERTY_START_DAY] = $t_bugnote_stats_from_d;
110 $t_filter[FILTER_PROPERTY_START_MONTH] = $t_bugnote_stats_from_m;
111 $t_filter[FILTER_PROPERTY_START_YEAR] = $t_bugnote_stats_from_y;
112 $t_filter[FILTER_PROPERTY_END_DAY] = $t_bugnote_stats_to_d;
113 $t_filter[FILTER_PROPERTY_END_MONTH] = $t_bugnote_stats_to_m;
114 $t_filter[FILTER_PROPERTY_END_YEAR] = $t_bugnote_stats_to_y;
115 print_filter_do_filter_by_date(true);
117 </td>
118 </tr>
119 <?php if ( $t_cost_col ) { ?>
120 <tr class="row-1">
121 <td>
122 <?php echo lang_get( 'time_tracking_cost_label' ) ?>
123 <input type="text" name="bugnote_cost" value="<?php echo $f_bugnote_cost ?>" />
124 </td>
125 </tr>
126 <?php } ?>
127 <tr>
128 <td class="center" colspan="2">
129 <input type="submit" class="button" name="get_bugnote_stats_button" value="<?php echo lang_get( 'time_tracking_get_info_button' ) ?>" />
130 </td>
131 </tr>
133 </table>
134 </form>
135 <?php
136 if ( !is_blank( $f_get_bugnote_stats_button ) ) {
137 $t_from = "$t_bugnote_stats_from_y-$t_bugnote_stats_from_m-$t_bugnote_stats_from_d";
138 $t_to = "$t_bugnote_stats_to_y-$t_bugnote_stats_to_m-$t_bugnote_stats_to_d";
139 $t_bugnote_stats = bugnote_stats_get_project_array( $f_project_id, $t_from, $t_to, $f_bugnote_cost );
141 if ( is_blank( $f_bugnote_cost ) || ( (double)$f_bugnote_cost == 0 ) ) {
142 $t_cost_col = false;
145 $t_prev_id = -1;
147 <br />
148 <table class="width100" cellspacing="0">
149 <tr class="row-category-history">
150 <td class="small-caption">
151 <?php echo lang_get( 'username' ) ?>
152 </td>
153 <td class="small-caption">
154 <?php echo lang_get( 'time_tracking' ) ?>
155 </td>
156 <?php if ( $t_cost_col) { ?>
157 <td class="small-caption">
158 <?php echo lang_get( 'time_tracking_cost' ) ?>
159 </td>
160 <?php } ?>
162 </tr>
163 <?php
164 $t_sum_in_minutes = 0;
165 $t_user_summary = array();
167 foreach ( $t_bugnote_stats as $t_item ) {
168 $t_sum_in_minutes += $t_item['sum_time_tracking'];
169 $t_user_summary[$t_item['username']] += $t_item['sum_time_tracking'];
171 $t_item['sum_time_tracking'] = db_minutes_to_hhmm( $t_item['sum_time_tracking'] );
172 if ( $t_item['bug_id'] != $t_prev_id) {
173 $t_link = sprintf( lang_get( 'label' ), string_get_bug_view_link( $t_item['bug_id'] ) ) . lang_get( 'word_separator' ) . string_display( $t_item['summary'] );
174 echo '<tr class="row-category-history"><td colspan="4">' . $t_link . "</td></tr>";
175 $t_prev_id = $t_item['bug_id'];
178 <tr <?php echo helper_alternate_class() ?>>
179 <td class="small-caption">
180 <?php echo $t_item['username'] ?>
181 </td>
182 <td class="small-caption">
183 <?php echo $t_item['sum_time_tracking'] ?>
184 </td>
185 <?php if ($t_cost_col) { ?>
186 <td>
187 <?php echo string_attribute( number_format( $t_item['cost'], 2 ) ); ?>
188 </td>
189 <?php } ?>
190 </tr>
191 <?php } # end for loop
193 <tr <?php echo helper_alternate_class() ?>>
194 <td class="small-caption">
195 <?php echo lang_get( 'total_time' ); ?>
196 </td>
197 <td class="small-caption">
198 <?php echo db_minutes_to_hhmm( $t_sum_in_minutes ); ?>
199 </td>
200 <?php if ($t_cost_col) { ?>
201 <td>
202 <?php echo string_attribute( number_format( $t_sum_in_minutes * $f_bugnote_cost / 60, 2 ) ); ?>
203 </td>
204 <?php } ?>
205 </tr>
206 </table>
208 <br />
209 <br />
211 <table class="width100" cellspacing="0">
212 <tr class="row-category-history">
213 <td class="small-caption">
214 <?php echo lang_get( 'username' ) ?>
215 </td>
216 <td class="small-caption">
217 <?php echo lang_get( 'time_tracking' ) ?>
218 </td>
219 <?php if ( $t_cost_col) { ?>
220 <td class="small-caption">
221 <?php echo lang_get( 'time_tracking_cost' ) ?>
222 </td>
223 <?php } ?>
224 </tr>
225 <?php
226 foreach ( $t_user_summary as $t_username => $t_total_time ) {
228 <tr <?php echo helper_alternate_class() ?>>
229 <td class="small-caption">
230 <?php echo $t_username; ?>
231 </td>
232 <td class="small-caption">
233 <?php echo db_minutes_to_hhmm($t_total_time); ?>
234 </td>
235 <?php if ($t_cost_col) { ?>
236 <td>
237 <?php echo string_attribute( number_format( $t_total_time * $f_bugnote_cost / 60, 2 ) ); ?>
238 </td>
239 <?php } ?>
240 </tr>
241 <?php } ?>
242 <tr <?php echo helper_alternate_class() ?>>
243 <td class="small-caption">
244 <?php echo lang_get( 'total_time' ); ?>
245 </td>
246 <td class="small-caption">
247 <?php echo db_minutes_to_hhmm( $t_sum_in_minutes ); ?>
248 </td>
249 <?php if ($t_cost_col) { ?>
250 <td>
251 <?php echo string_attribute( number_format( $t_sum_in_minutes * $f_bugnote_cost / 60, 2 ) ); ?>
252 </td>
253 <?php } ?>
254 </tr>
255 </table>
256 <?php } # end if
257 collapse_closed( 'bugnotestats' );
259 <table class="width100" cellspacing="0">
260 <tr>
261 <td class="form-title" colspan="4">
262 <?php collapse_icon( 'bugnotestats' );
263 echo lang_get( 'time_tracking' ) ?>
264 </td>
265 </tr>
266 </table>
267 <?php
268 collapse_end( 'bugnotestats' );