quick list of area codes and a kludge to print DA numbers for all of them
[freeside.git] / httemplate / search / timeworked.html
index 858cc62..b72dd0e 100644 (file)
@@ -1,6 +1,5 @@
 <% include( 'elements/search.html',
                  'title'       => 'Time Worked',
-                 'menubar'     => [ 'Main menu' => $p, ],
                  'name'        => 'time',
                 'html_form'   => qq!<FORM NAME="timeForm" ACTION="${p}misc/timeworked.html" METHOD="POST">!,
                  'query'       => $query,
@@ -12,7 +11,7 @@
                                '', # checkbox column
                              ],
                  'fields' => [ sub { shift->[0] },
-                               sub { shift->[1] },
+                               sub { encode_entities(shift->[1]) },
                                sub { shift->[2] },
                                sub { my $seconds = shift->[3];
                                      (($seconds < 0) ? '-' : '') .
                                  qq!<INPUT NAME="seconds$id" TYPE="hidden" VALUE="$seconds">!;
                                },
                              ],
+                 'links' => [
+                   $link,
+                   $link,
+                   '',
+                   '',
+                   '',
+                 ],
                  'html_foot' => sub {
                                   '<BR><INPUT TYPE="button" VALUE="select all" onClick="setAll(true)">'.
                                   '<INPUT TYPE="button" VALUE="unselect all" onClick="setAll(false)">'.
@@ -49,26 +55,63 @@ die "access denied"
 
 my @groupby = ();
 
-my $transactiontime = "CASE transactions.type when 'Set' THEN (to_number(newvalue,'999999')-to_number(oldvalue, '999999')) * 60 ELSE timetaken*60 END";
-push @groupby, "transactions.type";
-push @groupby, "newvalue";
-push @groupby, "oldvalue";
-push @groupby, "timetaken";
+my $transactiontime = "
+  CASE Transactions.Type WHEN 'Set'
+    THEN (TO_NUMBER(NewValue,'999999')-TO_NUMBER(OldValue, '999999')) * 60
+    ELSE TimeTaken*60
+  END
+";
 
-my $appliedtimeclause = "coalesce (sum(acct_rt_transaction.seconds), 0)";
+push @groupby, qw( transactions.type newvalue oldvalue timetaken );
 
-my $appliedtimeselect = "SELECT sum(seconds) FROM acct_rt_transaction where transaction_id = transactions.id";
-push @groupby, "transactions.id";
+my $appliedtimeclause = "COALESCE (SUM(acct_rt_transaction.seconds), 0)";
 
-my $wheretimeleft = "($transactiontime != ($appliedtimeselect) OR ($appliedtimeselect) is NULL)";
+my $appliedtimeselect = "
+  COALESCE(
+            ( SELECT SUM(seconds) FROM acct_rt_transaction
+                WHERE transaction_id = Transactions.id
+            ),
+            0
+          )
+";
 
-push @groupby, "tickets.id";
-push @groupby, "tickets.subject";
-push @groupby, "transactions.created";
+push @groupby, "Transactions.id";
+
+my $wheretimeleft = "$transactiontime != $appliedtimeselect";
+
+push @groupby, "Tickets.id";
+push @groupby, "Tickets.Subject";
+push @groupby, "Transactions.Created";
 
 my $groupby = join(',', @groupby);
 
-my $query = "SELECT tickets.id,tickets.subject,to_char(transactions.created, 'Dy Mon DD HH24:MI:SS YYYY'),$transactiontime-$appliedtimeclause,transactions.id FROM transactions JOIN tickets ON transactions.objectid = tickets.id LEFT JOIN acct_rt_transaction on transactions.id = acct_rt_transaction.transaction_id WHERE objecttype='RT::Ticket' AND ((transactions.type='Set' AND field='TimeWorked') OR transactions.type='Comment' OR transactions.type='Correspond') AND ($wheretimeleft) GROUP BY $groupby ORDER BY transactions.created";
-my $count_query = "SELECT count(*) FROM transactions WHERE objecttype='RT::Ticket' AND ((transactions.type='Set' AND field='TimeWorked') OR transactions.type='Comment' OR transactions.type='Correspond') AND ($wheretimeleft)";
+my $where = "
+  WHERE ObjectType='RT::Ticket'
+    AND ( ( Transactions.Type='Set' AND Field='TimeWorked' )
+          OR Transactions.Type='Create'
+          OR Transactions.Type='Comment'
+          OR Transactions.Type='Correspond'
+        )
+    AND $wheretimeleft
+";
+    #AND $wheretimeleft
+
+my $query = "
+  SELECT Tickets.id, Tickets.Subject,
+         TO_CHAR(Transactions.Created, 'Dy Mon DD HH24:MI:SS YYYY'),
+         $transactiontime-$appliedtimeclause,
+         Transactions.id
+    FROM Transactions
+      JOIN Tickets ON Transactions.ObjectId = Tickets.id
+      LEFT JOIN acct_rt_transaction
+        ON Transactions.id = acct_rt_transaction.transaction_id
+    $where
+    GROUP BY $groupby
+    ORDER BY Transactions.Created
+";
+
+my $count_query = "SELECT COUNT(*) FROM Transactions $where";
+
+my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->[0]; } ];
 
 </%init>