Add warning of svc unprovisioning on pkg cancel. See RT#29087.
[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>
10 <% emt(ucfirst($method)." [_1]", $part_pkg->pkg_comment(cust_pkg=>$cust_pkg) ) %>
11 <BR>
12 <font color="red"><% $unprovision_warning |h %></font>
13 <table style="background-color: #cccccc; border-spacing: 2; width: 100%">
14
15 % my $date_init = 0;
16 % if ($method eq 'expire' || $method eq 'adjourn' || $method eq 'resume') {
17 %   $submit =~ /^(\w*)\s/;
18   <& /elements/tr-input-date-field.html, {
19       'name'    => 'date',
20       'value'   => $date,
21       'label'   => mt("$1 package on"),
22       'format'  => $date_format,
23   } &>
24 %   $date_init = 1;
25 % }
26
27 % if ($method eq 'uncancel' ) {
28 %
29 % #XXX customer also requested setup
30 % # setup: what usefulness is changing or blanking this?  re-charge setup fee?
31 % #        an option that says that would be better if that's what we want to do
32
33 % # last_bill: isn't this informational?  what good would editing it do?
34 % #            something about invoice display?
35   <& /elements/tr-input-date-field.html, {
36       'name'    => 'last_bill',
37       'value'   => ( $cgi->param('last_bill') || $cust_pkg->get('last_bill') ),
38       'label'   => mt("Last bill date"),
39       'format'  => $date_format,
40   } &>
41
42   <& /elements/tr-input-date-field.html, {
43       'name'    => 'bill',
44       'value'   => ( $cgi->param('bill') || $cust_pkg->get('bill') ),
45       'label'   => mt("Next bill date"),
46       'format'  => $date_format,
47   } &>
48
49   <& /elements/tr-checkbox.html,
50        'label'  => mt("Uncancel even if service reprovisioning fails"),
51        'field'  => 'svc_not_fatal',
52        'value'  => 'Y',
53   &>
54
55 %   $date_init = 1;
56 %   my @uncancel_svcs = sort { $b->{'reprovisionable'} <=> $a->{'reprovisionable'} }
57 %                       sort { $a->{'svcpart'} <=> $b->{'svcpart'} } 
58 %                       $cust_pkg->uncancel_svc_summary();
59 %   if (@uncancel_svcs) {
60 <TR><TD COLSPAN="2">&nbsp;</TD></TR>
61 <TR><TH ALIGN="right"><% emt("Re-provision the following services") %></TH><TD></TD>
62 %     foreach my $uncancel_svc (@uncancel_svcs) {
63 %       my $uncancel_curr_value = $uncancel_svc->{'uncancel_svcnum'};
64 %       my $uncancel_disabled = '';
65 %       my $uncancel_postfix = '';
66 %       if ($cgi->param('error')) {
67 %         $uncancel_curr_value = '' unless grep { $_ == $uncancel_svc->{'uncancel_svcnum'} } $cgi->param('only_svcnum');
68 %       }
69 %       unless ($uncancel_svc->{'reprovisionable'}) {
70 %         $uncancel_curr_value = '';
71 %         $uncancel_disabled = 1;
72 %         $uncancel_postfix = '<I>(' . emt('Cannot be reprovisioned') . ')</I>';
73 %       }
74   <& /elements/tr-checkbox.html,
75        'label'  => $uncancel_svc->{'svc'} . ': ' . $uncancel_svc->{'label'},
76        'field'  => 'only_svcnum',
77        'value'  => $uncancel_svc->{'uncancel_svcnum'},
78        'curr_value' => $uncancel_curr_value,
79        'disabled'   => $uncancel_disabled,
80        'cell_style' => 'font-weight: normal',
81        'postfix' => $uncancel_postfix,
82   &>
83 %     }
84 %   }
85 % }
86
87 % unless ( $method eq 'resume' || $method eq 'uncancel' ) {
88   <& /elements/tr-select-reason.html,
89        field          => 'reasonnum',
90        reason_class   => $class,
91        curr_value     => $reasonnum,
92        control_button => "confirm_cancel_pkg_button",
93   &>
94 % }
95
96 % if (( $method eq 'adjourn' || $method eq 'suspend' ) && $curuser->access_right('Customize billing during suspension')) {
97     <TR><TD COLSPAN=2>
98 %   if ( $part_pkg->option('suspend_bill', 1) ) {
99       <& /elements/checkbox.html, name=>'no_suspend_bill', value=>'Y' &>
100       Disable recurring billing while suspended
101 %   } else {
102       <& /elements/checkbox.html, name=>'suspend_bill', value=>'Y' &>
103       Continue recurring billing while suspended
104 %   }
105     </TD></TR>
106 % }
107
108 % if ( ( $method eq 'adjourn' || $method eq 'suspend' ) and 
109 %      $curuser->access_right('Unsuspend customer package') )  { #later?
110 %   my $resume_date = $cgi->param('error') 
111 %                     ? str2time($cgi->param('resume_date'))
112 %                     : $cust_pkg->get('resume');
113
114   <& /elements/tr-input-date-field.html, {
115       'name'    => 'resume_date',
116       'value'   => $resume_date,
117       'label'   => mt('Unsuspend on'),
118       'format'  => $date_format,
119       'noinit'  => $date_init,
120   } &>
121 % }
122 </TABLE>
123
124 <BR>
125 <INPUT TYPE="submit" NAME="submit" ID="confirm_cancel_pkg_button" 
126   VALUE="<% mt($submit) |h %>"
127   <% $method !~ /^(resume|uncancel)$/ ? 'DISABLED' : '' %>>
128
129 </FORM>
130 </BODY>
131 </HTML>
132
133 <%init>
134 use Date::Parse qw(str2time);
135
136 my $conf = new FS::Conf;
137 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
138
139 my $date;
140
141 my($pkgnum, $reasonnum);
142 if ( $cgi->param('error') ) {
143   $pkgnum    = $cgi->param('pkgnum');
144   $reasonnum = $cgi->param('reasonnum');
145   $date      = str2time($cgi->param('date'));
146 } elsif ( $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
147   $pkgnum    = $1;
148   $reasonnum = '';
149 } else {
150   die "illegal query ". $cgi->keywords;
151 }
152
153 $cgi->param('method') =~ /^(\w+)$/ or die 'illegal method';
154 my $method = $1;
155
156 my($class, $submit, $right);
157 if ($method eq 'cancel') {
158   $class  = 'C';
159   $submit = 'Cancel Now';
160   $right  = 'Cancel customer package immediately';
161 } elsif ($method eq 'expire') {
162   $class  = 'C';
163   $submit = 'Cancel Later';
164   $right  = 'Cancel customer package later';
165 } elsif ($method eq 'suspend') {
166   $class  = 'S';
167   $submit = 'Suspend Now';
168   $right  = 'Suspend customer package';
169 } elsif ($method eq 'adjourn') {
170   $class  = 'S';
171   $submit = "Suspend Later";
172   $right  = 'Suspend customer package later';
173 } elsif ( $method eq 'resume') {
174   $class  = '';
175   $submit = 'Unsuspend Later';
176   $right  = 'Unsuspend customer package'; #later?
177 } elsif ( $method eq 'uncancel') {
178   $class  = '';
179   $submit = 'Un-Cancel';
180   $right  = 'Un-cancel customer package'; #later?
181 } else {
182   die 'illegal query (unknown method param)';
183 }
184
185 my $curuser = $FS::CurrentUser::CurrentUser;
186 die "access denied" unless $curuser->access_right($right);
187
188 my $title = ucfirst($method) . ' Package';
189 $title =~ s/Uncancel/Un-cancel/;
190
191 my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum})
192   or die "Unknown pkgnum: $pkgnum";
193
194 my $part_pkg = $cust_pkg->part_pkg;
195
196 my $unprovision_warning = '';
197 {
198     my @services_w_export;
199     for ( $cust_pkg->cust_svc ) {
200         push( @services_w_export, ($_->label)[0] . ': ' . ($_->label)[1], )
201           if $_->part_svc->export_svc;
202     }
203     if ( @services_w_export ) {
204         $unprovision_warning = 'NOTE: This package has ' . @services_w_export
205           . ' ' . PL( "service", @services_w_export )
206           . ' that will be unprovisioned';
207         $unprovision_warning .= ' (' . join( ', ', @services_w_export, ) . ')'
208           if @services_w_export < 10;
209         $unprovision_warning .= '.';
210     }
211 }
212
213 $date ||= $cust_pkg->get($method);
214 $date ||= time;
215
216 </%init>