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
|
<% include('elements/search.html',
'title' => 'Time worked',
'name_singular' => 'transaction',
'query' => $query,
'count_query' => $count_query,
'count_addl' => [ $format_seconds_sub, ],
'header' => [ 'Ticket #',
'Ticket',
'Date',
'Time',
],
'fields' => [ 'ticketid',
sub { encode_entities(shift->get('subject')) },
'created',
sub { my $seconds = shift->get('transaction_time');
&{ $format_seconds_sub }( $seconds );
},
],
'links' => [
$link,
$link,
'',
'',
],
)
%>
<%once>
my $format_seconds_sub = sub {
my $seconds = shift;
(($seconds < 0) ? '-' : '') . concise(duration($seconds));
};
</%once>
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
#some amount of false laziness w/timeworked.html...
my $transactiontime = "
CASE transactions.type when 'Set'
THEN (to_number(newvalue,'999999')-to_number(oldvalue, '999999')) * 60
ELSE timetaken*60
END
";
my $join = 'JOIN Tickets ON Transactions.ObjectId = Tickets.Id '.
'JOIN Users ON Transactions.Creator = Users.Id ';
my $where = "
WHERE objecttype='RT::Ticket'
AND ( ( Transactions.Type = 'Set'
AND Transactions.Field = 'TimeWorked'
AND Transactions.NewValue != Transactions.OldValue )
OR ( ( Transactions.Type='Create' OR Transactions.Type='Comment' OR Transactions.Type='Correspond' )
AND Transactions.TimeTaken > 0
)
)
";
#AND transaction_time != 0
#AND $wheretimeleft
my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
# TIMESTAMP is Pg-specific... ?
if ( $beginning > 0 ) {
$beginning = "TIMESTAMP '". time2str('%Y-%m-%d %X', $beginning). "'";
$where .= " AND Transactions.Created >= $beginning ";
}
if ( $ending < 4294967295 ) {
$ending = "TIMESTAMP '". time2str('%Y-%m-%d %X', $ending). "'";
$where .= " AND Transactions.Created <= $ending ";
}
if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
$where .= " AND Users.name = '$1' ";
}
my $query = {
'select' => "Transactions.*, Tickets.Id AS ticketid, Tickets.Subject, Users.name as otaker, $transactiontime AS transaction_time",
#'table' => 'Transactions',
'table' => 'transactions',
'addl_from' => $join.
'LEFT JOIN acct_rt_transaction '.
' ON Transactions.Id = acct_rt_transaction.transaction_id',
'extra_sql' => $where,
'order by' => 'ORDER BY Created',
};
my $count_query =
"SELECT COUNT(*), SUM($transactiontime) FROM Transactions $join $where";
my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->get('id'); } ];
</%init>
|