%# 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

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};

<%$incident_type%>

<%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 ""); $class_count++; } <%perl> }
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; }

<%$service_level%>

<& Elements/SLASummary, class_tix => $mytix, outstanding => $myoutstanding, service_level => $service_level, start => $rtstart, end => $rtend &> <%perl> } } <%init> 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 ($fid, $types, $classifications, $sla_levels, $CustomFields); my $Queue = new RT::Queue($session{'CurrentUser'}); $Queue->Load('Incidents'); $CustomFields = $Queue->CustomFields(); $CustomFields->{'find_disabled_rows'} = 1; my $i = 0; while (my $CustomField = $CustomFields->Next()) { if ($CustomField->Name eq '_RTIR_Function') { $fid = $CustomField->Id; my $values = $CustomField->Values; while (my $value = $values->Next) { $types->{$i} = $value->Name; $i++; } } } # of new reports created during the period broken down by classification $Queue = new RT::Queue($session{'CurrentUser'}); $Queue->Load('Incidents'); $CustomFields = $Queue->CustomFields(); $CustomFields->{'find_disabled_rows'} = 1; $i = 0; while (my $CustomField = $CustomFields->Next()) { if ($CustomField->Name eq '_RTIR_Classification') { $fid = $CustomField->Id; my $values = $CustomField->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 $Queue->Load('Incident Reports'); $CustomFields = $Queue->CustomFields(); $CustomFields->{'find_disabled_rows'} = 1; while (my $CustomField = $CustomFields->Next()) { if ($CustomField->Name eq '_RTIR_SLA') { $fid = $CustomField->Id; my $values = $CustomField->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 $incidents = $t->MemberOf; my $parent; $incidents->GotoFirstItem(); while (my $link = $incidents->Next) { my $incident = $link->TargetObj; if ($incident->QueueObj->Name eq 'Incidents') { $parent = $incident; last; } } if ( $parent ) { return $parent->FirstCustomFieldValue($field); } else { return undef; } } <%args> $mystart => undef $myend => undef $Constituency => undef