1 <% include( 'elements/search.html',
2 'title' => 'Time Worked',
4 'html_form' => qq!<FORM NAME="timeForm" ACTION="${p}misc/timeworked.html" METHOD="POST">!,
6 'count_query' => $count_query,
13 'fields' => [ sub { shift->[0] },
14 sub { encode_entities(shift->[1]) },
16 sub { my $seconds = shift->[3];
17 (($seconds < 0) ? '-' : '') .
18 concise(duration($seconds));
22 my $seconds = $row->[3];
24 qq!<INPUT NAME="transactionid$id" TYPE="checkbox" VALUE="1">!.
25 qq!<INPUT NAME="seconds$id" TYPE="hidden" VALUE="$seconds">!;
35 'html_foot' => $html_foot,
42 unless $FS::CurrentUser::CurrentUser->access_right('Time queue');
46 my $transactiontime = "
47 CASE Transactions.Type WHEN 'Set'
48 THEN ( CASE WHEN NewValue = '' THEN 0 ELSE TO_NUMBER(NewValue,'999999') END
49 -TO_NUMBER(OldValue, '999999')
55 push @groupby, qw( Transactions.Type NewValue OldValue TimeTaken );
57 my $appliedtimeclause = "COALESCE (SUM(acct_rt_transaction.seconds), 0)";
59 my $appliedtimeselect = "
61 ( SELECT SUM(seconds) FROM acct_rt_transaction
62 WHERE transaction_id = Transactions.id
68 push @groupby, "Transactions.id";
70 my $wheretimeleft = "$transactiontime != $appliedtimeselect";
72 push @groupby, "Tickets.id";
73 push @groupby, "Tickets.Subject";
74 push @groupby, "Transactions.Created";
76 my $groupby = join(',', @groupby);
79 WHERE ObjectType='RT::Ticket'
80 AND ( ( Transactions.Type='Set' AND Field='TimeWorked' )
81 OR Transactions.Type IN ( 'Create', 'Comment', 'Correspond', 'Touch' )
87 my $str2time_sql = str2time_sql;
88 my $closing = str2time_sql_closing;
90 my($begin, $end) = FS::UI::Web::parse_beginning_ending($cgi);
91 $where .= " AND $str2time_sql Transactions.Created $closing >= $begin ".
92 " AND $str2time_sql Transactions.Created $closing <= $end ";
95 SELECT Tickets.id, Tickets.Subject,
96 TO_CHAR(Transactions.Created, 'Dy Mon DD HH24:MI:SS YYYY'),
97 $transactiontime-$appliedtimeclause,
100 JOIN Tickets ON Transactions.ObjectId = Tickets.id
101 LEFT JOIN acct_rt_transaction
102 ON Transactions.id = acct_rt_transaction.transaction_id
105 ORDER BY Transactions.Created
108 my $count_query = "SELECT COUNT(*) FROM Transactions $where";
110 my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->[0]; } ];
113 <INPUT TYPE="hidden" NAME="begin" VALUE="$begin">
114 <INPUT TYPE="hidden" NAME="end" VALUE="$end">
116 <INPUT TYPE="button" VALUE="select all" onClick="setAll(true)">
117 <INPUT TYPE="button" VALUE="unselect all" onClick="setAll(false)">
119 <INPUT TYPE="submit" NAME="action" VALUE="Assign to accounts"><BR>
120 <SCRIPT TYPE="text/javascript">
121 function setAll(setTo) {
122 theForm = document.timeForm;
123 for (i=0,n=theForm.elements.length;i<n;i++)
124 if (theForm.elements[i].name.indexOf("transactionid") != -1)
125 theForm.elements[i].checked = setTo;