This commit was generated by cvs2svn to compensate for changes in r6255,
[freeside.git] / httemplate / search / rt_transaction.html
1 <% include('elements/search.html',
2              'title'         => 'Time worked',
3              'name_singular' => 'transaction',
4              'query'         => $query,
5              'count_query'   => $count_query,
6              'count_addl'    => [ $format_seconds_sub, ],
7              'header'        => [ 'Ticket #',
8                                   'Ticket',
9                                   'Date',
10                                   'Time',
11                                 ],
12              'fields'        => [ 'ticketid',
13                                   sub { encode_entities(shift->get('subject')) },
14                                   'created',
15                                   sub { my $seconds = shift->get('transaction_time');
16                                         &{ $format_seconds_sub }( $seconds );
17                                       },
18                                 ],
19              'links'         => [
20                                   $link,
21                                   $link,
22                                   '',
23                                   '',
24                                 ],
25           )
26 %>
27 <%once>
28
29 my $format_seconds_sub = sub {
30   my $seconds = shift;
31   (($seconds < 0) ? '-' : '') . concise(duration($seconds));
32 };
33
34 </%once>
35 <%init>
36
37 die "access denied"
38   unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
39
40 #some amount of false laziness w/timeworked.html...
41
42 my $transactiontime = "
43   CASE transactions.type when 'Set'
44     THEN (to_number(newvalue,'999999')-to_number(oldvalue, '999999')) * 60
45     ELSE timetaken*60
46   END
47 ";
48
49 my $join = 'JOIN Tickets ON Transactions.ObjectId = Tickets.Id '.
50            'JOIN Users   ON Transactions.Creator = Users.Id ';
51
52 my $where = "
53   WHERE objecttype='RT::Ticket'
54     AND (    ( Transactions.Type = 'Set'
55                AND Transactions.Field = 'TimeWorked'
56                AND Transactions.NewValue != Transactions.OldValue )
57           OR ( ( Transactions.Type='Create' OR Transactions.Type='Comment' OR Transactions.Type='Correspond' )
58                AND Transactions.TimeTaken > 0
59              )
60         )
61 ";
62 #AND transaction_time != 0
63 #AND $wheretimeleft
64
65 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
66 # TIMESTAMP is Pg-specific... ?
67 if ( $beginning > 0 ) {
68   $beginning = "TIMESTAMP '". time2str('%Y-%m-%d %X', $beginning). "'";
69   $where .= " AND Transactions.Created >= $beginning ";
70 }
71 if ( $ending < 4294967295 ) {
72   $ending =    "TIMESTAMP '". time2str('%Y-%m-%d %X', $ending).    "'";
73   $where .= " AND Transactions.Created <= $ending    ";
74 }
75
76 if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
77   $where .= " AND Users.name = '$1' ";
78 }
79
80 my $query = {
81   'select'    => "Transactions.*, Tickets.Id AS ticketid, Tickets.Subject, Users.name as otaker, $transactiontime AS transaction_time",
82   #'table'     => 'Transactions',
83   'table'     => 'transactions',
84   'addl_from' => $join.
85                  'LEFT JOIN acct_rt_transaction '.
86                  '  ON Transactions.Id = acct_rt_transaction.transaction_id',
87   'extra_sql' => $where,
88   'order by'  => 'ORDER BY Created',
89 };
90
91 my $count_query =
92   "SELECT COUNT(*), SUM($transactiontime) FROM Transactions $join $where";
93
94 my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->get('id'); } ];
95
96 </%init>