],
},
+ {
+ 'key' => 'unsuspend_reason_type',
+ 'section' => 'suspension',
+ 'description' => 'If set, limits automatic unsuspension to packages which were suspended for this reason type.',
+ reason_type_options('S'),
+ },
+
{
'key' => 'unsuspend-always_adjust_next_bill_date',
'section' => 'suspension',
sub unsuspend {
my $self = shift;
- grep { ($_->get('setup')) && $_->unsuspend } $self->suspended_pkgs;
+ grep { ($_->get('setup')) && $_->unsuspend } $self->suspended_pkgs(@_);
}
=item release_hold
}
-=item suspended_pkgs
+=item suspended_pkgs OPTION => VALUE ...
Returns all suspended packages (see L<FS::cust_pkg>) for this customer.
+Currently supports one option, I<reason_type>, which if set to a typenum,
+limits the results to packages which were suspended for reasons of this type.
+(Does not currently work in scalar context; i.e. when just asking for a count.)
+
=cut
sub suspended_pkgs {
my $self = shift;
- return $self->num_suspended_pkgs unless wantarray;
- grep { $_->susp } $self->ncancelled_pkgs;
+ my %opt = @_;
+
+ return $self->num_suspended_pkgs unless wantarray; #XXX opt in scalar context
+
+ my @pkgs = grep { $_->susp } $self->ncancelled_pkgs;
+
+ if ( $opt{reason_type} ) {
+ @pkgs = grep { my $r = $_->last_reason('susp');
+ $r && $r->reason_type == $opt{reason_type};
+ }
+ @pkgs;
+ }
+
+ @pkgs;
}
=item unsuspended_pkgs
}
my $balance = $cust_main->balance || 0;
if ($balance <= $maxbalance) {
- my @errors = $cust_main->unsuspend;
+ my @errors = $cust_main->unsuspend(
+ 'reason_type' => $conf->config('unsuspend_reason_type')
+ );
# side-fx with nested transactions? upstack rolls back?
warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ".
join(' / ', @errors)