enable CardFortress in test database, #71513
[freeside.git] / httemplate / misc / cust_main-cancel.cgi
1 <& /elements/header-popup.html, mt("Customer cancelled") &>
2   <SCRIPT TYPE="text/javascript">
3     topreload();
4   </SCRIPT>
5   </BODY>
6 </HTML>
7 <%init>
8
9 die "access denied"
10   unless $FS::CurrentUser::CurrentUser->access_right('Cancel customer');
11
12 my $custnum;
13 my $ban = '';
14 my $expire = '';
15 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
16   $custnum = $1;
17   $ban = $cgi->param('ban');
18   $expire = $cgi->param('expire');
19 } else {
20   my($query) = $cgi->keywords;
21   $query =~ /^(\d+)$/ || die "Illegal custnum";
22   $custnum = $1;
23 }
24
25
26 #untaint reasonnum / create new reason
27 my ($reasonnum, $error) = $m->comp('process/elements/reason');
28 if (!$reasonnum) {
29   $error ||= 'Reason required'
30 }
31
32 my $cust_main = qsearchs( {
33   'table'     => 'cust_main',
34   'hashref'   => { 'custnum' => $custnum },
35   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
36 } );
37
38 if ( $error ) {
39   # do nothing
40 } elsif ( $cgi->param('now_or_later') ) {
41   $expire = parse_datetime($expire);
42   if($expire) {
43     #warn "setting expire dates on custnum#$custnum\n";
44     my @pkgs = $cust_main->ncancelled_pkgs;
45     my @errors = grep {$_} map { $_->cancel(
46       'reason'  => $reasonnum,
47       'date'    => $expire,
48     ) } @pkgs;
49     $error = join(' / ', @errors);
50   }
51   else {
52     $error = ("error parsing expire date: ".$cgi->param('expire'));
53   }
54 }
55 else {
56   warn "cancelling $cust_main";
57   my @error = $cust_main->cancel( #returns list of errors
58     'ban'    => $ban,
59     'reason' => $reasonnum,
60   );
61   $error = join(', ',@error);
62 }
63
64 if ( $error ) {
65   $cgi->param('error', $error);
66   print $cgi->redirect(popurl(1). "cancel_cust.html?". $cgi->query_string );
67 }
68
69 </%init>