[freeside-commits] freeside/FS/FS cust_pkg.pm,1.192,1.193

Ivan,,, ivan at wavetail.420.am
Wed Jan 19 21:22:22 PST 2011


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

Modified Files:
	cust_pkg.pm 
Log Message:
fix crediting for unused time on expirations?

Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.192
retrieving revision 1.193
diff -u -w -d -r1.192 -r1.193
--- cust_pkg.pm	16 Jan 2011 22:31:25 -0000	1.192
+++ cust_pkg.pm	20 Jan 2011 05:22:20 -0000	1.193
@@ -748,9 +748,8 @@
     }
   }
 
-  my %svc;
-  if ( $date ) {
-# copied from below
+  my %svc_cancel_opt = ();
+  $svc_cancel_opt{'date'} = $date if $date;
     foreach my $cust_svc (
       #schwartz
       map  { $_->[0] }
@@ -758,29 +757,16 @@
       map  { [ $_, $_->svc_x->table_info->{'cancel_weight'} ]; }
       qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
     ) {
-      my $error = $cust_svc->cancel( ('date' => $date) );
+    my $error = $cust_svc->cancel( %svc_cancel_opt );
 
       if ( $error ) {
         $dbh->rollback if $oldAutoCommit;
-        return "Error expiring cust_svc: $error";
+      return 'Error '. ($svc_cancel_opt{'date'} ? 'expiring' : 'canceling' ).
+             " cust_svc: $error";
       }
     }
-  } else { #!date
-    foreach my $cust_svc (
-      #schwartz
-      map  { $_->[0] }
-      sort { $a->[1] <=> $b->[1] }
-      map  { [ $_, $_->svc_x->table_info->{'cancel_weight'} ]; }
-      qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
-    ) {
-      my $error = $cust_svc->cancel;
 
-      if ( $error ) {
-        $dbh->rollback if $oldAutoCommit;
-        return "Error cancelling cust_svc: $error";
-      }
-    }
-  } #if $date
+  unless ($date) {
 
   # Add a credit for remaining service
   my $last_bill = $self->getfield('last_bill') || 0;
@@ -799,9 +785,6 @@
   ) {
     my $remaining_value = $self->calc_remain('time' => $cancel_time);
     if ( $remaining_value > 0 ) {
-      # && !$options{'no_credit'} ) {
-      # Undocumented, unused option.
-      # part_pkg configuration should decide this anyway.
       my $error = $self->cust_main->credit(
         $remaining_value,
         'Credit for unused time on '. $self->part_pkg->pkg,
@@ -809,12 +792,14 @@
       );
       if ($error) {
         $dbh->rollback if $oldAutoCommit;
-        return "Error crediting customer \$$remaining_value for unused time on".
-               $self->part_pkg->pkg. ": $error";
+          return "Error crediting customer \$$remaining_value for unused time".
+                 " on ". $self->part_pkg->pkg. ": $error";
       }
     } #if $remaining_value
   } #if $do_credit
 
+  } #unless $date
+
   my %hash = $self->hash;
   $date ? ($hash{'expire'} = $date) : ($hash{'cancel'} = $cancel_time);
   my $new = new FS::cust_pkg ( \%hash );



More information about the freeside-commits mailing list