fix statistics report TitleBox, #13546
[freeside.git] / rt / share / html / RTx / Statistics / CallsQueueDay / index.html
1 <& /Elements/Header, Title => loc("Tickets per day in Queue:" . $QueueObj->Name()) &>
2 <& /RTx/Statistics/Elements/Tabs,  Title => loc("Tickets by status per day in Queue:" . $QueueObj->Name()) &>
3
4 <h3>Description</h3>
5 <p>This page displays details about tickets in the selected queue over the date range chosen. It shows how many tickets were created on
6 each day in the chosen range, and how many of those were either Resolved or Deleted.</p>
7 <p>To always show the current month to date, bookmark this <a href="<%$RT::WebPath%>/RTx/Statistics/CallsQueueDay/index.html?currentMonth=1">link</a>, or 
8 for a spreadsheet, use this <a href="<%$RT::WebPath%>/RTx/Statistics/CallsQueueDay/Results.tsv?currentMonth=1">link</a>.</p>
9
10 <form method="POST" action="index.html">
11
12 % Statistics::DebugLog("queue name=" . $QueueObj->Name() . "\n");
13
14 %my $title = "Ticket counts in " . $QueueObj->Name() . " by status per day from " . 
15 %         Statistics::FormatDate($Statistics::PerDayDateFormat, $dates[0]) . " through " .
16 %         Statistics::FormatDate($Statistics::PerDayDateFormat, $dates[$#dates-1]);
17 <&|/Elements/TitleBox, 
18         title => $title,
19         title_href => $RT::WebPath."/RTx/Statistics/CallsQueueDay/index.html?$QueryString" &>
20 <TABLE BORDER=0 cellspacing=0 cellpadding=1 WIDTH=100%>
21 % if ($ShowHeader) {
22 <& /RTx/Statistics/Elements/CollectionAsTable/Header, 
23     Format => \@Format, 
24     FormatString => $Format,
25     AllowSorting => $AllowSorting, 
26     Order => $Order, 
27     Query => undef,
28     Rows => $Rows,
29     Page => $Page,
30     OrderBy => $OrderBy , 
31     BaseURL => $BaseURL,
32     maxitems => $maxitems &> 
33 % }
34 % my $line = 1;
35 % LINE: for my $d (0..$#dates) {
36 % if ($d == $#dates){
37 %        next LINE;
38 % }
39 %     my $x = 1;
40 %     $values{Statistics_Date} = Statistics::FormatDate($Statistics::PerDayDateFormat, $dates[$d]);
41 %# NOTE need to handle all status values here....
42 %     for my $status (qw(created resolved deleted)) {
43 %         my $tix = new RT::Tickets($session{'CurrentUser'});
44 %         $tix->LimitQueue (VALUE => $Queue);
45 %         if ($status eq "created") {
46 %             $tix->LimitCreated(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
47 %             if ($dates[$d+1]) {
48 %                 $tix->LimitCreated(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
49 %            }
50 %            $values{Statistics_Created_Count} = $tix->Count;
51 %            $Totals{Statistics_Created_Count} += $tix->Count;
52 %         }
53 %         elsif ($status eq "resolved") {
54 %             $tix->LimitStatus(VALUE => $status);
55 %             $tix->LimitResolved(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
56 %             if ($dates[$d+1]) {
57 %                 $tix->LimitResolved(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
58 %             }
59 %            $values{Statistics_Resolved_Count} = $tix->Count;
60 %            $Totals{Statistics_Resolved_Count} += $tix->Count;
61 %         } 
62 %         elsif ($status eq "deleted") {
63 %             $tix->LimitStatus(VALUE => $status);
64 %             $tix->LimitLastUpdated(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
65 %             if ($dates[$d+1]) {
66 %                 $tix->LimitLastUpdated(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
67 %             }
68 %            $values{Statistics_Deleted_Count} = $tix->Count;
69 %            $Totals{Statistics_Deleted_Count} += $tix->Count;
70 %         }
71 %         $data[$x++][$d] = $tix->Count;
72 %     }
73 <&   /RTx/Statistics/Elements/CollectionAsTable/Row, Format => \@Format, i => $line, record => $record, maxitems => $maxitems &>
74 %    $line++;
75 % }
76 % $values {Statistics_Date} = "Totals";
77 % $values {Statistics_Created_Count} = $Totals{Statistics_Created_Count};
78 % $values {Statistics_Resolved_Count} = $Totals{Statistics_Resolved_Count};
79 % $values {Statistics_Deleted_Count} = $Totals{Statistics_Deleted_Count};
80 <&   /RTx/Statistics/Elements/CollectionAsTable/Row, Format => \@BoldFormat, i => $line, record => $record, maxitems => $maxitems &>
81 </table>
82 </&>
83
84 <%perl>
85 # Create the graph URL
86 my $url= 'Elements/Chart?x_labels=';
87 for (1..$diff) {
88     $url .= $data[0][$_] . ",";
89 }
90 chop $url;
91 $url .= "&";
92 shift @data;
93 for (0..$#data) {
94     $url .= "data".(1+$_)."=".(join ",", @{$data[$_]})."&";
95 }
96 chop $url;
97 $url .= "&set_legend=Created,Resolved,Deleted";
98 </%perl>
99
100 <& /RTx/Statistics/Elements/GraphBox, GraphURL => $url &>
101
102 <& /RTx/Statistics/Elements/ControlsAsTable/ControlBox, 
103          Title => "Change Queue or Dates", 
104          ShowDates => 1, sMonth => \$sMonth, sDay => \$sDay, sYear => \$sYear,
105                          eMonth => \$eMonth, eDay => \$eDay, eYear => \$eYear,
106                          weekends => $weekends,
107          ShowSingleQueue => 1, Queue => $Queue
108  &>
109
110 </form>
111
112 <a href="<%$RT::WebPath%>/RTx/Statistics/CallsQueueDay/index.html?<% $QueryString %>"><&|/l&>Bookmarkable link</&></a> |
113 <a href="<%$RT::WebPath%>/RTx/Statistics/CallsQueueDay/Results.tsv?<%$QueryString%>"><&|/l&>spreadsheet</&></a>
114 <BR>
115 <BR>
116
117
118 % Statistics::DebugLog("ref of eMonth is " . ref($eMonth) . "\n");
119 % Statistics::DebugInit( $m );
120
121 <%ARGS>
122 $Queue => undef
123 $weekends => $Statistics::PerDayWeekends;
124 $sMonth=>undef
125 $sDay=>undef
126 $sYear=>undef
127 $eMonth=>undef
128 $eDay=>undef
129 $eYear=>undef
130 $days=>undef
131 $currentMonth=>undef
132
133 $AllowSorting => undef
134 $Order => undef
135 $OrderBy => undef
136 $ShowNavigation => 1
137 $ShowHeader => 1
138 $Rows => 50
139 $Page => 1
140 $BaseURL => undef
141 </%ARGS>
142
143 <%INIT>
144 use RTx::Statistics;
145 use Time::Local;
146 my $selected;
147 my $n = 0;
148 my @data = ([]);
149 my @dates;
150 my @msgs;
151 my $diff;
152 my $sEpoch=0;
153 my $eEpoch=0;
154 my %Totals;
155 my $QueryString;
156 my $maxitems = 4;
157 my %record;
158 my %values;
159 my $record = \%record;
160
161 $record{values} = \%values;
162
163
164 # If debugging, set things up and display all the args
165 Statistics::DebugClear();
166 Statistics::DebugLog("CallsQueueDay/index.html ARGS:\n");
167 for my $key (keys %ARGS) {
168   Statistics::DebugLog("ARG{ $key }=" . $ARGS{$key} . "\n");
169 }
170
171 my $Format = qq{ Statistics_Date, 
172                  '__Statistics_Created_Count__/STYLE:text-align:right;', 
173                  '__Statistics_Resolved_Count__/STYLE:text-align:right;', 
174                  '__Statistics_Deleted_Count__/STYLE:text-align:right;' };
175 my $BoldFormat = qq{ '<B>__Statistics_Date__</B>', 
176                      '<B>__Statistics_Created_Count__</B>/STYLE:text-align:right;',
177                      '<B>__Statistics_Resolved_Count__</B>/STYLE:text-align:right;',
178                      '<B>__Statistics_Deleted_Count__</B>/STYLE:text-align:right;' };
179 my (@Format) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $Format);
180 my (@BoldFormat) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $BoldFormat);
181 Statistics::DebugLog("CallsQueueDay/index.html Format array=" . join(',', @Format) . "\n");
182
183 if (!defined $Queue) {
184   my $QueueObj = new RT::Queue($session{'CurrentUser'});
185   $QueueObj->Load($Statistics::PerDayQueue);
186   $Queue = $QueueObj->Id();
187 }
188
189 if ($sDay > $Statistics::monthsMaxDay{$sMonth}) {
190   $sDay = $Statistics::monthsMaxDay{$sMonth};
191 }
192
193 if ($eDay > $Statistics::monthsMaxDay{$eMonth}) {
194   $eDay = $Statistics::monthsMaxDay{$eMonth};
195 }
196
197 if ($sYear){
198         $sEpoch = timelocal(0, 0, 0, $sDay, $sMonth, $sYear-1900);
199 }
200 if ($eYear){
201 Statistics::DebugLog("eMonth = " . $eMonth . "\n");
202         $eEpoch = timelocal(0, 0, 0, $eDay, $eMonth, $eYear-1900);
203 } else {
204         # This case happens when the page is first loaded
205         my @local = localtime(time);
206         ($eDay, $eMonth, $eYear) = ($local[3], $local[4], $local[5]);
207         $eYear += 1900; 
208         $eEpoch = timelocal(0, 0, 0, $local[3], $local[4], $local[5], $local[6], $local[7], $local[8]);
209 Statistics::DebugLog("Setting eEpoch=$eEpoch from current time.\n");
210 }
211
212 if (($eEpoch < $sEpoch) || ($sEpoch == 0)) {
213     # We have an end, but not a start, or, overlapping.
214     
215     # if $currentMonth is set, just set the day to 1
216     if($currentMonth) {
217       # set start vars from end, but with day set to 1
218       (undef, undef, undef, $sDay, $sMonth, $sYear) = localtime($eEpoch);
219       $sDay=1;
220       $sEpoch = timelocal(0, 0, 0, $sDay, $sMonth, $sYear);
221     } else {
222       # If the user has specified how many days back to go, use that,
223       # If not, set start to configured default period before end
224       if(defined $days) {
225         $sEpoch = $eEpoch - ($days * $Statistics::secsPerDay);
226       } else {
227         $sEpoch = $eEpoch - ($Statistics::PerDayPeriod * $Statistics::secsPerDay);
228       }
229       (undef, undef, undef, $sDay, $sMonth, $sYear) = localtime($sEpoch);
230     }
231     $sYear += 1900;
232 }
233
234 # Compute days to chart.
235 # The +1 is because we need to generate one more date. If the user
236 # selected a 10 day range, we need to generate 11 days.
237 $diff = int(($eEpoch - $sEpoch + $Statistics::secsPerDay - 1) / $Statistics::secsPerDay)+1;
238 Statistics::DebugLog("Setting diff=$diff\n");
239
240 Statistics::DebugLog("sEpoch=$sEpoch, components=" . join(',', localtime($sEpoch)) . "\n");
241 Statistics::DebugLog("eEpoch=$eEpoch, components=" . join(',', localtime($eEpoch)) . "\n");
242
243 # Set up the string for the current query for bookmarkable link
244 $QueryString = "sDay=$sDay&sMonth=$sMonth&sYear=$sYear&eDay=$eDay&eMonth=$eMonth&eYear=$eYear&weekends=$weekends&Queue=$Queue";
245
246 # Set up the end date to be midnight(morning) of the date after the one the user wanted.
247 my $endRange = $eEpoch + $Statistics::secsPerDay;
248 my $QueueObj = new RT::Queue($session{'CurrentUser'});
249 $QueueObj->Load($Queue);
250 $n = 0;
251 until ($#dates == $diff) {
252     my $date = new RT::Date($session{CurrentUser});
253     $date->Set(Value=>$endRange - $n, Format => 'unix');
254     # Note: we used to adjust the time to local midnight, but
255     # none of the other date entry fields in RT seem to adjust, so we've stopped.
256     #Statistics::DebugLog("Before adjust to midnight date " . Statistics::FormatDate("%c", $date) . "\n");
257     $n+= $Statistics::secsPerDay;
258     # If we aren't showing weekends and this is one, decrement the number
259     # of days to show and skip to the next date.
260     if(!$weekends and Statistics::RTDateIsWeekend($date)) {$diff--; next;}
261     unshift @dates, $date;
262 Statistics::DebugLog("pushing date " . Statistics::FormatDate("%c", $date) . "\n");
263     unshift @{ $data[0] }, Statistics::FormatDate($Statistics::PerDayLabelDateFormat, $date);
264 }
265
266 # We put an extra day into the lists to cover up till midnight of the next day,
267 # But we don't want that to appear in the labels, so pop it off.
268 pop( @{ $data[0] } );
269
270 </%INIT>