fix selfservice balance display
[freeside.git] / httemplate / misc / cancel_pkg.html
1 <& /elements/header-popup.html, mt($title) &>
2
3 <& /elements/error.html &>
4
5 <FORM NAME="sc_popup" ACTION="<% popurl(1) %>process/cancel_pkg.html" METHOD=POST>
6 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
7 <INPUT TYPE="hidden" NAME="method" VALUE="<% $method %>">
8
9 <BR><BR>
10 <% emt(ucfirst($method)." [_1]", $part_pkg->pkg_comment) %>
11 <% ntable("#cccccc", 2) %>
12
13 % my $date_init = 0;
14 % if ($method eq 'expire' || $method eq 'adjourn' || $method eq 'resume') {
15 %   $submit =~ /^(\w*)\s/;
16 <& /elements/tr-input-date-field.html, {
17     'name'    => 'date',
18     'value'   => $date,
19     'label'   => mt("$1 package on"),
20     'format'  => $date_format,
21 } &>
22 %   $date_init = 1;
23 % }
24
25 % unless ( $method eq 'resume' ) { #the only one that doesn't need a reason
26 <& /elements/tr-select-reason.html,
27      'field'          => 'reasonnum',
28      'reason_class'   => $class,
29      'curr_value'     => $reasonnum,
30      'control_button' => "document.getElementById('confirm_cancel_pkg_button')",
31 &>
32 % }
33
34 % if ( $method eq 'adjourn' || $method eq 'suspend' ) {
35     <TR><TD COLSPAN=2>
36 %   if ( $part_pkg->option('suspend_bill', 1) ) {
37       <& /elements/checkbox.html, name=>'no_suspend_bill', value=>'Y' &>
38       Disable recurring billing while suspended
39 %   } else {
40       <& /elements/checkbox.html, name=>'suspend_bill', value=>'Y' &>
41       Continue recurring billing while suspended
42 %   }
43     </TD></TR>
44 % }
45
46 % if ( ( $method eq 'adjourn' || $method eq 'suspend' ) and 
47 %      $curuser->access_right('Unsuspend customer package') )  { #later?
48 %   my $resume_date = $cgi->param('error') 
49 %                     ? str2time($cgi->param('resume_date'))
50 %                     : $cust_pkg->get('resume');
51
52 <& /elements/tr-input-date-field.html, {
53     'name'    => 'resume_date',
54     'value'   => $resume_date,
55     'label'   => mt('Unsuspend on'),
56     'format'  => $date_format,
57     'noinit'  => $date_init,
58 } &>
59 % }
60 </TABLE>
61
62 <BR>
63 <INPUT TYPE="submit" NAME="submit" ID="confirm_cancel_pkg_button" 
64   VALUE="<% mt($submit) |h %>"
65   <% $method ne 'resume' ? 'DISABLED' : '' %>>
66
67 </FORM>
68 </BODY>
69 </HTML>
70
71 <%init>
72
73 my $conf = new FS::Conf;
74 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
75
76 my $date;
77
78 my($pkgnum, $reasonnum);
79 if ( $cgi->param('error') ) {
80   $pkgnum    = $cgi->param('pkgnum');
81   $reasonnum = $cgi->param('reasonnum');
82   $date      = str2time($cgi->param('date'));
83 } elsif ( $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
84   $pkgnum    = $1;
85   $reasonnum = '';
86 } else {
87   die "illegal query ". $cgi->keywords;
88 }
89
90 $cgi->param('method') =~ /^(\w+)$/ or die 'illegal method';
91 my $method = $1;
92
93 my($class, $submit, $right);
94 if ($method eq 'cancel') {
95   $class  = 'C';
96   $submit = 'Cancel Now';
97   $right  = 'Cancel customer package immediately';
98 } elsif ($method eq 'expire') {
99   $class  = 'C';
100   $submit = 'Cancel Later';
101   $right  = 'Cancel customer package later';
102 } elsif ($method eq 'suspend') {
103   $class  = 'S';
104   $submit = 'Suspend Now';
105   $right  = 'Suspend customer package';
106 } elsif ($method eq 'adjourn') {
107   $class  = 'S';
108   $submit = "Suspend Later";
109   $right  = 'Suspend customer package later';
110 } elsif ( $method eq 'resume') {
111   $class  = '';
112   $submit = 'Unsuspend Later';
113   $right  = 'Unsuspend customer package'; #later?
114 } else {
115   die 'illegal query (unknown method param)';
116 }
117
118 my $curuser = $FS::CurrentUser::CurrentUser;
119 die "access denied" unless $curuser->access_right($right);
120
121 my $title = ucfirst($method) . ' Package';
122
123 my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum})
124   or die "Unknown pkgnum: $pkgnum";
125
126 my $part_pkg = $cust_pkg->part_pkg;
127
128 $date ||= $cust_pkg->get($method);
129 $date ||= time;
130
131 </%init>