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') ) { #suspended or on hold
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
54 <% pkg_status_row( $cust_pkg, emt('On Hold'), '', 'color'=>'7E0079', %opt ) %>
56 % } else { #status: suspended
58 <% pkg_status_row( $cust_pkg, emt('Suspended'), 'susp', 'color'=>'FF9900', %opt ) %>
59 % my $cpr = $cust_pkg->last_cust_pkg_reason('susp');
60 <% pkg_reason_row( $cust_pkg, $cpr, 'color' => 'FF9900', %opt ) %>
64 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
66 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
68 % unless ( $cust_pkg->order_date eq $cust_pkg->get('susp') ) { #on hold
69 % unless ( $cust_pkg->get('setup') ) {
70 <% pkg_status_row_colspan( $cust_pkg, emt('Never billed'), '', %opt ) %>
72 <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt ) %>
76 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
78 <% pkg_status_row_changed( $cust_pkg, %opt ) %>
79 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
80 % if ( $cust_pkg->option('suspend_bill', 1)
81 % || ( $part_pkg->option('suspend_bill', 1)
82 % && ! $cust_pkg->option('no_suspend_bill',1)
86 <% pkg_status_row_if( $cust_pkg, emt('Next bill'), 'bill', %opt, curuser=>$curuser ) %>
88 <% pkg_status_row_if( $cust_pkg, emt('Will resume'), 'resume', %opt, curuser=>$curuser ) %>
89 <% pkg_status_row_expire($cust_pkg, %opt, curuser=>$curuser) %>
90 <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
92 % if ( !$supplemental && ! $opt{no_links} && !$change_from ) {
94 <TD COLSPAN=<%$opt{colspan}%>>
96 % if ( $cust_pkg->change_to_pkgnum ) {
97 % # then you can modify the package change
98 % if ( $curuser->access_right('Change customer package') ) {
99 ( <% pkg_change_now_link($cust_pkg) %> )
100 ( <% pkg_change_later_link($cust_pkg) %> )
101 ( <% pkg_unchange_link($cust_pkg) %> )
105 % if ( $curuser->access_right('Unsuspend customer package') ) {
106 % if ( $cust_pkg->order_date eq $cust_pkg->get('susp') ) { #on hold
107 ( <% pkg_link('misc/unsusp_pkg', emt('Start bililng now'), $cust_pkg) %> )
109 ( <% pkg_unsuspend_link($cust_pkg) %> )
110 ( <% pkg_resume_link($cust_pkg) %> )
113 % if ( !$cust_pkg->change_to_pkgnum and
114 % $curuser->access_right('Cancel customer package immediately')
116 ( <% pkg_cancel_link($cust_pkg) %> )
123 % } else { #status: active
125 % if ( $change_from ) { # future change
127 <% pkg_status_row_colspan( $cust_pkg, emt('Waiting for package change'), '', %opt ) %>
128 <% pkg_status_row( $cust_pkg,
129 emt('Will be activated on'),
133 % } elsif ( ! $cust_pkg->get('setup') ) { # not setup
135 % unless ( $part_pkg->freq ) { # one-time charge
137 <% pkg_status_row_colspan( $cust_pkg, emt('Not yet billed (one-time charge)'), '', %opt ) %>
139 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
141 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
143 <% pkg_status_row_if(
145 ( $part_pkg->freq ? emt('Start billing') : emt('Bill on') ),
151 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
153 % if ( !$supplemental && ! $opt{no_links} ) {
155 <TD COLSPAN=<%$opt{colspan}%>>
157 % if ( $curuser->access_right('Cancel customer package immediately') ) {
158 ( <% pkg_cancel_link($cust_pkg) %> )
167 <% pkg_status_row_colspan($cust_pkg, emt("Not yet billed ($billed_or_prepaid [_1])", myfreq($part_pkg) ), '', %opt ) %>
169 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
171 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
173 <% pkg_status_row_if($cust_pkg, emt('Start billing'), 'start_date', %opt) %>
174 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
180 % unless ( $part_pkg->freq ) {
182 <% pkg_status_row_colspan($cust_pkg, emt('One-time charge'), '', %opt ) %>
184 <% pkg_status_row($cust_pkg, emt('Billed'), 'setup', %opt) %>
186 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
188 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
190 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
194 % my $num_cust_svc = $cust_pkg->num_cust_svc;
195 % my $summarize = $opt{'cust_pkg-large_pkg_size'} > 0
196 % && $opt{'cust_pkg-large_pkg_size'} <= $num_cust_svc;
198 % #overlimit process is expensive with many services, so skip w/summary
199 % if ( !$summarize && scalar($cust_pkg->overlimit) ) {
201 <% pkg_status_row_colspan( $cust_pkg,
203 $billed_or_prepaid. ' '. myfreq($part_pkg),
210 <% pkg_status_row_colspan( $cust_pkg,
212 $billed_or_prepaid. ' '. myfreq($part_pkg),
219 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
221 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
223 <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt) %>
225 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
231 % if ( $opt{'cust_pkg-show_autosuspend'} ) {
232 % my $autosuspend = pkg_autosuspend_time( $cust_pkg );
233 % $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
236 <% pkg_status_row_changed( $cust_pkg, %opt ) %>
237 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
238 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
239 <% pkg_status_row_if($cust_pkg, emt('Will automatically suspend by'), 'autosuspend', %opt) %>
240 <% pkg_status_row_if($cust_pkg, emt('Automatic suspension delayed until'), 'dundate', %opt) %>
241 <% pkg_status_row_if( $cust_pkg, emt('Will suspend on'), 'adjourn', %opt, curuser=>$curuser ) %>
242 <% pkg_status_row_if( $cust_pkg, emt('Will resume on'), 'resume', %opt, curuser=>$curuser ) %>
243 <% pkg_status_row_expire($cust_pkg, %opt, curuser=>$curuser) %>
244 <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
246 % if ( $part_pkg->freq and !$supplemental && ! $opt{no_links} ) {
249 <TD COLSPAN=<%$opt{colspan}%>>
252 % if ( $change_from ) {
254 % } elsif ( $cust_pkg->change_to_pkgnum ) {
255 % # then you can modify the package change
256 % if ( $curuser->access_right('Change customer package') ) {
257 ( <% pkg_change_now_link($cust_pkg) %> )
258 ( <% pkg_change_later_link($cust_pkg) %> )
259 ( <% pkg_unchange_link($cust_pkg) %> )
264 % # suspension actions--always available
265 % if ( $curuser->access_right('Suspend customer package') ) {
266 ( <% pkg_suspend_link($cust_pkg) %> )
268 % if ( $curuser->access_right('Suspend customer package later') ) {
269 ( <% pkg_adjourn_link($cust_pkg) %> )
271 % if ( $curuser->access_right('Delay suspension events') ) {
272 ( <% pkg_delay_link($cust_pkg) %> )
275 % if ( $change_from or $cust_pkg->change_to_pkgnum ) {
276 % # you can't cancel the package while in this state
277 % } else { # the normal case: links to cancel the package
279 % if ( $curuser->access_right('Cancel customer package immediately') ) {
280 ( <% pkg_cancel_link($cust_pkg) %> )
282 % if ( $curuser->access_right('Cancel customer package later') ) {
283 ( <% pkg_expire_link($cust_pkg) %> )
301 my $bgcolor = $opt{'bgcolor'};
302 my $cust_pkg = $opt{'cust_pkg'};
303 my $part_pkg = $opt{'part_pkg'};
304 my $curuser = $FS::CurrentUser::CurrentUser;
305 my $width = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
306 my $supplemental = $opt{'supplemental'};
307 my $change_from = $opt{'change_from'};
309 $opt{colspan} = $opt{'cust_pkg-display_times'} ? 8 : 4;
311 #false laziness w/edit/REAL_cust_pkg.cgi
312 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
313 unless ( $part_pkg->is_prepaid ) {
314 $billed_or_prepaid = 'billed';
315 $last_bill_or_renewed = 'Last bill';
316 $next_bill_or_prepaid_until = 'Next bill';
318 $billed_or_prepaid = 'prepaid';
319 $last_bill_or_renewed = 'Renewed';
320 $next_bill_or_prepaid_until = 'Prepaid until';
326 my $part_pkg = shift;
327 my $freq = $part_pkg->freq_pretty;
328 #$freq =~ s/ / /g;
332 #false laziness w/package.html
334 my($action, $label, $cust_pkg) = @_;
335 return '' unless $cust_pkg;
336 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
340 my( $cust_pkg, $title, $field, %opt ) = @_;
342 if ( $field and $cust_pkg->main_pkgnum ) {
343 # for supplemental packages, we mostly only show these if they're
344 # different from the main package
345 my $main_pkg = $cust_pkg-> main_pkg;
346 if ( $main_pkg->get($field) ne $cust_pkg->get($field)
347 # with some exceptions
349 or $field eq 'last_bill'
352 or $field eq 'cancel'
360 my $color = $opt{'color'};
362 my $html = qq(<TR><TD WIDTH="$width" ALIGN="right">);
363 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
364 $html .= qq($title );
365 $html .= qq(</B></FONT>) if length($color);
367 if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
368 $html .= ' (Balance: <B>'. $opt{'money_char'}.
369 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
374 $html .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
379 sub pkg_status_row_if {
380 my( $cust_pkg, $title, $field, %opt ) = @_;
382 $title = '<FONT SIZE=-1>( '. pkg_unadjourn_link($cust_pkg). ' ) </FONT>'. $title
383 if ( $field eq 'adjourn' &&
384 $opt{curuser}->access_right('Suspend customer package later')
387 $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
390 sub pkg_status_row_expire {
391 my $cust_pkg = shift;
393 return unless $cust_pkg->get('expire');
397 if ( $cust_pkg->get('change_to_pkg') ) {
398 if ( $cust_pkg->change_to_pkg->pkgpart != $cust_pkg->pkgpart ) {
399 $title = mt('Will change to <b>[_1]</b> on',
400 $cust_pkg->change_to_pkg->part_pkg->pkg);
401 } elsif ( $cust_pkg->change_to_pkg->locationnum != $cust_pkg->locationnum )
403 $title = mt('Will <b>change location</b> on');
405 # FS::cust_pkg->change_later should have prevented this, but
406 # just so that we can display _something_
407 $title = '<font color="#ff0000">Unknown package change</font>';
412 $title = emt('Expires');
413 if ( $opt{curuser}->access_right('Cancel customer package later')) {
414 $title = '<FONT SIZE=-1>( '. pkg_unexpire_link($cust_pkg). ' ) </FONT>'. $title;
419 pkg_status_row( $cust_pkg, $title, 'expire', %opt );
422 sub pkg_status_row_changed {
423 my( $cust_pkg, %opt ) = @_;
425 return '' unless $cust_pkg->change_date;
428 pkg_status_row( $cust_pkg, emt('Package changed'), 'change_date', %opt );
430 my $old = $cust_pkg->old_cust_pkg;
432 my $part_pkg = $old->part_pkg;
433 $html .= pkg_status_row_colspan(
435 emt("Changed from [_1]: [_2]",
436 $cust_pkg->change_pkgnum,
437 $part_pkg->pkg_comment(cust_pkg=>$old, nopartpkg=>1)
448 sub pkg_status_row_detached {
449 my( $cust_pkg, %opt ) = @_;
451 return '' unless $cust_pkg->change_custnum;
455 my $cust_main = $cust_pkg->change_cust_main;
458 my $cust_link = '<A HREF="cust_main.cgi?'. $cust_pkg->change_custnum. '">'.
459 encode_entities( $cust_main->name ).
462 my $what = $opt{'pkg_attached'} ? 'Attached' : 'Detached';
464 $html .= pkg_status_row_colspan( $cust_pkg,
465 emt("$what to customer #[_1]: ",
466 $cust_pkg->change_custnum
479 sub pkg_status_row_noauto {
480 my( $cust_pkg, %opt ) = @_;
481 my $part_pkg = $opt{'part_pkg'};
482 return '' unless $cust_pkg->no_auto || $part_pkg->no_auto;
484 #inefficient, should be passed in
485 my $cust_main = $cust_pkg->cust_main;
487 return '' unless $cust_main->payby =~ /^(CARD|CHEK)$/;
488 my $what = lc(FS::payby->shortname($cust_main->payby));
490 pkg_status_row_colspan( $cust_pkg, emt("No automatic $what charge"), '');
493 sub pkg_status_row_discount {
494 my( $cust_pkg, %opt ) = @_;
498 foreach my $cust_pkg_discount (@{ $cust_pkg->{_cust_pkg_discount_active} }) {
500 my $discount = $cust_pkg_discount->discount;
502 my $label = '<B>'.emt('Discount').'</B>: '. $discount->description;
503 if ( $discount->months ) {
504 my $remaining = $discount->months - $cust_pkg_discount->months_used;
505 $remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
506 $label .= emt("([_1] months remaining)",$remaining);
509 $label .= ' <FONT SIZE="-1">('.
510 '<A HREF="../misc/delete-cust_pkg_discount.html?'.
511 $cust_pkg_discount->pkgdiscountnum.
512 '">'.emt('remove discount').'</A>)</FONT>';
514 $html .= pkg_status_row_colspan( $cust_pkg, $label, '', %opt );
522 my ($cust_pkg, $cpr, %opt) = @_;
523 return '' if $cust_pkg->main_pkgnum;
526 $reasontext = $cpr->reasontext . ' by ' . $cpr->otaker if $cpr;
527 pkg_status_row_colspan( $cust_pkg, $reasontext, '',
528 'align'=>'right', 'size'=>'-2', %opt
532 sub pkg_status_row_colspan {
533 my($cust_pkg, $title, $addl, %opt) = @_;
535 my $colspan = $opt{'colspan'};
537 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
538 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
539 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
541 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
542 $html .= qq(<FONT $color $size>) if length($color) || $size;
543 $html .= qq(<B>) if $color && !$size;
545 $html .= qq(</B>) if $color && !$size;
546 $html .= qq(</FONT>) if length($color) || $size;
547 $html .= ", $addl" if length($addl);
549 if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
550 $html .= ' (Balance: <B>'. $opt{'money_char'}.
551 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
555 $html .= qq(</TD></TR>);
562 my($cust_pkg, $field, %opt) = @_ or return '';
563 return ' ' unless $cust_pkg->get($field);
564 my $format = '<TD align="left"><B>%b</B></TD>'.
565 '<TD align="right"><B> %o,</B></TD>'.
566 '<TD align="right"><B> %Y</B></TD>';
567 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
568 $format .= '<TD ALIGN="right"><B> %l</TD>'.
569 '<TD ALIGN="center"><B>:</B></TD>'.
570 '<TD ALIGN="left"><B>%M</B></TD>'.
571 '<TD ALIGN="left"><B> %P</B></TD>'
572 if $opt{'cust_pkg-display_times'};
573 my $strip = time2str($format, $cust_pkg->get($field) );
574 $strip =~ s/ (\d)/$1/g;
578 sub pkg_suspend_link {
579 include( '/elements/popup_link-cust_pkg.html',
580 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
581 'label' => emt('Suspend now'),
582 'actionlabel' => emt('Suspend'),
583 'color' => '#FF9900',
589 sub pkg_adjourn_link {
590 include( '/elements/popup_link-cust_pkg.html',
591 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
592 'label' => emt('Suspend later'),
593 'actionlabel' => emt('Adjourn'),
594 'color' => '#CC6600',
601 my($cust_pkg) = shift;
602 include( '/elements/popup_link-cust_pkg.html',
603 'action' => $p. 'misc/delay_susp_pkg.html',
604 'label' => ( $cust_pkg->dundate
605 ? emt('Edit suspension delay')
606 : emt('Delay suspend')
608 'actionlabel' => emt('Delay suspend for'),
609 'cust_pkg' => $cust_pkg,
613 sub pkg_resume_link {
614 include( '/elements/popup_link-cust_pkg.html',
615 'action' => $p. 'misc/cancel_pkg.html?method=resume',
616 'label' => emt('Unsuspend later'),
617 'actionlabel' => emt('Resume'),
618 'color' => '#00CC00',
623 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', emt('Unsuspend now'), @_ ); }
624 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', emt('Abort'), @_ ); }
625 sub pkg_unexpire_link { pkg_link('misc/unexpire_pkg', emt('Abort'), @_ ); }
626 sub pkg_unchange_link { pkg_link('misc/do_not_change_pkg', emt('Abort change'), @_ ); }
627 sub pkg_change_now_link { pkg_link('misc/change_pkg_now', emt('Change now'), @_ ); }
629 sub pkg_cancel_link {
630 include( '/elements/popup_link-cust_pkg.html',
631 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
632 'label' => emt('Cancel now'),
633 'actionlabel' => emt('Cancel'),
634 'color' => '#ff0000',
639 sub pkg_uncancel_link {
640 include( '/elements/popup_link-cust_pkg.html',
641 'action' => $p. 'misc/cancel_pkg.html?method=uncancel',
642 'label' => emt('Un-cancel'),
643 'actionlabel' => emt('Un-cancel'),
649 sub pkg_expire_link {
650 include( '/elements/popup_link-cust_pkg.html',
651 'action' => $p. 'misc/cancel_pkg.html?method=expire',
652 'label' => emt('Cancel later'),
653 'actionlabel' => emt('Expire'),
654 'color' => '#CC0000',
659 sub pkg_change_later_link {
660 my $cust_pkg = shift;
661 include( '/elements/popup_link-cust_pkg.html',
662 'action' => $p . 'misc/change_pkg.cgi?',
663 'label' => emt('Reschedule'),
664 'actionlabel' => emt('Edit scheduled change for'),
665 'cust_pkg' => $cust_pkg,
671 sub svc_recharge_link {
672 include( '/elements/popup_link-cust_svc.html',
673 'action' => $p. 'misc/recharge_svc.html',
674 'label' => emt('Recharge'),
675 'actionlabel' => emt('Recharge'),
676 'color' => '#333399',
681 sub pkg_autosuspend_time {
682 my $cust_pkg = shift or return '';
685 my $pending_suspend = 0;
686 #this seems to be extremely inefficient... and is slowing down all customer
690 grep { $_->part_event->action eq 'suspend' }
691 @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
697 $pending_suspend = 1;
701 $pending_suspend ? time + ($days + 1) * 86400 : '';