diff options
author | Mark Wells <mark@freeside.biz> | 2014-11-25 19:39:23 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2014-11-25 19:39:23 -0800 |
commit | 3cda3a85eb0daa5b8b9f4d30cd0896da6ccf4a9b (patch) | |
tree | e1d8a4f8b8572396fd2d4fe7a82327f1c9768c0f /FS | |
parent | 77be6115a8972c8e7917fc9f80e30a6ba571a552 (diff) |
option to credit unused time on suspension as part of suspend reason, #31702
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Schema.pm | 1 | ||||
-rw-r--r-- | FS/FS/cust_credit.pm | 21 | ||||
-rw-r--r-- | FS/FS/cust_pkg.pm | 24 | ||||
-rw-r--r-- | FS/FS/reason.pm | 13 |
4 files changed, 31 insertions, 28 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 396c866..715a603 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -5881,6 +5881,7 @@ sub tables_hashref { 'disabled', 'char', 'NULL', 1, '', '', 'unsuspend_pkgpart', 'int', 'NULL', '', '', '', 'unsuspend_hold','char', 'NULL', 1, '', '', + 'unused_credit', 'char', 'NULL', 1, '', '', ], 'primary_key' => 'reasonnum', 'unique' => [], diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index 156ba5f..212be7a 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -679,11 +679,9 @@ Example: 'apply' => 1, #0 leaves the credit unapplied #the credit - 'newreasonnum' => scalar($cgi->param('newreasonnum')), - 'newreasonnum_type' => scalar($cgi->param('newreasonnumT')), map { $_ => scalar($cgi->param($_)) } #fields('cust_credit') - qw( custnum _date amount reason reasonnum addlinfo ), #pkgnum eventnum + qw( custnum _date amount reasonnum addlinfo ), #pkgnum eventnum ); @@ -725,26 +723,11 @@ sub credit_lineitems { #}); my $error = ''; - if ($arg{reasonnum} == -1) { - - $error = 'Enter a new reason (or select an existing one)' - unless $arg{newreasonnum} !~ /^\s*$/; - my $reason = new FS::reason { - 'reason' => $arg{newreasonnum}, - 'reason_type' => $arg{newreasonnum_type}, - }; - $error ||= $reason->insert; - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return "Error inserting reason: $error"; - } - $arg{reasonnum} = $reason->reasonnum; - } my $cust_credit = new FS::cust_credit ( { map { $_ => $arg{$_} } #fields('cust_credit') - qw( custnum _date amount reason reasonnum addlinfo ), #pkgnum eventnum + qw( custnum _date amount reasonnum addlinfo ), #pkgnum eventnum } ); $error = $cust_credit->insert; if ( $error ) { diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index e8e202e..a810f5a 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -1207,7 +1207,7 @@ Available options are: =over 4 -=item reason - can be set to a cancellation reason (see L<FS:reason>), +=item reason - can be set to a cancellation reason (see L<FS:reason>), either a reasonnum of an existing reason, or passing a hashref will create a new reason. The hashref should have the following keys: - typenum - Reason type (see L<FS::reason_type> @@ -1297,6 +1297,16 @@ sub suspend { } } + # if a reasonnum was passed, get the actual reason object so we can check + # unused_credit + # (passing a reason hashref is still allowed, but it can't be used with + # the fancy behavioral options.) + + my $reason; + if ($options{'reason'} =~ /^\d+$/) { + $reason = FS::reason->by_key($options{'reason'}); + } + my %hash = $self->hash; if ( $date ) { $hash{'adjourn'} = $date; @@ -1321,9 +1331,15 @@ sub suspend { return $error; } - unless ( $date ) { + unless ( $date ) { # then we are suspending now + # credit remaining time if appropriate - if ( $self->part_pkg->option('unused_credit_suspend', 1) ) { + # (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; @@ -3872,7 +3888,7 @@ sub insert_reason { $reasonnum = $reason->reasonnum; } else { - return "Unparsable reason: ". $options{'reason'}; + return "Unparseable reason: ". $options{'reason'}; } my $cust_pkg_reason = diff --git a/FS/FS/reason.pm b/FS/FS/reason.pm index e6b20db..f28989a 100644 --- a/FS/FS/reason.pm +++ b/FS/FS/reason.pm @@ -56,6 +56,10 @@ suspensions but not others. whether to bill the unsuspend package immediately ('') or to wait until the customer's next invoice ('Y'). +=item unused_credit - 'Y' or ''. For suspension reasons only (for now). +If enabled, the customer will be credited for their remaining time on +suspension. + =back =head1 METHODS @@ -109,7 +113,6 @@ sub check { || $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; @@ -117,11 +120,13 @@ sub check { $error = $self->ut_numbern('unsuspend_pkgpart') || $self->ut_foreign_keyn('unsuspend_pkgpart', 'part_pkg', 'pkgpart') || $self->ut_flag('unsuspend_hold') + || $self->ut_flag('unused_credit') ; return $error if $error; } else { - $self->set('unsuspend_pkgpart' => ''); - $self->set('unsuspend_hold' => ''); + foreach (qw(unsuspend_pkgpart unsuspend_hold unused_credit)) { + $self->set($_ => ''); + } } $self->SUPER::check; @@ -178,8 +183,6 @@ sub new_or_existing { =head1 BUGS -Here by termintes. Don't use on wooden computers. - =head1 SEE ALSO L<FS::Record>, schema.html from the base documentation. |