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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Mar 3 08:43:25 EST 2008


Author: sunnavy
Date: Mon Mar  3 08:43:25 2008
New Revision: 10980

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

Log:
added General type reports

Added: RT-Extension-Reports/html/Reports/Types/General
==============================================================================
--- (empty file)
+++ RT-Extension-Reports/html/Reports/Types/General	Mon Mar  3 08:43:25 2008
@@ -0,0 +1,193 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%# 
+%# COPYRIGHT:
+%#  
+%# This software is Copyright (c) 1996-2007 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 /><td>
+<input type="hidden" name="Run" value=1>
+<input type="submit" name="screen" value="Submit" />
+<input type="submit" name="csv" value="CSV File" />
+<input type="submit" name="chart" value="Chart" />
+</td>
+</tr>
+<table>
+</form>
+
+<& /Reports/Elements/ShowResults, Headers => \@headers, Results => \@results &>
+
+
+<%INIT>
+
+my ( @headers, $num, @results, %data );
+
+
+if ( $Run ) {
+    @headers = qw/Date Queue Created New Open Stalled Resolved Rejected Deleted
+/;
+
+    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 ranage to be inclusive
+
+    my $tickets = RT::Tickets->new( $session{CurrentUser} );
+    $tickets->UnLimit;
+
+    TICKET:
+    while ( my $ticket = $tickets->Next ) {
+        require RT::Extension::Reports::Filter;
+        $Filter =~ s/\r\n/\n/g;
+        $Filter =~ s/\r/\n/g;
+        my @filters = split /\n+/, $Filter;
+        for ( @filters ) {
+            next unless /\S/;
+            s/^\s+//;
+            my ( $field, $op, $value ) = split /\s+/, $_;
+            next TICKET unless RT::Extension::Reports::Filter::filter( Ticket
+                    => $ticket, Value => $value, Operator => $op, Field =>
+                    $field );
+        }
+
+        my $tmp_date = RT::Date->new( $session{CurrentUser} );
+        $tmp_date->Set( Value => $start_date->Unix );
+
+        while ( $tmp_date->Unix < $end_date->Unix ) {
+
+            if ( $ticket->CreatedObj->Date le $tmp_date->Date ) {
+
+            if ( $ticket->CreatedObj->Date eq $tmp_date->Date ) {
+                $data{$ticket->CreatedObj->Date}{$ticket->QueueObj->Name}{Created}++; # Created
+            }
+            my $txns = $ticket->Transactions;
+            $txns->Limit( FIELD => 'Type', VALUE => 'Status', ENTRYAGGREGATOR
+                    => 'AND' );
+            $txns->Limit( FIELD => 'Created', VALUE => $tmp_date->Date . ' 23:59:59', ENTRYAGGREGATOR => 'AND', OPERATOR => '>=' );
+            $txns->OrderBy( FIELD => 'id' );
+            my $txn = $txns->First;
+            if ( $txn ) {   # we've changed tickets after $tmp_date's next day
+                $data{$tmp_date->Date}{$ticket->QueueObj->Name}{ucfirst $txn->OldValue}++;
+            }
+            else {
+                $data{$tmp_date->Date}{$ticket->QueueObj->Name}{ucfirst $ticket->Status}++;
+
+            }
+            }
+            $tmp_date->AddDay;
+        }
+    }
+
+    use Data::Dumper;
+    open my $fh, '>', '/tmp/t';
+    print $fh Dumper \%data;
+    close $fh;
+
+    for my $day ( sort keys %data ) {
+        if ( keys %{$data{$day}} == 0 ) {
+            push @results, [$day];
+        }
+        else {
+            for my $queue ( sort keys %{$data{$day}} ) {
+                push @results, [ $day, $queue, map { $data{$day}{$queue}{$_} }
+                @headers[2 .. $#headers] ]; 
+            }
+        }
+    }
+
+    if ( $ARGS{csv} ) {
+        $m->comp( '/Reports/Elements/ShowResults', Headers => \@headers,
+Results => \@results, Type => 'csv' );
+    }
+    elsif ( $ARGS{chart} ) {
+        for ( @results ) {
+            splice @$_, 0, 2, $_->[1] ? ( join ':', @$_[0 .. 1] ) : $_->[0];
+        }
+        splice @headers, 0, 2, $headers[0 .. 1 ];
+
+        $m->comp( '/Reports/Elements/ShowResults', Headers => \@headers,
+Results => \@results, Type => 'chart' );
+    }
+}
+else {
+    my $today = RT::Date->new($session{CurrentUser});
+    $today->SetToNow;
+    $EndDate ||= $today->Date;
+    $today->AddDays( -7 );
+    $StartDate ||= $today->Date;
+}
+
+</%INIT>
+
+<%ARGS>
+$Title => 'Number of Tickets'
+$StartDate => undef
+$EndDate => undef
+$Run => undef
+$Filter => undef
+$Type => 'simple'
+</%ARGS>
+



More information about the Bps-public-commit mailing list