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