1 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>" VALIGN="top">
2 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
4 %#this should use cust_pkg->status and cust_pkg->statuscolor eventually
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 ) %>
12 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
13 % my $cpr = $cust_pkg->last_cust_pkg_reason('cancel');
15 <% pkg_status_row($cust_pkg, emt('Cancelled'), 'cancel', 'color'=>'FF0000', %opt ) %>
17 <% pkg_status_row_detached($cust_pkg, %opt) %>
19 <% pkg_reason_row($cust_pkg, $cpr, color => 'ff0000', %opt) %>
21 % unless ( $cust_pkg->get('setup') ) {
23 <% pkg_status_row_colspan( $cust_pkg, emt('Never billed'), '', %opt, ) %>
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 ) %>
34 % if ( $part_pkg->freq && !$supplemental && !$cust_pkg->change_custnum ) { #?
37 <TD COLSPAN=<%$opt{colspan}%>>
39 % if ( $curuser->access_right('Un-cancel customer package') && ! $opt{no_links} ) {
40 ( <% pkg_uncancel_link($cust_pkg) %> )
49 % if ( $cust_pkg->get('susp') ) { #status: suspended
50 % my $cpr = $cust_pkg->last_cust_pkg_reason('susp');
52 <% pkg_status_row( $cust_pkg, emt('Suspended'), 'susp', 'color'=>'FF9900', %opt ) %>
54 <% pkg_reason_row( $cust_pkg, $cpr, 'color' => 'FF9900', %opt ) %>
56 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
58 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
60 % unless ( $cust_pkg->get('setup') ) {
61 <% pkg_status_row_colspan( $cust_pkg, emt('Never billed'), '', %opt ) %>
63 <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt ) %>
66 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
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)
76 <% pkg_status_row_if( $cust_pkg, emt('Next bill'), 'bill', %opt, curuser=>$curuser ) %>
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 ) %>
82 % if ( !$supplemental && ! $opt{no_links} && !$change_from ) {
84 <TD COLSPAN=<%$opt{colspan}%>>
86 % if ( $cust_pkg->change_to_pkgnum ) {
87 % # then you can modify the package change
88 % if ( $curuser->access_right('Change customer package') ) {
89 ( <% pkg_change_now_link($cust_pkg) %> )
90 ( <% pkg_change_later_link($cust_pkg) %> )
91 ( <% pkg_unchange_link($cust_pkg) %> )
95 % if ( $curuser->access_right('Unsuspend customer package') ) {
96 ( <% pkg_unsuspend_link($cust_pkg) %> )
97 ( <% pkg_resume_link($cust_pkg) %> )
99 % if ( !$cust_pkg->change_to_pkgnum and
100 % $curuser->access_right('Cancel customer package immediately')
102 ( <% pkg_cancel_link($cust_pkg) %> )
109 % } else { #status: active
111 % if ( $change_from ) { # future change
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'),
119 % } elsif ( ! $cust_pkg->get('setup') ) { # not setup
121 % unless ( $part_pkg->freq ) { # one-time charge
123 <% pkg_status_row_colspan( $cust_pkg, emt('Not yet billed (one-time charge)'), '', %opt ) %>
125 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
127 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
129 <% pkg_status_row_if(
131 ( $part_pkg->freq ? emt('Start billing') : emt('Bill on') ),
137 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
139 % if ( !$supplemental && ! $opt{no_links} ) {
141 <TD COLSPAN=<%$opt{colspan}%>>
143 % if ( $curuser->access_right('Cancel customer package immediately') ) {
144 ( <% pkg_cancel_link($cust_pkg) %> )
153 <% pkg_status_row_colspan($cust_pkg, emt("Not yet billed ($billed_or_prepaid [_1])", myfreq($part_pkg) ), '', %opt ) %>
155 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
157 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
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 ) %>
166 % unless ( $part_pkg->freq ) {
168 <% pkg_status_row_colspan($cust_pkg, emt('One-time charge'), '', %opt ) %>
170 <% pkg_status_row($cust_pkg, emt('Billed'), 'setup', %opt) %>
172 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
174 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
176 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
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;
184 % #overlimit process is expensive with many services, so skip w/summary
185 % if ( !$summarize && scalar($cust_pkg->overlimit) ) {
187 <% pkg_status_row_colspan( $cust_pkg,
189 $billed_or_prepaid. ' '. myfreq($part_pkg),
196 <% pkg_status_row_colspan( $cust_pkg,
198 $billed_or_prepaid. ' '. myfreq($part_pkg),
205 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
207 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
209 <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt) %>
211 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
217 % if ( $opt{'cust_pkg-show_autosuspend'} ) {
218 % my $autosuspend = pkg_autosuspend_time( $cust_pkg );
219 % $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
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 ) %>
232 % if ( $part_pkg->freq and !$supplemental && ! $opt{no_links} ) {
235 <TD COLSPAN=<%$opt{colspan}%>>
238 % if ( $change_from ) {
240 % } elsif ( $cust_pkg->change_to_pkgnum ) {
241 % # then you can modify the package change
242 % if ( $curuser->access_right('Change customer package') ) {
243 ( <% pkg_change_now_link($cust_pkg) %> )
244 ( <% pkg_change_later_link($cust_pkg) %> )
245 ( <% pkg_unchange_link($cust_pkg) %> )
250 % # suspension actions--always available
251 % if ( $curuser->access_right('Suspend customer package') ) {
252 ( <% pkg_suspend_link($cust_pkg) %> )
254 % if ( $curuser->access_right('Suspend customer package later') ) {
255 ( <% pkg_adjourn_link($cust_pkg) %> )
257 % if ( $curuser->access_right('Delay suspension events') ) {
258 ( <% pkg_delay_link($cust_pkg) %> )
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
265 % if ( $curuser->access_right('Cancel customer package immediately') ) {
266 ( <% pkg_cancel_link($cust_pkg) %> )
268 % if ( $curuser->access_right('Cancel customer package later') ) {
269 ( <% pkg_expire_link($cust_pkg) %> )
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'};
295 $opt{colspan} = $opt{'cust_pkg-display_times'} ? 8 : 4;
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 bill';
302 $next_bill_or_prepaid_until = 'Next bill';
304 $billed_or_prepaid = 'prepaid';
305 $last_bill_or_renewed = 'Renewed';
306 $next_bill_or_prepaid_until = 'Prepaid until';
312 my $part_pkg = shift;
313 my $freq = $part_pkg->freq_pretty;
314 #$freq =~ s/ / /g;
318 #false laziness w/package.html
320 my($action, $label, $cust_pkg) = @_;
321 return '' unless $cust_pkg;
322 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
326 my( $cust_pkg, $title, $field, %opt ) = @_;
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
335 or $field eq 'last_bill'
338 or $field eq 'cancel'
346 my $color = $opt{'color'};
348 my $html = qq(<TR><TD WIDTH="$width" ALIGN="right">);
349 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
350 $html .= qq($title );
351 $html .= qq(</B></FONT>) if length($color);
353 if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
354 $html .= ' (Balance: <B>'. $opt{'money_char'}.
355 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
360 $html .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
365 sub pkg_status_row_if {
366 my( $cust_pkg, $title, $field, %opt ) = @_;
368 $title = '<FONT SIZE=-1>( '. pkg_unadjourn_link($cust_pkg). ' ) </FONT>'. $title
369 if ( $field eq 'adjourn' &&
370 $opt{curuser}->access_right('Suspend customer package later')
373 $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
376 sub pkg_status_row_expire {
377 my $cust_pkg = shift;
379 return unless $cust_pkg->get('expire');
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 )
389 $title = mt('Will <b>change location</b> on');
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>';
398 $title = emt('Expires');
399 if ( $opt{curuser}->access_right('Cancel customer package later')) {
400 $title = '<FONT SIZE=-1>( '. pkg_unexpire_link($cust_pkg). ' ) </FONT>'. $title;
405 pkg_status_row( $cust_pkg, $title, 'expire', %opt );
408 sub pkg_status_row_changed {
409 my( $cust_pkg, %opt ) = @_;
411 return '' unless $cust_pkg->change_date;
414 pkg_status_row( $cust_pkg, emt('Package changed'), 'change_date', %opt );
416 my $old = $cust_pkg->old_cust_pkg;
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) ),
432 sub pkg_status_row_detached {
433 my( $cust_pkg, %opt ) = @_;
435 return '' unless $cust_pkg->change_custnum;
439 my $cust_main = $cust_pkg->change_cust_main;
442 my $cust_link = '<A HREF="cust_main.cgi?'. $cust_pkg->change_custnum. '">'.
443 encode_entities( $cust_main->name ).
446 my $what = $opt{'pkg_attached'} ? 'Attached' : 'Detached';
448 $html .= pkg_status_row_colspan( $cust_pkg,
449 emt("$what to customer #[_1]: ",
450 $cust_pkg->change_custnum
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;
468 #inefficient, should be passed in
469 my $cust_main = $cust_pkg->cust_main;
471 return '' unless $cust_main->payby =~ /^(CARD|CHEK)$/;
472 my $what = lc(FS::payby->shortname($cust_main->payby));
474 pkg_status_row_colspan( $cust_pkg, emt("No automatic $what charge"), '');
477 sub pkg_status_row_discount {
478 my( $cust_pkg, %opt ) = @_;
482 foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
484 my $discount = $cust_pkg_discount->discount;
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);
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>';
498 $html .= pkg_status_row_colspan( $cust_pkg, $label, '', %opt );
506 my ($cust_pkg, $cpr, %opt) = @_;
507 return '' if $cust_pkg->main_pkgnum;
510 $reasontext = $cpr->reasontext . ' by ' . $cpr->otaker if $cpr;
511 pkg_status_row_colspan( $cust_pkg, $reasontext, '',
512 'align'=>'right', 'size'=>'-2', %opt
516 sub pkg_status_row_colspan {
517 my($cust_pkg, $title, $addl, %opt) = @_;
519 my $colspan = $opt{'colspan'};
521 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
522 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
523 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
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;
529 $html .= qq(</B>) if $color && !$size;
530 $html .= qq(</FONT>) if length($color) || $size;
531 $html .= ", $addl" if length($addl);
533 if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
534 $html .= ' (Balance: <B>'. $opt{'money_char'}.
535 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
539 $html .= qq(</TD></TR>);
546 my($cust_pkg, $field, %opt) = @_ or return '';
547 return ' ' unless $cust_pkg->get($field);
548 my $format = '<TD align="left"><B>%b</B></TD>'.
549 '<TD align="right"><B> %o,</B></TD>'.
550 '<TD align="right"><B> %Y</B></TD>';
551 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
552 $format .= '<TD ALIGN="right"><B> %l</TD>'.
553 '<TD ALIGN="center"><B>:</B></TD>'.
554 '<TD ALIGN="left"><B>%M</B></TD>'.
555 '<TD ALIGN="left"><B> %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;
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',
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',
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')
590 'actionlabel' => emt('Delay suspend for'),
591 'cust_pkg' => $cust_pkg,
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',
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'), @_ ); }
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',
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'),
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',
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,
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',
663 sub pkg_autosuspend_time {
664 my $cust_pkg = shift or return '';
667 my $pending_suspend = 0;
668 #this seems to be extremely inefficient... and is slowing down all customer
672 grep { $_->part_event->action eq 'suspend' }
673 @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
679 $pending_suspend = 1;
683 $pending_suspend ? time + ($days + 1) * 86400 : '';