RT#17599: display cancelled services from history
[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 <table style="background-color: #cccccc; border-spacing: 2; width: 100%">
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 service reprovisioning fails"),
49        'field'  => 'svc_not_fatal',
50        'value'  => 'Y',
51   &>
52
53 %   $date_init = 1;
54 %   my @uncancel_svcs = sort { $b->{'reprovisionable'} <=> $a->{'reprovisionable'} }
55 %                       sort { $a->{'svcpart'} <=> $b->{'svcpart'} } 
56 %                       $cust_pkg->uncancel_svc_summary();
57 %   if (@uncancel_svcs) {
58 <TR><TD COLSPAN="2">&nbsp;</TD></TR>
59 <TR><TH ALIGN="right"><% emt("Re-provision the following services") %></TH><TD></TD>
60 %     foreach my $uncancel_svc (@uncancel_svcs) {
61 %       my $uncancel_curr_value = $uncancel_svc->{'uncancel_svcnum'};
62 %       my $uncancel_disabled = '';
63 %       if ($cgi->param('error')) {
64 %         $uncancel_curr_value = '' unless grep { $_ == $uncancel_svc->{'_uncancel_svcnum'} } $cgi->param('only_svcnum');
65 %       }
66 %       unless ($uncancel_svc->{'reprovisionable'}) {
67 %         $uncancel_curr_value = '';
68 %         $uncancel_disabled = 1;
69 %       }
70   <& /elements/tr-checkbox.html,
71        'label'  => $uncancel_svc->{'svc'} . ': ' . $uncancel_svc->{'label'},
72        'field'  => 'only_svcnum',
73        'value'  => $uncancel_svc->{'uncancel_svcnum'},
74        'curr_value' => $uncancel_curr_value,
75        'disabled'   => $uncancel_disabled,
76        'cell_style' => 'font-weight: normal;'
77   &>
78 %     }
79 %   }
80 % }
81
82 % unless ( $method eq 'resume' || $method eq 'uncancel' ) {
83   <& /elements/tr-select-reason.html,
84        field          => 'reasonnum',
85        reason_class   => $class,
86        curr_value     => $reasonnum,
87        control_button => "confirm_cancel_pkg_button",
88   &>
89 % }
90
91 % if (( $method eq 'adjourn' || $method eq 'suspend' ) && $curuser->access_right('Customize billing during suspension')) {
92     <TR><TD COLSPAN=2>
93 %   if ( $part_pkg->option('suspend_bill', 1) ) {
94       <& /elements/checkbox.html, name=>'no_suspend_bill', value=>'Y' &>
95       Disable recurring billing while suspended
96 %   } else {
97       <& /elements/checkbox.html, name=>'suspend_bill', value=>'Y' &>
98       Continue recurring billing while suspended
99 %   }
100     </TD></TR>
101 % }
102
103 % if ( ( $method eq 'adjourn' || $method eq 'suspend' ) and 
104 %      $curuser->access_right('Unsuspend customer package') )  { #later?
105 %   my $resume_date = $cgi->param('error') 
106 %                     ? str2time($cgi->param('resume_date'))
107 %                     : $cust_pkg->get('resume');
108
109   <& /elements/tr-input-date-field.html, {
110       'name'    => 'resume_date',
111       'value'   => $resume_date,
112       'label'   => mt('Unsuspend on'),
113       'format'  => $date_format,
114       'noinit'  => $date_init,
115   } &>
116 % }
117 </TABLE>
118
119 <BR>
120 <INPUT TYPE="submit" NAME="submit" ID="confirm_cancel_pkg_button" 
121   VALUE="<% mt($submit) |h %>"
122   <% $method !~ /^(resume|uncancel)$/ ? 'DISABLED' : '' %>>
123
124 </FORM>
125 </BODY>
126 </HTML>
127
128 <%init>
129 use Date::Parse qw(str2time);
130
131 my $conf = new FS::Conf;
132 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
133
134 my $date;
135
136 my($pkgnum, $reasonnum);
137 if ( $cgi->param('error') ) {
138   $pkgnum    = $cgi->param('pkgnum');
139   $reasonnum = $cgi->param('reasonnum');
140   $date      = str2time($cgi->param('date'));
141 } elsif ( $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
142   $pkgnum    = $1;
143   $reasonnum = '';
144 } else {
145   die "illegal query ". $cgi->keywords;
146 }
147
148 $cgi->param('method') =~ /^(\w+)$/ or die 'illegal method';
149 my $method = $1;
150
151 my($class, $submit, $right);
152 if ($method eq 'cancel') {
153   $class  = 'C';
154   $submit = 'Cancel Now';
155   $right  = 'Cancel customer package immediately';
156 } elsif ($method eq 'expire') {
157   $class  = 'C';
158   $submit = 'Cancel Later';
159   $right  = 'Cancel customer package later';
160 } elsif ($method eq 'suspend') {
161   $class  = 'S';
162   $submit = 'Suspend Now';
163   $right  = 'Suspend customer package';
164 } elsif ($method eq 'adjourn') {
165   $class  = 'S';
166   $submit = "Suspend Later";
167   $right  = 'Suspend customer package later';
168 } elsif ( $method eq 'resume') {
169   $class  = '';
170   $submit = 'Unsuspend Later';
171   $right  = 'Unsuspend customer package'; #later?
172 } elsif ( $method eq 'uncancel') {
173   $class  = '';
174   $submit = 'Un-Cancel';
175   $right  = 'Un-cancel customer package'; #later?
176 } else {
177   die 'illegal query (unknown method param)';
178 }
179
180 my $curuser = $FS::CurrentUser::CurrentUser;
181 die "access denied" unless $curuser->access_right($right);
182
183 my $title = ucfirst($method) . ' Package';
184 $title =~ s/Uncancel/Un-cancel/;
185
186 my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum})
187   or die "Unknown pkgnum: $pkgnum";
188
189 my $part_pkg = $cust_pkg->part_pkg;
190
191 $date ||= $cust_pkg->get($method);
192 $date ||= time;
193
194 </%init>