e8ac8d31ebedea412bf2b5524129c6e6eddf0b22
[freeside.git] / httemplate / misc / cust_main-unsuspend.cgi
1 <& /elements/header-popup.html, mt("Customer unsuspended") &>
2   <SCRIPT TYPE="text/javascript">
3     window.top.location.reload();
4   </SCRIPT>
5   </BODY>
6 </HTML>
7 <%init>
8
9 #false laziness w/cust_main-cancel.cgi
10
11 die "access denied"
12   unless $FS::CurrentUser::CurrentUser->access_right('Unsuspend customer');
13
14 my $custnum;
15 my $resume = '';
16 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
17   $custnum = $1;
18   $resume = $cgi->param('resume');
19 } else {
20   my($query) = $cgi->keywords;
21   $query =~ /^(\d+)$/ || die "Illegal custnum";
22   $custnum = $1;
23 }
24
25 my $cust_main = qsearchs( {
26   'table'     => 'cust_main',
27   'hashref'   => { 'custnum' => $custnum },
28   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
29 } );
30
31 my @errors;
32 if($cgi->param('now_or_later')) {
33   $resume = parse_datetime($resume);
34   if($resume) {
35     #warn "setting resume dates on custnum#$custnum\n";
36     my @pkgs = $cust_main->suspended_pkgs;
37     if (!$cgi->param('release_hold')) {
38       # then avoid packages that are on hold
39       @pkgs = grep { $_->get('setup') } @pkgs;
40     }
41     @errors = grep {$_} map { $_->unsuspend(
42       'date'    => $resume,
43     ) } @pkgs;
44   }
45   else {
46     @errors = ("error parsing adjourn date: ".$cgi->param('adjourn'));
47   }
48 }
49 else { # unsuspending now
50   warn "unsuspending $cust_main";
51   @errors = $cust_main->unsuspend;
52
53   if ( $cgi->param('release_hold') ) {
54     push @errors, $cust_main->release_hold;
55   }
56 }
57 my $error = join(' / ', @errors) if scalar(@errors);
58
59 if ( $error ) {
60   $cgi->param('error', $error);
61   print $cgi->redirect(popurl(1). "unsuspend_cust.html?". $cgi->query_string );
62 }
63
64 </%init>