[freeside-commits] freeside/FS/FS cust_bill.pm, 1.156, 1.157 cust_main.pm, 1.247, 1.248 cust_pkg.pm, 1.65, 1.66 part_bill_event.pm, 1.25, 1.26

Jeff Finucane,420,, jeff at wavetail.420.am
Sun Oct 22 21:21:05 PDT 2006


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv31107/FS/FS

Modified Files:
	cust_bill.pm cust_main.pm cust_pkg.pm part_bill_event.pm 
Log Message:
events should attach reasons

Index: part_bill_event.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_bill_event.pm,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- part_bill_event.pm	18 Oct 2006 23:07:06 -0000	1.25
+++ part_bill_event.pm	23 Oct 2006 04:21:02 -0000	1.26
@@ -187,8 +187,10 @@
     }
   }
 
-  my $reasonr = qsearchs('reason', {'reasonnum' => $self->reason});
-  return "Unknown reason" unless $reasonr;
+  if ($self->reason){
+    my $reasonr = qsearchs('reason', {'reasonnum' => $self->reason});
+    return "Unknown reason" unless $reasonr;
+  }
 
   $self->SUPER::check;
 }

Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.156
retrieving revision 1.157
diff -u -d -r1.156 -r1.157
--- cust_bill.pm	8 Oct 2006 08:17:06 -0000	1.156
+++ cust_bill.pm	23 Oct 2006 04:21:02 -0000	1.157
@@ -294,7 +294,7 @@
   if ( $cust_main->total_owed_date($self->_date) < $amount ) {
     return ();
   } else {
-    $cust_main->suspend;
+    $cust_main->suspend(@_);
   }
 }
 

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.247
retrieving revision 1.248
diff -u -d -r1.247 -r1.248
--- cust_main.pm	12 Oct 2006 09:42:27 -0000	1.247
+++ cust_main.pm	23 Oct 2006 04:21:02 -0000	1.248
@@ -1642,7 +1642,7 @@
 
 sub suspend {
   my $self = shift;
-  grep { $_->suspend } $self->unsuspended_pkgs;
+  grep { $_->suspend(@_) } $self->unsuspended_pkgs;
 }
 
 =item suspend_if_pkgpart PKGPART [ , PKGPART ... ]
@@ -1656,8 +1656,14 @@
 
 sub suspend_if_pkgpart {
   my $self = shift;
-  my @pkgparts = @_;
-  grep { $_->suspend }
+  my (@pkgparts, %opt);
+  if (ref($_[0]) eq 'HASH'){
+    @pkgparts = @{$_[0]{pkgparts}};
+    %opt      = %{$_[0]};
+  }else{
+    @pkgparts = @_;
+  }
+  grep { $_->suspend(%opt) }
     grep { my $pkgpart = $_->pkgpart; grep { $pkgpart eq $_ } @pkgparts }
       $self->unsuspended_pkgs;
 }
@@ -1673,8 +1679,14 @@
 
 sub suspend_unless_pkgpart {
   my $self = shift;
-  my @pkgparts = @_;
-  grep { $_->suspend }
+  my (@pkgparts, %opt);
+  if (ref($_[0]) eq 'HASH'){
+    @pkgparts = @{$_[0]{pkgparts}};
+    %opt      = %{$_[0]};
+  }else{
+    @pkgparts = @_;
+  }
+  grep { $_->suspend(%opt) }
     grep { my $pkgpart = $_->pkgpart; ! grep { $pkgpart eq $_ } @pkgparts }
       $self->unsuspended_pkgs;
 }

Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- cust_pkg.pm	12 Aug 2006 06:45:14 -0000	1.65
+++ cust_pkg.pm	23 Oct 2006 04:21:02 -0000	1.66
@@ -15,6 +15,7 @@
 use FS::cust_bill_pkg;
 use FS::h_cust_svc;
 use FS::reg_code;
+use FS::cust_pkg_reason;
 
 # need to 'use' these instead of 'require' in sub { cancel, suspend, unsuspend,
 # setup }
@@ -270,7 +271,7 @@
 =cut
 
 sub replace {
-  my( $new, $old ) = ( shift, shift );
+  my( $new, $old, %options ) = @_;
 
   #return "Can't (yet?) change pkgpart!" if $old->pkgpart != $new->pkgpart;
   return "Can't change otaker!" if $old->otaker ne $new->otaker;
@@ -295,6 +296,16 @@
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
+  if ($options{'reason'} && $new->expire && $old->expire ne $new->expire) {
+    my $error = $new->insert_reason( 'reason' => $options{'reason'},
+                                     'date'      => $new->expire,
+		                    );
+    if ( $error ) {
+      dbh->rollback if $oldAutoCommit;
+      return "Error inserting cust_pkg_reason: $error";
+    }
+  }
+
   #save off and freeze RADIUS attributes for any associated svc_acct records
   my @svc_acct = ();
   if ( $old->part_pkg->is_prepaid || $new->part_pkg->is_prepaid ) {
@@ -431,6 +442,14 @@
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
+  if ($options{'reason'}) {
+    $error = $self->insert_reason( 'reason' => $options{'reason'} );
+    if ( $error ) {
+      dbh->rollback if $oldAutoCommit;
+      return "Error inserting cust_pkg_reason: $error";
+    }
+  }
+
   my %svc;
   foreach my $cust_svc (
       qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
@@ -503,7 +522,7 @@
 =cut
 
 sub suspend {
-  my $self = shift;
+  my( $self, %options ) = @_;
   my $error ;
 
   local $SIG{HUP} = 'IGNORE';
@@ -517,6 +536,14 @@
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
+  if ($options{'reason'}) {
+    $error = $self->insert_reason( 'reason' => $options{'reason'} );
+    if ( $error ) {
+      dbh->rollback if $oldAutoCommit;
+      return "Error inserting cust_pkg_reason: $error";
+    }
+  }
+
   foreach my $cust_svc (
     qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
   ) {
@@ -652,6 +679,23 @@
   $cust_bill_pkg ? $cust_bill_pkg->sdate : $self->setup || 0;
 }
 
+=item last_reason
+
+Returns the most recent FS::reason associated with the package.
+
+=cut
+
+sub last_reason {
+  my $self = shift;
+  my $cust_pkg_reason = qsearchs( {
+                                    'table' => 'cust_pkg_reason',
+				    'hashref' => { 'pkgnum' => $self->pkgnum, },
+				    'extra_sql'=> 'ORDER BY date DESC',
+				  } );
+  qsearchs ( 'reason', { 'reasonnum' => $cust_pkg_reason->reasonnum } )
+    if $cust_pkg_reason;
+}
+
 =item part_pkg
 
 Returns the definition for this billing item, as an FS::part_pkg object (see
@@ -1387,6 +1431,24 @@
   '';
 }
 
+sub insert_reason {
+  my ($self, %options) = @_;
+
+  my $otaker = $FS::CurrentUser::CurrentUser->name;
+  $otaker = $FS::CurrentUser::CurrentUser->username
+    if (($otaker) eq "User, Legacy");
+
+  my $cust_pkg_reason =
+    new FS::cust_pkg_reason({ 'pkgnum'    => $self->pkgnum,
+                              'reasonnum' => $options{'reason'}, 
+		              'otaker'    => $otaker,
+		              'date'      => $options{'date'}
+			                       ? $options{'date'}
+					       : time,
+	                    });
+  return $cust_pkg_reason->insert;
+}
+
 =back
 
 =head1 BUGS



More information about the freeside-commits mailing list