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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Apr 7 05:07:13 EDT 2008


Author: sunnavy
Date: Mon Apr  7 05:07:01 2008
New Revision: 11611

Modified:
   RT-Extension-Reports/html/Reports/Types/TicketsMoved

Log:
tickets moved reports

Modified: RT-Extension-Reports/html/Reports/Types/TicketsMoved
==============================================================================
--- RT-Extension-Reports/html/Reports/Types/TicketsMoved	(original)
+++ RT-Extension-Reports/html/Reports/Types/TicketsMoved	Mon Apr  7 05:07:01 2008
@@ -46,13 +46,164 @@
 %# 
 %# 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="in" <% $Type eq 'in' ?
+'checked="checked"' : ()%> >Moved In</input>
+<input type="radio" name="Type" value="out" <% $Type eq 'out' ?
+'checked="checked"' : ()%>>Moved Out</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><&|/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 $tickets = RT::Tickets->new( $RT::SystemUser );
+
+my ( @headers, $num, @results, %data );
+
+
+if ( $Run ) {
+
+    if ( $GroupBy eq 'date' ) {
+        @headers = ( 'Date', 'Queue' );
+    }
+    else {
+        @headers = ( 'Queue', 'Date' );
+    }
+
+    push @headers, 'Number';
+
+    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;
+
+    TICKET:
+    while ( my $ticket = $tickets->Next ) {
+        require RT::Extension::Reports::Filter;
+        $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 ) {
+
+            my $txns = $ticket->Transactions;
+            $txns->Limit( FIELD => 'Type', VALUE => 'Set', ENTRYAGGREGATOR
+                    => 'AND' );
+            $txns->Limit( FIELD => 'Field', VALUE => 'Queue', ENTRYAGGREGATOR
+                    => 'AND' );
+            $txns->Limit( FIELD => 'Created', VALUE => $tmp_date->Date . ' 00:00:00', ENTRYAGGREGATOR => 'AND', OPERATOR => '>=' );
+            $txns->Limit( FIELD => 'Created', VALUE => $tmp_date->Date . ' 23:59:59', ENTRYAGGREGATOR => 'AND', OPERATOR => '<=' );
+            $txns->OrderBy( FIELD => 'id' );
+            while ( my $txn = $txns->Next ) {
+                my ( $from, $to );
+                my $queue = RT::Queue->new( $session{CurrentUser} );
+                if ( $Type eq 'in' ) {
+                    $queue->Load( $txn->NewValue );
+                }
+                else {
+                    $queue->Load( $txn->OldValue );
+                }
+                $data{$tmp_date->Date}{$queue->Name}{Number}++;
+            }
+            $tmp_date->AddDay;
+        }
+    }
+
+    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 => 'Number of Tickets'
+$Title => 'Number of Moved Tickets'
+$StartDate => undef
+$EndDate => undef
+$Run => undef
+$Filter => undef
+$Type => 'in'
+$OutType => 'screen'
+$GroupBy => 'date'
 </%ARGS>
 



More information about the Bps-public-commit mailing list