1<?php
2# MantisBT - A PHP based bugtracking system
3
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.
8#
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.
13#
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/>.
16
17/**
18 * This include file prints out the bug bugnote_stats
19 * $f_bug_id must already be defined
20 *
21 * @package MantisBT
22 * @copyright Copyright 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
23 * @copyright Copyright 2002  MantisBT Team - mantisbt-dev@lists.sourceforge.net
24 * @link http://www.mantisbt.org
25 *
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
36 */
37
38if( !defined( 'BILLING_INC_ALLOW' ) ) {
39	return;
40}
41
42require_api( 'bugnote_api.php' );
43require_api( 'collapse_api.php' );
44require_api( 'config_api.php' );
45require_api( 'database_api.php' );
46require_api( 'filter_api.php' );
47require_api( 'gpc_api.php' );
48require_api( 'helper_api.php' );
49require_api( 'lang_api.php' );
50require_api( 'string_api.php' );
51require_api( 'utility_api.php' );
52
53?>
54<?php
55
56$t_today = date( 'd:m:Y' );
57$t_date_submitted = isset( $t_bug ) ? date( 'd:m:Y', $t_bug->date_submitted ) : $t_today;
58
59$t_bugnote_stats_from_def = $t_date_submitted;
60$t_bugnote_stats_from_def_ar = explode( ':', $t_bugnote_stats_from_def );
61$t_bugnote_stats_from_def_d = $t_bugnote_stats_from_def_ar[0];
62$t_bugnote_stats_from_def_m = $t_bugnote_stats_from_def_ar[1];
63$t_bugnote_stats_from_def_y = $t_bugnote_stats_from_def_ar[2];
64
65$t_bugnote_stats_from_d = gpc_get_int( FILTER_PROPERTY_DATE_SUBMITTED_START_DAY, $t_bugnote_stats_from_def_d );
66$t_bugnote_stats_from_m = gpc_get_int( FILTER_PROPERTY_DATE_SUBMITTED_START_MONTH, $t_bugnote_stats_from_def_m );
67$t_bugnote_stats_from_y = gpc_get_int( FILTER_PROPERTY_DATE_SUBMITTED_START_YEAR, $t_bugnote_stats_from_def_y );
68
69$t_bugnote_stats_to_def = $t_today;
70$t_bugnote_stats_to_def_ar = explode( ':', $t_bugnote_stats_to_def );
71$t_bugnote_stats_to_def_d = $t_bugnote_stats_to_def_ar[0];
72$t_bugnote_stats_to_def_m = $t_bugnote_stats_to_def_ar[1];
73$t_bugnote_stats_to_def_y = $t_bugnote_stats_to_def_ar[2];
74
75$t_bugnote_stats_to_d = gpc_get_int( FILTER_PROPERTY_DATE_SUBMITTED_END_DAY, $t_bugnote_stats_to_def_d );
76$t_bugnote_stats_to_m = gpc_get_int( FILTER_PROPERTY_DATE_SUBMITTED_END_MONTH, $t_bugnote_stats_to_def_m );
77$t_bugnote_stats_to_y = gpc_get_int( FILTER_PROPERTY_DATE_SUBMITTED_END_YEAR, $t_bugnote_stats_to_def_y );
78
79$f_get_bugnote_stats_button = gpc_get_string( 'get_bugnote_stats_button', '' );
80
81# Retrieve the cost as a string and convert to floating point
82$f_bugnote_cost = floatval( gpc_get_string( 'bugnote_cost', config_get( 'time_tracking_billing_rate' ) ) );
83
84$f_include_subprojects = gpc_get_bool( 'include_subprojects', false );
85
86$f_project_id = helper_get_current_project();
87
88if( ON == config_get( 'time_tracking_with_billing' ) ) {
89	$t_cost_col = true;
90} else {
91	$t_cost_col = false;
92}
93
94$t_collapse_block = is_collapsed( 'time_tracking_stats' );
95$t_block_css = $t_collapse_block ? 'collapsed' : '';
96$t_block_icon = $t_collapse_block ? 'fa-chevron-down' : 'fa-chevron-up';
97
98# Time tracking date range input form
99# CSRF protection not required here - form does not result in modifications
100?>
101
102<div class="col-md-12 col-xs-12">
103<div id="time_tracking_stats" class="widget-box widget-color-blue2 <?php echo $t_block_css ?>">
104<div class="widget-header widget-header-small">
105	<h4 class="widget-title lighter">
106		<?php print_icon( 'fa-clock-o', 'ace-icon' ); ?>
107		<?php echo lang_get( 'time_tracking' ) ?>
108	</h4>
109	<div class="widget-toolbar">
110		<a data-action="collapse" href="#">
111			<?php print_icon( $t_block_icon, 'ace-icon 1 bigger-125' ); ?>
112		</a>
113	</div>
114</div>
115
116<div class="widget-body">
117<form method="post" action="">
118	<div class="widget-main">
119	<input type="hidden" name="id" value="<?php echo isset( $f_bug_id ) ? $f_bug_id : 0 ?>" />
120		<?php
121			$t_filter = array();
122			$t_filter[FILTER_PROPERTY_FILTER_BY_DATE_SUBMITTED] = 'on';
123			$t_filter[FILTER_PROPERTY_DATE_SUBMITTED_START_DAY] = $t_bugnote_stats_from_d;
124			$t_filter[FILTER_PROPERTY_DATE_SUBMITTED_START_MONTH] = $t_bugnote_stats_from_m;
125			$t_filter[FILTER_PROPERTY_DATE_SUBMITTED_START_YEAR] = $t_bugnote_stats_from_y;
126			$t_filter[FILTER_PROPERTY_DATE_SUBMITTED_END_DAY] = $t_bugnote_stats_to_d;
127			$t_filter[FILTER_PROPERTY_DATE_SUBMITTED_END_MONTH] = $t_bugnote_stats_to_m;
128			$t_filter[FILTER_PROPERTY_DATE_SUBMITTED_END_YEAR] = $t_bugnote_stats_to_y;
129			filter_init( $t_filter );
130			print_filter_do_filter_by_date( true );
131		?>
132
133<?php
134	if( $t_cost_col ) {
135?>
136		<div class="space-6"></div>
137		<?php echo lang_get( 'time_tracking_cost_per_hour_label' ) ?>
138		<input type="text" name="bugnote_cost" class="input-sm" value="<?php echo $f_bugnote_cost ?>" />
139<?php
140	}
141?>
142<?php
143	if( $f_project_id != ALL_PROJECTS ) {
144?>
145		<div class="space-6"></div>
146		<label>
147			<input type="checkbox" name="include_subprojects" class="ace"
148				   <?php check_checked( $f_include_subprojects, true ); ?> />
149			<span class="lbl padding-6"><?php echo lang_get( 'subprojects' ) ?></span>
150		</label>
151<?php
152	}
153?>
154	</div>
155	<div class="widget-toolbox padding-8 clearfix">
156		<input name="get_bugnote_stats_button" class="btn btn-primary btn-sm btn-white btn-round"
157			value="<?php echo lang_get( 'time_tracking_get_info_button' ) ?>" type="submit">
158	</div>
159	</form>
160</div>
161</div>
162
163<?php
164	if( !is_blank( $f_get_bugnote_stats_button ) ) {
165		# Retrieve time tracking information
166		$t_from = $t_bugnote_stats_from_y . '-' . $t_bugnote_stats_from_m . '-' . $t_bugnote_stats_from_d;
167		$t_to = $t_bugnote_stats_to_y . '-' . $t_bugnote_stats_to_m . '-' . $t_bugnote_stats_to_d;
168		$t_bugnote_stats = billing_get_summaries( $f_project_id, $t_from, $t_to, $f_bugnote_cost, $f_include_subprojects );
169
170		if( is_blank( $f_bugnote_cost ) || ( (double)$f_bugnote_cost == 0 ) ) {
171			$t_cost_col = false;
172		}
173
174		echo '<br /><div class="noprint">';
175
176		$t_exports = array(
177			'csv_export' => 'billing_export_to_csv.php',
178			'excel_export' => 'billing_export_to_excel.php',
179		);
180
181		foreach( $t_exports as $t_export_label => $t_export_page ) {
182			echo '<a class="btn btn-primary btn-sm btn-white btn-round" ';
183			echo ' <a href="' . $t_export_page . '?';
184			echo 'from=' . $t_from . '&amp;to=' . $t_to;
185			echo '&amp;cost=' . $f_bugnote_cost;
186			echo '&amp;project_id=' . $f_project_id;
187			echo '&amp;include_subprojects=' . $f_include_subprojects;
188			echo '">' . lang_get( $t_export_label ) . '</a>';
189		}
190
191		echo '</div><br />';
192
193?>
194<div class="space-6"></div>
195<div class="table-responsive">
196<table class="table table-bordered table-condensed table-striped">
197	<tr>
198		<td class="small-caption">
199			<?php echo lang_get( 'username' ) ?>
200		</td>
201		<td class="small-caption">
202			<?php echo lang_get( 'time_tracking' ) ?>
203		</td>
204<?php	if( $t_cost_col ) { ?>
205		<td class="small-caption pull-right">
206			<?php echo lang_get( 'time_tracking_cost' ) ?>
207		</td>
208<?php	} ?>
209
210	</tr>
211<?php
212		foreach ( $t_bugnote_stats['issues'] as $t_issue_id => $t_issue ) {
213			$t_project_info = ( !isset( $f_bug_id ) && ( $f_project_id == ALL_PROJECTS || $f_include_subprojects ) ) ? '[' . project_get_name( $t_issue['project_id'] ) . ']' . lang_get( 'word_separator' ) : '';
214			$t_link = sprintf( lang_get( 'label' ), string_get_bug_view_link( $t_issue_id ) ) . lang_get( 'word_separator' ) . $t_project_info . string_display_line( $t_issue['summary'] );
215			echo '<tr class="row-category-history"><td colspan="4">' . $t_link . '</td></tr>';
216
217			uksort(
218				$t_issue['users'],
219				function ( $a, $b ) {
220					return strcasecmp( user_get_name( $a ), user_get_name( $b ) );
221				}
222			);
223
224			foreach( $t_issue['users'] as $t_user_id => $t_user_info ) {
225?>
226	<tr>
227		<td class="small-caption">
228			<?php print_user( $t_user_id ) ?>
229		</td>
230		<td class="small-caption">
231			<?php echo db_minutes_to_hhmm( $t_user_info['minutes'] ) ?>
232		</td>
233<?php		if( $t_cost_col ) { ?>
234		<td class="small-caption right">
235			<?php echo string_attribute( number_format( $t_user_info['cost'], 2 ) ); ?>
236		</td>
237<?php		} ?>
238	</tr>
239
240<?php
241			} # end of users within issues loop
242		} # end for issues loop ?>
243
244	<tr>
245		<td class="small-caption">
246			<?php echo lang_get( 'total_time' ); ?>
247		</td>
248		<td class="small-caption bold">
249			<?php echo db_minutes_to_hhmm( $t_bugnote_stats['total']['minutes'] ); ?>
250		</td>
251<?php	if( $t_cost_col ) { ?>
252		<td class="small-caption bold right">
253			<?php echo string_attribute( number_format( $t_bugnote_stats['total']['cost'], 2 ) ); ?>
254		</td>
255<?php 	} ?>
256	</tr>
257</table>
258
259<div class="space-6"></div>
260
261<div class="table-responsive">
262<table class="table table-bordered table-condensed table-striped">
263	<tr>
264		<td class="small-caption">
265			<?php echo lang_get( 'username' ) ?>
266		</td>
267		<td class="small-caption">
268			<?php echo lang_get( 'time_tracking' ) ?>
269		</td>
270<?php	if( $t_cost_col ) { ?>
271		<td class="small-caption pull-right">
272			<?php echo lang_get( 'time_tracking_cost' ) ?>
273		</td>
274<?php	} ?>
275	</tr>
276
277<?php
278	uksort(
279		$t_bugnote_stats['users'],
280		function ( $a, $b ) {
281			return strcasecmp( user_get_name( $a ), user_get_name( $b ) );
282		}
283	);
284
285	foreach ( $t_bugnote_stats['users'] as $t_user_id => $t_user_info ) {
286?>
287	<tr>
288		<td class="small-caption">
289			<?php print_user( $t_user_id ) ?>
290		</td>
291		<td class="small-caption">
292			<?php echo db_minutes_to_hhmm( $t_user_info['minutes'] ); ?>
293		</td>
294<?php		if( $t_cost_col ) { ?>
295		<td class="small-caption right">
296			<?php echo string_attribute( number_format( $t_user_info['cost'], 2 ) ); ?>
297		</td>
298<?php		} ?>
299	</tr>
300<?php	} ?>
301	<tr class="row-category2">
302		<td class="small-caption bold">
303			<?php echo lang_get( 'total_time' ); ?>
304		</td>
305		<td class="small-caption bold">
306			<?php echo db_minutes_to_hhmm( $t_bugnote_stats['total']['minutes'] ); ?>
307		</td>
308<?php	if( $t_cost_col ) { ?>
309		<td class="small-caption bold right">
310			<?php echo string_attribute( number_format( $t_bugnote_stats['total']['cost'], 2 ) ); ?>
311		</td>
312<?php	} ?>
313	</tr>
314</table>
315
316<?php
317	} # end if
318?>
319
320</div>
321
322<?php
323