common element for cust_pkg search form fields
[freeside.git] / httemplate / misc / cust_main-suspend.cgi
1 <& /elements/popup-topreload.html, mt("Customer suspended") &>
2 <%init>
3
4 #false laziness w/cust_main-cancel.cgi
5
6 die "access denied"
7   unless $FS::CurrentUser::CurrentUser->access_right('Suspend customer');
8
9 my $custnum;
10 my $adjourn = '';
11 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
12   $custnum = $1;
13   $adjourn = $cgi->param('adjourn');
14 } else {
15   my($query) = $cgi->keywords;
16   $query =~ /^(\d+)$/ || die "Illegal custnum";
17   $custnum = $1;
18 }
19
20 #untaint reasonnum / create new reason
21 my ($reasonnum, $error) = $m->comp('process/elements/reason');
22 if (!$reasonnum) {
23   $error ||= 'Reason required';
24 }
25
26 my $cust_main = qsearchs( {
27   'table'     => 'cust_main',
28   'hashref'   => { 'custnum' => $custnum },
29   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
30 } );
31
32 if ( $error ) {
33   # do nothing
34 } elsif ( $cgi->param('now_or_later') ) {
35   $adjourn = parse_datetime($adjourn);
36   if($adjourn) {
37     #warn "setting adjourn dates on custnum#$custnum\n";
38     my @pkgs = $cust_main->unsuspended_pkgs;
39     my @errors = grep {$_} map { $_->suspend(
40       'reason'  => $reasonnum,
41       'date'    => $adjourn,
42     ) } @pkgs;
43     $error = join(' / ', @errors);
44   } else {
45     $error = ("error parsing adjourn date: ".$cgi->param('adjourn'));
46   }
47 } else {
48   warn "suspending $cust_main";
49   $error = $cust_main->suspend(
50     'reason' => $reasonnum,
51   );
52 }
53
54 if ( $error ) {
55   $cgi->param('error', $error);
56   print $cgi->redirect(popurl(1). "suspend_cust.html?". $cgi->query_string );
57 }
58
59 </%init>