Пример #1
0
/**
 * Get a combined array with time recordings and expenses to export.
 *
 * @param int $start Time from which to take entries into account.
 * @param int $end Time until which to take entries into account.
 * @param array $users Array of user IDs to filter by.
 * @param array $customers Array of customer IDs to filter by.
 * @param array $projects Array of project IDs to filter by.
 * @param array $events Array of event IDs to filter by.
 * @param bool $limit sbould the amount of entries be limited
 * @param bool $reverse_order should the entries be put out in reverse order
 * @param string $default_location use this string if no location is set for the entry
 * @param int $filter_cleared (-1: show all, 0:only cleared 1: only not cleared) entries
 * @param int $filter_type (-1 show time and expenses, 0: only show time entries, 1: only show expenses)
 * @param int $limitCommentSize should comments be cut off, when they are too long
 * @return array with time recordings and expenses chronologically sorted
 */
function xp_get_arr($start, $end, $users = null, $customers = null, $projects = null, $events = null, $limit = false, $reverse_order = false, $default_location = '', $filter_cleared = -1, $filter_type = -1, $limitCommentSize = true, $filter_refundable = -1)
{
    global $expense_ext_available;
    $zef_arr = array();
    $exp_arr = array();
    if ($filter_type != 1) {
        $zef_arr = get_arr_zef($start, $end, $users, $customers, $projects, $events, $limit, $reverse_order, $filter_cleared);
    }
    if ($filter_type != 0 && $expense_ext_available) {
        $exp_arr = get_arr_exp($start, $end, $users, $customers, $projects, $limit, $reverse_order, $filter_refundable, $filter_cleared);
    }
    $result_arr = array();
    $zef_arr_index = 0;
    $exp_arr_index = 0;
    while ($zef_arr_index < count($zef_arr) && $exp_arr_index < count($exp_arr)) {
        $arr = array();
        if (!$reverse_order && $zef_arr[$zef_arr_index]['zef_in'] > $exp_arr[$exp_arr_index]['exp_timestamp'] || $reverse_order && $zef_arr[$zef_arr_index]['zef_in'] < $exp_arr[$exp_arr_index]['exp_timestamp']) {
            if ($zef_arr[$zef_arr_index]['zef_out'] != 0) {
                // active recordings will be omitted
                $arr['type'] = 'zef';
                $arr['id'] = $zef_arr[$zef_arr_index]['zef_ID'];
                $arr['time_in'] = $zef_arr[$zef_arr_index]['zef_in'];
                $arr['time_out'] = $zef_arr[$zef_arr_index]['zef_out'];
                $arr['zef_time'] = $zef_arr[$zef_arr_index]['zef_time'];
                $arr['zef_duration'] = $zef_arr[$zef_arr_index]['zef_duration'];
                $arr['dec_zef_time'] = sprintf("%01.2f", $zef_arr[$zef_arr_index]['zef_time'] / 3600);
                $arr['zef_rate'] = $zef_arr[$zef_arr_index]['zef_rate'];
                $arr['wage'] = $zef_arr[$zef_arr_index]['wage'];
                $arr['wage_decimal'] = $zef_arr[$zef_arr_index]['wage_decimal'];
                $arr['pct_kndID'] = $zef_arr[$zef_arr_index]['pct_kndID'];
                $arr['knd_name'] = $zef_arr[$zef_arr_index]['knd_name'];
                $arr['pct_ID'] = $zef_arr[$zef_arr_index]['pct_ID'];
                $arr['pct_name'] = $zef_arr[$zef_arr_index]['pct_name'];
                $arr['pct_comment'] = $zef_arr[$zef_arr_index]['pct_comment'];
                $arr['zef_evtID'] = $zef_arr[$zef_arr_index]['zef_evtID'];
                $arr['evt_name'] = $zef_arr[$zef_arr_index]['evt_name'];
                if ($limitCommentSize) {
                    $arr['comment'] = addEllipsis($zef_arr[$zef_arr_index]['zef_comment'], 150);
                } else {
                    $arr['comment'] = $zef_arr[$zef_arr_index]['zef_comment'];
                }
                $arr['comment_type'] = $zef_arr[$zef_arr_index]['zef_comment_type'];
                $arr['location'] = $zef_arr[$zef_arr_index]['zef_location'];
                if (empty($arr['location'])) {
                    $arr['location'] = $default_location;
                }
                $arr['trackingnr'] = $zef_arr[$zef_arr_index]['zef_trackingnr'];
                $arr['username'] = $zef_arr[$zef_arr_index]['usr_name'];
                $arr['cleared'] = $zef_arr[$zef_arr_index]['zef_cleared'];
            }
            $zef_arr_index++;
        } else {
            $arr['type'] = 'exp';
            $arr['id'] = $exp_arr[$exp_arr_index]['exp_ID'];
            $arr['time_in'] = $exp_arr[$exp_arr_index]['exp_timestamp'];
            $arr['time_out'] = $exp_arr[$exp_arr_index]['exp_timestamp'];
            $arr['zef_time'] = null;
            $arr['zef_apos'] = null;
            $arr['dec_zef_time'] = null;
            $arr['zef_rate'] = null;
            $arr['wage'] = sprintf("%01.2f", $exp_arr[$exp_arr_index]['exp_value'] * $exp_arr[$exp_arr_index]['exp_multiplier']);
            $arr['pct_kndID'] = $exp_arr[$exp_arr_index]['pct_kndID'];
            $arr['knd_name'] = $exp_arr[$exp_arr_index]['knd_name'];
            $arr['pct_ID'] = $exp_arr[$exp_arr_index]['pct_ID'];
            $arr['pct_name'] = $exp_arr[$exp_arr_index]['pct_name'];
            if ($limitCommentSize) {
                $arr['comment'] = addEllipsis($exp_arr[$exp_arr_index]['exp_comment'], 150);
            } else {
                $arr['comment'] = $exp_arr[$exp_arr_index]['exp_comment'];
            }
            $arr['evt_name'] = $exp_arr[$exp_arr_index]['exp_designation'];
            $arr['comment'] = $exp_arr[$exp_arr_index]['exp_comment'];
            $arr['comment_type'] = $exp_arr[$exp_arr_index]['exp_comment_type'];
            $arr['location'] = $default_location;
            $arr['trackingnr'] = null;
            $arr['username'] = $exp_arr[$exp_arr_index]['usr_name'];
            $arr['cleared'] = $exp_arr[$exp_arr_index]['exp_cleared'];
            $exp_arr_index++;
        }
        $result_arr[] = $arr;
    }
    while ($zef_arr_index < count($zef_arr)) {
        if ($zef_arr[$zef_arr_index]['zef_out'] != 0) {
            // active recordings will be omitted
            $arr = array();
            $arr['type'] = 'zef';
            $arr['id'] = $zef_arr[$zef_arr_index]['zef_ID'];
            $arr['time_in'] = $zef_arr[$zef_arr_index]['zef_in'];
            $arr['time_out'] = $zef_arr[$zef_arr_index]['zef_out'];
            $arr['zef_time'] = $zef_arr[$zef_arr_index]['zef_time'];
            $arr['zef_duration'] = $zef_arr[$zef_arr_index]['zef_duration'];
            $arr['dec_zef_time'] = sprintf("%01.2f", $zef_arr[$zef_arr_index]['zef_time'] / 3600);
            $arr['zef_rate'] = $zef_arr[$zef_arr_index]['zef_rate'];
            $arr['wage'] = $zef_arr[$zef_arr_index]['wage'];
            $arr['wage_decimal'] = $zef_arr[$zef_arr_index]['wage_decimal'];
            $arr['pct_kndID'] = $zef_arr[$zef_arr_index]['pct_kndID'];
            $arr['knd_name'] = $zef_arr[$zef_arr_index]['knd_name'];
            $arr['pct_ID'] = $zef_arr[$zef_arr_index]['pct_ID'];
            $arr['pct_name'] = $zef_arr[$zef_arr_index]['pct_name'];
            $arr['pct_comment'] = $zef_arr[$zef_arr_index]['pct_comment'];
            $arr['zef_evtID'] = $zef_arr[$zef_arr_index]['zef_evtID'];
            $arr['evt_name'] = $zef_arr[$zef_arr_index]['evt_name'];
            if ($limitCommentSize) {
                $arr['comment'] = addEllipsis($zef_arr[$zef_arr_index]['zef_comment'], 150);
            } else {
                $arr['comment'] = $zef_arr[$zef_arr_index]['zef_comment'];
            }
            $arr['comment_type'] = $zef_arr[$zef_arr_index]['zef_comment_type'];
            $arr['location'] = $zef_arr[$zef_arr_index]['zef_location'];
            if (empty($arr['location'])) {
                $arr['location'] = $default_location;
            }
            $arr['trackingnr'] = $zef_arr[$zef_arr_index]['zef_trackingnr'];
            $arr['username'] = $zef_arr[$zef_arr_index]['usr_name'];
            $arr['cleared'] = $zef_arr[$zef_arr_index]['zef_cleared'];
            $result_arr[] = $arr;
        }
        $zef_arr_index++;
    }
    while ($exp_arr_index < count($exp_arr)) {
        $arr = array();
        $arr['type'] = 'exp';
        $arr['id'] = $exp_arr[$exp_arr_index]['exp_ID'];
        $arr['time_in'] = $exp_arr[$exp_arr_index]['exp_timestamp'];
        $arr['time_out'] = $exp_arr[$exp_arr_index]['exp_timestamp'];
        $arr['zef_time'] = null;
        $arr['zef_apos'] = null;
        $arr['dec_zef_time'] = null;
        $arr['zef_rate'] = null;
        $arr['wage'] = sprintf("%01.2f", $exp_arr[$exp_arr_index]['exp_value'] * $exp_arr[$exp_arr_index]['exp_multiplier']);
        $arr['pct_kndID'] = $exp_arr[$exp_arr_index]['pct_kndID'];
        $arr['knd_name'] = $exp_arr[$exp_arr_index]['knd_name'];
        $arr['pct_ID'] = $exp_arr[$exp_arr_index]['pct_ID'];
        $arr['pct_name'] = $exp_arr[$exp_arr_index]['pct_name'];
        if ($limitCommentSize) {
            $arr['comment'] = addEllipsis($exp_arr[$exp_arr_index]['exp_comment'], 150);
        } else {
            $arr['comment'] = $exp_arr[$exp_arr_index]['exp_comment'];
        }
        $arr['evt_name'] = $exp_arr[$exp_arr_index]['exp_designation'];
        $arr['comment'] = $exp_arr[$exp_arr_index]['exp_comment'];
        $arr['comment_type'] = $exp_arr[$exp_arr_index]['exp_comment_type'];
        $arr['username'] = $exp_arr[$exp_arr_index]['usr_name'];
        $arr['cleared'] = $exp_arr[$exp_arr_index]['exp_cleared'];
        $exp_arr_index++;
        $result_arr[] = $arr;
    }
    return $result_arr;
}
Пример #2
0
/**
 * Create an array of arrays which hold the size of the pie chart elements
 * for every projects.
 * The first element in the inner arrays represents the unused budget costs,
 * the second element in the inner arrays represents the expense costs,
 * the third and all other elements in the inner arrays represents the
 * costs for individual events.
 * 
 * An visual example for two projects with the ID 2 and 5:
 * $array = {
 *   2 => array (budget left , expenses cost, task1, task2 ),
 *   5 => array (budget left , expenses cost, task1, task2 ),
 * };
 * 
 * @param array $projects IDs of all projects to include in the plot data
 * @param array $usedEvents array of all used events (each as an array of its data)
 * @return array containing arrays for every project which hold the size of the pie chart elements
 * 
 */
function budget_plot_data($projects, &$usedEvents, &$expensesOccured)
{
    $wages = array();
    $eventUsage = array();
    // track what events are used
    $usedEvents = array();
    $expensesOccured = false;
    $events = get_arr_evt("all");
    /*
     * sum up expenses
     */
    foreach ($projects as $project) {
        $pctId = $project['pct_ID'];
        $wages[$pctId]['budget'] = $project['pct_budget'];
        $wages[$pctId]['expenses'] = calculate_expenses_sum($project['pct_ID']);
        if ($wages[$pctId]['expenses'] != 0) {
            $expensesOccured = true;
        }
        if ($wages[$pctId]['budget'] < 0) {
            //Costs over budget, set remaining budget to 0.
            $wages[$pctId]['budget'] = 0;
        }
        // initialize entries for every event using its ID
        foreach ($events as $event) {
            $wages[$pctId][$event['evt_ID']] = 0;
        }
    }
    /*
     * sum up wages for every project and every event
     */
    foreach ($projects as $project) {
        $projectId = $project['pct_ID'];
        $zef_arr = get_arr_zef(0, time(), null, null, array($projectId));
        foreach ($zef_arr as $zef) {
            $pctId = $zef['zef_pctID'];
            if ($zef['wage_decimal'] == 0.0) {
                continue;
            }
            if (key_exists($zef['zef_evtID'], $wages[$pctId])) {
                $eventUsage[$zef['zef_evtID']] = true;
                $wages[$pctId][$zef['zef_evtID']] += $zef['wage_decimal'];
                $wages[$pctId]['budget'] -= $zef['wage_decimal'];
            }
            if ($wages[$pctId]['budget'] < 0) {
                //Costs over budget, set remaining budget to 0.
                $wages[$pctId]['budget'] = 0;
            }
        }
    }
    /*
     * Delete unused events.
     */
    foreach ($events as $event) {
        if (isset($eventUsage[$event['evt_ID']])) {
            $usedEvents[] = $event;
            continue;
        }
        foreach ($wages as $projectData) {
            unset($projectData[$event['evt_ID']]);
        }
    }
    /* 
     * Convert array of wages to javascript array for every project.
     */
    $plot_data = array();
    foreach ($wages as $project_id => $wage_array) {
        $plot_data[$project_id] = '[' . implode(',', $wage_array) . ']';
    }
    return $plot_data;
}
Пример #3
0
 } else {
     $filterPct = explode(':', $filters[2]);
 }
 if ($filters[3] == "") {
     $filterEvt = array();
 } else {
     $filterEvt = explode(':', $filters[3]);
 }
 // if no userfilter is set, set it to current user
 if (isset($kga['usr']) && count($filterUsr) == 0) {
     array_push($filterUsr, $kga['usr']['usr_ID']);
 }
 if (isset($kga['customer'])) {
     $filterKnd = array($kga['customer']['knd_ID']);
 }
 $arr_zef = get_arr_zef($in, $out, $filterUsr, $filterKnd, $filterPct, $filterEvt, 1);
 if (count($arr_zef) > 0) {
     $tpl->assign('arr_zef', $arr_zef);
 } else {
     $tpl->assign('arr_zef', 0);
 }
 $tpl->assign('total', formatDuration(get_zef_time($in, $out, $filterUsr, $filterKnd, $filterPct, $filterEvt)));
 $ann = get_arr_time_usr($in, $out, $filterUsr, $filterKnd, $filterPct, $filterEvt);
 formatAnnotations($ann);
 $tpl->assign('usr_ann', $ann);
 $ann = get_arr_time_knd($in, $out, $filterUsr, $filterKnd, $filterPct, $filterEvt);
 formatAnnotations($ann);
 $tpl->assign('knd_ann', $ann);
 $ann = get_arr_time_pct($in, $out, $filterUsr, $filterKnd, $filterPct, $filterEvt);
 formatAnnotations($ann);
 $tpl->assign('pct_ann', $ann);
Пример #4
0
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
// Get the total time displayed in the table.
if (isset($kga['customer'])) {
    $total = formatDuration(get_zef_time($in, $out, null, array($kga['customer']['knd_ID']), null));
} else {
    $total = formatDuration(get_zef_time($in, $out, array($kga['usr']['usr_ID']), null, null));
}
$tpl->assign('total', $total);
// Get the array of timesheet entries.
if (isset($kga['customer'])) {
    $arr_zef = get_arr_zef($in, $out, null, array($kga['customer']['knd_ID']), null, 1);
} else {
    $arr_zef = get_arr_zef($in, $out, array($kga['usr']['usr_ID']), null, null, 1);
}
if (count($arr_zef) > 0) {
    $tpl->assign('arr_zef', $arr_zef);
} else {
    $tpl->assign('arr_zef', 0);
}
// Get the annotations for the user sub list.
if (isset($kga['customer'])) {
    $ann = get_arr_time_usr($in, $out, null, array($kga['customer']['knd_ID']));
} else {
    $ann = get_arr_time_usr($in, $out, array($kga['usr']['usr_ID']));
}
formatAnnotations($ann);
$tpl->assign('usr_ann', $ann);
// Get the annotations for the customer sub list.
Пример #5
0
{
    $precision = $prec;
    // suppress division by zero errror
    if ($precision == 0.0) {
        $precision = 1.0;
    }
    return floor($value / $precision + 0.5) * $precision;
}
// insert KSPI
$isCoreProcessor = 0;
$dir_templates = "templates/";
$usr = checkUser();
$timespace = get_timespace();
$in = $timespace[0];
$out = $timespace[1];
$timeArray = get_arr_zef($in, $out, null, null, array($_REQUEST['pct_ID']), 1);
/* $timeArray now contains: zef_ID, zef_in, zef_out, zef_time, zef_rate, zef_pctID,
	zef_evtID, zef_usrID, pct_ID, knd_name, pct_kndID, evt_name, pct_comment,
	pct_name, zef_location, zef_trackingnr, zef_comment, zef_comment_type,
	usr_name, usr_alias, zef_cleared
*/
$date = date("m-d-Y");
$month = $kga['lang']['months'][date("n", $out) - 1];
$year = date("Y", $out);
if (count($timeArray) > 0) {
    // customer data
    $kndArray = get_entry_knd($timeArray[0]['knd_name']);
    $project = html_entity_decode($timeArray[0]['pct_name']);
    $customerName = html_entity_decode($timeArray[0]['knd_name']);
    $companyName = $kndArray['knd_company'];
    $customerStreet = $kndArray['knd_street'];