Ejemplo n.º 1
0
 */
require_once 'core.php';
require_api('billing_api.php');
require_api('bug_api.php');
require_api('csv_api.php');
helper_begin_long_process();
$t_filename = csv_get_default_filename();
$t_date_format = config_get('normal_date_format');
$f_project_id = gpc_get_int('project_id');
$f_cost = gpc_get_int('cost');
$f_from = gpc_get_string('from');
$f_to = gpc_get_string('to');
$t_separator = ',';
billing_ensure_reporting_access($f_project_id);
$t_show_cost = ON == config_get('time_tracking_with_billing') && $f_cost != 0;
$t_billing_rows = billing_get_for_project($f_project_id, $f_from, $f_to, $f_cost);
$t_show_realname = config_get('show_realname') == ON;
header('Pragma: public');
header('Content-Type: text/csv; name=' . urlencode(file_clean_name($t_filename)));
header('Content-Transfer-Encoding: BASE64;');
header('Content-Disposition: attachment; filename="' . urlencode(file_clean_name($t_filename)) . '"');
echo csv_escape_string(lang_get('issue_id')) . $t_separator;
echo csv_escape_string(lang_get('project_name')) . $t_separator;
echo csv_escape_string(lang_get('summary')) . $t_separator;
if ($t_show_realname) {
    echo csv_escape_string(lang_get('realname')) . $t_separator;
} else {
    echo csv_escape_string(lang_get('username')) . $t_separator;
}
echo csv_escape_string(lang_get('timestamp')) . $t_separator;
echo csv_escape_string(lang_get('minutes')) . $t_separator;
Ejemplo n.º 2
0
/**
 * Gets the billing summary for the specified project and the date range.
 *
 * @param integer $p_project_id    A project identifier or ALL_PROJECTS.
 * @param string  $p_from          Starting date (yyyy-mm-dd) inclusive, if blank, then ignored.
 * @param string  $p_to            Ending date (yyyy-mm-dd) inclusive, if blank, then ignored.
 * @param integer $p_cost_per_hour Cost per hour.
 * @return array The contains billing data grouped by issues, users, and total information.
 * @access public
 */
function billing_get_summaries($p_project_id, $p_from, $p_to, $p_cost_per_hour)
{
    $t_billing_notes = billing_get_for_project($p_project_id, $p_from, $p_to, $p_cost_per_hour);
    $t_issues = array();
    $t_users = array();
    foreach ($t_billing_notes as $t_note) {
        extract($t_note, EXTR_PREFIX_ALL, 'v');
        $t_username = user_get_name($v_reporter_id);
        # Create users in collection of users if not already exists
        if (!isset($t_users[$t_username])) {
            $t_users[$t_username] = array();
            $t_users[$t_username]['minutes'] = 0;
            $t_users[$t_username]['cost'] = 0;
        }
        # Update user total minutes
        $t_users[$t_username]['minutes'] += $v_minutes;
        # Create issue if it doesn't exist yet.
        if (!isset($t_issues[$v_bug_id])) {
            $t_issues[$v_bug_id]['issue_id'] = $v_bug_id;
            $t_issues[$v_bug_id]['project_id'] = $v_project_id;
            $t_issues[$v_bug_id]['project_name'] = $v_project_name;
            $t_issues[$v_bug_id]['summary'] = $v_bug_summary;
            $t_issues[$v_bug_id]['users'] = array();
            $t_issues[$v_bug_id]['minutes'] = 0;
            $t_issues[$v_bug_id]['cost'] = 0;
        }
        # Create user within issue if they don't exist yet
        if (!isset($t_issues[$v_bug_id]['users'][$t_username])) {
            $t_issues[$v_bug_id]['users'][$t_username] = array();
            $t_issues[$v_bug_id]['users'][$t_username]['minutes'] = 0;
            $t_issues[$v_bug_id]['users'][$t_username]['cost'] = 0;
        }
        # Update total minutes for user within the issue
        $t_issues[$v_bug_id]['users'][$t_username]['minutes'] += $v_minutes;
        # Update total minutes for issue
        $t_issues[$v_bug_id]['minutes'] += $v_minutes;
    }
    $t_total = array('minutes' => 0, 'cost' => 0);
    # Calculate costs and update total cost/minutes across all issues
    foreach ($t_issues as $t_issue_id => $t_issue_info) {
        # Calculate cost for issue
        $t_cost = $t_issue_info['minutes'] * $p_cost_per_hour / 60;
        $t_issues[$t_issue_id]['cost'] = $t_cost;
        $t_issues[$t_issue_id]['duration'] = db_minutes_to_hhmm($t_issue_info['minutes']);
        # Add issue cost and minutes to totals
        $t_total['cost'] += $t_cost;
        $t_total['minutes'] += $t_issue_info['minutes'];
        # Calculate cost per user per issue
        foreach ($t_issue_info['users'] as $t_username => $t_user_info) {
            $t_issues[$t_issue_id]['users'][$t_username]['cost'] = $t_user_info['minutes'] * $p_cost_per_hour / 60;
        }
        ksort($t_issues[$t_issue_id]['users']);
    }
    # Calculate total cost per user across all issues
    foreach ($t_users as $t_username => $t_info) {
        $t_users[$t_username]['cost'] = $t_info['minutes'] * $p_cost_per_hour / 60;
    }
    ksort($t_users);
    ksort($t_issues);
    return array('issues' => $t_issues, 'users' => $t_users, 'total' => $t_total);
}