Example #1
0
/**
 * Sum up expenses for the project.
 */
function calculate_expenses_sum($projectId)
{
    $expSum = 0;
    $exp_arr = get_arr_exp(0, time(), null, null, array($projectId));
    foreach ($exp_arr as $exp) {
        $expSum += $exp['exp_value'];
    }
    return $expSum;
}
Example #2
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;
}
Example #3
0
require_once '../../libraries/smarty/Smarty.class.php';
$tpl = new Smarty();
$tpl->template_dir = 'templates/';
$tpl->compile_dir = 'compile/';
$tpl->assign('kga', $kga);
// prevent IE from caching the response
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");
if (isset($kga['usr'])) {
    // user logged in
    $arr_exp = get_arr_exp($in, $out, array($kga['usr']['usr_ID']), null, null, 1);
} else {
    // customer logged in
    $arr_exp = get_arr_exp($in, $out, null, array($kga['customer']['knd_ID']), null, 1);
}
if (count($arr_exp) > 0) {
    $tpl->assign('arr_exp', $arr_exp);
} else {
    $tpl->assign('arr_exp', 0);
}
$tpl->assign('total', "");
if (isset($kga['usr'])) {
    // user logged in
    $ann = get_arr_exp_usr($in, $out, array($kga['usr']['usr_ID']));
} else {
    // customer logged in
    $ann = get_arr_exp_usr($in, $out, null, array($kga['customer']['knd_ID']));
}
$ann = formatCurrency($ann);
Example #4
0
 } else {
     $filterKnd = explode(':', $filters[1]);
 }
 if ($filters[2] == "") {
     $filterPct = array();
 } else {
     $filterPct = explode(':', $filters[2]);
 }
 // 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_exp = get_arr_exp($in, $out, $filterUsr, $filterKnd, $filterPct, 1);
 if (count($arr_exp) > 0) {
     $tpl->assign('arr_exp', $arr_exp);
 } else {
     $tpl->assign('arr_exp', 0);
 }
 $tpl->assign('total', "");
 $ann = get_arr_exp_usr($in, $out, $filterUsr, $filterKnd, $filterPct);
 $ann = formatCurrency($ann);
 $tpl->assign('usr_ann', $ann);
 // TODO: function for loops or convert it in template with new function
 $ann = get_arr_exp_knd($in, $out, $filterUsr, $filterKnd, $filterPct);
 $ann = formatCurrency($ann);
 $tpl->assign('knd_ann', $ann);
 $ann = get_arr_exp_pct($in, $out, $filterUsr, $filterKnd, $filterPct);
 $ann = formatCurrency($ann);