add some time-worked reporting
authorivan <ivan>
Tue, 4 Dec 2007 20:51:51 +0000 (20:51 +0000)
committerivan <ivan>
Tue, 4 Dec 2007 20:51:51 +0000 (20:51 +0000)
httemplate/elements/menu.html
httemplate/elements/select-otaker.html [new file with mode: 0644]
httemplate/elements/tr-select-otaker.html [new file with mode: 0644]
httemplate/search/elements/search.html
httemplate/search/report_cust_credit.html
httemplate/search/report_rt_transaction.html [new file with mode: 0644]
httemplate/search/rt_transaction.html [new file with mode: 0644]

index da8f580..b40b019 100644 (file)
@@ -162,6 +162,7 @@ $report_packages{'Advanced package reports'} =  [ $fsurl.'search/report_cust_pkg
 tie my %report_rating, 'Tie::IxHash',
   'RADIUS sessions' => [ $fsurl.'search/sqlradius.html', '' ],
   'Call Detail Records (CDRs)' => [ $fsurl.'search/report_cdr.html', '' ],
+  'Time worked' => [ $fsurl.'search/report_rt_transaction.html', '' ],
 ;
 
 tie my %report_bill_event, 'Tie::IxHash',
diff --git a/httemplate/elements/select-otaker.html b/httemplate/elements/select-otaker.html
new file mode 100644 (file)
index 0000000..2a689f3
--- /dev/null
@@ -0,0 +1,27 @@
+<SELECT NAME="otaker">
+
+% unless ( $opt{'multiple'} || $opt{'disable_empty'} ) {
+  <OPTION VALUE="">all</OPTION>
+% }
+
+% foreach my $otaker ( @{ $opt{'otakers'} } ) { 
+    <OPTION VALUE="<% $otaker %>"><% $otaker %></OPTION>
+% } 
+
+</SELECT>
+
+<%init>
+
+my %opt = @_;
+
+unless ( $opt{'otakers'} ) {
+
+  my $sth = dbh->prepare("SELECT username FROM access_user".
+                       " WHERE disabled = '' or disabled IS NULL")
+    or die dbh->errstr;
+  $sth->execute or die $sth->errstr;
+  $opt{'otakers'} = [ map { $_->[0] } @{$sth->fetchall_arrayref} ];
+
+}
+
+</%init>
diff --git a/httemplate/elements/tr-select-otaker.html b/httemplate/elements/tr-select-otaker.html
new file mode 100644 (file)
index 0000000..edf62dc
--- /dev/null
@@ -0,0 +1,10 @@
+<TR>
+  <TD ALIGN="right"><% $opt{'label'} || 'Employee: ' %></TD>
+  <TD><% include('select-otaker.html', %opt) %></TD>
+</TR>
+
+<%init>
+
+my %opt = @_;
+
+</%init>
index 7b1a515..5649c85 100644 (file)
@@ -45,7 +45,7 @@ Example:
     #required unless 'query' is an SQL query string (shouldn't be...)
     'count_query' => 'SELECT COUNT(*) FROM tablename',
    
-    'count_addl' => [], #additional count fields listref of sprintf strings
+    'count_addl' => [], #additional count fields listref of sprintf strings or coderefs
                         # [ $money_char.'%.2f total paid', ],
    
     #listref of column labels, <TH>
@@ -313,8 +313,14 @@ Example:
                 <BR>
 
 %               if ( $opt{'count_addl'} ) { 
-%                 my $n=0; foreach my $count ( @{$opt{'count_addl'}} ) { 
-                    <% sprintf( $count, $count_arrayref->[++$n] ) %><BR>
+%                 my $n=0;
+%                 foreach my $count ( @{$opt{'count_addl'}} ) { 
+%                   my $data = $count_arrayref->[++$n];
+%                   if ( ref($count) ) {
+                      <% &{ $count }( $data ) %>
+%                   } else {
+                      <% sprintf( $count, $data ) %><BR>
+%                   }
 %                 } 
 %               } 
               </FORM>
index 0490f43..be02e9f 100644 (file)
@@ -4,18 +4,12 @@
 <INPUT TYPE="hidden" NAME="magic" VALUE="_date">
 
 <TABLE>
-  <TR>
-    <TD ALIGN="right">Credits by employee: </TD>
-
-    <TD>
-      <SELECT NAME="otaker">
-        <OPTION VALUE="">all</OPTION>
-%       foreach my $otaker ( @otakers ) { 
-          <OPTION VALUE="<% $otaker %>"><% $otaker %></OPTION>
-%       } 
-      </SELECT>
-    </TD>
-  </TR>
+
+  <% include( '/elements/tr-select-otaker.html',
+                'label'   => 'Credits by employee: ',
+                'otakers' => \@otakers,
+            )
+  %>
 
   <% include( '/elements/tr-select-agent.html',
                  'curr_value' => scalar( $cgi->param('agentnum') ),
diff --git a/httemplate/search/report_rt_transaction.html b/httemplate/search/report_rt_transaction.html
new file mode 100644 (file)
index 0000000..89629e8
--- /dev/null
@@ -0,0 +1,22 @@
+<% include('/elements/header.html', 'Time worked report criteria' ) %>
+
+<FORM ACTION="rt_transaction.html" METHOD="GET">
+
+<TABLE>
+
+  <% include ( '/elements/tr-input-beginning_ending.html' ) %>
+
+  <% include ( '/elements/tr-select-otaker.html' ) %>
+
+</TABLE>
+
+<BR>
+<INPUT TYPE="submit" VALUE="Search">
+
+<% include('/elements/footer.html') %>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
+
+</%init>
diff --git a/httemplate/search/rt_transaction.html b/httemplate/search/rt_transaction.html
new file mode 100644 (file)
index 0000000..31ad10d
--- /dev/null
@@ -0,0 +1,96 @@
+<% include('elements/search.html',
+             'title'         => 'Time worked',
+             'name_singular' => 'transaction',
+             'query'         => $query,
+             'count_query'   => $count_query,
+             'count_addl'    => [ $format_seconds_sub, ],
+             'header'        => [ 'Ticket #',
+                                  'Ticket',
+                                  'Date',
+                                  'Time',
+                                ],
+             'fields'        => [ 'ticketid',
+                                  sub { encode_entities(shift->get('subject')) },
+                                  'created',
+                                  sub { my $seconds = shift->get('transaction_time');
+                                        &{ $format_seconds_sub }( $seconds );
+                                      },
+                                ],
+             'links'         => [
+                                  $link,
+                                  $link,
+                                  '',
+                                  '',
+                                ],
+          )
+%>
+<%once>
+
+my $format_seconds_sub = sub {
+  my $seconds = shift;
+  (($seconds < 0) ? '-' : '') . concise(duration($seconds));
+};
+
+</%once>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
+
+#some amount of false laziness w/timeworked.html...
+
+my $transactiontime = "
+  CASE transactions.type when 'Set'
+    THEN (to_number(newvalue,'999999')-to_number(oldvalue, '999999')) * 60
+    ELSE timetaken*60
+  END
+";
+
+my $join = 'JOIN Tickets ON Transactions.ObjectId = Tickets.Id '.
+           'JOIN Users   ON Transactions.Creator = Users.Id ';
+
+my $where = "
+  WHERE objecttype='RT::Ticket'
+    AND (    ( Transactions.Type = 'Set'
+               AND Transactions.Field = 'TimeWorked'
+               AND Transactions.NewValue != Transactions.OldValue )
+          OR ( ( Transactions.Type='Comment' OR Transactions.Type='Correspond' )
+               AND Transactions.TimeTaken > 0
+             )
+        )
+";
+#AND transaction_time != 0
+#AND $wheretimeleft
+
+my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
+# TIMESTAMP is Pg-specific... ?
+if ( $beginning > 0 ) {
+  $beginning = "TIMESTAMP '". time2str('%Y-%m-%d %X', $beginning). "'";
+  $where .= " AND Transactions.Created >= $beginning ";
+}
+if ( $ending < 4294967295 ) {
+  $ending =    "TIMESTAMP '". time2str('%Y-%m-%d %X', $ending).    "'";
+  $where .= " AND Transactions.Created <= $ending    ";
+}
+
+if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
+  $where .= " AND Users.name = '$1' ";
+}
+
+my $query = {
+  'select'    => "Transactions.*, Tickets.Id AS ticketid, Tickets.Subject, Users.name as otaker, $transactiontime AS transaction_time",
+  #'table'     => 'Transactions',
+  'table'     => 'transactions',
+  'addl_from' => $join.
+                 'LEFT JOIN acct_rt_transaction '.
+                 '  ON Transactions.Id = acct_rt_transaction.transaction_id',
+  'extra_sql' => $where,
+  'order by'  => 'ORDER BY Created',
+};
+
+my $count_query =
+  "SELECT COUNT(*), SUM($transactiontime) FROM Transactions $join $where";
+
+my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->get('id'); } ];
+
+</%init>