[freeside-commits] freeside/FS/FS cust_pkg.pm,1.73.2.16,1.73.2.17

Jeff Finucane,420,, jeff at wavetail.420.am
Mon Jun 30 14:49:16 PDT 2008


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv2970/FS/FS

Modified Files:
      Tag: FREESIDE_1_7_BRANCH
	cust_pkg.pm 
Log Message:
backport reason handling

Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.73.2.16
retrieving revision 1.73.2.17
diff -u -d -r1.73.2.16 -r1.73.2.17
--- cust_pkg.pm	5 Jun 2008 10:34:20 -0000	1.73.2.16
+++ cust_pkg.pm	30 Jun 2008 21:49:13 -0000	1.73.2.17
@@ -1873,6 +1873,26 @@
   '';
 }
 
+=item insert_reason
+
+Associates this package with a (suspension or cancellation) reason (see
+L<FS::cust_pkg_reason>, possibly inserting a new reason on the fly (see
+L<FS::reason>).
+
+Available options are:
+
+=over 4
+
+=item reason - can be set to a cancellation reason (see L<FS:reason>), either a reasonnum of an existing reason, or passing a hashref will create a new reason.  The hashref should have the following keys: typenum - Reason type (see L<FS::reason_type>, reason - Text of the new reason.
+
+=item date
+
+=back
+
+If there is an error, returns the error, otherwise returns false.
+
+=cut
+
 =item bulk_change PKGPARTS_ARYREF, REMOVE_PKGNUMS_ARYREF [ RETURN_CUST_PKG_ARRAYREF ]
 
 PKGPARTS is a list of pkgparts specifying the the billing item definitions (see
@@ -1936,15 +1956,39 @@
 
   my $otaker = $FS::CurrentUser::CurrentUser->username;
 
+  my $reasonnum;
+  if ( $options{'reason'} =~ /^(\d+)$/ ) {
+
+    $reasonnum = $1;
+
+  } elsif ( ref($options{'reason'}) ) {
+
+    return 'Enter a new reason (or select an existing one)'
+      unless $options{'reason'}->{'reason'} !~ /^\s*$/;
+
+    my $reason = new FS::reason({
+      'reason_type' => $options{'reason'}->{'typenum'},
+      'reason'      => $options{'reason'}->{'reason'},
+    });
+    my $error = $reason->insert;
+    return $error if $error;
+
+    $reasonnum = $reason->reasonnum;
+
+  } else {
+    return "Unparsable reason: ". $options{'reason'};
+  }
+
   my $cust_pkg_reason =
     new FS::cust_pkg_reason({ 'pkgnum'    => $self->pkgnum,
-                              'reasonnum' => $options{'reason'}, 
+                              'reasonnum' => $reasonnum, 
 		              'otaker'    => $otaker,
 		              'date'      => $options{'date'}
 			                       ? $options{'date'}
 					       : time,
 	                    });
-  return $cust_pkg_reason->insert;
+
+  $cust_pkg_reason->insert;
 }
 
 =item set_usage USAGE_VALUE_HASHREF 



More information about the freeside-commits mailing list