[Rt-commit] [svn] r1562 - in rtir/branches/1.1-TESTING: html/RTIR html/RTIR/Incident html/RTIR/Reporting/Elements lib/RT lib/RT/Action

leira at pallas.eruditorum.org leira at pallas.eruditorum.org
Sat Sep 25 02:08:50 EDT 2004


Author: leira
Date: Sat Sep 25 02:08:49 2004
New Revision: 1562

Added:
   rtir/branches/1.1-TESTING/lib/RT/IR.pm
Modified:
   rtir/branches/1.1-TESTING/html/RTIR/Create.html
   rtir/branches/1.1-TESTING/html/RTIR/Display.html
   rtir/branches/1.1-TESTING/html/RTIR/Incident/Reply.html
   rtir/branches/1.1-TESTING/html/RTIR/Reporting/Elements/SLASummary
   rtir/branches/1.1-TESTING/html/RTIR/Reporting/Elements/SLASummaryText
   rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetDueBySLA.pm
   rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetDueCorrespond.pm
   rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetStartsByBizHours.pm
Log:
Use Business::SLA module.


Modified: rtir/branches/1.1-TESTING/html/RTIR/Create.html
==============================================================================
--- rtir/branches/1.1-TESTING/html/RTIR/Create.html	(original)
+++ rtir/branches/1.1-TESTING/html/RTIR/Create.html	Sat Sep 25 02:08:49 2004
@@ -433,18 +433,9 @@
 }
 
 my $sla;
-my $date = RT::Date->new($RT::SystemUser);
-$date->SetToNow;
-use Business::Hours;
-my $bizhours = new Business::Hours;
-if ($RT::BusinessHours) {
-  $bizhours->business_hours(%$RT::BusinessHours);
-}
-# see if we're in business hours or not
-if ($bizhours->first_after($date->Unix) != $date->Unix) {
-  $sla = $RT::_RTIR_SLA_outofhours_default;
-} else {
-  $sla = $RT::_RTIR_SLA_inhours_default;
+if ($Queue eq 'Incident Reports') {
+    use RT::IR;
+    $sla = RT::IR::DefaultSLA();
 }
 
 </%INIT>

Modified: rtir/branches/1.1-TESTING/html/RTIR/Display.html
==============================================================================
--- rtir/branches/1.1-TESTING/html/RTIR/Display.html	(original)
+++ rtir/branches/1.1-TESTING/html/RTIR/Display.html	Sat Sep 25 02:08:49 2004
@@ -236,11 +236,11 @@
       my $date = RT::Date->new($RT::SystemUser);
       $date->SetToNow;
       $date->AddDays($RT::OverdueAfter);
-      use Business::Hours;
-      my $bizhours = new Business::Hours;
-      if ($RT::BusinessHours) {
-          $bizhours->business_hours(%$RT::BusinessHours);
-      }
+
+      # get business hours
+      use RT::IR;
+      my $bizhours = RT::IR::BusinessHours();
+
       my $due = $bizhours->first_after($date->Unix);
       $date->Set(Format => 'unix', Value => $due);
       $ARGS{'Due_Date'} = $date->AsString;

Modified: rtir/branches/1.1-TESTING/html/RTIR/Incident/Reply.html
==============================================================================
--- rtir/branches/1.1-TESTING/html/RTIR/Incident/Reply.html	(original)
+++ rtir/branches/1.1-TESTING/html/RTIR/Incident/Reply.html	Sat Sep 25 02:08:49 2004
@@ -195,11 +195,11 @@
       $date = RT::Date->new($RT::SystemUser);
       $date->SetToNow;
       $date->AddDays($RT::OverdueAfter);
-      use Business::Hours;
-      my $bizhours = new Business::Hours;
-      if ($RT::BusinessHours) {
-	  $bizhours->business_hours(%$RT::BusinessHours);
-      }
+
+      # get business hours
+      use RT::IR;
+      my $bizhours = RT::IR::BusinessHours();
+
       my $due = $bizhours->first_after($date->Unix);
       $date->Set(Format => 'unix', Value => $due);
       $ARGS{'Due_Date'} = $date->AsString;

Modified: rtir/branches/1.1-TESTING/html/RTIR/Reporting/Elements/SLASummary
==============================================================================
--- rtir/branches/1.1-TESTING/html/RTIR/Reporting/Elements/SLASummary	(original)
+++ rtir/branches/1.1-TESTING/html/RTIR/Reporting/Elements/SLASummary	Sat Sep 25 02:08:49 2004
@@ -82,12 +82,9 @@
     #
     if ($t->StartsObj->Unix > 0 && $t->StartedObj->Unix > 0) {
 	# Get a Business::Hours object for the period in question
-	use Business::Hours;
-	
-	my $bizhours = Business::Hours->new();
-	if ($RT::BusinessHours) {
-	    $bizhours->business_hours(%$RT::BusinessHours);
-	}
+	use RT::IR;
+	my $bizhours = RT::IR::BusinessHours();
+
 	my $started_time;
 	if ($t->StartsObj->Unix < $t->StartedObj->Unix) {
 	    $bizhours->for_timespan( Start => $t->StartsObj->Unix, 

Modified: rtir/branches/1.1-TESTING/html/RTIR/Reporting/Elements/SLASummaryText
==============================================================================
--- rtir/branches/1.1-TESTING/html/RTIR/Reporting/Elements/SLASummaryText	(original)
+++ rtir/branches/1.1-TESTING/html/RTIR/Reporting/Elements/SLASummaryText	Sat Sep 25 02:08:49 2004
@@ -52,12 +52,9 @@
     #
     if ($t->StartsObj->Unix > 0 && $t->StartedObj->Unix > 0) {
 	# Get a Business::Hours object for the period in question
-	use Business::Hours;
-	
-	my $bizhours = Business::Hours->new();
-	if ($RT::BusinessHours) {
-	    $bizhours->business_hours(%$RT::BusinessHours);
-	}
+	use RT::IR;
+	my $bizhours = RT::IR::BusinessHours();
+
 	my $started_time;
 	if ($t->StartsObj->Unix < $t->StartedObj->Unix) {
 	    $bizhours->for_timespan( Start => $t->StartsObj->Unix, 

Modified: rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetDueBySLA.pm
==============================================================================
--- rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetDueBySLA.pm	(original)
+++ rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetDueBySLA.pm	Sat Sep 25 02:08:49 2004
@@ -74,44 +74,35 @@
 
 sub Commit {
     my $self = shift;
+    use RT::IR;
 
-    my $date = RT::Date->new($RT::SystemUser);
-    $date->SetToNow;
-    use Business::Hours;
-    my $bizhours = new Business::Hours;
-    if ($RT::BusinessHours) {
-	$bizhours->business_hours(%$RT::BusinessHours);
-    }
+    # TODO: return if it isn't an Incident Report
 
-    my $sla;
-    if ($self->TicketObj->FirstCustomFieldValue('_RTIR_SLA')) {
-	$sla = $self->TicketObj->FirstCustomFieldValue('_RTIR_SLA');
-    } elsif ($bizhours->first_after($date->Unix) != $date->Unix) {
-	$sla = "Full service: out of hours";
-    } else {
-	$sla = "Full service";
-    }
+    # now that we know the SLA, set the value of the CF
+    if (! $self->TicketObj->FirstCustomFieldValue('_RTIR_SLA')) {
+	my $cf = RT::CustomField->new($self->CurrentUser);
 
-    # now that we know the SLA, set the value
-    my $cf = RT::CustomField->new($self->TransactionObj->CurrentUser);
-    $cf->LoadByNameAndQueue(Queue => $self->TicketObj->QueueObj->Id, Name => '_RTIR_SLA');
-    unless ($cf->Id) { 
-	return(1);
-    }
-    $self->TicketObj->AddCustomFieldValue(Field => $cf->id, Value => $sla);
+	$cf->LoadByNameAndQueue(Queue => $self->QueueObj->Id, Name => '_RTIR_SLA');
+	unless ($cf->Id) { 
+	    return(1);
+	}
 
-    # look up how many minutes to add for this SLA
-    my $addminutes = $RT::SLA->{$sla};
+	my $SLAObj = RT::IR::SLAInit();
+	my $sla = $SLAObj->SLA(time());
 
-    # find the next business time
-    my $starts = $bizhours->first_after($date->Unix);
-    $date->Set(Format => 'unix', Value => $starts);
+	$self->AddCustomFieldValue(Field => $cf->id, 
+				   Value => $sla);
 
-    # add the SLA minutes to that
-    my $due = $bizhours->add_seconds($date->Unix, $addminutes * 60);
-    $date->Set(Format => 'unix', Value => $due);
+    }
 
     # set the due date
+    my $SLAObj = RT::IR::SLAInit();
+
+    # TODO: specify a start date, but default to now
+    my $due = $SLAObj->Due(time(), $SLAObj->SLA(time()));
+
+    my $date = RT::Date->new($RT::SystemUser);
+    $date->Set(Format => 'unix', Value => $due);
     $self->TicketObj->SetDue($date->ISO);
 
     return 1;

Modified: rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetDueCorrespond.pm
==============================================================================
--- rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetDueCorrespond.pm	(original)
+++ rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetDueCorrespond.pm	Sat Sep 25 02:08:49 2004
@@ -75,7 +75,8 @@
 sub Commit {
     my $self = shift;
 
-    my $bizhours = $self->GetBusinessHours();
+    use RT::IR;
+    my $bizhours = RT::IR::BusinessHours();
 
     my $date = RT::Date->new($RT::SystemUser);
     $date->SetToNow;
@@ -92,18 +93,6 @@
 
 # }}}
 
-sub GetBusinessHours {
-    my $self = shift;
-
-    use Business::Hours;
-    my $bizhours = new Business::Hours;
-    if ($RT::BusinessHours) {
-	$bizhours->business_hours(%$RT::BusinessHours);
-    }
-
-    return $bizhours;
-}
-
 eval "require RT::Action::RTIR_SetDueCorrespond_Vendor";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RTIR_SetDueCorrespond_Vendor.pm});
 eval "require RT::Action::RTIR_SetDueCorrespond_Local";

Modified: rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetStartsByBizHours.pm
==============================================================================
--- rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetStartsByBizHours.pm	(original)
+++ rtir/branches/1.1-TESTING/lib/RT/Action/RTIR_SetStartsByBizHours.pm	Sat Sep 25 02:08:49 2004
@@ -82,7 +82,8 @@
     my $date = RT::Date->new($RT::SystemUser);
     $date->SetToNow;
 
-    my $bizhours = $self->GetBusinessHours();
+    use RT::IR;
+    my $bizhours = RT::IR::BusinessHours();
 
     my $starts = $bizhours->first_after($date->Unix);
     $date->Set(Format => 'unix', Value => $starts);
@@ -93,18 +94,6 @@
 
 # }}}
 
-sub GetBusinessHours {
-    my $self = shift;
-
-    use Business::Hours;
-    my $bizhours = new Business::Hours;
-    if ($RT::BusinessHours) {
-	$bizhours->business_hours(%$RT::BusinessHours);
-    }
-
-    return $bizhours;
-}
-
 eval "require RT::Action::RTIR_SetStartsByBizHours_Vendor";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RTIR_SetStartsByBizHours_Vendor.pm});
 eval "require RT::Action::RTIR_SetStartsByBizHours_Local";

Added: rtir/branches/1.1-TESTING/lib/RT/IR.pm
==============================================================================
--- (empty file)
+++ rtir/branches/1.1-TESTING/lib/RT/IR.pm	Sat Sep 25 02:08:49 2004
@@ -0,0 +1,90 @@
+# {{{ BEGIN BPS TAGGED BLOCK
+# 
+# COPYRIGHT:
+#  
+# This software is Copyright (c) 1996-2004 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+# 
+# 
+# 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
+#
+package RT::IR;
+
+sub BusinessHours {
+
+    use Business::Hours;
+
+    my $bizhours = new Business::Hours;
+    if ($RT::BusinessHours) {
+	$bizhours->business_hours(%$RT::BusinessHours);
+    }
+
+    return $bizhours;
+}
+
+sub DefaultSLA {
+
+    my $sla;
+    my $SLAObj = SLAInit();
+    $sla = $SLAObj->SLA(time());
+
+    return $sla;
+
+}
+
+sub SLAInit {
+
+    use Business::SLA;
+    my $SLAObj = new Business::SLA;
+
+    my $bh = RT::IR::BusinessHours();
+    $SLAObj->SetInHoursDefault($RT::_RTIR_SLA_inhours_default);
+    $SLAObj->SetOutOfHoursDefault($RT::_RTIR_SLA_outofhours_default);
+
+    $SLAObj->SetBusinessHours($bh);
+
+    foreach my $key (keys %$RT::SLA) {
+	$SLAObj->Add($key, ( BusinessMinutes =>  $RT::SLA->{$key} ));
+    }
+
+    return $SLAObj;
+
+}
+
+1;


More information about the Rt-commit mailing list