X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg.pm;h=88afe35c155254ab5973dea0d1ada16228b03e27;hb=06ffff9be0c3b58a3c14855597fb48035ef0f1f2;hp=69f7bc0a83ee306d24520fef8c89225a5d4aafdd;hpb=598f5364ffaab833463442f910fc9c533975e317;p=freeside.git diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 69f7bc0a8..88afe35c1 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -791,6 +791,10 @@ to a different pkgpart or location, and probably shouldn't be in any other case. If it's not set, the 'unused_credit_cancel' part_pkg option will be used. +=item delay_cancel - for internal use, to allow proper handling of +supplemental packages when the main package is flagged to suspend +before cancelling + =back If there is an error, returns the error, otherwise returns false. @@ -837,7 +841,7 @@ sub cancel { my $date = $options{'date'} if $options{'date'}; # expire/cancel later $date = '' if ($date && $date <= $cancel_time); # complain instead? - my $delay_cancel = undef; + my $delay_cancel = $options{'delay_cancel'}; if ( !$date && $self->part_pkg->option('delay_cancel',1) && (($self->status eq 'active') || ($self->status eq 'suspended')) ) { @@ -915,14 +919,13 @@ sub cancel { return $error; } } - } #unless $date my %hash = $self->hash; if ( $date ) { $hash{'expire'} = $date; if ($delay_cancel) { - $hash{'susp'} = $cancel_time unless $self->susp; + # just to be sure these are clear $hash{'adjourn'} = undef; $hash{'resume'} = undef; } @@ -949,22 +952,31 @@ sub cancel { } foreach my $supp_pkg ( $self->supplemental_pkgs ) { - if ($delay_cancel) { - $error = $supp_pkg->suspend(%options, 'from_main' => 1, 'reason' => undef); - } else { - $error = $supp_pkg->cancel(%options, 'from_main' => 1); - } + $error = $supp_pkg->cancel(%options, + 'from_main' => 1, + 'date' => $date, #in case it got changed by delay_cancel + 'delay_cancel' => $delay_cancel, + ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return "canceling supplemental pkg#".$supp_pkg->pkgnum.": $error"; } } - foreach my $usage ( $self->cust_pkg_usage ) { - $error = $usage->delete; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "deleting usage pools: $error"; + if ($delay_cancel && !$options{'from_main'}) { + $error = $new->suspend( + 'from_cancel' => 1, + 'time' => $cancel_time + ); + } + + unless ($date) { + foreach my $usage ( $self->cust_pkg_usage ) { + $error = $usage->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "deleting usage pools: $error"; + } } } @@ -1278,6 +1290,9 @@ separately. =item from_main - allows a supplemental package to be suspended, rather than redirecting the method call to its main package. For internal use. +=item from_cancel - used when suspending from the cancel method, forces +this to skip everything besides basic suspension. For internal use. + =back If there is an error, returns the error, otherwise returns false. @@ -1327,7 +1342,7 @@ sub suspend { } # some false laziness with sub cancel - if ( !$options{nobill} && !$date && + if ( !$options{nobill} && !$date && !$options{'from_cancel'} && $self->part_pkg->option('bill_suspend_as_cancel',1) ) { # kind of a kludge--'bill_suspend_as_cancel' to avoid having to # make the entire cust_main->bill path recognize 'suspend' and @@ -1392,17 +1407,19 @@ sub suspend { unless ( $date ) { # then we are suspending now - # credit remaining time if appropriate - # (if required by the package def, or the suspend reason) - my $unused_credit = $self->part_pkg->option('unused_credit_suspend',1) - || ( defined($reason) && $reason->unused_credit ); + unless ($options{'from_cancel'}) { + # credit remaining time if appropriate + # (if required by the package def, or the suspend reason) + my $unused_credit = $self->part_pkg->option('unused_credit_suspend',1) + || ( defined($reason) && $reason->unused_credit ); - if ( $unused_credit ) { - warn "crediting unused time on pkg#".$self->pkgnum."\n" if $DEBUG; - my $error = $self->credit_remaining('suspend', $suspend_time); - if ($error) { - $dbh->rollback if $oldAutoCommit; - return $error; + if ( $unused_credit ) { + warn "crediting unused time on pkg#".$self->pkgnum."\n" if $DEBUG; + my $error = $self->credit_remaining('suspend', $suspend_time); + if ($error) { + $dbh->rollback if $oldAutoCommit; + return $error; + } } } @@ -1433,7 +1450,7 @@ sub suspend { } my $conf = new FS::Conf; - if ( $conf->config('suspend_email_admin') ) { + if ( $conf->config('suspend_email_admin') && !$options{'from_cancel'} ) { my $error = send_email( 'from' => $conf->config('invoice_from', $self->cust_main->agentnum), @@ -3405,6 +3422,9 @@ really the whole point of the delay_cancel option. sub is_status_delay_cancel { my ($self) = @_; + if ( $self->main_pkgnum and $self->pkglinknum ) { + return $self->main_pkg->is_status_delay_cancel; + } return 0 unless $self->part_pkg->option('delay_cancel',1); return 0 unless $self->status eq 'suspended'; return 0 unless $self->expire;