1 <& elements/search.html,
2 'title' => 'Time worked',
3 'name_singular' => 'transaction',
5 'count_query' => $count_query,
6 'count_addl' => [ $format_seconds_sub,
7 $applied_time ? $format_seconds_sub : () ],
8 'header' => [ 'Ticket #',
12 $applied_time ? 'Applied' : (),
14 'fields' => [ 'ticketid',
15 sub { encode_entities(shift->get('subject')) },
17 sub { my $seconds = shift->get('transaction_time');
18 &{ $format_seconds_sub }( $seconds );
21 sub { my $seconds = shift->get('applied_time');
22 &{ $format_seconds_sub }( $seconds );
35 my $format_seconds_sub = sub {
37 #(($seconds < 0) ? '-' : '') . concise(duration($seconds));
38 (($seconds < 0) ? '-' : '' ). int(abs($seconds)/3600)."h".sprintf("%02d",(abs(
39 $seconds)%3600)/60)."m";
46 unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
48 local $FS::Record::nowarn_classload = 1;
49 #some amount of false laziness w/timeworked.html...
53 'Tickets.Id AS ticketid',
55 'Users.name AS otaker',
57 my @select_total = ( 'COUNT(*)' );
59 my ($transaction_time, $applied_time);
60 my $join = 'JOIN Tickets ON Transactions.ObjectId = Tickets.Id '.
61 'JOIN Users ON Transactions.Creator = Users.Id '.
63 SELECT DISTINCT ON (ObjectId)
65 FROM ObjectCustomFieldValues
67 ON (ObjectCustomFieldValues.CustomField = CustomFields.Id)
68 WHERE CustomFields.Name = 'TimeType'
69 AND ObjectCustomFieldValues.ObjectType = 'RT::Ticket'
70 AND ObjectCustomFieldValues.Disabled = 0
71 ORDER BY ObjectId ASC, ObjectCustomFieldValues.LastUpdated DESC
72 ) AS ocfv_TimeType ON (Tickets.Id = ocfv_TimeType.ObjectId)
75 my $where = "WHERE Transactions.ObjectType = 'RT::Ticket'";
77 # the intrinsic TimeWorked/TimeTaken fields
78 $transaction_time = "CASE Transactions.Type when 'Set'
79 THEN (to_number(NewValue,'999999')-to_number(OldValue, '999999')) * 60
84 if ( $cgi->param('svcnum') =~ /^\s*(\d+)\s*$/ ) {
85 $where .= " AND EXISTS( SELECT 1 FROM acct_rt_transaction WHERE acct_rt_transaction.transaction_id = Transactions.id AND svcnum = $1 )";
86 $applied = "AND svcnum = $1";
89 $applied_time = "( SELECT SUM(support) from acct_rt_transaction where transaction_id = Transactions.id $applied )";
92 AND ( ( Transactions.Type = 'Set'
93 AND Transactions.Field = 'TimeWorked'
94 AND Transactions.NewValue != Transactions.OldValue )
95 OR ( ( Transactions.Type='Create' OR Transactions.Type='Comment' OR Transactions.Type='Correspond' OR Transactions.Type='Touch' )
96 AND Transactions.TimeTaken > 0
101 if ( $cgi->param('category') =~ /^(\w+)$/ ) {
102 $where .= " AND ocfv_TimeType.Content = '$1'";
105 push @select, "($transaction_time) AS transaction_time";
106 push @select_total, "SUM($transaction_time)";
107 if ( $applied_time ) {
108 push @select, "($applied_time) AS applied_time";
109 push @select_total, "SUM($applied_time)";
112 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
113 # TIMESTAMP is Pg-specific... ?
114 if ( $beginning > 0 ) {
115 $beginning = "TIMESTAMP '". time2str('%Y-%m-%d %X', $beginning). "'";
116 $where .= " AND Transactions.Created >= $beginning ";
118 if ( $ending < 4294967295 ) {
119 $ending = "TIMESTAMP '". time2str('%Y-%m-%d %X', $ending). "'";
120 $where .= " AND Transactions.Created <= $ending ";
123 if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
124 $where .= " AND Users.name = '$1' ";
127 if ( $cgi->param('ticketid') =~ /^\s*(\d+)\s*$/ ) {
128 $where .= " AND Tickets.Id = $1";
132 'select' => join(', ', @select),
133 'table' => 'transactions', #Pg-ism
134 #'table' => 'Transactions',
135 'addl_from' => $join,
136 'extra_sql' => $where,
137 'order by' => 'ORDER BY Created',
140 my $count_query = 'SELECT '.join(', ', @select_total). " FROM Transactions $join $where";
142 my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->get('ticketid'); } ];