integrate RTx::Statistics package, part of merging spiritone RT changes (#1661)
[freeside.git] / rt / html / Reports / Activity / ActivityDetail.html
1 <&|Elements/Wrapper, %ARGS, title => loc("Activity detail"),
2     path => "Reports/Activity/ActivityDetail.html",
3     &>
4
5 <& Elements/MiniPlot, data => \%counts &>
6
7 <table style="width: 100%">
8 <tr class="titlerow">
9 <th>Queue</th><th>Activity</th><th>Date</th><th>Time</th><th>Ticket #</th><th>User</th><th>Short description</th>
10 </tr>
11 % for my $item (@items) {
12 <tr>
13 <td><% $item->{queue} %></td>
14 <td><% $item->{status} %></td>
15 <td><% $item->{date} %></td>
16 <td><% $item->{time} %></td>
17 <td><% $item->{id} %></td>
18 <td><% $item->{actor} %></td>
19 <td><% $item->{notes} %></td>
20 </tr>
21 % }
22 </table>
23
24 </&>
25 <%args>
26 $query => 'id > 0'
27 $start => "2005/01/01"
28 $end   => "2006/01/01"
29 </%args>
30 <%init>
31
32
33 my $summary_tickets = RT::Tickets->new($session{'CurrentUser'});
34 $summary_tickets->FromSQL($query . " AND ( Updated >= '$start' AND Updated <= '$end')");
35 my %counts;
36 while (my $ticket = $summary_tickets->Next) {
37     my $txns = $ticket->Transactions;
38     $txns->Limit(FIELD => 'Created', OPERATOR => '>=', VALUE => $start);
39     $txns->Limit(FIELD => 'Created', OPERATOR => '<=', VALUE => $end);
40     # I think they really don't just want status changes
41     $txns->Limit(FIELD => 'Type', VALUE => 'Status', ENTRYAGGREGATOR => 'OR');
42     $txns->Limit(FIELD => 'Type', VALUE => 'Create');
43
44     while (my $txn = $txns->Next){
45         my $date = substr($txn->Created, 0, 10);
46         # we don't have data on the status of a new ticket, default to 'new'
47         $counts{$date}{$txn->NewValue || 'new'}++;
48     }
49 }
50
51
52 my $tickets = RT::Tickets->new($session{'CurrentUser'});
53 $tickets->FromSQL($query);
54 my @items;
55 while (my $ticket = $tickets->Next) {
56     my $txns = $ticket->Transactions;
57     $txns->Limit(FIELD => 'Created', OPERATOR => '>=', VALUE => $start);
58     $txns->Limit(FIELD => 'Created', OPERATOR => '<=', VALUE => $end);
59     # I think they really don't just want status changes
60     $txns->Limit(FIELD => 'Type', VALUE => 'Status', ENTRYAGGREGATOR => 'OR');
61     $txns->Limit(FIELD => 'Type', VALUE => 'Create');
62
63     while (my $txn = $txns->Next) {
64         push @items, { queue => $txn->TicketObj->QueueObj->Name,
65                        id => $txn->TicketObj->id,
66                        date => (split ' ', $txn->CreatedObj->ISO)[0],
67                        time => (split ' ', $txn->CreatedObj->ISO)[1],
68                        status => $txn->NewValue || 'new',
69                        actor => $txn->CreatorObj->Name,
70                        notes => ($txn->Content ne 'This transaction appears to have no content' ? substr($txn->Content, 0, 60) :  $txn->BriefDescription)
71                      };
72     }
73 }
74
75 @items = sort {
76            $a->{queue}    cmp $b->{'queue'}
77         || $a->{'status'} cmp $b->{'status'}
78         || $a->{'id'}     <=> $b->{'id'}
79         || $a->{'actor'}  cmp $b->{'actor'}
80         || $a->{'notes'}  <=> $b->{'notes'}
81 } @items;
82
83 </%init>