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