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 );
21 'sort_fields' => [ 'ticketid',
36 my $format_seconds_sub = sub {
38 #(($seconds < 0) ? '-' : '') . concise(duration($seconds));
39 (($seconds < 0) ? '-' : '' ). int(abs($seconds)/3600)."h".sprintf("%02d",(abs(
40 $seconds)%3600)/60)."m";
46 #all sorts of false laziness w/rt_transaction.html
49 unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
51 #some amount of false laziness w/timeworked.html...
53 my $transactiontime = "
54 CASE transactions.type when 'Set'
55 THEN (to_number(newvalue,'999999')-to_number(oldvalue, '999999')) * 60
60 my $join = 'JOIN Users ON Transactions.Creator = Users.Id '; #.
61 # 'LEFT JOIN acct_rt_transaction '.
62 # ' ON Transactions.Id = acct_rt_transaction.transaction_id';
65 WHERE objecttype='RT::Ticket'
66 AND Transactions.ObjectId = Tickets.Id
67 AND ( ( Transactions.Type = 'Set'
68 AND Transactions.Field = 'TimeWorked'
69 AND Transactions.NewValue != Transactions.OldValue )
70 OR ( ( Transactions.Type='Create' OR Transactions.Type='Comment' OR Transactions.Type='Correspond' )
71 AND Transactions.TimeTaken > 0
75 #AND transaction_time != 0
80 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
81 # TIMESTAMP is Pg-specific... ?
82 if ( $beginning > 0 ) {
83 $beginning = "TIMESTAMP '". time2str('%Y-%m-%d %X', $beginning). "'";
84 $twhere .= " AND Transactions.Created >= $beginning ";
86 if ( $ending < 4294967295 ) {
87 $ending = "TIMESTAMP '". time2str('%Y-%m-%d %X', $ending). "'";
88 $twhere .= " AND Transactions.Created <= $ending ";
91 if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
92 $twhere .= " AND Users.name = '$1' ";
95 if ( $cgi->param('svcnum') =~ /^\s*(\d+)\s*$/ ) {
96 $twhere .= " AND EXISTS( SELECT 1 FROM acct_rt_transaction WHERE acct_rt_transaction.transaction_id = Transactions.id AND svcnum = $1 )";
97 $support = "AND svcnum = $1";
100 my $transactions = "FROM Transactions $join $twhere";
102 my $where = "WHERE EXISTS ( SELECT 1 $transactions )";
104 my $transaction_time = "( SELECT SUM($transactiontime) $transactions )";
105 my $support_time = "( SELECT SUM(support) FROM acct_rt_transaction LEFT JOIN Transactions ON ( transaction_id = Id ) $twhere $support )";
108 'select' => join(', ',
109 'Tickets.Id AS ticketid',
111 "$transaction_time AS transaction_time",
112 "$support_time AS support",
114 'table' => 'tickets', #Pg-ism
115 #'table' => 'Tickets',
116 'addl_from' => '', #$join,
117 'extra_sql' => $where,
118 'order by' => 'ORDER BY Created',
122 #"SELECT COUNT(*), SUM($transactiontime), SUM(acct_rt_transaction.support) FROM Transactions $join $where";
123 #"SELECT COUNT(*), ( SUM($transactiontime) $transactions ) FROM Tickets"; # $join $where";
125 SUM( $transaction_time ),
127 FROM Tickets $where"; # $join $where";
129 my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->get('ticketid'); } ];