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_if( $cust_pkg, emt('Expires'), 'expire', %opt, curuser=>$curuser ) %>
80 <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
82 % if ( !$supplemental && ! $opt{no_links} ) {
84 <TD COLSPAN=<%$opt{colspan}%>>
86 % if ( $curuser->access_right('Unsuspend customer package') ) {
87 ( <% pkg_unsuspend_link($cust_pkg) %> )
88 ( <% pkg_resume_link($cust_pkg) %> )
90 % if ( $curuser->access_right('Cancel customer package immediately') ) {
91 ( <% pkg_cancel_link($cust_pkg) %> )
98 % } else { #status: active
100 % unless ( $cust_pkg->get('setup') ) { #not setup
102 % unless ( $part_pkg->freq ) {
104 <% pkg_status_row_colspan( $cust_pkg, emt('Not yet billed (one-time charge)'), '', %opt ) %>
106 <% pkg_status_row_noauto( $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 % if ( !$supplemental && ! $opt{no_links} ) {
122 <TD COLSPAN=<%$opt{colspan}%>>
124 % if ( $curuser->access_right('Cancel customer package immediately') ) {
125 ( <% pkg_cancel_link($cust_pkg) %> )
134 <% pkg_status_row_colspan($cust_pkg, emt("Not yet billed ($billed_or_prepaid [_1])", myfreq($part_pkg) ), '', %opt ) %>
136 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
138 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
140 <% pkg_status_row_if($cust_pkg, emt('Start billing'), 'start_date', %opt) %>
141 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
147 % unless ( $part_pkg->freq ) {
149 <% pkg_status_row_colspan($cust_pkg, emt('One-time charge'), '', %opt ) %>
151 <% pkg_status_row($cust_pkg, emt('Billed'), 'setup', %opt) %>
153 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
155 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
157 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
161 % my $num_cust_svc = $cust_pkg->num_cust_svc;
162 % my $summarize = $opt{'cust_pkg-large_pkg_size'} > 0
163 % && $opt{'cust_pkg-large_pkg_size'} <= $num_cust_svc;
165 % #overlimit process is expensive with many services, so skip w/summary
166 % if ( !$summarize && scalar($cust_pkg->overlimit) ) {
168 <% pkg_status_row_colspan( $cust_pkg,
170 $billed_or_prepaid. ' '. myfreq($part_pkg),
177 <% pkg_status_row_colspan( $cust_pkg,
179 $billed_or_prepaid. ' '. myfreq($part_pkg),
186 <% pkg_status_row_noauto( $cust_pkg, %opt ) %>
188 <% pkg_status_row_discount( $cust_pkg, %opt ) %>
190 <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt) %>
192 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
198 % if ( $opt{'cust_pkg-show_autosuspend'} ) {
199 % my $autosuspend = pkg_autosuspend_time( $cust_pkg );
200 % $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
203 <% pkg_status_row_changed( $cust_pkg, %opt ) %>
204 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
205 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
206 <% pkg_status_row_if($cust_pkg, emt('Will automatically suspend by'), 'autosuspend', %opt) %>
207 <% pkg_status_row_if($cust_pkg, emt('Automatic suspension delayed until'), 'dundate', %opt) %>
208 <% pkg_status_row_if( $cust_pkg, emt('Will suspend on'), 'adjourn', %opt, curuser=>$curuser ) %>
209 <% pkg_status_row_if( $cust_pkg, emt('Will resume on'), 'resume', %opt, curuser=>$curuser ) %>
210 <% pkg_status_row_if( $cust_pkg, emt('Expires'), 'expire', %opt, curuser=>$curuser ) %>
211 <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
213 % if ( $part_pkg->freq and !$supplemental && ! $opt{no_links} ) {
216 <TD COLSPAN=<%$opt{colspan}%>>
218 % if ( $curuser->access_right('Suspend customer package') ) {
219 ( <% pkg_suspend_link($cust_pkg) %> )
221 % if ( $curuser->access_right('Suspend customer package later') ) {
222 ( <% pkg_adjourn_link($cust_pkg) %> )
224 % if ( $curuser->access_right('Delay suspension events') ) {
225 ( <% pkg_delay_link($cust_pkg) %> )
227 % if ( $curuser->access_right('Cancel customer package immediately') ) {
228 ( <% pkg_cancel_link($cust_pkg) %> )
230 % if ( $curuser->access_right('Cancel customer package later') ) {
231 ( <% pkg_expire_link($cust_pkg) %> )
248 my $bgcolor = $opt{'bgcolor'};
249 my $cust_pkg = $opt{'cust_pkg'};
250 my $part_pkg = $opt{'part_pkg'};
251 my $curuser = $FS::CurrentUser::CurrentUser;
252 my $width = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
253 my $supplemental = $opt{'supplemental'};
255 $opt{colspan} = $opt{'cust_pkg-display_times'} ? 8 : 4;
257 #false laziness w/edit/REAL_cust_pkg.cgi
258 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
259 unless ( $part_pkg->is_prepaid ) {
260 $billed_or_prepaid = 'billed';
261 $last_bill_or_renewed = 'Last bill';
262 $next_bill_or_prepaid_until = 'Next bill';
264 $billed_or_prepaid = 'prepaid';
265 $last_bill_or_renewed = 'Renewed';
266 $next_bill_or_prepaid_until = 'Prepaid until';
272 my $part_pkg = shift;
273 my $freq = $part_pkg->freq_pretty;
274 #$freq =~ s/ / /g;
278 #false laziness w/package.html
280 my($action, $label, $cust_pkg) = @_;
281 return '' unless $cust_pkg;
282 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
286 my( $cust_pkg, $title, $field, %opt ) = @_;
288 if ( $field and $cust_pkg->main_pkgnum ) {
289 # for supplemental packages, we mostly only show these if they're
290 # different from the main package
291 my $main_pkg = $cust_pkg-> main_pkg;
292 if ( $main_pkg->get($field) ne $cust_pkg->get($field)
293 # with some exceptions
295 or $field eq 'last_bill'
298 or $field eq 'cancel'
306 my $color = $opt{'color'};
308 my $html = qq(<TR><TD WIDTH="$width" ALIGN="right">);
309 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
310 $html .= qq($title );
311 $html .= qq(</B></FONT>) if length($color);
313 if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
314 $html .= ' (Balance: <B>'. $opt{'money_char'}.
315 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
320 $html .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
325 sub pkg_status_row_if {
326 my( $cust_pkg, $title, $field, %opt ) = @_;
328 $title = '<FONT SIZE=-1>( '. pkg_unadjourn_link($cust_pkg). ' ) </FONT>'. $title
329 if ( $field eq 'adjourn' &&
330 $opt{curuser}->access_right('Suspend customer package later')
333 $title = '<FONT SIZE=-1>( '. pkg_unexpire_link($cust_pkg). ' ) </FONT>'. $title
334 if ( $field eq 'expire' &&
335 $opt{curuser}->access_right('Cancel customer package later')
338 $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
341 sub pkg_status_row_changed {
342 my( $cust_pkg, %opt ) = @_;
344 return '' unless $cust_pkg->change_date;
347 pkg_status_row( $cust_pkg, emt('Package changed'), 'change_date', %opt );
349 my $old = $cust_pkg->old_cust_pkg;
351 my $part_pkg = $old->part_pkg;
352 $html .= pkg_status_row_colspan( $cust_pkg,
353 emt("Changed from [_1]: [_2]",
354 $cust_pkg->change_pkgnum,
355 $part_pkg->pkg_comment(nopartpkg => 1) ),
365 sub pkg_status_row_detached {
366 my( $cust_pkg, %opt ) = @_;
368 return '' unless $cust_pkg->change_custnum;
372 my $cust_main = $cust_pkg->change_cust_main;
375 my $cust_link = '<A HREF="cust_main.cgi?'. $cust_pkg->change_custnum. '">'.
376 encode_entities( $cust_main->name ).
379 my $what = $opt{'pkg_attached'} ? 'Attached' : 'Detached';
381 $html .= pkg_status_row_colspan( $cust_pkg,
382 emt("$what to customer #[_1]: ",
383 $cust_pkg->change_custnum
396 sub pkg_status_row_noauto {
397 my( $cust_pkg, %opt ) = @_;
398 my $part_pkg = $opt{'part_pkg'};
399 return '' unless $cust_pkg->no_auto || $part_pkg->no_auto;
401 #inefficient, should be passed in
402 my $cust_main = $cust_pkg->cust_main;
404 return '' unless $cust_main->payby =~ /^(CARD|CHEK)$/;
405 my $what = lc(FS::payby->shortname($cust_main->payby));
407 pkg_status_row_colspan( $cust_pkg, emt("No automatic $what charge"), '');
410 sub pkg_status_row_discount {
411 my( $cust_pkg, %opt ) = @_;
415 foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
417 my $discount = $cust_pkg_discount->discount;
419 my $label = '<B>'.emt('Discount').'</B>: '. $discount->description;
420 if ( $discount->months ) {
421 my $remaining = $discount->months - $cust_pkg_discount->months_used;
422 $remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
423 $label .= emt("([_1] months remaining)",$remaining);
426 $label .= ' <FONT SIZE="-1">('.
427 '<A HREF="../misc/delete-cust_pkg_discount.html?'.
428 $cust_pkg_discount->pkgdiscountnum.
429 '">'.emt('remove discount').'</A>)</FONT>';
431 $html .= pkg_status_row_colspan( $cust_pkg, $label, '', %opt );
439 my ($cust_pkg, $cpr, %opt) = @_;
440 return '' if $cust_pkg->main_pkgnum;
443 $reasontext = $cpr->reasontext . ' by ' . $cpr->otaker if $cpr;
444 pkg_status_row_colspan( $cust_pkg, $reasontext, '',
445 'align'=>'right', 'size'=>'-2', %opt
449 sub pkg_status_row_colspan {
450 my($cust_pkg, $title, $addl, %opt) = @_;
452 my $colspan = $opt{'colspan'};
454 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
455 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
456 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
458 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
459 $html .= qq(<FONT $color $size>) if length($color) || $size;
460 $html .= qq(<B>) if $color && !$size;
462 $html .= qq(</B>) if $color && !$size;
463 $html .= qq(</FONT>) if length($color) || $size;
464 $html .= ", $addl" if length($addl);
466 if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
467 $html .= ' (Balance: <B>'. $opt{'money_char'}.
468 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
472 $html .= qq(</TD></TR>);
479 my($cust_pkg, $field, %opt) = @_ or return '';
480 return ' ' unless $cust_pkg->get($field);
481 my $format = '<TD align="left"><B>%b</B></TD>'.
482 '<TD align="right"><B> %o,</B></TD>'.
483 '<TD align="right"><B> %Y</B></TD>';
484 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
485 $format .= '<TD ALIGN="right"><B> %l</TD>'.
486 '<TD ALIGN="center"><B>:</B></TD>'.
487 '<TD ALIGN="left"><B>%M</B></TD>'.
488 '<TD ALIGN="left"><B> %P</B></TD>'
489 if $opt{'cust_pkg-display_times'};
490 my $strip = time2str($format, $cust_pkg->get($field) );
491 $strip =~ s/ (\d)/$1/g;
495 sub pkg_suspend_link {
496 include( '/elements/popup_link-cust_pkg.html',
497 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
498 'label' => emt('Suspend now'),
499 'actionlabel' => emt('Suspend'),
500 'color' => '#FF9900',
505 sub pkg_adjourn_link {
506 include( '/elements/popup_link-cust_pkg.html',
507 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
508 'label' => emt('Suspend later'),
509 'actionlabel' => emt('Adjourn'),
510 'color' => '#CC6600',
516 my($cust_pkg) = shift;
517 include( '/elements/popup_link-cust_pkg.html',
518 'action' => $p. 'misc/delay_susp_pkg.html',
519 'label' => ( $cust_pkg->dundate
520 ? emt('Edit suspension delay')
521 : emt('Delay suspend')
523 'actionlabel' => emt('Delay suspend for'),
524 'cust_pkg' => $cust_pkg,
528 sub pkg_resume_link {
529 include( '/elements/popup_link-cust_pkg.html',
530 'action' => $p. 'misc/cancel_pkg.html?method=resume',
531 'label' => emt('Unsuspend later'),
532 'actionlabel' => emt('Resume'),
533 'color' => '#00CC00',
538 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', emt('Unsuspend now'), @_ ); }
539 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', emt('Abort'), @_ ); }
540 sub pkg_unexpire_link { pkg_link('misc/unexpire_pkg', emt('Abort'), @_ ); }
542 sub pkg_cancel_link {
543 include( '/elements/popup_link-cust_pkg.html',
544 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
545 'label' => emt('Cancel now'),
546 'actionlabel' => emt('Cancel'),
547 'color' => '#ff0000',
552 sub pkg_uncancel_link {
553 include( '/elements/popup_link-cust_pkg.html',
554 'action' => $p. 'misc/cancel_pkg.html?method=uncancel',
555 'label' => emt('Un-cancel'),
556 'actionlabel' => emt('Un-cancel'),
562 sub pkg_expire_link {
563 include( '/elements/popup_link-cust_pkg.html',
564 'action' => $p. 'misc/cancel_pkg.html?method=expire',
565 'label' => emt('Cancel later'),
566 'actionlabel' => emt('Expire'),
567 'color' => '#CC0000',
572 sub svc_recharge_link {
573 include( '/elements/popup_link-cust_svc.html',
574 'action' => $p. 'misc/recharge_svc.html',
575 'label' => emt('Recharge'),
576 'actionlabel' => emt('Recharge'),
577 'color' => '#333399',
582 sub pkg_autosuspend_time {
583 my $cust_pkg = shift or return '';
586 my $pending_suspend = 0;
587 #this seems to be extremely inefficient... and is slowing down all customer
591 grep { $_->part_event->action eq 'suspend' }
592 @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
598 $pending_suspend = 1;
602 $pending_suspend ? time + ($days + 1) * 86400 : '';