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