fix A/R report
[freeside.git] / httemplate / misc / cancel-unaudited.cgi
1 %if ( $error ) {
2 %  errorpage($error);
3 %} else {
4 <% $cgi->redirect(popurl(2)) %>
5 %}
6
7 <%init>
8
9 die "access denied"
10   unless $FS::CurrentUser::CurrentUser->access_right('Unprovision customer service')
11       && $FS::CurrentUser::CurrentUser->access_right('View/link unlinked services');
12
13 #untaint svcnum
14 my($query) = $cgi->keywords;
15 $query =~ /^(\d+)$/;
16 my $svcnum = $1;
17
18 my $error = '';
19 my $cust_svc = qsearchs('cust_svc',{'svcnum'=>$svcnum});
20 if ( $cust_svc ) {
21   my $cust_pkg = $cust_svc->cust_pkg;
22   if ( $cust_pkg ) {
23     errorpage( 'This account has already been audited.  Cancel the '.
24              qq!<A HREF="${p}view/cust_main.cgi?!. $cust_pkg->custnum.
25              '#cust_pkg'. $cust_pkg->pkgnum. '">'.
26              'package</A> instead.'); #'
27   }
28
29   $error = $cust_svc->cancel;
30 } else {
31   # the rare obscure case: svc_x without cust_svc
32   my $svc_x;
33   foreach my $svcdb (FS::part_svc->svc_tables) {
34     $svc_x = qsearchs($svcdb, { 'svcnum' => $svcnum });
35     last if $svc_x;
36   }
37   if ( $svc_x ) {
38     $error = $svc_x->return_inventory
39              || $svc_x->FS::Record::delete;
40   } else {
41     # the svcnum really doesn't exist
42     $error = "svcnum $svcnum not found";
43   }
44 }
45
46 </%init>