X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fmisc%2Fcancel-unaudited.cgi;h=4b3084f00a648348d0e8988a6831a2a30631fb5e;hb=1fa46a8e2890c2c6f1e0117856f5c481306b1c59;hp=f1fb1534156e3f1da17906fa42327dde3c1af457;hpb=23186f0338ec248d930c85db08cc997bca42525b;p=freeside.git diff --git a/httemplate/misc/cancel-unaudited.cgi b/httemplate/misc/cancel-unaudited.cgi index f1fb15341..4b3084f00 100755 --- a/httemplate/misc/cancel-unaudited.cgi +++ b/httemplate/misc/cancel-unaudited.cgi @@ -1,47 +1,46 @@ -<% +%if ( $error ) { +% errorpage($error); +%} else { +<% $cgi->redirect(popurl(2)) %> +%} + +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Unprovision customer service') + && $FS::CurrentUser::CurrentUser->access_right('View/link unlinked services'); -my $dbh = dbh; - #untaint svcnum my($query) = $cgi->keywords; $query =~ /^(\d+)$/; my $svcnum = $1; -#my $svc_acct = qsearchs('svc_acct',{'svcnum'=>$svcnum}); -#die "Unknown svcnum!" unless $svc_acct; - +my $error = ''; my $cust_svc = qsearchs('cust_svc',{'svcnum'=>$svcnum}); -die "Unknown svcnum!" unless $cust_svc; -&eidiot(qq!This account has already been audited. Cancel the - package instead.!) - if $cust_svc->pkgnum ne '' && $cust_svc->pkgnum ne '0'; - -my $svc_x = $cust_svc->svc_x; - -local $SIG{HUP} = 'IGNORE'; -local $SIG{INT} = 'IGNORE'; -local $SIG{QUIT} = 'IGNORE'; -local $SIG{TERM} = 'IGNORE'; -local $SIG{TSTP} = 'IGNORE'; - -local $FS::UID::AutoCommit = 0; - -my $error = $svc_x->cancel; -$error ||= $svc_x->delete; -$error ||= $cust_svc->delete; - -if ( $error ) { - $dbh->rollback; - %> - -<% - &eidiot($error); +if ( $cust_svc ) { + my $cust_pkg = $cust_svc->cust_pkg; + if ( $cust_pkg ) { + errorpage( 'This account has already been audited. Cancel the '. + qq!'. + 'package instead.'); #' + } + + $error = $cust_svc->cancel; } else { - - $dbh->commit or die $dbh->errstr; - - print $cgi->redirect(popurl(2)); + # the rare obscure case: svc_x without cust_svc + my $svc_x; + foreach my $svcdb (FS::part_svc->svc_tables) { + $svc_x = qsearchs($svcdb, { 'svcnum' => $svcnum }); + last if $svc_x; + } + if ( $svc_x ) { + $error = $svc_x->return_inventory + || $svc_x->FS::Record::delete; + } else { + # the svcnum really doesn't exist + $error = "svcnum $svcnum not found"; + } } -%> +