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 ) %>
35 % } else { # not canceled
37 % if ( $cust_pkg->get('susp') ) { #suspended or on hold
39 % #if ( $cust_pkg->order_date eq $cust_pkg->get('susp') ) # inconsistent with FS::cust_pkg::status
40 % if ( ! $cust_pkg->setup ) { #status: on hold
42 <% pkg_status_row( $cust_pkg, emt('On Hold'), '', 'color'=>'7E0079', %opt ) %>
44 % } else { #status: suspended
45 % my ($cpr,$susplabel);
46 % if ($cust_pkg->is_status_delay_cancel(%opt)) {
47 % $cpr = $cust_pkg->last_cust_pkg_reason('expire');
48 % $susplabel = 'Suspended (Cancelled)';
50 % $cpr = $cust_pkg->last_cust_pkg_reason('susp');
51 % $susplabel = 'Suspended';
53 <% pkg_status_row( $cust_pkg, emt($susplabel), 'susp', 'color'=>'FF9900', %opt ) %>
54 <% pkg_reason_row( $cust_pkg, $cpr, 'color' => 'FF9900', %opt ) %>
58 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
60 <% pkg_status_row_separate_bill( $cust_pkg, %opt ) %>
62 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
64 % if ( $cust_pkg->order_date ne $cust_pkg->get('susp') ) { # not on hold
65 % if ( $cust_pkg->get('setup') ) {
66 <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt ) %>
68 <% pkg_status_row_colspan( $cust_pkg, emt('Never billed'), '', %opt ) %>
72 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
74 <% pkg_status_row_changed( $cust_pkg, %opt ) %>
75 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
76 % if ( $cust_pkg->option('suspend_bill', 1)
77 % || ( $part_pkg->option('suspend_bill', 1)
78 % && ! $cust_pkg->option('no_suspend_bill',1)
82 <% pkg_status_row_if( $cust_pkg, emt('Next bill'), 'bill', %opt, curuser=>$curuser ) %>
84 <% pkg_status_row_if( $cust_pkg, emt('Will resume'), 'resume', %opt, curuser=>$curuser ) %>
85 <% pkg_status_row_expire($cust_pkg, %opt, curuser=>$curuser) %>
86 <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
88 % } else { #status: active
90 % if ( $change_from ) { # future change
92 <% pkg_status_row_colspan( $cust_pkg, emt('Waiting for package change'), '', %opt ) %>
93 <% pkg_status_row_if( $cust_pkg,
94 emt('Will be activated on'),
98 % } elsif ( ! $cust_pkg->get('setup') ) { # not setup
100 % unless ( $part_pkg->freq ) { # one-time charge
102 <% pkg_status_row_colspan( $cust_pkg, emt('Not yet billed (one-time charge)'), '', %opt ) %>
104 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
106 <% pkg_status_row_separate_bill( $cust_pkg, %opt ) %>
108 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
110 <% pkg_status_row_if(
112 ( $part_pkg->freq ? emt('Start billing') : emt('Bill on') ),
118 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
120 % } else { # recurring package, not yet billed
122 <% pkg_status_row_colspan($cust_pkg, emt("Not yet billed ($billed_or_prepaid [_1])", myfreq($part_pkg) ), '', %opt ) %>
124 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
126 <% pkg_status_row_separate_bill( $cust_pkg, %opt ) %>
128 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
130 <% pkg_status_row_if($cust_pkg, emt('Start billing'), 'start_date', %opt) %>
131 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
137 % unless ( $part_pkg->freq ) {
139 <% pkg_status_row_colspan($cust_pkg, emt('One-time charge'), '', %opt ) %>
141 <% pkg_status_row($cust_pkg, emt('Billed'), 'setup', %opt) %>
143 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
145 <% pkg_status_row_separate_bill( $cust_pkg, %opt ) %>
147 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
149 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
151 % } else { # recurring package
153 % my $num_cust_svc = $cust_pkg->num_cust_svc;
154 % my $summarize = $opt{'cust_pkg-large_pkg_size'} > 0
155 % && $opt{'cust_pkg-large_pkg_size'} <= $num_cust_svc;
157 % #overlimit process is expensive with many services, so skip w/summary
158 % if ( !$summarize && scalar($cust_pkg->overlimit) ) {
160 <% pkg_status_row_colspan( $cust_pkg,
162 $billed_or_prepaid. ' '. myfreq($part_pkg),
169 <% pkg_status_row_colspan( $cust_pkg,
171 $billed_or_prepaid. ' '. myfreq($part_pkg),
178 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
180 <% pkg_status_row_separate_bill( $cust_pkg, %opt ) %>
182 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
184 <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt) %>
186 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
192 % if ( $opt{'cust_pkg-show_autosuspend'} ) {
193 % my $autosuspend = pkg_autosuspend_time( $cust_pkg );
194 % $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
197 <% pkg_status_row_changed( $cust_pkg, %opt ) %>
198 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
199 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
200 <% pkg_status_row_if($cust_pkg, emt('Will automatically suspend by'), 'autosuspend', %opt) %>
201 <% pkg_status_row_if($cust_pkg, emt('Automatic suspension delayed until'), 'dundate', %opt) %>
202 <% pkg_status_row_if( $cust_pkg, emt('Will suspend on'), 'adjourn', %opt, curuser=>$curuser ) %>
203 <% pkg_status_row_if( $cust_pkg, emt('Will resume on'), 'resume', %opt, curuser=>$curuser ) %>
204 <% pkg_status_row_expire($cust_pkg, %opt, curuser=>$curuser) %>
205 <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
217 my $bgcolor = $opt{'bgcolor'};
218 my $cust_pkg = $opt{'cust_pkg'};
219 my $part_pkg = $opt{'part_pkg'};
220 my $curuser = $FS::CurrentUser::CurrentUser;
221 my $width = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
222 my $supplemental = $opt{'supplemental'};
223 my $change_from = $opt{'change_from'};
225 $opt{colspan} = $opt{'cust_pkg-display_times'} ? 8 : 4;
227 #false laziness w/edit/REAL_cust_pkg.cgi
228 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
229 unless ( $part_pkg->is_prepaid ) {
230 $billed_or_prepaid = 'billed';
231 $last_bill_or_renewed = 'Last bill';
232 $next_bill_or_prepaid_until = 'Next bill';
234 $billed_or_prepaid = 'prepaid';
235 $last_bill_or_renewed = 'Renewed';
236 $next_bill_or_prepaid_until = 'Prepaid until';
242 my $part_pkg = shift;
243 my $freq = $part_pkg->freq_pretty;
244 #$freq =~ s/ / /g;
248 #false laziness w/package.html
250 my($action, $label, $cust_pkg) = @_;
251 return '' unless $cust_pkg;
252 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
256 my( $cust_pkg, $title, $field, %opt ) = @_;
258 if ( $field and $cust_pkg->main_pkgnum ) {
259 # for supplemental packages, we mostly only show these if they're
260 # different from the main package
261 my $main_pkg = $cust_pkg-> main_pkg;
262 if ( $main_pkg->get($field) ne $cust_pkg->get($field)
263 # with some exceptions
265 or $field eq 'last_bill'
268 or $field eq 'cancel'
276 my $color = $opt{'color'};
278 my $html = qq(<TR><TD WIDTH="$width" ALIGN="right">);
279 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
280 $html .= qq($title );
281 $html .= qq(</B></FONT>) if length($color);
283 if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
284 $html .= ' (Balance: <B>'. $opt{'money_char'}.
285 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
290 $html .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
295 sub pkg_status_row_if {
296 my( $cust_pkg, $title, $field, %opt ) = @_;
298 $title = '<FONT SIZE=-1>( '. pkg_unadjourn_link($cust_pkg). ' ) </FONT>'. $title
299 if ( $field eq 'adjourn' &&
300 $opt{curuser}->access_right('Suspend customer package later')
303 $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
306 sub pkg_status_row_expire {
307 my $cust_pkg = shift;
309 return unless $cust_pkg->get('expire');
313 if ( $cust_pkg->get('change_to_pkg') ) {
314 if ( $cust_pkg->change_to_pkg->pkgpart != $cust_pkg->pkgpart ) {
315 $title = mt('Will change to <b>[_1]</b> on',
316 $cust_pkg->change_to_pkg->part_pkg->pkg);
317 } elsif ( $cust_pkg->change_to_pkg->locationnum != $cust_pkg->locationnum )
319 $title = mt('Will <b>change location</b> on');
320 } elsif (( $cust_pkg->change_to_pkg->quantity != $cust_pkg->quantity ) ||
321 ( $cust_pkg->change_to_pkg->contract_end != $cust_pkg->contract_end ))
323 $title = mt('Will change on');
325 # FS::cust_pkg->change_later should have prevented this, but
326 # just so that we can display _something_
327 $title = '<font color="#ff0000">Unknown package change</font>';
332 $title = emt('Expires');
333 if ( $opt{curuser}->access_right('Cancel customer package later')) {
334 $title = '<FONT SIZE=-1>( '. pkg_unexpire_link($cust_pkg). ' ) </FONT>'. $title;
339 pkg_status_row( $cust_pkg, $title, 'expire', %opt );
342 sub pkg_status_row_changed {
343 my( $cust_pkg, %opt ) = @_;
345 return '' unless $cust_pkg->change_date;
348 pkg_status_row( $cust_pkg, emt('Changed'), 'change_date', %opt );
350 my $old = $cust_pkg->old_cust_pkg;
352 my $part_pkg = $old->part_pkg;
353 $html .= pkg_status_row_colspan(
355 # emt("Changed from [_1]: [_2]",
356 # $cust_pkg->change_pkgnum,
357 # $part_pkg->pkg_comment(cust_pkg=>$old, nopartpkg=>1)
369 sub pkg_status_row_detached {
370 my( $cust_pkg, %opt ) = @_;
372 return '' unless $cust_pkg->change_custnum;
376 my $cust_main = $cust_pkg->change_cust_main;
379 my $cust_link = '<A HREF="cust_main.cgi?'. $cust_pkg->change_custnum. '">'.
380 encode_entities( $cust_main->name ).
383 my $what = $opt{'pkg_attached'} ? 'Attached' : 'Detached';
385 $html .= pkg_status_row_colspan( $cust_pkg,
386 emt("$what to customer #[_1]: ",
387 $cust_pkg->change_custnum
400 sub pkg_status_row_noauto {
401 my( $cust_pkg, %opt ) = @_;
403 return '' unless ( $cust_pkg->no_auto || $opt{'part_pkg'}->no_auto )
404 && $opt{'has_cust_payby_auto'};
406 pkg_status_row_colspan( $cust_pkg, emt("No automatic charge"), '');
409 sub pkg_status_row_separate_bill {
410 my $cust_pkg = shift;
411 return '' unless $cust_pkg->separate_bill;
412 pkg_status_row_colspan( $cust_pkg, emt("Invoiced separately") );
415 sub pkg_status_row_discount {
416 my( $cust_pkg, %opt ) = @_;
420 if ( $cust_pkg->waive_setup ) {
421 my $label = '<SPAN STYLE="font-size: small;font-weight: bold">' .
422 emt('Setup fee waived') .
424 $html .= pkg_status_row_colspan( $cust_pkg, $label, '', %opt );
427 foreach my $cust_pkg_discount (@{ $cust_pkg->{_cust_pkg_discount_active} }) {
429 my $discount = $cust_pkg_discount->discount;
431 my $label = '<SPAN STYLE="font-size: small"><B>';
432 if ( $cust_pkg_discount->setuprecur eq 'setup' ) {
433 $label .= emt('Setup Discount');
435 $label .= emt('Recurring Discount');
437 $label .= '</B>: '. $discount->description;
438 if ( $discount->months > 0 and $cust_pkg_discount->months_used > 0 ) {
439 my $remaining = $discount->months - $cust_pkg_discount->months_used;
440 $remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
441 $label .= <br> . emt(" ([quant,_1,month,months] remaining)",$remaining);
445 #$label .= ' <FONT SIZE="-1">('.
446 # '<A HREF="../misc/delete-cust_pkg_discount.html?'.
447 # $cust_pkg_discount->pkgdiscountnum.
448 # '">'.emt('remove discount').'</A>)</FONT>';
450 $html .= pkg_status_row_colspan( $cust_pkg, $label, '', %opt );
458 my ($cust_pkg, $cpr, %opt) = @_;
459 return '' if $cust_pkg->main_pkgnum;
462 $reasontext = $cpr->reasontext . ' by ' . $cpr->otaker if $cpr;
463 pkg_status_row_colspan( $cust_pkg, $reasontext, '',
464 'align'=>'right', 'size'=>'-2', %opt
468 sub pkg_status_row_colspan {
469 my($cust_pkg, $title, $addl, %opt) = @_;
471 my $colspan = $opt{'colspan'};
473 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
474 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
475 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
477 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
478 $html .= qq(<FONT $color $size>) if length($color) || $size;
479 $html .= qq(<B>) if $color && !$size;
481 $html .= qq(</B>) if $color && !$size;
482 $html .= qq(</FONT>) if length($color) || $size;
483 $html .= ", $addl" if length($addl);
485 if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
486 $html .= ' (Balance: <B>'. $opt{'money_char'}.
487 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
491 $html .= qq(</TD></TR>);
498 my($cust_pkg, $field, %opt) = @_ or return '';
499 return ' ' unless $cust_pkg->get($field);
500 my $format = '<TD align="left"><B>%b</B></TD>'.
501 '<TD align="right"><B> %o,</B></TD>'.
502 '<TD align="right"><B> %Y</B></TD>';
503 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
504 $format .= '<TD ALIGN="right"><B> %l</TD>'.
505 '<TD ALIGN="center"><B>:</B></TD>'.
506 '<TD ALIGN="left"><B>%M</B></TD>'.
507 '<TD ALIGN="left"><B> %P</B></TD>'
508 if $opt{'cust_pkg-display_times'};
509 my $strip = time2str($format, $cust_pkg->get($field) );
510 $strip =~ s/ (\d)/$1/g;
514 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', emt('Abort'), @_ ); }
515 sub pkg_unexpire_link { pkg_link('misc/unexpire_pkg', emt('Abort'), @_ ); }
517 sub svc_recharge_link {
518 include( '/elements/popup_link-cust_svc.html',
519 'action' => $p. 'misc/recharge_svc.html',
520 'label' => emt('Recharge'),
521 'actionlabel' => emt('Recharge'),
522 'color' => '#333399',
527 sub pkg_autosuspend_time {
528 my $cust_pkg = shift or return '';
531 my $pending_suspend = 0;
532 #this seems to be extremely inefficient... and is slowing down all customer
536 grep { $_->part_event->action eq 'suspend' }
537 @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
543 $pending_suspend = 1;
547 $pending_suspend ? time + ($days + 1) * 86400 : '';