diff options
author | jeff <jeff> | 2008-06-30 21:49:14 +0000 |
---|---|---|
committer | jeff <jeff> | 2008-06-30 21:49:14 +0000 |
commit | 31e5d11ee35ec63c7bcbb30c38c2c4ce020b6e75 (patch) | |
tree | 01167e9d99e40f08dab13678626b1c5bd2a81907 /FS | |
parent | be03537a0b2c9dafc2bd455daa19451c8058a577 (diff) |
backport reason handling
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/cust_pkg.pm | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 074746579..91a9b8114 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -1873,6 +1873,26 @@ sub order { ''; } +=item insert_reason + +Associates this package with a (suspension or cancellation) reason (see +L<FS::cust_pkg_reason>, possibly inserting a new reason on the fly (see +L<FS::reason>). + +Available options are: + +=over 4 + +=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>, reason - Text of the new reason. + +=item date + +=back + +If there is an error, returns the error, otherwise returns false. + +=cut + =item bulk_change PKGPARTS_ARYREF, REMOVE_PKGNUMS_ARYREF [ RETURN_CUST_PKG_ARRAYREF ] PKGPARTS is a list of pkgparts specifying the the billing item definitions (see @@ -1936,15 +1956,39 @@ sub insert_reason { my $otaker = $FS::CurrentUser::CurrentUser->username; + my $reasonnum; + if ( $options{'reason'} =~ /^(\d+)$/ ) { + + $reasonnum = $1; + + } elsif ( ref($options{'reason'}) ) { + + return 'Enter a new reason (or select an existing one)' + unless $options{'reason'}->{'reason'} !~ /^\s*$/; + + my $reason = new FS::reason({ + 'reason_type' => $options{'reason'}->{'typenum'}, + 'reason' => $options{'reason'}->{'reason'}, + }); + my $error = $reason->insert; + return $error if $error; + + $reasonnum = $reason->reasonnum; + + } else { + return "Unparsable reason: ". $options{'reason'}; + } + my $cust_pkg_reason = new FS::cust_pkg_reason({ 'pkgnum' => $self->pkgnum, - 'reasonnum' => $options{'reason'}, + 'reasonnum' => $reasonnum, 'otaker' => $otaker, 'date' => $options{'date'} ? $options{'date'} : time, }); - return $cust_pkg_reason->insert; + + $cust_pkg_reason->insert; } =item set_usage USAGE_VALUE_HASHREF |