Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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   <& /elements/tr-checkbox.html,
48        'label'  => mt("Uncancel even if a service can't be re-provisioned"),
49        'field'  => 'svc_not_fatal',
50        'value'  => 'Y',
51   &>
52
53 %   $date_init = 1;
54 % }
55
56 % unless ( $method eq 'resume' || $method eq 'uncancel' ) {
57   <& /elements/tr-select-reason.html,
58        field          => 'reasonnum',
59        reason_class   => $class,
60        curr_value     => $reasonnum,
61        control_button => "document.getElementById('confirm_cancel_pkg_button')",
62   &>
63 % }
64
65 % if ( $method eq 'adjourn' || $method eq 'suspend' ) {
66     <TR><TD COLSPAN=2>
67 %   if ( $part_pkg->option('suspend_bill', 1) ) {
68       <& /elements/checkbox.html, name=>'no_suspend_bill', value=>'Y' &>
69       Disable recurring billing while suspended
70 %   } else {
71       <& /elements/checkbox.html, name=>'suspend_bill', value=>'Y' &>
72       Continue recurring billing while suspended
73 %   }
74     </TD></TR>
75 % }
76
77 % if ( ( $method eq 'adjourn' || $method eq 'suspend' ) and 
78 %      $curuser->access_right('Unsuspend customer package') )  { #later?
79 %   my $resume_date = $cgi->param('error') 
80 %                     ? str2time($cgi->param('resume_date'))
81 %                     : $cust_pkg->get('resume');
82
83   <& /elements/tr-input-date-field.html, {
84       'name'    => 'resume_date',
85       'value'   => $resume_date,
86       'label'   => mt('Unsuspend on'),
87       'format'  => $date_format,
88       'noinit'  => $date_init,
89   } &>
90 % }
91 </TABLE>
92
93 <BR>
94 <INPUT TYPE="submit" NAME="submit" ID="confirm_cancel_pkg_button" 
95   VALUE="<% mt($submit) |h %>"
96   <% $method !~ /^(resume|uncancel)$/ ? 'DISABLED' : '' %>>
97
98 </FORM>
99 </BODY>
100 </HTML>
101
102 <%init>
103 use Date::Parse qw(str2time);
104
105 my $conf = new FS::Conf;
106 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
107
108 my $date;
109
110 my($pkgnum, $reasonnum);
111 if ( $cgi->param('error') ) {
112   $pkgnum    = $cgi->param('pkgnum');
113   $reasonnum = $cgi->param('reasonnum');
114   $date      = str2time($cgi->param('date'));
115 } elsif ( $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
116   $pkgnum    = $1;
117   $reasonnum = '';
118 } else {
119   die "illegal query ". $cgi->keywords;
120 }
121
122 $cgi->param('method') =~ /^(\w+)$/ or die 'illegal method';
123 my $method = $1;
124
125 my($class, $submit, $right);
126 if ($method eq 'cancel') {
127   $class  = 'C';
128   $submit = 'Cancel Now';
129   $right  = 'Cancel customer package immediately';
130 } elsif ($method eq 'expire') {
131   $class  = 'C';
132   $submit = 'Cancel Later';
133   $right  = 'Cancel customer package later';
134 } elsif ($method eq 'suspend') {
135   $class  = 'S';
136   $submit = 'Suspend Now';
137   $right  = 'Suspend customer package';
138 } elsif ($method eq 'adjourn') {
139   $class  = 'S';
140   $submit = "Suspend Later";
141   $right  = 'Suspend customer package later';
142 } elsif ( $method eq 'resume') {
143   $class  = '';
144   $submit = 'Unsuspend Later';
145   $right  = 'Unsuspend customer package'; #later?
146 } elsif ( $method eq 'uncancel') {
147   $class  = '';
148   $submit = 'Un-Cancel';
149   $right  = 'Un-cancel customer package'; #later?
150 } else {
151   die 'illegal query (unknown method param)';
152 }
153
154 my $curuser = $FS::CurrentUser::CurrentUser;
155 die "access denied" unless $curuser->access_right($right);
156
157 my $title = ucfirst($method) . ' Package';
158 $title =~ s/Uncancel/Un-cancel/;
159
160 my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum})
161   or die "Unknown pkgnum: $pkgnum";
162
163 my $part_pkg = $cust_pkg->part_pkg;
164
165 $date ||= $cust_pkg->get($method);
166 $date ||= time;
167
168 </%init>