[Bps-public-commit] r11662 - RT-Extension-Reports/html/Reports/Types

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed Apr 9 09:57:46 EDT 2008


Author: sunnavy
Date: Wed Apr  9 09:57:45 2008
New Revision: 11662

Added:
   RT-Extension-Reports/html/Reports/Types/TimeWorked

Log:
added TimeWorked reports

Added: RT-Extension-Reports/html/Reports/Types/TimeWorked
==============================================================================
--- (empty file)
+++ RT-Extension-Reports/html/Reports/Types/TimeWorked	Wed Apr  9 09:57:45 2008
@@ -0,0 +1,217 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%# 
+%# COPYRIGHT:
+%#  
+%# This software is Copyright (c) 2007-2008 Best Practical Solutions, LLC 
+%#                                          <jesse at bestpractical.com>
+%# 
+%# (Except where explicitly superseded by other copyright notices)
+%# 
+%# 
+%# LICENSE:
+%# 
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%# 
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%# 
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/copyleft/gpl.html.
+%# 
+%# 
+%# CONTRIBUTION SUBMISSION POLICY:
+%# 
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%# 
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%# 
+%# END BPS TAGGED BLOCK }}}
+
+<& /Elements/Header, Title => $Title &>
+<& /Elements/Tabs, Title => $Title, current_toptab => 'Reports'  &>
+
+<form>
+<table align="center">
+<tr>
+<td><&|/l&>Start Date</&></td>
+<td><& /Elements/SelectDate, Name => 'StartDate', current => 0, Default =>
+$StartDate &>
+</tr>
+<tr>
+<td><&|/l&>End Date</&></td>
+<td><& /Elements/SelectDate, Name => 'EndDate', current => 0, Default =>
+$EndDate &>
+</tr>
+<tr>
+<td><&|/l&>Filter</&></td>
+<td><& /Reports/Elements/EditFilter, Content => $Filter, Name => 'Filter' &></td>
+</tr>
+<tr>
+<td><&|/l&>GroupBy</&></td>
+<td>
+<& /Reports/Elements/SelectGroupBy, Name => 'GroupBy', Default => $GroupBy &>
+</td>
+</tr>
+<tr>
+<td><&|/l&>OutType</&></td>
+<td>
+<& /Reports/Elements/SelectOutType, Name => 'OutType', Default => $OutType &>
+</td>
+</tr>
+<tr>
+<td />
+<td>
+<input type="hidden" name="Run" value=1>
+<& /Elements/Submit &>
+</td>
+</tr>
+<table>
+</form>
+
+<%INIT>
+
+my ( @headers, $num, @results, %data );
+
+if ( $Run ) {
+
+    if ( $GroupBy eq 'date' ) {
+        @headers = ( 'Date', 'Queue' );
+    }
+    else {
+        @headers = ( 'Queue', 'Date' );
+    }
+
+    push @headers, 'Number', 'TimeWorked', 'MeanTimeWorked';
+
+    my ( $start_date, $end_date );
+    $start_date = RT::Date->new( $session{CurrentUser} );
+    $end_date = RT::Date->new( $session{CurrentUser} );
+    $start_date->Set( Format => 'iso', Value => $StartDate . ' 00:00:00' );
+    $end_date->Set( Format => 'iso', Value => $EndDate . ' 00:00:00' );
+
+
+    $end_date->AddDay; # we want the date range to be inclusive
+    my $tickets = RT::Tickets->new( $session{CurrentUser} );
+
+    $tickets->UnLimit;
+
+    require RT::Extension::Reports::Filter;
+
+    TICKET:
+    while ( my $ticket = $tickets->Next ) {
+        if ( $Filter ) {
+            next TICKET unless RT::Extension::Reports::Filter::filter_ticket( Filter => $Filter, Ticket => $ticket );
+        }
+
+        my $tmp_date = RT::Date->new( $session{CurrentUser} );
+        $tmp_date->Set( Value => $start_date->Unix );
+
+        while ( $tmp_date->Unix < $end_date->Unix ) {
+            if ( $Filter ) {
+                    next TICKET unless RT::Extension::Reports::Filter::filter_ticket( Filter => $Filter, Ticket => $ticket, Date => $tmp_date, OnlyDate => 1 );
+            }
+
+            my $txns = $ticket->Transactions;
+            $txns->Limit( FIELD => 'Created', VALUE => $tmp_date->Date . 
+' 23:59:59', ENTRYAGGREGATOR => 'AND', OPERATOR => '>' );
+            $txns->Limit( FIELD => 'Type', VALUE => 'Set', ENTRYAGGREGATOR
+                    => 'AND' );
+            $txns->Limit( FIELD => 'Field', VALUE => 'TimeWorked', ENTRYAGGREGATOR => 'AND' );
+            my ( $id, $value );
+            $txns->OrderBy( FIELD => 'id' );
+            my $txn = $txns->First;
+            if ( $txn ) {  # we have set TimeWorked later
+                $id = $txn->id;
+                $value = $txn->OldValue;
+            }
+            else {
+                $value = $ticket->TimeWorked;
+            }
+
+            $txns = $ticket->Transactions;
+            $txns->Limit( FIELD => 'Created', VALUE => $tmp_date->Date . 
+' 23:59:59', ENTRYAGGREGATOR => 'AND', OPERATOR => '>' );
+            $txns->Limit( FIELD => 'TimeTaken', VALUE => 0, ENTRYAGGREGATOR
+                    => 'AND', OPERATOR => '>' );
+            if ( $id ) {
+                $txns->Limit( FIELD => 'id', VALUE => $id, ENTRYAGGREGATOR
+                    => 'AND', OPERATOR => '<' );
+            }
+            while ( my $txn = $txns->Next ) {
+                $value -= $txn->TimeTaken;
+            }
+
+            $data{$tmp_date->Date}{$ticket->QueueObj->Name}{Number}++;
+            $data{$tmp_date->Date}{$ticket->QueueObj->Name}{TimeWorked} += $value;
+
+            $tmp_date->AddDay;
+        }
+    }
+
+    for my $date ( keys %data ) {
+        for my $queue ( keys %{$data{$date}} ) {
+            $data{$date}{$queue}{MeanTimeWorked} = int
+$data{$date}{$queue}{TimeWorked}/$data{$date}{$queue}{Number};
+        }
+    }
+
+    for my $day ( sort keys %data ) {
+        if ( $GroupBy eq 'date' ) {
+            for my $queue ( sort keys %{$data{$day}} ) {
+                push @results, [ $day, $queue, map { $data{$day}{$queue}{$_} }
+                @headers[2 .. $#headers] ]; 
+            }
+        }
+        else {
+            for my $queue ( sort keys %{$data{$day}} ) {
+                push @results, [ $queue, $day, map { $data{$day}{$queue}{$_} }
+                @headers[2 .. $#headers] ]; 
+            }
+            @results = sort { $b->[0] cmp $a->[0] } @results;
+        }
+    }
+
+    $m->comp('/Reports/Elements/ShowResults', Headers => \@headers, Results
+=> \@results, Type => $OutType );
+    $m->abort;
+
+}
+else {
+    my $today = RT::Date->new($session{CurrentUser});
+    $today->SetToNow;
+    $today->AddDays( -1 );
+    $EndDate ||= $today->Date;
+    $StartDate ||= $today->Date;
+}
+
+</%INIT>
+
+<%ARGS>
+$Title => 'Time Worked'
+$StartDate => undef
+$EndDate => undef
+$Run => undef
+$Filter => undef
+$OutType => 'screen'
+$GroupBy => 'date'
+</%ARGS>
+



More information about the Bps-public-commit mailing list