detach a package into a new customer, RT#22185
[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 warn $cust_pkg->pkgnum;
369 warn $cust_pkg->change_custnum;
370
371   return '' unless $cust_pkg->change_custnum;
372
373   my $html = '';
374
375   my $cust_main = $cust_pkg->change_cust_main;
376   if ( $cust_main ) {
377
378     my $cust_link = '<A HREF="cust_main.cgi?'.  $cust_pkg->change_custnum. '">'.
379                       encode_entities( $cust_main->name ).
380                     '</A>';
381
382     $html .= pkg_status_row_colspan( $cust_pkg, 
383                                      emt("Detached to customer #[_1]: ",
384                                             $cust_pkg->change_custnum
385                                         ).
386                                        $cust_link,
387                                      '',
388                                      'size'    => '-1',
389                                      'align'   => 'right',
390                                      'colspan' => 4,
391                                    );
392   }
393
394   $html;
395 }
396
397 sub pkg_status_row_noauto {
398   my( $cust_pkg, %opt ) = @_;
399   my $part_pkg = $opt{'part_pkg'};
400   return '' unless $cust_pkg->no_auto || $part_pkg->no_auto;
401
402   #inefficient, should be passed in
403   my $cust_main = $cust_pkg->cust_main;
404
405   return '' unless $cust_main->payby =~ /^(CARD|CHEK)$/;
406   my $what = lc(FS::payby->shortname($cust_main->payby));
407
408   pkg_status_row_colspan( $cust_pkg, emt("No automatic $what charge"), '');
409 }
410
411 sub pkg_status_row_discount {
412   my( $cust_pkg, %opt ) = @_;
413
414   my $html;
415
416   foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
417
418     my $discount = $cust_pkg_discount->discount;
419
420     my $label = '<B>'.emt('Discount').'</B>: '. $discount->description;
421     if ( $discount->months ) {
422       my $remaining = $discount->months - $cust_pkg_discount->months_used;
423       $remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
424       $label .= emt("([_1] months remaining)",$remaining);
425     }
426
427     $label .= ' <FONT SIZE="-1">('.
428                 '<A HREF="../misc/delete-cust_pkg_discount.html?'.
429                   $cust_pkg_discount->pkgdiscountnum.
430                 '">'.emt('remove discount').'</A>)</FONT>';
431
432     $html .= pkg_status_row_colspan( $cust_pkg, $label, '', %opt );
433
434   }
435
436   $html;
437 }
438
439 sub pkg_reason_row {
440   my ($cust_pkg, $cpr, %opt) = @_;
441   return '' if $cust_pkg->main_pkgnum;
442
443   my $reasontext = '';
444   $reasontext = $cpr->reasontext . ' by ' . $cpr->otaker if $cpr;
445   pkg_status_row_colspan( $cust_pkg, $reasontext, '',
446     'align'=>'right', 'size'=>'-2', %opt
447   );
448 }
449
450 sub pkg_status_row_colspan {
451   my($cust_pkg, $title, $addl, %opt) = @_;
452
453   my $colspan  = $opt{'colspan'};
454
455   my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
456   my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
457   my $size  = $opt{'size'}  ? 'SIZE="'.  $opt{'size'}. '"' : '';
458
459   my $html = qq(<TR><TD COLSPAN=$colspan $align>);
460   $html   .= qq(<FONT $color $size>) if length($color) || $size;
461   $html   .= qq(<B>) if $color && !$size;
462   $html   .= $title;
463   $html   .= qq(</B>) if $color && !$size;
464   $html   .= qq(</FONT>) if length($color) || $size;
465   $html   .= ",&nbsp;$addl" if length($addl);
466
467   if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
468     $html .= ' (Balance:&nbsp;<B>'. $opt{'money_char'}.
469              $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
470              '</B>)';
471   }
472
473   $html   .= qq(</TD></TR>);
474
475   $html;
476
477 }
478
479 sub pkg_datestr {
480   my($cust_pkg, $field, %opt) = @_ or return '';
481   return '&nbsp;' unless $cust_pkg->get($field);
482   my $format = '<TD align="left"><B>%b</B></TD>'.
483                '<TD align="right"><B>&nbsp;%o,</B></TD>'.
484                '<TD align="right"><B>&nbsp;%Y</B></TD>';
485   #$format .= '&nbsp;<FONT SIZE=-3>%l:%M:%S%P&nbsp;%z</FONT>'
486   $format .= '<TD ALIGN="right"><B>&nbsp;%l</TD>'.
487              '<TD ALIGN="center"><B>:</B></TD>'.
488              '<TD ALIGN="left"><B>%M</B></TD>'.
489              '<TD ALIGN="left"><B>&nbsp;%P</B></TD>'
490     if $opt{'cust_pkg-display_times'};
491   my $strip = time2str($format, $cust_pkg->get($field) );
492   $strip =~ s/ (\d)/$1/g;
493   $strip;
494 }
495
496 sub pkg_suspend_link {
497   include( '/elements/popup_link-cust_pkg.html',
498              'action'      => $p. 'misc/cancel_pkg.html?method=suspend',
499              'label'       => emt('Suspend now'),
500              'actionlabel' => emt('Suspend'),
501              'color'       => '#FF9900',
502              'cust_pkg'    => shift,
503          )
504 }
505
506 sub pkg_adjourn_link {
507   include( '/elements/popup_link-cust_pkg.html',
508              'action'      => $p. 'misc/cancel_pkg.html?method=adjourn',
509              'label'       => emt('Suspend later'),
510              'actionlabel' => emt('Adjourn'),
511              'color'       => '#CC6600',
512              'cust_pkg'    => shift,
513          )
514 }
515
516 sub pkg_delay_link  {
517   my($cust_pkg) = shift;
518   include( '/elements/popup_link-cust_pkg.html',
519              'action'      => $p. 'misc/delay_susp_pkg.html',
520              'label'       => ( $cust_pkg->dundate
521                                   ? emt('Edit suspension delay')
522                                   : emt('Delay suspend')
523                               ),
524              'actionlabel' => emt('Delay suspend for'),
525              'cust_pkg'    => $cust_pkg,
526          )
527 }
528
529 sub pkg_resume_link {
530   include( '/elements/popup_link-cust_pkg.html',
531              'action'      => $p. 'misc/cancel_pkg.html?method=resume',
532              'label'       => emt('Unsuspend later'),
533              'actionlabel' => emt('Resume'),
534              'color'       => '#00CC00',
535              'cust_pkg'    => shift,
536          )
537 }
538
539 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg',    emt('Unsuspend now'), @_ ); }
540 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', emt('Abort'),     @_ ); }
541 sub pkg_unexpire_link  { pkg_link('misc/unexpire_pkg',  emt('Abort'),     @_ ); }
542
543 sub pkg_cancel_link {
544   include( '/elements/popup_link-cust_pkg.html',
545              'action'      => $p. 'misc/cancel_pkg.html?method=cancel',
546              'label'       => emt('Cancel now'),
547              'actionlabel' => emt('Cancel'),
548              'color'       => '#ff0000',
549              'cust_pkg'    => shift,
550          )
551 }
552
553 sub pkg_uncancel_link {
554   include( '/elements/popup_link-cust_pkg.html',
555              'action'      => $p. 'misc/cancel_pkg.html?method=uncancel',
556              'label'       => emt('Un-cancel'),
557              'actionlabel' => emt('Un-cancel'),
558              #'color'       =>  #?
559              'cust_pkg'    => shift,
560          )
561 }
562
563 sub pkg_expire_link {
564   include( '/elements/popup_link-cust_pkg.html',
565              'action'      => $p. 'misc/cancel_pkg.html?method=expire',
566              'label'       => emt('Cancel later'),
567              'actionlabel' => emt('Expire'),
568              'color'       => '#CC0000',
569              'cust_pkg'    => shift,
570          )
571 }
572
573 sub svc_recharge_link {
574   include( '/elements/popup_link-cust_svc.html',
575              'action'      => $p. 'misc/recharge_svc.html',
576              'label'       => emt('Recharge'),
577              'actionlabel' => emt('Recharge'),
578              'color'       => '#333399',
579              'cust_svc'    => shift,
580          )
581 }
582
583 sub pkg_autosuspend_time {
584   my $cust_pkg = shift or return '';
585   my $days = 7;
586   my $time = time;
587   my $pending_suspend = 0;
588   #this seems to be extremely inefficient...  and is slowing down all customer
589   #views
590   while ( $days > 0 &&
591           scalar(
592             grep { $_->part_event->action eq 'suspend' }
593             @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
594                                                     testonly => 1,
595                                                   ) }
596           )
597         )
598   {
599     $pending_suspend = 1;
600     $days--;
601   }
602
603   $pending_suspend ? time + ($days + 1) * 86400 : '';
604
605 }
606
607 </%init>