diff options
| -rw-r--r-- | FS/FS/cust_main.pm | 107 | 
1 files changed, 87 insertions, 20 deletions
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index ebc4812ab..9c0e36e18 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -286,26 +286,10 @@ sub insert {    # packages    local $FS::svc_Common::noexport_hack = 1 if $options{'noexport'}; -  foreach my $cust_pkg ( keys %$cust_pkgs ) { -    $cust_pkg->custnum( $self->custnum ); -    $error = $cust_pkg->insert; -    if ( $error ) { -      $dbh->rollback if $oldAutoCommit; -      return "inserting cust_pkg (transaction rolled back): $error"; -    } -    foreach my $svc_something ( @{$cust_pkgs->{$cust_pkg}} ) { -      $svc_something->pkgnum( $cust_pkg->pkgnum ); -      if ( $seconds && $svc_something->isa('FS::svc_acct') ) { -        $svc_something->seconds( $svc_something->seconds + $seconds ); -        $seconds = 0; -      } -      $error = $svc_something->insert; -      if ( $error ) { -        $dbh->rollback if $oldAutoCommit; -        #return "inserting svc_ (transaction rolled back): $error"; -        return $error; -      } -    } +  $error = $self->order_pkgs($cust_pkgs, \$seconds); +  if ( $error ) { +    $dbh->rollback if $oldAutoCommit; +    return $error;    }    if ( $seconds ) { @@ -336,6 +320,89 @@ sub insert {  } +=item order_pkgs + +document me.  like ->insert(%cust_pkg) on an existing record + +=cut + +sub order_pkgs { +  my $self = shift; +  my $cust_pkgs = shift; +  my $seconds = 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; + +  foreach my $cust_pkg ( keys %$cust_pkgs ) { +    $cust_pkg->custnum( $self->custnum ); +    my $error = $cust_pkg->insert; +    if ( $error ) { +      $dbh->rollback if $oldAutoCommit; +      return "inserting cust_pkg (transaction rolled back): $error"; +    } +    foreach my $svc_something ( @{$cust_pkgs->{$cust_pkg}} ) { +      $svc_something->pkgnum( $cust_pkg->pkgnum ); +      if ( $seconds && $$seconds && $svc_something->isa('FS::svc_acct') ) { +        $svc_something->seconds( $svc_something->seconds + $$seconds ); +        $$seconds = 0; +      } +      $error = $svc_something->insert; +      if ( $error ) { +        $dbh->rollback if $oldAutoCommit; +        #return "inserting svc_ (transaction rolled back): $error"; +        return $error; +      } +    } +  } + +  $dbh->commit or die $dbh->errstr if $oldAutoCommit; +  ''; #no error +} + +=item reexport + +document me.  Re-schedules all exports by calling the B<reexport> method +of all associated packages (see L<FS::cust_pkg>).  If there is an error, +returns the error; otherwise returns false. + +=cut + +sub reexport { +  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; + +  foreach my $cust_pkg ( $self->ncancelled_pkgs ) { +    my $error = $cust_pkg->reexport; +    if ( $error ) { +      $dbh->rollback if $oldAutoCommit; +      return $error; +    } +  } + +  $dbh->commit or die $dbh->errstr if $oldAutoCommit; +  ''; + +} +  =item delete NEW_CUSTNUM  This deletes the customer.  If there is an error, returns the error, otherwise  | 
