disable display of auto-suspend dates unless enabled by config. at least until it...
[freeside.git] / httemplate / view / cust_main / packages / status.html
1 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
2   <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
3
4 %#this should use cust_pkg->status and cust_pkg->statuscolor eventually
5
6 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
7 %   my $cpr = $cust_pkg->last_cust_pkg_reason('cancel');
8
9     <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000', %opt ) %>
10
11     <% pkg_status_row_colspan(
12          ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
13          'align' => 'right', 'color' => 'ff0000', 'size' => '-2',
14        )
15     %>
16
17 %   unless ( $cust_pkg->get('setup') ) { 
18
19         <% pkg_status_row_colspan('Never billed') %>
20
21 %   } else { 
22
23        <% pkg_status_row( $cust_pkg, 'Setup', 'setup', %opt ) %>
24        <% pkg_status_row_changed( $cust_pkg, %opt ) %>
25        <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
26        <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp', %opt, curuser=>$curuser ) %>
27
28 %   } 
29 %
30 % } else { 
31 %
32 %   if ( $cust_pkg->get('susp') ) { #status: suspended
33 %     my $cpr = $cust_pkg->last_cust_pkg_reason('susp');
34
35     <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', %opt ) %>
36
37     <% pkg_status_row_colspan(
38          ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
39          'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
40        )
41     %>
42
43 %   unless ( $cust_pkg->get('setup') ) { 
44       <% pkg_status_row_colspan('Never billed') %>
45 %   } else { 
46       <% pkg_status_row($cust_pkg, 'Setup', 'setup', %opt ) %>
47 %   } 
48
49     <% pkg_status_row_changed( $cust_pkg, %opt ) %>
50     <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
51 %   # pkg_status_row($cust_pkg, 'Next bill', 'bill', %opt)
52     <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', %opt, curuser=>$curuser ) %>
53
54     <TR>
55       <TD COLSPAN=<%$colspan%>>
56         <FONT SIZE=-1>
57 %         if ( $curuser->access_right('Unsuspend customer package') ) { 
58             (&nbsp;<% pkg_unsuspend_link($cust_pkg) %>&nbsp;)
59 %         } 
60 %         if ( $curuser->access_right('Cancel customer package immediately') ) {
61             (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
62 %         } 
63         </FONT>
64       </TD>
65     </TR>
66
67 %   } else { #status: active
68 %
69 %     unless ( $cust_pkg->get('setup') ) { #not setup
70 %
71 %       unless ( $part_pkg->freq ) { 
72
73           <% pkg_status_row_colspan('Not&nbsp;yet&nbsp;billed&nbsp;(one-time&nbsp;charge)') %>
74
75           <TR>
76             <TD COLSPAN=<%$colspan%>>
77               <FONT SIZE=-1>
78 %               if ( $curuser->access_right('Cancel customer package immediately') ) { 
79                   (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
80 %               } 
81               </FONT>
82             </TD>
83           </TR>
84
85 %       } else { 
86
87          <% pkg_status_row_colspan("Not&nbsp;yet&nbsp;billed&nbsp;($billed_or_prepaid&nbsp;". myfreq($part_pkg). ')' ) %>
88
89 %       } 
90 %
91 %     } else { #setup
92 %
93 %       unless ( $part_pkg->freq ) { 
94
95           <% pkg_status_row_colspan('One-time&nbsp;charge') %>
96
97           <% pkg_status_row($cust_pkg, 'Billed', 'setup', %opt) %>
98
99 %       } else { 
100 %
101 %         if (scalar($cust_pkg->overlimit)) {
102
103             <% pkg_status_row_colspan(
104                  'Overlimit',
105                  $billed_or_prepaid. '&nbsp;'. myfreq($part_pkg),
106                  'color' => 'FFD000',
107                )
108             %>
109
110 %         } else {
111             <% pkg_status_row_colspan(
112                  'Active',
113                  $billed_or_prepaid. '&nbsp;'. myfreq($part_pkg),
114                  'color' => '00CC00',
115                )
116             %>
117 %         } 
118
119           <% pkg_status_row($cust_pkg, 'Setup', 'setup', %opt) %>
120
121 %       } 
122 %
123 %     } 
124 %
125 %     if ( $conf->exists('cust_pkg-show_autosuspend') ) {
126 %       my $autosuspend = pkg_autosuspend_time( $cust_pkg );
127 %       $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
128 %     }
129
130       <% pkg_status_row_changed( $cust_pkg, %opt ) %>
131       <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
132       <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
133       <% pkg_status_row_if($cust_pkg, 'Will automatically suspend by', 'autosuspend', %opt) %>
134       <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', %opt, curuser=>$curuser ) %>
135       <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', %opt, curuser=>$curuser ) %>
136
137 %     if ( $part_pkg->freq ) { 
138
139         <TR>
140           <TD COLSPAN=<%$colspan%>>
141             <FONT SIZE=-1>
142 %             if ( $curuser->access_right('Suspend customer package') ) { 
143                 (&nbsp;<% pkg_suspend_link($cust_pkg) %>&nbsp;)
144 %             } 
145 %             if ( $curuser->access_right('Suspend customer package later') ) { 
146                 (&nbsp;<% pkg_adjourn_link($cust_pkg) %>&nbsp;)
147 %             } 
148 %             if ( $curuser->access_right('Delay suspension events') ) { 
149                 (&nbsp;<% pkg_delay_link($cust_pkg) %>&nbsp;)
150 %             } 
151 %             if ( $curuser->access_right('Cancel customer package immediately') ) { 
152                 (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
153 %             } 
154 %             if ( $curuser->access_right('Cancel customer package later') ) { 
155                 (&nbsp;<% pkg_expire_link($cust_pkg) %>&nbsp;)
156 %             } 
157
158             <FONT>
159           </TD>
160         </TR>
161 %     }
162 %
163 %   } 
164 % } 
165
166   </TABLE>
167 </TD>
168
169 <%init>
170
171 my %opt = @_;
172
173 my $conf = new FS::Conf;
174
175 my $bgcolor  = $opt{'bgcolor'};
176 my $cust_pkg = $opt{'cust_pkg'};
177 my $part_pkg = $opt{'part_pkg'};
178 my $curuser  = $FS::CurrentUser::CurrentUser;
179 my $colspan  = $opt{'cust_pkg-display_times'} ? 8 : 4;
180 my $width    = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
181
182 #false laziness w/edit/REAL_cust_pkg.cgi
183 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
184 unless ( $part_pkg->is_prepaid ) {
185   $billed_or_prepaid = 'billed';
186   $last_bill_or_renewed = 'Last&nbsp;bill';
187   $next_bill_or_prepaid_until = 'Next&nbsp;bill';
188 } else {
189   $billed_or_prepaid = 'prepaid';
190   $last_bill_or_renewed = 'Renewed';
191   $next_bill_or_prepaid_until = 'Prepaid&nbsp;until';
192 }
193
194 #subroutines
195
196 sub myfreq {
197   my $part_pkg = shift;
198   my $freq = $part_pkg->freq_pretty;
199   $freq =~ s/ /&nbsp;/g;
200   $freq;
201 }
202
203 #false laziness w/package.html
204 sub pkg_link {
205   my($action, $label, $cust_pkg) = @_;
206   return '' unless $cust_pkg;
207   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
208 }
209
210 sub pkg_status_row {
211   my( $cust_pkg, $title, $field, %opt ) = @_;
212
213   my $color = $opt{'color'};
214
215   my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
216   $html   .= qq(<FONT COLOR="#$color"><B>) if length($color);
217   $html   .= qq($title&nbsp;);
218   $html   .= qq(</B></FONT>) if length($color);
219   $html   .= qq(</TD>);
220   $html   .= pkg_datestr($cust_pkg, $field, %opt).'</TR>';
221
222   $html;
223 }
224
225 sub pkg_status_row_if {
226   my( $cust_pkg, $title, $field, %opt ) = @_;
227   
228   $title = '<FONT SIZE=-1>(&nbsp;'. pkg_unadjourn_link($cust_pkg). '&nbsp;)&nbsp;</FONT>'. $title
229     if ( $field eq 'adjourn' &&
230          $opt{curuser}->access_right('Suspend customer package later')
231        );
232
233   $title = '<FONT SIZE=-1>(&nbsp;'. pkg_unexpire_link($cust_pkg). '&nbsp;)&nbsp;</FONT>'. $title
234     if ( $field eq 'expire' &&
235          $opt{curuser}->access_right('Cancel customer package later')
236        );
237
238   $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
239 }
240
241 sub pkg_status_row_changed {
242   my( $cust_pkg, %opt ) = @_;
243   return '' unless $cust_pkg->change_date;
244   my $html = pkg_status_row( $cust_pkg, 'Package&nbsp;changed', 'change_date', %opt );
245   my $old = $cust_pkg->old_cust_pkg;
246   if ( $old ) {
247     my $part_pkg = $old->part_pkg;
248     my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
249                 $part_pkg->pkg. ' - '. $part_pkg->comment;
250     $html .= pkg_status_row_colspan( $label, '', size=>'-1', align=>'right' );
251   }
252   $html;
253 }
254
255 sub pkg_status_row_colspan {
256   my($title, $addl, %opt) = @_;
257
258   my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
259   my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
260   my $size  = $opt{'size'}  ? 'SIZE="'.  $opt{'size'}. '"' : '';
261
262   my $html = qq(<TR><TD COLSPAN=$colspan $align>);
263   $html   .= qq(<FONT $color $size>) if length($color) || $size;
264   $html   .= qq(<B>) if $color && !$size;
265   $html   .= $title;
266   $html   .= qq(</B>) if $color && !$size;
267   $html   .= qq(</FONT>) if length($color) || $size;
268   $html   .= ",&nbsp;$addl" if length($addl);
269   $html   .= qq(</TD></TR>);
270
271   $html;
272
273 }
274
275 sub pkg_datestr {
276   my($cust_pkg, $field, %opt) = @_ or return '';
277   return '&nbsp;' unless $cust_pkg->get($field);
278   my $format = '<TD align="left"><B>%b</B></TD>'.
279                '<TD align="right"><B>&nbsp;%o,</B></TD>'.
280                '<TD align="right"><B>&nbsp;%Y</B></TD>';
281   #$format .= '&nbsp;<FONT SIZE=-3>%l:%M:%S%P&nbsp;%z</FONT>'
282   $format .= '<TD ALIGN="right"><B>&nbsp;%l</TD>'.
283              '<TD ALIGN="center"><B>:</B></TD>'.
284              '<TD ALIGN="left"><B>%M</B></TD>'.
285              '<TD ALIGN="left"><B>&nbsp;%P</B></TD>'
286     if $opt{'cust_pkg-display_times'};
287   my $strip = time2str($format, $cust_pkg->get($field) );
288   $strip =~ s/ (\d)/$1/g;
289   $strip;
290 }
291
292 sub pkg_suspend_link {
293   include( '/elements/popup_link-cust_pkg.html',
294              'action'      => $p. 'misc/cancel_pkg.html?method=suspend',
295              'label'       => 'Suspend&nbsp;now',
296              'actionlabel' => 'Suspend',
297              'color'       => '#FF9900',
298              'cust_pkg'    => shift,
299          )
300 }
301
302 sub pkg_adjourn_link {
303   include( '/elements/popup_link-cust_pkg.html',
304              'action'      => $p. 'misc/cancel_pkg.html?method=adjourn',
305              'label'       => 'Suspend&nbsp;later',
306              'actionlabel' => 'Adjourn',
307              'color'       => '#CC6600',
308              'cust_pkg'    => shift,
309          )
310 }
311
312 sub pkg_delay_link  {
313   include( '/elements/popup_link-cust_pkg.html',
314              'action'      => $p. 'misc/delay_susp_pkg.html',
315              'label'       => 'Delay&nbsp;suspend',
316              'actionlabel' => 'Delay suspend for',
317              'cust_pkg'    => shift,
318          )
319 }
320
321 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg',    'Unsuspend', @_ ); }
322 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', 'Abort',     @_ ); }
323 sub pkg_unexpire_link  { pkg_link('misc/unexpire_pkg',  'Abort',     @_ ); }
324
325 sub pkg_cancel_link {
326   include( '/elements/popup_link-cust_pkg.html',
327              'action'      => $p. 'misc/cancel_pkg.html?method=cancel',
328              'label'       => 'Cancel&nbsp;now',
329              'actionlabel' => 'Cancel',
330              'color'       => '#ff0000',
331              'cust_pkg'    => shift,
332          )
333 }
334
335 sub pkg_expire_link {
336   include( '/elements/popup_link-cust_pkg.html',
337              'action'      => $p. 'misc/cancel_pkg.html?method=expire',
338              'label'       => 'Cancel&nbsp;later',
339              'actionlabel' => 'Expire', #"Cancel package $num later"
340              'color'       => '#CC0000',
341              'cust_pkg'    => shift,
342          )
343 }
344
345 sub svc_recharge_link {
346   include( '/elements/popup_link-cust_svc.html',
347              'action'      => $p. 'misc/recharge_svc.html',
348              'label'       => 'Recharge',
349              'actionlabel' => 'Recharge',
350              'color'       => '#333399',
351              'cust_svc'    => shift,
352          )
353 }
354
355 sub pkg_autosuspend_time {
356   my $cust_pkg = shift or return '';
357   my $days = 7;
358   my $time = time;
359   my $pending_suspend = 0;
360   #this seems to be extremely inefficient...  and is slowing down all customer
361   #views
362   while ( $days > 0 &&
363           scalar(
364             grep { $_->part_event->action eq 'suspend' }
365             @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
366                                                     testonly => 1,
367                                                   ) }
368           )
369         )
370   {
371     $pending_suspend = 1;
372     $days--;
373   }
374
375   $pending_suspend ? time + ($days + 1) * 86400 : '';
376
377 }
378
379 </%init>