summaryrefslogtreecommitdiff
path: root/FS/FS/cust_pkg.pm
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2015-02-17 18:11:21 -0600
committerJonathan Prykop <jonathan@freeside.biz>2015-02-17 18:11:21 -0600
commit0c2cb2d865f84d21032ebc9780118d44df4ddf26 (patch)
treedf2d1ae6b90489293b001e86ef04c4157e764777 /FS/FS/cust_pkg.pm
parent7a8ff6a0a75e0a50b6fde0bff3d49e8372853e94 (diff)
#14671: Usage for current day when billing outstanding usage (for cancelling customers) [various fixes to previous]
Diffstat (limited to 'FS/FS/cust_pkg.pm')
-rw-r--r--FS/FS/cust_pkg.pm50
1 files changed, 30 insertions, 20 deletions
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 7678a02..fb3b0ff 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -901,7 +901,6 @@ sub cancel {
return $error;
}
}
-
} #unless $date
my %hash = $self->hash;
@@ -936,9 +935,13 @@ sub cancel {
foreach my $supp_pkg ( $self->supplemental_pkgs ) {
if ($delay_cancel) {
- $error = $supp_pkg->suspend(%options, 'from_main' => 1, 'reason' => undef);
+ $error = $supp_pkg->suspend(
+ 'from_main' => 1,
+ 'from_cancel' => 1,
+ 'time' => $cancel_time
+ );
} else {
- $error = $supp_pkg->cancel(%options, 'from_main' => 1);
+ $error = $supp_pkg->cancel(%options, 'from_main' => 1);
}
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
@@ -946,11 +949,13 @@ sub cancel {
}
}
- foreach my $usage ( $self->cust_pkg_usage ) {
- $error = $usage->delete;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "deleting usage pools: $error";
+ unless ($date) {
+ foreach my $usage ( $self->cust_pkg_usage ) {
+ $error = $usage->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "deleting usage pools: $error";
+ }
}
}
@@ -1249,6 +1254,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.
@@ -1291,7 +1299,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
@@ -1356,17 +1364,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;
+ }
}
}
@@ -1397,7 +1407,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),