summaryrefslogtreecommitdiff
path: root/httemplate/misc/cust_main-suspend.cgi
blob: e81e2b4906710c0fe3b063c80b01f0b0726405f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<& /elements/header-popup.html, mt("Customer suspended") &>
  <SCRIPT TYPE="text/javascript">
    topreload();
  </SCRIPT>
  </BODY>
</HTML>
<%init>

#false laziness w/cust_main-cancel.cgi

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Suspend customer');

my $custnum;
my $adjourn = '';
if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
  $custnum = $1;
  $adjourn = $cgi->param('adjourn');
} else {
  my($query) = $cgi->keywords;
  $query =~ /^(\d+)$/ || die "Illegal custnum";
  $custnum = $1;
}

#untaint reasonnum / create new reason
my ($reasonnum, $error) = $m->comp('process/elements/reason');
if (!$reasonnum) {
  $error ||= 'Reason required';
}

my $cust_main = qsearchs( {
  'table'     => 'cust_main',
  'hashref'   => { 'custnum' => $custnum },
  'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
} );

if ( $error ) {
  # do nothing
} elsif ( $cgi->param('now_or_later') ) {
  $adjourn = parse_datetime($adjourn);
  if($adjourn) {
    #warn "setting adjourn dates on custnum#$custnum\n";
    my @pkgs = $cust_main->unsuspended_pkgs;
    my @errors = grep {$_} map { $_->suspend(
      'reason'  => $reasonnum,
      'date'    => $adjourn,
    ) } @pkgs;
    $error = join(' / ', @errors);
  } else {
    $error = ("error parsing adjourn date: ".$cgi->param('adjourn'));
  }
} else {
  warn "suspending $cust_main";
  $error = $cust_main->suspend(
    'reason' => $reasonnum,
  );
}

if ( $error ) {
  $cgi->param('error', $error);
  print $cgi->redirect(popurl(1). "suspend_cust.html?". $cgi->query_string );
}

</%init>