RT#17599: display cancelled services from history
[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 my $curuser = $FS::CurrentUser::CurrentUser;
37
38 die "access denied"
39   unless $curuser->access_right($right{$method});
40
41 #untaint pkgnum
42 my $pkgnum = $cgi->param('pkgnum');
43 $pkgnum =~ /^(\d+)$/ or die "Illegal pkgnum";
44 $pkgnum = $1;
45
46 my $date = time;
47 if ($method eq 'expire' || $method eq 'adjourn' || $method eq 'resume') {
48   #untaint date
49   $date = $cgi->param('date'); #huh?
50   parse_datetime($cgi->param('date')) =~ /^(\d+)$/ or die "Illegal date";
51   $date = $1;
52   $method = 'cancel'    if $method eq 'expire';
53   $method = 'suspend'   if $method eq 'adjourn';
54   $method = 'unsuspend' if $method eq 'resume';
55 }
56
57 my $resume_date = '';
58 my $options = '';
59 if ( $method eq 'suspend' ) { #or 'adjourn'
60   $resume_date = parse_datetime($cgi->param('resume_date'))
61     if $cgi->param('resume_date');
62
63   $options = { map { $_ => scalar($cgi->param($_)) }
64                  qw( suspend_bill no_suspend_bill )
65              }
66     if $curuser->access_right('Customize billing during suspension');
67 }
68
69 my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} );
70
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');
75   if (!$reasonnum) {
76     $error ||= 'Reason required';
77   }
78 }
79
80 #for uncancel
81 my $last_bill =
82   $cgi->param('last_bill') ? parse_datetime($cgi->param('last_bill')) : '';
83 my $bill =
84   $cgi->param('bill')      ? parse_datetime($cgi->param('bill'))      : '';
85
86 my $svc_fatal = ( $cgi->param('svc_not_fatal') ne 'Y' );
87
88 my $only_svcnum = ($method eq 'uncancel') ? [ $cgi->param('only_svcnum') ] : undef;
89
90 $error ||=  $cust_pkg->$method( 'reason'      => $reasonnum,
91                                 'date'        => $date,
92                                 'resume_date' => $resume_date,
93                                 'last_bill'   => $last_bill,
94                                 'bill'        => $bill,
95                                 'svc_fatal'   => $svc_fatal,
96                                 'options'     => $options,
97                                 'only_svcnum' => $only_svcnum,
98                               );
99
100 if ($error) {
101   $cgi->param('error', $error);
102   print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string );
103 }
104
105 </%init>