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