combine ticket notification scrips, #15353
[freeside.git] / httemplate / search / timeworked.html
index 49173bd..e810822 100644 (file)
                    '',
                    '',
                  ],
-                 'html_foot' => sub {
-                                  '<BR><INPUT TYPE="button" VALUE="select all" onClick="setAll(true)">'.
-                                  '<INPUT TYPE="button" VALUE="unselect all" onClick="setAll(false)">'.
-                                  '<BR><INPUT TYPE="submit" NAME="action" VALUE="Assign to accounts"><BR>'.
-                                  '<SCRIPT TYPE="text/javascript">'.
-                                  '  function setAll(setTo) { '.
-                                  '    theForm = document.timeForm;'.
-                                  '    for (i=0,n=theForm.elements.length;i<n;i++)'.
-                                  '      if (theForm.elements[i].name.indexOf("transactionid") != -1)'.
-                                  '        theForm.elements[i].checked = setTo;'.
-                                  '  }'.
-                                  '</SCRIPT>';
-                                },
+                 'html_foot' => $html_foot,
              )
 
 %>
@@ -57,12 +45,14 @@ my @groupby = ();
 
 my $transactiontime = "
   CASE Transactions.Type WHEN 'Set'
-    THEN (TO_NUMBER(NewValue,'999999')-TO_NUMBER(OldValue, '999999')) * 60
+    THEN (  CASE WHEN NewValue = '' THEN 0 ELSE TO_NUMBER(NewValue,'999999') END
+           -TO_NUMBER(OldValue, '999999')
+          ) * 60
     ELSE TimeTaken*60
   END
 ";
 
-push @groupby, qw( transactions.type newvalue oldvalue timetaken );
+push @groupby, qw( Transactions.Type NewValue OldValue TimeTaken );
 
 my $appliedtimeclause = "COALESCE (SUM(acct_rt_transaction.seconds), 0)";
 
@@ -88,6 +78,7 @@ my $groupby = join(',', @groupby);
 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'
         )
@@ -95,6 +86,13 @@ my $where = "
 ";
     #AND $wheretimeleft
 
+my $str2time_sql = str2time_sql;
+my $closing      = str2time_sql_closing;
+
+my($begin, $end) = FS::UI::Web::parse_beginning_ending($cgi);
+$where .= " AND $str2time_sql Transactions.Created $closing >= $begin ".
+          " AND $str2time_sql Transactions.Created $closing <= $end ";
+
 my $query = "
   SELECT Tickets.id, Tickets.Subject,
          TO_CHAR(Transactions.Created, 'Dy Mon DD HH24:MI:SS YYYY'),
@@ -113,4 +111,22 @@ my $count_query = "SELECT COUNT(*) FROM Transactions $where";
 
 my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->[0]; } ];
 
+my $html_foot = qq'
+  <INPUT TYPE="hidden" NAME="begin" VALUE="$begin">
+  <INPUT TYPE="hidden" NAME="end"   VALUE="$end">
+  <BR>
+  <INPUT TYPE="button" VALUE="select all" onClick="setAll(true)">
+  <INPUT TYPE="button" VALUE="unselect all" onClick="setAll(false)">
+  <BR>
+  <INPUT TYPE="submit" NAME="action" VALUE="Assign to accounts"><BR>
+  <SCRIPT TYPE="text/javascript">
+    function setAll(setTo) {
+      theForm = document.timeForm;
+      for (i=0,n=theForm.elements.length;i<n;i++)
+        if (theForm.elements[i].name.indexOf("transactionid") != -1)
+          theForm.elements[i].checked = setTo;
+    }
+  </SCRIPT>
+';
+
 </%init>