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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Mar 4 04:33:27 EST 2008


Author: sunnavy
Date: Tue Mar  4 04:33:26 2008
New Revision: 10987

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

Log:
added ActiveOrInactive type

Added: RT-Extension-Reports/html/Reports/Types/ActiveOrInactive
==============================================================================
--- (empty file)
+++ RT-Extension-Reports/html/Reports/Types/ActiveOrInactive	Tue Mar  4 04:33:26 2008
@@ -0,0 +1,218 @@
+%# 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&>Type</&></td>
+<td>
+<input type="radio" name="Type" value="active" <% $Type eq 'active' ?
+'checked="checked"' : ()%> >Active</input>
+<input type="radio" name="Type" value="inactive" <% $Type eq 'inactive' ?
+'checked="checked"' : ()%>>Inactive</input>
+</td>
+</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 = ( 'Date', 'Queue', ucfirst $Type, '0-7', '8-14', '15-30', '31+' );
+
+    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 ) {
+            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;
+            my $status;
+            if ( $txn ) {   # we've changed tickets after $tmp_date's next day
+                $status = $txn->OldValue;
+            }
+            else {
+                $status = $ticket->Status;
+            }
+            if ( $Type eq 'active' && $ticket->QueueObj->IsActiveStatus(
+$status ) || $Type eq 'inactive' && $ticket->QueueObj->IsInactiveStatus( $status ) ) {
+            $data{$tmp_date->Date}{$ticket->QueueObj->Name}{ucfirst $Type}++;
+                my $age;
+                if ( $Type eq 'active' ) {
+                        $age = int( ($tmp_date->Unix - $ticket->CreatedObj->Unix)/3600/24) + 1;
+                }
+                else {
+                    $age = int( ($ticket->ResolvedObj->Unix - $ticket->CreatedObj->Unix)/3600/24) + 1;
+                }
+
+                $age = 1 if $age < 1; # make it 1 day if less than 1 day
+
+                if ( $age <= 7 ) {
+                    $data{$tmp_date->Date}{$ticket->QueueObj->Name}{'0-7'}++;
+                }
+                elsif ( $age <= 14 ) {
+                    $data{$tmp_date->Date}{$ticket->QueueObj->Name}{'8-14'}++;
+                }
+                elsif ( $age <= 30 ) {
+                    $data{$tmp_date->Date}{$ticket->QueueObj->Name}{'15-30'}++;
+                }
+                else {
+                    $data{$tmp_date->Date}{$ticket->QueueObj->Name}{'31+'}++;
+                }
+            }
+        }
+            $tmp_date->AddDay;
+        }
+    }
+
+    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( -1 );
+    $StartDate ||= $today->Date;
+}
+
+</%INIT>
+
+<%ARGS>
+$Title => 'Number of Tickets'
+$StartDate => undef
+$EndDate => undef
+$Run => undef
+$Filter => undef
+$Type   => 'active'
+</%ARGS>
+



More information about the Bps-public-commit mailing list