1 <% include('elements/search.html',
2 'title' => 'Time worked summary',
3 'name_singular' => 'ticket',
5 'count_query' => $count_query,
6 'count_addl' => [ $format_seconds_sub, $format_seconds_sub, ],
7 'header' => [ 'Ticket #',
12 'fields' => [ 'ticketid',
13 sub { encode_entities(shift->get('subject')) },
14 sub { my $seconds = shift->get('transaction_time');
15 &{ $format_seconds_sub }( $seconds );
17 sub { my $seconds = shift->get('support');
18 &{ $format_seconds_sub }( $seconds );
31 my $format_seconds_sub = sub {
33 #(($seconds < 0) ? '-' : '') . concise(duration($seconds));
34 (($seconds < 0) ? '-' : '' ). int(abs($seconds)/3600)."h".sprintf("%02d",(abs(
35 $seconds)%3600)/60)."m";
41 #all sorts of false laziness w/rt_transaction.html
44 unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
46 #some amount of false laziness w/timeworked.html...
48 my $transactiontime = "
49 CASE transactions.type when 'Set'
50 THEN (to_number(newvalue,'999999')-to_number(oldvalue, '999999')) * 60
55 my $join = 'JOIN Users ON Transactions.Creator = Users.Id '; #.
56 # 'LEFT JOIN acct_rt_transaction '.
57 # ' ON Transactions.Id = acct_rt_transaction.transaction_id';
60 WHERE objecttype='RT::Ticket'
61 AND Transactions.ObjectId = Tickets.Id
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 $twhere .= " AND Transactions.Created >= $beginning ";
81 if ( $ending < 4294967295 ) {
82 $ending = "TIMESTAMP '". time2str('%Y-%m-%d %X', $ending). "'";
83 $twhere .= " AND Transactions.Created <= $ending ";
86 if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
87 $twhere .= " AND Users.name = '$1' ";
90 if ( $cgi->param('svcnum') =~ /^\s*(\d+)\s*$/ ) {
91 $twhere .= " AND EXISTS( SELECT 1 FROM acct_rt_transaction WHERE acct_rt_transaction.transaction_id = Transactions.id AND svcnum = $1 )";
92 $support = "AND svcnum = $1";
95 my $transactions = "FROM Transactions $join $twhere";
97 my $where = "WHERE EXISTS ( SELECT 1 $transactions )";
99 my $transaction_time = "( SELECT SUM($transactiontime) $transactions )";
100 my $support_time = "( SELECT SUM(support) FROM acct_rt_transaction LEFT JOIN Transactions ON ( transaction_id = Id ) $twhere $support )";
103 'select' => join(', ',
104 'Tickets.Id AS ticketid',
106 "$transaction_time AS transaction_time",
107 "$support_time AS support",
109 'table' => 'tickets', #Pg-ism
110 #'table' => 'Tickets',
111 'addl_from' => '', #$join,
112 'extra_sql' => $where,
113 'order by' => 'ORDER BY Created',
117 #"SELECT COUNT(*), SUM($transactiontime), SUM(acct_rt_transaction.support) FROM Transactions $join $where";
118 #"SELECT COUNT(*), ( SUM($transactiontime) $transactions ) FROM Tickets"; # $join $where";
120 SUM( $transaction_time ),
122 FROM Tickets $where"; # $join $where";
124 my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->get('ticketid'); } ];