eliminate some false laziness in FS::Misc::send_email vs. msg_template/email.pm send_...
[freeside.git] / FS / FS / cust_bill_pkg.pm
index d0d62bd..f0d7105 100644 (file)
@@ -6,7 +6,7 @@ use vars qw( @ISA $DEBUG $me );
 use Carp;
 use List::Util qw( sum min );
 use Text::CSV_XS;
-use FS::Record qw( qsearch qsearchs dbh );
+use FS::Record qw( qsearch qsearchs dbh fields );
 use FS::cust_pkg;
 use FS::cust_bill_pkg_detail;
 use FS::cust_bill_pkg_display;
@@ -392,7 +392,7 @@ sub void {
 
   }
 
-  $error = $self->delete;
+  $error = $self->delete( skip_update_cust_bill_charged=>1 );
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
     return $error;
@@ -429,8 +429,10 @@ sub void_cust_bill_pkg_detail {
     $self->billpkgnum
   );
 
-  $self->scalar_sql("INSERT INTO cust_bill_pkg_detail_void
-                       SELECT * $from_cust_bill_pkg_detail",
+  my $fields = join(', ', fields('cust_bill_pkg_detail_void') );
+
+  $self->scalar_sql("INSERT INTO cust_bill_pkg_detail_void ($fields)
+                       SELECT $fields $from_cust_bill_pkg_detail",
                     $self->billpkgnum
                    );
 
@@ -446,6 +448,7 @@ Not recommended.
 
 sub delete {
   my $self = shift;
+  my %opt = @_;
 
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
@@ -491,18 +494,24 @@ sub delete {
     }
   }
 
-  #fix the invoice amount
+  unless ( $opt{skip_update_cust_bill_charged} ) {
 
-  my $cust_bill = $self->cust_bill;
-  $cust_bill->charged( $cust_bill->charged - $self->setup - $self->recur );
+    #fix the invoice amount
 
-  #not adding a cc surcharge, but this override lets us modify charged
-  $cust_bill->{'Hash'}{'cc_surcharge_replace_hack'} = 1;
+    my $cust_bill = $self->cust_bill;
+    my $charged = $cust_bill->charged - $self->setup - $self->recur;
+    $charged = sprintf('%.2f', $charged + 0.00000001 );
+    $cust_bill->charged( $charged );
+
+    #not adding a cc surcharge, but this override lets us modify charged
+    $cust_bill->{'Hash'}{'cc_surcharge_replace_hack'} = 1;
+
+    my $error = $cust_bill->replace;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
 
-  my $error = $cust_bill->replace;
-  if ( $error ) {
-    $dbh->rollback if $oldAutoCommit;
-    return $error;
   }
 
   my $error = $self->SUPER::delete(@_);