Esempio n. 1
0
/**
 * Gets the billing information for the specified project during the specified date range.
 * 
 * @param integer $p_project_id    A project identifier.
 * @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 array of bugnotes
 * @access public
 */
function billing_get_for_project($p_project_id, $p_from, $p_to, $p_cost_per_hour)
{
    $t_params = array();
    $c_to = strtotime($p_to) + SECONDS_PER_DAY - 1;
    $c_from = strtotime($p_from);
    if ($c_to === false || $c_from === false) {
        error_parameters(array($p_from, $p_to));
        trigger_error(ERROR_GENERIC, ERROR);
    }
    if (ALL_PROJECTS != $p_project_id) {
        $t_project_where = ' AND b.project_id = ' . db_param() . ' AND bn.bug_id = b.id ';
        $t_params[] = $p_project_id;
    } else {
        $t_project_where = '';
    }
    if (!is_blank($c_from)) {
        $t_from_where = ' AND bn.date_submitted >= ' . db_param();
        $t_params[] = $c_from;
    } else {
        $t_from_where = '';
    }
    if (!is_blank($c_to)) {
        $t_to_where = ' AND bn.date_submitted <= ' . db_param();
        $t_params[] = $c_to;
    } else {
        $t_to_where = '';
    }
    $t_results = array();
    $t_query = 'SELECT bn.id id, bn.time_tracking minutes, bn.date_submitted as date_submitted, bnt.note note,
			u.realname realname, b.summary bug_summary, bn.bug_id bug_id, bn.reporter_id reporter_id
			FROM {user} u, {bugnote} bn, {bug} b, {bugnote_text} bnt
			WHERE u.id = bn.reporter_id AND bn.time_tracking != 0 AND bn.bug_id = b.id AND bnt.id = bn.bugnote_text_id
			' . $t_project_where . $t_from_where . $t_to_where . '
			ORDER BY bn.id';
    $t_result = db_query($t_query, $t_params);
    $t_cost_per_min = $p_cost_per_hour / 60.0;
    while ($t_row = db_fetch_array($t_result)) {
        $t_total_cost = $t_cost_per_min * $t_row['minutes'];
        $t_row['cost'] = $t_total_cost;
        $t_results[] = $t_row;
    }
    $t_billing_rows = billing_rows_to_array($t_results);
    return $t_billing_rows;
}
Esempio n. 2
0
/**
 * Gets the billing information for the specified project during the specified 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 array of bugnotes
 * @access public
 */
function billing_get_for_project($p_project_id, $p_from, $p_to, $p_cost_per_hour)
{
    $t_params = array();
    $c_to = strtotime($p_to) + SECONDS_PER_DAY - 1;
    $c_from = strtotime($p_from);
    if ($c_to === false || $c_from === false) {
        error_parameters(array($p_from, $p_to));
        trigger_error(ERROR_GENERIC, ERROR);
    }
    db_param_push();
    if (ALL_PROJECTS != $p_project_id) {
        access_ensure_project_level(config_get('view_bug_threshold'), $p_project_id);
        $t_project_where = ' AND b.project_id = ' . db_param() . ' AND bn.bug_id = b.id ';
        $t_params[] = $p_project_id;
    } else {
        $t_project_ids = user_get_all_accessible_projects();
        $t_project_where = ' AND b.project_id in (' . implode(', ', $t_project_ids) . ')';
    }
    if (!is_blank($c_from)) {
        $t_from_where = ' AND bn.date_submitted >= ' . db_param();
        $t_params[] = $c_from;
    } else {
        $t_from_where = '';
    }
    if (!is_blank($c_to)) {
        $t_to_where = ' AND bn.date_submitted <= ' . db_param();
        $t_params[] = $c_to;
    } else {
        $t_to_where = '';
    }
    $t_results = array();
    $t_query = 'SELECT bn.id id, bn.time_tracking minutes, bn.date_submitted as date_submitted, bnt.note note,
			u.realname realname, b.project_id project_id, c.name bug_category, b.summary bug_summary, bn.bug_id bug_id, bn.reporter_id reporter_id
			FROM {user} u, {bugnote} bn, {bug} b, {bugnote_text} bnt, {category} c
			WHERE u.id = bn.reporter_id AND bn.time_tracking != 0 AND bn.bug_id = b.id AND bnt.id = bn.bugnote_text_id AND c.id=b.category_id
			' . $t_project_where . $t_from_where . $t_to_where . '
			ORDER BY bn.id';
    $t_result = db_query($t_query, $t_params);
    $t_cost_per_min = $p_cost_per_hour / 60.0;
    $t_access_level_required = config_get('time_tracking_view_threshold');
    while ($t_row = db_fetch_array($t_result)) {
        if (!access_has_bugnote_level($t_access_level_required, $t_row['id'])) {
            continue;
        }
        $t_total_cost = $t_cost_per_min * $t_row['minutes'];
        $t_row['cost'] = $t_total_cost;
        $t_results[] = $t_row;
    }
    $t_billing_rows = billing_rows_to_array($t_results);
    return $t_billing_rows;
}