~sit-developers/sit/master

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
// ??
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2010-2014 The Support Incident Tracker Project
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
//
//  Author:   Paul Heaney

require ('core.php');
$permission = PERM_REPORT_RUN;  // Run Reports 
include (APPLICATION_LIBPATH . 'functions.inc.php');

// This page requires authentication
require (APPLICATION_LIBPATH . 'auth.inc.php');

$mode = clean_fixed_list($_REQUEST['mode'], array('showform','runreport'));

if (empty($mode) OR $mode == 'showform')
{
    include (APPLICATION_INCPATH . 'htmlheader.inc.php');

    echo "<h2>".icon('reports', 32)." {$strMonthlyActivityTotals}</h2>";
    echo "<form name='report' action='{$_SERVER['PHP_SELF']}' method='post'>";
    echo "<table class='vertical'>";

    echo "<tr><th>{$strStartDate}:</th>";
    echo "<td><input type='text' name='startdate' id='startdate' size='10' /> ";
    echo date_picker('report.startdate');
    echo "</td></tr>\n";
    echo "<tr><th>{$strEndDate}:</th>";
    echo "<td><input type='text' name='enddate' id='enddate' size='10' /> ";
    echo date_picker('report.enddate');
    echo "</td></tr>\n";

    echo "<tr><th>{$strOptions}</th><td>";
    echo "<label><input type='checkbox' name='calcote' value='yes' /> {$strCalculateUnits}</label>\n";
    echo "</td></tr>";

    echo "</table>";

    echo "<p class='formbuttons'>";
    echo "<input type='hidden' name='mode' value='report' />";
    echo "<input type='reset' value=\"{$strReset}\" /> ";
    echo "<input type='submit' value=\"{$strRunReport}\" />";
    echo "</p>";
    echo "<input type='hidden' id='mode' name='mode' value='runreport' />";
    echo "</form>";

    include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
}
elseif ($mode == 'runreport')
{
    $startdate = strtotime(cleanvar($_REQUEST['startdate']));
    $enddate = strtotime(cleanvar($_REQUEST['enddate']));

    if (empty($startdate)) $startdate = $now - 31536000; // 1 year ago
    if (empty($enddate)) $enddate = $now;

    $calcote = clean_fixed_list($_REQUEST['calcote'], array('','no','yes'));
    $sql = "SELECT userid, duration, timestamp FROM `{$dbUpdates}` WHERE timestamp >= '{$startdate}' AND timestamp <= '{$enddate}' AND duration != 0 AND duration IS NOT NULL ORDER BY timestamp";
    // echo $sql;
    $result = mysql_query($sql);
    if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);

    while ($obj = mysql_fetch_object($result))
    {
        $year = date('Y', $obj->timestamp);
        $month = date('F', $obj->timestamp);

        $value = 0;

        if ($calcote == 'yes')
        {
            // Engineer OTE each rounded to the nearest hour
            $mod = 60 - ($obj->duration % 60);
            $value = $obj->duration + $mod;
        }
        else
        {
            $value = $obj->duration;
        }

        $util[$year]['months'][$month]['name'] = $month;
        $util[$year]['months'][$month]['users'][$obj->userid]['userid'] = $obj->userid;
        if ($value > 0)
        {
            $util[$year]['months'][$month]['users'][$obj->userid]['valuepos'] += $value;
        }
        else
        {
            $util[$year]['months'][$month]['users'][$obj->userid]['valueneg'] += $value;
        }
        $util[$year]['months'][$month]['total'] += $obj->duration;
        $util[$year]['name'] = $year;
    }

    // echo "<pre>";
    // print_r($util);
    // echo "</pre>";

    include (APPLICATION_INCPATH . 'htmlheader.inc.php');

    echo "<h2>".icon('reports', 32)." {$strMonthlyActivityTotals}</h2>";

    if (count($util) > 0)
    {
        foreach ($util AS $u)
        {
            echo "<h3>{$u['name']}</h3>";
            foreach ($u['months'] AS $month)
            {
                echo "<p><table class='vertical maintable'>";
                echo "<tr><th colspan='3'>{$month['name']} {$u['name']}</th></tr>";
                echo "<tr><th>{$strEngineer}</th><th>{$strPositive}</th><th>{$strNegative}</th></tr>";

                $totalpos = 0;
                $totalneg = 0;

                $shade = 'shade1';
                foreach ($month['users'] AS $user)
                {

                    $minspos = 0;
                    $minsneg = 0;

                    if (!empty($user['valuepos']))
                    {
                        $minspos = ceil($user['valuepos']);
                        $totalpos += $minspos;
                    }

                    if (!empty($user['valueneg']))
                    {
                        $minsneg = ceil($user['valueneg']);
                        $totalneg += $minsneg;
                    }

                    echo "<tr class='{$shade}'><td>".user_realname($user['userid'])."</td><td>".sprintf($strXMinutes, $minspos)."</td><td>".sprintf($strXMinutes, $minsneg)."</td></tr>";

                    $grandtotals[$user['userid']]['userid'] = $user['userid'];
                    $grandtotals[$user['userid']]['totalpos'] += $minspos;
                    $grandtotals[$user['userid']]['totalneg'] += $minsneg;

                    if ($shade == 'shade1') $shade = 'shade2';
                    else $shade = 'shade1';
                }

                echo "<tr><td>{$strTotal}</td><td>". sprintf($strXMinutes, $totalpos)."</td><td>". sprintf($strXMinutes, $totalneg)."</td></tr>";

                echo "</table></p>";
            }
        }

        echo "<p align='center'><h3>{$strGrandTotal}</h3></p>";

        echo "<table class='vertical maintable'>";
        echo "<tr><th>{$strEngineer}</th><th>{$strPositive}</th><th>{$strNegative}</th></tr>";

        $shade = 'shade1';
        foreach ($grandtotals AS $gt)
        {
            echo "<tr class='{$shade}'><td>".user_realname($gt['userid'])."</td><td>".sprintf($strXMinutes, $gt['totalpos'])."</td><td>".sprintf($strXMinutes, $gt['totalneg'])."</td></tr>";
            if ($shade == 'shade1') $shade = 'shade2';
            else $shade = 'shade1';
        }

        echo "</table>";
    }
    else
    {
        echo "<p align='center'>{$strNoRecords}</p>";
    }

    include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
}

?>