RTx-Statistics in 2.1 / 3.8
[freeside.git] / rt / html / RTx / Statistics / DayOfWeek / index.html
1 <& /Elements/Header, Title =>loc('Tickets by Day Of Week in Queue:' . $QueueObj->Name()) &>
2 <& /RTx/Statistics/Elements/Tabs, Title =>loc('Trends in ticket status by Day Of Week in Queue:' . $QueueObj->Name()) &>
3
4 <h3>Description</h3>
5 <p>The purpose of this page is to show historical trends for each day of the week. 
6 It displays details of number of tickets created in your
7 selected queue for each day. It also hows how many of those created tickets were Resolved or Deleted</p>
8
9 <form method="POST" action="index.html">
10
11
12 %my $title = "Ticket counts by day of week in " . $QueueObj->Name();
13 <&|/Elements/TitleBox, 
14         title => $title,
15         title_href => "/RTx/Statistics/DayOfWeek/index.html?$QueryString" &>
16 <TABLE BORDER=0 cellspacing=0 cellpadding=1 WIDTH=100%>
17 % if ($ShowHeader) {
18 <& /RTx/Statistics/Elements/CollectionAsTable/Header, 
19     Format => \@Format, 
20     FormatString => $Format,
21     AllowSorting => $AllowSorting, 
22     Order => $Order, 
23     Query => undef,
24     Rows => $Rows,
25     Page => $Page,
26     OrderBy => $OrderBy , 
27     BaseURL => $BaseURL,
28     maxitems => $maxitems &> 
29 % }
30 % my $line = 1;
31 % for my $d (0..$#days) {
32 %     my $x = 1;
33 %     $values{Statistics_Date} = $days[$d];
34 %# NOTE Show all status values???
35 %     $values{Statistics_Created_Count} = $counts[$d]{new};
36 %     $values{Statistics_Resolved_Count} = $counts[$d]{resolved};
37 %     $values{Statistics_Deleted_Count} = $counts[$d]{deleted};
38 <&   /RTx/Statistics/Elements/CollectionAsTable/Row, Format => \@Format, i => $line, record => $record, maxitems => $maxitems &>
39 %    $line++;
40 % }
41 % $values {Statistics_Date} = "Totals";
42 % $values {Statistics_Created_Count} = $Totals{new};
43 % $values {Statistics_Resolved_Count} = $Totals{resolved};
44 % $values {Statistics_Deleted_Count} = $Totals{deleted};
45 <&   /RTx/Statistics/Elements/CollectionAsTable/Row, Format => \@BoldFormat, i => $line, record => $record, maxitems => $maxitems &>
46 </table>
47 </&>
48
49 <hr>
50
51 <BR />
52 <BR />
53
54 <%perl>
55 my $url = 'Elements/Chart?&x_labels=';
56 for (0..$#days) {
57   $url .= $days[$_] . "," ;
58 }
59 chop $url;
60 $url .= "&";
61
62 my @things = qw(new resolved deleted);
63 for my $th (0..$#things) {
64   $url .= "data".(1+$th)."=".(join ",", map { $counts[$_]{$things[$th]} } (0..6))."&";
65 }
66 chop $url;
67 $url .= '&set_legend=Created,Resolved,Deleted';
68 </%perl>
69
70 <& /RTx/Statistics/Elements/GraphBox, GraphURL => $url &>
71
72 % Statistics::DebugLog("queue name=" . $QueueObj->Id() . "\n");
73
74 <& /RTx/Statistics/Elements/ControlsAsTable/ControlBox, 
75          Title => "Change Queue", 
76          ShowSingleQueue => 1, Queue => $QueueObj->Id()
77  &>
78
79 </form>
80
81 % Statistics::DebugInit( $m );
82
83 <%ARGS>
84 $Queue => $Statistics::DayOfWeekQueue
85
86 $AllowSorting => undef
87 $Order => undef
88 $OrderBy => undef
89 $ShowNavigation => 1
90 $ShowHeader => 1
91 $Rows => 50
92 $Page => 1
93 $BaseURL => undef
94 </%ARGS>
95
96 <%INIT>
97 use GD::Graph;
98 use RTx::Statistics;
99 my @days = qw(Sun Mon Tue Wed Thu Fri Sat);
100 my $n = 0;
101 my @data = ([]);
102 my @msgs;
103 my @counts;
104 my %Totals = (
105   resolved => 0,
106   deleted => 0,
107   new => 0
108 );
109 my $QueryString = "Queue=$Queue";
110 my $maxitems = 4;
111 my %record;
112 my %values;
113 my $record = \%record;
114
115 $record{values} = \%values;
116
117 my $Format = qq{ Statistics_Date, 
118                  '__Statistics_Created_Count__/STYLE:text-align:right;', 
119                  '__Statistics_Resolved_Count__/STYLE:text-align:right;', 
120                  '__Statistics_Deleted_Count__/STYLE:text-align:right;' };
121 my $BoldFormat = qq{ '<B>__Statistics_Date__</B>', 
122                      '<B>__Statistics_Created_Count__</B>/STYLE:text-align:right;',
123                      '<B>__Statistics_Resolved_Count__</B>/STYLE:text-align:right;',
124                      '<B>__Statistics_Deleted_Count__</B>/STYLE:text-align:right;' };
125 my (@Format) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $Format);
126 my (@BoldFormat) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $BoldFormat);
127
128 my $QueueObj = new RT::Queue($session{'CurrentUser'});
129 $QueueObj->Load($Queue);
130 $RT::Logger->warning("Loaded queue $Queue, name=". $QueueObj->Name());
131
132 my $tix = new RT::Tickets($session{'CurrentUser'});
133 $tix->LimitQueue (VALUE => $Queue);
134 $tix->UnLimit;
135 if ($tix->Count) {
136     # Initialize the counters to zero, so that all the cells show up
137     foreach my $day (0..@days) {
138         $counts[$day]{resolved} = 0;
139         $counts[$day]{deleted} = 0;
140         $counts[$day]{new} = 0;
141     }
142     while (my $t = $tix->RT::SearchBuilder::Next) {  # BLOODY HACK
143         if($t->Status eq "resolved") {
144           $counts[(localtime($t->ResolvedObj->Unix))[6]]{resolved}++;
145           $Totals{resolved}++;
146         }
147         if($t->Status eq "deleted") {
148           $counts[(localtime($t->LastUpdatedObj->Unix))[6]]{deleted}++;
149           $Totals{deleted}++;
150         }
151         $counts[(localtime($t->CreatedObj->Unix))[6]]{new}++;
152         $Totals{new}++;
153     }
154 }
155 </%INIT>