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
57 % my ($cpr,$susplabel);
58 % if ($cust_pkg->is_status_delay_cancel) {
59 % $cpr = $cust_pkg->last_cust_pkg_reason('expire');
60 % $susplabel = 'Suspended (Cancelled)';
62 % $cpr = $cust_pkg->last_cust_pkg_reason('susp');
63 % $susplabel = 'Suspended';
65 <% pkg_status_row( $cust_pkg, emt($susplabel), 'susp', 'color'=>'FF9900', %opt ) %>
66 <% pkg_reason_row( $cust_pkg, $cpr, 'color' => 'FF9900', %opt ) %>
70 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
72 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
74 % unless ( $cust_pkg->order_date eq $cust_pkg->get('susp') ) { #on hold
75 % unless ( $cust_pkg->get('setup') ) {
76 <% pkg_status_row_colspan( $cust_pkg, emt('Never billed'), '', %opt ) %>
78 <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt ) %>
82 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
84 <% pkg_status_row_changed( $cust_pkg, %opt ) %>
85 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
86 % if ( $cust_pkg->option('suspend_bill', 1)
87 % || ( $part_pkg->option('suspend_bill', 1)
88 % && ! $cust_pkg->option('no_suspend_bill',1)
92 <% pkg_status_row_if( $cust_pkg, emt('Next bill'), 'bill', %opt, curuser=>$curuser ) %>
94 <% pkg_status_row_if( $cust_pkg, emt('Will resume'), 'resume', %opt, curuser=>$curuser ) %>
95 <% pkg_status_row_expire($cust_pkg, %opt, curuser=>$curuser) %>
96 <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
98 % if ( !$supplemental && ! $opt{no_links} && !$change_from ) {
100 <TD COLSPAN=<%$opt{colspan}%>>
102 % if ( $cust_pkg->change_to_pkgnum ) {
103 % # then you can modify the package change
104 % if ( $curuser->access_right('Change customer package') ) {
105 ( <% pkg_change_now_link($cust_pkg) %> )
106 ( <% pkg_change_later_link($cust_pkg) %> )
107 ( <% pkg_unchange_link($cust_pkg) %> )
111 % if ( $curuser->access_right('Unsuspend customer package') ) {
112 % if ( $cust_pkg->order_date eq $cust_pkg->get('susp') ) { #on hold
113 ( <% pkg_link('misc/unsusp_pkg', emt('Start bililng now'), $cust_pkg) %> )
115 ( <% pkg_unsuspend_link($cust_pkg) %> )
116 ( <% pkg_resume_link($cust_pkg) %> )
119 % if ( !$cust_pkg->change_to_pkgnum and
120 % $curuser->access_right('Cancel customer package immediately')
122 ( <% pkg_cancel_link($cust_pkg) %> )
129 % } else { #status: active
131 % if ( $change_from ) { # future change
133 <% pkg_status_row_colspan( $cust_pkg, emt('Waiting for package change'), '', %opt ) %>
134 <% pkg_status_row( $cust_pkg,
135 emt('Will be activated on'),
139 % } elsif ( ! $cust_pkg->get('setup') ) { # not setup
141 % unless ( $part_pkg->freq ) { # one-time charge
143 <% pkg_status_row_colspan( $cust_pkg, emt('Not yet billed (one-time charge)'), '', %opt ) %>
145 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
147 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
149 <% pkg_status_row_if(
151 ( $part_pkg->freq ? emt('Start billing') : emt('Bill on') ),
157 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
159 % if ( !$supplemental && ! $opt{no_links} ) {
161 <TD COLSPAN=<%$opt{colspan}%>>
163 % if ( $curuser->access_right('Cancel customer package immediately') ) {
164 ( <% pkg_cancel_link($cust_pkg) %> )
173 <% pkg_status_row_colspan($cust_pkg, emt("Not yet billed ($billed_or_prepaid [_1])", myfreq($part_pkg) ), '', %opt ) %>
175 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
177 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
179 <% pkg_status_row_if($cust_pkg, emt('Start billing'), 'start_date', %opt) %>
180 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
186 % unless ( $part_pkg->freq ) {
188 <% pkg_status_row_colspan($cust_pkg, emt('One-time charge'), '', %opt ) %>
190 <% pkg_status_row($cust_pkg, emt('Billed'), 'setup', %opt) %>
192 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
194 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
196 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
200 % my $num_cust_svc = $cust_pkg->num_cust_svc;
201 % my $summarize = $opt{'cust_pkg-large_pkg_size'} > 0
202 % && $opt{'cust_pkg-large_pkg_size'} <= $num_cust_svc;
204 % #overlimit process is expensive with many services, so skip w/summary
205 % if ( !$summarize && scalar($cust_pkg->overlimit) ) {
207 <% pkg_status_row_colspan( $cust_pkg,
209 $billed_or_prepaid. ' '. myfreq($part_pkg),
216 <% pkg_status_row_colspan( $cust_pkg,
218 $billed_or_prepaid. ' '. myfreq($part_pkg),
225 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
227 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
229 <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt) %>
231 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
237 % if ( $opt{'cust_pkg-show_autosuspend'} ) {
238 % my $autosuspend = pkg_autosuspend_time( $cust_pkg );
239 % $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
242 <% pkg_status_row_changed( $cust_pkg, %opt ) %>
243 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
244 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
245 <% pkg_status_row_if($cust_pkg, emt('Will automatically suspend by'), 'autosuspend', %opt) %>
246 <% pkg_status_row_if($cust_pkg, emt('Automatic suspension delayed until'), 'dundate', %opt) %>
247 <% pkg_status_row_if( $cust_pkg, emt('Will suspend on'), 'adjourn', %opt, curuser=>$curuser ) %>
248 <% pkg_status_row_if( $cust_pkg, emt('Will resume on'), 'resume', %opt, curuser=>$curuser ) %>
249 <% pkg_status_row_expire($cust_pkg, %opt, curuser=>$curuser) %>
250 <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
252 % if ( $part_pkg->freq and !$supplemental && ! $opt{no_links} ) {
255 <TD COLSPAN=<%$opt{colspan}%>>
258 % if ( $change_from ) {
260 % } elsif ( $cust_pkg->change_to_pkgnum ) {
261 % # then you can modify the package change
262 % if ( $curuser->access_right('Change customer package') ) {
263 ( <% pkg_change_now_link($cust_pkg) %> )
264 ( <% pkg_change_later_link($cust_pkg) %> )
265 ( <% pkg_unchange_link($cust_pkg) %> )
270 % # suspension actions--always available
271 % if ( $curuser->access_right('Suspend customer package') ) {
272 ( <% pkg_suspend_link($cust_pkg) %> )
274 % if ( $curuser->access_right('Suspend customer package later') ) {
275 ( <% pkg_adjourn_link($cust_pkg) %> )
277 % if ( $curuser->access_right('Delay suspension events') ) {
278 ( <% pkg_delay_link($cust_pkg) %> )
281 % if ( $change_from or $cust_pkg->change_to_pkgnum ) {
282 % # you can't cancel the package while in this state
283 % } else { # the normal case: links to cancel the package
285 % if ( $curuser->access_right('Cancel customer package immediately') ) {
286 ( <% pkg_cancel_link($cust_pkg) %> )
288 % if ( $curuser->access_right('Cancel customer package later') ) {
289 ( <% pkg_expire_link($cust_pkg) %> )
307 my $bgcolor = $opt{'bgcolor'};
308 my $cust_pkg = $opt{'cust_pkg'};
309 my $part_pkg = $opt{'part_pkg'};
310 my $curuser = $FS::CurrentUser::CurrentUser;
311 my $width = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
312 my $supplemental = $opt{'supplemental'};
313 my $change_from = $opt{'change_from'};
315 $opt{colspan} = $opt{'cust_pkg-display_times'} ? 8 : 4;
317 #false laziness w/edit/REAL_cust_pkg.cgi
318 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
319 unless ( $part_pkg->is_prepaid ) {
320 $billed_or_prepaid = 'billed';
321 $last_bill_or_renewed = 'Last bill';
322 $next_bill_or_prepaid_until = 'Next bill';
324 $billed_or_prepaid = 'prepaid';
325 $last_bill_or_renewed = 'Renewed';
326 $next_bill_or_prepaid_until = 'Prepaid until';
332 my $part_pkg = shift;
333 my $freq = $part_pkg->freq_pretty;
334 #$freq =~ s/ / /g;
338 #false laziness w/package.html
340 my($action, $label, $cust_pkg) = @_;
341 return '' unless $cust_pkg;
342 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
346 my( $cust_pkg, $title, $field, %opt ) = @_;
348 if ( $field and $cust_pkg->main_pkgnum ) {
349 # for supplemental packages, we mostly only show these if they're
350 # different from the main package
351 my $main_pkg = $cust_pkg-> main_pkg;
352 if ( $main_pkg->get($field) ne $cust_pkg->get($field)
353 # with some exceptions
355 or $field eq 'last_bill'
358 or $field eq 'cancel'
366 my $color = $opt{'color'};
368 my $html = qq(<TR><TD WIDTH="$width" ALIGN="right">);
369 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
370 $html .= qq($title );
371 $html .= qq(</B></FONT>) if length($color);
373 if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
374 $html .= ' (Balance: <B>'. $opt{'money_char'}.
375 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
380 $html .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
385 sub pkg_status_row_if {
386 my( $cust_pkg, $title, $field, %opt ) = @_;
388 $title = '<FONT SIZE=-1>( '. pkg_unadjourn_link($cust_pkg). ' ) </FONT>'. $title
389 if ( $field eq 'adjourn' &&
390 $opt{curuser}->access_right('Suspend customer package later')
393 $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
396 sub pkg_status_row_expire {
397 my $cust_pkg = shift;
399 return unless $cust_pkg->get('expire');
403 if ( $cust_pkg->get('change_to_pkg') ) {
404 if ( $cust_pkg->change_to_pkg->pkgpart != $cust_pkg->pkgpart ) {
405 $title = mt('Will change to <b>[_1]</b> on',
406 $cust_pkg->change_to_pkg->part_pkg->pkg);
407 } elsif ( $cust_pkg->change_to_pkg->locationnum != $cust_pkg->locationnum )
409 $title = mt('Will <b>change location</b> on');
411 # FS::cust_pkg->change_later should have prevented this, but
412 # just so that we can display _something_
413 $title = '<font color="#ff0000">Unknown package change</font>';
418 $title = emt('Expires');
419 if ( $opt{curuser}->access_right('Cancel customer package later')) {
420 $title = '<FONT SIZE=-1>( '. pkg_unexpire_link($cust_pkg). ' ) </FONT>'. $title;
425 pkg_status_row( $cust_pkg, $title, 'expire', %opt );
428 sub pkg_status_row_changed {
429 my( $cust_pkg, %opt ) = @_;
431 return '' unless $cust_pkg->change_date;
434 pkg_status_row( $cust_pkg, emt('Package changed'), 'change_date', %opt );
436 my $old = $cust_pkg->old_cust_pkg;
438 my $part_pkg = $old->part_pkg;
439 $html .= pkg_status_row_colspan(
441 emt("Changed from [_1]: [_2]",
442 $cust_pkg->change_pkgnum,
443 $part_pkg->pkg_comment(cust_pkg=>$old, nopartpkg=>1)
454 sub pkg_status_row_detached {
455 my( $cust_pkg, %opt ) = @_;
457 return '' unless $cust_pkg->change_custnum;
461 my $cust_main = $cust_pkg->change_cust_main;
464 my $cust_link = '<A HREF="cust_main.cgi?'. $cust_pkg->change_custnum. '">'.
465 encode_entities( $cust_main->name ).
468 my $what = $opt{'pkg_attached'} ? 'Attached' : 'Detached';
470 $html .= pkg_status_row_colspan( $cust_pkg,
471 emt("$what to customer #[_1]: ",
472 $cust_pkg->change_custnum
485 sub pkg_status_row_noauto {
486 my( $cust_pkg, %opt ) = @_;
487 my $part_pkg = $opt{'part_pkg'};
488 return '' unless $cust_pkg->no_auto || $part_pkg->no_auto;
490 #inefficient, should be passed in
491 my $cust_main = $cust_pkg->cust_main;
493 return '' unless $cust_main->payby =~ /^(CARD|CHEK)$/;
494 my $what = lc(FS::payby->shortname($cust_main->payby));
496 pkg_status_row_colspan( $cust_pkg, emt("No automatic $what charge"), '');
499 sub pkg_status_row_discount {
500 my( $cust_pkg, %opt ) = @_;
504 foreach my $cust_pkg_discount (@{ $cust_pkg->{_cust_pkg_discount_active} }) {
506 my $discount = $cust_pkg_discount->discount;
508 my $label = '<B>'.emt('Discount').'</B>: '. $discount->description;
509 if ( $discount->months ) {
510 my $remaining = $discount->months - $cust_pkg_discount->months_used;
511 $remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
512 $label .= emt("([_1] months remaining)",$remaining);
515 $label .= ' <FONT SIZE="-1">('.
516 '<A HREF="../misc/delete-cust_pkg_discount.html?'.
517 $cust_pkg_discount->pkgdiscountnum.
518 '">'.emt('remove discount').'</A>)</FONT>';
520 $html .= pkg_status_row_colspan( $cust_pkg, $label, '', %opt );
528 my ($cust_pkg, $cpr, %opt) = @_;
529 return '' if $cust_pkg->main_pkgnum;
532 $reasontext = $cpr->reasontext . ' by ' . $cpr->otaker if $cpr;
533 pkg_status_row_colspan( $cust_pkg, $reasontext, '',
534 'align'=>'right', 'size'=>'-2', %opt
538 sub pkg_status_row_colspan {
539 my($cust_pkg, $title, $addl, %opt) = @_;
541 my $colspan = $opt{'colspan'};
543 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
544 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
545 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
547 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
548 $html .= qq(<FONT $color $size>) if length($color) || $size;
549 $html .= qq(<B>) if $color && !$size;
551 $html .= qq(</B>) if $color && !$size;
552 $html .= qq(</FONT>) if length($color) || $size;
553 $html .= ", $addl" if length($addl);
555 if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
556 $html .= ' (Balance: <B>'. $opt{'money_char'}.
557 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
561 $html .= qq(</TD></TR>);
568 my($cust_pkg, $field, %opt) = @_ or return '';
569 return ' ' unless $cust_pkg->get($field);
570 my $format = '<TD align="left"><B>%b</B></TD>'.
571 '<TD align="right"><B> %o,</B></TD>'.
572 '<TD align="right"><B> %Y</B></TD>';
573 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
574 $format .= '<TD ALIGN="right"><B> %l</TD>'.
575 '<TD ALIGN="center"><B>:</B></TD>'.
576 '<TD ALIGN="left"><B>%M</B></TD>'.
577 '<TD ALIGN="left"><B> %P</B></TD>'
578 if $opt{'cust_pkg-display_times'};
579 my $strip = time2str($format, $cust_pkg->get($field) );
580 $strip =~ s/ (\d)/$1/g;
584 sub pkg_suspend_link {
585 include( '/elements/popup_link-cust_pkg.html',
586 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
587 'label' => emt('Suspend now'),
588 'actionlabel' => emt('Suspend'),
589 'color' => '#FF9900',
595 sub pkg_adjourn_link {
596 include( '/elements/popup_link-cust_pkg.html',
597 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
598 'label' => emt('Suspend later'),
599 'actionlabel' => emt('Adjourn'),
600 'color' => '#CC6600',
607 my($cust_pkg) = shift;
608 include( '/elements/popup_link-cust_pkg.html',
609 'action' => $p. 'misc/delay_susp_pkg.html',
610 'label' => ( $cust_pkg->dundate
611 ? emt('Edit suspension delay')
612 : emt('Delay suspend')
614 'actionlabel' => emt('Delay suspend for'),
615 'cust_pkg' => $cust_pkg,
619 sub pkg_resume_link {
620 include( '/elements/popup_link-cust_pkg.html',
621 'action' => $p. 'misc/cancel_pkg.html?method=resume',
622 'label' => emt('Unsuspend later'),
623 'actionlabel' => emt('Resume'),
624 'color' => '#00CC00',
629 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', emt('Unsuspend now'), @_ ); }
630 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', emt('Abort'), @_ ); }
631 sub pkg_unexpire_link { pkg_link('misc/unexpire_pkg', emt('Abort'), @_ ); }
632 sub pkg_unchange_link { pkg_link('misc/do_not_change_pkg', emt('Abort change'), @_ ); }
633 sub pkg_change_now_link { pkg_link('misc/change_pkg_now', emt('Change now'), @_ ); }
635 sub pkg_cancel_link {
636 include( '/elements/popup_link-cust_pkg.html',
637 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
638 'label' => emt('Cancel now'),
639 'actionlabel' => emt('Cancel'),
640 'color' => '#ff0000',
645 sub pkg_uncancel_link {
646 include( '/elements/popup_link-cust_pkg.html',
647 'action' => $p. 'misc/cancel_pkg.html?method=uncancel',
648 'label' => emt('Un-cancel'),
649 'actionlabel' => emt('Un-cancel'),
655 sub pkg_expire_link {
656 include( '/elements/popup_link-cust_pkg.html',
657 'action' => $p. 'misc/cancel_pkg.html?method=expire',
658 'label' => emt('Cancel later'),
659 'actionlabel' => emt('Expire'),
660 'color' => '#CC0000',
665 sub pkg_change_later_link {
666 my $cust_pkg = shift;
667 include( '/elements/popup_link-cust_pkg.html',
668 'action' => $p . 'misc/change_pkg.cgi?',
669 'label' => emt('Reschedule'),
670 'actionlabel' => emt('Edit scheduled change for'),
671 'cust_pkg' => $cust_pkg,
677 sub svc_recharge_link {
678 include( '/elements/popup_link-cust_svc.html',
679 'action' => $p. 'misc/recharge_svc.html',
680 'label' => emt('Recharge'),
681 'actionlabel' => emt('Recharge'),
682 'color' => '#333399',
687 sub pkg_autosuspend_time {
688 my $cust_pkg = shift or return '';
691 my $pending_suspend = 0;
692 #this seems to be extremely inefficient... and is slowing down all customer
696 grep { $_->part_event->action eq 'suspend' }
697 @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
703 $pending_suspend = 1;
707 $pending_suspend ? time + ($days + 1) * 86400 : '';