improve unsuspend behavior for packages on hold, #28508
[freeside.git] / httemplate / view / cust_main / packages / status.html
1 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" VALIGN="top">
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 ( $supplemental ) {
7     <% pkg_status_row_colspan($cust_pkg, emt('Supplemental'), '', 'color' => '7777FF', %opt) %>
8 % } elsif ( $cust_pkg->order_date ) {
9     <% pkg_status_row($cust_pkg, emt('Ordered'), 'order_date', %opt ) %>
10 % }
11
12 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
13 %   my $cpr = $cust_pkg->last_cust_pkg_reason('cancel');
14
15     <% pkg_status_row($cust_pkg, emt('Cancelled'), 'cancel', 'color'=>'FF0000', %opt ) %>
16
17     <% pkg_status_row_detached($cust_pkg, %opt) %>
18
19     <% pkg_reason_row($cust_pkg, $cpr, color => 'ff0000', %opt) %>
20
21 %   unless ( $cust_pkg->get('setup') ) { 
22
23         <% pkg_status_row_colspan( $cust_pkg, emt('Never billed'), '', %opt, ) %>
24
25 %   } else { 
26
27        <% pkg_status_row( $cust_pkg, emt('Setup'), 'setup', %opt ) %>
28        <% pkg_status_row_changed( $cust_pkg, %opt ) %>
29        <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
30        <% pkg_status_row_if( $cust_pkg, emt('Suspended'), 'susp', %opt, curuser=>$curuser ) %>
31
32 %   } 
33 %
34 %   if ( $part_pkg->freq && !$supplemental && !$cust_pkg->change_custnum ) { #?
35
36       <TR>
37         <TD COLSPAN=<%$opt{colspan}%>>
38           <FONT SIZE=-1>
39 %           if ( $curuser->access_right('Un-cancel customer package') && ! $opt{no_links} ) { 
40               (&nbsp;<% pkg_uncancel_link($cust_pkg) %>&nbsp;)
41 %           } 
42           <FONT>
43         </TD>
44       </TR>
45 %   }
46 %
47 % } else {
48 %
49 %   if ( $cust_pkg->get('susp') ) { #suspended or on hold
50 %
51 %     #if ( $cust_pkg->order_date eq $cust_pkg->get('susp') ) { # inconsistent with FS::cust_pkg::status
52 %     if ( ! $cust_pkg->setup ) { #status: on hold
53
54         <% pkg_status_row( $cust_pkg, emt('On Hold'), '', 'color'=>'7E0079', %opt ) %>
55
56 %     } else { #status: suspended
57
58         <% pkg_status_row( $cust_pkg, emt('Suspended'), 'susp', 'color'=>'FF9900', %opt ) %>
59 %       my $cpr = $cust_pkg->last_cust_pkg_reason('susp');
60         <% pkg_reason_row( $cust_pkg, $cpr, 'color' => 'FF9900', %opt ) %>
61
62 %     }
63
64     <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
65
66     <% pkg_status_row_discount( $cust_pkg, %opt ) %>
67
68 %   unless ( $cust_pkg->order_date eq $cust_pkg->get('susp') ) { #on hold
69 %     unless ( $cust_pkg->get('setup') ) { 
70         <% pkg_status_row_colspan( $cust_pkg, emt('Never billed'), '', %opt ) %>
71 %     } else { 
72         <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt ) %>
73 %     }
74 %   } 
75
76     <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
77
78     <% pkg_status_row_changed( $cust_pkg, %opt ) %>
79     <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
80 %   if ( $cust_pkg->option('suspend_bill', 1)
81 %        || ( $part_pkg->option('suspend_bill', 1)
82 %               && ! $cust_pkg->option('no_suspend_bill',1)
83 %           )
84 %      )
85 %   {
86       <% pkg_status_row_if( $cust_pkg, emt('Next bill'), 'bill', %opt, curuser=>$curuser ) %>
87 %   }
88     <% pkg_status_row_if( $cust_pkg, emt('Will resume'), 'resume', %opt, curuser=>$curuser ) %>
89     <% pkg_status_row_expire($cust_pkg, %opt, curuser=>$curuser) %>
90     <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
91
92 % if ( !$supplemental && ! $opt{no_links} && !$change_from ) {
93       <TR>
94         <TD COLSPAN=<%$opt{colspan}%>>
95           <FONT SIZE=-1>
96 %           if ( $cust_pkg->change_to_pkgnum ) {
97 %               # then you can modify the package change
98 %               if ( $curuser->access_right('Change customer package') ) {
99                 (&nbsp;<% pkg_change_now_link($cust_pkg) %>&nbsp;)
100                 (&nbsp;<% pkg_change_later_link($cust_pkg) %>&nbsp;)
101                 (&nbsp;<% pkg_unchange_link($cust_pkg) %>&nbsp;)
102                 <BR>
103 %               }
104 %           }
105 %           if ( $curuser->access_right('Unsuspend customer package') ) { 
106 %             if ( $cust_pkg->order_date eq $cust_pkg->get('susp') ) { #on hold
107                 (&nbsp;<% pkg_link('misc/unsusp_pkg', emt('Start bililng now'), $cust_pkg) %>&nbsp;)
108 %             } else {
109                 (&nbsp;<% pkg_unsuspend_link($cust_pkg) %>&nbsp;)
110                 (&nbsp;<% pkg_resume_link($cust_pkg) %>&nbsp;)
111 %             }
112 %           }
113 %           if ( !$cust_pkg->change_to_pkgnum and
114 %                $curuser->access_right('Cancel customer package immediately')
115 %           ) {
116               (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
117 %           } 
118           </FONT>
119         </TD>
120       </TR>
121 %     }
122 %
123 %   } else { #status: active
124 %
125 %     if ( $change_from ) { # future change
126 %
127           <% pkg_status_row_colspan( $cust_pkg, emt('Waiting for package change'), '', %opt ) %>
128           <% pkg_status_row( $cust_pkg,
129                              emt('Will be activated on'),
130                              'start_date',
131                              %opt ) %>
132 %
133 %     } elsif ( ! $cust_pkg->get('setup') ) { # not setup
134 %
135 %       unless ( $part_pkg->freq ) { # one-time charge
136
137           <% pkg_status_row_colspan( $cust_pkg, emt('Not yet billed (one-time charge)'), '', %opt ) %>
138
139           <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
140
141           <% pkg_status_row_discount( $cust_pkg, %opt ) %>
142
143           <% pkg_status_row_if(
144                $cust_pkg,
145                ( $part_pkg->freq ? emt('Start billing') : emt('Bill on') ),
146                'start_date',
147                %opt
148              )
149           %>
150
151           <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
152
153 %         if ( !$supplemental && ! $opt{no_links} ) {
154           <TR>
155             <TD COLSPAN=<%$opt{colspan}%>>
156               <FONT SIZE=-1>
157 %               if ( $curuser->access_right('Cancel customer package immediately') ) { 
158                   (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
159 %               } 
160               </FONT>
161             </TD>
162           </TR>
163 %         }
164
165 %       } else { 
166
167           <% pkg_status_row_colspan($cust_pkg, emt("Not yet billed ($billed_or_prepaid [_1])", myfreq($part_pkg) ), '', %opt ) %>
168
169           <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
170
171           <% pkg_status_row_discount( $cust_pkg, %opt ) %>
172
173           <% pkg_status_row_if($cust_pkg, emt('Start billing'), 'start_date', %opt) %>
174           <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
175
176 %       } 
177 %
178 %     } else { #setup
179 %
180 %       unless ( $part_pkg->freq ) { 
181
182           <% pkg_status_row_colspan($cust_pkg, emt('One-time charge'), '', %opt ) %>
183
184           <% pkg_status_row($cust_pkg, emt('Billed'), 'setup', %opt) %>
185
186           <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
187
188           <% pkg_status_row_discount( $cust_pkg, %opt ) %>
189
190           <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
191
192 %       } else { 
193 %
194 %         my $num_cust_svc = $cust_pkg->num_cust_svc;
195 %         my $summarize = $opt{'cust_pkg-large_pkg_size'} > 0
196 %                           && $opt{'cust_pkg-large_pkg_size'} <= $num_cust_svc;
197 %
198 %         #overlimit process is expensive with many services, so skip w/summary
199 %         if ( !$summarize && scalar($cust_pkg->overlimit) ) {
200
201             <% pkg_status_row_colspan( $cust_pkg,
202                  emt('Overlimit'),
203                  $billed_or_prepaid. '&nbsp;'. myfreq($part_pkg),
204                  'color'=>'FFD000',
205                  %opt
206                )
207             %>
208
209 %         } else {
210             <% pkg_status_row_colspan( $cust_pkg,
211                  emt('Active'),
212                  $billed_or_prepaid. '&nbsp;'. myfreq($part_pkg),
213                  'color'=>'00CC00',
214                  %opt
215                )
216             %>
217 %         } 
218
219           <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
220
221           <% pkg_status_row_discount( $cust_pkg, %opt ) %>
222
223           <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt) %>
224
225           <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
226
227 %       } 
228 %
229 %     }
230 %
231 %     if ( $opt{'cust_pkg-show_autosuspend'} ) {
232 %       my $autosuspend = pkg_autosuspend_time( $cust_pkg );
233 %       $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
234 %     }
235
236       <% pkg_status_row_changed( $cust_pkg, %opt ) %>
237       <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
238       <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
239       <% pkg_status_row_if($cust_pkg, emt('Will automatically suspend by'), 'autosuspend', %opt) %>
240       <% pkg_status_row_if($cust_pkg, emt('Automatic suspension delayed until'), 'dundate', %opt) %>
241       <% pkg_status_row_if( $cust_pkg, emt('Will suspend on'), 'adjourn', %opt, curuser=>$curuser ) %>
242       <% pkg_status_row_if( $cust_pkg, emt('Will resume on'), 'resume', %opt, curuser=>$curuser ) %>
243       <% pkg_status_row_expire($cust_pkg, %opt, curuser=>$curuser) %>
244       <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
245
246 %     if ( $part_pkg->freq and !$supplemental && ! $opt{no_links} ) { 
247
248         <TR>
249           <TD COLSPAN=<%$opt{colspan}%>>
250             <FONT SIZE=-1>
251 % # action links
252 %           if ( $change_from ) {
253 %               # nothing
254 %           } elsif ( $cust_pkg->change_to_pkgnum ) {
255 %               # then you can modify the package change
256 %               if ( $curuser->access_right('Change customer package') ) {
257                 (&nbsp;<% pkg_change_now_link($cust_pkg) %>&nbsp;)
258                 (&nbsp;<% pkg_change_later_link($cust_pkg) %>&nbsp;)
259                 (&nbsp;<% pkg_unchange_link($cust_pkg) %>&nbsp;)
260                 <BR>
261 %               }
262 %           }
263
264 %           # suspension actions--always available
265 %           if ( $curuser->access_right('Suspend customer package') ) { 
266               (&nbsp;<% pkg_suspend_link($cust_pkg) %>&nbsp;)
267 %           } 
268 %           if ( $curuser->access_right('Suspend customer package later') ) { 
269               (&nbsp;<% pkg_adjourn_link($cust_pkg) %>&nbsp;)
270 %           } 
271 %           if ( $curuser->access_right('Delay suspension events') ) { 
272               (&nbsp;<% pkg_delay_link($cust_pkg) %>&nbsp;)
273 %           }
274 %
275 %           if ( $change_from or $cust_pkg->change_to_pkgnum ) {
276 %               # you can't cancel the package while in this state
277 %           } else { # the normal case: links to cancel the package
278               <BR>
279 %             if ( $curuser->access_right('Cancel customer package immediately') ) { 
280                 (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
281 %             }
282 %             if ( $curuser->access_right('Cancel customer package later') ) { 
283                 (&nbsp;<% pkg_expire_link($cust_pkg) %>&nbsp;)
284 %             } 
285 %           }
286
287             <FONT>
288           </TD>
289         </TR>
290 %     }
291 %
292 %   } 
293 % } 
294
295   </TABLE>
296 </TD>
297 <%init>
298
299 my %opt = @_;
300
301 my $bgcolor  = $opt{'bgcolor'};
302 my $cust_pkg = $opt{'cust_pkg'};
303 my $part_pkg = $opt{'part_pkg'};
304 my $curuser  = $FS::CurrentUser::CurrentUser;
305 my $width    = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
306 my $supplemental = $opt{'supplemental'};
307 my $change_from  = $opt{'change_from'};
308
309 $opt{colspan}  = $opt{'cust_pkg-display_times'} ? 8 : 4;
310
311 #false laziness w/edit/REAL_cust_pkg.cgi
312 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
313 unless ( $part_pkg->is_prepaid ) {
314   $billed_or_prepaid = 'billed';
315   $last_bill_or_renewed = 'Last&nbsp;bill';
316   $next_bill_or_prepaid_until = 'Next&nbsp;bill';
317 } else {
318   $billed_or_prepaid = 'prepaid';
319   $last_bill_or_renewed = 'Renewed';
320   $next_bill_or_prepaid_until = 'Prepaid&nbsp;until';
321 }
322
323 #subroutines
324
325 sub myfreq {
326   my $part_pkg = shift;
327   my $freq = $part_pkg->freq_pretty;
328   #$freq =~ s/ /&nbsp;/g;
329   $freq;
330 }
331
332 #false laziness w/package.html
333 sub pkg_link {
334   my($action, $label, $cust_pkg) = @_;
335   return '' unless $cust_pkg;
336   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
337 }
338
339 sub pkg_status_row {
340   my( $cust_pkg, $title, $field, %opt ) = @_;
341
342   if ( $field and $cust_pkg->main_pkgnum ) {
343     # for supplemental packages, we mostly only show these if they're 
344     # different from the main package
345     my $main_pkg = $cust_pkg-> main_pkg;
346     if (    $main_pkg->get($field) ne $cust_pkg->get($field)
347         # with some exceptions
348         or  $field eq 'bill'
349         or  $field eq 'last_bill'
350         or  $field eq 'setup'
351         or  $field eq 'susp'
352         or  $field eq 'cancel'
353       ) {
354       # handle it normally
355     } else {
356       return '';
357     }
358   }
359
360   my $color = $opt{'color'};
361
362   my $html = qq(<TR><TD WIDTH="$width" ALIGN="right">);
363   $html   .= qq(<FONT COLOR="#$color"><B>) if length($color);
364   $html   .= qq($title&nbsp;);
365   $html   .= qq(</B></FONT>) if length($color);
366
367   if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
368     $html .= ' (Balance:&nbsp;<B>'. $opt{'money_char'}.
369              $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
370              '</B>)';
371   }
372
373   $html   .= qq(</TD>);
374   $html   .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
375
376   $html;
377 }
378
379 sub pkg_status_row_if {
380   my( $cust_pkg, $title, $field, %opt ) = @_;
381   
382   $title = '<FONT SIZE=-1>(&nbsp;'. pkg_unadjourn_link($cust_pkg). '&nbsp;)&nbsp;</FONT>'. $title
383     if ( $field eq 'adjourn' &&
384          $opt{curuser}->access_right('Suspend customer package later')
385        );
386
387   $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
388 }
389
390 sub pkg_status_row_expire {
391   my $cust_pkg = shift;
392   my %opt = @_;
393   return unless $cust_pkg->get('expire');
394
395   my $title;
396
397   if ( $cust_pkg->get('change_to_pkg') ) {
398     if ( $cust_pkg->change_to_pkg->pkgpart != $cust_pkg->pkgpart ) {
399       $title = mt('Will change to <b>[_1]</b> on',
400                  $cust_pkg->change_to_pkg->part_pkg->pkg);
401     } elsif ( $cust_pkg->change_to_pkg->locationnum != $cust_pkg->locationnum )
402     {
403       $title = mt('Will <b>change location</b> on');
404     } else {
405       # FS::cust_pkg->change_later should have prevented this, but 
406       # just so that we can display _something_
407       $title = '<font color="#ff0000">Unknown package change</font>';
408     }
409
410   } else {
411
412     $title = emt('Expires');
413     if ( $opt{curuser}->access_right('Cancel customer package later')) {
414       $title = '<FONT SIZE=-1>(&nbsp;'. pkg_unexpire_link($cust_pkg). '&nbsp;)&nbsp;</FONT>'. $title;
415     }
416
417   }
418
419   pkg_status_row( $cust_pkg, $title, 'expire', %opt );
420 }
421
422 sub pkg_status_row_changed {
423   my( $cust_pkg, %opt ) = @_;
424
425   return '' unless $cust_pkg->change_date;
426
427   my $html =
428     pkg_status_row( $cust_pkg, emt('Package changed'), 'change_date', %opt );
429
430   my $old = $cust_pkg->old_cust_pkg;
431   if ( $old ) {
432     my $part_pkg = $old->part_pkg;
433     $html .= pkg_status_row_colspan(
434       $cust_pkg, 
435       emt("Changed from [_1]: [_2]",
436              $cust_pkg->change_pkgnum,
437              $part_pkg->pkg_comment(cust_pkg=>$old, nopartpkg=>1)
438          ),
439       '',
440       'size'    => '-1',
441       'align'   => 'right',
442     );
443   }
444
445   $html;
446 }
447
448 sub pkg_status_row_detached {
449   my( $cust_pkg, %opt ) = @_;
450
451   return '' unless $cust_pkg->change_custnum;
452
453   my $html = '';
454
455   my $cust_main = $cust_pkg->change_cust_main;
456   if ( $cust_main ) {
457
458     my $cust_link = '<A HREF="cust_main.cgi?'.  $cust_pkg->change_custnum. '">'.
459                       encode_entities( $cust_main->name ).
460                     '</A>';
461
462     my $what = $opt{'pkg_attached'} ? 'Attached' : 'Detached';
463
464     $html .= pkg_status_row_colspan( $cust_pkg, 
465                                      emt("$what to customer #[_1]: ",
466                                             $cust_pkg->change_custnum
467                                         ).
468                                        $cust_link,
469                                      '',
470                                      'size'    => '-1',
471                                      'align'   => 'right',
472                                      'colspan' => 4,
473                                    );
474   }
475
476   $html;
477 }
478
479 sub pkg_status_row_noauto {
480   my( $cust_pkg, %opt ) = @_;
481   my $part_pkg = $opt{'part_pkg'};
482   return '' unless $cust_pkg->no_auto || $part_pkg->no_auto;
483
484   #inefficient, should be passed in
485   my $cust_main = $cust_pkg->cust_main;
486
487   return '' unless $cust_main->payby =~ /^(CARD|CHEK)$/;
488   my $what = lc(FS::payby->shortname($cust_main->payby));
489
490   pkg_status_row_colspan( $cust_pkg, emt("No automatic $what charge"), '');
491 }
492
493 sub pkg_status_row_discount {
494   my( $cust_pkg, %opt ) = @_;
495
496   my $html;
497
498   foreach my $cust_pkg_discount (@{ $cust_pkg->{_cust_pkg_discount_active} }) {
499
500     my $discount = $cust_pkg_discount->discount;
501
502     my $label = '<B>'.emt('Discount').'</B>: '. $discount->description;
503     if ( $discount->months ) {
504       my $remaining = $discount->months - $cust_pkg_discount->months_used;
505       $remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
506       $label .= emt("([_1] months remaining)",$remaining);
507     }
508
509     $label .= ' <FONT SIZE="-1">('.
510                 '<A HREF="../misc/delete-cust_pkg_discount.html?'.
511                   $cust_pkg_discount->pkgdiscountnum.
512                 '">'.emt('remove discount').'</A>)</FONT>';
513
514     $html .= pkg_status_row_colspan( $cust_pkg, $label, '', %opt );
515
516   }
517
518   $html;
519 }
520
521 sub pkg_reason_row {
522   my ($cust_pkg, $cpr, %opt) = @_;
523   return '' if $cust_pkg->main_pkgnum;
524
525   my $reasontext = '';
526   $reasontext = $cpr->reasontext . ' by ' . $cpr->otaker if $cpr;
527   pkg_status_row_colspan( $cust_pkg, $reasontext, '',
528     'align'=>'right', 'size'=>'-2', %opt
529   );
530 }
531
532 sub pkg_status_row_colspan {
533   my($cust_pkg, $title, $addl, %opt) = @_;
534
535   my $colspan  = $opt{'colspan'};
536
537   my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
538   my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
539   my $size  = $opt{'size'}  ? 'SIZE="'.  $opt{'size'}. '"' : '';
540
541   my $html = qq(<TR><TD COLSPAN=$colspan $align>);
542   $html   .= qq(<FONT $color $size>) if length($color) || $size;
543   $html   .= qq(<B>) if $color && !$size;
544   $html   .= $title;
545   $html   .= qq(</B>) if $color && !$size;
546   $html   .= qq(</FONT>) if length($color) || $size;
547   $html   .= ",&nbsp;$addl" if length($addl);
548
549   if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
550     $html .= ' (Balance:&nbsp;<B>'. $opt{'money_char'}.
551              $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
552              '</B>)';
553   }
554
555   $html   .= qq(</TD></TR>);
556
557   $html;
558
559 }
560
561 sub pkg_datestr {
562   my($cust_pkg, $field, %opt) = @_ or return '';
563   return '&nbsp;' unless $cust_pkg->get($field);
564   my $format = '<TD align="left"><B>%b</B></TD>'.
565                '<TD align="right"><B>&nbsp;%o,</B></TD>'.
566                '<TD align="right"><B>&nbsp;%Y</B></TD>';
567   #$format .= '&nbsp;<FONT SIZE=-3>%l:%M:%S%P&nbsp;%z</FONT>'
568   $format .= '<TD ALIGN="right"><B>&nbsp;%l</TD>'.
569              '<TD ALIGN="center"><B>:</B></TD>'.
570              '<TD ALIGN="left"><B>%M</B></TD>'.
571              '<TD ALIGN="left"><B>&nbsp;%P</B></TD>'
572     if $opt{'cust_pkg-display_times'};
573   my $strip = time2str($format, $cust_pkg->get($field) );
574   $strip =~ s/ (\d)/$1/g;
575   $strip;
576 }
577
578 sub pkg_suspend_link {
579   include( '/elements/popup_link-cust_pkg.html',
580              'action'      => $p. 'misc/cancel_pkg.html?method=suspend',
581              'label'       => emt('Suspend now'),
582              'actionlabel' => emt('Suspend'),
583              'color'       => '#FF9900',
584              'cust_pkg'    => shift,
585          )
586 }
587
588 sub pkg_adjourn_link {
589   include( '/elements/popup_link-cust_pkg.html',
590              'action'      => $p. 'misc/cancel_pkg.html?method=adjourn',
591              'label'       => emt('Suspend later'),
592              'actionlabel' => emt('Adjourn'),
593              'color'       => '#CC6600',
594              'cust_pkg'    => shift,
595          )
596 }
597
598 sub pkg_delay_link  {
599   my($cust_pkg) = shift;
600   include( '/elements/popup_link-cust_pkg.html',
601              'action'      => $p. 'misc/delay_susp_pkg.html',
602              'label'       => ( $cust_pkg->dundate
603                                   ? emt('Edit suspension delay')
604                                   : emt('Delay suspend')
605                               ),
606              'actionlabel' => emt('Delay suspend for'),
607              'cust_pkg'    => $cust_pkg,
608          )
609 }
610
611 sub pkg_resume_link {
612   include( '/elements/popup_link-cust_pkg.html',
613              'action'      => $p. 'misc/cancel_pkg.html?method=resume',
614              'label'       => emt('Unsuspend later'),
615              'actionlabel' => emt('Resume'),
616              'color'       => '#00CC00',
617              'cust_pkg'    => shift,
618          )
619 }
620
621 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg',    emt('Unsuspend now'), @_ ); }
622 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', emt('Abort'),     @_ ); }
623 sub pkg_unexpire_link  { pkg_link('misc/unexpire_pkg',  emt('Abort'),     @_ ); }
624 sub pkg_unchange_link  { pkg_link('misc/do_not_change_pkg',  emt('Abort change'),     @_ ); }
625 sub pkg_change_now_link  { pkg_link('misc/change_pkg_now',  emt('Change now'),     @_ ); }
626
627 sub pkg_cancel_link {
628   include( '/elements/popup_link-cust_pkg.html',
629              'action'      => $p. 'misc/cancel_pkg.html?method=cancel',
630              'label'       => emt('Cancel now'),
631              'actionlabel' => emt('Cancel'),
632              'color'       => '#ff0000',
633              'cust_pkg'    => shift,
634          )
635 }
636
637 sub pkg_uncancel_link {
638   include( '/elements/popup_link-cust_pkg.html',
639              'action'      => $p. 'misc/cancel_pkg.html?method=uncancel',
640              'label'       => emt('Un-cancel'),
641              'actionlabel' => emt('Un-cancel'),
642              #'color'       =>  #?
643              'cust_pkg'    => shift,
644          )
645 }
646
647 sub pkg_expire_link {
648   include( '/elements/popup_link-cust_pkg.html',
649              'action'      => $p. 'misc/cancel_pkg.html?method=expire',
650              'label'       => emt('Cancel later'),
651              'actionlabel' => emt('Expire'),
652              'color'       => '#CC0000',
653              'cust_pkg'    => shift,
654          )
655 }
656
657 sub pkg_change_later_link {
658   my $cust_pkg = shift;
659   include( '/elements/popup_link-cust_pkg.html',
660     'action'      => $p . 'misc/change_pkg.cgi?',
661     'label'       => emt('Reschedule'),
662     'actionlabel' => emt('Edit scheduled change for'),
663     'cust_pkg'    => $cust_pkg,
664     'width'       => 960,
665     'height'      => 490,
666   )
667 }
668
669 sub svc_recharge_link {
670   include( '/elements/popup_link-cust_svc.html',
671              'action'      => $p. 'misc/recharge_svc.html',
672              'label'       => emt('Recharge'),
673              'actionlabel' => emt('Recharge'),
674              'color'       => '#333399',
675              'cust_svc'    => shift,
676          )
677 }
678
679 sub pkg_autosuspend_time {
680   my $cust_pkg = shift or return '';
681   my $days = 7;
682   my $time = time;
683   my $pending_suspend = 0;
684   #this seems to be extremely inefficient...  and is slowing down all customer
685   #views
686   while ( $days > 0 &&
687           scalar(
688             grep { $_->part_event->action eq 'suspend' }
689             @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
690                                                     testonly => 1,
691                                                   ) }
692           )
693         )
694   {
695     $pending_suspend = 1;
696     $days--;
697   }
698
699   $pending_suspend ? time + ($days + 1) * 86400 : '';
700
701 }
702
703 </%init>