1 <% header(emt("Package $past_method")) %>
2 <SCRIPT TYPE="text/javascript">
3 window.top.location.reload();
9 my %past = ( 'cancel' => 'cancelled',
10 'expire' => 'expired',
11 'suspend' => 'suspended',
12 'adjourn' => 'adjourned',
13 'resume' => 'scheduled to resume',
14 'uncancel' => 'un-cancelled',
17 #i'm sure this is false laziness with somewhere, at least w/misc/cancel_pkg.html
18 my %right = ( 'cancel' => 'Cancel customer package immediately',
19 'expire' => 'Cancel customer package later',
20 'suspend' => 'Suspend customer package',
21 'adjourn' => 'Suspend customer package later',
22 'resume' => 'Unsuspend customer package', #later?
23 'uncancel' => 'Un-cancel customer package',
30 my $method = $cgi->param('method');
31 $method =~ /^(cancel|expire|suspend|adjourn|resume|uncancel)$/
32 or die "Illegal method";
34 my $past_method = $past{$method};
36 my $curuser = $FS::CurrentUser::CurrentUser;
39 unless $curuser->access_right($right{$method});
42 my $pkgnum = $cgi->param('pkgnum');
43 $pkgnum =~ /^(\d+)$/ or die "Illegal pkgnum";
47 if ($method eq 'expire' || $method eq 'adjourn' || $method eq 'resume') {
49 $date = $cgi->param('date'); #huh?
50 parse_datetime($cgi->param('date')) =~ /^(\d+)$/ or die "Illegal date";
52 $method = 'cancel' if $method eq 'expire';
53 $method = 'suspend' if $method eq 'adjourn';
54 $method = 'unsuspend' if $method eq 'resume';
59 if ( $method eq 'suspend' ) { #or 'adjourn'
60 $resume_date = parse_datetime($cgi->param('resume_date'))
61 if $cgi->param('resume_date');
63 $options = { map { $_ => scalar($cgi->param($_)) }
64 qw( suspend_bill no_suspend_bill )
66 if $curuser->access_right('Customize billing during suspension');
69 my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} );
71 #untaint reasonnum, and set up new reason if appropriate
72 my ($reasonnum, $error);
73 if ($method ne 'unsuspend' and $method ne 'uncancel') {
74 ($reasonnum, $error) = $m->comp('elements/reason');
76 $error ||= 'Reason required';
82 $cgi->param('last_bill') ? parse_datetime($cgi->param('last_bill')) : '';
84 $cgi->param('bill') ? parse_datetime($cgi->param('bill')) : '';
86 my $svc_fatal = ( $cgi->param('svc_not_fatal') ne 'Y' );
88 my $only_svcnum = ($method eq 'uncancel') ? [ $cgi->param('only_svcnum') ] : undef;
90 $error ||= $cust_pkg->$method( 'reason' => $reasonnum,
92 'resume_date' => $resume_date,
93 'last_bill' => $last_bill,
95 'svc_fatal' => $svc_fatal,
96 'options' => $options,
97 'only_svcnum' => $only_svcnum,
101 $cgi->param('error', $error);
102 print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string );