summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2009-04-28 04:13:53 +0000
committerivan <ivan>2009-04-28 04:13:53 +0000
commit1605da22a4fb996cb5e39571cbf38985506a2cfb (patch)
treed13508ef60ff37390ce824490205beaeb8b71f0b
parent7b6ddb00855032c2d71456b22a3fe030f1089d7c (diff)
add cancelled_cust-noevents flag to emulate SG billing-daily -r behavior
-rw-r--r--FS/FS/Conf.pm7
-rw-r--r--FS/FS/cust_main.pm55
2 files changed, 37 insertions, 25 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 9725957df..e37c6caa6 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -2457,6 +2457,13 @@ worry that config_items is freeside-specific and icky.
'type' => 'text',
},
+ {
+ 'key' => 'cancelled_cust-noevents',
+ 'section' => 'billing',
+ 'description' => "Don't run events for cancelled customers",
+ 'type' => 'checkbox',
+ },
+
);
1;
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 076831a9d..4976a6d6b 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -1935,18 +1935,36 @@ Debugging level. Default is 0 (no debugging), or can be set to 1 (passed-in opt
sub bill_and_collect {
my( $self, %options ) = @_;
- ###
- # cancel packages
- ###
-
#$options{actual_time} not $options{time} because freeside-daily -d is for
#pre-printing invoices
- my @cancel_pkgs = grep { $_->expire && $_->expire <= $options{actual_time} }
+ $self->cancel_expired_pkgs( $options{actual_time} );
+ $self->suspend_adjourned_pkgs( $options{actual_time} );
+
+ my $error = $self->bill( %options );
+ warn "Error billing, custnum ". $self->custnum. ": $error" if $error;
+
+ $self->apply_payments_and_credits;
+
+ unless ( $conf->config('cancelled_cust-noevents')
+ && ! $self->num_ncancelled_pkgs
+ ) {
+
+ $error = $self->collect( %options );
+ warn "Error collecting, custnum". $self->custnum. ": $error" if $error;
+
+ }
+
+}
+
+sub cancel_expired_pkgs {
+ my ( $self, $time ) = @_;
+
+ my @cancel_pkgs = grep { $_->expire && $_->expire <= $time }
$self->ncancelled_pkgs;
foreach my $cust_pkg ( @cancel_pkgs ) {
my $cpr = $cust_pkg->last_cust_pkg_reason('expire');
- my $error = $cust_pkg->cancel($cpr ? ( 'reason' => $cpr->reasonnum,
+ my $error = $cust_pkg->cancel($cpr ? ( 'reason' => $cpr->reasonnum,
'reason_otaker' => $cpr->otaker
)
: ()
@@ -1956,20 +1974,19 @@ sub bill_and_collect {
if $error;
}
- ###
- # suspend packages
- ###
+}
+
+sub suspend_adjourned_pkgs {
+ my ( $self, $time ) = @_;
- #$options{actual_time} not $options{time} because freeside-daily -d is for
- #pre-printing invoices
my @susp_pkgs =
grep { ! $_->susp
&& ( ( $_->part_pkg->is_prepaid
&& $_->bill
- && $_->bill < $options{actual_time}
+ && $_->bill < $time
)
|| ( $_->adjourn
- && $_->adjourn <= $options{actual_time}
+ && $_->adjourn <= $time
)
)
}
@@ -1989,18 +2006,6 @@ sub bill_and_collect {
if $error;
}
- ###
- # bill and collect
- ###
-
- my $error = $self->bill( %options );
- warn "Error billing, custnum ". $self->custnum. ": $error" if $error;
-
- $self->apply_payments_and_credits;
-
- $error = $self->collect( %options );
- warn "Error collecting, custnum". $self->custnum. ": $error" if $error;
-
}
=item bill OPTIONS