1 <% include('elements/search.html',
2 'title' => 'Time worked',
3 'name_singular' => 'transaction',
5 'count_query' => $count_query,
6 'count_addl' => [ $format_seconds_sub, $format_seconds_sub, ],
7 'header' => [ 'Ticket #',
13 'fields' => [ 'ticketid',
14 sub { encode_entities(shift->get('subject')) },
16 sub { my $seconds = shift->get('transaction_time');
17 &{ $format_seconds_sub }( $seconds );
19 sub { my $seconds = shift->get('support');
20 &{ $format_seconds_sub }( $seconds );
34 my $format_seconds_sub = sub {
36 #(($seconds < 0) ? '-' : '') . concise(duration($seconds));
37 (($seconds < 0) ? '-' : '' ). int(abs($seconds)/3600)."h".sprintf("%02d",(abs(
38 $seconds)%3600)/60)."m";
45 unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
47 #some amount of false laziness w/timeworked.html...
49 my $transactiontime = "
50 CASE transactions.type when 'Set'
51 THEN (to_number(newvalue,'999999')-to_number(oldvalue, '999999')) * 60
56 my $join = 'JOIN Tickets ON Transactions.ObjectId = Tickets.Id '.
57 'JOIN Users ON Transactions.Creator = Users.Id '; #.
58 # 'LEFT JOIN acct_rt_transaction '.
59 # ' ON Transactions.Id = acct_rt_transaction.transaction_id';
61 WHERE objecttype='RT::Ticket'
62 AND ( ( Transactions.Type = 'Set'
63 AND Transactions.Field = 'TimeWorked'
64 AND Transactions.NewValue != Transactions.OldValue )
65 OR ( ( Transactions.Type='Create' OR Transactions.Type='Comment' OR Transactions.Type='Correspond' )
66 AND Transactions.TimeTaken > 0
70 #AND transaction_time != 0
75 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
76 # TIMESTAMP is Pg-specific... ?
77 if ( $beginning > 0 ) {
78 $beginning = "TIMESTAMP '". time2str('%Y-%m-%d %X', $beginning). "'";
79 $where .= " AND Transactions.Created >= $beginning ";
81 if ( $ending < 4294967295 ) {
82 $ending = "TIMESTAMP '". time2str('%Y-%m-%d %X', $ending). "'";
83 $where .= " AND Transactions.Created <= $ending ";
86 if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
87 $where .= " AND Users.name = '$1' ";
90 if ( $cgi->param('ticketid') =~ /^\s*(\d+)\s*$/ ) {
91 $where .= " AND Tickets.Id = $1";
94 if ( $cgi->param('svcnum') =~ /^\s*(\d+)\s*$/ ) {
95 $where .= " AND EXISTS( SELECT 1 FROM acct_rt_transaction WHERE acct_rt_transaction.transaction_id = Transactions.id AND svcnum = $1 )";
96 $support = "AND svcnum = $1";
99 my $support_time = "( SELECT SUM(support) from acct_rt_transaction where transaction_id = Transactions.id $support )";
102 'select' => join(', ',
104 'Tickets.Id AS ticketid',
106 'Users.name AS otaker',
107 "$transactiontime AS transaction_time",
108 "$support_time AS support",
110 'table' => 'transactions', #Pg-ism
111 #'table' => 'Transactions',
112 'addl_from' => $join,
113 'extra_sql' => $where,
114 'order by' => 'ORDER BY Created',
118 #"SELECT COUNT(*), SUM($transactiontime), SUM(acct_rt_transaction.support) FROM Transactions $join $where";
120 SUM($transactiontime),
122 FROM Transactions $join $where";
124 my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->get('ticketid'); } ];