option to credit unused time on suspension as part of suspend reason, #31702
[freeside.git] / httemplate / misc / process / cancel_pkg.html
1 <% header(emt("Package $past_method")) %>
2   <SCRIPT TYPE="text/javascript">
3     window.top.location.reload();
4   </SCRIPT>
5   </BODY>
6 </HTML>
7 <%once>
8
9 my %past = ( 'cancel'   => 'cancelled',
10              'expire'   => 'expired',
11              'suspend'  => 'suspended',
12              'adjourn'  => 'adjourned',
13              'resume'   => 'scheduled to resume',
14              'uncancel' => 'un-cancelled',
15            );
16
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',
24             );
25
26 </%once>
27 <%init>
28
29 #untaint method
30 my $method = $cgi->param('method');
31 $method =~ /^(cancel|expire|suspend|adjourn|resume|uncancel)$/
32   or die "Illegal method";
33 $method = $1;
34 my $past_method = $past{$method};
35
36 die "access denied"
37   unless $FS::CurrentUser::CurrentUser->access_right($right{$method});
38
39 #untaint pkgnum
40 my $pkgnum = $cgi->param('pkgnum');
41 $pkgnum =~ /^(\d+)$/ or die "Illegal pkgnum";
42 $pkgnum = $1;
43
44 my $date = time;
45 if ($method eq 'expire' || $method eq 'adjourn' || $method eq 'resume') {
46   #untaint date
47   $date = $cgi->param('date'); #huh?
48   parse_datetime($cgi->param('date')) =~ /^(\d+)$/ or die "Illegal date";
49   $date = $1;
50   $method = 'cancel'    if $method eq 'expire';
51   $method = 'suspend'   if $method eq 'adjourn';
52   $method = 'unsuspend' if $method eq 'resume';
53 }
54
55 my $resume_date = '';
56 my $options = '';
57 if ( $method eq 'suspend' ) { #or 'adjourn'
58   $resume_date = parse_datetime($cgi->param('resume_date'))
59     if $cgi->param('resume_date');
60
61   $options = { map { $_ => scalar($cgi->param($_)) }
62                  qw( suspend_bill no_suspend_bill )
63              };
64 }
65
66 my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} );
67
68 #untaint reasonnum, and set up new reason if appropriate
69 my ($reasonnum, $error);
70 if ($method ne 'resume' and $method ne 'uncancel') {
71   ($reasonnum, $error) = $m->comp('elements/reason');
72   if (!$reasonnum) {
73     $error ||= 'Reason required';
74   }
75 }
76
77 #for uncancel
78 my $last_bill =
79   $cgi->param('last_bill') ? parse_datetime($cgi->param('last_bill')) : '';
80 my $bill =
81   $cgi->param('bill')      ? parse_datetime($cgi->param('bill'))      : '';
82
83 my $svc_fatal = ( $cgi->param('svc_not_fatal') ne 'Y' );
84
85 $error ||=  $cust_pkg->$method( 'reason'      => $reasonnum,
86                                 'date'        => $date,
87                                 'resume_date' => $resume_date,
88                                 'last_bill'   => $last_bill,
89                                 'bill'        => $bill,
90                                 'svc_fatal'   => $svc_fatal,
91                                 'options'     => $options,
92                               );
93
94 if ($error) {
95   $cgi->param('error', $error);
96   print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string );
97 }
98
99 </%init>