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