%# BEGIN BPS TAGGED BLOCK {{{ %# %# COPYRIGHT: %# %# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC %# %# %# (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/licenses/old-licenses/gpl-2.0.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 }}} <%PERL> if ( $Constituency ){ $m->comp("SELF:Heading$ReportAs", Text => loc('RTIR Periodic Report for [_1]', $Constituency) ); } else{ $m->comp("SELF:Heading$ReportAs", Text => loc('RTIR Periodic Report') ); } $m->comp("SELF:TwoColumnsTable$ReportAs", Body => [ [ loc('Start date'), $rtstart->AsString ], [ loc('End date'), $rtend->AsString ], ] ); $m->comp("SELF:TwoColumnsTable$ReportAs", Title => loc('Incident Report Summary'), Body => [ [ loc('Outstanding reports at the beginning of this period'), scalar keys %$outstanding_pruned ], [ loc('Total new reports for this period'), scalar keys %$tix_created_pruned ], [ loc('Incident Reports resolved during this period'), scalar keys %$tix_resolved_pruned ], [ loc('Reports unresolved at the end of the period'), scalar keys %$tix_unresolved_pruned ], ], ); foreach my $incident_type( @functions ) { $m->comp("SELF:Heading$ReportAs", Level => 2, Text => $incident_type, ); my @table; foreach my $class (@classifications) { my $class_count = 0; $tix_created->GotoFirstItem(); my $filtered = $filter_by_incident_field->( $filter_by_incident_field->( $filter_by_incident_field->( $tix_created, 'Constituency', $Constituency ), 'Function', $incident_type, ), 'Classification', $class ne 'Unclassified'? $class: '', ); push @table, [ $class, scalar keys %{$filtered} ]; } $m->comp("SELF:TwoColumnsTable$ReportAs", Title => loc('Incident reports received'), Body => \@table, ); } $m->abort if $TextReport || $SpreadsheetReport; <%INIT> my $get_incident_field = sub { my $t = shift; my $field = shift; my $parent = RT::IR->Incidents( $t )->First; return undef unless $parent; return $parent->FirstCustomFieldValue( $field ); }; my $filter_by_incident_field = sub { my ($tickets, $field, $condition) = (@_); my $res = {}; unless ( ref $tickets eq 'HASH' ) { while ( my $t = $tickets->Next ) { $res->{ $t->Id } = $t } } else { %$res = %$tickets; } # No filter on Constituency if that feature isn't being used return $res if $field eq 'Constituency' and not $condition; while( my($id, $t) = each %$res ) { my $value = $get_incident_field->( $t, $field ); delete $res->{$id} if $value? $value ne $condition: $condition; } return $res; }; my $ReportAs = 'HTML'; $ReportAs = 'Text' if $TextReport; $ReportAs = 'TSV' if $SpreadsheetReport; my $start = ParseDateToISO( $StartDate ); my $end = ParseDateToISO( $EndDate ); my $rtstart = RT::Date->new( $session{'CurrentUser'} ); $rtstart->Set( Format => 'ISO', Value => $start ); my $rtend = RT::Date->new( $session{'CurrentUser'} ); $rtend->Set( Format => 'ISO', Value => $end ); # of new reports created during the period broken down by function my @functions; { my $cf = RT::CustomField->new( $session{'CurrentUser'} ); $cf->LoadByNameAndQueue( Queue => 'Incidents', Name => 'Function' ); my $values = $cf->Values; while ( my $value = $values->Next ) { push @functions, $value->Name; } } # of new reports created during the period broken down by classification my @classifications; { my $cf = RT::CustomField->new( $session{'CurrentUser'} ); $cf->LoadByNameAndQueue( Queue => 'Incidents', Name => 'Classification' ); my $values = $cf->Values; while ( my $value = $values->Next ) { push @classifications, $value->Name; } push @classifications, 'Unclassified'; } # of new reports outstanding at start of the period my $outstanding = RT::Tickets->new( $session{'CurrentUser'} ); $outstanding->FromSQL("Queue = 'Incident Reports' AND Created < '$start' AND (Resolved = '1970-01-01 00:00:01' OR Resolved > '$start')"); my $outstanding_pruned = $filter_by_incident_field->($outstanding, 'Constituency', $Constituency); # of new reports created during the period my $tix_created = RT::Tickets->new( $session{'CurrentUser'} ); $tix_created->FromSQL("Queue = 'Incident Reports' AND Created > '$start' AND Created < '$end'"); my $tix_created_pruned = $filter_by_incident_field->( $tix_created, 'Constituency', $Constituency ); # of new reports resolved/closed/deleted during the period # this means "number of reports created during the period that were # also closed during the period(or before which is insane but possible)" my $tix_resolved = RT::Tickets->new( $session{'CurrentUser'} ); $tix_resolved->FromSQL("Queue = 'Incident Reports' AND Created > '$start' AND Created < '$end' AND (Resolved > '1970-01-01 00:00:01' AND Resolved < '$end')"); my $tix_resolved_pruned = $filter_by_incident_field->($tix_resolved, 'Constituency', $Constituency); # of new reports oustanding at end of the period # this is "number of reports created during the period that were also # closed during the period" my $tix_unresolved = RT::Tickets->new( $session{'CurrentUser'} ); $tix_unresolved->FromSQL("Queue = 'Incident Reports' AND Created > '$start' AND Created < '$end' AND ( Resolved = '1970-01-01 00:00:01' OR Resolved > '$end' )"); my $tix_unresolved_pruned = $filter_by_incident_field->($tix_unresolved, 'Constituency', $Constituency); if ( $TextReport ) { $r->content_type('text/plain'); } elsif( $SpreadsheetReport ) { $r->content_type('application/vnd.ms-excel'); } <%ARGS> $StartDate => undef $EndDate => undef $Constituency => undef $HTMLReport => 1 $TextReport => !$HTMLReport $SpreadsheetReport => !($HTMLReport || $TextReport) <%METHOD TwoColumnsTableText> <%ARGS> $Title => undef $Body => [] % if ( $Title ) { <% $Title |n %> % } % foreach my $line( @$Body ) { <% sprintf "%-$max[0]s", $line->[0] |n %> <% $line->[1] |n %> % } <%INIT> my @max = (0, 0); foreach my $line( @$Body ) { for( my $col = 0; $col < @$line; $col++ ) { $max[$col] = length $line->[$col] if length $line->[$col] > $max[$col]; } } <%METHOD TwoColumnsTableTSV> <%ARGS> $Title => undef $Body => [] % if ( $Title ) { <% $Title |n %> % } % foreach my $line( @$Body ) { <% $line->[0] |n %> <% $line->[1] |n %> % } <%METHOD TwoColumnsTableHTML> <%ARGS> $Title => undef $Body => [] % if ( $Title ) { % } % foreach my $line( @$Body ) { % }
<% $Title %>
<% $line->[0] %><% $line->[1] %>
<%METHOD HeadingText> <%ARGS> $Text => undef <% $Text |n %> <%METHOD HeadingTSV> <%ARGS> $Text => undef <% $Text |n %> <%METHOD HeadingHTML> <%ARGS> $Text => undef $Level => 1 ><% $Text %>>