un-cancel, RT#17518
[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 % if ($method eq 'uncancel' ) {
26 %
27 % #XXX customer also requested setup
28 % # setup: what usefulness is changing or blanking this?  re-charge setup fee?
29 % #        an option that says that would be better if that's what we want to do
30
31 % # last_bill: isn't this informational?  what good would editing it do?
32 % #            something about invoice display?
33   <& /elements/tr-input-date-field.html, {
34       'name'    => 'last_bill',
35       'value'   => ( $cgi->param('last_bill') || $cust_pkg->get('last_bill') ),
36       'label'   => mt("Last bill date"),
37       'format'  => $date_format,
38   } &>
39
40   <& /elements/tr-input-date-field.html, {
41       'name'    => 'bill',
42       'value'   => ( $cgi->param('bill') || $cust_pkg->get('bill') ),
43       'label'   => mt("Next bill date"),
44       'format'  => $date_format,
45   } &>
46
47 %   $date_init = 1;
48 % }
49
50 % unless ( $method eq 'resume' || $method eq 'uncancel' ) {
51   <& /elements/tr-select-reason.html,
52        field          => 'reasonnum',
53        reason_class   => $class,
54        curr_value     => $reasonnum,
55        control_button => "document.getElementById('confirm_cancel_pkg_button')",
56   &>
57 % }
58
59 % if ( ( $method eq 'adjourn' or $method eq 'suspend' ) and 
60 %      $curuser->access_right('Unsuspend customer package') )  { #later?
61 %   my $resume_date = $cgi->param('error') 
62 %                     ? str2time($cgi->param('resume_date'))
63 %                     : $cust_pkg->get('resume');
64
65   <& /elements/tr-input-date-field.html, {
66       'name'    => 'resume_date',
67       'value'   => $resume_date,
68       'label'   => mt('Unsuspend on'),
69       'format'  => $date_format,
70       'noinit'  => $date_init,
71   } &>
72 % }
73 </TABLE>
74
75 <BR>
76 <INPUT TYPE="submit" NAME="submit" ID="confirm_cancel_pkg_button" 
77   VALUE="<% mt($submit) |h %>"
78   <% $method !~ /^(resume|uncancel)$/ ? 'DISABLED' : '' %>>
79
80 </FORM>
81 </BODY>
82 </HTML>
83
84 <%init>
85 use Date::Parse qw(str2time);
86
87 my $conf = new FS::Conf;
88 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
89
90 my $date;
91
92 my($pkgnum, $reasonnum);
93 if ( $cgi->param('error') ) {
94   $pkgnum    = $cgi->param('pkgnum');
95   $reasonnum = $cgi->param('reasonnum');
96   $date      = str2time($cgi->param('date'));
97 } elsif ( $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
98   $pkgnum    = $1;
99   $reasonnum = '';
100 } else {
101   die "illegal query ". $cgi->keywords;
102 }
103
104 $cgi->param('method') =~ /^(\w+)$/ or die 'illegal method';
105 my $method = $1;
106
107 my($class, $submit, $right);
108 if ($method eq 'cancel') {
109   $class  = 'C';
110   $submit = 'Cancel Now';
111   $right  = 'Cancel customer package immediately';
112 } elsif ($method eq 'expire') {
113   $class  = 'C';
114   $submit = 'Cancel Later';
115   $right  = 'Cancel customer package later';
116 } elsif ($method eq 'suspend') {
117   $class  = 'S';
118   $submit = 'Suspend Now';
119   $right  = 'Suspend customer package';
120 } elsif ($method eq 'adjourn') {
121   $class  = 'S';
122   $submit = "Suspend Later";
123   $right  = 'Suspend customer package later';
124 } elsif ( $method eq 'resume') {
125   $class  = '';
126   $submit = 'Unsuspend Later';
127   $right  = 'Unsuspend customer package'; #later?
128 } elsif ( $method eq 'uncancel') {
129   $class  = '';
130   $submit = 'Un-Cancel';
131   $right  = 'Un-cancel customer package'; #later?
132 } else {
133   die 'illegal query (unknown method param)';
134 }
135
136 my $curuser = $FS::CurrentUser::CurrentUser;
137 die "access denied" unless $curuser->access_right($right);
138
139 my $title = ucfirst($method) . ' Package';
140 $title =~ s/Uncancel/Un-cancel/;
141
142 my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum})
143   or die "Unknown pkgnum: $pkgnum";
144
145 my $part_pkg = $cust_pkg->part_pkg;
146
147 $date ||= $cust_pkg->get($method);
148 $date ||= time;
149
150 </%init>