From: jeff Date: Mon, 30 Jun 2008 21:49:14 +0000 (+0000) Subject: backport reason handling X-Git-Tag: freeside_1_7_4rc1~264 X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=31e5d11ee35ec63c7bcbb30c38c2c4ce020b6e75;p=freeside.git backport reason handling --- 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, possibly inserting a new reason on the fly (see +L). + +Available options are: + +=over 4 + +=item reason - can be set to a cancellation reason (see L), 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, 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 diff --git a/httemplate/misc/process/cancel_pkg.html b/httemplate/misc/process/cancel_pkg.html index 1a8d23b6f..d265c1849 100755 --- a/httemplate/misc/process/cancel_pkg.html +++ b/httemplate/misc/process/cancel_pkg.html @@ -50,45 +50,30 @@ if ($method eq 'expire' || $method eq 'adjourn'){ my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} ); -my $oldAutoCommit = $FS::UID::AutoCommit; -local $FS::UID::AutoCommit = 0; -my $dbh = dbh; +#my $otaker = $FS::CurrentUser::CurrentUser->name; +#$otaker = $FS::CurrentUser::CurrentUser->username +# if ($otaker eq "User, Legacy"); -my $otaker = $FS::CurrentUser::CurrentUser->name; -$otaker = $FS::CurrentUser::CurrentUser->username - if ($otaker eq "User, Legacy"); - -my $error = ''; if ($reasonnum == -1) { - - $error = 'Enter a new reason (or select an existing one)' - unless $cgi->param('newreasonnum') !~ /^\s*$/; - - my $reason = new FS::reason({ 'reason_type' => $cgi->param('newreasonnumT'), - 'reason' => $cgi->param('newreasonnum'), - }); - $error ||= $reason->insert; - $reasonnum = $reason->reasonnum - unless $error; + $reasonnum = { + 'typenum' => scalar( $cgi->param('newreasonnumT') ), + 'reason' => scalar( $cgi->param('newreasonnum' ) ), + }; } -unless ($error) { - if ($method eq 'expire' || $method eq 'adjourn'){ - my %hash = $cust_pkg->hash; - $hash{$method}=$date; - my $new = new FS::cust_pkg (\%hash); - $error = $new->replace($cust_pkg, 'reason' => $reasonnum); - }else{ - $error = $cust_pkg->$method( 'reason' => $reasonnum ); - } +my $error; +if ($method eq 'expire' || $method eq 'adjourn'){ + my %hash = $cust_pkg->hash; + $hash{$method} = $date; + my $new = new FS::cust_pkg \%hash; + $error = $new->replace($cust_pkg, 'reason' => $reasonnum); +} else { + $error = $cust_pkg->$method( 'reason' => $reasonnum ); } if ($error) { $cgi->param('error', $error); - $dbh->rollback if $oldAutoCommit; print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string ); } -$dbh->commit or die $dbh->errstr if $oldAutoCommit; -