CDR reprocess with termination, RT8763
authorlevinse <levinse>
Mon, 24 Jan 2011 23:06:49 +0000 (23:06 +0000)
committerlevinse <levinse>
Mon, 24 Jan 2011 23:06:49 +0000 (23:06 +0000)
FS/FS/cdr.pm
httemplate/misc/cdr.cgi

index f7402ee..478dcff 100644 (file)
@@ -678,6 +678,50 @@ sub invoice_header {
   $export_names{$format}->{'invoice_header'};
 }
 
+=item clear_status 
+
+Clears cdr and any associated cdr_termination statuses - used for 
+CDR reprocessing.
+
+=cut
+
+sub clear_status {
+  my $self = shift;
+
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  $self->freesidestatus('');
+  my $error = $self->replace;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  } 
+
+  my @cdr_termination = qsearch('cdr_termination', 
+                               { 'acctid' => $self->acctid } );
+  foreach my $cdr_termination ( @cdr_termination ) {
+      $cdr_termination->status('');
+      $error = $cdr_termination->replace;
+      if ( $error ) {
+       $dbh->rollback if $oldAutoCommit;
+       return $error;
+      } 
+  }
+  
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+  '';
+}
+
 =item import_formats
 
 Returns an ordered list of key value pairs containing import format names
index d2ee773..a344e50 100644 (file)
@@ -33,10 +33,7 @@ if ( $action eq 'new' ) {
   ) {
     my $cdr = qsearchs('cdr', { 'acctid' => $acctid });
     if ( $action eq 'reprocess selected' && $cdr ) { #new
-      my %hash = $cdr->hash;
-      $hash{'freesidestatus'} = '';
-      my $new = new FS::cdr \%hash;
-      my $error = $new->replace($cdr);
+      my $error = $cdr->clear_status;
       die $error if $error;
     } elsif ( $action eq 'delete selected' && $cdr ) { #del
       my $error = $cdr->delete;