summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2009-04-28 04:14:23 +0000
committerivan <ivan>2009-04-28 04:14:23 +0000
commit16401012b02d1cb1bd16296f8437041dd9363996 (patch)
tree51036bd985af589456396f283d5a32fd530be99a /FS
parent6091686905d1457950805c075c41580d6ac70288 (diff)
add cancelled_cust-noevents flag to emulate SG billing-daily -r behavior
Diffstat (limited to 'FS')
-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 279a17058..cf4c43908 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -2765,6 +2765,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 3296cf543..92cf92485 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -2225,18 +2225,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
)
: ()
@@ -2246,20 +2264,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
)
)
}
@@ -2279,18 +2296,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