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