summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2012-08-15 13:58:13 -0700
committerIvan Kohler <ivan@freeside.biz>2012-08-15 13:58:13 -0700
commit372b4a5284387258a5fbfcef791597f2964917e7 (patch)
tree772d7ddb6f13cd3c55098941eaa901ff68054106 /FS
parent947347097f67c615d2306e34772535f312e2fb2d (diff)
parent8728da844700ef4a10b05195f901d25630c416d8 (diff)
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Schema.pm2
-rw-r--r--FS/FS/cust_pkg.pm37
-rw-r--r--FS/FS/reason.pm27
3 files changed, 63 insertions, 3 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 6b32d7153..0f1d1513a 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -3671,6 +3671,8 @@ sub tables_hashref {
'reason_type', 'int', '', '', '', '',
'reason', 'text', '', '', '', '',
'disabled', 'char', 'NULL', 1, '', '',
+ 'unsuspend_pkgpart', 'int', 'NULL', '', '', '',
+ 'unsuspend_hold','char', 'NULL', 1, '', '',
],
'primary_key' => 'reasonnum',
'unique' => [],
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 721c9dbed..ea29a2c68 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -1322,7 +1322,8 @@ sub credit_remaining {
Unsuspends all services (see L<FS::cust_svc> and L<FS::part_svc>) in this
package, then unsuspends the package itself (clears the susp field and the
-adjourn field if it is in the past).
+adjourn field if it is in the past). If the suspend reason includes an
+unsuspension package, that package will be ordered.
Available options are:
@@ -1426,6 +1427,8 @@ sub unsuspend {
}
+ my $reason = $self->last_cust_pkg_reason('susp')->reason;
+
my %hash = $self->hash;
my $inactive = time - $hash{'susp'};
@@ -1452,6 +1455,33 @@ sub unsuspend {
return $error;
}
+ my $unsusp_pkg;
+
+ if ( $reason->unsuspend_pkgpart ) {
+ my $part_pkg = FS::part_pkg->by_key($reason->unsuspend_pkgpart)
+ or $error = "Unsuspend package definition ".$reason->unsuspend_pkgpart.
+ " not found.";
+ my $start_date = $self->cust_main->next_bill_date
+ if $reason->unsuspend_hold;
+
+ if ( $part_pkg ) {
+ $unsusp_pkg = FS::cust_pkg->new({
+ 'custnum' => $self->custnum,
+ 'pkgpart' => $reason->unsuspend_pkgpart,
+ 'start_date' => $start_date,
+ 'locationnum' => $self->locationnum,
+ # discount? probably not...
+ });
+
+ $error ||= $self->cust_main->order_pkg( 'cust_pkg' => $unsusp_pkg );
+ }
+
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
if ( $conf->config('unsuspend_email_admin') ) {
my $error = send_email(
@@ -1465,6 +1495,11 @@ sub unsuspend {
'Customer: #'. $self->custnum. ' '. $self->cust_main->name. "\n",
'Package : #'. $self->pkgnum. " (". $self->part_pkg->pkg_comment. ")\n",
( map { "Service : $_\n" } @labels ),
+ ($unsusp_pkg ?
+ "An unsuspension fee was charged: ".
+ $unsusp_pkg->part_pkg->pkg_comment."\n"
+ : ''
+ ),
],
);
diff --git a/FS/FS/reason.pm b/FS/FS/reason.pm
index 377da4985..a9a7d745d 100644
--- a/FS/FS/reason.pm
+++ b/FS/FS/reason.pm
@@ -46,6 +46,15 @@ FS::Record. The following fields are currently supported:
=item disabled - 'Y' or ''
+=item unsuspend_pkgpart - for suspension reasons only, the pkgpart (see
+L<FS::part_pkg>) of a package to be ordered when the package is unsuspended.
+Typically this will be some kind of reactivation fee. Attaching it to
+a suspension reason allows the reactivation fee to be charged for some
+suspensions but not others.
+
+=item unsuspend_hold - 'Y' or ''. If unsuspend_pkgpart is set, this tells
+whether to bill the unsuspend package immediately ('') or to wait until
+the customer's next invoice ('Y').
=back
@@ -97,16 +106,30 @@ sub check {
my $error =
$self->ut_numbern('reasonnum')
+ || $self->ut_number('reason_type')
+ || $self->ut_foreign_key('reason_type', 'reason_type', 'typenum')
|| $self->ut_text('reason')
+ || $self->ut_flag('disabled')
;
return $error if $error;
+ if ( $self->reasontype->class eq 'S' ) {
+ $error = $self->ut_numbern('unsuspend_pkgpart')
+ || $self->ut_foreign_keyn('unsuspend_pkgpart', 'part_pkg', 'pkgpart')
+ || $self->ut_flag('unsuspend_hold')
+ ;
+ return $error if $error;
+ } else {
+ $self->set('unsuspend_pkgpart' => '');
+ $self->set('unsuspend_hold' => '');
+ }
+
$self->SUPER::check;
}
=item reasontype
-Returns the reason_type (see <I>FS::reason_type</I>) associated with this reason.
+Returns the reason_type (see L<FS::reason_type>) associated with this reason.
=cut
@@ -118,7 +141,7 @@ sub reasontype {
=head1 BUGS
-Here be termintes. Don't use on wooden computers.
+Here by termintes. Don't use on wooden computers.
=head1 SEE ALSO