%# BEGIN LICENSE BLOCK %# %# Copyright (c) 1996-2003 Jesse Vincent %# %# (Except where explictly superceded by other copyright notices) %# %# 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. %# %# %# Unless otherwise specified, all modifications, corrections or %# extensions to this work which alter its source code become the %# property of Best Practical Solutions, LLC when submitted for %# inclusion in the work. %# %# %# END LICENSE BLOCK % if ($tabbed) { RTIR Periodic Report for <%$Constituency%> Start date:;<%$rtstart->AsString%> End date:;<%$rtend->AsString%> Incident Report Summary (including unlinked Incident Reports) Outstanding reports at the beginning of this period;<% scalar keys %$outstanding_pruned %> Total new reports for this period;<% scalar keys %$tix_created_pruned %> Incident Reports resolved during this period;<% scalar keys %$tix_resolved_pruned %> Reports unresolved at the end of the period;<% scalar keys %$tix_unresolved_pruned %> % } else {

RTIR Periodic Report for <%$Constituency%>

Start date: <%$rtstart->AsString%>
End date: <%$rtend->AsString%>
Incident Report Summary (including unlinked Incident Reports)
Outstanding reports at the beginning of this period <% scalar keys %$outstanding_pruned %>
Total new reports for this period <% scalar keys %$tix_created_pruned %>
Incident Reports resolved during this period <% scalar keys %$tix_resolved_pruned %>
Reports unresolved at the end of the period <% scalar keys %$tix_unresolved_pruned %>
% } <%perl> foreach my $key (sort keys %$types) { my $incident_type = $types->{$key}; % if ($tabbed) { <%$incident_type%> % } else {

<%$incident_type%>

% } % if ($tabbed) { Incident reports received % } else { % } <%perl> foreach my $key (sort keys %$classifications) { my $class = $classifications->{$key}; my $class_count = 0; $tix_created->GotoFirstItem(); while ( my $t = $tix_created->Next) { my $value = get_incident_field( $t, '_RTIR_Constituency'); next if ($value ne $Constituency); $value = get_incident_field( $t, '_RTIR_Classification'); next if ($class ne 'Unclassified' && $value ne $class); next if ($class eq 'Unclassified' && $value ne ""); $value = get_incident_field( $t, '_RTIR_Function'); next if ($value ne $incident_type); $class_count++; } % if ($tabbed) { <%$class%>;<%$class_count%> % } else { % } <%perl> } % if ($tabbed) { % } else {
Incident reports received
<%$class%> <%$class_count%>
% } <%perl> foreach my $service_level (keys %$sla_levels) { my $class_tix = RT::Tickets->new( $session{'CurrentUser'} ); $class_tix->LimitQueue(VALUE => 'Incident Reports'); $class_tix->LimitCreated(VALUE => $start, OPERATOR => ">"); $class_tix->LimitCreated(VALUE => $end, OPERATOR => "<"); $class_tix->LimitCustomField(CUSTOMFIELD => $fid, VALUE => $service_level); my $mytix = {}; while ( my $t = $class_tix->Next) { my $value = get_incident_field( $t, '_RTIR_Constituency'); next if ($value ne $Constituency); $value = get_incident_field( $t, '_RTIR_Function'); next unless ($value eq $incident_type); $mytix->{$t->Id} = $t; } my $myoutstanding = {}; while ( my $t = $outstanding->Next) { my $value = get_incident_field( $t, '_RTIR_Constituency'); next if ($value ne $Constituency); $value = get_incident_field( $t, '_RTIR_Function'); next unless ($value eq $incident_type); $myoutstanding->{$t->Id} = $t; } % if ($tabbed) { <%$service_level%> % } else {

<%$service_level%>

% } % if ($tabbed) { <& Elements/SLASummaryText, class_tix => $mytix, outstanding => $myoutstanding, service_level => $service_level, start => $rtstart, end => $rtend &> % } else { <& Elements/SLASummary, class_tix => $mytix, outstanding => $myoutstanding, service_level => $service_level, start => $rtstart, end => $rtend &> % } <%perl> } } if ($tabbed) { $m->abort(); } <%init> my $tabbed = 0; if ($ARGS{TextReport}) { $tabbed = 1; } my $start = ParseDateToISO($mystart); my $end = ParseDateToISO($myend); $Constituency = $ARGS{$Constituency} if $Constituency; # of new reports created during the period broken down by function my ($cf, $values, $fid, $types, $classifications, $sla_levels); my $i = 0; $cf = RT::CustomField->new($session{'CurrentUser'}); $cf->LoadByNameAndQueue(Queue => 'Incidents', Name => '_RTIR_Function'); $values = $cf->Values; while (my $value = $values->Next) { $types->{$i} = $value->Name; $i++; } # of new reports created during the period broken down by classification $i = 0; $cf = RT::CustomField->new($session{'CurrentUser'}); $cf->LoadByNameAndQueue(Queue => 'Incidents', Name => '_RTIR_Classification'); $values = $cf->Values; while (my $value = $values->Next) { $classifications->{$i} = $value->Name; $i++; } $classifications->{$i} = 'Unclassified'; # of new reports created during the period broken down by SLA level $cf = RT::CustomField->new($session{'CurrentUser'}); $cf->LoadByNameAndQueue(Queue => 'Incident Reports', Name => '_RTIR_SLA'); $fid = $cf->Id; $values = $cf->Values; while (my $value = $values->Next) { $sla_levels->{$value->Name} = $value->Description; } my $rtstart = new RT::Date($RT::SystemUser); $rtstart->Set( Format => 'ISO', Value => $start ); my $rtend = new RT::Date($RT::SystemUser); $rtend->Set( Format => 'ISO', Value => $end ); # 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:00' OR Resolved > '$start')"); my $outstanding_pruned = {}; while ( my $t = $outstanding->Next) { my $value = get_incident_field( $t, '_RTIR_Constituency'); next unless ($value eq $Constituency || !defined $value); $outstanding_pruned->{$t->Id} = $t; } # 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 = {}; while ( my $t = $tix_created->Next) { my $value = get_incident_field( $t, '_RTIR_Constituency'); next unless ($value eq $Constituency || !defined $value); $tix_created_pruned->{$t->Id} = $t; } # 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" 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:00' AND Resolved <'$end')"); my $tix_resolved_pruned = {}; while ( my $t = $tix_resolved->Next) { my $value = get_incident_field( $t, '_RTIR_Constituency'); next unless ($value eq $Constituency || !defined $value); $tix_resolved_pruned->{$t->Id} = $t; } # 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:00' OR Resolved>'$end')"); my $tix_unresolved_pruned = {}; while ( my $t = $tix_unresolved->Next) { my $value = get_incident_field( $t, '_RTIR_Constituency'); next unless ($value eq $Constituency || !defined $value); $tix_unresolved_pruned->{$t->Id} = $t; } sub get_incident_field { my $t = shift; my $field = shift; # find the parent incident my $query = "Queue = 'Incidents' AND HasMember = " . $t->Id; my $incidents = new RT::Tickets($session{'CurrentUser'}); $incidents->FromSQL($query); my $parent; $incidents->GotoFirstItem(); while (my $incident = $incidents->Next) { if ($incident->QueueObj->Name eq 'Incidents') { $parent = $incident; last; } } if ( $parent ) { return $parent->FirstCustomFieldValue($field); } else { return undef; } } if ($tabbed) { $r->content_type('text/plain'); } <%args> $mystart => undef $myend => undef $Constituency => undef